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 "vtkSystemIncludes.h" 00032 00033 class VTK_COMMON_EXPORT vtkBoundingBox 00034 { 00035 public: 00037 00039 vtkBoundingBox(); 00040 vtkBoundingBox(double bounds[6]); 00041 vtkBoundingBox(double xMin, double xMax, 00042 double yMin, double yMax, 00043 double zMin, double zMax); 00045 00047 vtkBoundingBox(const vtkBoundingBox &bbox); 00048 00050 vtkBoundingBox &operator=(const vtkBoundingBox &bbox); 00051 00053 00054 int operator==(const vtkBoundingBox &bbox)const; 00055 int operator!=(const vtkBoundingBox &bbox)const; 00057 00059 00061 void SetBounds(double bounds[6]); 00062 void SetBounds(double xMin, double xMax, 00063 double yMin, double yMax, 00064 double zMin, double zMax); 00066 00068 00070 void SetMinPoint(double x, double y, double z); 00071 void SetMinPoint(double p[3]); 00073 00075 00077 void SetMaxPoint(double x, double y, double z); 00078 void SetMaxPoint(double p[3]); 00080 00082 00084 void AddPoint(double p[3]); 00085 void AddPoint(double px, double py, double pz); 00087 00089 void AddBox(const vtkBoundingBox &bbox); 00090 00093 void AddBounds(double bounds[6]); 00094 00095 // Desciption: 00096 // Intersect this box with bbox. The method returns 1 if 00097 // both boxes are valid and they do have overlap else it will return 0. 00098 // If 0 is returned the box has not been modified 00099 int IntersectBox(const vtkBoundingBox &bbox); 00100 00102 int Intersects(const vtkBoundingBox &bbox) const; 00103 00106 int Contains(const vtkBoundingBox &bbox) const; 00107 00109 00110 void GetBounds(double bounds[6]) const; 00111 void GetBounds(double &xMin, double &xMax, 00112 double &yMin, double &yMax, 00113 double &zMin, double &zMax) const; 00115 00117 double GetBound(int i) const; 00118 00120 00121 const double *GetMinPoint() const; 00122 void GetMinPoint(double &x, double &y, double &z) const; 00124 00126 00127 const double *GetMaxPoint() const; 00128 void GetMaxPoint(double &x, double &y, double &z) const; 00130 00132 00133 int ContainsPoint(double p[3]) const; 00134 int ContainsPoint(double px, double py, double pz) const; 00136 00138 void GetCenter(double center[3]) const; 00139 00141 void GetLengths(double lengths[3]) const; 00142 00144 double GetLength(int i) const; 00145 00147 double GetMaxLength() const; 00148 00150 double GetDiagonalLength() const; 00151 00154 void Inflate(double delta); 00155 00158 int IsValid() const; 00159 00161 void Reset(); 00162 00164 00168 void Scale(double s[3]); 00169 void Scale(double sx, 00170 double sy, 00171 double sz); 00173 00174 protected: 00175 double MinPnt[3], MaxPnt[3]; 00176 }; 00177 00178 inline void vtkBoundingBox::Reset() 00179 { 00180 this->MinPnt[0] = this->MinPnt[1] = this->MinPnt[2] = VTK_DOUBLE_MAX; 00181 this->MaxPnt[0] = this->MaxPnt[1] = this->MaxPnt[2] = VTK_DOUBLE_MIN; 00182 } 00183 00184 inline void vtkBoundingBox::GetBounds(double &xMin, double &xMax, 00185 double &yMin, double &yMax, 00186 double &zMin, double &zMax) const 00187 { 00188 xMin = this->MinPnt[0]; 00189 xMax = this->MaxPnt[0]; 00190 yMin = this->MinPnt[1]; 00191 yMax = this->MaxPnt[1]; 00192 zMin = this->MinPnt[2]; 00193 zMax = this->MaxPnt[2]; 00194 } 00195 00196 inline double vtkBoundingBox::GetBound(int i) const 00197 { 00198 // If i is odd then when are returning a part of the max bounds 00199 // else part of the min bounds is requested. The exact component 00200 // needed is i /2 (or i right shifted by 1 00201 return ((i & 0x1) ? this->MaxPnt[i>>1] : this->MinPnt[i>>1]); 00202 } 00203 00204 inline const double *vtkBoundingBox::GetMinPoint() const 00205 { 00206 return this->MinPnt; 00207 } 00208 00209 inline const double *vtkBoundingBox::GetMaxPoint() const 00210 { 00211 return this->MaxPnt; 00212 } 00213 00214 inline int vtkBoundingBox::IsValid() const 00215 { 00216 return ((this->MinPnt[0] <= this->MaxPnt[0]) && 00217 (this->MinPnt[1] <= this->MaxPnt[1]) && 00218 (this->MinPnt[2] <= this->MaxPnt[2])); 00219 } 00220 00221 inline double vtkBoundingBox::GetLength(int i) const 00222 { 00223 return this->MaxPnt[i] - this->MinPnt[i]; 00224 } 00225 00226 inline void vtkBoundingBox::GetLengths(double lengths[3]) const 00227 { 00228 lengths[0] = this->GetLength(0); 00229 lengths[1] = this->GetLength(1); 00230 lengths[2] = this->GetLength(2); 00231 } 00232 00233 inline void vtkBoundingBox::GetCenter(double center[3]) const 00234 { 00235 center[0] = 0.5 * (this->MaxPnt[0] + this->MinPnt[0]); 00236 center[1] = 0.5 * (this->MaxPnt[1] + this->MinPnt[1]); 00237 center[2] = 0.5 * (this->MaxPnt[2] + this->MinPnt[2]); 00238 } 00239 00240 inline void vtkBoundingBox::SetBounds(double bounds[6]) 00241 { 00242 this->SetBounds(bounds[0], bounds[1], bounds[2], 00243 bounds[3], bounds[4], bounds[5]); 00244 } 00245 00246 inline void vtkBoundingBox::GetBounds(double bounds[6]) const 00247 { 00248 this->GetBounds(bounds[0], bounds[1], bounds[2], 00249 bounds[3], bounds[4], bounds[5]); 00250 } 00251 00252 inline vtkBoundingBox::vtkBoundingBox() 00253 { 00254 this->Reset(); 00255 } 00256 00257 inline vtkBoundingBox::vtkBoundingBox(double bounds[6]) 00258 { 00259 this->Reset(); 00260 this->SetBounds(bounds); 00261 } 00262 00263 inline vtkBoundingBox::vtkBoundingBox(double xMin, double xMax, 00264 double yMin, double yMax, 00265 double zMin, double zMax) 00266 { 00267 this->Reset(); 00268 this->SetBounds(xMin, xMax, yMin, yMax, zMin, zMax); 00269 } 00270 00271 inline vtkBoundingBox::vtkBoundingBox(const vtkBoundingBox &bbox) 00272 { 00273 this->MinPnt[0] = bbox.MinPnt[0]; 00274 this->MinPnt[1] = bbox.MinPnt[1]; 00275 this->MinPnt[2] = bbox.MinPnt[2]; 00276 00277 this->MaxPnt[0] = bbox.MaxPnt[0]; 00278 this->MaxPnt[1] = bbox.MaxPnt[1]; 00279 this->MaxPnt[2] = bbox.MaxPnt[2]; 00280 } 00281 00282 inline vtkBoundingBox &vtkBoundingBox::operator=(const vtkBoundingBox &bbox) 00283 { 00284 this->MinPnt[0] = bbox.MinPnt[0]; 00285 this->MinPnt[1] = bbox.MinPnt[1]; 00286 this->MinPnt[2] = bbox.MinPnt[2]; 00287 00288 this->MaxPnt[0] = bbox.MaxPnt[0]; 00289 this->MaxPnt[1] = bbox.MaxPnt[1]; 00290 this->MaxPnt[2] = bbox.MaxPnt[2]; 00291 return *this; 00292 } 00293 00294 inline int vtkBoundingBox::operator==(const vtkBoundingBox &bbox)const 00295 { 00296 return ((this->MinPnt[0] == bbox.MinPnt[0]) && 00297 (this->MinPnt[1] == bbox.MinPnt[1]) && 00298 (this->MinPnt[2] == bbox.MinPnt[2]) && 00299 (this->MaxPnt[0] == bbox.MaxPnt[0]) && 00300 (this->MaxPnt[1] == bbox.MaxPnt[1]) && 00301 (this->MaxPnt[2] == bbox.MaxPnt[2])); 00302 } 00303 00304 inline int vtkBoundingBox::operator!=(const vtkBoundingBox &bbox)const 00305 { 00306 return !((*this) == bbox); 00307 } 00308 00309 inline void vtkBoundingBox::SetMinPoint(double p[3]) 00310 { 00311 this->SetMinPoint(p[0], p[1], p[2]); 00312 } 00313 00314 inline void vtkBoundingBox::SetMaxPoint(double p[3]) 00315 { 00316 this->SetMaxPoint(p[0], p[1], p[2]); 00317 } 00318 00319 inline void vtkBoundingBox::GetMinPoint(double &x, double &y, double &z) const 00320 { 00321 x = this->MinPnt[0]; 00322 y = this->MinPnt[1]; 00323 z = this->MinPnt[2]; 00324 } 00325 00326 inline void vtkBoundingBox::GetMaxPoint(double &x, double &y, double &z) const 00327 { 00328 x = this->MaxPnt[0]; 00329 y = this->MaxPnt[1]; 00330 z = this->MaxPnt[2]; 00331 } 00332 00333 inline int vtkBoundingBox::ContainsPoint(double px, double py, 00334 double pz) const 00335 { 00336 if ((px < this->MinPnt[0]) || (px > this->MaxPnt[0])) 00337 { 00338 return 0; 00339 } 00340 if ((py < this->MinPnt[1]) || (py > this->MaxPnt[1])) 00341 { 00342 return 0; 00343 } 00344 if ((pz < this->MinPnt[2]) || (pz > this->MaxPnt[2])) 00345 { 00346 return 0; 00347 } 00348 return 1; 00349 } 00350 00351 inline int vtkBoundingBox::ContainsPoint(double p[3]) const 00352 { 00353 return this->ContainsPoint(p[0], p[1], p[2]); 00354 } 00355 00356 #endif