From 7de5697a2d70f229cd4281d96fe4c4821d5b25d0 Mon Sep 17 00:00:00 2001
From: mattijs <mattijs@hunt.opencfd.co.uk>
Date: Mon, 20 Apr 2009 17:49:24 +0100
Subject: [PATCH] use PatchTools algorithms

---
 .../surface/surfaceCheck/surfaceCheck.C       |   6 +-
 .../PatchTools/PatchToolsCheck.C              |  20 +--
 src/triSurface/triSurface/triSurface.C        | 121 ------------------
 src/triSurface/triSurface/triSurface.H        |   9 +-
 4 files changed, 17 insertions(+), 139 deletions(-)

diff --git a/applications/utilities/surface/surfaceCheck/surfaceCheck.C b/applications/utilities/surface/surfaceCheck/surfaceCheck.C
index 4731ed3ec25..d714c19ec36 100644
--- a/applications/utilities/surface/surfaceCheck/surfaceCheck.C
+++ b/applications/utilities/surface/surfaceCheck/surfaceCheck.C
@@ -32,6 +32,7 @@ License
 #include "OFstream.H"
 #include "surfaceIntersection.H"
 #include "SortableList.H"
+#include "PatchTools.H"
 
 using namespace Foam;
 
@@ -596,13 +597,14 @@ int main(int argc, char *argv[])
     // Check orientation
     // ~~~~~~~~~~~~~~~~~
 
-    boolList borderEdge(surf.checkOrientation(false));
+    labelHashSet borderEdge(surf.size()/1000);
+    PatchTools::checkOrientation(surf, false, &borderEdge);
 
     //
     // Colour all faces into zones using borderEdge
     //
     labelList normalZone;
-    label numNormalZones = surf.markZones(borderEdge, normalZone);
+    label numNormalZones = PatchTools::markZones(surf, borderEdge, normalZone);
 
     Pout<< endl
         << "Number of zones (connected area with consistent normal) : "
diff --git a/src/OpenFOAM/meshes/primitiveMesh/PatchTools/PatchToolsCheck.C b/src/OpenFOAM/meshes/primitiveMesh/PatchTools/PatchToolsCheck.C
index 5fcec15c958..a644cd19349 100644
--- a/src/OpenFOAM/meshes/primitiveMesh/PatchTools/PatchToolsCheck.C
+++ b/src/OpenFOAM/meshes/primitiveMesh/PatchTools/PatchToolsCheck.C
@@ -58,7 +58,7 @@ Foam::PatchTools::checkOrientation
             {
                 Info<< "Face[" << faceI << "] " << p[faceI]
                     << " has fewer than 3 edges. Edges: " << edgeLabels
-                    << nl;
+                    << endl;
             }
             valid = false;
         }
@@ -70,10 +70,12 @@ Foam::PatchTools::checkOrientation
                 {
                     if (report)
                     {
-                        Info<< "edge number " << edgeLabels[i] << " on face " << faceI
+                        Info<< "edge number " << edgeLabels[i]
+                            << " on face " << faceI
                             << " out-of-range\n"
                             << "This usually means the input surface has "
-                            << "edges with more than 2 faces connected." << nl;
+                            << "edges with more than 2 faces connected."
+                            << endl;
                     }
                     valid = false;
                 }
@@ -91,9 +93,9 @@ Foam::PatchTools::checkOrientation
         //- Compute normal from 3 points, use the first as the origin
         // minor warpage should not be a problem
         const Face& f = p[faceI];
-        const point p0(p.points()[f[0]]);
-        const point p1(p.points()[f[1]]);
-        const point p2(p.points()[f[f.size()-1]]);
+        const point& p0 = p.points()[f[0]];
+        const point& p1 = p.points()[f[1]];
+        const point& p2 = p.points()[f[f.size()-1]];
 
         const vector pointNormal((p1 - p0) ^ (p2 - p0));
         if ((pointNormal & p.faceNormals()[faceI]) < 0)
@@ -103,12 +105,12 @@ Foam::PatchTools::checkOrientation
             if (report)
             {
                 Info
-                    << "Normal calculated from points inconsistent with faceNormal"
-                    << nl
+                    << "Normal calculated from points inconsistent"
+                    << " with faceNormal" << nl
                     << "face: " << f << nl
                     << "points: " << p0 << ' ' << p1 << ' ' << p2 << nl
                     << "pointNormal:" << pointNormal << nl
-                    << "faceNormal:" << p.faceNormals()[faceI] << nl;
+                    << "faceNormal:" << p.faceNormals()[faceI] << endl;
             }
         }
     }
diff --git a/src/triSurface/triSurface/triSurface.C b/src/triSurface/triSurface/triSurface.C
index 9b63d3de862..b17aa88bb58 100644
--- a/src/triSurface/triSurface/triSurface.C
+++ b/src/triSurface/triSurface/triSurface.C
@@ -347,127 +347,6 @@ void Foam::triSurface::checkEdges(const bool verbose)
 }
 
 
