boundbox intersect renaming

This commit is contained in:
mattijs
2008-08-28 15:50:11 +01:00
parent 4dc1c78a28
commit 212a70a17b
18 changed files with 86 additions and 46 deletions

View File

@ -504,7 +504,7 @@ int main(int argc, char *argv[])
!bbsTargetSet[procITarget] !bbsTargetSet[procITarget]
|| ( || (
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(); bbsTarget[procITarget] = meshTarget.bounds();
bbsTargetSet[procITarget] = true; bbsTargetSet[procITarget] = true;
if (bbsTarget[procITarget].intersects(bbSource)) if (bbsTarget[procITarget].overlaps(bbSource))
{ {
if (consistent) if (consistent)
{ {

View File

@ -118,7 +118,7 @@ public:
// Query // Query
//- Intersects other boundingbox? //- Intersects other boundingbox?
bool intersects(const boundBox& bb) const bool overlaps(const boundBox& bb) const
{ {
if if
( (

View File

@ -399,7 +399,7 @@ bool Foam::octreeDataFaceList::overlaps
const treeBoundBox& sampleBb const treeBoundBox& sampleBb
) const ) const
{ {
return sampleBb.intersects(allBb_[index]); return sampleBb.overlaps(allBb_[index]);
} }

View File

@ -40,7 +40,7 @@ namespace Foam
// Does bb intersect a sphere around sample? Or is any corner point of bb // Does bb intersect a sphere around sample? Or is any corner point of bb
// closer than nearestDistSqr to sample. // closer than nearestDistSqr to sample.
template <class Type> template <class Type>
bool indexedOctree<Type>::intersects bool indexedOctree<Type>::overlaps
( (
const point& p0, const point& p0,
const point& p1, 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 // Does bb intersect a sphere around sample? Or is any corner point of bb
// closer than nearestDistSqr to sample. // closer than nearestDistSqr to sample.
template <class Type> template <class Type>
bool indexedOctree<Type>::intersects bool indexedOctree<Type>::overlaps
( (
const treeBoundBox& parentBb, const treeBoundBox& parentBb,
const direction octant, const direction octant,
@ -94,7 +94,7 @@ bool indexedOctree<Type>::intersects
{ {
//- Speeded up version of //- Speeded up version of
// treeBoundBox subBb(parentBb.subBbox(mid, octant)) // treeBoundBox subBb(parentBb.subBbox(mid, octant))
// intersects // overlaps
// ( // (
// subBb.min(), // subBb.min(),
// subBb.max(), // subBb.max(),
@ -136,7 +136,7 @@ bool indexedOctree<Type>::intersects
const point mid(0.5*(min+max)); 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_; const treeBoundBox& subBb = nodes_[subNodeI].bb_;
if (intersects(subBb.min(), subBb.max(), nearestDistSqr, sample)) if (overlaps(subBb.min(), subBb.max(), nearestDistSqr, sample))
{ {
findNearest findNearest
( (
@ -584,7 +584,7 @@ void indexedOctree<Type>::findNearest
{ {
if if
( (
intersects overlaps
( (
nod.bb_, nod.bb_,
octant, octant,
@ -639,7 +639,7 @@ void indexedOctree<Type>::findNearest
{ {
const treeBoundBox& subBb = nodes_[getNode(index)].bb_; const treeBoundBox& subBb = nodes_[getNode(index)].bb_;
if (subBb.intersects(tightest)) if (subBb.overlaps(tightest))
{ {
findNearest findNearest
( (
@ -657,7 +657,7 @@ void indexedOctree<Type>::findNearest
{ {
const treeBoundBox subBb(nodeBb.subBbox(octant)); const treeBoundBox subBb(nodeBb.subBbox(octant));
if (subBb.intersects(tightest)) if (subBb.overlaps(tightest))
{ {
shapes_.findNearest shapes_.findNearest
( (
@ -1121,7 +1121,7 @@ void indexedOctree<Type>::findBox
{ {
const treeBoundBox& subBb = nodes_[getNode(index)].bb_; const treeBoundBox& subBb = nodes_[getNode(index)].bb_;
if (subBb.intersects(searchBox)) if (subBb.overlaps(searchBox))
{ {
findBox(getNode(index), searchBox, elements); findBox(getNode(index), searchBox, elements);
} }
@ -1130,7 +1130,7 @@ void indexedOctree<Type>::findBox
{ {
const treeBoundBox subBb(nodeBb.subBbox(octant)); const treeBoundBox subBb(nodeBb.subBbox(octant));
if (subBb.intersects(searchBox)) if (subBb.overlaps(searchBox))
{ {
const labelList& indices = contents_[getContent(index)]; const labelList& indices = contents_[getContent(index)];

View File

@ -36,9 +36,9 @@ SourceFiles
#ifndef indexedOctree_H #ifndef indexedOctree_H
#define indexedOctree_H #define indexedOctree_H
#include "treeBoundBox.H"
#include "pointIndexHit.H" #include "pointIndexHit.H"
#include "FixedList.H" #include "FixedList.H"
#include "treeBoundBox.H"
#include "Ostream.H" #include "Ostream.H"
#include "labelHashSet.H" #include "labelHashSet.H"
#include "labelBits.H" #include "labelBits.H"
@ -146,7 +146,7 @@ private:
//- Like above but now bb is implicitly provided as parent bb + mid //- Like above but now bb is implicitly provided as parent bb + mid
// + octant // + octant
static bool intersects static bool overlaps
( (
const treeBoundBox& parentBb, const treeBoundBox& parentBb,
const direction octant, const direction octant,
@ -497,7 +497,7 @@ public:
//- Helper: does bb intersect a sphere around sample? Or is any //- Helper: does bb intersect a sphere around sample? Or is any
// corner point of bb closer than nearestDistSqr to sample. // corner point of bb closer than nearestDistSqr to sample.
static bool intersects static bool overlaps
( (
const point& bbMin, const point& bbMin,
const point& bbMax, const point& bbMax,

View File

@ -137,11 +137,11 @@ bool Foam::treeDataCell::overlaps
{ {
if (cacheBb_) if (cacheBb_)
{ {
return cubeBb.intersects(bbs_[index]); return cubeBb.overlaps(bbs_[index]);
} }
else else
{ {
return cubeBb.intersects(calcCellBb(cellLabels_[index])); return cubeBb.overlaps(calcCellBb(cellLabels_[index]));
} }
} }

View File

@ -110,11 +110,11 @@ bool Foam::treeDataEdge::overlaps
{ {
if (cacheBb_) if (cacheBb_)
{ {
return cubeBb.intersects(bbs_[index]); return cubeBb.overlaps(bbs_[index]);
} }
else else
{ {
return cubeBb.intersects(calcBb(edgeLabels_[index])); return cubeBb.overlaps(calcBb(edgeLabels_[index]));
} }
} }

View File

@ -412,14 +412,14 @@ bool Foam::treeDataFace::overlaps
// 1. Quick rejection: bb does not intersect face bb at all // 1. Quick rejection: bb does not intersect face bb at all
if (cacheBb_) if (cacheBb_)
{ {
if (!cubeBb.intersects(bbs_[index])) if (!cubeBb.overlaps(bbs_[index]))
{ {
return false; return false;
} }
} }
else else
{ {
if (!cubeBb.intersects(calcBb(faceLabels_[index]))) if (!cubeBb.overlaps(calcBb(faceLabels_[index])))
{ {
return false; return false;
} }

View File

@ -284,13 +284,13 @@ bool Foam::treeDataTriSurface::overlaps
triBb.max() = max(triBb.max(), p2); triBb.max() = max(triBb.max(), p2);
//- For testing: robust one //- For testing: robust one
//return cubeBb.intersects(triBb); //return cubeBb.overlaps(triBb);
//- Exact test of triangle intersecting bb //- Exact test of triangle intersecting bb
// Quick rejection. If whole bounding box of tri is outside cubeBb then // Quick rejection. If whole bounding box of tri is outside cubeBb then
// there will be no intersection. // there will be no intersection.
if (!cubeBb.intersects(triBb)) if (!cubeBb.overlaps(triBb))
{ {
return false; return false;
} }

View File

@ -113,7 +113,7 @@ bool Foam::octreeDataCell::overlaps
const treeBoundBox& cubeBb const treeBoundBox& cubeBb
) const ) const
{ {
return cubeBb.intersects(bbs_[index]); return cubeBb.overlaps(bbs_[index]);
} }

View File

@ -107,7 +107,7 @@ bool Foam::octreeDataEdges::overlaps
const treeBoundBox& sampleBb const treeBoundBox& sampleBb
) const ) const
{ {
return sampleBb.intersects(allBb_[index]); return sampleBb.overlaps(allBb_[index]);
} }

View File

@ -507,12 +507,12 @@ bool Foam::octreeDataFace::overlaps
const treeBoundBox& sampleBb const treeBoundBox& sampleBb
) const ) const
{ {
//return sampleBb.intersects(allBb_[index]); //return sampleBb.overlaps(allBb_[index]);
//- Exact test of face intersecting bb //- Exact test of face intersecting bb
// 1. Quick rejection: bb does not intersect face bb at all // 1. Quick rejection: bb does not intersect face bb at all
if (!sampleBb.intersects(allBb_[index])) if (!sampleBb.overlaps(allBb_[index]))
{ {
return false; return false;
} }

View File

@ -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 // line intersection. Returns true if line (start to end) inside
// bb or intersects bb. Sets pt to intersection. // bb or intersects bb. Sets pt to intersection.
// //

View File

@ -263,8 +263,11 @@ public:
FixedList<direction, 8>& octantOrder FixedList<direction, 8>& octantOrder
) const; ) const;
//- Intersects other boundingbox? //- Overlaps other boundingbox?
inline bool intersects(const treeBoundBox&) const; 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, //- Intersects segment; set point to intersection position,
// return true if intersection found. // return true if intersection found.

View File

@ -24,9 +24,7 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "error.H"
#include "treeBoundBox.H" #include "treeBoundBox.H"
#include "point.H"
#include "Random.H" #include "Random.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -414,9 +412,9 @@ inline void treeBoundBox::searchOrder
// true if bb's intersect or overlap. // true if bb's intersect or overlap.
// Note: <= to make sure we catch all. // 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);
} }

View File

@ -798,7 +798,7 @@ bool treeNode<Type>::findTightest
// Node: recurse into subnodes // Node: recurse into subnodes
const treeNode<Type>* subNodePtr = getNodePtr(octant); 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 // there might be a better fit inside this subNode
changed |= changed |=
@ -815,7 +815,7 @@ bool treeNode<Type>::findTightest
// Leaf: let leaf::find handle this // Leaf: let leaf::find handle this
const treeLeaf<Type>* subLeafPtr = getLeafPtr(octant); 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 // there might be a better fit inside this subLeaf
changed |= changed |=
@ -884,7 +884,7 @@ bool treeNode<Type>::findNearest
// Node // Node
const treeNode<Type>* subNodePtr = getNodePtr(octant); 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 // there might be a better fit inside this subNode
changed |= changed |=
@ -903,7 +903,7 @@ bool treeNode<Type>::findNearest
// Leaf: let leaf::find handle this // Leaf: let leaf::find handle this
const treeLeaf<Type>* subLeafPtr = getLeafPtr(octant); 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 // there might be a better fit inside this subNode
changed |= changed |=
@ -975,7 +975,7 @@ bool treeNode<Type>::findNearest
// Node // Node
const treeNode<Type>* subNodePtr = getNodePtr(octant); 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 // there might be a better fit inside this subNode
changed |= changed |=
@ -995,7 +995,7 @@ bool treeNode<Type>::findNearest
// Leaf: let leaf::find handle this // Leaf: let leaf::find handle this
const treeLeaf<Type>* subLeafPtr = getLeafPtr(octant); 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 // there might be a better fit inside this subNode
changed |= changed |=
@ -1060,7 +1060,7 @@ bool treeNode<Type>::findBox
// Node // Node
const treeNode<Type>* subNodePtr = getNodePtr(octant); const treeNode<Type>* subNodePtr = getNodePtr(octant);
if (subNodePtr->bb().intersects(box)) if (subNodePtr->bb().overlaps(box))
{ {
// Visit sub node. // Visit sub node.
changed |= subNodePtr->findBox(shapes, box, elements); changed |= subNodePtr->findBox(shapes, box, elements);
@ -1071,7 +1071,7 @@ bool treeNode<Type>::findBox
// Leaf: let leaf::find handle this // Leaf: let leaf::find handle this
const treeLeaf<Type>* subLeafPtr = getLeafPtr(octant); const treeLeaf<Type>* subLeafPtr = getLeafPtr(octant);
if (subLeafPtr->bb().intersects(box)) if (subLeafPtr->bb().overlaps(box))
{ {
// Visit sub leaf. // Visit sub leaf.
changed |= subLeafPtr->findBox(shapes, box, elements); changed |= subLeafPtr->findBox(shapes, box, elements);

View File

@ -385,12 +385,12 @@ bool Foam::octreeDataTriSurface::overlaps
const treeBoundBox& cubeBb const treeBoundBox& cubeBb
) const ) const
{ {
//return cubeBb.intersects(allBb_[index]); //return cubeBb.overlaps(allBb_[index]);
//- Exact test of triangle intersecting bb //- Exact test of triangle intersecting bb
// Quick rejection. // Quick rejection.
if (!cubeBb.intersects(allBb_[index])) if (!cubeBb.overlaps(allBb_[index]))
{ {
return false; return false;
} }

View File

@ -54,7 +54,7 @@ bool Foam::treeLeaf<Foam::octreeDataTriSurface>::findNearest
label faceI = indices_[i]; label faceI = indices_[i];
// Quick rejection test. // Quick rejection test.
if (tightest.intersects(allBb[faceI])) if (tightest.overlaps(allBb[faceI]))
{ {
// Full calculation // Full calculation
scalar dist = shapes.calcNearest(faceI, sample, nearest); scalar dist = shapes.calcNearest(faceI, sample, nearest);