From 991d8560173321739bf38f7d0d2fd672d839eab5 Mon Sep 17 00:00:00 2001
From: Mark Olesen <Mark.Olesen@Germany>
Date: Wed, 4 Aug 2010 11:18:22 +0200
Subject: [PATCH] ENH: add Xfer<> construction for indexedOctree components

- in preparation for using PackedBoolList
---
 src/meshTools/indexedOctree/indexedOctree.H   |  8 +--
 src/meshTools/indexedOctree/treeDataCell.C    | 52 ++++++++++++-------
 src/meshTools/indexedOctree/treeDataCell.H    | 27 +++++++---
 src/meshTools/indexedOctree/treeDataEdge.C    | 50 +++++++++++++-----
 src/meshTools/indexedOctree/treeDataEdge.H    | 19 +++++--
 src/meshTools/indexedOctree/treeDataFace.C    | 25 +++++++--
 src/meshTools/indexedOctree/treeDataFace.H    | 24 ++++++---
 src/meshTools/indexedOctree/treeDataPoint.C   |  9 ++--
 src/meshTools/indexedOctree/treeDataPoint.H   |  8 +--
 .../indexedOctree/treeDataPrimitivePatch.C    |  4 +-
 .../indexedOctree/treeDataPrimitivePatch.H    |  8 +--
 .../indexedOctree/treeDataTriSurface.C        |  6 +--
 .../indexedOctree/treeDataTriSurface.H        |  8 +--
 13 files changed, 164 insertions(+), 84 deletions(-)

diff --git a/src/meshTools/indexedOctree/indexedOctree.H b/src/meshTools/indexedOctree/indexedOctree.H
index 6d7f4251769..d82603ab4f4 100644
--- a/src/meshTools/indexedOctree/indexedOctree.H
+++ b/src/meshTools/indexedOctree/indexedOctree.H
@@ -164,8 +164,8 @@ private:
 
         // Construction
 
-            //- Split list of indices into 8 bins according to where they are in
-            //  relation to mid.
+            //- Split list of indices into 8 bins
+            //  according to where they are in relation to mid.
             void divide
             (
                 const labelList& indices,
@@ -173,8 +173,8 @@ private:
                 labelListList& result
             ) const;
 
-            //- Subdivide the contents node at position contentI. Appends to
-            //  contents.
+            //- Subdivide the contents node at position contentI.
+            //  Appends to contents.
             node divide
             (
                 const treeBoundBox& bb,
diff --git a/src/meshTools/indexedOctree/treeDataCell.C b/src/meshTools/indexedOctree/treeDataCell.C
index 87b5dde1238..8492f59c4f8 100644
--- a/src/meshTools/indexedOctree/treeDataCell.C
+++ b/src/meshTools/indexedOctree/treeDataCell.C
@@ -64,29 +64,49 @@ Foam::treeBoundBox Foam::treeDataCell::calcCellBb(const label cellI) const
 }
 
 
+void Foam::treeDataCell::update()
+{
+    if (cacheBb_)
+    {
+        bbs_.setSize(cellLabels_.size());
+
+        forAll(cellLabels_, i)
+        {
+            bbs_[i] = calcCellBb(cellLabels_[i]);
+        }
+    }
+}
+
+
 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
 
-// Construct from components
 Foam::treeDataCell::treeDataCell
 (
     const bool cacheBb,
     const primitiveMesh& mesh,
-    const labelList& cellLabels
+    const unallocLabelList& cellLabels
 )
 :
     mesh_(mesh),
     cellLabels_(cellLabels),
     cacheBb_(cacheBb)
 {
-    if (cacheBb_)
-    {
-        bbs_.setSize(cellLabels_.size());
+    update();
+}
 
-        forAll(cellLabels_, i)
-        {
-            bbs_[i] = calcCellBb(cellLabels_[i]);
-        }
-    }
+
+Foam::treeDataCell::treeDataCell
+(
+    const bool cacheBb,
+    const primitiveMesh& mesh,
+    const Xfer<labelList>& cellLabels
+)
+:
+    mesh_(mesh),
+    cellLabels_(cellLabels),
+    cacheBb_(cacheBb)
+{
+    update();
 }
 
 
