From 6e02125e05709d0444edbd8dd318554dacd4b308 Mon Sep 17 00:00:00 2001
From: mattijs <mattijs@hunt.opencfd.co.uk>
Date: Wed, 27 Aug 2008 18:09:32 +0100
Subject: [PATCH] stats without mesh addressing; reuse constructor

---
 src/triSurface/triSurface/triSurface.C | 49 +++++++++++++++++++-------
 src/triSurface/triSurface/triSurface.H | 11 +++++-
 2 files changed, 47 insertions(+), 13 deletions(-)

diff --git a/src/triSurface/triSurface/triSurface.C b/src/triSurface/triSurface/triSurface.C
index 336987ade85..89a48a30d60 100644
--- a/src/triSurface/triSurface/triSurface.C
+++ b/src/triSurface/triSurface/triSurface.C
@@ -31,6 +31,7 @@ License
 #include "Time.H"
 #include "boundBox.H"
 #include "SortableList.H"
+#include "PackedList.H"
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
@@ -743,6 +744,26 @@ triSurface::triSurface
 {}
 
 
+triSurface::triSurface
+(
+    List<labelledTri>& triangles,
+    const geometricSurfacePatchList& patches,
+    pointField& points,
+    const bool reUse
+)
+:
+    PrimitivePatch<labelledTri, ::Foam::List, pointField>
+    (
+        triangles,
+        points,
+        reUse
+    ),
+    patches_(patches),
+    sortedEdgeFacesPtr_(NULL),
+    edgeOwnerPtr_(NULL)
+{}
+
+
 triSurface::triSurface
 (
     const List<labelledTri>& triangles,
@@ -1148,9 +1169,7 @@ triSurface triSurface::subsetMesh
     }
 
     // Construct subsurface
-    triSurface subSurface(newTriangles, patches(), newPoints);
-
-    return subSurface;
+    return triSurface(newTriangles, patches(), newPoints, true);
 }
 
 
@@ -1187,30 +1206,36 @@ void triSurface::write(const Time& d) const
 
 void triSurface::writeStats(Ostream& os) const
 {
-    // Calculate bounding box without any additional addressing
-    // Copy of treeBoundBox code. Cannot use meshTools from triSurface...
+    // Unfortunately nPoints constructs meshPoints() so do compact version
+    // ourselves.
+    PackedList<1> pointIsUsed(points().size());
+    pointIsUsed = 0U;
+
+    label nPoints = 0;
     boundBox bb
     (
         point(VGREAT, VGREAT, VGREAT),
         point(-VGREAT, -VGREAT, -VGREAT)
     );
+
     forAll(*this, triI)
     {
         const labelledTri& f = operator[](triI);
 
         forAll(f, fp)
         {
-            const point& pt = points()[f[fp]];
-            bb.min() = ::Foam::min(bb.min(), pt);
-            bb.max() = ::Foam::max(bb.max(), pt);
+            label pointI = f[fp];
+            if (pointIsUsed.set(pointI, 1))
+            {
+                bb.min() = ::Foam::min(bb.min(), points()[pointI]);
+                bb.max() = ::Foam::max(bb.max(), points()[pointI]);
+                nPoints++;
+            }
         }
     }
 
-    // Unfortunately nPoints constructs meshPoints() ...
-
     os  << "Triangles    : " << size() << endl
-        //<< "Edges        : " << nEdges() << endl
-        << "Vertices     : " << nPoints() << endl
+        << "Vertices     : " << nPoints << endl
         << "Bounding Box : " << bb << endl;
 }
 
diff --git a/src/triSurface/triSurface/triSurface.H b/src/triSurface/triSurface/triSurface.H
index 56b1abc8492..624b7931172 100644
--- a/src/triSurface/triSurface/triSurface.H
+++ b/src/triSurface/triSurface/triSurface.H
@@ -36,9 +36,9 @@ SourceFiles
 #ifndef triSurface_H
 #define triSurface_H
 
+#include "PrimitivePatch.H"
 #include "pointField.H"
 #include "labelledTri.H"
-#include "PrimitivePatch.H"
 #include "boolList.H"
 #include "geometricSurfacePatchList.H"
 #include "surfacePatchList.H"
@@ -215,6 +215,15 @@ public:
             const pointField&
         );
 
+        //- Construct from triangles, patches, points. Reuse storage.
+        triSurface
+        (
+            List<labelledTri>&,
+            const geometricSurfacePatchList&,
+            pointField&,
+            const bool reUse
+        );
+
         //- Construct from triangles, points. Set patchnames to default.
         triSurface(const List<labelledTri>&, const pointField&);
 
-- 
GitLab