PrimitivePatchExtra orientation fixed and improved face::edgeDirection()

This commit is contained in:
Mark Olesen
2009-01-21 01:19:31 +01:00
parent 81184573c8
commit 0690c64d31
5 changed files with 96 additions and 58 deletions

View File

@ -34,6 +34,9 @@ Usage
@param -clean \n @param -clean \n
Perform some surface checking/cleanup on the input surface Perform some surface checking/cleanup on the input surface
@param -orient \n
Check face orientation on the input surface
@param -scale \<scale\> \n @param -scale \<scale\> \n
Specify a scaling factor for writing the files Specify a scaling factor for writing the files
@ -68,6 +71,7 @@ int main(int argc, char *argv[])
argList::validArgs.append("inputFile"); argList::validArgs.append("inputFile");
argList::validArgs.append("outputFile"); argList::validArgs.append("outputFile");
argList::validOptions.insert("clean", ""); argList::validOptions.insert("clean", "");
argList::validOptions.insert("orient", "");
argList::validOptions.insert("scale", "scale"); argList::validOptions.insert("scale", "scale");
argList::validOptions.insert("triSurface", ""); argList::validOptions.insert("triSurface", "");
argList::validOptions.insert("unsorted", ""); argList::validOptions.insert("unsorted", "");
@ -108,6 +112,13 @@ int main(int argc, char *argv[])
surf.writeStats(Info); surf.writeStats(Info);
Info<< endl; Info<< endl;
if (args.options().found("orient"))
{
Info<< "Checking surface orientation" << endl;
surf.checkOrientation(true);
Info<< endl;
}
if (args.options().found("clean")) if (args.options().found("clean"))
{ {
Info<< "Cleaning up surface" << endl; Info<< "Cleaning up surface" << endl;
@ -140,6 +151,13 @@ int main(int argc, char *argv[])
surf.writeStats(Info); surf.writeStats(Info);
Info<< endl; Info<< endl;
if (args.options().found("orient"))
{
Info<< "Checking surface orientation" << endl;
surf.checkOrientation(true);
Info<< endl;
}
if (args.options().found("clean")) if (args.options().found("clean"))
{ {
Info<< "Cleaning up surface" << endl; Info<< "Cleaning up surface" << endl;
@ -171,6 +189,13 @@ int main(int argc, char *argv[])
surf.writeStats(Info); surf.writeStats(Info);
Info<< endl; Info<< endl;
if (args.options().found("orient"))
{
Info<< "Checking surface orientation" << endl;
surf.checkOrientation(true);
Info<< endl;
}
if (args.options().found("clean")) if (args.options().found("clean"))
{ {
Info<< "Cleaning up surface" << endl; Info<< "Cleaning up surface" << endl;
@ -202,6 +227,13 @@ int main(int argc, char *argv[])
surf.writeStats(Info); surf.writeStats(Info);
Info<< endl; Info<< endl;
if (args.options().found("orient"))
{
Info<< "Checking surface orientation" << endl;
surf.checkOrientation(true);
Info<< endl;
}
if (args.options().found("clean")) if (args.options().found("clean"))
{ {
Info<< "Cleaning up surface" << endl; Info<< "Cleaning up surface" << endl;

View File

@ -713,41 +713,43 @@ Foam::edgeList Foam::face::edges() const
int Foam::face::edgeDirection(const edge& e) const int Foam::face::edgeDirection(const edge& e) const
{ {
if (size() > 2)
{
edge found(-1,-1);
// find start/end points - this breaks down for degenerate faces
forAll (*this, i) forAll (*this, i)
{ {
if (operator[](i) == e.start()) if (operator[](i) == e.start())
{ {
found.start() = i; if (operator[](rcIndex(i)) == e.end())
{
// reverse direction
return -1;
}
else if (operator[](fcIndex(i)) == e.end())
{
// forward direction
return 1;
}
// no match
return 0;
} }
else if (operator[](i) == e.end()) else if (operator[](i) == e.end())
{ {
found.end() = i; if (operator[](rcIndex(i)) == e.start())
}
}
label diff = found.end() - found.start();
if (!diff || found.start() < 0 || found.end() < 0)
{ {
return 0;
}
// forward direction // forward direction
if (diff == 1 || diff == 1 - size())
{
return 1; return 1;
} }
// reverse direction else if (operator[](fcIndex(i)) == e.start())
if (diff == -1 || diff == -1 + size())
{ {
// reverse direction
return -1; return -1;
} }
// no match
return 0;
}
} }
// not found
return 0; return 0;
} }

View File

@ -125,11 +125,8 @@ public:
// Topological data; no mesh required. // Topological data; no mesh required.
//- Return edge-face addressing sorted //- Return edge-face addressing sorted by angle around the edge.
// (for edges with more than 2 faces) according to the // Orientation is anticlockwise looking from edge.vec(localPoints())
// angle around the edge.
// Orientation is anticlockwise looking from
// edge.vec(localPoints())
const labelListList& sortedEdgeFaces() const; const labelListList& sortedEdgeFaces() const;
//- If 2 face neighbours: label of face where ordering of edge //- If 2 face neighbours: label of face where ordering of edge

View File

@ -171,26 +171,25 @@ calcEdgeOwner() const
forAll(edgeLst, edgeI) forAll(edgeLst, edgeI)
{ {
const edge& e = edgeLst[edgeI]; const edge& e = edgeLst[edgeI];
const labelList& neighbouringFaces = eFaces[edgeI];
const labelList& myFaces = eFaces[edgeI]; if (neighbouringFaces.size() == 1)
if (myFaces.size() == 1)
{ {
edgeOwner[edgeI] = myFaces[0]; edgeOwner[edgeI] = neighbouringFaces[0];
} }
else else
{ {
// Find the first face whose vertices are aligned with the edge. // Find the first face whose vertices are aligned with the edge.
// (in case of multiply connected edge the best we can do) // with multiply connected edges, this is the best we can do
edgeOwner[edgeI] = -1; edgeOwner[edgeI] = -1;
forAll(myFaces, i) forAll(neighbouringFaces, i)
{ {
const Face& f = locFaceLst[myFaces[i]]; const Face& f = locFaceLst[neighbouringFaces[i]];
if (f.findEdge(e) > 0) if (f.edgeDirection(e) > 0)
{ {
edgeOwner[edgeI] = myFaces[i]; edgeOwner[edgeI] = neighbouringFaces[i];
break; break;
} }
} }
@ -203,9 +202,9 @@ calcEdgeOwner() const
"calcEdgeOwner()" "calcEdgeOwner()"
) )
<< "Edge " << edgeI << " vertices:" << e << "Edge " << edgeI << " vertices:" << e
<< " is used by faces " << myFaces << " is used by faces " << neighbouringFaces
<< " vertices:" << " vertices:"
<< IndirectList<Face>(locFaceLst, myFaces)() << IndirectList<Face>(locFaceLst, neighbouringFaces)()
<< " none of which use the edge vertices in the same order" << " none of which use the edge vertices in the same order"
<< nl << "I give up" << abort(FatalError); << nl << "I give up" << abort(FatalError);
} }

View File

@ -99,6 +99,11 @@ checkOrientation
const Field<PointType>& pointLst = this->points(); const Field<PointType>& pointLst = this->points();
const vectorField& normLst = this->faceNormals(); const vectorField& normLst = this->faceNormals();
if (ParentType::debug)
{
Info<<"checkOrientation:::checkOrientation(bool)" << endl;
}
// Check edge normals, face normals, point normals. // Check edge normals, face normals, point normals.
forAll(faceEs, faceI) forAll(faceEs, faceI)
{ {
@ -153,8 +158,8 @@ checkOrientation
( (
"PrimitivePatchExtra::checkOrientation(bool)" "PrimitivePatchExtra::checkOrientation(bool)"
) )
<< "Normal calculated from points not consistent with " << "Normal calculated from points inconsistent with faceNormal"
<< "faceNormal" << nl << nl
<< "face: " << f << nl << "face: " << f << nl
<< "points: " << p0 << ' ' << p1 << ' ' << p2 << nl << "points: " << p0 << ' ' << p1 << ' ' << p2 << nl
<< "pointNormal:" << pointNormal << nl << "pointNormal:" << pointNormal << nl
@ -174,21 +179,18 @@ checkOrientation
forAll(edgeLst, edgeI) forAll(edgeLst, edgeI)
{ {
const edge& e = edgeLst[edgeI]; const edge& e = edgeLst[edgeI];
const labelList& neighbours = eFaces[edgeI]; const labelList& neighbouringFaces = eFaces[edgeI];
if (neighbours.size() == 2) if (neighbouringFaces.size() == 2)
{ {
const Face& faceA = faceLst[neighbours[0]]; // we use localFaces() since edges() are LOCAL
const Face& faceB = faceLst[neighbours[1]]; // these are both already available
const Face& faceA = this->localFaces()[neighbouringFaces[0]];
const Face& faceB = this->localFaces()[neighbouringFaces[1]];
// The edge cannot be going in the same direction if both faces // If the faces are correctly oriented, the edges must go in
// are oriented counterclockwise. // different directions on connected faces.
// Thus the next face point *must* different between the faces. if (faceA.edgeDirection(e) == faceB.edgeDirection(e))
if
(
faceA[faceA.fcIndex(findIndex(faceA, e.start()))]
== faceB[faceB.fcIndex(findIndex(faceB, e.start()))]
)
{ {
borderEdge[edgeI] = true; borderEdge[edgeI] = true;
if (verbose) if (verbose)
@ -198,14 +200,20 @@ checkOrientation
"PrimitivePatchExtra::checkOrientation(bool)" "PrimitivePatchExtra::checkOrientation(bool)"
) )
<< "face orientation incorrect." << nl << "face orientation incorrect." << nl
<< "edge[" << edgeI << "] " << e << "localEdge[" << edgeI << "] " << e
<< " between faces " << neighbours << ":" << nl << " between faces:" << nl
<< "face[" << neighbours[0] << "] " << faceA << nl << " face[" << neighbouringFaces[0] << "] "
<< "face[" << neighbours[1] << "] " << faceB << endl; << faceLst[neighbouringFaces[0]]
<< " localFace: " << faceA
<< nl
<< " face[" << neighbouringFaces[1] << "] "
<< faceLst[neighbouringFaces[1]]
<< " localFace: " << faceB
<< endl;
} }
} }
} }
else if (neighbours.size() != 1) else if (neighbouringFaces.size() != 1)
{ {
if (verbose) if (verbose)
{ {
@ -217,7 +225,7 @@ checkOrientation
<< "edge[" << edgeI << "] " << e << "edge[" << edgeI << "] " << e
<< " with points:" << locPointsLst[e.start()] << " with points:" << locPointsLst[e.start()]
<< ' ' << locPointsLst[e.end()] << ' ' << locPointsLst[e.end()]
<< " has neighbours:" << neighbours << endl; << " has neighbouringFaces:" << neighbouringFaces << endl;
} }
borderEdge[edgeI] = true; borderEdge[edgeI] = true;
} }