VTK
|
00001 /*========================================================================= 00002 00003 Program: Visualization Toolkit 00004 Module: vtkBoundingBox.h 00005 00006 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 00007 All rights reserved. 00008 See Copyright.txt or http://www.kitware.com/Copyright.htm for details. 00009 00010 This software is distributed WITHOUT ANY WARRANTY; without even 00011 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00012 PURPOSE. See the above copyright notice for more information. 00013 00014 =========================================================================*/ 00029 #ifndef __vtkBoundingBox_h 00030 #define __vtkBoundingBox_h 00031 #include "vtkCommonDataModelModule.h" // For export macro 00032 #include "vtkSystemIncludes.h" 00033 00034 class VTKCOMMONDATAMODEL_EXPORT vtkBoundingBox 00035 { 00036 public: 00038 00040 vtkBoundingBox(); 00041 vtkBoundingBox(double bounds[6]); 00042 vtkBoundingBox(double xMin, double xMax, 00043 double yMin, double yMax, 00044 double zMin, double zMax); 00046 00048 vtkBoundingBox(const vtkBoundingBox &bbox); 00049 00051 vtkBoundingBox &operator=(const vtkBoundingBox &bbox); 00052 00054 00055 int operator==(const vtkBoundingBox &bbox)const; 00056 int operator!=(const vtkBoundingBox &bbox)const; 00058 00060 00062 void SetBounds(const double bounds[6]); 00063 void SetBounds(double xMin, double xMax, 00064 double yMin, double yMax, 00065 double zMin, double zMax); 00067 00069 00071 void SetMinPoint(double x, double y, double z); 00072 void SetMinPoint(double p[3]); 00074 00076 00078 void SetMaxPoint(double x, double y, double z); 00079 void SetMaxPoint(double p[3]); 00081 00083 00085 void AddPoint(double p[3]); 00086 void AddPoint(double px, double py, double pz); 00088 00090 void AddBox(const vtkBoundingBox &bbox); 00091 00094 void AddBounds(const double bounds[]); 00095 00096 // Desciption: 00097 // Intersect this box with bbox. The method returns 1 if 00098 // both boxes are valid and they do have overlap else it will return 0. 00099 // If 0 is returned the box has not been modified 00100 int IntersectBox(const vtkBoundingBox &bbox); 00101 00103 int Intersects(const vtkBoundingBox &bbox) const; 00104 00105 00106 // Desciption: 00107 // Intersect this box with the half space defined by plane. 00108 //Returns true if there is intersection---which implies that the box has been modified 00109 // Returns false otherwise 00110 bool IntersectPlane(double origin[3],double normal[3]); 00111 00112 00115 int Contains(const vtkBoundingBox &bbox) const; 00116 00118 00119 void GetBounds(double bounds[6]) const; 00120 void GetBounds(double &xMin, double &xMax, 00121 double &yMin, double &yMax, 00122 double &zMin, double &zMax) const; 00124 00126 double GetBound(int i) const; 00127 00129 00130 const double *GetMinPoint() const; 00131 void GetMinPoint(double &x, double &y, double &z) const; 00133 00135 00136 const double *GetMaxPoint() const; 00137 void GetMaxPoint(double &x, double &y, double &z) const; 00139 00141 00142 int ContainsPoint(double p[3]) const; 00143 int ContainsPoint(double px, double py, double pz) const; 00145 00147 void GetCenter(double center[3]) const; 00148 00150 void GetLengths(double lengths[3]) const; 00151 00153 double GetLength(int i) const; 00154 00156 double GetMaxLength() const; 00157 00159 double GetDiagonalLength() const; 00160 00163 void Inflate(double delta); 00164 00166 00168 int IsValid() const; 00169 static int IsValid(const double bounds[6]); 00171 00173 void Reset(); 00174 00176 00180 void Scale(double s[3]); 00181 void Scale(double sx, 00182 double sy, 00183 double sz); 00185 00186 protected: 00187 double MinPnt[3], MaxPnt[3]; 00188 }; 00189 00190 inline void vtkBoundingBox::Reset() 00191 { 00192 this->MinPnt[0] = this->MinPnt[1] = this->MinPnt[2] = VTK_DOUBLE_MAX; 00193 this->MaxPnt[0] = this->MaxPnt[1] = this->MaxPnt[2] = VTK_DOUBLE_MIN; 00194 } 00195 00196 inline void vtkBoundingBox::GetBounds(double &xMin, double &xMax, 00197 double &yMin, double &yMax, 00198 double &zMin, double &zMax) const 00199 { 00200 xMin = this->MinPnt[0]; 00201 xMax = this->MaxPnt[0]; 00202 yMin = this->MinPnt[1]; 00203 yMax = this->MaxPnt[1]; 00204 zMin = this->MinPnt[2]; 00205 zMax = this->MaxPnt[2]; 00206 } 00207 00208 inline double vtkBoundingBox::GetBound(int i) const 00209 { 00210 // If i is odd then when are returning a part of the max bounds 00211 // else part of the min bounds is requested. The exact component 00212 // needed is i /2 (or i right shifted by 1 00213 return ((i & 0x1) ? this->MaxPnt[i>>1] : this->MinPnt[i>>1]); 00214 } 00215 00216 inline const double *vtkBoundingBox::GetMinPoint() const 00217 { 00218 return this->MinPnt; 00219 } 00220 00221 inline const double *vtkBoundingBox::GetMaxPoint() const 00222 { 00223 return this->MaxPnt; 00224 } 00225 00226 inline int vtkBoundingBox::IsValid() const 00227 { 00228 return ((this->MinPnt[0] <= this->MaxPnt[0]) && 00229 (this->MinPnt[1] <= this->MaxPnt[1]) && 00230 (this->MinPnt[2] <= this->MaxPnt[2])); 00231 } 00232 00233 inline int vtkBoundingBox::IsValid(const double bounds[6]) 00234 { 00235 return (bounds[0] <= bounds[1] && 00236 bounds[2] <= bounds[3] && 00237 bounds[4] <= bounds[5]); 00238 } 00239 00240 inline double vtkBoundingBox::GetLength(int i) const 00241 { 00242 return this->MaxPnt[i] - this->MinPnt[i]; 00243 } 00244 00245 inline void vtkBoundingBox::GetLengths(double lengths[3]) const 00246 { 00247 lengths[0] = this->GetLength(0); 00248 lengths[1] = this->GetLength(1); 00249 lengths[2] = this->GetLength(2); 00250 } 00251 00252 inline void vtkBoundingBox::GetCenter(double center[3]) const 00253 { 00254 center[0] = 0.5 * (this->MaxPnt[0] + this->MinPnt[0]); 00255 center[1] = 0.5 * (this->MaxPnt[1] + this->MinPnt[1]); 00256 center[2] = 0.5 * (this->MaxPnt[2] + this->MinPnt[2]); 00257 } 00258 00259 inline void vtkBoundingBox::SetBounds(const double bounds[6]) 00260 { 00261 this->SetBounds(bounds[0], bounds[1], bounds[2], 00262 bounds[3], bounds[4], bounds[5]); 00263 } 00264 00265 inline void vtkBoundingBox::GetBounds(double bounds[6]) const 00266 { 00267 this->GetBounds(bounds[0], bounds[1], bounds[2], 00268 bounds[3], bounds[4], bounds[5]); 00269 } 00270 00271 inline vtkBoundingBox::vtkBoundingBox() 00272 { 00273 this->Reset(); 00274 } 00275 00276 inline vtkBoundingBox::vtkBoundingBox(double bounds[6]) 00277 { 00278 this->Reset(); 00279 this->SetBounds(bounds); 00280 } 00281 00282 inline vtkBoundingBox::vtkBoundingBox(double xMin, double xMax, 00283 double yMin, double yMax, 00284 double zMin, double zMax) 00285 { 00286 this->Reset(); 00287 this->SetBounds(xMin, xMax, yMin, yMax, zMin, zMax); 00288 } 00289 00290 inline vtkBoundingBox::vtkBoundingBox(const vtkBoundingBox &bbox) 00291 { 00292 this->MinPnt[0] = bbox.MinPnt[0]; 00293 this->MinPnt[1] = bbox.MinPnt[1]; 00294 this->MinPnt[2] = bbox.MinPnt[2]; 00295 00296 this->MaxPnt[0] = bbox.MaxPnt[0]; 00297 this->MaxPnt[1] = bbox.MaxPnt[1]; 00298 this->MaxPnt[2] = bbox.MaxPnt[2]; 00299 } 00300 00301 inline vtkBoundingBox &vtkBoundingBox::operator=(const vtkBoundingBox &bbox) 00302 { 00303 this->MinPnt[0] = bbox.MinPnt[0]; 00304 this->MinPnt[1] = bbox.MinPnt[1]; 00305 this->MinPnt[2] = bbox.MinPnt[2]; 00306 00307 this->MaxPnt[0] = bbox.MaxPnt[0]; 00308 this->MaxPnt[1] = bbox.MaxPnt[1]; 00309 this->MaxPnt[2] = bbox.MaxPnt[2]; 00310 return *this; 00311 } 00312 00313 inline int vtkBoundingBox::operator==(const vtkBoundingBox &bbox)const 00314 { 00315 return ((this->MinPnt[0] == bbox.MinPnt[0]) && 00316 (this->MinPnt[1] == bbox.MinPnt[1]) && 00317 (this->MinPnt[2] == bbox.MinPnt[2]) && 00318 (this->MaxPnt[0] == bbox.MaxPnt[0]) && 00319 (this->MaxPnt[1] == bbox.MaxPnt[1]) && 00320 (this->MaxPnt[2] == bbox.MaxPnt[2])); 00321 } 00322 00323 inline int vtkBoundingBox::operator!=(const vtkBoundingBox &bbox)const 00324 { 00325 return !((*this) == bbox); 00326 } 00327 00328 inline void vtkBoundingBox::SetMinPoint(double p[3]) 00329 { 00330 this->SetMinPoint(p[0], p[1], p[2]); 00331 } 00332 00333 inline void vtkBoundingBox::SetMaxPoint(double p[3]) 00334 { 00335 this->SetMaxPoint(p[0], p[1], p[2]); 00336 } 00337 00338 inline void vtkBoundingBox::GetMinPoint(double &x, double &y, double &z) const 00339 { 00340 x = this->MinPnt[0]; 00341 y = this->MinPnt[1]; 00342 z = this->MinPnt[2]; 00343 } 00344 00345 inline void vtkBoundingBox::GetMaxPoint(double &x, double &y, double &z) const 00346 { 00347 x = this->MaxPnt[0]; 00348 y = this->MaxPnt[1]; 00349 z = this->MaxPnt[2]; 00350 } 00351 00352 inline int vtkBoundingBox::ContainsPoint(double px, double py, 00353 double pz) const 00354 { 00355 if ((px < this->MinPnt[0]) || (px > this->MaxPnt[0])) 00356 { 00357 return 0; 00358 } 00359 if ((py < this->MinPnt[1]) || (py > this->MaxPnt[1])) 00360 { 00361 return 0; 00362 } 00363 if ((pz < this->MinPnt[2]) || (pz > this->MaxPnt[2])) 00364 { 00365 return 0; 00366 } 00367 return 1; 00368 } 00369 00370 inline int vtkBoundingBox::ContainsPoint(double p[3]) const 00371 { 00372 return this->ContainsPoint(p[0], p[1], p[2]); 00373 } 00374 00375 #endif 00376 // VTK-HeaderTest-Exclude: vtkBoundingBox.h