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)
109 FatalErrorIn(
"orientedSurface::edgeToFace(..)") <<
"Problem" 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)
335 "orientSurface(const point&, const label, const point&)" 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;
373 labelList flipState(s.size(), UNVISITED);
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;
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);
536 borderEdge[edgeI] =
true;
545 for (
label zoneI = 0; zoneI < nZones; zoneI++)
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;
const Point & rawPoint() const
Return point with no checking.
orientedSurface()
Construct null.
vector point
Point is a vector.
dimensioned< scalar > mag(const dimensioned< Type > &)
const labelListList & edgeFaces() const
Return edge-face addressing.
Triangulated surface description with patch information.
label markZones(const boolList &borderEdge, labelList &faceZone) const
(size and) fills faceZone with zone of face. Zone is area
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Standard boundBox + extra functionality for use in octree.
void size(const label)
Override size to be inconsistent with allocated storage.
triSurface()
Construct null.
static bool orient(triSurface &, const point &, const bool orientOutside)
Flip faces such that normals are consistent with point:
static vector surfaceNormal(const triSurface &surf, const label nearestFaceI, const point &nearestPt)
Triangle (unit) normal. If nearest point to triangle on edge use.
vectorField pointField
pointField is a vectorField.
Ostream & endl(Ostream &os)
Add newline and flush stream.
const labelList & meshPoints() const
Return labelList of mesh points in patch. They are constructed.
errorManip< error > abort(error &err)
sideType
On which side of surface.
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
scalar distance() const
Return distance to hit.
List< label > labelList
A List of labels.
Vector< scalar > vector
A scalar version of the templated Vector.
label nEdges() const
Return number of edges in patch.
const Field< PointType > & points() const
Return reference to global points.
static sideType surfaceSide(const triSurface &surf, const point &sample, const label nearestFaceI)
Given nearest point (to sample) on surface determines which side.
defineTypeNameAndDebug(combustionModel, 0)
prefixOSstream Pout(cout,"Pout")
Helper class to search on triSurface.