VTK
vtkBoundingBox.h
Go to the documentation of this file.
1/*=========================================================================
2
3Program: Visualization Toolkit
4Module: vtkBoundingBox.h
5
6Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7All rights reserved.
8See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9
10This software is distributed WITHOUT ANY WARRANTY; without even
11the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12PURPOSE. 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
35class VTKCOMMONDATAMODEL_EXPORT vtkBoundingBox
36{
37public:
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
103 void AddPoint(double p[3]);
104 void AddPoint(double px, double py, double pz);
106
110 void AddBox(const vtkBoundingBox &bbox);
111
115 void AddBounds(const double bounds[]);
116
117 // Desciption:
118 // Intersect this box with bbox. The method returns 1 if
119 // both boxes are valid and they do have overlap else it will return 0.
120 // If 0 is returned the box has not been modified
121 int IntersectBox(const vtkBoundingBox &bbox);
122
126 int Intersects(const vtkBoundingBox &bbox) const;
127
128
129 // Desciption:
130 // Intersect this box with the half space defined by plane.
131 //Returns true if there is intersection---which implies that the box has been modified
132 // Returns false otherwise
133 bool IntersectPlane(double origin[3],double normal[3]);
134
135
140 int Contains(const vtkBoundingBox &bbox) const;
141
143
146 void GetBounds(double bounds[6]) const;
147 void GetBounds(double &xMin, double &xMax,
148 double &yMin, double &yMax,
149 double &zMin, double &zMax) const;
151
155 double GetBound(int i) const;
156
158
161 const double *GetMinPoint() const;
162 void GetMinPoint(double &x, double &y, double &z) const;
164
166
169 const double *GetMaxPoint() const;
170 void GetMaxPoint(double &x, double &y, double &z) const;
172
174
177 int ContainsPoint(double p[3]) const;
178 int ContainsPoint(double px, double py, double pz) const;
180
184 void GetCenter(double center[3]) const;
185
189 void GetLengths(double lengths[3]) const;
190
194 double GetLength(int i) const;
195
199 double GetMaxLength() const;
200
205 double GetDiagonalLength() const;
206
211 void Inflate(double delta);
212
214
218 int IsValid() const;
219 static int IsValid(const double bounds[6]);
221
225 void Reset();
226
228
234 void Scale(double s[3]);
235 void Scale(double sx,
236 double sy,
237 double sz);
239
240protected:
241 double MinPnt[3], MaxPnt[3];
242};
243
245{
246 this->MinPnt[0] = this->MinPnt[1] = this->MinPnt[2] = VTK_DOUBLE_MAX;
247 this->MaxPnt[0] = this->MaxPnt[1] = this->MaxPnt[2] = VTK_DOUBLE_MIN;
248}
249
250inline void vtkBoundingBox::GetBounds(double &xMin, double &xMax,
251 double &yMin, double &yMax,
252 double &zMin, double &zMax) const
253{
254 xMin = this->MinPnt[0];
255 xMax = this->MaxPnt[0];
256 yMin = this->MinPnt[1];
257 yMax = this->MaxPnt[1];
258 zMin = this->MinPnt[2];
259 zMax = this->MaxPnt[2];
260}
261
262inline double vtkBoundingBox::GetBound(int i) const
263{
264 // If i is odd then when are returning a part of the max bounds
265 // else part of the min bounds is requested. The exact component
266 // needed is i /2 (or i right shifted by 1
267 return ((i & 0x1) ? this->MaxPnt[i>>1] : this->MinPnt[i>>1]);
268}
269
270inline const double *vtkBoundingBox::GetMinPoint() const
271{
272 return this->MinPnt;
273}
274
275inline const double *vtkBoundingBox::GetMaxPoint() const
276{
277 return this->MaxPnt;
278}
279
280inline int vtkBoundingBox::IsValid() const
281{
282 return ((this->MinPnt[0] <= this->MaxPnt[0]) &&
283 (this->MinPnt[1] <= this->MaxPnt[1]) &&
284 (this->MinPnt[2] <= this->MaxPnt[2]));
285}
286
287inline int vtkBoundingBox::IsValid(const double bounds[6])
288{
289 return (bounds[0] <= bounds[1] &&
290 bounds[2] <= bounds[3] &&
291 bounds[4] <= bounds[5]);
292}
293
294inline double vtkBoundingBox::GetLength(int i) const
295{
296 return this->MaxPnt[i] - this->MinPnt[i];
297}
298
299inline void vtkBoundingBox::GetLengths(double lengths[3]) const
300{
301 lengths[0] = this->GetLength(0);
302 lengths[1] = this->GetLength(1);
303 lengths[2] = this->GetLength(2);
304}
305
306inline void vtkBoundingBox::GetCenter(double center[3]) const
307{
308 center[0] = 0.5 * (this->MaxPnt[0] + this->MinPnt[0]);
309 center[1] = 0.5 * (this->MaxPnt[1] + this->MinPnt[1]);
310 center[2] = 0.5 * (this->MaxPnt[2] + this->MinPnt[2]);
311}
312
313inline void vtkBoundingBox::SetBounds(const double bounds[6])
314{
315 this->SetBounds(bounds[0], bounds[1], bounds[2],
316 bounds[3], bounds[4], bounds[5]);
317}
318
319inline void vtkBoundingBox::GetBounds(double bounds[6]) const
320{
321 this->GetBounds(bounds[0], bounds[1], bounds[2],
322 bounds[3], bounds[4], bounds[5]);
323}
324
326{
327 this->Reset();
328}
329
330inline vtkBoundingBox::vtkBoundingBox(const double bounds[6])
331{
332 this->Reset();
333 this->SetBounds(bounds);
334}
335
336inline vtkBoundingBox::vtkBoundingBox(double xMin, double xMax,
337 double yMin, double yMax,
338 double zMin, double zMax)
339{
340 this->Reset();
341 this->SetBounds(xMin, xMax, yMin, yMax, zMin, zMax);
342}
343
345{
346 this->MinPnt[0] = bbox.MinPnt[0];
347 this->MinPnt[1] = bbox.MinPnt[1];
348 this->MinPnt[2] = bbox.MinPnt[2];
349
350 this->MaxPnt[0] = bbox.MaxPnt[0];
351 this->MaxPnt[1] = bbox.MaxPnt[1];
352 this->MaxPnt[2] = bbox.MaxPnt[2];
353}
354
356{
357 this->MinPnt[0] = bbox.MinPnt[0];
358 this->MinPnt[1] = bbox.MinPnt[1];
359 this->MinPnt[2] = bbox.MinPnt[2];
360
361 this->MaxPnt[0] = bbox.MaxPnt[0];
362 this->MaxPnt[1] = bbox.MaxPnt[1];
363 this->MaxPnt[2] = bbox.MaxPnt[2];
364 return *this;
365}
366
367inline bool vtkBoundingBox::operator==(const vtkBoundingBox &bbox)const
368{
369 return ((this->MinPnt[0] == bbox.MinPnt[0]) &&
370 (this->MinPnt[1] == bbox.MinPnt[1]) &&
371 (this->MinPnt[2] == bbox.MinPnt[2]) &&
372 (this->MaxPnt[0] == bbox.MaxPnt[0]) &&
373 (this->MaxPnt[1] == bbox.MaxPnt[1]) &&
374 (this->MaxPnt[2] == bbox.MaxPnt[2]));
375}
376
377inline bool vtkBoundingBox::operator!=(const vtkBoundingBox &bbox)const
378{
379 return !((*this) == bbox);
380}
381
382inline void vtkBoundingBox::SetMinPoint(double p[3])
383{
384 this->SetMinPoint(p[0], p[1], p[2]);
385}
386
387inline void vtkBoundingBox::SetMaxPoint(double p[3])
388{
389 this->SetMaxPoint(p[0], p[1], p[2]);
390}
391
392inline void vtkBoundingBox::GetMinPoint(double &x, double &y, double &z) const
393{
394 x = this->MinPnt[0];
395 y = this->MinPnt[1];
396 z = this->MinPnt[2];
397}
398
399inline void vtkBoundingBox::GetMaxPoint(double &x, double &y, double &z) const
400{
401 x = this->MaxPnt[0];
402 y = this->MaxPnt[1];
403 z = this->MaxPnt[2];
404}
405
406inline int vtkBoundingBox::ContainsPoint(double px, double py,
407 double pz) const
408{
409 if ((px < this->MinPnt[0]) || (px > this->MaxPnt[0]))
410 {
411 return 0;
412 }
413 if ((py < this->MinPnt[1]) || (py > this->MaxPnt[1]))
414 {
415 return 0;
416 }
417 if ((pz < this->MinPnt[2]) || (pz > this->MaxPnt[2]))
418 {
419 return 0;
420 }
421 return 1;
422}
423
424inline int vtkBoundingBox::ContainsPoint(double p[3]) const
425{
426 return this->ContainsPoint(p[0], p[1], p[2]);
427}
428
429#endif
430// VTK-HeaderTest-Exclude: vtkBoundingBox.h
Fast Simple Class for dealing with 3D bounds.
void Scale(double s[3])
Scale each dimension of the box by some given factor.
int IntersectBox(const vtkBoundingBox &bbox)
const double * GetMinPoint() const
Get the minimum point of the bounding box.
double GetDiagonalLength() const
Return the length of the diagonal.
void SetBounds(double xMin, double xMax, double yMin, double yMax, double zMin, double zMax)
void AddBox(const vtkBoundingBox &bbox)
Change the bouding box to be the union of itself and bbox.
void AddBounds(const double bounds[])
Change the bounding box so it includes bounds (defined by vtk standard)
int Contains(const vtkBoundingBox &bbox) const
Returns 1 if the min and max points of bbox are contained within the bounds of this 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...
int Intersects(const vtkBoundingBox &bbox) const
Returns 1 if the boxes intersect else returns 0.
double GetMaxLength() const
Return the Max Length of the box.
bool operator!=(const vtkBoundingBox &bbox) const
void AddPoint(double px, double py, double pz)
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 ...
void Reset()
Returns the box to its initialized state.
bool IntersectPlane(double origin[3], double normal[3])
void GetCenter(double center[3]) const
Get the center of the bounding box.
void AddPoint(double p[3])
Change bounding box so it includes the point p Note that the bounding box may have 0 volume if its bo...
double GetLength(int i) const
Return the length in the ith direction.
bool operator==(const vtkBoundingBox &bbox) const
Equality Operator.
vtkBoundingBox()
Construct a bounding box with the min point set to VTK_DOUBLE_MAX and the max point set to VTK_DOUBLE...
double MinPnt[3]
void Scale(double sx, double sy, double sz)
int ContainsPoint(double p[3]) const
Returns 1 if the point is contained in the box else 0;.
double MaxPnt[3]
void GetLengths(double lengths[3]) const
Get the lengths of the box.
void Inflate(double delta)
Expand the Box by delta on each side, the box will grow by 2*delta in x,y and z.
void SetBounds(const double bounds[6])
Set the bounds explicitly of the box (vtk Style) Returns 1 if the box was changed else 0.
const double * GetMaxPoint() const
Get the maximum point of the bounding box.
double GetBound(int i) const
Return the ith bounds of the box (defined by vtk style)
void GetBounds(double bounds[6]) const
Get the bounds of the box (defined by vtk style)
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...
vtkBoundingBox & operator=(const vtkBoundingBox &bbox)
Assignment Operator.
@ center
Definition: vtkX3D.h:230
#define VTK_DOUBLE_MIN
Definition: vtkType.h:162
#define VTK_DOUBLE_MAX
Definition: vtkType.h:163
VTKCOMMONCORE_EXPORT bool operator!=(const vtkUnicodeString &lhs, const vtkUnicodeString &rhs)
VTKCOMMONCORE_EXPORT bool operator==(const vtkUnicodeString &lhs, const vtkUnicodeString &rhs)