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 =========================================================================*/
29 #ifndef vtkBoundingBox_h
30 #define vtkBoundingBox_h
31 #include "vtkCommonDataModelModule.h" // For export macro
32 #include "vtkSystemIncludes.h"
33 
35 {
36 public:
38 
41  vtkBoundingBox(const double bounds[6]);
42  vtkBoundingBox(double xMin, double xMax,
43  double yMin, double yMax,
44  double zMin, double zMax);
46 
48  vtkBoundingBox(const vtkBoundingBox &bbox);
49 
51  vtkBoundingBox &operator=(const vtkBoundingBox &bbox);
52 
54 
55  int operator==(const vtkBoundingBox &bbox)const;
56  int operator!=(const vtkBoundingBox &bbox)const;
58 
60 
62  void SetBounds(const double bounds[6]);
63  void SetBounds(double xMin, double xMax,
64  double yMin, double yMax,
65  double zMin, double zMax);
67 
69 
71  void SetMinPoint(double x, double y, double z);
72  void SetMinPoint(double p[3]);
74 
76 
78  void SetMaxPoint(double x, double y, double z);
79  void SetMaxPoint(double p[3]);
81 
83 
85  void AddPoint(double p[3]);
86  void AddPoint(double px, double py, double pz);
88 
90  void AddBox(const vtkBoundingBox &bbox);
91 
94  void AddBounds(const double bounds[]);
95 
96  // Desciption:
97  // Intersect this box with bbox. The method returns 1 if
98  // both boxes are valid and they do have overlap else it will return 0.
99  // If 0 is returned the box has not been modified
100  int IntersectBox(const vtkBoundingBox &bbox);
101 
103  int Intersects(const vtkBoundingBox &bbox) const;
104 
105 
106  // Desciption:
107  // Intersect this box with the half space defined by plane.
108  //Returns true if there is intersection---which implies that the box has been modified
109  // Returns false otherwise
110  bool IntersectPlane(double origin[3],double normal[3]);
111 
112 
115  int Contains(const vtkBoundingBox &bbox) const;
116 
118 
119  void GetBounds(double bounds[6]) const;
120  void GetBounds(double &xMin, double &xMax,
121  double &yMin, double &yMax,
122  double &zMin, double &zMax) const;
124 
126  double GetBound(int i) const;
127 
129 
130  const double *GetMinPoint() const;
131  void GetMinPoint(double &x, double &y, double &z) const;
133 
135 
136  const double *GetMaxPoint() const;
137  void GetMaxPoint(double &x, double &y, double &z) const;
139 
141 
142  int ContainsPoint(double p[3]) const;
143  int ContainsPoint(double px, double py, double pz) const;
145 
147  void GetCenter(double center[3]) const;
148 
150  void GetLengths(double lengths[3]) const;
151 
153  double GetLength(int i) const;
154 
156  double GetMaxLength() const;
157 
159  double GetDiagonalLength() const;
160 
163  void Inflate(double delta);
164 
166 
168  int IsValid() const;
169  static int IsValid(const double bounds[6]);
171 
173  void Reset();
174 
176 
180  void Scale(double s[3]);
181  void Scale(double sx,
182  double sy,
183  double sz);
185 
186 protected:
187  double MinPnt[3], MaxPnt[3];
188 };
189 
191 {
192  this->MinPnt[0] = this->MinPnt[1] = this->MinPnt[2] = VTK_DOUBLE_MAX;
193  this->MaxPnt[0] = this->MaxPnt[1] = this->MaxPnt[2] = VTK_DOUBLE_MIN;
194 }
195 
196 inline void vtkBoundingBox::GetBounds(double &xMin, double &xMax,
197  double &yMin, double &yMax,
198  double &zMin, double &zMax) const
199 {
200  xMin = this->MinPnt[0];
201  xMax = this->MaxPnt[0];
202  yMin = this->MinPnt[1];
203  yMax = this->MaxPnt[1];
204  zMin = this->MinPnt[2];
205  zMax = this->MaxPnt[2];
206 }
207 
208 inline double vtkBoundingBox::GetBound(int i) const
209 {
210  // If i is odd then when are returning a part of the max bounds
211  // else part of the min bounds is requested. The exact component
212  // needed is i /2 (or i right shifted by 1
213  return ((i & 0x1) ? this->MaxPnt[i>>1] : this->MinPnt[i>>1]);
214 }
215 
216 inline const double *vtkBoundingBox::GetMinPoint() const
217 {
218  return this->MinPnt;
219 }
220 
221 inline const double *vtkBoundingBox::GetMaxPoint() const
222 {
223  return this->MaxPnt;
224 }
225 
226 inline int vtkBoundingBox::IsValid() const
227 {
228  return ((this->MinPnt[0] <= this->MaxPnt[0]) &&
229  (this->MinPnt[1] <= this->MaxPnt[1]) &&
230  (this->MinPnt[2] <= this->MaxPnt[2]));
231 }
232 
233 inline int vtkBoundingBox::IsValid(const double bounds[6])
234 {
235  return (bounds[0] <= bounds[1] &&
236  bounds[2] <= bounds[3] &&
237  bounds[4] <= bounds[5]);
238 }
239 
240 inline double vtkBoundingBox::GetLength(int i) const
241 {
242  return this->MaxPnt[i] - this->MinPnt[i];
243 }
244 
245 inline void vtkBoundingBox::GetLengths(double lengths[3]) const
246 {
247  lengths[0] = this->GetLength(0);
248  lengths[1] = this->GetLength(1);
249  lengths[2] = this->GetLength(2);
250 }
251 
252 inline void vtkBoundingBox::GetCenter(double center[3]) const
253 {
254  center[0] = 0.5 * (this->MaxPnt[0] + this->MinPnt[0]);
255  center[1] = 0.5 * (this->MaxPnt[1] + this->MinPnt[1]);
256  center[2] = 0.5 * (this->MaxPnt[2] + this->MinPnt[2]);
257 }
258 
259 inline void vtkBoundingBox::SetBounds(const double bounds[6])
260 {
261  this->SetBounds(bounds[0], bounds[1], bounds[2],
262  bounds[3], bounds[4], bounds[5]);
263 }
264 
265 inline void vtkBoundingBox::GetBounds(double bounds[6]) const
266 {
267  this->GetBounds(bounds[0], bounds[1], bounds[2],
268  bounds[3], bounds[4], bounds[5]);
269 }
270 
272 {
273  this->Reset();
274 }
275 
276 inline vtkBoundingBox::vtkBoundingBox(const double bounds[6])
277 {
278  this->Reset();
279  this->SetBounds(bounds);
280 }
281 
282 inline vtkBoundingBox::vtkBoundingBox(double xMin, double xMax,
283  double yMin, double yMax,
284  double zMin, double zMax)
285 {
286  this->Reset();
287  this->SetBounds(xMin, xMax, yMin, yMax, zMin, zMax);
288 }
289 
291 {
292  this->MinPnt[0] = bbox.MinPnt[0];
293  this->MinPnt[1] = bbox.MinPnt[1];
294  this->MinPnt[2] = bbox.MinPnt[2];
295 
296  this->MaxPnt[0] = bbox.MaxPnt[0];
297  this->MaxPnt[1] = bbox.MaxPnt[1];
298  this->MaxPnt[2] = bbox.MaxPnt[2];
299 }
300 
302 {
303  this->MinPnt[0] = bbox.MinPnt[0];
304  this->MinPnt[1] = bbox.MinPnt[1];
305  this->MinPnt[2] = bbox.MinPnt[2];
306 
307  this->MaxPnt[0] = bbox.MaxPnt[0];
308  this->MaxPnt[1] = bbox.MaxPnt[1];
309  this->MaxPnt[2] = bbox.MaxPnt[2];
310  return *this;
311 }
312 
313 inline int vtkBoundingBox::operator==(const vtkBoundingBox &bbox)const
314 {
315  return ((this->MinPnt[0] == bbox.MinPnt[0]) &&
316  (this->MinPnt[1] == bbox.MinPnt[1]) &&
317  (this->MinPnt[2] == bbox.MinPnt[2]) &&
318  (this->MaxPnt[0] == bbox.MaxPnt[0]) &&
319  (this->MaxPnt[1] == bbox.MaxPnt[1]) &&
320  (this->MaxPnt[2] == bbox.MaxPnt[2]));
321 }
322 
323 inline int vtkBoundingBox::operator!=(const vtkBoundingBox &bbox)const
324 {
325  return !((*this) == bbox);
326 }
327 
328 inline void vtkBoundingBox::SetMinPoint(double p[3])
329 {
330  this->SetMinPoint(p[0], p[1], p[2]);
331 }
332 
333 inline void vtkBoundingBox::SetMaxPoint(double p[3])
334 {
335  this->SetMaxPoint(p[0], p[1], p[2]);
336 }
337 
338 inline void vtkBoundingBox::GetMinPoint(double &x, double &y, double &z) const
339 {
340  x = this->MinPnt[0];
341  y = this->MinPnt[1];
342  z = this->MinPnt[2];
343 }
344 
345 inline void vtkBoundingBox::GetMaxPoint(double &x, double &y, double &z) const
346 {
347  x = this->MaxPnt[0];
348  y = this->MaxPnt[1];
349  z = this->MaxPnt[2];
350 }
351 
352 inline int vtkBoundingBox::ContainsPoint(double px, double py,
353  double pz) const
354 {
355  if ((px < this->MinPnt[0]) || (px > this->MaxPnt[0]))
356  {
357  return 0;
358  }
359  if ((py < this->MinPnt[1]) || (py > this->MaxPnt[1]))
360  {
361  return 0;
362  }
363  if ((pz < this->MinPnt[2]) || (pz > this->MaxPnt[2]))
364  {
365  return 0;
366  }
367  return 1;
368 }
369 
370 inline int vtkBoundingBox::ContainsPoint(double p[3]) const
371 {
372  return this->ContainsPoint(p[0], p[1], p[2]);
373 }
374 
375 #endif
376 // VTK-HeaderTest-Exclude: vtkBoundingBox.h
void GetBounds(double bounds[6]) const
const double * GetMinPoint() const
#define VTK_DOUBLE_MAX
Definition: vtkType.h:140
void SetMaxPoint(double x, double y, double z)
int operator!=(const vtkBoundingBox &bbox) const
int ContainsPoint(double p[3]) const
int operator==(const vtkBoundingBox &bbox) const
void GetCenter(double center[3]) const
int IsValid() const
double GetBound(int i) const
void GetLengths(double lengths[3]) const
vtkBoundingBox & operator=(const vtkBoundingBox &bbox)
void SetMinPoint(double x, double y, double z)
#define VTK_DOUBLE_MIN
Definition: vtkType.h:139
double GetLength(int i) const
void SetBounds(const double bounds[6])
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
#define VTKCOMMONDATAMODEL_EXPORT
Fast Simple Class for dealing with 3D bounds.
double MinPnt[3]