diff --git a/src/meshTools/indexedOctree/treeDataEdge.C b/src/meshTools/indexedOctree/treeDataEdge.C index 99c6e65fbe..670e7fb8c7 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 341df0e9f8..d4e9216bbe 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 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 1586249c8e..987f3ba304 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 d097c04cd7..9aab4cd3e4 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 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& 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 51c87e68d0..61d8016302 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 f5b259faeb..95af6f95a9 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 indexedOctree; /*---------------------------------------------------------------------------*\ - Class treeDataPoint Declaration + Class treeDataPoint Declaration \*---------------------------------------------------------------------------*/ class treeDataPoint { - // Private data + // Private Data const pointField& points_; @@ -110,8 +110,8 @@ public: findIntersectOp(const indexedOctree& 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 - { - return points_; - } - - bool useSubset() const + //- Use a subset of points + inline bool useSubset() const { return useSubset_; } - //- Get representative point cloud for all shapes inside - // (one point per shape) + //- The original (non-subset) point label + inline label pointLabel(const label index) const + { + 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] + ); + } + + //- 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&, - const point& + const indexedOctree& 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 5fb5a1cb48..e97dc0bbec 100644 --- a/src/meshTools/indexedOctree/treeDataPrimitivePatch.C +++ b/src/meshTools/indexedOctree/treeDataPrimitivePatch.C @@ -475,13 +475,12 @@ void Foam::treeDataPrimitivePatch::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 5327ae1fee..d77840053e 100644 --- a/src/meshTools/indexedOctree/treeDataPrimitivePatch.H +++ b/src/meshTools/indexedOctree/treeDataPrimitivePatch.H @@ -130,8 +130,8 @@ public: findIntersectOp(const indexedOctree& 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