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 =========================================================================*/
30 #ifndef vtkBoundingBox_h
31 #define vtkBoundingBox_h
32 #include "vtkCommonDataModelModule.h" // For export macro
33 #include "vtkSystemIncludes.h"
34 
35 class VTKCOMMONDATAMODEL_EXPORT vtkBoundingBox
36 {
37 public:
39 
44  vtkBoundingBox(const double bounds[6]);
45  vtkBoundingBox(double xMin, double xMax,
46  double yMin, double yMax,
47  double zMin, double zMax);
49 
53  vtkBoundingBox(const vtkBoundingBox &bbox);
54 
58  vtkBoundingBox &operator=(const vtkBoundingBox &bbox);
59 
61 
64  bool operator==(const vtkBoundingBox &bbox)const;
65  bool operator!=(const vtkBoundingBox &bbox)const;
67 
69 
73  void SetBounds(const double bounds[6]);
74  void SetBounds(double xMin, double xMax,
75  double yMin, double yMax,
76  double zMin, double zMax);
78 
80 
84  void SetMinPoint(double x, double y, double z);
85  void SetMinPoint(double p[3]);
87 
89 
93  void SetMaxPoint(double x, double y, double z);
94  void SetMaxPoint(double p[3]);
96 
98 
102  int IsValid() const;
103  static int IsValid(const double bounds[6]);
105 
107 
112  void AddPoint(double p[3]);
113  void AddPoint(double px, double py, double pz);
115 
119  void AddBox(const vtkBoundingBox &bbox);
120 
125  void AddBounds(const double bounds[]);
126 
132  int IntersectBox(const vtkBoundingBox &bbox);
133 
137  int Intersects(const vtkBoundingBox &bbox) const;
138 
144  bool IntersectPlane(double origin[3],double normal[3]);
145 
150  int Contains(const vtkBoundingBox &bbox) const;
151 
153 
156  void GetBounds(double bounds[6]) const;
157  void GetBounds(double &xMin, double &xMax,
158  double &yMin, double &yMax,
159  double &zMin, double &zMax) const;
161 
165  double GetBound(int i) const;
166 
168 
171  const double *GetMinPoint() const;
172  void GetMinPoint(double &x, double &y, double &z) const;
174 
176 
179  const double *GetMaxPoint() const;
180  void GetMaxPoint(double &x, double &y, double &z) const;
182 
184 
187  int ContainsPoint(double p[3]) const;
188  int ContainsPoint(double px, double py, double pz) const;
190 
194  void GetCenter(double center[3]) const;
195 
199  void GetLengths(double lengths[3]) const;
200 
204  double GetLength(int i) const;
205 
209  double GetMaxLength() const;
210 
215  double GetDiagonalLength() const;
216 
218 
225  void Inflate(double delta);
226  void Inflate();
228 
230 
236  void Scale(double s[3]);
237  void Scale(double sx, double sy, double sz);
239 
250  vtkIdType ComputeDivisions(vtkIdType totalBins, double bounds[6], int divs[3]) const;
251 
255  void Reset();
256 
257 protected:
258  double MinPnt[3], MaxPnt[3];
259 };
260 
262 {
263  this->MinPnt[0] = this->MinPnt[1] = this->MinPnt[2] = VTK_DOUBLE_MAX;
264  this->MaxPnt[0] = this->MaxPnt[1] = this->MaxPnt[2] = VTK_DOUBLE_MIN;
265 }
266 
267 inline void vtkBoundingBox::GetBounds(double &xMin, double &xMax,
268  double &yMin, double &yMax,
269  double &zMin, double &zMax) const
270 {
271  xMin = this->MinPnt[0];
272  xMax = this->MaxPnt[0];
273  yMin = this->MinPnt[1];
274  yMax = this->MaxPnt[1];
275  zMin = this->MinPnt[2];
276  zMax = this->MaxPnt[2];
277 }
278 
279 inline double vtkBoundingBox::GetBound(int i) const
280 {
281  // If i is odd then when are returning a part of the max bounds
282  // else part of the min bounds is requested. The exact component
283  // needed is i /2 (or i right shifted by 1
284  return ((i & 0x1) ? this->MaxPnt[i>>1] : this->MinPnt[i>>1]);
285 }
286 
287 inline const double *vtkBoundingBox::GetMinPoint() const
288 {
289  return this->MinPnt;
290 }
291 
292 inline const double *vtkBoundingBox::GetMaxPoint() const
293 {
294  return this->MaxPnt;
295 }
296 
297 inline int vtkBoundingBox::IsValid() const
298 {
299  return ((this->MinPnt[0] <= this->MaxPnt[0]) &&
300  (this->MinPnt[1] <= this->MaxPnt[1]) &&
301  (this->MinPnt[2] <= this->MaxPnt[2]));
302 }
303 
304 inline int vtkBoundingBox::IsValid(const double bounds[6])
305 {
306  return (bounds[0] <= bounds[1] &&
307  bounds[2] <= bounds[3] &&
308  bounds[4] <= bounds[5]);
309 }
310 
311 inline double vtkBoundingBox::GetLength(int i) const
312 {
313  return this->MaxPnt[i] - this->MinPnt[i];
314 }
315 
316 inline void vtkBoundingBox::GetLengths(double lengths[3]) const
317 {
318  lengths[0] = this->GetLength(0);
319  lengths[1] = this->GetLength(1);
320  lengths[2] = this->GetLength(2);
321 }
322 
323 inline void vtkBoundingBox::GetCenter(double center[3]) const
324 {
325  center[0] = 0.5 * (this->MaxPnt[0] + this->MinPnt[0]);
326  center[1] = 0.5 * (this->MaxPnt[1] + this->MinPnt[1]);
327  center[2] = 0.5 * (this->MaxPnt[2] + this->MinPnt[2]);
328 }
329 
330 inline void vtkBoundingBox::SetBounds(const double bounds[6])
331 {
332  this->SetBounds(bounds[0], bounds[1], bounds[2],
333  bounds[3], bounds[4], bounds[5]);
334 }
335 
336 inline void vtkBoundingBox::GetBounds(double bounds[6]) const
337 {
338  this->GetBounds(bounds[0], bounds[1], bounds[2],
339  bounds[3], bounds[4], bounds[5]);
340 }
341 
343 {
344  this->Reset();
345 }
346 
347 inline vtkBoundingBox::vtkBoundingBox(const double bounds[6])
348 {
349  this->Reset();
350  this->SetBounds(bounds);
351 }
352 
353 inline vtkBoundingBox::vtkBoundingBox(double xMin, double xMax,
354  double yMin, double yMax,
355  double zMin, double zMax)
356 {
357  this->Reset();
358  this->SetBounds(xMin, xMax, yMin, yMax, zMin, zMax);
359 }
360 
362 {
363  this->MinPnt[0] = bbox.MinPnt[0];
364  this->MinPnt[1] = bbox.MinPnt[1];
365  this->MinPnt[2] = bbox.MinPnt[2];
366 
367  this->MaxPnt[0] = bbox.MaxPnt[0];
368  this->MaxPnt[1] = bbox.MaxPnt[1];
369  this->MaxPnt[2] = bbox.MaxPnt[2];
370 }
371 
373 {
374  this->MinPnt[0] = bbox.MinPnt[0];
375  this->MinPnt[1] = bbox.MinPnt[1];
376  this->MinPnt[2] = bbox.MinPnt[2];
377 
378  this->MaxPnt[0] = bbox.MaxPnt[0];
379  this->MaxPnt[1] = bbox.MaxPnt[1];
380  this->MaxPnt[2] = bbox.MaxPnt[2];
381  return *this;
382 }
383 
384 inline bool vtkBoundingBox::operator==(const vtkBoundingBox &bbox)const
385 {
386  return ((this->MinPnt[0] == bbox.MinPnt[0]) &&
387  (this->MinPnt[1] == bbox.MinPnt[1]) &&
388  (this->MinPnt[2] == bbox.MinPnt[2]) &&
389  (this->MaxPnt[0] == bbox.MaxPnt[0]) &&
390  (this->MaxPnt[1] == bbox.MaxPnt[1]) &&
391  (this->MaxPnt[2] == bbox.MaxPnt[2]));
392 }
393 
394 inline bool vtkBoundingBox::operator!=(const vtkBoundingBox &bbox)const
395 {
396  return !((*this) == bbox);
397 }
398 
399 inline void vtkBoundingBox::SetMinPoint(double p[3])
400 {
401  this->SetMinPoint(p[0], p[1], p[2]);
402 }
403 
404 inline void vtkBoundingBox::SetMaxPoint(double p[3])
405 {
406  this->SetMaxPoint(p[0], p[1], p[2]);
407 }
408 
409 inline void vtkBoundingBox::GetMinPoint(double &x, double &y, double &z) const
410 {
411  x = this->MinPnt[0];
412  y = this->MinPnt[1];
413  z = this->MinPnt[2];
414 }
415 
416 inline void vtkBoundingBox::GetMaxPoint(double &x, double &y, double &z) const
417 {
418  x = this->MaxPnt[0];
419  y = this->MaxPnt[1];
420  z = this->MaxPnt[2];
421 }
422 
423 inline int vtkBoundingBox::ContainsPoint(double px, double py,
424  double pz) const
425 {
426  if ((px < this->MinPnt[0]) || (px > this->MaxPnt[0]))
427  {
428  return 0;
429  }
430  if ((py < this->MinPnt[1]) || (py > this->MaxPnt[1]))
431  {
432  return 0;
433  }
434  if ((pz < this->MinPnt[2]) || (pz > this->MaxPnt[2]))
435  {
436  return 0;
437  }
438  return 1;
439 }
440 
441 inline int vtkBoundingBox::ContainsPoint(double p[3]) const
442 {
443  return this->ContainsPoint(p[0], p[1], p[2]);
444 }
445 
446 #endif
447 // 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.
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]