19 #ifndef vtkBoundingBox_h
20 #define vtkBoundingBox_h
21 #include "vtkCommonDataModelModule.h"
27 VTK_ABI_NAMESPACE_BEGIN
46 vtkBoundingBox(
double xMin,
double xMax,
double yMin,
double yMax,
double zMin,
double zMax);
80 void SetBounds(
const double bounds[6]);
81 void SetBounds(
double xMin,
double xMax,
double yMin,
double yMax,
double zMin,
double zMax);
92 static void ComputeBounds(
vtkPoints* pts,
double bounds[6]);
93 static void ComputeBounds(
vtkPoints* pts,
const unsigned char* ptUses,
double bounds[6]);
94 static void ComputeBounds(
95 vtkPoints* pts,
const std::atomic<unsigned char>* ptUses,
double bounds[6]);
96 template <
typename TIter>
97 static void ComputeBounds(
vtkPoints* pts, TIter ptIds,
vtkIdType numPointIds,
double bounds[6]);
102 this->MinPnt[0] = bds[0];
103 this->MinPnt[1] = bds[2];
104 this->MinPnt[2] = bds[4];
105 this->MaxPnt[0] = bds[1];
106 this->MaxPnt[1] = bds[3];
107 this->MaxPnt[2] = bds[5];
113 this->MinPnt[0] = bds[0];
114 this->MinPnt[1] = bds[2];
115 this->MinPnt[2] = bds[4];
116 this->MaxPnt[0] = bds[1];
117 this->MaxPnt[1] = bds[3];
118 this->MaxPnt[2] = bds[5];
127 static void ComputeLocalBounds(
128 vtkPoints*
points,
double u[3],
double v[3],
double w[3],
double outputBounds[6]);
136 void SetMinPoint(
double x,
double y,
double z);
137 void SetMinPoint(
double p[3]);
145 void SetMaxPoint(
double x,
double y,
double z);
146 void SetMaxPoint(
double p[3]);
155 static int IsValid(
const double bounds[6]);
163 void AddPoint(
double p[3]);
164 void AddPoint(
double px,
double py,
double pz);
177 void AddBounds(
const double bounds[6]);
201 bool IntersectPlane(
double origin[3],
double normal[3]);
211 const double min[3],
const double max[3],
const double center[3],
double r2)
214 for (
int i = 0; i < 3; ++i)
216 if (center[i] < min[i])
218 d2 += (center[i] - min[i]) * (center[i] - min[i]);
220 else if (center[i] > max[i])
222 d2 += (center[i] - max[i]) * (center[i] - max[i]);
232 bool IntersectsSphere(
double center[3],
double radius)
const;
250 const double min[3],
const double max[3],
const double center[3],
double r2)
253 for (
int i = 0; i < 3; ++i)
255 double a = (center[i] - min[i]) * (center[i] - min[i]);
256 double b = (center[i] - max[i]) * (center[i] - max[i]);
275 bool IntersectsLine(
const double p1[3],
const double p2[3])
const;
280 int ComputeInnerDimension()
const;
304 static bool ContainsLine(
const double x[3],
const double s[3],
const double lineEnd[3],
double& t,
305 double xInt[3],
int& plane);
313 double& xMin,
double& xMax,
double& yMin,
double& yMax,
double& zMin,
double& zMax)
const;
319 double GetBound(
int i)
const;
326 void GetMinPoint(
double& x,
double& y,
double& z) const;
327 void GetMinPoint(
double x[3]) const;
335 void GetMaxPoint(
double& x,
double& y,
double& z) const;
336 void GetMaxPoint(
double x[3]) const;
343 void GetCorner(
int corner,
double p[3]) const;
349 vtkTypeBool ContainsPoint(const
double p[3]) const;
350 vtkTypeBool ContainsPoint(
double px,
double py,
double pz) const;
351 template <class PointT>
352 bool ContainsPoint(const PointT& p) const;
358 void GetCenter(
double center[3]) const;
363 void GetLengths(
double lengths[3]) const;
368 double GetLength(
int i) const;
373 double GetMaxLength() const;
380 double GetDiagonalLength2() const;
381 double GetDiagonalLength() const;
396 void Inflate(
double delta);
397 void Inflate(
double deltaX,
double deltaY,
double deltaZ);
399 void InflateSlice(
double delta);
409 void Scale(
double s[3]);
410 void Scale(
double sx,
double sy,
double sz);
419 void ScaleAboutCenter(
double s);
420 void ScaleAboutCenter(
double s[3]);
421 void ScaleAboutCenter(
double sx,
double sy,
double sz);
440 static
void ClampDivisions(
vtkIdType targetBins,
int divs[3]);
451 void ClampPoint(
double point[3]);
459 void GetDistance(
double point[3],
double distance[3]);
465 void Translate(
double motion[3]);
468 double MinPnt[3], MaxPnt[3];
473 this->MinPnt[0] = this->MinPnt[1] = this->MinPnt[2] =
VTK_DOUBLE_MAX;
474 this->MaxPnt[0] = this->MaxPnt[1] = this->MaxPnt[2] =
VTK_DOUBLE_MIN;
478 double& xMin,
double& xMax,
double& yMin,
double& yMax,
double& zMin,
double& zMax)
const
480 xMin = this->MinPnt[0];
481 xMax = this->MaxPnt[0];
482 yMin = this->MinPnt[1];
483 yMax = this->MaxPnt[1];
484 zMin = this->MinPnt[2];
485 zMax = this->MaxPnt[2];
493 return ((i & 0x1) ? this->MaxPnt[i >> 1] : this->MinPnt[i >> 1]);
503 x[0] = this->MinPnt[0];
504 x[1] = this->MinPnt[1];
505 x[2] = this->MinPnt[2];
515 x[0] = this->MaxPnt[0];
516 x[1] = this->MaxPnt[1];
517 x[2] = this->MaxPnt[2];
522 return ((this->MinPnt[0] <= this->MaxPnt[0]) && (this->MinPnt[1] <= this->MaxPnt[1]) &&
523 (this->MinPnt[2] <= this->MaxPnt[2]));
528 return (bounds[0] <= bounds[1] && bounds[2] <= bounds[3] && bounds[4] <= bounds[5]);
533 return this->MaxPnt[i] - this->MinPnt[i];
538 lengths[0] = this->GetLength(0);
539 lengths[1] = this->GetLength(1);
540 lengths[2] = this->GetLength(2);
545 center[0] = 0.5 * (this->MaxPnt[0] + this->MinPnt[0]);
546 center[1] = 0.5 * (this->MaxPnt[1] + this->MinPnt[1]);
547 center[2] = 0.5 * (this->MaxPnt[2] + this->MinPnt[2]);
554 return this->MaxPnt[0] < bboxMaxPnt[0] && this->MinPnt[0] > bboxMinPnt[0] &&
555 this->MaxPnt[1] < bboxMaxPnt[1] && this->MinPnt[1] > bboxMinPnt[1] &&
556 this->MaxPnt[2] < bboxMaxPnt[2] && this->MinPnt[2] > bboxMinPnt[2];
561 this->SetBounds(bounds[0], bounds[1], bounds[2], bounds[3], bounds[4], bounds[5]);
566 this->
GetBounds(bounds[0], bounds[1], bounds[2], bounds[3], bounds[4], bounds[5]);
577 this->SetBounds(bounds);
581 double xMin,
double xMax,
double yMin,
double yMax,
double zMin,
double zMax)
584 this->SetBounds(xMin, xMax, yMin, yMax, zMin, zMax);
589 this->MinPnt[0] = bbox.
MinPnt[0];
590 this->MinPnt[1] = bbox.
MinPnt[1];
591 this->MinPnt[2] = bbox.
MinPnt[2];
593 this->MaxPnt[0] = bbox.
MaxPnt[0];
594 this->MaxPnt[1] = bbox.
MaxPnt[1];
595 this->MaxPnt[2] = bbox.
MaxPnt[2];
600 this->MinPnt[0] = min[0];
601 this->MinPnt[1] = min[1];
602 this->MinPnt[2] = min[2];
604 this->MaxPnt[0] = max[0];
605 this->MaxPnt[1] = max[1];
606 this->MaxPnt[2] = max[2];
612 this->AddPoint(center);
613 this->Inflate(delta);
618 this->MinPnt[0] = bbox.
MinPnt[0];
619 this->MinPnt[1] = bbox.
MinPnt[1];
620 this->MinPnt[2] = bbox.
MinPnt[2];
622 this->MaxPnt[0] = bbox.
MaxPnt[0];
623 this->MaxPnt[1] = bbox.
MaxPnt[1];
624 this->MaxPnt[2] = bbox.
MaxPnt[2];
630 return ((this->MinPnt[0] == bbox.
MinPnt[0]) && (this->MinPnt[1] == bbox.
MinPnt[1]) &&
631 (this->MinPnt[2] == bbox.
MinPnt[2]) && (this->MaxPnt[0] == bbox.
MaxPnt[0]) &&
632 (this->MaxPnt[1] == bbox.
MaxPnt[1]) && (this->MaxPnt[2] == bbox.
MaxPnt[2]));
637 return !((*this) == bbox);
642 this->SetMinPoint(p[0], p[1], p[2]);
647 this->SetMaxPoint(p[0], p[1], p[2]);
666 if ((px < this->MinPnt[0]) || (px > this->MaxPnt[0]))
670 if ((py < this->MinPnt[1]) || (py > this->MaxPnt[1]))
674 if ((pz < this->MinPnt[2]) || (pz > this->MaxPnt[2]))
683 return this->ContainsPoint(p[0], p[1], p[2]);
686 template <
class Po
intT>
689 return this->ContainsPoint(p[0], p[1], p[2]);
694 if ((corner < 0) || (corner > 7))
702 int ix = (corner & 1) ? 1 : 0;
703 int iy = ((corner >> 1) & 1) ? 1 : 0;
704 int iz = (corner >> 2) ? 1 : 0;
706 const double* pts[2] = { this->MinPnt, this->MaxPnt };
712 VTK_ABI_NAMESPACE_END
void GetBounds(double bounds[6]) const
Get the bounds of the box (defined by VTK style).
void GetBounds(T a, double bds[6])
const double * GetMinPoint() const
Get the minimum point of the bounding box.
void SetMaxPoint(double x, double y, double z)
Set the maximum point of the bounding box - if the max point is less than the min point then the min ...
void ComputeBounds(vtkPoints *pts)
Compute the bounding box from an array of vtkPoints.
bool operator!=(const vtkBoundingBox &bbox) const
Equality operator.
static void ComputeBounds(vtkPoints *pts, double bounds[6])
Compute the bounding box from an array of vtkPoints.
bool VTKCOMMONCORE_EXPORT operator==(const std::string &a, const vtkStringToken &b)
void GetCorner(int corner, double p[3]) const
Get the ith corner of the bounding box.
bool operator==(const vtkBoundingBox &bbox) const
Equality operator.
void GetCenter(double center[3]) const
Get the center of the bounding box.
int IsValid() const
Returns 1 if the bounds have been set and 0 if the box is in its initialized state which is an invert...
double GetBound(int i) const
Return the ith bounds of the box (defined by VTK style).
void GetLengths(double lengths[3]) const
Get the length of each side of the box.
static bool InsideSphere(const double min[3], const double max[3], const double center[3], double r2)
Determine if a box is fully inside a sphere.
vtkBoundingBox & operator=(const vtkBoundingBox &bbox)
Assignment Operator.
bool VTKCOMMONCORE_EXPORT operator!=(const std::string &a, const vtkStringToken &b)
vtkTypeBool ContainsPoint(const double p[3]) const
Returns 1 if the point is contained in the box else 0.
#define VTK_SIZEHINT(...)
bool IsSubsetOf(const vtkBoundingBox &bbox) const
Returns true if this instance is entirely contained by bbox.
void SetMinPoint(double x, double y, double z)
Set the minimum point of the bounding box - if the min point is greater than the max point then the m...
double GetLength(int i) const
Return the length of the bounding box in the ith direction.
bool IntersectsSphere2(double center[3], double radius2) const
Intersect this box with a sphere.
void SetBounds(const double bounds[6])
Set the bounds explicitly of the box (using the VTK convention for representing a bounding box)...
vtkBoundingBox()
Construct a bounding box with the min point set to VTK_DOUBLE_MAX and the max point set to VTK_DOUBLE...
static bool IntersectsSphere(const double min[3], const double max[3], const double center[3], double r2)
Performant method to intersect box with a sphere.
void ComputeBounds(vtkPoints *pts, unsigned char *ptUses)
Compute the bounding box from an array of vtkPoints.
const double * GetMaxPoint() const
Get the maximum point of the bounding box.
represent and manipulate 3D points
Fast, simple class for representing and operating on 3D bounds.
bool InsideSphere(double center[3], double radius2) const
Determine if this bounding box is completely contained by a sphere.