@@ -100,15 +120,7 @@ Foam::treeDataCell::treeDataCell
     cellLabels_(identity(mesh_.nCells())),
     cacheBb_(cacheBb)
 {
-    if (cacheBb_)
-    {
-        bbs_.setSize(cellLabels_.size());
-
-        forAll(cellLabels_, i)
-        {
-            bbs_[i] = calcCellBb(cellLabels_[i]);
-        }
-    }
+    update();
 }
 
 
@@ -159,7 +171,7 @@ bool Foam::treeDataCell::contains
 // nearestPoint.
 void Foam::treeDataCell::findNearest
 (
-    const labelList& indices,
+    const unallocLabelList& indices,
     const point& sample,
 
     scalar& nearestDistSqr,
diff --git a/src/meshTools/indexedOctree/treeDataCell.H b/src/meshTools/indexedOctree/treeDataCell.H
index 7e42a6d9066..4bf5ddb5c23 100644
--- a/src/meshTools/indexedOctree/treeDataCell.H
+++ b/src/meshTools/indexedOctree/treeDataCell.H
@@ -48,7 +48,7 @@ class primitiveMesh;
 template<class Type> class indexedOctree;
 
 /*---------------------------------------------------------------------------*\
-                           Class treeDataCell Declaration
+                        Class treeDataCell Declaration
 \*---------------------------------------------------------------------------*/
 
 class treeDataCell
@@ -72,6 +72,9 @@ class treeDataCell
         //- Calculate cell bounding box
         treeBoundBox calcCellBb(const label cellI) const;
 
+        //- Initialise all member data
+        void update();
+
 public:
 
     // Declare name of the class and its debug switch
@@ -85,7 +88,15 @@ public:
         (
             const bool cacheBb,
             const primitiveMesh&,
-            const labelList&
+            const unallocLabelList&
+        );
+
+        //- Construct from mesh and subset of cells, transferring contents
+        treeDataCell
+        (
+            const bool cacheBb,
+            const primitiveMesh&,
+            const Xfer<labelList>&
         );
 
         //- Construct from mesh. Uses all cells in mesh.
@@ -96,18 +107,18 @@ public:
 
         // Access
 
-            const labelList& cellLabels() const
+            inline const labelList& cellLabels() const
             {
                 return cellLabels_;
             }
 
-            const primitiveMesh& mesh() const
+            inline const primitiveMesh& mesh() const
             {
                 return mesh_;
             }
 
 
-            label size() const
+            inline label size() const
             {
                 return cellLabels_.size();
             }
@@ -153,7 +164,7 @@ public:
             //  Returns actual point and distance (squared)
             void findNearest
             (
-                const labelList& indices,
+                const unallocLabelList& indices,
                 const point& sample,
 
                 scalar& nearestDistSqr,
@@ -165,7 +176,7 @@ public:
             //  Returns point and distance (squared)
             void findNearest
             (
-                const labelList& indices,
+                const unallocLabelList& indices,
                 const linePointRef& ln,
 
                 treeBoundBox& tightest,
@@ -177,7 +188,7 @@ public:
                 notImplemented
                 (
                     "treeDataCell::findNearest"
-                    "(const labelList&, const linePointRef&, ..)"
+                    "(const unallocLabelList&, const linePointRef&, ..)"
                 );
             }
 
diff --git a/src/meshTools/indexedOctree/treeDataEdge.C b/src/meshTools/indexedOctree/treeDataEdge.C
index 0adc3b781cc..0a65f8ece81 100644
--- a/src/meshTools/indexedOctree/treeDataEdge.C
+++ b/src/meshTools/indexedOctree/treeDataEdge.C
@@ -43,15 +43,28 @@ Foam::treeBoundBox Foam::treeDataEdge::calcBb(const label edgeI) const
 }
 
 
+void Foam::treeDataEdge::update()
+{
+    if (cacheBb_)
+    {
+        bbs_.setSize(edgeLabels_.size());
+
+        forAll(edgeLabels_, i)
+        {
+            bbs_[i] = calcBb(edgeLabels_[i]);
+        }
+    }
+}
+
+
 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
 
-// Construct from components
 Foam::treeDataEdge::treeDataEdge
 (
     const bool cacheBb,
     const edgeList& edges,
     const pointField& points,
-    const labelList& edgeLabels
+    const unallocLabelList& edgeLabels
 )
 :
     edges_(edges),
@@ -59,15 +72,24 @@ Foam::treeDataEdge::treeDataEdge
     edgeLabels_(edgeLabels),
     cacheBb_(cacheBb)
 {
-    if (cacheBb_)
-    {
-        bbs_.setSize(edgeLabels_.size());
+    update();
+}
 
-        forAll(edgeLabels_, i)
-        {
-            bbs_[i] = calcBb(edgeLabels_[i]);
-        }
-    }
+
+Foam::treeDataEdge::treeDataEdge
+(
+    const bool cacheBb,
+    const edgeList& edges,
+    const pointField& points,
+    const Xfer<labelList>& edgeLabels
+)
+:
+    edges_(edges),
+    points_(points),
+    edgeLabels_(edgeLabels),
+    cacheBb_(cacheBb)
+{
+    update();
 }
 
 
@@ -121,7 +143,7 @@ bool Foam::treeDataEdge::overlaps
 // nearestPoint.
 void Foam::treeDataEdge::findNearest
 (
-    const labelList& indices,
+    const unallocLabelList& indices,
     const point& sample,
 
     scalar& nearestDistSqr,
@@ -131,7 +153,7 @@ void Foam::treeDataEdge::findNearest
 {
     forAll(indices, i)
     {
-        label index = indices[i];
+        const label index = indices[i];
 
         const edge& e = edges_[edgeLabels_[index]];
 
@@ -153,7 +175,7 @@ void Foam::treeDataEdge::findNearest
 //  Returns point and distance (squared)
 void Foam::treeDataEdge::findNearest
 (
-    const labelList& indices,
+    const unallocLabelList& indices,
     const linePointRef& ln,
 
     treeBoundBox& tightest,
@@ -167,7 +189,7 @@ void Foam::treeDataEdge::findNearest
 
     forAll(indices, i)
     {
-        label index = indices[i];
+        const label index = indices[i];
 
         const edge& e = edges_[edgeLabels_[index]];
 
diff --git a/src/meshTools/indexedOctree/treeDataEdge.H b/src/meshTools/indexedOctree/treeDataEdge.H
index 68f3a5924a3..8b7e54879fa 100644
--- a/src/meshTools/indexedOctree/treeDataEdge.H
+++ b/src/meshTools/indexedOctree/treeDataEdge.H
@@ -81,6 +81,9 @@ class treeDataEdge
         //- Calculate edge bounding box
         treeBoundBox calcBb(const label edgeI) const;
 
+        //- Initialise all member data
+        void update();
+
 public:
 
     // Declare name of the class and its debug switch
@@ -95,7 +98,17 @@ public:
             const bool cacheBb,
             const edgeList& edges,
             const pointField& points,
-            const labelList& edgeLabels
+            const unallocLabelList& edgeLabels
+        );
+
+        //- Construct from selected edges, transferring contents.
+        // !Holds references to edges and points
+        treeDataEdge
+        (
+            const bool cacheBb,
+            const edgeList& edges,
+            const pointField& points,
+            const Xfer<labelList>& edgeLabels
         );
 
 
@@ -139,7 +152,7 @@ public:
             //  Returns actual point and distance (squared)
             void findNearest
             (
-                const labelList& indices,
+                const unallocLabelList& indices,
                 const point& sample,
 
                 scalar& nearestDistSqr,
@@ -151,7 +164,7 @@ public:
             //  Returns point and distance (squared)
             void findNearest
             (
-                const labelList& indices,
+                const unallocLabelList& indices,
                 const linePointRef& ln,
 
                 treeBoundBox& tightest,
diff --git a/src/meshTools/indexedOctree/treeDataFace.C b/src/meshTools/indexedOctree/treeDataFace.C
index bf2bd722e5b..f8273bec03a 100644
--- a/src/meshTools/indexedOctree/treeDataFace.C
+++ b/src/meshTools/indexedOctree/treeDataFace.C
@@ -76,12 +76,27 @@ void Foam::treeDataFace::update()
 
 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
 
-// Construct from components
 Foam::treeDataFace::treeDataFace
 (
     const bool cacheBb,
     const primitiveMesh& mesh,
-    const labelList& faceLabels
+    const unallocLabelList& faceLabels
+)
+:
+    mesh_(mesh),
+    faceLabels_(faceLabels),
+    isTreeFace_(mesh.nFaces(), 0),
+    cacheBb_(cacheBb)
+{
+    update();
+}
+
+
+Foam::treeDataFace::treeDataFace
+(
+    const bool cacheBb,
+    const primitiveMesh& mesh,
+    const Xfer<labelList>& faceLabels
 )
 :
     mesh_(mesh),
@@ -467,7 +482,7 @@ bool Foam::treeDataFace::overlaps
 // nearestPoint.
 void Foam::treeDataFace::findNearest
 (
-    const labelList& indices,
+    const unallocLabelList& indices,
     const point& sample,
 
     scalar& nearestDistSqr,
@@ -477,7 +492,7 @@ void Foam::treeDataFace::findNearest
 {
     forAll(indices, i)
     {
-        label index = indices[i];
+        const label index = indices[i];
 
         const face& f = mesh_.faces()[faceLabels_[index]];
 
@@ -514,7 +529,7 @@ bool Foam::treeDataFace::intersects
         }
     }
 
-    label faceI = faceLabels_[index];
+    const label faceI = faceLabels_[index];
 
     const vector dir(end - start);
 
diff --git a/src/meshTools/indexedOctree/treeDataFace.H b/src/meshTools/indexedOctree/treeDataFace.H
index 4337f1b78d2..6dbb881dbb5 100644
--- a/src/meshTools/indexedOctree/treeDataFace.H
+++ b/src/meshTools/indexedOctree/treeDataFace.H
@@ -51,7 +51,7 @@ class primitiveMesh;
 class polyPatch;
 
 /*---------------------------------------------------------------------------*\
-                           Class treeDataFace Declaration
+                        Class treeDataFace Declaration
 \*---------------------------------------------------------------------------*/
 
 class treeDataFace
@@ -101,7 +101,15 @@ public:
         (
             const bool cacheBb,
             const primitiveMesh&,
-            const labelList&
+            const unallocLabelList&
+        );
+
+        //- Construct from mesh and subset of faces, transferring contents
+        treeDataFace
+        (
+            const bool cacheBb,
+            const primitiveMesh&,
+            const Xfer<labelList>&
         );
 
         //- Construct from mesh. Uses all faces in mesh.
@@ -115,17 +123,17 @@ public:
 
         // Access
 
-            const labelList& faceLabels() const
+            inline const labelList& faceLabels() const
             {
                 return faceLabels_;
             }
 
-            const primitiveMesh& mesh() const
+            inline const primitiveMesh& mesh() const
             {
                 return mesh_;
             }
 
-            label size() const
+            inline label size() const
             {
                 return faceLabels_.size();
             }
@@ -156,7 +164,7 @@ public:
             //  Returns actual point and distance (squared)
             void findNearest
             (
-                const labelList& indices,
+                const unallocLabelList& indices,
                 const point& sample,
 
                 scalar& nearestDistSqr,
@@ -168,7 +176,7 @@ public:
             //  Returns point and distance (squared)
             void findNearest
             (
-                const labelList& indices,
+                const unallocLabelList& indices,
                 const linePointRef& ln,
 
                 treeBoundBox& tightest,
@@ -180,7 +188,7 @@ public:
                 notImplemented
                 (
                     "treeDataFace::findNearest"
-                    "(const labelList&, const linePointRef&, ..)"
+                    "(const unallocLabelList&, const linePointRef&, ..)"
                 );
             }
 
diff --git a/src/meshTools/indexedOctree/treeDataPoint.C b/src/meshTools/indexedOctree/treeDataPoint.C
index db5f61e0010..ffdbfdd4e09 100644
--- a/src/meshTools/indexedOctree/treeDataPoint.C
+++ b/src/meshTools/indexedOctree/treeDataPoint.C
@@ -36,7 +36,6 @@ defineTypeNameAndDebug(Foam::treeDataPoint, 0);
 
 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
 
-// Construct from components
 Foam::treeDataPoint::treeDataPoint(const pointField& points)
 :
     points_(points)
@@ -78,7 +77,7 @@ bool Foam::treeDataPoint::overlaps
 // nearestPoint.
 void Foam::treeDataPoint::findNearest
 (
-    const labelList& indices,
+    const unallocLabelList& indices,
     const point& sample,
 
     scalar& nearestDistSqr,
@@ -88,7 +87,7 @@ void Foam::treeDataPoint::findNearest
 {
     forAll(indices, i)
     {
-        label index = indices[i];
+        const label index = indices[i];
 
         const point& pt = points_[index];
 
@@ -108,7 +107,7 @@ void Foam::treeDataPoint::findNearest
 //  Returns point and distance (squared)
 void Foam::treeDataPoint::findNearest
 (
-    const labelList& indices,
+    const unallocLabelList& indices,
     const linePointRef& ln,
 
     treeBoundBox& tightest,
@@ -122,7 +121,7 @@ void Foam::treeDataPoint::findNearest
 
     forAll(indices, i)
     {
-        label index = indices[i];
+        const label index = indices[i];
 
         const point& shapePt = points_[index];
 
diff --git a/src/meshTools/indexedOctree/treeDataPoint.H b/src/meshTools/indexedOctree/treeDataPoint.H
index c2522120f7c..236f8139b8d 100644
--- a/src/meshTools/indexedOctree/treeDataPoint.H
+++ b/src/meshTools/indexedOctree/treeDataPoint.H
@@ -69,14 +69,14 @@ public:
     // Constructors
 
         //- Construct from components. Holds reference to points!
-        treeDataPoint(const pointField& points);
+        treeDataPoint(const pointField&);
 
 
     // Member Functions
 
         // Access
 
-            label size() const
+            inline label size() const
             {
                 return points_.size();
             }
@@ -107,7 +107,7 @@ public:
             //  Returns actual point and distance (squared)
             void findNearest
             (
-                const labelList& indices,
+                const unallocLabelList& indices,
                 const point& sample,
 
                 scalar& nearestDistSqr,
@@ -119,7 +119,7 @@ public:
             //  Returns point and distance (squared)
             void findNearest
             (
-                const labelList& indices,
+                const unallocLabelList& indices,
                 const linePointRef& ln,
 
                 treeBoundBox& tightest,
diff --git a/src/meshTools/indexedOctree/treeDataPrimitivePatch.C b/src/meshTools/indexedOctree/treeDataPrimitivePatch.C
index ec4bcb54374..8fc75b77c50 100644
--- a/src/meshTools/indexedOctree/treeDataPrimitivePatch.C
+++ b/src/meshTools/indexedOctree/treeDataPrimitivePatch.C
@@ -477,7 +477,7 @@ void
 Foam::treeDataPrimitivePatch<Face, FaceList, PointField, PointType>::
 findNearest
 (
-    const labelList& indices,
+    const unallocLabelList& indices,
     const point& sample,
 
     scalar& nearestDistSqr,
@@ -489,7 +489,7 @@ findNearest
 
     forAll(indices, i)
     {
-        label index = indices[i];
+        const label index = indices[i];
 
         const face& f = patch_[index];
 
diff --git a/src/meshTools/indexedOctree/treeDataPrimitivePatch.H b/src/meshTools/indexedOctree/treeDataPrimitivePatch.H
index cf7b0cb1eb8..7c3757504b6 100644
--- a/src/meshTools/indexedOctree/treeDataPrimitivePatch.H
+++ b/src/meshTools/indexedOctree/treeDataPrimitivePatch.H
@@ -56,7 +56,7 @@ TemplateName(treeDataPrimitivePatch);
 
 
 /*---------------------------------------------------------------------------*\
-                           Class treeDataPrimitivePatch Declaration
+                   Class treeDataPrimitivePatch Declaration
 \*---------------------------------------------------------------------------*/
 
 template
@@ -151,7 +151,7 @@ public:
             //  Returns actual point and distance (squared)
             void findNearest
             (
-                const labelList& indices,
+                const unallocLabelList& indices,
                 const point& sample,
 
                 scalar& nearestDistSqr,
@@ -163,7 +163,7 @@ public:
             //  Returns point and distance (squared)
             void findNearest
             (
-                const labelList& indices,
+                const unallocLabelList& indices,
                 const linePointRef& ln,
 
                 treeBoundBox& tightest,
@@ -175,7 +175,7 @@ public:
                 notImplemented
                 (
                     "treeDataPrimitivePatch::findNearest"
-                    "(const labelList&, const linePointRef&, ..)"
+                    "(const unallocLabelList&, const linePointRef&, ..)"
                 );
             }
 
diff --git a/src/meshTools/indexedOctree/treeDataTriSurface.C b/src/meshTools/indexedOctree/treeDataTriSurface.C
index e0afe06906a..e0f6d1a9df3 100644
--- a/src/meshTools/indexedOctree/treeDataTriSurface.C
+++ b/src/meshTools/indexedOctree/treeDataTriSurface.C
@@ -313,7 +313,7 @@ bool Foam::treeDataTriSurface::overlaps
 // nearestPoint.
 void Foam::treeDataTriSurface::findNearest
 (
-    const labelList& indices,
+    const unallocLabelList& indices,
     const point& sample,
 
     scalar& nearestDistSqr,
@@ -396,7 +396,7 @@ void Foam::treeDataTriSurface::findNearest
 // nearestPoint.
 void Foam::treeDataTriSurface::findNearest
 (
-    const labelList& indices,
+    const unallocLabelList& indices,
     const linePointRef& ln,
 
     treeBoundBox& tightest,
@@ -407,7 +407,7 @@ void Foam::treeDataTriSurface::findNearest
 {
     notImplemented
     (
-        "treeDataTriSurface::findNearest(const labelList&"
+        "treeDataTriSurface::findNearest(const unallocLabelList&"
         ", const linePointRef&, treeBoundBox&, label&, point&, point&) const"
     );
 }
diff --git a/src/meshTools/indexedOctree/treeDataTriSurface.H b/src/meshTools/indexedOctree/treeDataTriSurface.H
index 88f92c0ba4e..f602783afef 100644
--- a/src/meshTools/indexedOctree/treeDataTriSurface.H
+++ b/src/meshTools/indexedOctree/treeDataTriSurface.H
@@ -91,12 +91,12 @@ public:
 
         // Access
 
-            const triSurface& surface() const
+            inline const triSurface& surface() const
             {
                 return surface_;
             }
 
-            label size() const
+            inline label size() const
             {
                 return surface_.size();
             }
@@ -127,7 +127,7 @@ public:
             //  Returns actual point and distance (squared)
             void findNearest
             (
-                const labelList& indices,
+                const unallocLabelList& indices,
                 const point& sample,
 
                 scalar& nearestDistSqr,
@@ -139,7 +139,7 @@ public:
             //  Returns point and distance (squared)
             void findNearest
             (
-                const labelList& indices,
+                const unallocLabelList& indices,
                 const linePointRef& ln,
 
                 treeBoundBox& tightest,
-- 
GitLab