Debian Codegraph @

tools/physicalModeling/mesh2faust/vega/libraries/wildMagic/meshKey/tetKey.h

raw symbols SCIP
1 /*
2 This code is based on code from the Geometric Tools library,
3 which is licensed under a boost license.
4 Such usage is permitted by the boost license; for details,
5 please see the boost license below.
6 */
7
8 // Geometric Tools, LLC
9 // Copyright (c) 1998-2014
10 // Distributed under the Boost Software License, Version 1.0.
11 // http://www.boost.org/LICENSE_1_0.txt
12 // http://www.geometrictools.com/License/Boost/LICENSE_1_0.txt
13
14 /*************************************************************************
15 * *
16 * We release our improvements to the wildMagic code under our standard *
17 * Vega FEM license, as follows: *
18 * *
19 * Vega FEM Simulation Library Version 3.1 *
20 * *
21 * "improvements to the wildMagic library" , Copyright (C) 2016 USC *
22 * All rights reserved. *
23 * *
24 * Code author: Yijing Li *
25 * http://www.jernejbarbic.com/code *
26 * *
27 * Funding: National Science Foundation *
28 * *
29 * This library is free software; you can redistribute it and/or *
30 * modify it under the terms of the BSD-style license that is *
31 * included with this library in the file LICENSE.txt *
32 * *
33 * This library is distributed in the hope that it will be useful, *
34 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
35 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the file *
36 * LICENSE.TXT for more details. *
37 * *
38 *************************************************************************/
39
40 #ifndef TETKEYS_H
41 #define TETKEYS_H
42
43 #include "triKey.h"
44 #include <algorithm>
45
46 // unoriented tet key based on vtx indices
47 struct UTetKey
48 {
49 inline UTetKey(const int v[4]);
50 inline UTetKey(int v0, int v1, int v2, int v3);
51 inline bool operator < (const UTetKey &) const;
52 const int & operator[](int index) const { return v[index]; }
53 const int * indices() const { return v; }
54 UTriKey uFaceKey(int ind) const;
55
56 // opposite face for each vtx in a tet. The faces are ordered so that its normals pointing outside the tet if tet has positive orientation
57 // static const int tetFaceIndex[4][3];
58 protected:
59 int v[4];
60 };
61
62 // oriented tet key based on vtx indices
63 struct OTetKey
64 {
65 inline OTetKey(const int v[4]);
66 inline OTetKey(int v0, int v1, int v2, int v3);
67 inline bool operator < (const OTetKey &) const;
68 const int & operator[](int index) const { return v[index]; }
69 const int * indices() const { return v; }
70 OTriKey oFaceKey(int ind) const;
71 UTriKey uFaceKey(int ind) const;
72 int getInd(const int vtx) const;
73 // permute v0, v1, v2, v3 and store into r0, r1, r2, r3 so that they share the same orientation but r0 = min(v0,v1,v2,v3)
74 inline static void permute(int v0, int v1, int v2, int v3, int & r0, int & r1, int & r2, int & r3);
75 // opposite face for each vtx in a tet. The faces are ordered so that its normals pointing outside the tet if tet has positive orientation
76 static const int tetFaceIndex[4][3];
77
78 int v[4];
79 };
80
81
82 ///////////////////////////////////////////////////////////////////////////////
83 // IMPLEMENTATION //
84 ///////////////////////////////////////////////////////////////////////////////
85
86 inline UTetKey::UTetKey(int v0, int v1, int v2, int v3)
87 {
88 v[0] = v0;
89 v[1] = v1;
90 v[2] = v2;
91 v[3] = v3;
92 std::sort(v, v + 4);
93 }
94
95 inline UTetKey::UTetKey(const int vtx[4])
96 {
97 v[0] = vtx[0];
98 v[1] = vtx[1];
99 v[2] = vtx[2];
100 v[3] = vtx[3];
101 std::sort(v, v + 4);
102 }
103
104
105 inline bool UTetKey::operator < (const UTetKey & other) const
106 {
107 if (v[0] < other.v[0])
108 return true;
109 if (v[0] > other.v[0])
110 return false;
111 if (v[1] < other.v[1])
112 return true;
113 if (v[1] > other.v[1])
114 return false;
115 if (v[2] < other.v[2])
116 return true;
117 if (v[2] > other.v[2])
118 return false;
119 return v[3] < other.v[3];
120 }
121
122 inline UTriKey UTetKey::uFaceKey(int ind) const
123 {
124 return UTriKey(v[OTetKey::tetFaceIndex[ind][0]], v[OTetKey::tetFaceIndex[ind][1]], v[OTetKey::tetFaceIndex[ind][2]]);
125 }
126
127 inline void OTetKey::permute(int v0, int v1, int v2, int v3, int & r0, int & r1, int & r2, int & r3) {
128 int minInd = 0;
129 r0 = v0;
130 if (v1 < r0)
131 {
132 r0 = v1;
133 minInd = 1;
134 }
135 if (v2 < r0)
136 {
137 r0 = v2;
138 minInd = 2;
139 }
140 if (v3 < r0)
141 {
142 r0 = v3;
143 minInd = 3;
144 }
145
146 if (minInd == 0)
147 OTriKey::permute(v1, v2, v3, r1, r2, r3);
148 else if (minInd == 1)
149 OTriKey::permute(v0, v3, v2, r1, r2, r3);
150 else if (minInd == 2)
151 OTriKey::permute(v0, v1, v3, r1, r2, r3);
152 else // minInd == 3
153 OTriKey::permute(v0, v2, v1, r1, r2, r3);
154 }
155
156 inline OTetKey::OTetKey(int v0, int v1, int v2, int v3)
157 {
158 permute(v0, v1, v2, v3, v[0], v[1], v[2], v[3]);
159 }
160
161 inline OTetKey::OTetKey(const int vtx[4])
162 {
163 permute(vtx[0], vtx[1], vtx[2], vtx[3], v[0], v[1], v[2], v[3]);
164 }
165
166 inline bool OTetKey::operator < (const OTetKey & other) const
167 {
168 if (v[0] < other.v[0])
169 return true;
170 if (v[0] > other.v[0])
171 return false;
172 if (v[1] < other.v[1])
173 return true;
174 if (v[1] > other.v[1])
175 return false;
176 if (v[2] < other.v[2])
177 return true;
178 if (v[2] > other.v[2])
179 return false;
180 return v[3] < other.v[3];
181 }
182
183 inline OTriKey OTetKey::oFaceKey(int ind) const
184 {
185 return OTriKey(v[tetFaceIndex[ind][0]], v[tetFaceIndex[ind][1]], v[tetFaceIndex[ind][2]]);
186 }
187
188 inline UTriKey OTetKey::uFaceKey(int ind) const
189 {
190 return UTriKey(v[tetFaceIndex[ind][0]], v[tetFaceIndex[ind][1]], v[tetFaceIndex[ind][2]]);
191 }
192
193 inline int OTetKey::getInd(const int vtx) const
194 {
195 for(int i = 0; i < 4; i++)
196 if (vtx == v[i])
197 return i;
198 return -1;
199 }
200
201 #endif