• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

dox/Common/vtkBoundingBox.h

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

Generated by  doxygen 1.7.1