Debian Codegraph @

tools/physicalModeling/mesh2faust/vega/libraries/wildMagic/meshKey/triKey.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 TRIKEYS_H
41 #define TRIKEYS_H
42
43 #include <algorithm>
44
45 // unoriented edge
46 struct UEdgeKey
47 {
48 int v[2];
49 inline UEdgeKey(int v0, int v1);
50 inline UEdgeKey();//creates an invalid key with v = {-1,-1}
51 const int & operator[](int index) const { return v[index]; }
52 inline bool operator < (const UEdgeKey &) const;
53 inline bool operator == (const UEdgeKey &) const;
54 };
55
56 // oriented edge
57 struct OEdgeKey
58 {
59 int v[2];
60 inline OEdgeKey(int v0, int v1);
61 inline OEdgeKey();//creates an invalid key with v = {-1,-1}
62 const int & operator[](int index) const { return v[index]; }
63 inline bool operator < (const OEdgeKey &) const;
64 inline void reverse(); // reverse the orientation of this edge
65 };
66
67 // unoriented triangle key based on vtx indices
68 struct UTriKey
69 {
70
71 inline UTriKey(const int v[3]);
72 inline UTriKey(int v0, int v1, int v2);
73 inline UTriKey(); // creates an invalid key with v = {-1,-1,-1}
74 inline bool operator < (const UTriKey &) const;
75 inline bool operator == (const UTriKey &) const;
76 const int & operator[](int index) const { return v[index]; }
77 const int * indices() const { return v; }
78 UEdgeKey uEdgeKey(int ind) const;
79 protected:
80 int v[3];
81 };
82
83 // oriented triangle key that remember its orientation
84 struct OTriKey : public UTriKey
85 {
86 inline OTriKey(const int v[3]);
87 inline OTriKey(int v0, int v1, int v2);
88 inline OTriKey();
89 inline void reverse(); // reverse the orientation
90 // permute v0, v1, v2 and store into r0, r1, r2 so that they share the same orientation but r0 = min(v0,v1,v2)
91 inline static void permute(int v0, int v1, int v2, int & r0, int & r1, int & r2);
92 // UEdgeKey unorientedEdgeKey(int ind) const;
93 inline int getInd(const int vtx) const;
94 OEdgeKey oEdgeKey(int ind) const;
95 static const int triEdgeIndex[3][2];
96 };
97
98
99 ///////////////////////////////////////////////////////////////////////////////
100 // IMPLEMENTATION //
101 ///////////////////////////////////////////////////////////////////////////////
102
103 inline UEdgeKey::UEdgeKey(int v0, int v1)
104 {
105 if (v0 < v1)
106 {
107 v[0] = v0; v[1] = v1;
108 }
109 else
110 {
111 v[0] = v1; v[1] = v0;
112 }
113 }
114
115 inline UEdgeKey::UEdgeKey()
116 {
117 v[0] = v[1] = -1;
118 }
119
120 inline bool UEdgeKey::operator < (const UEdgeKey & other) const
121 {
122 if (v[0] < other.v[0])
123 return true;
124 if (v[0] > other.v[0])
125 return false;
126 return v[1] < other.v[1];
127 }
128
129 inline bool UEdgeKey::operator == (const UEdgeKey & other) const
130 {
131 return v[0] == other.v[0] && v[1] == other.v[1];
132 }
133
134 inline OEdgeKey::OEdgeKey(int v0, int v1)
135 {
136 v[0] = v0;
137 v[1] = v1;
138 }
139
140 inline OEdgeKey::OEdgeKey()
141 {
142 v[0] = v[1] = -1;
143 }
144
145 inline bool OEdgeKey::operator < (const OEdgeKey & other) const
146 {
147 if (v[0] < other.v[0])
148 return true;
149 if (v[0] > other.v[0])
150 return false;
151 return v[1] < other.v[1];
152 }
153
154 inline void OEdgeKey::reverse()
155 {
156 std::swap(v[0], v[1]);
157 }
158
159 inline UTriKey::UTriKey(int v0, int v1, int v2)
160 {
161 v[0] = v0;
162 v[1] = v1;
163 v[2] = v2;
164 std::sort(v, v + 3);
165 }
166
167 inline UTriKey::UTriKey(const int vtx[3])
168 {
169 v[0] = vtx[0];
170 v[1] = vtx[1];
171 v[2] = vtx[2];
172 std::sort(v, v + 3);
173 }
174
175 inline UTriKey::UTriKey()
176 {
177 v[0] = v[1] = v[2] = -1;
178 }
179
180 inline bool UTriKey::operator < (const UTriKey & other) const
181 {
182 if (v[0] < other.v[0])
183 return true;
184 if (v[0] > other.v[0])
185 return false;
186 if (v[1] < other.v[1])
187 return true;
188 if (v[1] > other.v[1])
189 return false;
190 return v[2] < other.v[2];
191 }
192
193 inline bool UTriKey::operator == (const UTriKey & other) const
194 {
195 return v[0] == other.v[0] && v[1] == other.v[1] && v[2] == other.v[2];
196 }
197
198 inline UEdgeKey UTriKey::uEdgeKey(int ind) const
199 {
200 return UEdgeKey(v[OTriKey::triEdgeIndex[ind][0]], v[OTriKey::triEdgeIndex[ind][1]]);
201 }
202
203 inline OEdgeKey OTriKey::oEdgeKey(int ind) const
204 {
205 return OEdgeKey(v[OTriKey::triEdgeIndex[ind][0]], v[OTriKey::triEdgeIndex[ind][1]]);
206 }
207
208 inline OTriKey::OTriKey(int v0, int v1, int v2)
209 {
210 permute(v0, v1, v2, v[0], v[1], v[2]);
211 }
212
213 inline OTriKey::OTriKey(const int vtx[3])
214 {
215 permute(vtx[0], vtx[1], vtx[2], v[0], v[1], v[2]);
216 }
217
218 inline OTriKey::OTriKey()
219 {
220 v[0] = v[1] = v[2] = -1;
221 }
222
223 inline void OTriKey::permute(int v0, int v1, int v2, int & r0, int & r1, int & r2)
224 {
225 if (v0 < v1)
226 {
227 if (v0 < v2)
228 {
229 r0 = v0; r1 = v1; r2 = v2;
230 }
231 else
232 { // v2 <= v0
233 r0 = v2; r1 = v0; r2 = v1;
234 }
235 }
236 else
237 { // v1 <= v0
238 if (v1 < v2)
239 {
240 r0 = v1; r1 = v2; r2 = v0;
241 }
242 else
243 { // v2 <= v1
244 r0 = v2; r1 = v0; r2 = v1;
245 }
246 }
247 }
248
249 inline void OTriKey::reverse()
250 {
251 std::swap(v[1], v[2]);
252 }
253
254 inline int OTriKey::getInd(const int vtx) const
255 {
256 for(int i = 0; i < 3; i++)
257 if (vtx == v[i])
258 return i;
259 return -1;
260 }
261
262 #endif