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 "vtkSystemIncludes.h"
32 
34 {
35 public:
37 
40  vtkBoundingBox(double bounds[6]);
41  vtkBoundingBox(double xMin, double xMax,
42  double yMin, double yMax,
43  double zMin, double zMax);
45 
47  vtkBoundingBox(const vtkBoundingBox &bbox);
48 
50  vtkBoundingBox &operator=(const vtkBoundingBox &bbox);
51 
53 
54  int operator==(const vtkBoundingBox &bbox)const;
55  int operator!=(const vtkBoundingBox &bbox)const;
57 
59 
61  void SetBounds(double bounds[6]);
62  void SetBounds(double xMin, double xMax,
63  double yMin, double yMax,
64  double zMin, double zMax);
66 
68 
70  void SetMinPoint(double x, double y, double z);
71  void SetMinPoint(double p[3]);
73 
75 
77  void SetMaxPoint(double x, double y, double z);
78  void SetMaxPoint(double p[3]);
80 
82 
84  void AddPoint(double p[3]);
85  void AddPoint(double px, double py, double pz);
87 
89  void AddBox(const vtkBoundingBox &bbox);
90 
93  void AddBounds(double bounds[6]);
94 
95  // Desciption:
96  // Intersect this box with bbox. The method returns 1 if
97  // both boxes are valid and they do have overlap else it will return 0.
98  // If 0 is returned the box has not been modified
99  int IntersectBox(const vtkBoundingBox &bbox);
100 
102  int Intersects(const vtkBoundingBox &bbox) const;
103 
106  int Contains(const vtkBoundingBox &bbox) const;
107 
109 
110  void GetBounds(double bounds[6]) const;
111  void GetBounds(double &xMin, double &xMax,
112  double &yMin, double &yMax,
113  double &zMin, double &zMax) const;
115 
117  double GetBound(int i) const;
118 
120 
121  const double *GetMinPoint() const;
122  void GetMinPoint(double &x, double &y, double &z) const;
124 
126 
127  const double *GetMaxPoint() const;
128  void GetMaxPoint(double &x, double &y, double &z) const;
130 
132 
133  int ContainsPoint(double p[3]) const;
134  int ContainsPoint(double px, double py, double pz) const;
136 
138  void GetCenter(double center[3]) const;
139 
141  void GetLengths(double lengths[3]) const;
142 
144  double GetLength(int i) const;
145 
147  double GetMaxLength() const;
148 
150  double GetDiagonalLength() const;
151 
154  void Inflate(double delta);
155 
157 
159  int IsValid() const;
160  static int IsValid(double bounds[6]);
162 
164  void Reset();
165 
167 
171  void Scale(double s[3]);
172  void Scale(double sx,
173  double sy,
174  double sz);
176 
177 protected:
178  double MinPnt[3], MaxPnt[3];
179 };
180 
182 {
183  this->MinPnt[0] = this->MinPnt[1] = this->MinPnt[2] = VTK_DOUBLE_MAX;
184  this->MaxPnt[0] = this->MaxPnt[1] = this->MaxPnt[2] = VTK_DOUBLE_MIN;
185 }
186 
187 inline void vtkBoundingBox::GetBounds(double &xMin, double &xMax,
188  double &yMin, double &yMax,
189  double &zMin, double &zMax) const
190 {
191  xMin = this->MinPnt[0];
192  xMax = this->MaxPnt[0];
193  yMin = this->MinPnt[1];
194  yMax = this->MaxPnt[1];
195  zMin = this->MinPnt[2];
196  zMax = this->MaxPnt[2];
197 }
198 
199 inline double vtkBoundingBox::GetBound(int i) const
200 {
201  // If i is odd then when are returning a part of the max bounds
202  // else part of the min bounds is requested. The exact component
203  // needed is i /2 (or i right shifted by 1
204  return ((i & 0x1) ? this->MaxPnt[i>>1] : this->MinPnt[i>>1]);
205 }
206 
207 inline const double *vtkBoundingBox::GetMinPoint() const
208 {
209  return this->MinPnt;
210 }
211 
212 inline const double *vtkBoundingBox::GetMaxPoint() const
213 {
214  return this->MaxPnt;
215 }
216 
217 inline int vtkBoundingBox::IsValid() const
218 {
219  return ((this->MinPnt[0] <= this->MaxPnt[0]) &&
220  (this->MinPnt[1] <= this->MaxPnt[1]) &&
221  (this->MinPnt[2] <= this->MaxPnt[2]));
222 }
223 
224 inline int vtkBoundingBox::IsValid(double bounds[6])
225 {
226  return (bounds[0] <= bounds[1] &&
227  bounds[2] <= bounds[3] &&
228  bounds[4] <= bounds[5]);
229 }
230 
231 inline double vtkBoundingBox::GetLength(int i) const
232 {
233  return this->MaxPnt[i] - this->MinPnt[i];
234 }
235 
236 inline void vtkBoundingBox::GetLengths(double lengths[3]) const
237 {
238  lengths[0] = this->GetLength(0);
239  lengths[1] = this->GetLength(1);
240  lengths[2] = this->GetLength(2);
241 }
242 
243 inline void vtkBoundingBox::GetCenter(double center[3]) const
244 {
245  center[0] = 0.5 * (this->MaxPnt[0] + this->MinPnt[0]);
246  center[1] = 0.5 * (this->MaxPnt[1] + this->MinPnt[1]);
247  center[2] = 0.5 * (this->MaxPnt[2] + this->MinPnt[2]);
248 }
249 
250 inline void vtkBoundingBox::SetBounds(double bounds[6])
251 {
252  this->SetBounds(bounds[0], bounds[1], bounds[2],
253  bounds[3], bounds[4], bounds[5]);
254 }
255 
256 inline void vtkBoundingBox::GetBounds(double bounds[6]) const
257 {
258  this->GetBounds(bounds[0], bounds[1], bounds[2],
259  bounds[3], bounds[4], bounds[5]);
260 }
261 
263 {
264  this->Reset();
265 }
266 
267 inline vtkBoundingBox::vtkBoundingBox(double bounds[6])
268 {
269  this->Reset();
270  this->SetBounds(bounds);
271 }
272 
273 inline vtkBoundingBox::vtkBoundingBox(double xMin, double xMax,
274  double yMin, double yMax,
275  double zMin, double zMax)
276 {
277  this->Reset();
278  this->SetBounds(xMin, xMax, yMin, yMax, zMin, zMax);
279 }
280 
282 {
283  this->MinPnt[0] = bbox.MinPnt[0];
284  this->MinPnt[1] = bbox.MinPnt[1];
285  this->MinPnt[2] = bbox.MinPnt[2];
286 
287  this->MaxPnt[0] = bbox.MaxPnt[0];
288  this->MaxPnt[1] = bbox.MaxPnt[1];
289  this->MaxPnt[2] = bbox.MaxPnt[2];
290 }
291 
293 {
294  this->MinPnt[0] = bbox.MinPnt[0];
295  this->MinPnt[1] = bbox.MinPnt[1];
296  this->MinPnt[2] = bbox.MinPnt[2];
297 
298  this->MaxPnt[0] = bbox.MaxPnt[0];
299  this->MaxPnt[1] = bbox.MaxPnt[1];
300  this->MaxPnt[2] = bbox.MaxPnt[2];
301  return *this;
302 }
303 
304 inline int vtkBoundingBox::operator==(const vtkBoundingBox &bbox)const
305 {
306  return ((this->MinPnt[0] == bbox.MinPnt[0]) &&
307  (this->MinPnt[1] == bbox.MinPnt[1]) &&
308  (this->MinPnt[2] == bbox.MinPnt[2]) &&
309  (this->MaxPnt[0] == bbox.MaxPnt[0]) &&
310  (this->MaxPnt[1] == bbox.MaxPnt[1]) &&
311  (this->MaxPnt[2] == bbox.MaxPnt[2]));
312 }
313 
314 inline int vtkBoundingBox::operator!=(const vtkBoundingBox &bbox)const
315 {
316  return !((*this) == bbox);
317 }
318 
319 inline void vtkBoundingBox::SetMinPoint(double p[3])
320 {
321  this->SetMinPoint(p[0], p[1], p[2]);
322 }
323 
324 inline void vtkBoundingBox::SetMaxPoint(double p[3])
325 {
326  this->SetMaxPoint(p[0], p[1], p[2]);
327 }
328 
329 inline void vtkBoundingBox::GetMinPoint(double &x, double &y, double &z) const
330 {
331  x = this->MinPnt[0];
332  y = this->MinPnt[1];
333  z = this->MinPnt[2];
334 }
335 
336 inline void vtkBoundingBox::GetMaxPoint(double &x, double &y, double &z) const
337 {
338  x = this->MaxPnt[0];
339  y = this->MaxPnt[1];
340  z = this->MaxPnt[2];
341 }
342 
343 inline int vtkBoundingBox::ContainsPoint(double px, double py,
344  double pz) const
345 {
346  if ((px < this->MinPnt[0]) || (px > this->MaxPnt[0]))
347  {
348  return 0;
349  }
350  if ((py < this->MinPnt[1]) || (py > this->MaxPnt[1]))
351  {
352  return 0;
353  }
354  if ((pz < this->MinPnt[2]) || (pz > this->MaxPnt[2]))
355  {
356  return 0;
357  }
358  return 1;
359 }
360 
361 inline int vtkBoundingBox::ContainsPoint(double p[3]) const
362 {
363  return this->ContainsPoint(p[0], p[1], p[2]);
364 }
365 
366 #endif
void GetBounds(double bounds[6]) const
const double * GetMinPoint() const
#define VTK_DOUBLE_MAX
Definition: vtkType.h:133
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
VTK_COMMON_EXPORT bool operator==(const vtkUnicodeString &lhs, const vtkUnicodeString &rhs)
int IsValid() const
double GetBound(int i) const
void GetLengths(double lengths[3]) const
vtkBoundingBox & operator=(const vtkBoundingBox &bbox)
void SetBounds(double bounds[6])
#define VTK_COMMON_EXPORT
void SetMinPoint(double x, double y, double z)
#define VTK_DOUBLE_MIN
Definition: vtkType.h:132
double GetLength(int i) const
double MaxPnt[3]
VTK_COMMON_EXPORT bool operator!=(const vtkUnicodeString &lhs, const vtkUnicodeString &rhs)
const double * GetMaxPoint() const
Fast Simple Class for dealing with 3D bounds.
double MinPnt[3]