diff --git a/applications/utilities/preProcessing/mapFields/mapFields.C b/applications/utilities/preProcessing/mapFields/mapFields.C index 0fb8e40fff2c2905297a978b0d1ab85b07b1f78d..5d4a6471e49c2fb083331585da9abdeea87274fa 100644 --- a/applications/utilities/preProcessing/mapFields/mapFields.C +++ b/applications/utilities/preProcessing/mapFields/mapFields.C @@ -504,7 +504,7 @@ int main(int argc, char *argv[]) !bbsTargetSet[procITarget] || ( bbsTargetSet[procITarget] - && bbsTarget[procITarget].intersects(bbSource) + && bbsTarget[procITarget].overlaps(bbSource) ) ) { @@ -533,7 +533,7 @@ int main(int argc, char *argv[]) bbsTarget[procITarget] = meshTarget.bounds(); bbsTargetSet[procITarget] = true; - if (bbsTarget[procITarget].intersects(bbSource)) + if (bbsTarget[procITarget].overlaps(bbSource)) { if (consistent) { diff --git a/src/OpenFOAM/meshes/boundBox/boundBox.H b/src/OpenFOAM/meshes/boundBox/boundBox.H index a11aa68266269e79ebdf07a56c7dbd1df6495044..40287e53ebe5fa342811cdca979de96b0518bf73 100644 --- a/src/OpenFOAM/meshes/boundBox/boundBox.H +++ b/src/OpenFOAM/meshes/boundBox/boundBox.H @@ -118,7 +118,7 @@ public: // Query //- Intersects other boundingbox? - bool intersects(const boundBox& bb) const + bool overlaps(const boundBox& bb) const { if ( diff --git a/src/dynamicMesh/boundaryMesh/octreeDataFaceList.C b/src/dynamicMesh/boundaryMesh/octreeDataFaceList.C index 2249bc006ecae81697ec0b144c74d89e3cd4aff8..2ce870af9d7cbc7824b71231d17090a824fd7663 100644 --- a/src/dynamicMesh/boundaryMesh/octreeDataFaceList.C +++ b/src/dynamicMesh/boundaryMesh/octreeDataFaceList.C @@ -399,7 +399,7 @@ bool Foam::octreeDataFaceList::overlaps const treeBoundBox& sampleBb ) const { - return sampleBb.intersects(allBb_[index]); + return sampleBb.overlaps(allBb_[index]); } diff --git a/src/meshTools/indexedOctree/indexedOctree.C b/src/meshTools/indexedOctree/indexedOctree.C index f0f8bd94d0ae149373799c8012caa2956437c792..1a55a88547e1b9e4dbdfeee4506a9278808f2212 100644 --- a/src/meshTools/indexedOctree/indexedOctree.C +++ b/src/meshTools/indexedOctree/indexedOctree.C @@ -40,7 +40,7 @@ namespace Foam // Does bb intersect a sphere around sample? Or is any corner point of bb // closer than nearestDistSqr to sample. template <class Type> -bool indexedOctree<Type>::intersects +bool indexedOctree<Type>::overlaps ( const point& p0, const point& p1, @@ -84,7 +84,7 @@ bool indexedOctree<Type>::intersects // Does bb intersect a sphere around sample? Or is any corner point of bb // closer than nearestDistSqr to sample. template <class Type> -bool indexedOctree<Type>::intersects +bool indexedOctree<Type>::overlaps ( const treeBoundBox& parentBb, const direction octant, @@ -94,7 +94,7 @@ bool indexedOctree<Type>::intersects { //- Speeded up version of // treeBoundBox subBb(parentBb.subBbox(mid, octant)) - // intersects + // overlaps // ( // subBb.min(), // subBb.max(), @@ -136,7 +136,7 @@ bool indexedOctree<Type>::intersects const point mid(0.5*(min+max)); - return intersects(mid, other, nearestDistSqr, sample); + return overlaps(mid, other, nearestDistSqr, sample); } @@ -567,7 +567,7 @@ void indexedOctree<Type>::findNearest const treeBoundBox& subBb = nodes_[subNodeI].bb_; - if (intersects(subBb.min(), subBb.max(), nearestDistSqr, sample)) + if (overlaps(subBb.min(), subBb.max(), nearestDistSqr, sample)) { findNearest ( @@ -584,7 +584,7 @@ void indexedOctree<Type>::findNearest { if ( - intersects + overlaps ( nod.bb_, octant, @@ -639,7 +639,7 @@ void indexedOctree<Type>::findNearest { const treeBoundBox& subBb = nodes_[getNode(index)].bb_; - if (subBb.intersects(tightest)) + if (subBb.overlaps(tightest)) { findNearest ( @@ -657,7 +657,7 @@ void indexedOctree<Type>::findNearest { const treeBoundBox subBb(nodeBb.subBbox(octant)); - if (subBb.intersects(tightest)) + if (subBb.overlaps(tightest)) { shapes_.findNearest ( @@ -1121,7 +1121,7 @@ void indexedOctree<Type>::findBox { const treeBoundBox& subBb = nodes_[getNode(index)].bb_; - if (subBb.intersects(searchBox)) + if (subBb.overlaps(searchBox)) { findBox(getNode(index), searchBox, elements); } @@ -1130,7 +1130,7 @@ void indexedOctree<Type>::findBox { const treeBoundBox subBb(nodeBb.subBbox(octant)); - if (subBb.intersects(searchBox)) + if (subBb.overlaps(searchBox)) { const labelList& indices = contents_[getContent(index)]; diff --git a/src/meshTools/indexedOctree/indexedOctree.H b/src/meshTools/indexedOctree/indexedOctree.H index 249eb1b5f14d6ac067612d65e42a477ab594d0d2..97b6ab607c6428bf78977c0d5f307f827e66b82d 100644 --- a/src/meshTools/indexedOctree/indexedOctree.H +++ b/src/meshTools/indexedOctree/indexedOctree.H @@ -36,9 +36,9 @@ SourceFiles #ifndef indexedOctree_H #define indexedOctree_H +#include "treeBoundBox.H" #include "pointIndexHit.H" #include "FixedList.H" -#include "treeBoundBox.H" #include "Ostream.H" #include "labelHashSet.H" #include "labelBits.H" @@ -146,7 +146,7 @@ private: //- Like above but now bb is implicitly provided as parent bb + mid // + octant - static bool intersects + static bool overlaps ( const treeBoundBox& parentBb, const direction octant, @@ -497,7 +497,7 @@ public: //- Helper: does bb intersect a sphere around sample? Or is any // corner point of bb closer than nearestDistSqr to sample. - static bool intersects + static bool overlaps ( const point& bbMin, const point& bbMax, diff --git a/src/meshTools/indexedOctree/treeDataCell.C b/src/meshTools/indexedOctree/treeDataCell.C index 2ade66780caba39267dfd4f439386bd77e3f8db7..cb41899306b29d9c0669e9fb93ab679a4c52a74f 100644 --- a/src/meshTools/indexedOctree/treeDataCell.C +++ b/src/meshTools/indexedOctree/treeDataCell.C @@ -137,11 +137,11 @@ bool Foam::treeDataCell::overlaps { if (cacheBb_) { - return cubeBb.intersects(bbs_[index]); + return cubeBb.overlaps(bbs_[index]); } else { - return cubeBb.intersects(calcCellBb(cellLabels_[index])); + return cubeBb.overlaps(calcCellBb(cellLabels_[index])); } } diff --git a/src/meshTools/indexedOctree/treeDataEdge.C b/src/meshTools/indexedOctree/treeDataEdge.C index d918fab9447596f591fefc975eb47e55bac8cb07..6b8d54399ee709486abc89cb8646f4355c5f50f3 100644 --- a/src/meshTools/indexedOctree/treeDataEdge.C +++ b/src/meshTools/indexedOctree/treeDataEdge.C @@ -110,11 +110,11 @@ bool Foam::treeDataEdge::overlaps { if (cacheBb_) { - return cubeBb.intersects(bbs_[index]); + return cubeBb.overlaps(bbs_[index]); } else { - return cubeBb.intersects(calcBb(edgeLabels_[index])); + return cubeBb.overlaps(calcBb(edgeLabels_[index])); } } diff --git a/src/meshTools/indexedOctree/treeDataFace.C b/src/meshTools/indexedOctree/treeDataFace.C index e8d148ec230a820c27407d34d21cb1fdcc39b345..5764841bbd23f7e7cc6d5a91610db371631bb376 100644 --- a/src/meshTools/indexedOctree/treeDataFace.C +++ b/src/meshTools/indexedOctree/treeDataFace.C @@ -412,14 +412,14 @@ bool Foam::treeDataFace::overlaps // 1. Quick rejection: bb does not intersect face bb at all if (cacheBb_) { - if (!cubeBb.intersects(bbs_[index])) + if (!cubeBb.overlaps(bbs_[index])) { return false; } } else { - if (!cubeBb.intersects(calcBb(faceLabels_[index]))) + if (!cubeBb.overlaps(calcBb(faceLabels_[index]))) { return false; } diff --git a/src/meshTools/indexedOctree/treeDataTriSurface.C b/src/meshTools/indexedOctree/treeDataTriSurface.C index 23ba7f5116b8a72dbdc89995fab2a21e34cc2d57..c226de94998a27abeca362d130200648a81ac82e 100644 --- a/src/meshTools/indexedOctree/treeDataTriSurface.C +++ b/src/meshTools/indexedOctree/treeDataTriSurface.C @@ -284,13 +284,13 @@ bool Foam::treeDataTriSurface::overlaps triBb.max() = max(triBb.max(), p2); //- For testing: robust one - //return cubeBb.intersects(triBb); + //return cubeBb.overlaps(triBb); //- Exact test of triangle intersecting bb // Quick rejection. If whole bounding box of tri is outside cubeBb then // there will be no intersection. - if (!cubeBb.intersects(triBb)) + if (!cubeBb.overlaps(triBb)) { return false; } diff --git a/src/meshTools/octree/octreeDataCell.C b/src/meshTools/octree/octreeDataCell.C index 81a3600be946c86f078f87800e109ae10cea8f9d..17bba8b2c993093a193b44fbcc09c553fe160e74 100644 --- a/src/meshTools/octree/octreeDataCell.C +++ b/src/meshTools/octree/octreeDataCell.C @@ -113,7 +113,7 @@ bool Foam::octreeDataCell::overlaps const treeBoundBox& cubeBb ) const { - return cubeBb.intersects(bbs_[index]); + return cubeBb.overlaps(bbs_[index]); } diff --git a/src/meshTools/octree/octreeDataEdges.C b/src/meshTools/octree/octreeDataEdges.C index 3974a0b91d149af516107ee646fb229e7a75b9fb..9828599e616da3d2e91468eec0a8d81bdd1ab850 100644 --- a/src/meshTools/octree/octreeDataEdges.C +++ b/src/meshTools/octree/octreeDataEdges.C @@ -107,7 +107,7 @@ bool Foam::octreeDataEdges::overlaps const treeBoundBox& sampleBb ) const { - return sampleBb.intersects(allBb_[index]); + return sampleBb.overlaps(allBb_[index]); } diff --git a/src/meshTools/octree/octreeDataFace.C b/src/meshTools/octree/octreeDataFace.C index 46f03993cc5ffa9501432c34ed76402f3c8b3132..6a8c3f875a6e55025770de6ef3e927974d404996 100644 --- a/src/meshTools/octree/octreeDataFace.C +++ b/src/meshTools/octree/octreeDataFace.C @@ -507,12 +507,12 @@ bool Foam::octreeDataFace::overlaps const treeBoundBox& sampleBb ) const { - //return sampleBb.intersects(allBb_[index]); + //return sampleBb.overlaps(allBb_[index]); //- Exact test of face intersecting bb // 1. Quick rejection: bb does not intersect face bb at all - if (!sampleBb.intersects(allBb_[index])) + if (!sampleBb.overlaps(allBb_[index])) { return false; } diff --git a/src/meshTools/octree/treeBoundBox.C b/src/meshTools/octree/treeBoundBox.C index 042209ec7c9ef35c923f46945728e0f007d547d4..26530b5a3ab60a728282ff8da5323c934b57bda6 100644 --- a/src/meshTools/octree/treeBoundBox.C +++ b/src/meshTools/octree/treeBoundBox.C @@ -297,6 +297,45 @@ Foam::treeBoundBox Foam::treeBoundBox::subBbox } +bool Foam::treeBoundBox::overlaps +( + const point& centre, + const scalar radiusSqr +) const +{ + // Find out where centre is in relation to bb. + // Find nearest point on bb. + scalar distSqr = 0; + + for (direction dir = 0; dir < vector::nComponents; dir++) + { + scalar d0 = min()[dir] - centre[dir]; + scalar d1 = max()[dir] - centre[dir]; + + if ((d0 > 0) != (d1 > 0)) + { + // centre inside both extrema. This component does not add any + // distance. + } + else if (Foam::mag(d0) < Foam::mag(d1)) + { + distSqr += d0*d0; + } + else + { + distSqr += d1*d1; + } + + if (distSqr > radiusSqr) + { + return false; + } + } + + return true; +} + + // line intersection. Returns true if line (start to end) inside // bb or intersects bb. Sets pt to intersection. // diff --git a/src/meshTools/octree/treeBoundBox.H b/src/meshTools/octree/treeBoundBox.H index 01d7a9a6bd6e432bee2a3fcff038f5622ac8d5c9..02dbac38afbced8498d80f1fb168d320de0affe7 100644 --- a/src/meshTools/octree/treeBoundBox.H +++ b/src/meshTools/octree/treeBoundBox.H @@ -263,8 +263,11 @@ public: FixedList<direction, 8>& octantOrder ) const; - //- Intersects other boundingbox? - inline bool intersects(const treeBoundBox&) const; + //- Overlaps other boundingbox? + inline bool overlaps(const treeBoundBox&) const; + + //- Overlaps boundingSphere (centre + sqr(radius))? + bool overlaps(const point&, const scalar radiusSqr) const; //- Intersects segment; set point to intersection position, // return true if intersection found. diff --git a/src/meshTools/octree/treeBoundBoxI.H b/src/meshTools/octree/treeBoundBoxI.H index 431eb8a04d34f04add1d31491efd0be344f2d613..c444b2808ae2a2e2856c6b3c161fe012cddb029a 100644 --- a/src/meshTools/octree/treeBoundBoxI.H +++ b/src/meshTools/octree/treeBoundBoxI.H @@ -24,9 +24,7 @@ License \*---------------------------------------------------------------------------*/ -#include "error.H" #include "treeBoundBox.H" -#include "point.H" #include "Random.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -414,9 +412,9 @@ inline void treeBoundBox::searchOrder // true if bb's intersect or overlap. // Note: <= to make sure we catch all. -inline bool treeBoundBox::intersects(const treeBoundBox& bb) const +inline bool treeBoundBox::overlaps(const treeBoundBox& bb) const { - return boundBox::intersects(bb); + return boundBox::overlaps(bb); } diff --git a/src/meshTools/octree/treeNode.C b/src/meshTools/octree/treeNode.C index 678bcfb694d3c81db7c7cd09aaed6f78b6c94896..771ef2cdd98514624701f0bea2cb5c2384808e39 100644 --- a/src/meshTools/octree/treeNode.C +++ b/src/meshTools/octree/treeNode.C @@ -798,7 +798,7 @@ bool treeNode<Type>::findTightest // Node: recurse into subnodes const treeNode<Type>* subNodePtr = getNodePtr(octant); - if (subNodePtr->bb().intersects(tightest)) + if (subNodePtr->bb().overlaps(tightest)) { // there might be a better fit inside this subNode changed |= @@ -815,7 +815,7 @@ bool treeNode<Type>::findTightest // Leaf: let leaf::find handle this const treeLeaf<Type>* subLeafPtr = getLeafPtr(octant); - if (subLeafPtr->bb().intersects(tightest)) + if (subLeafPtr->bb().overlaps(tightest)) { // there might be a better fit inside this subLeaf changed |= @@ -884,7 +884,7 @@ bool treeNode<Type>::findNearest // Node const treeNode<Type>* subNodePtr = getNodePtr(octant); - if (subNodePtr->bb().intersects(tightest)) + if (subNodePtr->bb().overlaps(tightest)) { // there might be a better fit inside this subNode changed |= @@ -903,7 +903,7 @@ bool treeNode<Type>::findNearest // Leaf: let leaf::find handle this const treeLeaf<Type>* subLeafPtr = getLeafPtr(octant); - if (subLeafPtr->bb().intersects(tightest)) + if (subLeafPtr->bb().overlaps(tightest)) { // there might be a better fit inside this subNode changed |= @@ -975,7 +975,7 @@ bool treeNode<Type>::findNearest // Node const treeNode<Type>* subNodePtr = getNodePtr(octant); - if (subNodePtr->bb().intersects(tightest)) + if (subNodePtr->bb().overlaps(tightest)) { // there might be a better fit inside this subNode changed |= @@ -995,7 +995,7 @@ bool treeNode<Type>::findNearest // Leaf: let leaf::find handle this const treeLeaf<Type>* subLeafPtr = getLeafPtr(octant); - if (subLeafPtr->bb().intersects(tightest)) + if (subLeafPtr->bb().overlaps(tightest)) { // there might be a better fit inside this subNode changed |= @@ -1060,7 +1060,7 @@ bool treeNode<Type>::findBox // Node const treeNode<Type>* subNodePtr = getNodePtr(octant); - if (subNodePtr->bb().intersects(box)) + if (subNodePtr->bb().overlaps(box)) { // Visit sub node. changed |= subNodePtr->findBox(shapes, box, elements); @@ -1071,7 +1071,7 @@ bool treeNode<Type>::findBox // Leaf: let leaf::find handle this const treeLeaf<Type>* subLeafPtr = getLeafPtr(octant); - if (subLeafPtr->bb().intersects(box)) + if (subLeafPtr->bb().overlaps(box)) { // Visit sub leaf. changed |= subLeafPtr->findBox(shapes, box, elements); diff --git a/src/meshTools/triSurface/octreeData/octreeDataTriSurface.C b/src/meshTools/triSurface/octreeData/octreeDataTriSurface.C index 6a21879f35efb1f95d93ac9943b3c00891dd89d3..f3dd4f3e03e8b563c8ecc87ac789b529a71cb44f 100644 --- a/src/meshTools/triSurface/octreeData/octreeDataTriSurface.C +++ b/src/meshTools/triSurface/octreeData/octreeDataTriSurface.C @@ -385,12 +385,12 @@ bool Foam::octreeDataTriSurface::overlaps const treeBoundBox& cubeBb ) const { - //return cubeBb.intersects(allBb_[index]); + //return cubeBb.overlaps(allBb_[index]); //- Exact test of triangle intersecting bb // Quick rejection. - if (!cubeBb.intersects(allBb_[index])) + if (!cubeBb.overlaps(allBb_[index])) { return false; } diff --git a/src/meshTools/triSurface/octreeData/octreeDataTriSurfaceTreeLeaf.C b/src/meshTools/triSurface/octreeData/octreeDataTriSurfaceTreeLeaf.C index 6582cfd2399581a2978afc36637aec7947f3906a..ca4a34975c324438fb36f9aa6b95a576c29cef23 100644 --- a/src/meshTools/triSurface/octreeData/octreeDataTriSurfaceTreeLeaf.C +++ b/src/meshTools/triSurface/octreeData/octreeDataTriSurfaceTreeLeaf.C @@ -54,7 +54,7 @@ bool Foam::treeLeaf<Foam::octreeDataTriSurface>::findNearest label faceI = indices_[i]; // Quick rejection test. - if (tightest.intersects(allBb[faceI])) + if (tightest.overlaps(allBb[faceI])) { // Full calculation scalar dist = shapes.calcNearest(faceI, sample, nearest);