47 |
|
|
48 |
#include <set> |
#include <set> |
49 |
|
|
50 |
|
class SurfaceMeshGenerator::Internals |
51 |
|
{ |
52 |
|
private: |
53 |
|
friend class SurfaceMeshGenerator; |
54 |
|
|
55 |
|
struct __ltv |
56 |
|
{ |
57 |
|
bool operator()(const TinyVector<3,real_t>& s1, const TinyVector<3,real_t>& s2) const |
58 |
|
{ |
59 |
|
if (s1[0]<s2[0]) |
60 |
|
return true; |
61 |
|
if (s1[1]<s2[1]) |
62 |
|
return true; |
63 |
|
if (s1[1]<s2[1]) |
64 |
|
return true; |
65 |
|
return false; |
66 |
|
} |
67 |
|
}; |
68 |
|
|
69 |
|
typedef std::map<TinyVector<3,real_t>, |
70 |
|
std::vector<SurfaceMesh*>, __ltv> VRRefMesh; |
71 |
|
|
72 |
|
typedef std::list<TinyVector<3,Edge::Pair> > EdgePairList; |
73 |
|
typedef std::list<const Cell*> MotherCellList; |
74 |
|
|
75 |
|
typedef std::map<const Cell*, |
76 |
|
std::pair<ReferenceCounting<std::vector<TetrahedronByEdges> >, |
77 |
|
ReferenceCounting<std::vector<Edge> > > > |
78 |
|
HexaTetraAssociation; |
79 |
|
|
80 |
|
typedef std::map<Edge::Pair, Vertex*> VerticesList; |
81 |
|
|
82 |
|
//! list of cut edges and intersection vertex. |
83 |
|
std::map<Edge::Pair, size_t> edgesRef; |
84 |
|
|
85 |
|
EdgePairList triangleList; |
86 |
|
EdgePairList localTriangleList; |
87 |
|
|
88 |
|
//! This list is used to provide an orientation to the Surfacic Elements. |
89 |
|
std::list<TinyVector<3> > InsideVertexList; |
90 |
|
|
91 |
|
//! list of cut edges and intersection vertex. |
92 |
|
VerticesList verticesList; |
93 |
|
|
94 |
|
HexaTetraAssociation hexaTetraAssociation; |
95 |
|
|
96 |
|
MotherCellList cellList; |
97 |
|
|
98 |
|
TinyVector<3> __splitEdge(const Edge& e, |
99 |
|
const Reference::Representation& ref, |
100 |
|
const Shape& S); |
101 |
|
|
102 |
|
void __createTriangles(const Shape& S, |
103 |
|
const Reference::Representation& ref); |
104 |
|
|
105 |
|
void __setBoundaryType(const Boundary& B, |
106 |
|
POVRayReferences& vrRefList, |
107 |
|
TinyVector<6,bool>& faces); |
108 |
|
|
109 |
|
public: |
110 |
|
Internals() |
111 |
|
{ |
112 |
|
; |
113 |
|
} |
114 |
|
}; |
115 |
|
|
116 |
|
void |
117 |
|
SurfaceMeshGenerator::Internals:: |
118 |
|
__setBoundaryType(const Boundary& B, |
119 |
|
POVRayReferences& vrRefList, |
120 |
|
TinyVector<6,bool>& faces) |
121 |
|
{ |
122 |
|
switch (B.type()) { |
123 |
|
case (Boundary::povRay): { |
124 |
|
const BoundaryPOVRay& bp = dynamic_cast<const BoundaryPOVRay&>(B); |
125 |
|
for (size_t l=0; l<bp.nbPOVRef(); ++l) |
126 |
|
vrRefList[bp.POVRef(l)]++; |
127 |
|
break; |
128 |
|
} |
129 |
|
case (Boundary::structured3DMesh): { |
130 |
|
const BoundaryStructured3DMesh& bs |
131 |
|
= dynamic_cast<const BoundaryStructured3DMesh&>(B); |
132 |
|
for (size_t l=0; l<6; ++l) |
133 |
|
faces[l] = faces[l] || bs.structMesh(l); |
134 |
|
break; |
135 |
|
} |
136 |
|
case (Boundary::surfaceMesh): { |
137 |
|
//! Nothing to do. |
138 |
|
break; |
139 |
|
} |
140 |
|
default: { |
141 |
|
fferr(0) << '\n' << __FILE__ << ':' << __LINE__ << ": Not implemented\n"; |
142 |
|
std::exit(1); |
143 |
|
} |
144 |
|
} |
145 |
|
} |
146 |
|
|
147 |
|
TinyVector<3, real_t> |
148 |
|
SurfaceMeshGenerator::Internals:: |
149 |
|
__splitEdge(const Edge& e, |
150 |
|
const Reference::Representation& ref, |
151 |
|
const Shape& S) |
152 |
|
{ |
153 |
|
int in = -1; // number of the vertex inside |
154 |
|
int out = -1; // same thing for outside |
155 |
|
|
156 |
|
for (int j=0; j<2; j++) { |
157 |
|
if (!e(j).Ref().isSet(ref)) { |
158 |
|
out = j; |
159 |
|
} else { |
160 |
|
in = j; |
161 |
|
} |
162 |
|
} |
163 |
|
|
164 |
|
assert((in != -1)&&(out != -1)); |
165 |
|
|
166 |
|
TinyVector<3> vi = e(in); |
167 |
|
TinyVector<3> vo = e(out); |
168 |
|
TinyVector<3> vs = (vi+vo)/2; |
169 |
|
|
170 |
|
for (int l = 0; l<5; l++) { // 3% error after 5 iterations. |
171 |
|
if(S.inside(vs)) { |
172 |
|
vi = vs; |
173 |
|
vs = (vo+vi)/2; |
174 |
|
} else { |
175 |
|
vo = vs; |
176 |
|
vs = (vo+vi)/2; |
177 |
|
} |
178 |
|
} |
179 |
|
|
180 |
|
return vs; |
181 |
|
} |
182 |
|
|
183 |
|
void SurfaceMeshGenerator::Internals:: |
184 |
|
__createTriangles(const Shape& S, |
185 |
|
const Reference::Representation& ref) |
186 |
|
{ |
187 |
|
for(SurfaceMeshGenerator::Internals::HexaTetraAssociation::iterator i |
188 |
|
= hexaTetraAssociation.begin(); |
189 |
|
i != hexaTetraAssociation.end(); ++i) { |
190 |
|
|
191 |
|
const CartesianHexahedron& currentCell |
192 |
|
= static_cast<const CartesianHexahedron&>(*(*i).first); |
193 |
|
std::vector<TetrahedronByEdges>& T = *(((*i).second).first); |
194 |
|
|
195 |
|
for (std::vector<TetrahedronByEdges>::iterator currentT = T.begin(); |
196 |
|
currentT < T.end(); ++currentT) { |
197 |
|
std::vector<const Edge*> cutEdges; |
198 |
|
|
199 |
|
for(size_t ie=0; ie<6; ++ie) { |
200 |
|
const Edge& e = currentT->edge(ie); |
201 |
|
if ((e(0).Ref().isSet(ref)) xor (e(1).Ref().isSet(ref))) { |
202 |
|
cutEdges.push_back(&e); |
203 |
|
} |
204 |
|
} |
205 |
|
|
206 |
|
switch (cutEdges.size()) { |
207 |
|
case 3: { |
208 |
|
std::vector<TinyVector<3> > V(cutEdges.size()); |
209 |
|
for(size_t i=0; i<cutEdges.size(); ++i) { |
210 |
|
const Edge& e = *cutEdges[i]; |
211 |
|
if(e(0).Ref().isSet(ref)) |
212 |
|
V[i] = (e(0).Vector3() - e(1).Vector3()); |
213 |
|
else |
214 |
|
V[i] = (e(1).Vector3() - e(0).Vector3()); |
215 |
|
} |
216 |
|
|
217 |
|
if ((V[0]^V[1])*V[2] < 0) |
218 |
|
std::swap(cutEdges[1], cutEdges[2]); |
219 |
|
|
220 |
|
//! Addes a triangle to the list. |
221 |
|
localTriangleList.push_front(TinyVector<3,Edge::Pair>()); |
222 |
|
cellList.push_front(¤tCell); |
223 |
|
|
224 |
|
//! Sets the triangle vertices (actually just store the edge where it lives). |
225 |
|
EdgePairList::iterator currentTriangle = localTriangleList.begin(); |
226 |
|
for(size_t i=0; i<cutEdges.size(); ++i) |
227 |
|
(*currentTriangle)[i] = (Edge::Pair)(*cutEdges[i]); |
228 |
|
|
229 |
|
//! Stores the Edges on which the vertex will be computed. |
230 |
|
for (size_t i=0; i<cutEdges.size(); ++i) |
231 |
|
verticesList[*cutEdges[i]] = new Vertex(Internals::__splitEdge(*cutEdges[i], ref, S)); |
232 |
|
break; |
233 |
|
} |
234 |
|
case 4: { |
235 |
|
//! Orders the Edges using a map ! |
236 |
|
std::map<Edge::Pair, const Edge*> cutEdgesMap; |
237 |
|
for(size_t ie=0; ie<cutEdges.size(); ++ie) |
238 |
|
cutEdgesMap[(Edge::Pair)*(cutEdges[ie])] = (cutEdges[ie]); |
239 |
|
|
240 |
|
//! Addes a triangle to the list. |
241 |
|
localTriangleList.push_front(TinyVector<3,Edge::Pair>()); |
242 |
|
cellList.push_front(¤tCell); |
243 |
|
|
244 |
|
std::vector<TinyVector<3> > V(cutEdges.size()); |
245 |
|
std::map<Edge::Pair, const Edge*>::iterator currentCutEdge=cutEdgesMap.begin(); |
246 |
|
for (size_t i=0; i<V.size(); ++i) { |
247 |
|
const Edge& e = *(*currentCutEdge).second; |
248 |
|
if(e(0).Ref().isSet(ref)) |
249 |
|
V[i] = (e(0).Vector3() - e(1).Vector3()); |
250 |
|
else |
251 |
|
V[i] = (e(1).Vector3() - e(0).Vector3()); |
252 |
|
++currentCutEdge; |
253 |
|
} |
254 |
|
|
255 |
|
bool swapEdge = ((V[0]^V[1])*V[2] > 0); |
256 |
|
|
257 |
|
//! Sets the triangle vertices (actually just store the edge where it lives). |
258 |
|
EdgePairList::iterator currentTriangle = localTriangleList.begin(); |
259 |
|
|
260 |
|
currentCutEdge = cutEdgesMap.begin(); |
261 |
|
if (!swapEdge) |
262 |
|
for(size_t i=0; i<3; ++i) { |
263 |
|
(*currentTriangle)[i] = (Edge::Pair)(currentCutEdge->first); |
264 |
|
++currentCutEdge; |
265 |
|
} |
266 |
|
else |
267 |
|
for(int i=2; i>=0; --i) { |
268 |
|
(*currentTriangle)[i] = (Edge::Pair)(currentCutEdge->first); |
269 |
|
++currentCutEdge; |
270 |
|
} |
271 |
|
|
272 |
|
for (size_t i=0; i<4; ++i) { |
273 |
|
verticesList[*cutEdges[i]] = new Vertex(__splitEdge(*cutEdges[i], ref, S)); |
274 |
|
} |
275 |
|
|
276 |
|
//! Addes a triangle to the list. |
277 |
|
localTriangleList.push_front(TinyVector<3,Edge::Pair>()); |
278 |
|
cellList.push_front(¤tCell); |
279 |
|
|
280 |
|
currentTriangle = localTriangleList.begin(); |
281 |
|
|
282 |
|
//! Sets the triangle vertices (actually just store the edge where it lives). |
283 |
|
currentCutEdge = cutEdgesMap.begin(); |
284 |
|
if (!swapEdge) |
285 |
|
for(int i=2; i>=0; --i) { |
286 |
|
++currentCutEdge; |
287 |
|
(*currentTriangle)[i] = (Edge::Pair)(currentCutEdge->first); |
288 |
|
} |
289 |
|
else |
290 |
|
for(size_t i=0; i<3; ++i) { |
291 |
|
++currentCutEdge; |
292 |
|
(*currentTriangle)[i] = (Edge::Pair)(currentCutEdge->first); |
293 |
|
} |
294 |
|
break; |
295 |
|
} |
296 |
|
case 1: |
297 |
|
case 2: { |
298 |
|
ffout(3) << "?!\n"; |
299 |
|
break; |
300 |
|
} |
301 |
|
} |
302 |
|
} |
303 |
|
|
304 |
|
|
305 |
|
for (EdgePairList::iterator t = localTriangleList.begin(); |
306 |
|
t != localTriangleList.end(); ++t) { |
307 |
|
size_t nbInside = 0; |
308 |
|
for (size_t k =0; k<3; ++k) { |
309 |
|
std::map<Edge::Pair, size_t>::iterator eRef |
310 |
|
= edgesRef.find((*t)[k]); |
311 |
|
if ((*eRef).second == 1) |
312 |
|
nbInside ++; |
313 |
|
} |
314 |
|
if (nbInside == 3) { |
315 |
|
ffout(3) << "yaduboulo\n"; |
316 |
|
triangleList.push_front(*t); |
317 |
|
} else { |
318 |
|
ffout(3) << "cava " << nbInside << '\n'; |
319 |
|
} |
320 |
|
} |
321 |
|
|
322 |
|
for (EdgePairList::iterator t = localTriangleList.begin(); |
323 |
|
t != localTriangleList.end(); ++t) { |
324 |
|
triangleList.push_front(*t); |
325 |
|
} |
326 |
|
|
327 |
|
localTriangleList.clear(); |
328 |
|
} |
329 |
|
} |
330 |
|
|
331 |
|
|
332 |
void |
void |
333 |
SurfaceMeshGenerator:: |
SurfaceMeshGenerator:: |
334 |
generatesAllSufaceMeshes(const Problem& problem, |
generatesAllSufaceMeshes(const Problem& problem, |
335 |
BoundaryConditionSurfaceMeshAssociation& bcMeshAssociation, |
BoundaryConditionSurfaceMeshAssociation& bcMeshAssociation, |
336 |
Mesh& M) |
Mesh& M) |
337 |
{ |
{ |
338 |
VRRefMesh vrRefMesh; |
Internals::VRRefMesh vrRefMesh; |
339 |
|
|
340 |
const Domain& Omega = problem.domain(); |
const Domain& Omega = problem.domain(); |
341 |
|
|
349 |
|
|
350 |
for (size_t j=0; j<bcSet.nbBoundaryCondition(); ++j) { |
for (size_t j=0; j<bcSet.nbBoundaryCondition(); ++j) { |
351 |
const Boundary& B = bcSet[j].boundary(); |
const Boundary& B = bcSet[j].boundary(); |
352 |
SurfaceMeshGenerator::setBoundaryType(B,povRefList,faces); |
(*__internals).__setBoundaryType(B,povRefList,faces); |
353 |
} |
} |
354 |
} |
} |
355 |
|
|
359 |
for (VariationalProblem::bilinearBorderOperatorConst_iterator i = VP.beginBilinearBorderOperator(); |
for (VariationalProblem::bilinearBorderOperatorConst_iterator i = VP.beginBilinearBorderOperator(); |
360 |
i != VP.endBilinearBorderOperator(); ++i) { |
i != VP.endBilinearBorderOperator(); ++i) { |
361 |
const Boundary& B = dynamic_cast<const Boundary&>((*(*i)).boundary()); |
const Boundary& B = dynamic_cast<const Boundary&>((*(*i)).boundary()); |
362 |
setBoundaryType(B,povRefList,faces); |
(*__internals).__setBoundaryType(B,povRefList,faces); |
363 |
} |
} |
364 |
|
|
365 |
for (VariationalProblem::linearBorderOperatorConst_iterator i = VP.beginLinearBorderOperator(); |
for (VariationalProblem::linearBorderOperatorConst_iterator i = VP.beginLinearBorderOperator(); |
366 |
i != VP.endLinearBorderOperator(); ++i) { |
i != VP.endLinearBorderOperator(); ++i) { |
367 |
const Boundary& B = dynamic_cast<const Boundary&>((*(*i)).boundary()); |
const Boundary& B = dynamic_cast<const Boundary&>((*(*i)).boundary()); |
368 |
setBoundaryType(B,povRefList,faces); |
(*__internals).__setBoundaryType(B,povRefList,faces); |
369 |
} |
} |
370 |
} |
} |
371 |
|
|
372 |
|
dynamic_cast<Structured3DMesh&>(M).createReferences(Omega); |
373 |
|
|
374 |
const Scene& S =Omega.scene(); |
const Scene& S =Omega.scene(); |
375 |
|
|
376 |
|
std::set<Reference::Representation> referencesList; |
377 |
for(POVRayReferences::iterator povRef = povRefList.begin(); |
for(POVRayReferences::iterator povRef = povRefList.begin(); |
378 |
povRef!= povRefList.end(); ++povRef) { |
povRef!= povRefList.end(); ++povRef) { |
379 |
|
Reference::Representation ref; |
380 |
|
ref.resize(S.nbObjects()); |
381 |
for (size_t i=0; i<S.nbObjects(); ++i) { |
for (size_t i=0; i<S.nbObjects(); ++i) { |
382 |
const Object& O = S.object(i); |
const Object& O = S.object(i); |
383 |
if (O.reference() == povRef->first) { |
if (O.reference() == povRef->first) { |
|
dynamic_cast<Structured3DMesh&>(M).createReferences(Omega); |
|
384 |
dynamic_cast<Structured3DMesh&>(M).createReferences(Omega,O.reference()); |
dynamic_cast<Structured3DMesh&>(M).createReferences(Omega,O.reference()); |
385 |
|
} |
386 |
|
} |
387 |
|
referencesList.insert(ref); |
388 |
|
} |
389 |
|
|
390 |
|
for(POVRayReferences::iterator povRef = povRefList.begin(); |
391 |
|
povRef!= povRefList.end(); ++povRef) { |
392 |
|
for (size_t i=0; i<S.nbObjects(); ++i) { |
393 |
|
const Object& O = S.object(i); |
394 |
|
if (O.reference() == povRef->first) { |
395 |
|
|
396 |
SurfaceMeshOfTriangles* surfMesh |
SurfaceMeshOfTriangles* surfMesh |
397 |
= new SurfaceMeshOfTriangles; |
= new SurfaceMeshOfTriangles; |
402 |
ref[i] = true; |
ref[i] = true; |
403 |
|
|
404 |
this->generateSurfacicMesh(*(O.shape()), |
this->generateSurfacicMesh(*(O.shape()), |
405 |
|
Omega, |
406 |
*surfMesh, |
*surfMesh, |
407 |
dynamic_cast<Structured3DMesh&>(M), |
dynamic_cast<Structured3DMesh&>(M), |
408 |
ref); |
ref, |
409 |
|
referencesList); |
410 |
|
|
411 |
vrRefMesh[povRef->first].push_back(surfMesh); |
vrRefMesh[povRef->first].push_back(surfMesh); |
412 |
} |
} |
539 |
} |
} |
540 |
} |
} |
541 |
|
|
|
void |
|
|
SurfaceMeshGenerator:: |
|
|
setBoundaryType(const Boundary& B, |
|
|
POVRayReferences& vrRefList, |
|
|
TinyVector<6,bool>& faces) |
|
|
{ |
|
|
switch (B.type()) { |
|
|
case (Boundary::povRay): { |
|
|
const BoundaryPOVRay& bp = dynamic_cast<const BoundaryPOVRay&>(B); |
|
|
for (size_t l=0; l<bp.nbPOVRef(); ++l) |
|
|
vrRefList[bp.POVRef(l)]++; |
|
|
break; |
|
|
} |
|
|
case (Boundary::structured3DMesh): { |
|
|
const BoundaryStructured3DMesh& bs |
|
|
= dynamic_cast<const BoundaryStructured3DMesh&>(B); |
|
|
for (size_t l=0; l<6; ++l) |
|
|
faces[l] = faces[l] || bs.structMesh(l); |
|
|
break; |
|
|
} |
|
|
case (Boundary::surfaceMesh): { |
|
|
//! Nothing to do. |
|
|
break; |
|
|
} |
|
|
default: { |
|
|
fferr(0) << '\n' << __FILE__ << ':' << __LINE__ << ": Not implemented\n"; |
|
|
std::exit(1); |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
TinyVector<3, real_t> |
|
|
SurfaceMeshGenerator:: |
|
|
__splitEdge(const Edge& e, |
|
|
const Reference::Representation& ref, |
|
|
const Shape& S) |
|
|
{ |
|
|
int in = -1; // number of the vertex inside |
|
|
int out = -1; // same thing for outside |
|
|
|
|
|
for (int j=0; j<2; j++) { |
|
|
if (!e(j).Ref().isSet(ref)) { |
|
|
out = j; |
|
|
} else { |
|
|
in = j; |
|
|
} |
|
|
} |
|
|
|
|
|
assert((in != -1)&&(out != -1)); |
|
|
|
|
|
TinyVector<3> vi = e(in); |
|
|
TinyVector<3> vo = e(out); |
|
|
TinyVector<3> vs = (vi+vo)/2; |
|
|
|
|
|
for (int l = 0; l<5; l++) { // 3% error after 5 iterations. |
|
|
if(S.inside(vs)) { |
|
|
vi = vs; |
|
|
vs = (vo+vi)/2; |
|
|
} else { |
|
|
vo = vs; |
|
|
vs = (vo+vi)/2; |
|
|
} |
|
|
} |
|
|
|
|
|
return vs; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
542 |
#warning REMOVE THIS NOW ! |
#warning REMOVE THIS NOW ! |
543 |
void plot(const SurfaceMeshOfTriangles& s, |
void plot(const SurfaceMeshOfTriangles& s, |
544 |
std::set<const Cell*>& hlist, |
std::set<const Cell*>& hlist, |
548 |
Structured3DMesh& SMesh); |
Structured3DMesh& SMesh); |
549 |
|
|
550 |
|
|
551 |
|
|
552 |
/*! Generates a surfacic mesh using only characteristic function of an object |
/*! Generates a surfacic mesh using only characteristic function of an object |
553 |
and the Structured 3D Mesh. |
and the Structured 3D Mesh. |
554 |
|
|
557 |
void |
void |
558 |
SurfaceMeshGenerator:: |
SurfaceMeshGenerator:: |
559 |
generateSurfacicMesh(const Shape& S, |
generateSurfacicMesh(const Shape& S, |
560 |
|
const Domain& Omega, |
561 |
SurfaceMeshOfTriangles& s_mesh, |
SurfaceMeshOfTriangles& s_mesh, |
562 |
Structured3DMesh& SMesh, |
Structured3DMesh& SMesh, |
563 |
const Reference::Representation& ref) |
const Reference::Representation& ref, |
564 |
|
const std::set<Reference::Representation>& referencesList) |
565 |
{ |
{ |
|
//! This list is used to provide an orientation to the Surfacic Elements. |
|
|
std::list<TinyVector<3> > InsideVertexList; |
|
|
|
|
|
//! list of cut edges and intersection vertex. |
|
|
std::map<Edge::Pair, Vertex*> verticesList; |
|
|
|
|
|
//! list of cut edges and intersection vertex. |
|
|
std::map<Edge::Pair, size_t> edgesRef; |
|
|
|
|
|
/** |
|
|
* This contains the generate triangles |
|
|
* They just point on verticesList elements |
|
|
*/ |
|
|
typedef std::list<TinyVector<3,Edge::Pair> > EdgePairList; |
|
|
typedef std::list<const Cell*> MotherCellList; |
|
|
EdgePairList triangleList; |
|
|
EdgePairList localTriangleList; |
|
|
MotherCellList cellList; |
|
|
|
|
566 |
for (size_t i = 0; i<SMesh.nbEdges(); i++) { |
for (size_t i = 0; i<SMesh.nbEdges(); i++) { |
567 |
Edge& e = SMesh.edge(i); |
Edge& e = SMesh.edge(i); |
568 |
#warning THIS TEST IS NOT ENOUGH! THINK TO THE BORDER! |
#warning THIS TEST IS NOT ENOUGH! THINK TO THE BORDER! |
569 |
if((e(0).Ref().insideDomain() xor e(1).Ref().insideDomain()) |
if((e(0).Ref().insideDomain() xor e(1).Ref().insideDomain()) |
570 |
and ((e(0).Ref().isSet(ref)) xor (e(1).Ref().isSet(ref)))) |
and ((e(0).Ref().isSet(ref)) xor (e(1).Ref().isSet(ref)))) |
571 |
{ |
{ |
572 |
verticesList[e] = new Vertex(__splitEdge(e, ref, S)); |
(*__internals).verticesList[e] = new Vertex((*__internals).__splitEdge(e, ref, S)); |
573 |
edgesRef[e] = 1; |
(*__internals).edgesRef[e] = 1; |
574 |
} |
} |
575 |
} |
} |
576 |
|
|
580 |
/// a triangulation has been generated inside the hexahedron |
/// a triangulation has been generated inside the hexahedron |
581 |
std::set<const Cell*> meshedHexahedra; |
std::set<const Cell*> meshedHexahedra; |
582 |
|
|
583 |
if (verticesList.size()==0) { |
if ((*__internals).verticesList.size()==0) { |
584 |
fferr(2) << __FILE__ << ':' << __LINE__ << ": " |
fferr(2) << __FILE__ << ':' << __LINE__ << ": " |
585 |
<< "meshing object " << S << " a problem occured ...\n" |
<< "meshing object " << S << " a problem occured ...\n" |
586 |
<< "Check that:\n" |
<< "Check that:\n" |
589 |
std::exit(1); |
std::exit(1); |
590 |
} |
} |
591 |
|
|
|
typedef std::map<const Cell*, |
|
|
std::pair<ReferenceCounting<std::vector<TetrahedronByEdges> >, |
|
|
ReferenceCounting<std::vector<Edge> > > > |
|
|
HexaTetraAssociation; |
|
|
|
|
|
HexaTetraAssociation hexaTetraAssociation; |
|
|
|
|
592 |
for (size_t icell=0; icell<SMesh.shape().nx()-1; ++icell) |
for (size_t icell=0; icell<SMesh.shape().nx()-1; ++icell) |
593 |
for (size_t jcell=0; jcell<SMesh.shape().ny()-1; ++jcell) |
for (size_t jcell=0; jcell<SMesh.shape().ny()-1; ++jcell) |
594 |
for (size_t kcell=0; kcell<SMesh.shape().nz()-1; ++kcell) { |
for (size_t kcell=0; kcell<SMesh.shape().nz()-1; ++kcell) { |
623 |
|
|
624 |
for (size_t l=0; l<H.numberOfEdges(); l++) { |
for (size_t l=0; l<H.numberOfEdges(); l++) { |
625 |
Edge& e = H.edge(l); |
Edge& e = H.edge(l); |
626 |
if (verticesList.count(e) > 0) { |
if ((*__internals).verticesList.count(e) > 0) { |
627 |
intersected = true; |
intersected = true; |
628 |
cuttedHexahedra.insert(¤tCell); |
cuttedHexahedra.insert(¤tCell); |
629 |
break; |
break; |
669 |
if (((e(0).Ref().isSet(ref)) xor (e(1).Ref().isSet(ref))) |
if (((e(0).Ref().isSet(ref)) xor (e(1).Ref().isSet(ref))) |
670 |
and (e(0).Ref().insideDomain() xor e(1).Ref().insideDomain())) { |
and (e(0).Ref().insideDomain() xor e(1).Ref().insideDomain())) { |
671 |
e.Ref() = 1; |
e.Ref() = 1; |
672 |
edgesRef[e] = 1; |
(*__internals).edgesRef[e] = 1; |
673 |
} |
} |
674 |
currentAddedEdge++; |
currentAddedEdge++; |
675 |
} |
} |
761 |
|
|
762 |
for(size_t ie=0; ie<6; ++ie) { |
for(size_t ie=0; ie<6; ++ie) { |
763 |
const Edge& e = currentT->edge(ie); |
const Edge& e = currentT->edge(ie); |
764 |
if (edgesRef.find(e) != edgesRef.end()) |
if ((*__internals).edgesRef.find(e) != (*__internals).edgesRef.end()) |
765 |
cutEdges.push_back(&e); |
cutEdges.push_back(&e); |
766 |
} |
} |
767 |
|
|
768 |
switch (cutEdges.size()) { |
switch (cutEdges.size()) { |
769 |
case 3: { |
case 3: { |
770 |
//! Addes a triangle to the list. |
//! Addes a triangle to the list. |
771 |
localTriangleList.push_front(TinyVector<3,Edge::Pair>()); |
(*__internals).localTriangleList.push_front(TinyVector<3,Edge::Pair>()); |
772 |
cellList.push_front(¤tCell); |
(*__internals).cellList.push_front(¤tCell); |
773 |
|
|
774 |
std::vector<TinyVector<3> > V(cutEdges.size()); |
std::vector<TinyVector<3> > V(cutEdges.size()); |
775 |
for(size_t i=0; i<cutEdges.size(); ++i) { |
for(size_t i=0; i<cutEdges.size(); ++i) { |
784 |
std::swap(cutEdges[1], cutEdges[2]); |
std::swap(cutEdges[1], cutEdges[2]); |
785 |
|
|
786 |
//! Sets the triangle vertices (actually just store the edge where it lives). |
//! Sets the triangle vertices (actually just store the edge where it lives). |
787 |
EdgePairList::iterator currentTriangle = localTriangleList.begin(); |
SurfaceMeshGenerator::Internals::EdgePairList::iterator currentTriangle |
788 |
|
= (*__internals).localTriangleList.begin(); |
789 |
|
|
790 |
for(size_t i=0; i<cutEdges.size(); ++i) |
for(size_t i=0; i<cutEdges.size(); ++i) |
791 |
(*currentTriangle)[i] = (Edge::Pair)(*cutEdges[i]); |
(*currentTriangle)[i] = (Edge::Pair)(*cutEdges[i]); |
792 |
|
|
793 |
//! Stores the Edges on which the vertex will be computed. |
//! Stores the Edges on which the vertex will be computed. |
794 |
for (size_t i=0; i<cutEdges.size(); ++i) { |
for (size_t i=0; i<cutEdges.size(); ++i) { |
795 |
verticesList[*cutEdges[i]] = new Vertex(__splitEdge(*cutEdges[i], ref, S)); |
(*__internals).verticesList[*cutEdges[i]] |
796 |
edgesRef[*cutEdges[i]] = 1; |
= new Vertex((*__internals).__splitEdge(*cutEdges[i], ref, S)); |
797 |
|
(*__internals).edgesRef[*cutEdges[i]] = 1; |
798 |
} |
} |
799 |
break; |
break; |
800 |
} |
} |
805 |
cutEdgesMap[(Edge::Pair)*(cutEdges[ie])] = (cutEdges[ie]); |
cutEdgesMap[(Edge::Pair)*(cutEdges[ie])] = (cutEdges[ie]); |
806 |
|
|
807 |
//! Addes a triangle to the list. |
//! Addes a triangle to the list. |
808 |
localTriangleList.push_front(TinyVector<3,Edge::Pair>()); |
(*__internals).localTriangleList.push_front(TinyVector<3,Edge::Pair>()); |
809 |
cellList.push_front(¤tCell); |
(*__internals).cellList.push_front(¤tCell); |
810 |
|
|
811 |
std::vector<TinyVector<3> > V(cutEdges.size()); |
std::vector<TinyVector<3> > V(cutEdges.size()); |
812 |
std::map<Edge::Pair, const Edge*>::iterator currentCutEdge=cutEdgesMap.begin(); |
std::map<Edge::Pair, const Edge*>::iterator currentCutEdge=cutEdgesMap.begin(); |
822 |
bool swapEdge = ((V[0]^V[1])*V[2] > 0); |
bool swapEdge = ((V[0]^V[1])*V[2] > 0); |
823 |
|
|
824 |
//! Sets the triangle vertices (actually just store the edge where it lives). |
//! Sets the triangle vertices (actually just store the edge where it lives). |
825 |
EdgePairList::iterator currentTriangle = localTriangleList.begin(); |
SurfaceMeshGenerator::Internals::EdgePairList::iterator currentTriangle |
826 |
|
= (*__internals).localTriangleList.begin(); |
827 |
|
|
828 |
currentCutEdge = cutEdgesMap.begin(); |
currentCutEdge = cutEdgesMap.begin(); |
829 |
if (!swapEdge) |
if (!swapEdge) |
838 |
} |
} |
839 |
|
|
840 |
for (size_t i=0; i<4; ++i) { |
for (size_t i=0; i<4; ++i) { |
841 |
verticesList[*cutEdges[i]] = new Vertex(__splitEdge(*cutEdges[i], ref, S)); |
(*__internals).verticesList[*cutEdges[i]] |
842 |
edgesRef[*cutEdges[i]] = 1; |
= new Vertex((*__internals).__splitEdge(*cutEdges[i], ref, S)); |
843 |
|
(*__internals).edgesRef[*cutEdges[i]] = 1; |
844 |
} |
} |
845 |
|
|
846 |
//! Addes a triangle to the list. |
//! Addes a triangle to the list. |
847 |
localTriangleList.push_front(TinyVector<3,Edge::Pair>()); |
(*__internals).localTriangleList.push_front(TinyVector<3,Edge::Pair>()); |
848 |
cellList.push_front(¤tCell); |
(*__internals).cellList.push_front(¤tCell); |
849 |
|
|
850 |
currentTriangle = localTriangleList.begin(); |
currentTriangle = (*__internals).localTriangleList.begin(); |
851 |
|
|
852 |
//! Sets the triangle vertices (actually just store the edge where it lives). |
//! Sets the triangle vertices (actually just store the edge where it lives). |
853 |
currentCutEdge = cutEdgesMap.begin(); |
currentCutEdge = cutEdgesMap.begin(); |
873 |
|
|
874 |
if(jobDone) { |
if(jobDone) { |
875 |
meshedHexahedra.insert(¤tCell); |
meshedHexahedra.insert(¤tCell); |
876 |
for (EdgePairList::iterator t = localTriangleList.begin(); |
for (SurfaceMeshGenerator::Internals::EdgePairList::iterator t |
877 |
t != localTriangleList.end(); ++t) { |
= (*__internals).localTriangleList.begin(); |
878 |
triangleList.push_front(*t); |
t != (*__internals).localTriangleList.end(); ++t) { |
879 |
|
(*__internals).triangleList.push_front(*t); |
880 |
} |
} |
881 |
} else { |
} else { |
882 |
hexaTetraAssociation[¤tCell] |
(*__internals).hexaTetraAssociation[¤tCell] |
883 |
= std::pair<ReferenceCounting<std::vector<TetrahedronByEdges> >, |
= std::pair<ReferenceCounting<std::vector<TetrahedronByEdges> >, |
884 |
ReferenceCounting<std::vector<Edge> > > |
ReferenceCounting<std::vector<Edge> > > |
885 |
(pT,pAddedEdges); |
(pT,pAddedEdges); |
886 |
} |
} |
887 |
|
|
888 |
localTriangleList.clear(); |
(*__internals).localTriangleList.clear(); |
889 |
} |
} |
890 |
} |
} |
891 |
|
|
892 |
// triangleList.clear(); |
(*__internals).triangleList.clear(); |
893 |
// verticesList.clear(); |
(*__internals).verticesList.clear(); |
894 |
|
|
895 |
|
|
896 |
// for(HexaTetraAssociation::iterator i = hexaTetraAssociation.begin(); |
(*__internals).__createTriangles(S, ref); |
|
// i != hexaTetraAssociation.end(); ++i) { |
|
|
|
|
|
// const CartesianHexahedron& currentCell |
|
|
// = static_cast<const CartesianHexahedron&>(*(*i).first); |
|
|
// std::vector<TetrahedronByEdges>& T = *(((*i).second).first); |
|
|
|
|
|
// for (std::vector<TetrahedronByEdges>::iterator currentT = T.begin(); |
|
|
// currentT < T.end(); ++currentT) { |
|
|
// std::vector<const Edge*> cutEdges; |
|
|
|
|
|
// for(size_t ie=0; ie<6; ++ie) { |
|
|
// const Edge& e = currentT->edge(ie); |
|
|
// if ((e(0).Ref().isSet(ref)) xor (e(1).Ref().isSet(ref))) { |
|
|
// cutEdges.push_back(&e); |
|
|
// } |
|
|
// } |
|
|
|
|
|
// switch (cutEdges.size()) { |
|
|
// case 3: { |
|
|
// std::vector<TinyVector<3> > V(cutEdges.size()); |
|
|
// for(size_t i=0; i<cutEdges.size(); ++i) { |
|
|
// const Edge& e = *cutEdges[i]; |
|
|
// if(e(0).Ref().isSet(ref)) |
|
|
// V[i] = (e(0).Vector3() - e(1).Vector3()); |
|
|
// else |
|
|
// V[i] = (e(1).Vector3() - e(0).Vector3()); |
|
|
// } |
|
|
|
|
|
// if ((V[0]^V[1])*V[2] < 0) |
|
|
// std::swap(cutEdges[1], cutEdges[2]); |
|
|
|
|
|
// //! Addes a triangle to the list. |
|
|
// localTriangleList.push_front(TinyVector<3,Edge::Pair>()); |
|
|
// cellList.push_front(¤tCell); |
|
|
|
|
|
// //! Sets the triangle vertices (actually just store the edge where it lives). |
|
|
// EdgePairList::iterator currentTriangle = localTriangleList.begin(); |
|
|
// for(size_t i=0; i<cutEdges.size(); ++i) |
|
|
// (*currentTriangle)[i] = (Edge::Pair)(*cutEdges[i]); |
|
|
|
|
|
// //! Stores the Edges on which the vertex will be computed. |
|
|
// for (size_t i=0; i<cutEdges.size(); ++i) |
|
|
// verticesList[*cutEdges[i]] = new Vertex(__splitEdge(*cutEdges[i], ref, S)); |
|
|
// break; |
|
|
// } |
|
|
// case 4: { |
|
|
// //! Orders the Edges using a map ! |
|
|
// std::map<Edge::Pair, const Edge*> cutEdgesMap; |
|
|
// for(size_t ie=0; ie<cutEdges.size(); ++ie) |
|
|
// cutEdgesMap[(Edge::Pair)*(cutEdges[ie])] = (cutEdges[ie]); |
|
|
|
|
|
// //! Addes a triangle to the list. |
|
|
// localTriangleList.push_front(TinyVector<3,Edge::Pair>()); |
|
|
// cellList.push_front(¤tCell); |
|
|
|
|
|
// std::vector<TinyVector<3> > V(cutEdges.size()); |
|
|
// std::map<Edge::Pair, const Edge*>::iterator currentCutEdge=cutEdgesMap.begin(); |
|
|
// for (size_t i=0; i<V.size(); ++i) { |
|
|
// const Edge& e = *(*currentCutEdge).second; |
|
|
// if(e(0).Ref().isSet(ref)) |
|
|
// V[i] = (e(0).Vector3() - e(1).Vector3()); |
|
|
// else |
|
|
// V[i] = (e(1).Vector3() - e(0).Vector3()); |
|
|
// ++currentCutEdge; |
|
|
// } |
|
|
|
|
|
// bool swapEdge = ((V[0]^V[1])*V[2] > 0); |
|
|
|
|
|
// //! Sets the triangle vertices (actually just store the edge where it lives). |
|
|
// EdgePairList::iterator currentTriangle = localTriangleList.begin(); |
|
|
|
|
|
// currentCutEdge = cutEdgesMap.begin(); |
|
|
// if (!swapEdge) |
|
|
// for(size_t i=0; i<3; ++i) { |
|
|
// (*currentTriangle)[i] = (Edge::Pair)(currentCutEdge->first); |
|
|
// ++currentCutEdge; |
|
|
// } |
|
|
// else |
|
|
// for(int i=2; i>=0; --i) { |
|
|
// (*currentTriangle)[i] = (Edge::Pair)(currentCutEdge->first); |
|
|
// ++currentCutEdge; |
|
|
// } |
|
|
|
|
|
// for (size_t i=0; i<4; ++i) { |
|
|
// verticesList[*cutEdges[i]] = new Vertex(__splitEdge(*cutEdges[i], ref, S)); |
|
|
// } |
|
|
|
|
|
// //! Addes a triangle to the list. |
|
|
// localTriangleList.push_front(TinyVector<3,Edge::Pair>()); |
|
|
// cellList.push_front(¤tCell); |
|
|
|
|
|
// currentTriangle = localTriangleList.begin(); |
|
|
|
|
|
// //! Sets the triangle vertices (actually just store the edge where it lives). |
|
|
// currentCutEdge = cutEdgesMap.begin(); |
|
|
// if (!swapEdge) |
|
|
// for(int i=2; i>=0; --i) { |
|
|
// ++currentCutEdge; |
|
|
// (*currentTriangle)[i] = (Edge::Pair)(currentCutEdge->first); |
|
|
// } |
|
|
// else |
|
|
// for(size_t i=0; i<3; ++i) { |
|
|
// ++currentCutEdge; |
|
|
// (*currentTriangle)[i] = (Edge::Pair)(currentCutEdge->first); |
|
|
// } |
|
|
// break; |
|
|
// } |
|
|
// case 1: |
|
|
// case 2: { |
|
|
// ffout(3) << "?!\n"; |
|
|
// break; |
|
|
// } |
|
|
// } |
|
|
// } |
|
|
|
|
|
|
|
|
// for (EdgePairList::iterator t = localTriangleList.begin(); |
|
|
// t != localTriangleList.end(); ++t) { |
|
|
// size_t nbInside = 0; |
|
|
// for (size_t k =0; k<3; ++k) { |
|
|
// std::map<Edge::Pair, size_t>::iterator eRef |
|
|
// = edgesRef.find((*t)[k]); |
|
|
// if ((*eRef).second == 1) |
|
|
// nbInside ++; |
|
|
// } |
|
|
// if (nbInside == 3) { |
|
|
// ffout(3) << "yaduboulo\n"; |
|
|
// triangleList.push_front(*t); |
|
|
// } else { |
|
|
// ffout(3) << "cava " << nbInside << '\n'; |
|
|
// } |
|
|
// } |
|
|
|
|
|
// for (EdgePairList::iterator t = localTriangleList.begin(); |
|
|
// t != localTriangleList.end(); ++t) { |
|
|
// triangleList.push_front(*t); |
|
|
// } |
|
|
|
|
|
// localTriangleList.clear(); |
|
|
// } |
|
897 |
|
|
898 |
|
|
899 |
s_mesh.setNumberOfVertices(verticesList.size()); |
s_mesh.setNumberOfVertices((*__internals).verticesList.size()); |
900 |
s_mesh.setNumberOfCells(triangleList.size()); |
s_mesh.setNumberOfCells((*__internals).triangleList.size()); |
901 |
|
|
902 |
//! copies vertices into the s_mesh. |
//! copies vertices into the s_mesh. |
903 |
int i = 0; |
int i = 0; |
904 |
for(std::map<Edge::Pair, Vertex*>::iterator splitVertex |
for(SurfaceMeshGenerator::Internals::VerticesList::iterator splitVertex |
905 |
= verticesList.begin(); |
= (*__internals).verticesList.begin(); |
906 |
splitVertex != verticesList.end(); ++splitVertex) { |
splitVertex != (*__internals).verticesList.end(); ++splitVertex) { |
907 |
|
|
908 |
s_mesh.vertex(i) = (*(*splitVertex).second); |
s_mesh.vertex(i) = (*(*splitVertex).second); |
909 |
delete (*splitVertex).second; |
delete (*splitVertex).second; |
916 |
meshedHexahedra.begin(), meshedHexahedra.end(), |
meshedHexahedra.begin(), meshedHexahedra.end(), |
917 |
inserter(toTreatHexahedra, toTreatHexahedra.begin())); |
inserter(toTreatHexahedra, toTreatHexahedra.begin())); |
918 |
|
|
|
|
|
919 |
i = 0; |
i = 0; |
|
MotherCellList::iterator motherCell = cellList.begin(); |
|
920 |
|
|
921 |
for(EdgePairList::iterator currentTriangle = triangleList.begin(); |
SurfaceMeshGenerator::Internals::MotherCellList::iterator motherCell |
922 |
currentTriangle != triangleList.end(); ++currentTriangle) { |
= (*__internals).cellList.begin(); |
923 |
Vertex& V0 = *(verticesList[(*currentTriangle)[0]]); |
|
924 |
Vertex& V1 = *(verticesList[(*currentTriangle)[1]]); |
for(SurfaceMeshGenerator::Internals::EdgePairList::iterator currentTriangle |
925 |
Vertex& V2 = *(verticesList[(*currentTriangle)[2]]); |
= (*__internals).triangleList.begin(); |
926 |
|
currentTriangle != (*__internals).triangleList.end(); |
927 |
|
++currentTriangle) { |
928 |
|
Vertex& V0 = *((*__internals).verticesList[(*currentTriangle)[0]]); |
929 |
|
Vertex& V1 = *((*__internals).verticesList[(*currentTriangle)[1]]); |
930 |
|
Vertex& V2 = *((*__internals).verticesList[(*currentTriangle)[2]]); |
931 |
|
|
932 |
s_mesh.cell(i) = Triangle(V0,V1,V2); |
s_mesh.cell(i) = Triangle(V0,V1,V2); |
933 |
#warning SHOULD USE BC NUMBER (ie OBJECT NUMBER IN SCENE INSTEAD) |
#warning SHOULD USE BC NUMBER (ie OBJECT NUMBER IN SCENE INSTEAD) |
945 |
|
|
946 |
|
|
947 |
|
|
948 |
|
SurfaceMeshGenerator::SurfaceMeshGenerator() |
949 |
|
: __internals(new SurfaceMeshGenerator::Internals()) |
950 |
|
{ |
951 |
|
; |
952 |
|
} |
953 |
|
|
954 |
|
SurfaceMeshGenerator::~SurfaceMeshGenerator() |
955 |
|
{ |
956 |
|
; |
957 |
|
} |
958 |
|
|
959 |
|
|
960 |
// #include <vtkPolyDataMapper.h> |
// #include <vtkPolyDataMapper.h> |
961 |
// #include <vtkRenderWindow.h> |
// #include <vtkRenderWindow.h> |
962 |
// #include <vtkRenderWindowInteractor.h> |
// #include <vtkRenderWindowInteractor.h> |
1120 |
// // coneActor->Delete(); |
// // coneActor->Delete(); |
1121 |
// // ren1->Delete(); |
// // ren1->Delete(); |
1122 |
// } |
// } |
|
|
|