VTK  9.0.3
vtkBoundingBox.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3 Program: Visualization Toolkit
4 Module: vtkBoundingBox.h
5 
6 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7 All rights reserved.
8 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10 This software is distributed WITHOUT ANY WARRANTY; without even
11 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12 PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
27 #ifndef vtkBoundingBox_h
28 #define vtkBoundingBox_h
29 #include "vtkCommonDataModelModule.h" // For export macro
30 #include "vtkSystemIncludes.h"
31 
32 class vtkPoints;
33 
34 class VTKCOMMONDATAMODEL_EXPORT vtkBoundingBox
35 {
36 public:
38 
43  vtkBoundingBox(const double bounds[6]);
44  vtkBoundingBox(double xMin, double xMax, double yMin, double yMax, double zMin, double zMax);
46 
50  vtkBoundingBox(const vtkBoundingBox& bbox);
51 
55  vtkBoundingBox& operator=(const vtkBoundingBox& bbox);
56 
58 
61  bool operator==(const vtkBoundingBox& bbox) const;
62  bool operator!=(const vtkBoundingBox& bbox) const;
64 
66 
70  void SetBounds(const double bounds[6]);
71  void SetBounds(double xMin, double xMax, double yMin, double yMax, double zMin, double zMax);
73 
75 
80  static void ComputeBounds(vtkPoints* pts, double bounds[6]);
81  static void ComputeBounds(vtkPoints* pts, const unsigned char* ptUses, double bounds[6]);
83 
85 
89  void SetMinPoint(double x, double y, double z);
90  void SetMinPoint(double p[3]);
92 
94 
98  void SetMaxPoint(double x, double y, double z);
99  void SetMaxPoint(double p[3]);
101 
103 
107  int IsValid() const;
108  static int IsValid(const double bounds[6]);
110 
112 
116  void AddPoint(double p[3]);
117  void AddPoint(double px, double py, double pz);
119 
124  void AddBox(const vtkBoundingBox& bbox);
125 
130  void AddBounds(const double bounds[]);
131 
137  int IntersectBox(const vtkBoundingBox& bbox);
138 
142  int Intersects(const vtkBoundingBox& bbox) const;
143 
149  bool IntersectPlane(double origin[3], double normal[3]);
150 
155  int Contains(const vtkBoundingBox& bbox) const;
156 
158 
161  void GetBounds(double bounds[6]) const;
162  void GetBounds(
163  double& xMin, double& xMax, double& yMin, double& yMax, double& zMin, double& zMax) const;
165 
169  double GetBound(int i) const;
170 
172 
175  const double* GetMinPoint() const VTK_SIZEHINT(3);
176  void GetMinPoint(double& x, double& y, double& z) const;
177  void GetMinPoint(double x[3]) const;
179 
181 
184  const double* GetMaxPoint() const VTK_SIZEHINT(3);
185  void GetMaxPoint(double& x, double& y, double& z) const;
186  void GetMaxPoint(double x[3]) const;
188 
193  void GetCorner(int corner, double p[3]) const;
194 
196 
199  vtkTypeBool ContainsPoint(double p[3]) const;
200  vtkTypeBool ContainsPoint(double px, double py, double pz) const;
202 
206  void GetCenter(double center[3]) const;
207 
211  void GetLengths(double lengths[3]) const;
212 
216  double GetLength(int i) const;
217 
221  double GetMaxLength() const;
222 
227  double GetDiagonalLength() const;
228 
230 
238  void Inflate(double delta);
239  void Inflate(double deltaX, double deltaY, double deltaZ);
240  void Inflate();
242 
244 
250  void Scale(double s[3]);
251  void Scale(double sx, double sy, double sz);
253 
255 
260  void ScaleAboutCenter(double s);
261  void ScaleAboutCenter(double s[3]);
262  void ScaleAboutCenter(double sx, double sy, double sz);
264 
275  vtkIdType ComputeDivisions(vtkIdType totalBins, double bounds[6], int divs[3]) const;
276 
280  void Reset();
281 
282 protected:
283  double MinPnt[3], MaxPnt[3];
284 };
285 
286 inline void vtkBoundingBox::Reset()
287 {
288  this->MinPnt[0] = this->MinPnt[1] = this->MinPnt[2] = VTK_DOUBLE_MAX;
289  this->MaxPnt[0] = this->MaxPnt[1] = this->MaxPnt[2] = VTK_DOUBLE_MIN;
290 }
291 
293  double& xMin, double& xMax, double& yMin, double& yMax, double& zMin, double& zMax) const
294 {
295  xMin = this->MinPnt[0];
296  xMax = this->MaxPnt[0];
297  yMin = this->MinPnt[1];
298  yMax = this->MaxPnt[1];
299  zMin = this->MinPnt[2];
300  zMax = this->MaxPnt[2];
301 }
302 
303 inline double vtkBoundingBox::GetBound(int i) const
304 {
305  // If i is odd then when are returning a part of the max bounds
306  // else part of the min bounds is requested. The exact component
307  // needed is i /2 (or i right shifted by 1
308  return ((i & 0x1) ? this->MaxPnt[i >> 1] : this->MinPnt[i >> 1]);
309 }
310 
311 inline const double* vtkBoundingBox::GetMinPoint() const
312 {
313  return this->MinPnt;
314 }
315 
316 inline void vtkBoundingBox::GetMinPoint(double x[3]) const
317 {
318  x[0] = this->MinPnt[0];
319  x[1] = this->MinPnt[1];
320  x[2] = this->MinPnt[2];
321 }
322 
323 inline const double* vtkBoundingBox::GetMaxPoint() const
324 {
325  return this->MaxPnt;
326 }
327 
328 inline void vtkBoundingBox::GetMaxPoint(double x[3]) const
329 {
330  x[0] = this->MaxPnt[0];
331  x[1] = this->MaxPnt[1];
332  x[2] = this->MaxPnt[2];
333 }
334 
335 inline int vtkBoundingBox::IsValid() const
336 {
337  return ((this->MinPnt[0] <= this->MaxPnt[0]) && (this->MinPnt[1] <= this->MaxPnt[1]) &&
338  (this->MinPnt[2] <= this->MaxPnt[2]));
339 }
340 
341 inline int vtkBoundingBox::IsValid(const double bounds[6])
342 {
343  return (bounds[0] <= bounds[1] && bounds[2] <= bounds[3] && bounds[4] <= bounds[5]);
344 }
345 
346 inline double vtkBoundingBox::GetLength(int i) const
347 {
348  return this->MaxPnt[i] - this->MinPnt[i];
349 }
350 
351 inline void vtkBoundingBox::GetLengths(double lengths[3]) const
352 {
353  lengths[0] = this->GetLength(0);
354  lengths[1] = this->GetLength(1);
355  lengths[2] = this->GetLength(2);
356 }
357 
358 inline void vtkBoundingBox::GetCenter(double center[3]) const
359 {
360  center[0] = 0.5 * (this->MaxPnt[0] + this->MinPnt[0]);
361  center[1] = 0.5 * (this->MaxPnt[1] + this->MinPnt[1]);
362  center[2] = 0.5 * (this->MaxPnt[2] + this->MinPnt[2]);
363 }
364 
365 inline void vtkBoundingBox::SetBounds(const double bounds[6])
366 {
367  this->SetBounds(bounds[0], bounds[1], bounds[2], bounds[3], bounds[4], bounds[5]);
368 }
369 
370 inline void vtkBoundingBox::GetBounds(double bounds[6]) const
371 {
372  this->GetBounds(bounds[0], bounds[1], bounds[2], bounds[3], bounds[4], bounds[5]);
373 }
374 
376 {
377  this->Reset();
378 }
379 
380 inline vtkBoundingBox::vtkBoundingBox(const double bounds[6])
381 {
382  this->Reset();
383  this->SetBounds(bounds);
384 }
385 
387  double xMin, double xMax, double yMin, double yMax, double zMin, double zMax)
388 {
389  this->Reset();
390  this->SetBounds(xMin, xMax, yMin, yMax, zMin, zMax);
391 }
392 
394 {
395  this->MinPnt[0] = bbox.MinPnt[0];
396  this->MinPnt[1] = bbox.MinPnt[1];
397  this->MinPnt[2] = bbox.MinPnt[2];
398 
399  this->MaxPnt[0] = bbox.MaxPnt[0];
400  this->MaxPnt[1] = bbox.MaxPnt[1];
401  this->MaxPnt[2] = bbox.MaxPnt[2];
402 }
403 
405 {
406  this->MinPnt[0] = bbox.MinPnt[0];
407  this->MinPnt[1] = bbox.MinPnt[1];
408  this->MinPnt[2] = bbox.MinPnt[2];
409 
410  this->MaxPnt[0] = bbox.MaxPnt[0];
411  this->MaxPnt[1] = bbox.MaxPnt[1];
412  this->MaxPnt[2] = bbox.MaxPnt[2];
413  return *this;
414 }
415 
416 inline bool vtkBoundingBox::operator==(const vtkBoundingBox& bbox) const
417 {
418  return ((this->MinPnt[0] == bbox.MinPnt[0]) && (this->MinPnt[1] == bbox.MinPnt[1]) &&
419  (this->MinPnt[2] == bbox.MinPnt[2]) && (this->MaxPnt[0] == bbox.MaxPnt[0]) &&
420  (this->MaxPnt[1] == bbox.MaxPnt[1]) && (this->MaxPnt[2] == bbox.MaxPnt[2]));
421 }
422 
423 inline bool vtkBoundingBox::operator!=(const vtkBoundingBox& bbox) const
424 {
425  return !((*this) == bbox);
426 }
427 
428 inline void vtkBoundingBox::SetMinPoint(double p[3])
429 {
430  this->SetMinPoint(p[0], p[1], p[2]);
431 }
432 
433 inline void vtkBoundingBox::SetMaxPoint(double p[3])
434 {
435  this->SetMaxPoint(p[0], p[1], p[2]);
436 }
437 
438 inline void vtkBoundingBox::GetMinPoint(double& x, double& y, double& z) const
439 {
440  x = this->MinPnt[0];
441  y = this->MinPnt[1];
442  z = this->MinPnt[2];
443 }
444 
445 inline void vtkBoundingBox::GetMaxPoint(double& x, double& y, double& z) const
446 {
447  x = this->MaxPnt[0];
448  y = this->MaxPnt[1];
449  z = this->MaxPnt[2];
450 }
451 
452 inline vtkTypeBool vtkBoundingBox::ContainsPoint(double px, double py, double pz) const
453 {
454  if ((px < this->MinPnt[0]) || (px > this->MaxPnt[0]))
455  {
456  return 0;
457  }
458  if ((py < this->MinPnt[1]) || (py > this->MaxPnt[1]))
459  {
460  return 0;
461  }
462  if ((pz < this->MinPnt[2]) || (pz > this->MaxPnt[2]))
463  {
464  return 0;
465  }
466  return 1;
467 }
468 
470 {
471  return this->ContainsPoint(p[0], p[1], p[2]);
472 }
473 
474 inline void vtkBoundingBox::GetCorner(int corner, double p[3]) const
475 {
476  if ((corner < 0) || (corner > 7))
477  {
478  p[0] = VTK_DOUBLE_MAX;
479  p[1] = VTK_DOUBLE_MAX;
480  p[2] = VTK_DOUBLE_MAX;
481  return; // out of bounds
482  }
483 
484  int ix = (corner & 1) ? 1 : 0; // 0,1,0,1,0,1,0,1
485  int iy = ((corner >> 1) & 1) ? 1 : 0; // 0,0,1,1,0,0,1,1
486  int iz = (corner >> 2) ? 1 : 0; // 0,0,0,0,1,1,1,1
487 
488  const double* pts[2] = { this->MinPnt, this->MaxPnt };
489  p[0] = pts[ix][0];
490  p[1] = pts[iy][1];
491  p[2] = pts[iz][2];
492 }
493 
494 #endif
495 // VTK-HeaderTest-Exclude: vtkBoundingBox.h
Fast, simple class for dealing with 3D bounds.
vtkTypeBool ContainsPoint(double p[3]) const
Returns 1 if the point is contained in the box else 0.
int IntersectBox(const vtkBoundingBox &bbox)
Intersect this box with bbox.
const double * GetMinPoint() const
Get the minimum point of the bounding box.
void SetBounds(double xMin, double xMax, double yMin, double yMax, double zMin, double zMax)
void AddBox(const vtkBoundingBox &bbox)
Change the bounding box to be the union of itself and the specified bbox.
void AddBounds(const double bounds[])
Adjust the bounding box so it contains the specified bounds (defined by the VTK representation (xmin,...
int Contains(const vtkBoundingBox &bbox) const
Returns 1 if the min and max points of bbox are contained within the bounds of the specified 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...
int Intersects(const vtkBoundingBox &bbox) const
Returns 1 if the boxes intersect else returns 0.
bool operator!=(const vtkBoundingBox &bbox) const
void AddPoint(double px, double py, double pz)
void GetCorner(int corner, double p[3]) const
Get the ith corner of the bounding box.
static void ComputeBounds(vtkPoints *pts, double bounds[6])
Compute the bounding box from an array of vtkPoints.
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 ...
bool IntersectPlane(double origin[3], double normal[3])
Intersect this box with the half space defined by plane.
void GetCenter(double center[3]) const
Get the center of the bounding box.
void AddPoint(double p[3])
Change bounding box so it includes the point p.
double GetLength(int i) const
Return the length of the bounding box in the ith direction.
bool operator==(const vtkBoundingBox &bbox) const
Equality operator.
vtkBoundingBox()
Construct a bounding box with the min point set to VTK_DOUBLE_MAX and the max point set to VTK_DOUBLE...
double MinPnt[3]
double MaxPnt[3]
void GetLengths(double lengths[3]) const
Get the length of each sode of the box.
static void ComputeBounds(vtkPoints *pts, const unsigned char *ptUses, double bounds[6])
void SetBounds(const double bounds[6])
Set the bounds explicitly of the box (using the VTK convention for representing a bounding box).
const double * GetMaxPoint() const
Get the maximum point of the bounding box.
double GetBound(int i) const
Return the ith bounds of the box (defined by VTK style).
void GetBounds(double bounds[6]) const
Get the bounds of the box (defined by VTK style).
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...
vtkBoundingBox & operator=(const vtkBoundingBox &bbox)
Assignment Operator.
represent and manipulate 3D points
Definition: vtkPoints.h:34
@ center
Definition: vtkX3D.h:236
int vtkTypeBool
Definition: vtkABI.h:69
int vtkIdType
Definition: vtkType.h:338
#define VTK_DOUBLE_MIN
Definition: vtkType.h:164
#define VTK_DOUBLE_MAX
Definition: vtkType.h:165
VTKCOMMONCORE_EXPORT bool operator!=(const vtkUnicodeString &lhs, const vtkUnicodeString &rhs)
VTKCOMMONCORE_EXPORT bool operator==(const vtkUnicodeString &lhs, const vtkUnicodeString &rhs)
#define VTK_SIZEHINT(...)