ENH: bug in findSphere test and implemented for treeDataPrimitivePatch.

This commit is contained in:
graham
2011-06-03 16:07:17 +01:00
parent 013be3215b
commit 231d1318bd
3 changed files with 66 additions and 2 deletions

View File

@ -2076,7 +2076,7 @@ void Foam::indexedOctree<Type>::findSphere
if (subBb.overlaps(centre, radiusSqr)) if (subBb.overlaps(centre, radiusSqr))
{ {
findBox(getNode(index), centre, radiusSqr, elements); findSphere(getNode(index), centre, radiusSqr, elements);
} }
} }
else if (isContent(index)) else if (isContent(index))

View File

@ -461,6 +461,55 @@ overlaps
} }
// Check if any point on shape is inside sphere.
template
<
class Face,
template<class> class FaceList,
class PointField,
class PointType
>
bool
Foam::treeDataPrimitivePatch<Face, FaceList, PointField, PointType>::
overlaps
(
const label index,
const point& centre,
const scalar radiusSqr
) const
{
// 1. Quick rejection: sphere does not intersect face bb at all
if (cacheBb_)
{
if (!bbs_[index].overlaps(centre, radiusSqr))
{
return false;
}
}
else
{
if (!calcBb(patch_.points(), patch_[index]).overlaps(centre, radiusSqr))
{
return false;
}
}
const pointField& points = patch_.points();
const face& f = patch_[index];
pointHit nearHit = f.nearestPoint(centre, points);
// If the distance to the nearest point on the face from the sphere centres
// is within the radius, then the sphere touches the face.
if (sqr(nearHit.distance()) < radiusSqr)
{
return true;
}
return false;
}
// Calculate nearest point to sample. Updates (if any) nearestDistSqr, minIndex, // Calculate nearest point to sample. Updates (if any) nearestDistSqr, minIndex,
// nearestPoint. // nearestPoint.
template template

View File

@ -120,6 +120,13 @@ public:
// (one point per shape) // (one point per shape)
pointField shapePoints() const; pointField shapePoints() const;
//- Return access to the underlying patch
const PrimitivePatch<Face, FaceList, PointField, PointType>&
patch() const
{
return patch_;
}
// Search // Search
@ -140,13 +147,21 @@ public:
const point& const point&
) const; ) const;
//- Does (bb of) shape at index overlap bb //- Does shape at index overlap bb
bool overlaps bool overlaps
( (
const label index, const label index,
const treeBoundBox& sampleBb const treeBoundBox& sampleBb
) const; ) const;
//- Does shape at index overlap sphere
bool overlaps
(
const label index,
const point& centre,
const scalar radiusSqr
) const;
//- Calculates nearest (to sample) point in shape. //- Calculates nearest (to sample) point in shape.
// Returns actual point and distance (squared) // Returns actual point and distance (squared)
void findNearest void findNearest