diff --git a/src/meshTools/indexedOctree/treeDataEdge.C b/src/meshTools/indexedOctree/treeDataEdge.C index 99c6e65fbe54760a88b05cf8070fa0d8cebaeb28..670e7fb8c7ee8dd71ef48a165f6bad5af8fe6b0c 100644 --- a/src/meshTools/indexedOctree/treeDataEdge.C +++ b/src/meshTools/indexedOctree/treeDataEdge.C @@ -170,12 +170,7 @@ bool Foam::treeDataEdge::overlaps const scalar distSqr = sqr(nearHit.distance()); - if (distSqr <= radiusSqr) - { - return true; - } - - return false; + return (distSqr <= radiusSqr); } @@ -191,15 +186,13 @@ void Foam::treeDataEdge::findNearestOp::operator() { const treeDataEdge& shape = tree_.shapes(); - forAll(indices, i) + for (const label index : indices) { - const label index = indices[i]; - const edge& e = shape.edges()[shape.edgeLabels()[index]]; pointHit nearHit = e.line(shape.points()).nearestDist(sample); - scalar distSqr = sqr(nearHit.distance()); + const scalar distSqr = sqr(nearHit.distance()); if (distSqr < nearestDistSqr) { @@ -227,10 +220,8 @@ void Foam::treeDataEdge::findNearestOp::operator() // Best so far scalar nearestDistSqr = magSqr(linePoint - nearestPoint); - forAll(indices, i) + for (const label index : indices) { - const label index = indices[i]; - const edge& e = shape.edges()[shape.edgeLabels()[index]]; // Note: could do bb test ? Worthwhile? diff --git a/src/meshTools/indexedOctree/treeDataEdge.H b/src/meshTools/indexedOctree/treeDataEdge.H index 341df0e9f8d9e285cb1ed6e10de90ceb24c68176..d4e9216bbe8fa27c46e69afc42b3fd348481d038 100644 --- a/src/meshTools/indexedOctree/treeDataEdge.H +++ b/src/meshTools/indexedOctree/treeDataEdge.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | + \\ / A nd | Copyright (C) 2019 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- | Copyright (C) 2011-2015 OpenFOAM Foundation @@ -55,13 +55,13 @@ template<class Type> class indexedOctree; class treeDataEdge { - // Static data + // Static Data //- Tolerance on linear dimensions static scalar tol; - // Private data + // Private Data //- Reference to edgeList const edgeList& edges_; @@ -145,7 +145,8 @@ public: // Constructors - //- Construct from selected edges. !Holds references to edges and points + //- Construct from selected edges. + // \note Holds references to edges and points! treeDataEdge ( const bool cacheBb, @@ -155,7 +156,7 @@ public: ); //- Construct from selected edges, transferring contents. - // !Holds references to edges and points + // \note Holds references to edges and points! treeDataEdge ( const bool cacheBb, @@ -189,8 +190,8 @@ public: return edgeLabels_.size(); } - //- Get representative point cloud for all shapes inside - // (one point per shape) + //- Representative point cloud for all shapes inside + //- (one point per shape) pointField shapePoints() const; diff --git a/src/meshTools/indexedOctree/treeDataFace.C b/src/meshTools/indexedOctree/treeDataFace.C index 1586249c8e802437f094271a49016d979a216b5c..987f3ba3046fb7b1233c7b65fad34f2848d49e8a 100644 --- a/src/meshTools/indexedOctree/treeDataFace.C +++ b/src/meshTools/indexedOctree/treeDataFace.C @@ -479,10 +479,8 @@ void Foam::treeDataFace::findNearestOp::operator() { const treeDataFace& shape = tree_.shapes(); - forAll(indices, i) + for (const label index : indices) { - const label index = indices[i]; - const face& f = shape.mesh().faces()[shape.faceLabels()[index]]; pointHit nearHit = f.nearestPoint(sample, shape.mesh().points()); diff --git a/src/meshTools/indexedOctree/treeDataFace.H b/src/meshTools/indexedOctree/treeDataFace.H index d097c04cd7b0fb846ec2852841281db2fb528c45..9aab4cd3e4b877256d390f6753f7ab11392d7d88 100644 --- a/src/meshTools/indexedOctree/treeDataFace.H +++ b/src/meshTools/indexedOctree/treeDataFace.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | + \\ / A nd | Copyright (C) 2019 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- | Copyright (C) 2011-2016 OpenFOAM Foundation @@ -50,8 +50,6 @@ namespace Foam { // Forward declaration of classes -//class primitiveMesh; -//template<class Type> class indexedOctree; class polyPatch; /*---------------------------------------------------------------------------*\ @@ -60,13 +58,13 @@ class polyPatch; class treeDataFace { - // Static data + // Static Data //- Tolerance on linear dimensions static scalar tolSqr; - // Private data + // Private Data const primitiveMesh& mesh_; @@ -133,8 +131,8 @@ public: findIntersectOp(const indexedOctree<treeDataFace>& tree); - //- Calculate intersection of triangle with ray. Sets result - // accordingly + //- Calculate intersection of triangle with ray. + // Sets result accordingly bool operator() ( const label index, @@ -152,7 +150,6 @@ public: // Constructors //- Construct from mesh, copying subset of faces - //- Construct from mesh and subset of faces. treeDataFace ( const bool cacheBb, @@ -194,8 +191,8 @@ public: return faceLabels_.size(); } - //- Get representative point cloud for all shapes inside - // (one point per shape) + //- Representative point cloud for all shapes inside + //- (one point per shape) pointField shapePoints() const; diff --git a/src/meshTools/indexedOctree/treeDataPoint.C b/src/meshTools/indexedOctree/treeDataPoint.C index 51c87e68d01232190125932509f3628d9cc4e533..61d801630267ffdbaf31b02f334b42bd3fb99a2e 100644 --- a/src/meshTools/indexedOctree/treeDataPoint.C +++ b/src/meshTools/indexedOctree/treeDataPoint.C @@ -50,12 +50,26 @@ Foam::treeDataPoint::treeDataPoint(const pointField& points) Foam::treeDataPoint::treeDataPoint ( const pointField& points, - const labelList& pointLabels + const labelUList& pointLabels, + const bool useSubsetPoints ) : points_(points), pointLabels_(pointLabels), - useSubset_(true) + useSubset_(useSubsetPoints) +{} + + +Foam::treeDataPoint::treeDataPoint +( + const pointField& points, + labelList&& pointLabels, + const bool useSubsetPoints +) +: + points_(points), + pointLabels_(std::move(pointLabels)), + useSubset_(useSubsetPoints) {} @@ -104,8 +118,7 @@ bool Foam::treeDataPoint::overlaps const treeBoundBox& cubeBb ) const { - label pointi = (useSubset_ ? pointLabels_[index] : index); - return cubeBb.contains(points_[pointi]); + return cubeBb.contains(shapePoint(index)); } @@ -116,14 +129,7 @@ bool Foam::treeDataPoint::overlaps const scalar radiusSqr ) const { - label pointi = (useSubset_ ? pointLabels_[index] : index); - - if (magSqr(points_[pointi] - centre) <= radiusSqr) - { - return true; - } - - return false; + return (magSqr(shapePoint(index) - centre) <= radiusSqr); } @@ -139,19 +145,11 @@ void Foam::treeDataPoint::findNearestOp::operator() { const treeDataPoint& shape = tree_.shapes(); - forAll(indices, i) + for (const label index : indices) { - const label index = indices[i]; - label pointi = - ( - shape.useSubset() - ? shape.pointLabels()[index] - : index - ); + const point& pt = shape.shapePoint(index); - const point& pt = shape.points()[pointi]; - - scalar distSqr = magSqr(pt - sample); + const scalar distSqr = magSqr(pt - sample); if (distSqr < nearestDistSqr) { @@ -183,23 +181,15 @@ void Foam::treeDataPoint::findNearestOp::operator() nearestDistSqr = magSqr(linePoint - nearestPoint); } - forAll(indices, i) + for (const label index : indices) { - const label index = indices[i]; - label pointi = - ( - shape.useSubset() - ? shape.pointLabels()[index] - : index - ); - - const point& shapePt = shape.points()[pointi]; + const point& shapePt = shape.shapePoint(index); if (tightest.contains(shapePt)) { // Nearest point on line pointHit pHit = ln.nearestDist(shapePt); - scalar distSqr = sqr(pHit.distance()); + const scalar distSqr = sqr(pHit.distance()); if (distSqr < nearestDistSqr) { diff --git a/src/meshTools/indexedOctree/treeDataPoint.H b/src/meshTools/indexedOctree/treeDataPoint.H index f5b259faeb9dadbc311d950c0cb2bf18c49581de..95af6f95a95f686591e7bbd1438b9016f3f18879 100644 --- a/src/meshTools/indexedOctree/treeDataPoint.H +++ b/src/meshTools/indexedOctree/treeDataPoint.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | + \\ / A nd | Copyright (C) 2019 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- | Copyright (C) 2011-2013 OpenFOAM Foundation @@ -52,16 +52,16 @@ SourceFiles namespace Foam { -// Forward declaration of classes +// Forward declarations template<class Type> class indexedOctree; /*---------------------------------------------------------------------------*\ - Class treeDataPoint Declaration + Class treeDataPoint Declaration \*---------------------------------------------------------------------------*/ class treeDataPoint { - // Private data + // Private Data const pointField& points_; @@ -110,8 +110,8 @@ public: findIntersectOp(const indexedOctree<treeDataPoint>& tree); - //- Calculate intersection of triangle with ray. Sets result - // accordingly + //- Calculate intersection of triangle with ray. + // Sets result accordingly bool operator() ( const label index, @@ -128,17 +128,45 @@ public: // Constructors - //- Construct from pointField. Holds reference! - treeDataPoint(const pointField&); + //- Construct from pointField + // \note Holds reference to the points! + explicit treeDataPoint(const pointField& points); - //- Construct from subset of pointField. Holds reference! - treeDataPoint(const pointField&, const labelList&); + //- Construct from subset of pointField, copies point ids + // \note Holds reference to the points! + treeDataPoint + ( + const pointField& points, + const labelUList& pointLabels, + const bool useSubsetPoints = true + ); + + //- Construct from subset of pointField, moves point ids + // \note Holds reference to the points! + treeDataPoint + ( + const pointField& points, + labelList&& pointLabels, + const bool useSubsetPoints = true + ); // Member Functions // Access + //- An empty effective point field? + inline bool empty() const + { + return + ( + useSubset_ + ? pointLabels_.empty() + : points_.empty() + ); + } + + //- The effective point field size inline label size() const { return @@ -149,23 +177,48 @@ public: ); } + //- The original point field + inline const pointField& points() const + { + return points_; + } + + //- The original point ids inline const labelList& pointLabels() const { return pointLabels_; } - const pointField& points() const + //- Use a subset of points + inline bool useSubset() const { - return points_; + return useSubset_; } - bool useSubset() const + //- The original (non-subset) point label + inline label pointLabel(const label index) const { - return useSubset_; + return + ( + useSubset_ && index >= 0 + ? pointLabels_[index] + : index + ); + } + + //- Point at specified index + inline const point& shapePoint(const label index) const + { + return + ( + useSubset_ + ? points_[pointLabels_[index]] + : points_[index] + ); } - //- Get representative point cloud for all shapes inside - // (one point per shape) + //- Representative point cloud for all shapes inside + //- (one point per shape) pointField shapePoints() const; @@ -175,8 +228,8 @@ public: // Only makes sense for closed surfaces. volumeType getVolumeType ( - const indexedOctree<treeDataPoint>&, - const point& + const indexedOctree<treeDataPoint>& os, + const point& sample ) const; //- Does (bb of) shape at index overlap bb @@ -193,6 +246,15 @@ public: const point& centre, const scalar radiusSqr ) const; + + + // Member Operators + + //- The point at the specified index + inline const point& operator[](const label index) const + { + return shapePoint(index); + } }; diff --git a/src/meshTools/indexedOctree/treeDataPrimitivePatch.C b/src/meshTools/indexedOctree/treeDataPrimitivePatch.C index 5fb5a1cb481c002c5d324b3f5487f7a87f89de7b..e97dc0bbec0fcaf245157df9400e360d63d6e748 100644 --- a/src/meshTools/indexedOctree/treeDataPrimitivePatch.C +++ b/src/meshTools/indexedOctree/treeDataPrimitivePatch.C @@ -475,13 +475,12 @@ void Foam::treeDataPrimitivePatch<PatchType>::findNearestOp::operator() const pointField& points = patch.points(); - forAll(indices, i) + for (const label index : indices) { - const label index = indices[i]; const typename PatchType::FaceType& f = patch[index]; - pointHit nearHit = f.nearestPoint(sample, points); - scalar distSqr = sqr(nearHit.distance()); + const pointHit nearHit = f.nearestPoint(sample, points); + const scalar distSqr = sqr(nearHit.distance()); if (distSqr < nearestDistSqr) { diff --git a/src/meshTools/indexedOctree/treeDataPrimitivePatch.H b/src/meshTools/indexedOctree/treeDataPrimitivePatch.H index 5327ae1feed9acea1226ec53e5ffdbf718e58f47..d77840053e7deb53e1948060667ec778e1f91a50 100644 --- a/src/meshTools/indexedOctree/treeDataPrimitivePatch.H +++ b/src/meshTools/indexedOctree/treeDataPrimitivePatch.H @@ -130,8 +130,8 @@ public: findIntersectOp(const indexedOctree<treeDataPrimitivePatch>& tree); - //- Calculate intersection of any face with ray. Sets result - // accordingly. Used to find first intersection. + //- Calculate intersection of any face with ray. + // Sets result accordingly. Used to find first intersection. bool operator() ( const label index, @@ -156,8 +156,8 @@ public: DynamicList<label>& shapeMask ); - //- Calculate intersection of unique face with ray. Sets result - // accordingly. Used to find all faces. + //- Calculate intersection of unique face with ray. + // Sets result accordingly. Used to find all faces. bool operator() ( const label index, @@ -182,8 +182,8 @@ public: const label edgeID ); - //- Calculate intersection of face with edge of patch. Excludes - // faces that use edgeID. Used to find self intersection. + //- Calculate intersection of face with edge of patch. + // Excludes faces that use edgeID. Used to find self intersection. bool operator() ( const label index, @@ -214,8 +214,8 @@ public: return patch_.size(); } - //- Get representative point cloud for all shapes inside - // (one point per shape) + //- Representative point cloud for all shapes inside + //- (one point per shape) pointField shapePoints() const; //- Return access to the underlying patch diff --git a/src/meshTools/indexedOctree/treeDataTriSurface.C b/src/meshTools/indexedOctree/treeDataTriSurface.C index a93347d53c55322e9029b526a2c77b021f4fc327..de5f5cf94ddc3382e9ac1b3f2a88eb229336a352 100644 --- a/src/meshTools/indexedOctree/treeDataTriSurface.C +++ b/src/meshTools/indexedOctree/treeDataTriSurface.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | + \\ / A nd | Copyright (C) 2019 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- | Copyright (C) 2011-2016 OpenFOAM Foundation @@ -38,7 +38,7 @@ Foam::volumeType Foam::treeDataPrimitivePatch<Foam::triSurface>::getVolumeType ) const { // Find nearest face to sample - pointIndexHit info = oc.findNearest(sample, sqr(GREAT)); + const pointIndexHit info = oc.findNearest(sample, sqr(GREAT)); if (info.index() == -1) { @@ -48,9 +48,9 @@ Foam::volumeType Foam::treeDataPrimitivePatch<Foam::triSurface>::getVolumeType } // Get actual intersection point on face - label facei = info.index(); + const label facei = info.index(); - triSurfaceTools::sideType t = triSurfaceTools::surfaceSide + const triSurfaceTools::sideType t = triSurfaceTools::surfaceSide ( patch_, sample, diff --git a/src/meshTools/indexedOctree/treeDataTriSurface.H b/src/meshTools/indexedOctree/treeDataTriSurface.H index ef9c88385c9cffa61c5d71b010009109e29d16c0..856cbefb6bc4955fbe78ba2defefd940a0fc1642 100644 --- a/src/meshTools/indexedOctree/treeDataTriSurface.H +++ b/src/meshTools/indexedOctree/treeDataTriSurface.H @@ -61,7 +61,6 @@ namespace Foam // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - #endif // ************************************************************************* //