-// Check normals and orientation
-Foam::boolList Foam::triSurface::checkOrientation(const bool verbose)
-{
-    const edgeList& es = edges();
-    const labelListList& faceEs = faceEdges();
-
-    // Check edge normals, face normals, point normals.
-    forAll(faceEs, facei)
-    {
-        const labelList& edgeLabels = faceEs[facei];
-
-        if (edgeLabels.size() != 3)
-        {
-            FatalErrorIn("triSurface::checkOrientation(bool)")
-                << "triangle " << (*this)[facei]
-                << " does not have 3 edges. Edges:" << edgeLabels
-                << exit(FatalError);
-        }
-
-        bool valid = true;
-        forAll(edgeLabels, i)
-        {
-            if (edgeLabels[i] < 0 || edgeLabels[i] >= nEdges())
-            {
-                WarningIn
-                (
-                    "triSurface::checkOrientation(bool)"
-                )   << "edge number " << edgeLabels[i] << " on face " << facei
-                    << " out-of-range\n"
-                    << "This usually means that the input surface has "
-                    << "edges with more than 2 triangles connected.\n"
-                    << endl;
-                valid = false;
-            }
-        }
-        if (! valid)
-        {
-            continue;
-        }
-
-
-        //
-        //- Compute normal from triangle points.
-        //
-
-        const labelledTri& tri = (*this)[facei];
-        const point pa(points()[tri[0]]);
-        const point pb(points()[tri[1]]);
-        const point pc(points()[tri[2]]);
-
-        const vector pointNormal((pc - pb) ^ (pa - pb));
-        if ((pointNormal & faceNormals()[facei]) < 0)
-        {
-            FatalErrorIn("triSurface::checkOrientation(bool)")
-                << "Normal calculated from points not consistent with"
-                " faceNormal" << endl
-                << "triangle:" << tri << endl
-                << "points:" << pa << ' ' << pb << ' ' << pc << endl
-                << "pointNormal:" << pointNormal << endl
-                << "faceNormal:" << faceNormals()[facei]
-                << exit(FatalError);
-        }
-    }
-
-
-    const labelListList& eFaces = edgeFaces();
-
-    // Storage for holding status of edge. True if normal flips across this
-    // edge
-    boolList borderEdge(nEdges(), false);
-
-    forAll(es, edgeI)
-    {
-        const edge& e = es[edgeI];
-        const labelList& neighbours = eFaces[edgeI];
-
-        if (neighbours.size() == 2)
-        {
-            const labelledTri& faceA = (*this)[neighbours[0]];
-            const labelledTri& faceB = (*this)[neighbours[1]];
-
-            // The edge cannot be going in the same direction if both faces
-            // are oriented counterclockwise.
-            // Thus the next face point *must* different between the faces.
-            if
-            (
-                faceA[faceA.fcIndex(findIndex(faceA, e.start()))]
-             == faceB[faceB.fcIndex(findIndex(faceB, e.start()))]
-            )
-            {
-                borderEdge[edgeI] = true;
-                if (verbose)
-                {
-                    WarningIn("PrimitivePatchExtra::checkOrientation(bool)")
-                        << "face orientation incorrect." << nl
-                        << "edge[" << edgeI << "] " << e
-                        << " between faces " << neighbours << ":" << nl
-                        << "face[" << neighbours[0] << "] " << faceA << nl
-                        << "face[" << neighbours[1] << "] " << faceB << endl;
-                }
-            }
-        }
-        else if (neighbours.size() != 1)
-        {
-            if (verbose)
-            {
-                WarningIn("triSurface::checkOrientation(bool)")
-                    << "Wrong number of edge neighbours." << endl
-                    << "edge[" << edgeI << "] " << e
-                    << "with points:" << localPoints()[e.start()]
-                    << ' ' << localPoints()[e.end()]
-                    << " has neighbours:" << neighbours << endl;
-            }
-            borderEdge[edgeI] = true;
-        }
-    }
-
-    return borderEdge;
-}
-
-
 // Read triangles, points from Istream
 bool Foam::triSurface::read(Istream& is)
 {
diff --git a/src/triSurface/triSurface/triSurface.H b/src/triSurface/triSurface/triSurface.H
index e6fb6239afe..9ee5b5ca4d9 100644
--- a/src/triSurface/triSurface/triSurface.H
+++ b/src/triSurface/triSurface/triSurface.H
@@ -326,17 +326,12 @@ public:
             //- Scale points. A non-positive factor is ignored
             virtual void scalePoints(const scalar&);
 
-            //- Check/fix duplicate/degenerate triangles
+            //- Check/remove duplicate/degenerate triangles
             void checkTriangles(const bool verbose);
 
-            //- Check triply (or more) connected edges. Return list of faces
-            //  sharing these edges.
+            //- Check triply (or more) connected edges.
             void checkEdges(const bool verbose);
 
-            //- Check orientation (normals) and normals of neighbouring
-            //  triangles
-            boolList checkOrientation(const bool verbose);
-
             //- Remove non-valid triangles
             void cleanup(const bool verbose);
 
-- 
GitLab