diff --git a/applications/utilities/mesh/generation/extrudeMesh/extrudeMesh.C b/applications/utilities/mesh/generation/extrudeMesh/extrudeMesh.C index d38ab5a659..0bb37f6727 100644 --- a/applications/utilities/mesh/generation/extrudeMesh/extrudeMesh.C +++ b/applications/utilities/mesh/generation/extrudeMesh/extrudeMesh.C @@ -178,8 +178,7 @@ int main(int argc, char *argv[]) const boundBox& bb = mesh.globalData().bb(); const vector span = bb.span(); - const scalar minDim = min(span[0], min(span[1], span[2])); - const scalar mergeDim = 1E-4 * minDim; + const scalar mergeDim = 1E-4 * bb.minDim(); Pout<< "Mesh bounding box:" << bb << nl << " with span:" << span << nl diff --git a/src/OpenFOAM/meshes/boundBox/boundBox.C b/src/OpenFOAM/meshes/boundBox/boundBox.C index d11fcfc04c..9ff80d26fa 100644 --- a/src/OpenFOAM/meshes/boundBox/boundBox.C +++ b/src/OpenFOAM/meshes/boundBox/boundBox.C @@ -26,9 +26,12 @@ License #include "boundBox.H" #include "PstreamReduceOps.H" +#include "tmp.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // +const Foam::scalar Foam::boundBox::great(VGREAT); + const Foam::boundBox Foam::boundBox::greatBox ( point(-VGREAT, -VGREAT, -VGREAT), @@ -43,16 +46,16 @@ const Foam::boundBox Foam::boundBox::invertedBox ); -// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // -Foam::boundBox::boundBox(const pointField& points, const bool doReduce) -: - min_(point::zero), - max_(point::zero) +void Foam::boundBox::calculate(const pointField& points, const bool doReduce) { if (points.size() == 0) { - if (Pstream::parRun() && doReduce) + min_ = point::zero; + max_ = point::zero; + + if (doReduce && Pstream::parRun()) { // Use values that get overwritten by reduce minOp, maxOp below min_ = point(VGREAT, VGREAT, VGREAT); @@ -64,22 +67,43 @@ Foam::boundBox::boundBox(const pointField& points, const bool doReduce) min_ = points[0]; max_ = points[0]; - forAll(points, i) + for (label i = 1; i < points.size(); i++) { min_ = ::Foam::min(min_, points[i]); max_ = ::Foam::max(max_, points[i]); } } + // Reduce parallel information if (doReduce) { - // Reduce parallel information reduce(min_, minOp()); reduce(max_, maxOp()); } } +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::boundBox::boundBox(const pointField& points, const bool doReduce) +: + min_(point::zero), + max_(point::zero) +{ + calculate(points, doReduce); +} + + +Foam::boundBox::boundBox(const tmp& points, const bool doReduce) +: + min_(point::zero), + max_(point::zero) +{ + calculate(points(), doReduce); + points.clear(); +} + + Foam::boundBox::boundBox(Istream& is) { operator>>(is, *this); diff --git a/src/OpenFOAM/meshes/boundBox/boundBox.H b/src/OpenFOAM/meshes/boundBox/boundBox.H index 82fac0b1e3..927ff3dc5b 100644 --- a/src/OpenFOAM/meshes/boundBox/boundBox.H +++ b/src/OpenFOAM/meshes/boundBox/boundBox.H @@ -43,12 +43,13 @@ namespace Foam // Forward declaration of friend functions and operators class boundBox; +template class tmp; Ostream& operator<<(Ostream& os, const boundBox& b); /*---------------------------------------------------------------------------*\ - Class boundBox Declaration + Class boundBox Declaration \*---------------------------------------------------------------------------*/ class boundBox @@ -58,11 +59,19 @@ class boundBox //- Minimum and maximum describing the bounding box point min_, max_; + // Private Member Functions + + //- Calculate the bounding box from the given pointField. + // Does parallel communication (doReduce = true) + void calculate(const pointField&, const bool doReduce = true); public: // Static data members + //- The great value used for greatBox and invertedBox + static const scalar great; + //- A very large boundBox: min/max == -/+ VGREAT static const boundBox greatBox; @@ -88,7 +97,11 @@ public: //- Construct as the bounding box of the given pointField. // Does parallel communication (doReduce = true) - boundBox(const pointField& points, const bool doReduce = true); + boundBox(const pointField&, const bool doReduce = true); + + //- Construct as the bounding box of the given temporary pointField. + // Does parallel communication (doReduce = true) + boundBox(const tmp&, const bool doReduce = true); //- Construct from Istream boundBox(Istream&); @@ -122,6 +135,12 @@ public: return max_; } + //- The midpoint of the bounding box + point midpoint() const + { + return 0.5 * (max_ + min_); + } + //- The bounding box span (from minimum to maximum) vector span() const { @@ -134,28 +153,57 @@ public: return ::Foam::mag(max_ - min_); } + //- Smallest length/height/width dimension + scalar minDim() const + { + return cmptMin(span()); + } + + //- Largest length/height/width dimension + scalar maxDim() const + { + return cmptMax(span()); + } + + //- Average length/height/width dimension + scalar avgDim() const + { + return cmptAv(span()); + } + // Query - //- Intersects other boundingBox? + //- Completely contains other boundingBox? (inside or on edge) bool overlaps(const boundBox& bb) const { return ( - min_.x() <= bb.max().x() && max_.x() >= bb.min().x() - && min_.y() <= bb.max().y() && max_.y() >= bb.min().y() - && min_.z() <= bb.max().z() && max_.z() >= bb.min().z() + bb.max_.x() >= min_.x() && bb.min_.x() <= max_.x() + && bb.max_.y() >= min_.y() && bb.min_.y() <= max_.y() + && bb.max_.z() >= min_.z() && bb.min_.z() <= max_.z() ); } - //- Contains a point? + //- Contains point? (inside or on edge) bool contains(const point& pt) const { return ( - pt.x() >= min().x() && pt.x() <= max().x() - && pt.y() >= min().y() && pt.y() <= max().y() - && pt.z() >= min().z() && pt.z() <= max().z() + pt.x() >= min_.x() && pt.x() <= max_.x() + && pt.y() >= min_.y() && pt.y() <= max_.y() + && pt.z() >= min_.z() && pt.z() <= max_.z() + ); + } + + //- Contains point? (inside only) + bool containsInside(const point& pt) const + { + return + ( + pt.x() > min_.x() && pt.x() < max_.x() + && pt.y() > min_.y() && pt.y() < max_.y() + && pt.z() > min_.z() && pt.z() < max_.z() ); } @@ -189,6 +237,8 @@ inline bool contiguous() {return contiguous();} } // End namespace Foam +// #include "boundBoxI.H" + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // #endif diff --git a/src/OpenFOAM/meshes/polyMesh/globalMeshData/globalMeshData.C b/src/OpenFOAM/meshes/polyMesh/globalMeshData/globalMeshData.C index b51330b762..121b2a643e 100644 --- a/src/OpenFOAM/meshes/polyMesh/globalMeshData/globalMeshData.C +++ b/src/OpenFOAM/meshes/polyMesh/globalMeshData/globalMeshData.C @@ -728,8 +728,8 @@ void Foam::globalMeshData::updateMesh() // Do processor patch addressing initProcAddr(); - // Bounding box (does communication) - bb_ = boundBox(mesh_.points(), true); + // Note: boundBox does reduce + bb_ = boundBox(mesh_.points()); scalar tolDim = matchTol_ * bb_.mag(); @@ -740,7 +740,6 @@ void Foam::globalMeshData::updateMesh() } - // Option 1. Topological { // Calculate all shared points. This does all the hard work. @@ -770,7 +769,7 @@ void Foam::globalMeshData::updateMesh() // processor faces (on highest numbered processor) before summing. nTotalFaces_ = mesh_.nFaces(); - // Do not count processorpatch faces that are coincident. + // Do not count processor-patch faces that are coincident. forAll(processorPatches_, i) { label patchI = processorPatches_[i]; diff --git a/src/dynamicMesh/boundaryMesh/boundaryMesh.C b/src/dynamicMesh/boundaryMesh/boundaryMesh.C index d40764b07b..28396e2918 100644 --- a/src/dynamicMesh/boundaryMesh/boundaryMesh.C +++ b/src/dynamicMesh/boundaryMesh/boundaryMesh.C @@ -902,7 +902,7 @@ Foam::labelList Foam::boundaryMesh::getNearest // Extend domain slightly (also makes it 3D if was 2D) // Note asymmetry to avoid having faces align with octree cubes. - scalar tol = 1E-6*overallBb.avgDim(); + scalar tol = 1E-6 * overallBb.avgDim(); point& bbMin = overallBb.min(); bbMin.x() -= tol; diff --git a/src/fvMotionSolver/fvMotionSolvers/displacement/SBRStress/displacementSBRStressFvMotionSolver.C b/src/fvMotionSolver/fvMotionSolvers/displacement/SBRStress/displacementSBRStressFvMotionSolver.C index ac4144c60f..68f7280c19 100644 --- a/src/fvMotionSolver/fvMotionSolvers/displacement/SBRStress/displacementSBRStressFvMotionSolver.C +++ b/src/fvMotionSolver/fvMotionSolvers/displacement/SBRStress/displacementSBRStressFvMotionSolver.C @@ -224,8 +224,8 @@ void Foam::displacementSBRStressFvMotionSolver::updateMesh ); // Note: boundBox does reduce - const vector span0 = boundBox(points0_, true).span(); - const vector span = boundBox(points, true).span(); + const vector span0 = boundBox(points0_).span(); + const vector span = boundBox(points).span(); vector scaleFactors(cmptDivide(span0, span)); @@ -246,13 +246,11 @@ void Foam::displacementSBRStressFvMotionSolver::updateMesh else { // New point. Assume motion is scaling. - newPoints0[pointI] = - points0_[oldPointI] - + cmptMultiply - ( - scaleFactors, - points[pointI]-points[masterPointI] - ); + newPoints0[pointI] = points0_[oldPointI] + cmptMultiply + ( + scaleFactors, + points[pointI]-points[masterPointI] + ); } } else diff --git a/src/fvMotionSolver/fvMotionSolvers/displacement/interpolation/displacementInterpolationFvMotionSolver.C b/src/fvMotionSolver/fvMotionSolvers/displacement/interpolation/displacementInterpolationFvMotionSolver.C index fc1a4afe07..dfb7d4ac61 100644 --- a/src/fvMotionSolver/fvMotionSolvers/displacement/interpolation/displacementInterpolationFvMotionSolver.C +++ b/src/fvMotionSolver/fvMotionSolvers/displacement/interpolation/displacementInterpolationFvMotionSolver.C @@ -433,8 +433,8 @@ void Foam::displacementInterpolationFvMotionSolver::updateMesh ); // Note: boundBox does reduce - const vector span0 = boundBox(points0_, true).span(); - const vector span = boundBox(points, true).span(); + const vector span0 = boundBox(points0_).span(); + const vector span = boundBox(points).span(); vector scaleFactors(cmptDivide(span0, span)); @@ -455,13 +455,11 @@ void Foam::displacementInterpolationFvMotionSolver::updateMesh else { // New point. Assume motion is scaling. - newPoints0[pointI] = - points0_[oldPointI] - + cmptMultiply - ( - scaleFactors, - points[pointI]-points[masterPointI] - ); + newPoints0[pointI] = points0_[oldPointI] + cmptMultiply + ( + scaleFactors, + points[pointI]-points[masterPointI] + ); } } else diff --git a/src/fvMotionSolver/fvMotionSolvers/displacement/laplacian/displacementLaplacianFvMotionSolver.C b/src/fvMotionSolver/fvMotionSolvers/displacement/laplacian/displacementLaplacianFvMotionSolver.C index 502dd0c5b2..a979feebb3 100644 --- a/src/fvMotionSolver/fvMotionSolvers/displacement/laplacian/displacementLaplacianFvMotionSolver.C +++ b/src/fvMotionSolver/fvMotionSolvers/displacement/laplacian/displacementLaplacianFvMotionSolver.C @@ -272,8 +272,8 @@ void Foam::displacementLaplacianFvMotionSolver::updateMesh ); // Note: boundBox does reduce - const vector span0 = boundBox(points0_, true).span(); - const vector span = boundBox(points, true).span(); + const vector span0 = boundBox(points0_).span(); + const vector span = boundBox(points).span(); vector scaleFactors(cmptDivide(span0, span)); @@ -294,13 +294,11 @@ void Foam::displacementLaplacianFvMotionSolver::updateMesh else { // New point. Assume motion is scaling. - newPoints0[pointI] = - points0_[oldPointI] - + cmptMultiply - ( - scaleFactors, - points[pointI]-points[masterPointI] - ); + newPoints0[pointI] = points0_[oldPointI] + cmptMultiply + ( + scaleFactors, + points[pointI]-points[masterPointI] + ); } } else diff --git a/src/meshTools/cellClassification/cellClassification.C b/src/meshTools/cellClassification/cellClassification.C index b907160ab6..9adf4c6526 100644 --- a/src/meshTools/cellClassification/cellClassification.C +++ b/src/meshTools/cellClassification/cellClassification.C @@ -63,7 +63,7 @@ Foam::label Foam::cellClassification::count } } return cnt; - + } @@ -150,7 +150,7 @@ Foam::boolList Foam::cellClassification::markFaces treeBoundBox allBb(mesh_.points()); // Extend domain slightly (also makes it 3D if was 2D) - scalar tol = 1E-6*allBb.avgDim(); + scalar tol = 1E-6 * allBb.avgDim(); point& bbMin = allBb.min(); bbMin.x() -= tol; @@ -166,9 +166,9 @@ Foam::boolList Foam::cellClassification::markFaces ( treeDataFace(false, mesh_, allFaces), allBb, // overall search domain - 8, // maxLevel - 10, // leafsize - 3.0 // duplicity + 8, // maxLevel + 10, // leafsize + 3.0 // duplicity ); const triSurface& surf = search.surface(); @@ -359,7 +359,7 @@ void Foam::cellClassification::classifyPoints const labelList& pCells = mesh_.pointCells()[pointI]; pointSide[pointI] = UNSET; - + forAll(pCells, i) { label type = cellType[pCells[i]]; @@ -665,7 +665,7 @@ Foam::label Foam::cellClassification::growSurface nChanged++; } - } + } } } return nChanged; @@ -694,7 +694,7 @@ Foam::label Foam::cellClassification::fillHangingCells classifyPoints(meshType, *this, pointSide); // Check all cells using mixed point type for whether they use mixed - // points only. Note: could probably speed this up by counting number + // points only. Note: could probably speed this up by counting number // of mixed verts per face and mixed faces per cell or something? forAll(pointSide, pointI) { @@ -800,7 +800,7 @@ Foam::label Foam::cellClassification::fillRegionEdges return nTotChanged; } - + Foam::label Foam::cellClassification::fillRegionPoints ( diff --git a/src/meshTools/indexedOctree/indexedOctree.C b/src/meshTools/indexedOctree/indexedOctree.C index b58850d095..233dac95f5 100644 --- a/src/meshTools/indexedOctree/indexedOctree.C +++ b/src/meshTools/indexedOctree/indexedOctree.C @@ -26,21 +26,16 @@ License #include "indexedOctree.H" #include "linePointRef.H" -//#include "triSurface.H" +// #include "triSurface.H" #include "meshTools.H" #include "OFstream.H" -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -namespace Foam -{ - // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // Does bb intersect a sphere around sample? Or is any corner point of bb // closer than nearestDistSqr to sample. template -bool indexedOctree::overlaps +bool Foam::indexedOctree::overlaps ( const point& p0, const point& p1, @@ -84,7 +79,7 @@ bool indexedOctree::overlaps // Does bb intersect a sphere around sample? Or is any corner point of bb // closer than nearestDistSqr to sample. template -bool indexedOctree::overlaps +bool Foam::indexedOctree::overlaps ( const treeBoundBox& parentBb, const direction octant, @@ -92,7 +87,7 @@ bool indexedOctree::overlaps const point& sample ) { - //- Speeded up version of + //- Accelerated version of // treeBoundBox subBb(parentBb.subBbox(mid, octant)) // overlaps // ( @@ -147,7 +142,7 @@ bool indexedOctree::overlaps // Split list of indices into 8 bins template -void indexedOctree::divide +void Foam::indexedOctree::divide ( const labelList& indices, const treeBoundBox& bb, @@ -190,7 +185,8 @@ void indexedOctree::divide // Subdivide the (content) node. template -typename indexedOctree::node indexedOctree::divide +typename Foam::indexedOctree::node +Foam::indexedOctree::divide ( const treeBoundBox& bb, DynamicList& contents, @@ -259,7 +255,7 @@ typename indexedOctree::node indexedOctree::divide // Split any contents node with more than minSize elements. template -void indexedOctree::splitNodes +void Foam::indexedOctree::splitNodes ( const label minSize, DynamicList::node>& nodes, @@ -313,7 +309,7 @@ void indexedOctree::splitNodes // Reorder contents to be in same order as nodes. Returns number of nodes on // the compactLevel. template -label indexedOctree::compactContents +Foam::label Foam::indexedOctree::compactContents ( DynamicList& nodes, DynamicList& contents, @@ -383,7 +379,8 @@ label indexedOctree::compactContents // Recurses to determine status of lowest level boxes. Level above is // combination of octants below. template -typename indexedOctree::volumeType indexedOctree::calcVolumeType +typename Foam::indexedOctree::volumeType +Foam::indexedOctree::calcVolumeType ( const label nodeI ) const @@ -415,7 +412,10 @@ typename indexedOctree::volumeType indexedOctree::calcVolumeType // of its bounding box. const treeBoundBox subBb = nod.bb_.subBbox(octant); - subType = volumeType(shapes_.getVolumeType(*this, subBb.mid())); + subType = volumeType + ( + shapes_.getVolumeType(*this, subBb.midpoint()) + ); } // Store octant type @@ -437,7 +437,8 @@ typename indexedOctree::volumeType indexedOctree::calcVolumeType template -typename indexedOctree::volumeType indexedOctree::getVolumeType +typename Foam::indexedOctree::volumeType +Foam::indexedOctree::getVolumeType ( const label nodeI, const point& sample @@ -512,7 +513,8 @@ typename indexedOctree::volumeType indexedOctree::getVolumeType template -typename indexedOctree::volumeType indexedOctree::getSide +typename Foam::indexedOctree::volumeType +Foam::indexedOctree::getSide ( const vector& outsideNormal, const vector& vec @@ -536,7 +538,7 @@ typename indexedOctree::volumeType indexedOctree::getSide // Find nearest point starting from nodeI template -void indexedOctree::findNearest +void Foam::indexedOctree::findNearest ( const label nodeI, const point& sample, @@ -608,7 +610,7 @@ void indexedOctree::findNearest // Find nearest point to line. template -void indexedOctree::findNearest +void Foam::indexedOctree::findNearest ( const label nodeI, const linePointRef& ln, @@ -678,7 +680,7 @@ void indexedOctree::findNearest // the faceID (one of treeBoundBox::LEFTBIT, RIGHTBIT etc.) // Returns false if edge of tree hit. template -bool indexedOctree::walkToNeighbour +bool Foam::indexedOctree::walkToNeighbour ( const point& facePoint, const direction faceID, // direction to walk in @@ -785,7 +787,11 @@ bool indexedOctree::walkToNeighbour // (number is single bit but not really nessecary) // Return 0 if point not on any face of bb. template -direction indexedOctree::getFace(const treeBoundBox& bb, const point& pt) +Foam::direction Foam::indexedOctree::getFace +( + const treeBoundBox& bb, + const point& pt +) { direction faceID = 0; @@ -824,7 +830,7 @@ direction indexedOctree::getFace(const treeBoundBox& bb, const point& pt) // hitInfo.point = coordinate of intersection of ray with bounding box // faceID = index of bounding box face template -void indexedOctree::traverseNode +void Foam::indexedOctree::traverseNode ( const bool findAny, const point& start, @@ -950,7 +956,7 @@ void indexedOctree::traverseNode // Find first intersection template -pointIndexHit indexedOctree::findLine +Foam::pointIndexHit Foam::indexedOctree::findLine ( const bool findAny, const point& treeStart, @@ -1037,7 +1043,7 @@ pointIndexHit indexedOctree::findLine // Find first intersection template -pointIndexHit indexedOctree::findLine +Foam::pointIndexHit Foam::indexedOctree::findLine ( const bool findAny, const point& start, @@ -1101,7 +1107,7 @@ pointIndexHit indexedOctree::findLine template -void indexedOctree::findBox +void Foam::indexedOctree::findBox ( const label nodeI, const treeBoundBox& searchBox, @@ -1149,7 +1155,10 @@ void indexedOctree::findBox // Number of elements in node. template -label indexedOctree::countElements(const labelBits index) const +Foam::label Foam::indexedOctree::countElements +( + const labelBits index +) const { label nElems = 0; @@ -1179,7 +1188,7 @@ label indexedOctree::countElements(const labelBits index) const template -void indexedOctree::writeOBJ +void Foam::indexedOctree::writeOBJ ( const label nodeI, const direction octant @@ -1256,7 +1265,7 @@ void indexedOctree::writeOBJ // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // template -indexedOctree::indexedOctree(const Type& shapes) +Foam::indexedOctree::indexedOctree(const Type& shapes) : shapes_(shapes), nodes_(0), @@ -1266,7 +1275,7 @@ indexedOctree::indexedOctree(const Type& shapes) template -indexedOctree::indexedOctree +Foam::indexedOctree::indexedOctree ( const Type& shapes, const List& nodes, @@ -1281,7 +1290,7 @@ indexedOctree::indexedOctree template -indexedOctree::indexedOctree +Foam::indexedOctree::indexedOctree ( const Type& shapes, const treeBoundBox& bb, @@ -1422,7 +1431,7 @@ indexedOctree::indexedOctree template -indexedOctree::indexedOctree +Foam::indexedOctree::indexedOctree ( const Type& shapes, Istream& is @@ -1438,7 +1447,7 @@ indexedOctree::indexedOctree // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // template -pointIndexHit indexedOctree::findNearest +Foam::pointIndexHit Foam::indexedOctree::findNearest ( const point& sample, const scalar startDistSqr @@ -1470,7 +1479,7 @@ pointIndexHit indexedOctree::findNearest template -pointIndexHit indexedOctree::findNearest +Foam::pointIndexHit Foam::indexedOctree::findNearest ( const linePointRef& ln, treeBoundBox& tightest, @@ -1504,7 +1513,7 @@ pointIndexHit indexedOctree::findNearest // Find nearest intersection template -pointIndexHit indexedOctree::findLine +Foam::pointIndexHit Foam::indexedOctree::findLine ( const point& start, const point& end @@ -1516,7 +1525,7 @@ pointIndexHit indexedOctree::findLine // Find nearest intersection template -pointIndexHit indexedOctree::findLineAny +Foam::pointIndexHit Foam::indexedOctree::findLineAny ( const point& start, const point& end @@ -1527,7 +1536,10 @@ pointIndexHit indexedOctree::findLineAny template -labelList indexedOctree::findBox(const boundBox& searchBox) const +Foam::labelList Foam::indexedOctree::findBox +( + const boundBox& searchBox +) const { // Storage for labels of shapes inside bb. Size estimate. labelHashSet elements(shapes_.size() / 100); @@ -1543,7 +1555,7 @@ labelList indexedOctree::findBox(const boundBox& searchBox) const // Find node (as parent+octant) containing point template -labelBits indexedOctree::findNode +Foam::labelBits Foam::indexedOctree::findNode ( const label nodeI, const point& sample @@ -1581,7 +1593,8 @@ labelBits indexedOctree::findNode // Determine type (inside/outside/mixed) per node. template -typename indexedOctree::volumeType indexedOctree::getVolumeType +typename Foam::indexedOctree::volumeType +Foam::indexedOctree::getVolumeType ( const point& sample ) const @@ -1651,7 +1664,7 @@ typename indexedOctree::volumeType indexedOctree::getVolumeType // Print contents of nodeI template -void indexedOctree::print +void Foam::indexedOctree::print ( prefixOSstream& os, const bool printContents, @@ -1715,7 +1728,7 @@ void indexedOctree::print // Print contents of nodeI template -bool indexedOctree::write(Ostream& os) const +bool Foam::indexedOctree::write(Ostream& os) const { os << *this; @@ -1724,7 +1737,7 @@ bool indexedOctree::write(Ostream& os) const template -Ostream& operator<<(Ostream& os, const indexedOctree& t) +Foam::Ostream& Foam::operator<<(Ostream& os, const indexedOctree& t) { return os << t.bb() << token::SPACE << t.nodes() @@ -1732,8 +1745,4 @@ Ostream& operator<<(Ostream& os, const indexedOctree& t) } -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -} // End namespace Foam - // ************************************************************************* // diff --git a/src/meshTools/octree/octree.C b/src/meshTools/octree/octree.C index 791c3759a8..0dbda8434a 100644 --- a/src/meshTools/octree/octree.C +++ b/src/meshTools/octree/octree.C @@ -34,15 +34,10 @@ Description #include "linePointRef.H" #include "pointIndexHit.H" -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -namespace Foam -{ - // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // template -string octree::volType(const label type) +Foam::string Foam::octree::volType(const label type) { if (type == UNKNOWN) { @@ -70,10 +65,13 @@ string octree::volType(const label type) } -// Determine inside/outside status of vector compared to geometry based -// normal +// Determine inside/outside status of vector compared to geometry-based normal template -label octree::getVolType(const vector& geomNormal, const vector& vec) +Foam::label Foam::octree::getVolType +( + const vector& geomNormal, + const vector& vec +) { scalar sign = geomNormal & vec; @@ -91,7 +89,7 @@ label octree::getVolType(const vector& geomNormal, const vector& vec) // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // template -octree::octree +Foam::octree::octree ( const treeBoundBox& octreeBb, const Type& shapes, @@ -141,7 +139,7 @@ octree::octree } // Breadth first creation of tree - // Stop if: - level above minlevel and + // Stop if: - level above minlevel and // - less than so many cells per endpoint // (so bottom level is fine enough) // - every shape mentioned in only so many @@ -233,7 +231,7 @@ octree::octree // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // template -octree::~octree() +Foam::octree::~octree() { delete topNode_; } @@ -242,45 +240,44 @@ octree::~octree() // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // template -label octree::getSampleType(const point& sample) const +Foam::label Foam::octree::getSampleType(const point& sample) const { return topNode_->getSampleType(0, *this, shapes_, sample); } template -label octree::find(const point& sample) const +Foam::label Foam::octree::find(const point& sample) const { return topNode_->find(shapes_, sample); } template -bool octree::findTightest(const point& sample, treeBoundBox& tightest) - const +bool Foam::octree::findTightest +( + const point& sample, + treeBoundBox& tightest +) const { - label tightesti = -1; - scalar tightestDist = GREAT; - - return - topNode_->findTightest - ( - shapes_, - sample, - tightest - ); + return topNode_->findTightest + ( + shapes_, + sample, + tightest + ); } template -label octree::findNearest +Foam::label Foam::octree::findNearest ( const point& sample, treeBoundBox& tightest, scalar& tightestDist ) const { - label tightesti = -1; + label tightestI = -1; if (debug & 4) { @@ -294,7 +291,7 @@ label octree::findNearest shapes_, sample, tightest, - tightesti, + tightestI, tightestDist ); @@ -302,18 +299,18 @@ label octree::findNearest { Pout<< "octree::findNearest : found nearest for " << "sample:" << sample << " with " - << " tightesti:" << tightesti + << " tightestI:" << tightestI << " tightest:" << tightest << " tightestDist:" << tightestDist << endl; } - return tightesti; + return tightestI; } template -label octree::findNearest +Foam::label Foam::octree::findNearest ( const linePointRef& ln, treeBoundBox& tightest, @@ -322,7 +319,7 @@ label octree::findNearest ) const { // Start off from miss with points at large distance apart. - label tightesti = -1; + label tightestI = -1; linePoint = point(-GREAT, -GREAT, -GREAT); shapePoint = point(GREAT, GREAT, GREAT); @@ -331,17 +328,17 @@ label octree::findNearest shapes_, ln, tightest, - tightesti, + tightestI, linePoint, shapePoint ); - return tightesti; + return tightestI; } template -labelList octree::findBox(const boundBox& bb) const +Foam::labelList Foam::octree::findBox(const boundBox& bb) const { // Storage for labels of shapes inside bb. Size estimate. labelHashSet elements(100); @@ -353,7 +350,7 @@ labelList octree::findBox(const boundBox& bb) const template -pointIndexHit octree::findLine +Foam::pointIndexHit Foam::octree::findLine ( const point& treeStart, const point& treeEnd @@ -368,18 +365,17 @@ pointIndexHit octree::findLine point start(treeStart); point end(treeEnd); - while(true) + while (true) { // Find nearest treeLeaf intersected by line point leafIntPoint; - const treeLeaf* leafPtr = - findLeafLine - ( - start, - end, - leafIntPoint - ); + const treeLeaf* leafPtr = findLeafLine + ( + start, + end, + leafIntPoint + ); if (!leafPtr) { @@ -389,7 +385,7 @@ pointIndexHit octree::findLine } // Inside treeLeaf find nearest intersection - scalar minS = GREAT; + scalar minS = GREAT; const labelList& indices = leafPtr->indices(); @@ -435,15 +431,18 @@ pointIndexHit octree::findLine template -pointIndexHit octree::findLineAny(const point& start, const point& end) - const +Foam::pointIndexHit Foam::octree::findLineAny +( + const point& start, + const point& end +) const { // Initialize to a miss pointIndexHit hitInfo(false, start, -1); // Start of segment in current treeNode. point p(start); - while(true) + while (true) { // Find treeLeaf intersected by line point leafIntPoint; @@ -469,14 +468,13 @@ pointIndexHit octree::findLineAny(const point& start, const point& end) label index = indices[elemI]; point pt; - bool hit = - shapes().intersects - ( - index, - p, - end, - pt - ); + bool hit = shapes().intersects + ( + index, + p, + end, + pt + ); if (hit) { @@ -503,7 +501,7 @@ pointIndexHit octree::findLineAny(const point& start, const point& end) template -const treeLeaf* octree::findLeafLine +const Foam::treeLeaf* Foam::octree::findLeafLine ( const point& start, const point& end, @@ -518,7 +516,7 @@ const treeLeaf* octree::findLeafLine << "start:" << start << " end:" << end << endl; } - + // If start is outside project onto top cube if (octreeBb_.contains(start)) { @@ -546,14 +544,13 @@ const treeLeaf* octree::findLeafLine } // Normal action: find next intersection along line - const treeLeaf* leafPtr = - topNode_->findLeafLine - ( - 0, - shapes_, - leafIntPoint, - end - ); + const treeLeaf* leafPtr = topNode_->findLeafLine + ( + 0, + shapes_, + leafIntPoint, + end + ); if (debug & 2) { @@ -567,7 +564,11 @@ const treeLeaf* octree::findLeafLine template -void octree::writeOBJ(Ostream& os, label& vertNo) const +void Foam::octree::writeOBJ +( + Ostream& os, + label& vertNo +) const { scalar minx = octreeBb_.min().x(); scalar miny = octreeBb_.min().y(); @@ -587,7 +588,7 @@ void octree::writeOBJ(Ostream& os, label& vertNo) const os << "v " << maxx << " " << maxy << " " << maxz << endl; os << "v " << minx << " " << maxy << " " << maxz << endl; - // Botttom face + // Bottom face os << "l " << vertNo + 1 << " " << vertNo + 2 << endl; os << "l " << vertNo + 2 << " " << vertNo + 3 << endl; os << "l " << vertNo + 3 << " " << vertNo + 4 << endl; @@ -612,7 +613,7 @@ void octree::writeOBJ(Ostream& os, label& vertNo) const template -void octree::printStats(Ostream& os) const +void Foam::octree::printStats(Ostream& os) const { os << "Statistics after iteration " << deepestLevel() << ':' << endl << " nShapes :" << shapes().size() << endl @@ -637,7 +638,7 @@ void octree::printStats(Ostream& os) const // Construct from a octree. Set index at end. template -octree::iterator::iterator(octree& oc) +Foam::octree::iterator::iterator(octree& oc) : octree_(oc), curLeaf_(oc.nLeaves()) @@ -648,7 +649,7 @@ octree::iterator::iterator(octree& oc) // Construct from octree. Set index. template -octree::iterator::iterator(octree& oc, label index) +Foam::octree::iterator::iterator(octree& oc, label index) : octree_(oc), curLeaf_(index) @@ -676,7 +677,7 @@ octree::iterator::iterator(octree& oc, label index) template -void octree::iterator::operator=(const iterator& iter) +void Foam::octree::iterator::operator=(const iterator& iter) { if ((curLeaf_ < 0) && (iter.curLeaf_ >= 0)) { @@ -694,7 +695,7 @@ void octree::iterator::operator=(const iterator& iter) template -bool octree::iterator::operator==(const iterator& iter) const +bool Foam::octree::iterator::operator==(const iterator& iter) const { label index1 = (curLeaf_ >= 0 ? curLeaf_ : octree_.nLeaves()); @@ -706,21 +707,22 @@ bool octree::iterator::operator==(const iterator& iter) const template -bool octree::iterator::operator!=(const iterator& iter) const +bool Foam::octree::iterator::operator!=(const iterator& iter) const { return !(iterator::operator==(iter)); } template -treeLeaf& octree::iterator::operator*() +Foam::treeLeaf& Foam::octree::iterator::operator*() { return *leaves_[curLeaf_]; } template -typename octree::iterator& octree::iterator::operator++() +typename Foam::octree::iterator& +Foam::octree::iterator::operator++() { curLeaf_++; return *this; @@ -728,7 +730,8 @@ typename octree::iterator& octree::iterator::operator++() template -typename octree::iterator octree::iterator::operator++(int) +typename Foam::octree::iterator +Foam::octree::iterator::operator++(int) { iterator tmp = *this; ++*this; @@ -737,14 +740,16 @@ typename octree::iterator octree::iterator::operator++(int) template -typename octree::iterator octree::begin() +typename Foam::octree::iterator +Foam::octree::begin() { return iterator(*this, 0); } template -const typename octree::iterator& octree::end() +const typename Foam::octree::iterator& +Foam::octree::end() { return octree::endIter_; } @@ -754,7 +759,7 @@ const typename octree::iterator& octree::end() // Construct for a given octree template -octree::const_iterator::const_iterator(const octree& oc) +Foam::octree::const_iterator::const_iterator(const octree& oc) : octree_(oc), curLeaf_(oc.nLeaves()) @@ -765,7 +770,7 @@ octree::const_iterator::const_iterator(const octree& oc) // Construct for a given octree template -octree::const_iterator::const_iterator +Foam::octree::const_iterator::const_iterator ( const octree& oc, label index @@ -797,7 +802,7 @@ octree::const_iterator::const_iterator template -void octree::const_iterator::operator=(const const_iterator& iter) +void Foam::octree::const_iterator::operator=(const const_iterator& iter) { if ((curLeaf_ < 0) && (iter.curLeaf_ >= 0)) { @@ -816,7 +821,7 @@ void octree::const_iterator::operator=(const const_iterator& iter) template -bool octree::const_iterator::operator== +bool Foam::octree::const_iterator::operator== ( const const_iterator& iter ) const @@ -831,7 +836,7 @@ bool octree::const_iterator::operator== template -bool octree::const_iterator::operator!= +bool Foam::octree::const_iterator::operator!= ( const const_iterator& iter ) const @@ -841,15 +846,15 @@ bool octree::const_iterator::operator!= template -const treeLeaf& octree::const_iterator::operator*() +const Foam::treeLeaf& Foam::octree::const_iterator::operator*() { return *leaves_[curLeaf_]; } template -typename octree::const_iterator& -octree::const_iterator::operator++() +typename Foam::octree::const_iterator& +Foam::octree::const_iterator::operator++() { curLeaf_++; return *this; @@ -857,8 +862,8 @@ octree::const_iterator::operator++() template -typename octree::const_iterator -octree::const_iterator::operator++(int) +typename Foam::octree::const_iterator +Foam::octree::const_iterator::operator++(int) { const_iterator tmp = *this; ++*this; @@ -867,14 +872,16 @@ octree::const_iterator::operator++(int) template -typename octree::const_iterator octree::begin() const +typename Foam::octree::const_iterator +Foam::octree::begin() const { return const_iterator(*this, 0); } template -const typename octree::const_iterator& octree::end() const +const typename Foam::octree::const_iterator& +Foam::octree::end() const { return octree::endConstIter_; } @@ -883,10 +890,10 @@ const typename octree::const_iterator& octree::end() const // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * // template -Ostream& operator<<(Ostream& os, const octree& oc) +Foam::Ostream& Foam::operator<<(Ostream& os, const octree& oc) { return os << token::BEGIN_LIST - //<< token::SPACE << oc.shapes_ + //<< token::SPACE << oc.shapes_ << token::SPACE << oc.octreeBb_ << token::SPACE << oc.maxLeafRatio_ << token::SPACE << oc.maxShapeRatio_ @@ -899,8 +906,5 @@ Ostream& operator<<(Ostream& os, const octree& oc) << token::SPACE << token::END_LIST; } -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -} // End namespace Foam // ************************************************************************* // diff --git a/src/meshTools/octree/octreeDataCell.C b/src/meshTools/octree/octreeDataCell.C index c312ed7f7f..df9bd9ef12 100644 --- a/src/meshTools/octree/octreeDataCell.C +++ b/src/meshTools/octree/octreeDataCell.C @@ -58,11 +58,7 @@ Foam::octreeDataCell::octreeDataCell bbs_ ( mesh_.nCells(), - treeBoundBox - ( - vector(GREAT, GREAT, GREAT), - vector(-GREAT, -GREAT, -GREAT) - ) + treeBoundBox::invertedBox ) { // Set one-one indexing diff --git a/src/meshTools/octree/octreeDataCell.H b/src/meshTools/octree/octreeDataCell.H index 64076f9b0d..d6824eaf04 100644 --- a/src/meshTools/octree/octreeDataCell.H +++ b/src/meshTools/octree/octreeDataCell.H @@ -52,7 +52,7 @@ class polyMesh; template class octree; /*---------------------------------------------------------------------------*\ - Class octreeDataCell Declaration + Class octreeDataCell Declaration \*---------------------------------------------------------------------------*/ class octreeDataCell @@ -73,16 +73,13 @@ public: //- Construct from components. octreeDataCell ( - const polyMesh& mesh, + const polyMesh&, const labelList& cellLabels, const treeBoundBoxList& bbs ); //- Construct from mesh. Uses all cells in mesh. - octreeDataCell - ( - const polyMesh& mesh - ); + octreeDataCell(const polyMesh&); // Member Functions @@ -149,10 +146,10 @@ public: treeBoundBox& tightest ) const; - //- Given index get unit normal and calculate (numerical) sign + //- Given index get unit normal and calculate (numerical) sign // of sample. // Used to determine accuracy of calcNearest or inside/outside. - //Note: always returns GREAT since no inside/outside. + // Note: always returns GREAT since no inside/outside. scalar calcSign ( const label index, diff --git a/src/meshTools/octree/octreeDataEdges.C b/src/meshTools/octree/octreeDataEdges.C index 3ed68c9700..8a9bcb0b91 100644 --- a/src/meshTools/octree/octreeDataEdges.C +++ b/src/meshTools/octree/octreeDataEdges.C @@ -36,7 +36,7 @@ License defineTypeNameAndDebug(Foam::octreeDataEdges, 0); -Foam::scalar Foam::octreeDataEdges::tol = 1E-6; +Foam::scalar Foam::octreeDataEdges::tol(1E-6); // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // diff --git a/src/meshTools/octree/octreeDataEdges.H b/src/meshTools/octree/octreeDataEdges.H index 54f1b86748..a48ee57c6b 100644 --- a/src/meshTools/octree/octreeDataEdges.H +++ b/src/meshTools/octree/octreeDataEdges.H @@ -51,7 +51,7 @@ namespace Foam template class octree; /*---------------------------------------------------------------------------*\ - Class octreeDataEdges Declaration + Class octreeDataEdges Declaration \*---------------------------------------------------------------------------*/ class octreeDataEdges @@ -154,8 +154,8 @@ public: const point& sample ) const; - //- Segment (from start to end) intersection with shape - // at index. If intersects returns true and sets intersectionPoint + //- Segment (from start to end) intersection with shape at index. + // If intersects returns true and sets intersectionPoint bool intersects ( const label index, @@ -174,7 +174,7 @@ public: treeBoundBox& tightest ) const; - //- Given index get unit normal and calculate (numerical) sign + //- Given index get unit normal and calculate (numerical) sign // of sample. // Used to determine accuracy of calcNearest or inside/outside. scalar calcSign diff --git a/src/meshTools/octree/octreeDataFace.C b/src/meshTools/octree/octreeDataFace.C index a9abfc478a..c8b9e7943c 100644 --- a/src/meshTools/octree/octreeDataFace.C +++ b/src/meshTools/octree/octreeDataFace.C @@ -36,7 +36,7 @@ License defineTypeNameAndDebug(Foam::octreeDataFace, 0); -Foam::scalar Foam::octreeDataFace::tol = 1E-6; +Foam::scalar Foam::octreeDataFace::tol(1E-6); // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // @@ -44,11 +44,7 @@ Foam::scalar Foam::octreeDataFace::tol = 1E-6; void Foam::octreeDataFace::calcBb() { allBb_.setSize(meshFaces_.size()); - allBb_ = treeBoundBox - ( - vector(GREAT, GREAT, GREAT), - vector(-GREAT, -GREAT, -GREAT) - ); + allBb_ = treeBoundBox::invertedBox; forAll (meshFaces_, i) { @@ -104,8 +100,8 @@ Foam::octreeDataFace::octreeDataFace Foam::octreeDataFace::octreeDataFace ( const primitiveMesh& mesh, - const List& meshFaceListPtrs, - const List& bbListPtrs + const UList& meshFaceListPtrs, + const UList& bbListPtrs ) : mesh_(mesh), @@ -122,7 +118,7 @@ Foam::octreeDataFace::octreeDataFace meshFaces_.setSize(faceI); allBb_.setSize(faceI); - faceI = 0; + faceI = 0; forAll(meshFaceListPtrs, listI) { @@ -143,7 +139,7 @@ Foam::octreeDataFace::octreeDataFace Foam::octreeDataFace::octreeDataFace ( const primitiveMesh& mesh, - const List& meshFaceListPtrs + const UList& meshFaceListPtrs ) : mesh_(mesh), @@ -158,7 +154,7 @@ Foam::octreeDataFace::octreeDataFace meshFaces_.setSize(faceI); - faceI = 0; + faceI = 0; forAll(meshFaceListPtrs, listI) { @@ -204,7 +200,7 @@ Foam::octreeDataFace::octreeDataFace(const primitiveMesh& mesh) // Set info for all boundary faces. label boundaryFaceI = 0; - for(label faceI = mesh_.nInternalFaces(); faceI < mesh_.nFaces(); faceI++) + for (label faceI = mesh_.nInternalFaces(); faceI < mesh_.nFaces(); faceI++) { meshFaces_[boundaryFaceI++] = faceI; } @@ -247,12 +243,9 @@ Foam::label Foam::octreeDataFace::getSampleType // or where on the face it has hit so we have to recreate all that // information. - - // Find nearest face to sample treeBoundBox tightest(treeBoundBox::greatBox); - - scalar tightestDist = GREAT; - + scalar tightestDist(treeBoundBox::great); + // Find nearest face to sample label index = oc.findNearest(sample, tightest, tightestDist); if (index == -1) @@ -383,12 +376,11 @@ Foam::label Foam::octreeDataFace::getSampleType { const edge& e = mesh_.edges()[myEdges[myEdgeI]]; - pointHit edgeHit = - line - ( - points[e.start()], - points[e.end()] - ).nearestDist(sample); + pointHit edgeHit = line + ( + points[e.start()], + points[e.end()] + ).nearestDist(sample); if ((mag(edgeHit.rawPoint() - curHit.missPoint())/typDim) < tol) @@ -540,14 +532,13 @@ bool Foam::octreeDataFace::overlaps { label fp1 = (fp == f.size()-1 ? 0 : fp+1); - bool triIntersects = - triangleFuncs::intersectBb - ( - points[f[fp]], - points[f[fp1]], - fc, - sampleBb - ); + bool triIntersects = triangleFuncs::intersectBb + ( + points[f[fp]], + points[f[fp1]], + fc, + sampleBb + ); if (triIntersects) { @@ -585,15 +576,14 @@ bool Foam::octreeDataFace::intersects // Disable picking up intersections behind us. scalar oldTol = intersection::setPlanarTol(0.0); - pointHit inter = - f.ray - ( - start, - dir, - mesh_.points(), - intersection::HALF_RAY, - intersection::VECTOR - ); + pointHit inter = f.ray + ( + start, + dir, + mesh_.points(), + intersection::HALF_RAY, + intersection::VECTOR + ); intersection::setPlanarTol(oldTol); @@ -637,7 +627,7 @@ bool Foam::octreeDataFace::findTightest else { // Construct bb around sample and myFar - const point dist2(fabs(dist.x()), fabs(dist.y()), fabs(dist.z())); + const point dist2(fabs(dist.x()), fabs(dist.y()), fabs(dist.z())); tightest.min() = sample - dist2; tightest.max() = sample + dist2; diff --git a/src/meshTools/octree/octreeDataFace.H b/src/meshTools/octree/octreeDataFace.H index a3ca2ef8b2..0f0fef78cb 100644 --- a/src/meshTools/octree/octreeDataFace.H +++ b/src/meshTools/octree/octreeDataFace.H @@ -56,7 +56,7 @@ template class octree; class polyPatch; /*---------------------------------------------------------------------------*\ - Class octreeDataFace Declaration + Class octreeDataFace Declaration \*---------------------------------------------------------------------------*/ class octreeDataFace @@ -111,20 +111,20 @@ public: octreeDataFace ( const primitiveMesh&, - const List&, - const List& + const UList&, + const UList& ); - //- Construct from selected mesh faces. Tight fitting bounding boxes - // generated internally. - octreeDataFace(const primitiveMesh&, const List&); + //- Construct from selected mesh faces. + // Tight-fitting bounding boxes generated internally. + octreeDataFace(const primitiveMesh&, const UList&); - //- Construct from alll faces in patch. Tight fitting bounding boxes - // generated internally. - octreeDataFace(const polyPatch& patch); + //- Construct from all faces in patch. + // Tight-fitting bounding boxes generated internally. + octreeDataFace(const polyPatch&); - //- Construct from all boundary faces. Tight fitting bounding boxes - // generated internally. + //- Construct from all boundary faces. + // Tight-fitting bounding boxes generated internally. octreeDataFace(const primitiveMesh&); //- Construct as copy @@ -200,7 +200,7 @@ public: treeBoundBox& tightest ) const; - //- Given index get unit normal and calculate (numerical) sign + //- Given index get unit normal and calculate (numerical) sign // of sample. // Used to determine accuracy of calcNearest or inside/outside. scalar calcSign diff --git a/src/meshTools/octree/octreeDataPoint.H b/src/meshTools/octree/octreeDataPoint.H index 90b4327dbf..32e4709734 100644 --- a/src/meshTools/octree/octreeDataPoint.H +++ b/src/meshTools/octree/octreeDataPoint.H @@ -69,7 +69,7 @@ public: // Constructors //- Construct from components. Holds reference to points! - octreeDataPoint(const pointField& points); + octreeDataPoint(const pointField&); // Member Functions diff --git a/src/meshTools/octree/octreeDataPointTreeLeaf.C b/src/meshTools/octree/octreeDataPointTreeLeaf.C index 3a0f527a51..2e5cafc9b7 100644 --- a/src/meshTools/octree/octreeDataPointTreeLeaf.C +++ b/src/meshTools/octree/octreeDataPointTreeLeaf.C @@ -56,7 +56,7 @@ bool Foam::treeLeaf::findNearest const octreeDataPoint& shapes, const point& sample, treeBoundBox& tightest, - label& tightesti, + label& tightestI, scalar& tightestDist ) const { @@ -93,7 +93,7 @@ bool Foam::treeLeaf::findNearest tMax.y() = sample.y() + tightestDist; tMax.z() = sample.z() + tightestDist; - tightesti = minIndex; + tightestI = minIndex; return true; } diff --git a/src/meshTools/octree/octreeDataPointTreeLeaf.H b/src/meshTools/octree/octreeDataPointTreeLeaf.H index aecf9d7512..2641bcedca 100644 --- a/src/meshTools/octree/octreeDataPointTreeLeaf.H +++ b/src/meshTools/octree/octreeDataPointTreeLeaf.H @@ -60,7 +60,7 @@ bool treeLeaf::findNearest const octreeDataPoint& shapes, const point& sample, treeBoundBox& tightest, - label& tightesti, + label& tightestI, scalar& tightestDist ) const; diff --git a/src/meshTools/octree/octreeLine.C b/src/meshTools/octree/octreeLine.C index 40e2239ebd..540721e950 100644 --- a/src/meshTools/octree/octreeLine.C +++ b/src/meshTools/octree/octreeLine.C @@ -27,16 +27,11 @@ License #include "octreeLine.H" #include "octree.H" -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -namespace Foam -{ - // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // Calculate sorted list of intersections template -void octreeLine::calcSortedIntersections() +void Foam::octreeLine::calcSortedIntersections() { // Determine intersections and sort acc. to distance to start @@ -45,35 +40,33 @@ void octreeLine::calcSortedIntersections() sortedIntersections_.setSize(indices.size()); const vector direction = endPoint_ - realStartPoint_; - + label nHits = 0; forAll(indices, elemI) { point pt; - bool hit = - tree_.shapes().intersects - ( - indices[elemI], - realStartPoint_, - direction, - pt - ); + bool hit = tree_.shapes().intersects + ( + indices[elemI], + realStartPoint_, + direction, + pt + ); if (hit && (indices[elemI] != lastElem_)) { - sortedIntersections_[nHits++] = - pointHitSort + sortedIntersections_[nHits++] = pointHitSort + ( + pointHit ( - pointHit - ( - true, - pt, - Foam::magSqr(pt - leafExitPoint_), - false - ), - indices[elemI] - ); + true, + pt, + Foam::magSqr(pt - leafExitPoint_), + false + ), + indices[elemI] + ); } } @@ -108,7 +101,7 @@ void octreeLine::calcSortedIntersections() // Searches for leaf with intersected elements. Return true if found; false // otherwise. Sets currentLeaf_ and sortedIntersections_. template -bool octreeLine::getNextLeaf() +bool Foam::octreeLine::getNextLeaf() { do { @@ -136,7 +129,7 @@ bool octreeLine::getNextLeaf() // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // template -octreeLine::octreeLine +Foam::octreeLine::octreeLine ( const octree& tree, const point& startPoint, @@ -158,14 +151,14 @@ octreeLine::octreeLine // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // template -octreeLine::~octreeLine() +Foam::octreeLine::~octreeLine() {} // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // template -bool octreeLine::getIntersection() +bool Foam::octreeLine::getIntersection() { // Go to next element in sortedIntersections @@ -185,9 +178,4 @@ bool octreeLine::getIntersection() return true; } - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -} // End namespace Foam - // ************************************************************************* // diff --git a/src/meshTools/octree/treeBoundBox.C b/src/meshTools/octree/treeBoundBox.C index 5e811bba99..c511f74758 100644 --- a/src/meshTools/octree/treeBoundBox.C +++ b/src/meshTools/octree/treeBoundBox.C @@ -29,6 +29,8 @@ License // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // +const Foam::scalar Foam::treeBoundBox::great(GREAT); + const Foam::treeBoundBox Foam::treeBoundBox::greatBox ( vector(-GREAT, -GREAT, -GREAT), @@ -36,6 +38,13 @@ const Foam::treeBoundBox Foam::treeBoundBox::greatBox ); +const Foam::treeBoundBox Foam::treeBoundBox::invertedBox +( + vector(GREAT, GREAT, GREAT), + vector(-GREAT, -GREAT, -GREAT) +); + + //! @cond - skip documentation : local scope only const Foam::label facesArray[6][4] = { @@ -185,63 +194,7 @@ Foam::pointField Foam::treeBoundBox::points() const Foam::treeBoundBox Foam::treeBoundBox::subBbox(const direction octant) const { - if (octant > 7) - { - FatalErrorIn - ( - "treeBoundBox::subCube(const direction)" - ) << "octant should be [0..7]" - << abort(FatalError); - } - - scalar leftx, lefty, leftz; - scalar rightx, righty, rightz; - - scalar midx=0.5*(min().x() + max().x()); - scalar midy=0.5*(min().y() + max().y()); - scalar midz=0.5*(min().z() + max().z()); - - // X half - if (octant & treeBoundBox::RIGHTHALF) - { - leftx = midx; - rightx = max().x(); - } - else - { - leftx = min().x(); - rightx = midx; - } - - // Y half - if (octant & treeBoundBox::TOPHALF) - { - lefty = midy; - righty = max().y(); - } - else - { - lefty = min().y(); - righty = midy; - } - - // Z half - if (octant & treeBoundBox::FRONTHALF) - { - leftz = midz; - rightz = max().z(); - } - else - { - leftz = min().z(); - rightz = midz; - } - - return treeBoundBox - ( - point(leftx, lefty, leftz), - point(rightx, righty, rightz) - ); + return subBbox(midpoint(), octant); } @@ -256,44 +209,41 @@ Foam::treeBoundBox Foam::treeBoundBox::subBbox { FatalErrorIn ( - "treeBoundBox::subCube(const point&, const direction)" + "treeBoundBox::subBbox(const point&, const direction)" ) << "octant should be [0..7]" << abort(FatalError); } - treeBoundBox subBb; - point& subMin = subBb.min(); - point& subMax = subBb.max(); + // start with a copy of this bounding box and adjust limits accordingly + treeBoundBox subBb(*this); + point& bbMin = subBb.min(); + point& bbMax = subBb.max(); if (octant & treeBoundBox::RIGHTHALF) { - subMin.x() = mid.x(); - subMax.x() = max().x(); + bbMin.x() = mid.x(); // mid -> max } else { - subMin.x() = min().x(); - subMax.x() = mid.x(); + bbMax.x() = mid.x(); // min -> mid } + if (octant & treeBoundBox::TOPHALF) { - subMin.y() = mid.y(); - subMax.y() = max().y(); + bbMin.y() = mid.y(); // mid -> max } else { - subMin.y() = min().y(); - subMax.y() = mid.y(); + bbMax.y() = mid.y(); // min -> mid } + if (octant & treeBoundBox::FRONTHALF) { - subMin.z() = mid.z(); - subMax.z() = max().z(); + bbMin.z() = mid.z(); // mid -> max } else { - subMin.z() = min().z(); - subMax.z() = mid.z(); + bbMax.z() = mid.z(); // min -> mid } return subBb; @@ -364,13 +314,11 @@ bool Foam::treeBoundBox::intersects point& pt ) const { - vector vec(end - start); - + const vector vec(end - start); + const direction endBits = posBits(end); pt = start; - const direction endBits = posBits(end); - - while(true) + while (true) { direction ptBits = posBits(pt); @@ -465,32 +413,18 @@ bool Foam::treeBoundBox::contains(const treeBoundBox& bb) const } -bool Foam::treeBoundBox::containsNarrow(const point& sample) const -{ - return - ( - (sample.x() > min().x()) && - (sample.y() > min().y()) && - (sample.z() > min().z()) && - (sample.x() < max().x()) && - (sample.y() < max().y()) && - (sample.z() < max().z()) - ); -} - -bool Foam::treeBoundBox::contains(const vector& dir, const point& sample) const +bool Foam::treeBoundBox::contains(const vector& dir, const point& pt) const { // // Compare all components against min and max of bb // - for (direction cmpt=0; cmpt<3; cmpt++) { - if (sample[cmpt] < min()[cmpt]) + if (pt[cmpt] < min()[cmpt]) { return false; } - else if (sample[cmpt] == min()[cmpt]) + else if (pt[cmpt] == min()[cmpt]) { // On edge. Outside if direction points outwards. if (dir[cmpt] < 0) @@ -499,11 +433,11 @@ bool Foam::treeBoundBox::contains(const vector& dir, const point& sample) const } } - if (sample[cmpt] > max()[cmpt]) + if (pt[cmpt] > max()[cmpt]) { return false; } - else if (sample[cmpt] == max()[cmpt]) + else if (pt[cmpt] == max()[cmpt]) { // On edge. Outside if direction points outwards. if (dir[cmpt] > 0) @@ -557,7 +491,7 @@ Foam::direction Foam::treeBoundBox::posBits(const point& pt) const // !names of treeBoundBox::min() and treeBoundBox::max() are confusing! void Foam::treeBoundBox::calcExtremities ( - const point& sample, + const point& pt, point& nearest, point& furthest ) const @@ -565,7 +499,7 @@ void Foam::treeBoundBox::calcExtremities scalar nearX, nearY, nearZ; scalar farX, farY, farZ; - if (Foam::mag(min().x() - sample.x()) < Foam::mag(max().x() - sample.x())) + if (Foam::mag(min().x() - pt.x()) < Foam::mag(max().x() - pt.x())) { nearX = min().x(); farX = max().x(); @@ -576,7 +510,7 @@ void Foam::treeBoundBox::calcExtremities farX = min().x(); } - if (Foam::mag(min().y() - sample.y()) < Foam::mag(max().y() - sample.y())) + if (Foam::mag(min().y() - pt.y()) < Foam::mag(max().y() - pt.y())) { nearY = min().y(); farY = max().y(); @@ -587,7 +521,7 @@ void Foam::treeBoundBox::calcExtremities farY = min().y(); } - if (Foam::mag(min().z() - sample.z()) < Foam::mag(max().z() - sample.z())) + if (Foam::mag(min().z() - pt.z()) < Foam::mag(max().z() - pt.z())) { nearZ = min().z(); farZ = max().z(); @@ -603,12 +537,12 @@ void Foam::treeBoundBox::calcExtremities } -Foam::scalar Foam::treeBoundBox::maxDist(const point& sample) const +Foam::scalar Foam::treeBoundBox::maxDist(const point& pt) const { point near, far; - calcExtremities(sample, near, far); + calcExtremities(pt, near, far); - return Foam::mag(far - sample); + return Foam::mag(far - pt); } @@ -617,57 +551,57 @@ Foam::scalar Foam::treeBoundBox::maxDist(const point& sample) const // box to see if all vertices of one are nearer Foam::label Foam::treeBoundBox::distanceCmp ( - const point& sample, + const point& pt, const treeBoundBox& other ) const { // - // Distance sample <-> nearest and furthest away vertex of this + // Distance point <-> nearest and furthest away vertex of this // point nearThis, farThis; // get nearest and furthest away vertex - calcExtremities(sample, nearThis, farThis); + calcExtremities(pt, nearThis, farThis); const scalar minDistThis = - sqr(nearThis.x() - sample.x()) - + sqr(nearThis.y() - sample.y()) - + sqr(nearThis.z() - sample.z()); + sqr(nearThis.x() - pt.x()) + + sqr(nearThis.y() - pt.y()) + + sqr(nearThis.z() - pt.z()); const scalar maxDistThis = - sqr(farThis.x() - sample.x()) - + sqr(farThis.y() - sample.y()) - + sqr(farThis.z() - sample.z()); + sqr(farThis.x() - pt.x()) + + sqr(farThis.y() - pt.y()) + + sqr(farThis.z() - pt.z()); // - // Distance sample <-> other + // Distance point <-> other // point nearOther, farOther; // get nearest and furthest away vertex - other.calcExtremities(sample, nearOther, farOther); + other.calcExtremities(pt, nearOther, farOther); const scalar minDistOther = - sqr(nearOther.x() - sample.x()) - + sqr(nearOther.y() - sample.y()) - + sqr(nearOther.z() - sample.z()); + sqr(nearOther.x() - pt.x()) + + sqr(nearOther.y() - pt.y()) + + sqr(nearOther.z() - pt.z()); const scalar maxDistOther = - sqr(farOther.x() - sample.x()) - + sqr(farOther.y() - sample.y()) - + sqr(farOther.z() - sample.z()); + sqr(farOther.x() - pt.x()) + + sqr(farOther.y() - pt.y()) + + sqr(farOther.z() - pt.z()); // // Categorize // if (maxDistThis < minDistOther) { - // All vertices of this are nearer to sample than any vertex of other + // All vertices of this are nearer to point than any vertex of other return -1; } else if (minDistThis > maxDistOther) { - // All vertices of this are further from sample than any vertex of other + // All vertices of this are further from point than any vertex of other return 1; } else diff --git a/src/meshTools/octree/treeBoundBox.H b/src/meshTools/octree/treeBoundBox.H index a8de9fb0cc..e9d9b942da 100644 --- a/src/meshTools/octree/treeBoundBox.H +++ b/src/meshTools/octree/treeBoundBox.H @@ -87,16 +87,22 @@ public: // Static data members + //- The great value used for greatBox and invertedBox + static const scalar great; + //- As per boundBox::greatBox, but with GREAT instead of VGREAT static const treeBoundBox greatBox; - //- Bits used for octant/point coding. Every octant/corner point - // is the combination of three faces. + //- As per boundBox::invertedBox, but with GREAT instead of VGREAT + static const treeBoundBox invertedBox; + + //- Bits used for octant/point coding. + // Every octant/corner point is the combination of three faces. enum octantBit { - RIGHTHALF = 0x1 << 0, - TOPHALF = 0x1 << 1, - FRONTHALF = 0x1 << 2 + RIGHTHALF = 0x1 << 0, + TOPHALF = 0x1 << 1, + FRONTHALF = 0x1 << 2 }; //- Face codes @@ -167,11 +173,12 @@ public: //- Construct from components inline treeBoundBox(const boundBox& bb); - //- Construct as the bounding box of the given pointField. Local - // processor domain only (no reduce as in boundBox) - treeBoundBox(const UList& points); + //- Construct as the bounding box of the given pointField. + // Local processor domain only (no reduce as in boundBox) + treeBoundBox(const UList&); //- Construct as subset of points + // Local processor domain only (no reduce as in boundBox) treeBoundBox(const UList&, const UList