Skip to content
Snippets Groups Projects
Commit e999e0ac authored by Yohann Bearzi (Kitware)'s avatar Yohann Bearzi (Kitware)
Browse files

Adding API to `vtkBoundingBox`

`vtkBoundingBox` can now test intersection with spheres
with `vtkBoundingBox::IntersectsSphere`.

Method `vtkBoundingBox::ComputeInnerDimension` tells
what is the inner dimension of itself.
parent 32a4d0ba
No related branches found
No related tags found
No related merge requests found
...@@ -628,6 +628,38 @@ bool vtkBoundingBox::IntersectPlane(double origin[3], double normal[3]) ...@@ -628,6 +628,38 @@ bool vtkBoundingBox::IntersectPlane(double origin[3], double normal[3])
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
bool vtkBoundingBox::IntersectsSphere(double center[3], double radius) const
{
return center[0] >= this->MinPnt[0] - radius && center[0] <= this->MaxPnt[0] + radius &&
center[1] >= this->MinPnt[1] - radius && center[1] <= this->MaxPnt[1] + radius &&
center[2] >= this->MinPnt[2] - radius && center[2] <= this->MaxPnt[2] + radius;
}
// ---------------------------------------------------------------------------
int vtkBoundingBox::ComputeInnerDimension() const
{
double thickness = this->MaxPnt[0] - this->MinPnt[0];
int dim = 3;
if (std::abs(thickness) <=
std::max(std::fabs(this->MaxPnt[0]), std::fabs(this->MinPnt[0])) * VTK_DBL_EPSILON)
{
--dim;
}
thickness = this->MaxPnt[1] - this->MinPnt[1];
if (std::abs(thickness) <=
std::max(std::fabs(this->MaxPnt[1]), std::fabs(this->MinPnt[1])) * VTK_DBL_EPSILON)
{
--dim;
}
thickness = this->MaxPnt[2] - this->MinPnt[2];
if (std::fabs(thickness) <=
std::max(std::fabs(this->MaxPnt[2]), std::fabs(this->MinPnt[2])) * VTK_DBL_EPSILON)
{
--dim;
}
return dim;
}
// Support ComputeBounds() // Support ComputeBounds()
namespace namespace
{ {
......
...@@ -143,6 +143,11 @@ public: ...@@ -143,6 +143,11 @@ public:
*/ */
void AddBounds(const double bounds[]); void AddBounds(const double bounds[]);
/**
* Returns true if this instance is entirely contained by bbox.
*/
bool IsSubsetOf(const vtkBoundingBox& bbox) const;
/** /**
* Intersect this box with bbox. The method returns 1 if both boxes are * Intersect this box with bbox. The method returns 1 if both boxes are
* valid and they do have overlap else it will return 0. If 0 is returned * valid and they do have overlap else it will return 0. If 0 is returned
...@@ -162,6 +167,17 @@ public: ...@@ -162,6 +167,17 @@ public:
*/ */
bool IntersectPlane(double origin[3], double normal[3]); bool IntersectPlane(double origin[3], double normal[3]);
/**
* Intersect this box with a sphere.
* Parameters involve the center of the sphere and the squared radius.
*/
bool IntersectsSphere(double center[3], double squaredRadius) const;
/**
* Returns the inner dimension of the bounding box.
*/
int ComputeInnerDimension() const;
/** /**
* Returns 1 if the min and max points of bbox are contained * Returns 1 if the min and max points of bbox are contained
* within the bounds of the specified box, else returns 0. * within the bounds of the specified box, else returns 0.
...@@ -376,6 +392,15 @@ inline void vtkBoundingBox::GetCenter(double center[3]) const ...@@ -376,6 +392,15 @@ inline void vtkBoundingBox::GetCenter(double center[3]) const
center[2] = 0.5 * (this->MaxPnt[2] + this->MinPnt[2]); center[2] = 0.5 * (this->MaxPnt[2] + this->MinPnt[2]);
} }
inline bool vtkBoundingBox::IsSubsetOf(const vtkBoundingBox& bbox) const
{
const double* bboxMaxPnt = bbox.GetMaxPoint();
const double* bboxMinPnt = bbox.GetMinPoint();
return this->MaxPnt[0] < bboxMaxPnt[0] && this->MinPnt[0] > bboxMinPnt[0] &&
this->MaxPnt[1] < bboxMaxPnt[1] && this->MinPnt[1] > bboxMinPnt[1] &&
this->MaxPnt[2] < bboxMaxPnt[2] && this->MinPnt[2] > bboxMinPnt[2];
}
inline void vtkBoundingBox::SetBounds(const double bounds[6]) inline void vtkBoundingBox::SetBounds(const double bounds[6])
{ {
this->SetBounds(bounds[0], bounds[1], bounds[2], bounds[3], bounds[4], bounds[5]); this->SetBounds(bounds[0], bounds[1], bounds[2], bounds[3], bounds[4], bounds[5]);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment