44 bool Foam::orientedSurface::consistentEdge
47 const triSurface::FaceType& f0,
48 const triSurface::FaceType& f1
51 return (f0.edgeDirection(
e) > 0) ^ (f1.edgeDirection(
e) > 0);
61 labelList changedEdges(3*changedFaces.size());
66 const labelList& fEdges =
s.faceEdges()[changedFaces[i]];
70 changedEdges[changedI++] = fEdges[j];
73 changedEdges.setSize(changedI);
86 labelList changedFaces(2*changedEdges.size());
91 label edgeI = changedEdges[i];
93 const labelList& eFaces =
s.edgeFaces()[edgeI];
95 if (eFaces.size() < 2)
99 else if (eFaces.size() == 2)
101 label face0 = eFaces[0];
102 label face1 = eFaces[1];
107 if (flip[face0] == UNVISITED)
109 if (flip[face1] == UNVISITED)
117 if (consistentEdge(
s.edges()[edgeI], f0, f1))
120 flip[face0] = (flip[face1] == FLIP ? FLIP : NOFLIP);
125 flip[face0] = (flip[face1] == FLIP ? NOFLIP : FLIP);
127 changedFaces[changedI++] = face0;
132 if (flip[face1] == UNVISITED)
135 if (consistentEdge(
s.edges()[edgeI], f0, f1))
137 flip[face1] = (flip[face0] == FLIP ? FLIP : NOFLIP);
141 flip[face1] = (flip[face0] == FLIP ? NOFLIP : FLIP);
143 changedFaces[changedI++] = face1;
152 changedFaces.setSize(changedI);
158 void Foam::orientedSurface::walkSurface
161 const label startFacei,
172 changedEdges = faceToEdge(
s, changedFaces);
174 if (changedEdges.empty())
179 changedFaces = edgeToFace(
s, changedEdges, flipState);
181 if (changedFaces.empty())
189 void Foam::orientedSurface::propagateOrientation
192 const point& samplePoint,
193 const bool orientOutside,
194 const label nearestFacei,
195 const point& nearestPt,
213 flipState[nearestFacei] = NOFLIP;
219 flipState[nearestFacei] = NOFLIP;
224 flipState[nearestFacei] = FLIP;
231 Pout<<
"orientedSurface::propagateOrientation : starting face"
232 <<
" orientation:" <<
nl
233 <<
" for samplePoint:" << samplePoint <<
nl
234 <<
" starting from point:" << nearestPt <<
nl
235 <<
" on face:" << nearestFacei <<
nl
236 <<
" with normal:" <<
n <<
nl
237 <<
" decided side:" <<
label(side)
242 walkSurface(
s, nearestFacei, flipState);
248 void Foam::orientedSurface::findZoneSide
250 const triSurfaceSearch& surfSearches,
253 const point& outsidePoint,
258 const triSurface&
s = surfSearches.surface();
264 List<List<pointIndexHit>> hits(1, List<pointIndexHit>());
268 if (faceZone[facei] == zoneI)
270 const point& fc =
s.faceCentres()[facei];
271 const vector&
n =
s.faceNormals()[facei];
273 const vector d = fc - outsidePoint;
274 const scalar magD =
mag(d);
277 if (magD > SMALL && (
mag(
n & d/magD) > 1
e-6))
288 surfSearches.findLineAll(
start,
end, hits);
290 label zoneIndex = -1;
293 if (hits[0][i].index() == facei)
304 if ((zoneIndex%2) == 0)
308 isOutside = ((
n & d) < 0);
312 isOutside = ((
n & d) > 0);
322 bool Foam::orientedSurface::flipSurface
328 bool hasFlipped =
false;
333 if (flipState[facei] == UNVISITED)
336 <<
"unvisited face " << facei
339 else if (flipState[facei] == FLIP)
341 labelledTri& tri =
s[facei];
360 bool Foam::orientedSurface::orientConsistent(triSurface&
s)
362 bool anyFlipped =
false;
378 label startFacei = -1;
379 while (facei <
s.size())
381 if (flipState[facei] == UNVISITED)
389 if (startFacei == -1)
394 flipState[startFacei] = NOFLIP;
395 walkSurface(
s, startFacei, flipState);
398 anyFlipped = flipSurface(
s, flipState);
417 const point& samplePoint,
418 const bool orientOutside
423 orient(*
this, samplePoint, orientOutside);
431 const bool orientOutside
439 point outsidePoint = bb.
max() + bb.span();
441 orient(*
this, outsidePoint, orientOutside);
450 const point& samplePoint,
451 const bool orientOutside
457 bool topoFlipped = orientConsistent(
s);
471 scalar minDist = GREAT;
477 if (flipState[facei] == UNVISITED)
480 s[facei].nearestPoint(samplePoint,
s.points());
511 bool geomFlipped = flipSurface(
s, flipState);
513 return topoFlipped || geomFlipped;
521 const point& samplePoint,
522 const bool orientOutside
528 bool topoFlipped = orientConsistent(
s);
534 if (
s.edgeFaces()[edgeI].size() != 2)
536 borderEdge[edgeI] =
true;
547 label zoneFacei = -1;
560 if (isOutside == orientOutside)
562 flipState[zoneFacei] = NOFLIP;
566 flipState[zoneFacei] = FLIP;
568 walkSurface(
s, zoneFacei, flipState);
572 bool geomFlipped = flipSurface(
s, flipState);
574 return topoFlipped || geomFlipped;