40 bool Foam::orientedSurface::edgeOrder
48 (f[0] == e[0] && f[1] == e[1])
49 || (f[1] == e[0] && f[2] == e[1])
50 || (f[2] == e[0] && f[0] == e[1])
63 bool Foam::orientedSurface::consistentEdge
66 const labelledTri& f0,
70 return edgeOrder(f0, e) ^ edgeOrder(f1, e);
80 labelList changedEdges(3*changedFaces.size());
85 const labelList& fEdges = s.faceEdges()[changedFaces[i]];
89 changedEdges[changedI++] = fEdges[j];
92 changedEdges.setSize(changedI);
105 labelList changedFaces(2*changedEdges.size());
110 label edgeI = changedEdges[i];
112 const labelList& eFaces = s.edgeFaces()[edgeI];
114 if (eFaces.size() < 2)
118 else if (eFaces.size() == 2)
120 label face0 = eFaces[0];
121 label face1 = eFaces[1];
123 const labelledTri& f0 = s.localFaces()[face0];
124 const labelledTri& f1 = s.localFaces()[face1];
126 if (flip[face0] == UNVISITED)
128 if (flip[face1] == UNVISITED)
130 FatalErrorIn(
"orientedSurface::edgeToFace") <<
"Problem"
136 if (consistentEdge(s.edges()[edgeI], f0, f1))
139 flip[face0] = (flip[face1] == FLIP ? FLIP : NOFLIP);
144 flip[face0] = (flip[face1] == FLIP ? NOFLIP : FLIP);
146 changedFaces[changedI++] = face0;
151 if (flip[face1] == UNVISITED)
154 if (consistentEdge(s.edges()[edgeI], f0, f1))
156 flip[face1] = (flip[face0] == FLIP ? FLIP : NOFLIP);
160 flip[face1] = (flip[face0] == FLIP ? NOFLIP : FLIP);
162 changedFaces[changedI++] = face1;
171 changedFaces.setSize(changedI);
177 void Foam::orientedSurface::walkSurface
180 const label startFaceI,
191 changedEdges = faceToEdge(s, changedFaces);
195 Pout<<
"From changedFaces:" << changedFaces.size()
196 <<
" to changedEdges:" << changedEdges.size()
200 if (changedEdges.empty())
205 changedFaces = edgeToFace(s, changedEdges, flipState);
209 Pout<<
"From changedEdges:" << changedEdges.size()
210 <<
" to changedFaces:" << changedFaces.size()
214 if (changedFaces.empty())
222 void Foam::orientedSurface::propagateOrientation
225 const point& samplePoint,
226 const bool orientOutside,
227 const label nearestFaceI,
228 const point& nearestPt,
248 flipState[nearestFaceI] = NOFLIP;
254 flipState[nearestFaceI] = NOFLIP;
259 flipState[nearestFaceI] = FLIP;
266 Pout<<
"orientedSurface::propagateOrientation : starting face"
267 <<
" orientation:" <<
nl
268 <<
" for samplePoint:" << samplePoint <<
nl
269 <<
" starting from point:" << nearestPt <<
nl
270 <<
" on face:" << nearestFaceI <<
nl
271 <<
" with normal:" << n <<
nl
272 <<
" decided side:" << label(side)
277 walkSurface(s, nearestFaceI, flipState);
281 bool Foam::orientedSurface::flipSurface
287 bool hasFlipped =
false;
292 if (flipState[faceI] == UNVISITED)
296 "orientSurface(const point&, const label, const point&)"
297 ) <<
"unvisited face " << faceI
300 else if (flipState[faceI] == FLIP)
302 labelledTri& tri = s[faceI];
332 const point& samplePoint,
333 const bool orientOutside
338 orient(*
this, samplePoint, orientOutside);
346 const bool orientOutside
354 point outsidePoint = bb.
max() + bb.span();
356 orient(*
this, outsidePoint, orientOutside);
365 const point& samplePoint,
366 const bool orientOutside
369 bool anyFlipped =
false;
382 flipState[0] = NOFLIP;
383 walkSurface(s, 0, flipState);
385 anyFlipped = flipSurface(s, flipState);
400 scalar minDist = GREAT;
406 if (flipState[faceI] == UNVISITED)
416 ).nearestPoint(samplePoint);
447 bool geomFlipped = flipSurface(s, flipState);
449 return anyFlipped || geomFlipped;