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 
100  void AddPoint(double p[3]);
101  void AddPoint(double px, double py, double pz);
103 
107  void AddBox(const vtkBoundingBox &bbox);
108 
112  void AddBounds(const double bounds[]);
113 
119  int IntersectBox(const vtkBoundingBox &bbox);
120 
124  int Intersects(const vtkBoundingBox &bbox) const;
125 
131  bool IntersectPlane(double origin[3],double normal[3]);
132 
137  int Contains(const vtkBoundingBox &bbox) const;
138 
140 
143  void GetBounds(double bounds[6]) const;
144  void GetBounds(double &xMin, double &xMax,
145  double &yMin, double &yMax,
146  double &zMin, double &zMax) const;
148 
152  double GetBound(int i) const;
153 
155 
158  const double *GetMinPoint() const;
159  void GetMinPoint(double &x, double &y, double &z) const;
161 
163 
166  const double *GetMaxPoint() const;
167  void GetMaxPoint(double &x, double &y, double &z) const;
169 
171 
174  int ContainsPoint(double p[3]) const;
175  int ContainsPoint(double px, double py, double pz) const;
177 
181  void GetCenter(double center[3]) const;
182 
186  void GetLengths(double lengths[3]) const;
187 
191  double GetLength(int i) const;
192 
196  double GetMaxLength() const;
197 
202  double GetDiagonalLength() const;
203 
208  void Inflate(double delta);
209 
211 
215  int IsValid() const;
216  static int IsValid(const double bounds[6]);
218 
222  void Reset();
223 
225 
231  void Scale(double s[3]);
232  void Scale(double sx,
233  double sy,
234  double sz);
236 
237 protected:
238  double MinPnt[3], MaxPnt[3];
239 };
240 
242 {
243  this->MinPnt[0] = this->MinPnt[1] = this->MinPnt[2] = VTK_DOUBLE_MAX;
244  this->MaxPnt[0] = this->MaxPnt[1] = this->MaxPnt[2] = VTK_DOUBLE_MIN;
245 }
246 
247 inline void vtkBoundingBox::GetBounds(double &xMin, double &xMax,
248  double &yMin, double &yMax,
249  double &zMin, double &zMax) const
250 {
251  xMin = this->MinPnt[0];
252  xMax = this->MaxPnt[0];
253  yMin = this->MinPnt[1];
254  yMax = this->MaxPnt[1];
255  zMin = this->MinPnt[2];
256  zMax = this->MaxPnt[2];
257 }
258 
259 inline double vtkBoundingBox::GetBound(int i) const
260 {
261  // If i is odd then when are returning a part of the max bounds
262  // else part of the min bounds is requested. The exact component
263  // needed is i /2 (or i right shifted by 1
264  return ((i & 0x1) ? this->MaxPnt[i>>1] : this->MinPnt[i>>1]);
265 }
266 
267 inline const double *vtkBoundingBox::GetMinPoint() const
268 {
269  return this->MinPnt;
270 }
271 
272 inline const double *vtkBoundingBox::GetMaxPoint() const
273 {
274  return this->MaxPnt;
275 }
276 
277 inline int vtkBoundingBox::IsValid() const
278 {
279  return ((this->MinPnt[0] <= this->MaxPnt[0]) &&
280  (this->MinPnt[1] <= this->MaxPnt[1]) &&
281  (this->MinPnt[2] <= this->MaxPnt[2]));
282 }
283 
284 inline int vtkBoundingBox::IsValid(const double bounds[6])
285 {
286  return (bounds[0] <= bounds[1] &&
287  bounds[2] <= bounds[3] &&
288  bounds[4] <= bounds[5]);
289 }
290 
291 inline double vtkBoundingBox::GetLength(int i) const
292 {
293  return this->MaxPnt[i] - this->MinPnt[i];
294 }
295 
296 inline void vtkBoundingBox::GetLengths(double lengths[3]) const
297 {
298  lengths[0] = this->GetLength(0);
299  lengths[1] = this->GetLength(1);
300  lengths[2] = this->GetLength(2);
301 }
302 
303 inline void vtkBoundingBox::GetCenter(double center[3]) const
304 {
305  center[0] = 0.5 * (this->MaxPnt[0] + this->MinPnt[0]);
306  center[1] = 0.5 * (this->MaxPnt[1] + this->MinPnt[1]);
307  center[2] = 0.5 * (this->MaxPnt[2] + this->MinPnt[2]);
308 }
309 
310 inline void vtkBoundingBox::SetBounds(const double bounds[6])
311 {
312  this->SetBounds(bounds[0], bounds[1], bounds[2],
313  bounds[3], bounds[4], bounds[5]);
314 }
315 
316 inline void vtkBoundingBox::GetBounds(double bounds[6]) const
317 {
318  this->GetBounds(bounds[0], bounds[1], bounds[2],
319  bounds[3], bounds[4], bounds[5]);
320 }
321 
323 {
324  this->Reset();
325 }
326 
327 inline vtkBoundingBox::vtkBoundingBox(const double bounds[6])
328 {
329  this->Reset();
330  this->SetBounds(bounds);
331 }
332 
333 inline vtkBoundingBox::vtkBoundingBox(double xMin, double xMax,
334  double yMin, double yMax,
335  double zMin, double zMax)
336 {
337  this->Reset();
338  this->SetBounds(xMin, xMax, yMin, yMax, zMin, zMax);
339 }
340 
342 {
343  this->MinPnt[0] = bbox.MinPnt[0];
344  this->MinPnt[1] = bbox.MinPnt[1];
345  this->MinPnt[2] = bbox.MinPnt[2];
346 
347  this->MaxPnt[0] = bbox.MaxPnt[0];
348  this->MaxPnt[1] = bbox.MaxPnt[1];
349  this->MaxPnt[2] = bbox.MaxPnt[2];
350 }
351 
353 {
354  this->MinPnt[0] = bbox.MinPnt[0];
355  this->MinPnt[1] = bbox.MinPnt[1];
356  this->MinPnt[2] = bbox.MinPnt[2];
357 
358  this->MaxPnt[0] = bbox.MaxPnt[0];
359  this->MaxPnt[1] = bbox.MaxPnt[1];
360  this->MaxPnt[2] = bbox.MaxPnt[2];
361  return *this;
362 }
363 
364 inline bool vtkBoundingBox::operator==(const vtkBoundingBox &bbox)const
365 {
366  return ((this->MinPnt[0] == bbox.MinPnt[0]) &&
367  (this->MinPnt[1] == bbox.MinPnt[1]) &&
368  (this->MinPnt[2] == bbox.MinPnt[2]) &&
369  (this->MaxPnt[0] == bbox.MaxPnt[0]) &&
370  (this->MaxPnt[1] == bbox.MaxPnt[1]) &&
371  (this->MaxPnt[2] == bbox.MaxPnt[2]));
372 }
373 
374 inline bool vtkBoundingBox::operator!=(const vtkBoundingBox &bbox)const
375 {
376  return !((*this) == bbox);
377 }
378 
379 inline void vtkBoundingBox::SetMinPoint(double p[3])
380 {
381  this->SetMinPoint(p[0], p[1], p[2]);
382 }
383 
384 inline void vtkBoundingBox::SetMaxPoint(double p[3])
385 {
386  this->SetMaxPoint(p[0], p[1], p[2]);
387 }
388 
389 inline void vtkBoundingBox::GetMinPoint(double &x, double &y, double &z) const
390 {
391  x = this->MinPnt[0];
392  y = this->MinPnt[1];
393  z = this->MinPnt[2];
394 }
395 
396 inline void vtkBoundingBox::GetMaxPoint(double &x, double &y, double &z) const
397 {
398  x = this->MaxPnt[0];
399  y = this->MaxPnt[1];
400  z = this->MaxPnt[2];
401 }
402 
403 inline int vtkBoundingBox::ContainsPoint(double px, double py,
404  double pz) const
405 {
406  if ((px < this->MinPnt[0]) || (px > this->MaxPnt[0]))
407  {
408  return 0;
409  }
410  if ((py < this->MinPnt[1]) || (py > this->MaxPnt[1]))
411  {
412  return 0;
413  }
414  if ((pz < this->MinPnt[2]) || (pz > this->MaxPnt[2]))
415  {
416  return 0;
417  }
418  return 1;
419 }
420 
421 inline int vtkBoundingBox::ContainsPoint(double p[3]) const
422 {
423  return this->ContainsPoint(p[0], p[1], p[2]);
424 }
425 
426 #endif
427 // VTK-HeaderTest-Exclude: vtkBoundingBox.h
void GetBounds(double bounds[6]) const
Get the bounds of the box (defined by vtk style)
const double * GetMinPoint() const
Get the minimum point 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 ...
bool operator!=(const vtkBoundingBox &bbox) const
Equality Operator.
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;.
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 lengths of the box.
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
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...
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]
VTKCOMMONCORE_EXPORT bool operator!=(const vtkUnicodeString &lhs, const vtkUnicodeString &rhs)
VTKCOMMONCORE_EXPORT bool operator==(const vtkUnicodeString &lhs, const vtkUnicodeString &rhs)
const double * GetMaxPoint() const
Get the maximum point of the bounding box.
Fast Simple Class for dealing with 3D bounds.
double MinPnt[3]