42 bool Foam::orientedSurface::consistentEdge
49 return (f0.edgeDirection(e) > 0) ^ (f1.edgeDirection(e) > 0);
59 labelList changedEdges(3*changedFaces.size());
64 const labelList& fEdges = s.faceEdges()[changedFaces[i]];
68 changedEdges[changedI++] = fEdges[j];
71 changedEdges.setSize(changedI);
84 labelList changedFaces(2*changedEdges.size());
89 label edgeI = changedEdges[i];
91 const labelList& eFaces = s.edgeFaces()[edgeI];
93 if (eFaces.size() < 2)
97 else if (eFaces.size() == 2)
99 label face0 = eFaces[0];
100 label face1 = eFaces[1];
105 if (flip[face0] == UNVISITED)
107 if (flip[face1] == UNVISITED)
115 if (consistentEdge(s.edges()[edgeI], f0,
f1))
118 flip[face0] = (flip[face1] == FLIP ? FLIP : NOFLIP);
123 flip[face0] = (flip[face1] == FLIP ? NOFLIP : FLIP);
125 changedFaces[changedI++] = face0;
130 if (flip[face1] == UNVISITED)
133 if (consistentEdge(s.edges()[edgeI], f0,
f1))
135 flip[face1] = (flip[face0] == FLIP ? FLIP : NOFLIP);
139 flip[face1] = (flip[face0] == FLIP ? NOFLIP : FLIP);
141 changedFaces[changedI++] = face1;
150 changedFaces.setSize(changedI);
156 void Foam::orientedSurface::walkSurface
159 const label startFacei,
170 changedEdges = faceToEdge(s, changedFaces);
172 if (changedEdges.empty())
177 changedFaces = edgeToFace(s, changedEdges, flipState);
179 if (changedFaces.empty())
187 void Foam::orientedSurface::propagateOrientation
190 const point& samplePoint,
191 const bool orientOutside,
192 const label nearestFacei,
193 const point& nearestPt,
211 flipState[nearestFacei] = NOFLIP;
217 flipState[nearestFacei] = NOFLIP;
222 flipState[nearestFacei] = FLIP;
229 Pout<<
"orientedSurface::propagateOrientation : starting face" 230 <<
" orientation:" <<
nl 231 <<
" for samplePoint:" << samplePoint <<
nl 232 <<
" starting from point:" << nearestPt <<
nl 233 <<
" on face:" << nearestFacei <<
nl 234 <<
" with normal:" << n <<
nl 235 <<
" decided side:" <<
label(side)
240 walkSurface(s, nearestFacei, flipState);
246 void Foam::orientedSurface::findZoneSide
248 const triSurfaceSearch& surfSearches,
251 const point& outsidePoint,
256 const triSurface& s = surfSearches.surface();
262 List<List<pointIndexHit>> hits(1, List<pointIndexHit>());
266 if (faceZone[facei] == zoneI)
268 const point& fc = s.faceCentres()[facei];
269 const vector& n = s.faceNormals()[facei];
271 const vector d = fc - outsidePoint;
272 const scalar magD =
mag(d);
275 if (magD > small && (
mag(n & d/magD) > 1e-6))
286 surfSearches.findLineAll(start, end, hits);
288 label zoneIndex = -1;
291 if (hits[0][i].index() == facei)
302 if ((zoneIndex%2) == 0)
306 isOutside = ((n & d) < 0);
310 isOutside = ((n & d) > 0);
320 bool Foam::orientedSurface::flipSurface
326 bool hasFlipped =
false;
331 if (flipState[facei] == UNVISITED)
334 <<
"unvisited face " << facei
337 else if (flipState[facei] == FLIP)
339 labelledTri& tri = s[facei];
358 bool Foam::orientedSurface::orientConsistent(triSurface& s)
360 bool anyFlipped =
false;
371 labelList flipState(s.size(), UNVISITED);
376 label startFacei = -1;
377 while (facei < s.size())
379 if (flipState[facei] == UNVISITED)
387 if (startFacei == -1)
392 flipState[startFacei] = NOFLIP;
393 walkSurface(s, startFacei, flipState);
396 anyFlipped = flipSurface(s, flipState);
415 const point& samplePoint,
416 const bool orientOutside
421 orient(*
this, samplePoint, orientOutside);
429 const bool orientOutside
437 point outsidePoint = bb.
max() + bb.span();
439 orient(*
this, outsidePoint, orientOutside);
448 const point& samplePoint,
449 const bool orientOutside
455 bool topoFlipped = orientConsistent(s);
478 s[facei].nearestPoint(samplePoint, s.
points());
509 bool geomFlipped = flipSurface(s, flipState);
511 return topoFlipped || geomFlipped;
519 const point& samplePoint,
520 const bool orientOutside
526 bool topoFlipped = orientConsistent(s);
534 borderEdge[edgeI] =
true;
543 for (
label zoneI = 0; zoneI < nZones; zoneI++)
545 label zoneFacei = -1;
558 if (isOutside == orientOutside)
560 flipState[zoneFacei] =
NOFLIP;
564 flipState[zoneFacei] =
FLIP;
566 walkSurface(s, zoneFacei, flipState);
570 bool geomFlipped = flipSurface(s, flipState);
572 return topoFlipped || geomFlipped;
#define forAll(list, i)
Loop across all elements in list.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
void size(const label)
Override size to be inconsistent with allocated storage.
Ostream & endl(Ostream &os)
Add newline and flush stream.
static bool orient(triSurface &, const point &, const bool orientOutside)
Flip faces such that normals are consistent with point:
Vector< scalar > vector
A scalar version of the templated Vector.
scalar minDist(const List< pointIndexHit > &hitList)
orientedSurface()
Construct null.
const labelList & meshPoints() const
Return labelList of mesh points in patch. They are constructed.
Helper class to search on triSurface.
vectorField pointField
pointField is a vectorField.
const Field< PointType > & points() const
Return reference to global points.
const labelListList & edgeFaces() const
Return edge-face addressing.
List< label > labelList
A List of labels.
errorManip< error > abort(error &err)
const Point & rawPoint() const
Return point with no checking.
label nEdges() const
Return number of edges in patch.
defineTypeNameAndDebug(combustionModel, 0)
triSurface()
Construct null.
std::remove_reference< ::Foam::List< labelledTri > >::type::value_type FaceType
vector point
Point is a vector.
prefixOSstream Pout(cout, "Pout")
Standard boundBox + extra functionality for use in octree.
dimensioned< scalar > mag(const dimensioned< Type > &)
scalar distance() const
Return distance to hit.
label markZones(const boolList &borderEdge, labelList &faceZone) const
(size and) fills faceZone with zone of face. Zone is area
Triangulated surface description with patch information.