VTK
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 VTKCOMMONDATAMODEL_EXPORT vtkBoundingBox
33 {
34 public:
36 
41  vtkBoundingBox(const double bounds[6]);
42  vtkBoundingBox(double xMin, double xMax,
43  double yMin, double yMax,
44  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,
72  double yMin, double yMax,
73  double zMin, double zMax);
75 
77 
81  void SetMinPoint(double x, double y, double z);
82  void SetMinPoint(double p[3]);
84 
86 
90  void SetMaxPoint(double x, double y, double z);
91  void SetMaxPoint(double p[3]);
93 
95 
99  int IsValid() const;
100  static int IsValid(const double bounds[6]);
102 
104 
109  void AddPoint(double p[3]);
110  void AddPoint(double px, double py, double pz);
112 
116  void AddBox(const vtkBoundingBox &bbox);
117 
122  void AddBounds(const double bounds[]);
123 
129  int IntersectBox(const vtkBoundingBox &bbox);
130 
134  int Intersects(const vtkBoundingBox &bbox) const;
135 
141  bool IntersectPlane(double origin[3],double normal[3]);
142 
147  int Contains(const vtkBoundingBox &bbox) const;
148 
150 
153  void GetBounds(double bounds[6]) const;
154  void GetBounds(double &xMin, double &xMax,
155  double &yMin, double &yMax,
156  double &zMin, double &zMax) const;
158 
162  double GetBound(int i) const;
163 
165 
168  const double *GetMinPoint() const VTK_SIZEHINT(3);
169  void GetMinPoint(double &x, double &y, double &z) const;
171 
173 
176  const double *GetMaxPoint() const VTK_SIZEHINT(3);
177  void GetMaxPoint(double &x, double &y, double &z) const;
179 
181 
184  int ContainsPoint(double p[3]) const;
185  int ContainsPoint(double px, double py, double pz) const;
187 
191  void GetCenter(double center[3]) const;
192 
196  void GetLengths(double lengths[3]) const;
197 
201  double GetLength(int i) const;
202 
206  double GetMaxLength() const;
207 
212  double GetDiagonalLength() const;
213 
215 
222  void Inflate(double delta);
223  void Inflate();
225 
227 
233  void Scale(double s[3]);
234  void Scale(double sx, double sy, double sz);
236 
247  vtkIdType ComputeDivisions(vtkIdType totalBins, double bounds[6], int divs[3]) const;
248 
252  void Reset();
253 
254 protected:
255  double MinPnt[3], MaxPnt[3];
256 };
257 
259 {
260  this->MinPnt[0] = this->MinPnt[1] = this->MinPnt[2] = VTK_DOUBLE_MAX;
261  this->MaxPnt[0] = this->MaxPnt[1] = this->MaxPnt[2] = VTK_DOUBLE_MIN;
262 }
263 
264 inline void vtkBoundingBox::GetBounds(double &xMin, double &xMax,
265  double &yMin, double &yMax,
266  double &zMin, double &zMax) const
267 {
268  xMin = this->MinPnt[0];
269  xMax = this->MaxPnt[0];
270  yMin = this->MinPnt[1];
271  yMax = this->MaxPnt[1];
272  zMin = this->MinPnt[2];
273  zMax = this->MaxPnt[2];
274 }
275 
276 inline double vtkBoundingBox::GetBound(int i) const
277 {
278  // If i is odd then when are returning a part of the max bounds
279  // else part of the min bounds is requested. The exact component
280  // needed is i /2 (or i right shifted by 1
281  return ((i & 0x1) ? this->MaxPnt[i>>1] : this->MinPnt[i>>1]);
282 }
283 
284 inline const double *vtkBoundingBox::GetMinPoint() const
285 {
286  return this->MinPnt;
287 }
288 
289 inline const double *vtkBoundingBox::GetMaxPoint() const
290 {
291  return this->MaxPnt;
292 }
293 
294 inline int vtkBoundingBox::IsValid() const
295 {
296  return ((this->MinPnt[0] <= this->MaxPnt[0]) &&
297  (this->MinPnt[1] <= this->MaxPnt[1]) &&
298  (this->MinPnt[2] <= this->MaxPnt[2]));
299 }
300 
301 inline int vtkBoundingBox::IsValid(const double bounds[6])
302 {
303  return (bounds[0] <= bounds[1] &&
304  bounds[2] <= bounds[3] &&
305  bounds[4] <= bounds[5]);
306 }
307 
308 inline double vtkBoundingBox::GetLength(int i) const
309 {
310  return this->MaxPnt[i] - this->MinPnt[i];
311 }
312 
313 inline void vtkBoundingBox::GetLengths(double lengths[3]) const
314 {
315  lengths[0] = this->GetLength(0);
316  lengths[1] = this->GetLength(1);
317  lengths[2] = this->GetLength(2);
318 }
319 
320 inline void vtkBoundingBox::GetCenter(double center[3]) const
321 {
322  center[0] = 0.5 * (this->MaxPnt[0] + this->MinPnt[0]);
323  center[1] = 0.5 * (this->MaxPnt[1] + this->MinPnt[1]);
324  center[2] = 0.5 * (this->MaxPnt[2] + this->MinPnt[2]);
325 }
326 
327 inline void vtkBoundingBox::SetBounds(const double bounds[6])
328 {
329  this->SetBounds(bounds[0], bounds[1], bounds[2],
330  bounds[3], bounds[4], bounds[5]);
331 }
332 
333 inline void vtkBoundingBox::GetBounds(double bounds[6]) const
334 {
335  this->GetBounds(bounds[0], bounds[1], bounds[2],
336  bounds[3], bounds[4], bounds[5]);
337 }
338 
340 {
341  this->Reset();
342 }
343 
344 inline vtkBoundingBox::vtkBoundingBox(const double bounds[6])
345 {
346  this->Reset();
347  this->SetBounds(bounds);
348 }
349 
350 inline vtkBoundingBox::vtkBoundingBox(double xMin, double xMax,
351  double yMin, double yMax,
352  double zMin, double zMax)
353 {
354  this->Reset();
355  this->SetBounds(xMin, xMax, yMin, yMax, zMin, zMax);
356 }
357 
359 {
360  this->MinPnt[0] = bbox.MinPnt[0];
361  this->MinPnt[1] = bbox.MinPnt[1];
362  this->MinPnt[2] = bbox.MinPnt[2];
363 
364  this->MaxPnt[0] = bbox.MaxPnt[0];
365  this->MaxPnt[1] = bbox.MaxPnt[1];
366  this->MaxPnt[2] = bbox.MaxPnt[2];
367 }
368 
370 {
371  this->MinPnt[0] = bbox.MinPnt[0];
372  this->MinPnt[1] = bbox.MinPnt[1];
373  this->MinPnt[2] = bbox.MinPnt[2];
374 
375  this->MaxPnt[0] = bbox.MaxPnt[0];
376  this->MaxPnt[1] = bbox.MaxPnt[1];
377  this->MaxPnt[2] = bbox.MaxPnt[2];
378  return *this;
379 }
380 
381 inline bool vtkBoundingBox::operator==(const vtkBoundingBox &bbox)const
382 {
383  return ((this->MinPnt[0] == bbox.MinPnt[0]) &&
384  (this->MinPnt[1] == bbox.MinPnt[1]) &&
385  (this->MinPnt[2] == bbox.MinPnt[2]) &&
386  (this->MaxPnt[0] == bbox.MaxPnt[0]) &&
387  (this->MaxPnt[1] == bbox.MaxPnt[1]) &&
388  (this->MaxPnt[2] == bbox.MaxPnt[2]));
389 }
390 
391 inline bool vtkBoundingBox::operator!=(const vtkBoundingBox &bbox)const
392 {
393  return !((*this) == bbox);
394 }
395 
396 inline void vtkBoundingBox::SetMinPoint(double p[3])
397 {
398  this->SetMinPoint(p[0], p[1], p[2]);
399 }
400 
401 inline void vtkBoundingBox::SetMaxPoint(double p[3])
402 {
403  this->SetMaxPoint(p[0], p[1], p[2]);
404 }
405 
406 inline void vtkBoundingBox::GetMinPoint(double &x, double &y, double &z) const
407 {
408  x = this->MinPnt[0];
409  y = this->MinPnt[1];
410  z = this->MinPnt[2];
411 }
412 
413 inline void vtkBoundingBox::GetMaxPoint(double &x, double &y, double &z) const
414 {
415  x = this->MaxPnt[0];
416  y = this->MaxPnt[1];
417  z = this->MaxPnt[2];
418 }
419 
420 inline int vtkBoundingBox::ContainsPoint(double px, double py,
421  double pz) const
422 {
423  if ((px < this->MinPnt[0]) || (px > this->MaxPnt[0]))
424  {
425  return 0;
426  }
427  if ((py < this->MinPnt[1]) || (py > this->MaxPnt[1]))
428  {
429  return 0;
430  }
431  if ((pz < this->MinPnt[2]) || (pz > this->MaxPnt[2]))
432  {
433  return 0;
434  }
435  return 1;
436 }
437 
438 inline int vtkBoundingBox::ContainsPoint(double p[3]) const
439 {
440  return this->ContainsPoint(p[0], p[1], p[2]);
441 }
442 
443 #endif
444 // VTK-HeaderTest-Exclude: vtkBoundingBox.h
double GetBound(int i) const
Return the ith bounds of the box (defined by vtk style).
void GetCenter(double center[3]) const
Get the center of the bounding box.
#define VTK_DOUBLE_MAX
Definition: vtkType.h:167
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 ...
const double * GetMaxPoint() const
Get the maximum point of the bounding box.
void Reset()
Returns the box to its initialized state.
int ContainsPoint(double p[3]) const
Returns 1 if the point is contained in the box else 0.
int vtkIdType
Definition: vtkType.h:345
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...
vtkBoundingBox & operator=(const vtkBoundingBox &bbox)
Assignment Operator.
#define VTK_SIZEHINT(...)
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...
#define VTK_DOUBLE_MIN
Definition: vtkType.h:166
const double * GetMinPoint() const
Get the minimum point of the bounding box.
bool operator!=(const vtkBoundingBox &bbox) const
Equality Operator.
double GetLength(int i) const
Return the length in the ith direction.
void SetBounds(const double bounds[6])
Set the bounds explicitly of the box (vtk Style) Returns 1 if the box was changed else 0...
void GetBounds(double bounds[6]) const
Get the bounds of the box (defined by vtk style).
vtkBoundingBox()
Construct a bounding box with the min point set to VTK_DOUBLE_MAX and the max point set to VTK_DOUBLE...
double MaxPnt[3]
bool operator==(const vtkBoundingBox &bbox) const
Equality Operator.
VTKCOMMONCORE_EXPORT bool operator!=(const vtkUnicodeString &lhs, const vtkUnicodeString &rhs)
VTKCOMMONCORE_EXPORT bool operator==(const vtkUnicodeString &lhs, const vtkUnicodeString &rhs)
void GetLengths(double lengths[3]) const
Get the lengths of the box.
Fast Simple Class for dealing with 3D bounds.
double MinPnt[3]