00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00026 #ifndef __vtkBoundingBox_h
00027 #define __vtkBoundingBox_h
00028 #include "vtkSystemIncludes.h"
00029
00030 class VTK_COMMON_EXPORT vtkBoundingBox
00031 {
00032 public:
00035 vtkBoundingBox();
00036
00038 vtkBoundingBox(const vtkBoundingBox &bbox);
00039
00041 vtkBoundingBox &operator=(const vtkBoundingBox &bbox);
00042
00044
00045 int operator==(const vtkBoundingBox &bbox)const;
00046 int operator!=(const vtkBoundingBox &bbox)const;
00048
00050
00052 void SetBounds(double bounds[6]);
00053 void SetBounds(double xMin, double xMax,
00054 double yMin, double yMax,
00055 double zMin, double zMax);
00057
00059
00061 void SetMinPoint(double x, double y, double z);
00062 void SetMinPoint(double p[3]);
00064
00066
00068 void SetMaxPoint(double x, double y, double z);
00069 void SetMaxPoint(double p[3]);
00071
00073
00075 void AddPoint(double p[3]);
00076 void AddPoint(double px, double py, double pz);
00078
00080 void AddBox(const vtkBoundingBox &bbox);
00081
00084 void AddBounds(double bounds[6]);
00085
00086
00087
00088
00089
00090 int IntersectBox(const vtkBoundingBox &bbox);
00091
00093 int Intersects(const vtkBoundingBox &bbox) const;
00094
00096
00097 void GetBounds(double bounds[6]) const;
00098 void GetBounds(double &xMin, double &xMax,
00099 double &yMin, double &yMax,
00100 double &zMin, double &zMax) const;
00102
00104 double GetBound(int i) const;
00105
00107
00108 const double *GetMinPoint() const;
00109 void GetMinPoint(double &x, double &y, double &z) const;
00111
00113
00114 const double *GetMaxPoint() const;
00115 void GetMaxPoint(double &x, double &y, double &z) const;
00117
00119
00120 int ContainsPoint(double p[3]) const;
00121 int ContainsPoint(double px, double py, double pz) const;
00123
00125 void GetCenter(double center[3]) const;
00126
00128 void GetLengths(double lengths[3]) const;
00129
00131 double GetLength(int i) const;
00132
00134 double GetMaxLength() const;
00135
00138 int IsValid() const;
00139
00141 void Reset();
00142 protected:
00143 double MinPnt[3], MaxPnt[3];
00144 };
00145
00146 inline void vtkBoundingBox::Reset()
00147 {
00148 this->MinPnt[0] = this->MinPnt[1] = this->MinPnt[2] = VTK_DOUBLE_MAX;
00149 this->MaxPnt[0] = this->MaxPnt[1] = this->MaxPnt[2] = VTK_DOUBLE_MIN;
00150 }
00151
00152 inline vtkBoundingBox::vtkBoundingBox()
00153 {
00154 this->Reset();
00155 }
00156
00157 inline void vtkBoundingBox::GetBounds(double &xMin, double &xMax,
00158 double &yMin, double &yMax,
00159 double &zMin, double &zMax) const
00160 {
00161 xMin = this->MinPnt[0];
00162 xMax = this->MaxPnt[0];
00163 yMin = this->MinPnt[1];
00164 yMax = this->MaxPnt[1];
00165 zMin = this->MinPnt[2];
00166 zMax = this->MaxPnt[2];
00167 }
00168
00169 inline double vtkBoundingBox::GetBound(int i) const
00170 {
00171
00172
00173
00174 return ((i | 0x1) ? this->MaxPnt[i>>1] : this->MinPnt[i>>1]);
00175 }
00176
00177 inline const double *vtkBoundingBox::GetMinPoint() const
00178 {
00179 return this->MinPnt;
00180 }
00181
00182 inline const double *vtkBoundingBox::GetMaxPoint() const
00183 {
00184 return this->MaxPnt;
00185 }
00186
00187 inline int vtkBoundingBox::IsValid() const
00188 {
00189 return ((this->MinPnt[0] <= this->MaxPnt[0]) &&
00190 (this->MinPnt[1] <= this->MaxPnt[1]) &&
00191 (this->MinPnt[2] <= this->MaxPnt[2]));
00192 }
00193
00194 inline double vtkBoundingBox::GetLength(int i) const
00195 {
00196 return this->MaxPnt[i] - this->MinPnt[i];
00197 }
00198
00199 inline void vtkBoundingBox::GetLengths(double lengths[3]) const
00200 {
00201 lengths[0] = this->GetLength(0);
00202 lengths[1] = this->GetLength(1);
00203 lengths[2] = this->GetLength(2);
00204 }
00205
00206 inline void vtkBoundingBox::GetCenter(double center[3]) const
00207 {
00208 center[0] = 0.5 * (this->MaxPnt[0] + this->MinPnt[0]);
00209 center[1] = 0.5 * (this->MaxPnt[1] + this->MinPnt[1]);
00210 center[2] = 0.5 * (this->MaxPnt[2] + this->MinPnt[2]);
00211 }
00212
00213 inline void vtkBoundingBox::SetBounds(double bounds[6])
00214 {
00215 this->SetBounds(bounds[0], bounds[1], bounds[2],
00216 bounds[3], bounds[4], bounds[5]);
00217 }
00218
00219 inline void vtkBoundingBox::GetBounds(double bounds[6]) const
00220 {
00221 this->GetBounds(bounds[0], bounds[1], bounds[2],
00222 bounds[3], bounds[4], bounds[5]);
00223 }
00224
00225 inline vtkBoundingBox::vtkBoundingBox(const vtkBoundingBox &bbox)
00226 {
00227 this->MinPnt[0] = bbox.MinPnt[0];
00228 this->MinPnt[1] = bbox.MinPnt[1];
00229 this->MinPnt[2] = bbox.MinPnt[2];
00230
00231 this->MaxPnt[0] = bbox.MaxPnt[0];
00232 this->MaxPnt[1] = bbox.MaxPnt[1];
00233 this->MaxPnt[2] = bbox.MaxPnt[2];
00234 }
00235
00236 inline vtkBoundingBox &vtkBoundingBox::operator=(const vtkBoundingBox &bbox)
00237 {
00238 this->MinPnt[0] = bbox.MinPnt[0];
00239 this->MinPnt[1] = bbox.MinPnt[1];
00240 this->MinPnt[2] = bbox.MinPnt[2];
00241
00242 this->MaxPnt[0] = bbox.MaxPnt[0];
00243 this->MaxPnt[1] = bbox.MaxPnt[1];
00244 this->MaxPnt[2] = bbox.MaxPnt[2];
00245 return *this;
00246 }
00247
00248 inline int vtkBoundingBox::operator==(const vtkBoundingBox &bbox)const
00249 {
00250 return ((this->MinPnt[0] == bbox.MinPnt[0]) &&
00251 (this->MinPnt[1] == bbox.MinPnt[1]) &&
00252 (this->MinPnt[2] == bbox.MinPnt[2]) &&
00253 (this->MaxPnt[0] == bbox.MaxPnt[0]) &&
00254 (this->MaxPnt[1] == bbox.MaxPnt[1]) &&
00255 (this->MaxPnt[2] == bbox.MaxPnt[2]));
00256 }
00257
00258 inline int vtkBoundingBox::operator!=(const vtkBoundingBox &bbox)const
00259 {
00260 return !((*this) == bbox);
00261 }
00262
00263 inline void vtkBoundingBox::SetMinPoint(double p[3])
00264 {
00265 this->SetMinPoint(p[0], p[1], p[2]);
00266 }
00267
00268 inline void vtkBoundingBox::SetMaxPoint(double p[3])
00269 {
00270 this->SetMaxPoint(p[0], p[1], p[2]);
00271 }
00272
00273 inline void vtkBoundingBox::GetMinPoint(double &x, double &y, double &z) const
00274 {
00275 x = this->MinPnt[0];
00276 y = this->MinPnt[1];
00277 z = this->MinPnt[2];
00278 }
00279
00280 inline void vtkBoundingBox::GetMaxPoint(double &x, double &y, double &z) const
00281 {
00282 x = this->MaxPnt[0];
00283 y = this->MaxPnt[1];
00284 z = this->MaxPnt[2];
00285 }
00286
00287 inline int vtkBoundingBox::ContainsPoint(double px, double py,
00288 double pz) const
00289 {
00290 if ((px < this->MinPnt[0]) || (px > this->MaxPnt[0]))
00291 {
00292 return 0;
00293 }
00294 if ((py < this->MinPnt[1]) || (py > this->MaxPnt[1]))
00295 {
00296 return 0;
00297 }
00298 if ((pz < this->MinPnt[2]) || (pz > this->MaxPnt[2]))
00299 {
00300 return 0;
00301 }
00302 return 1;
00303 }
00304
00305 inline int vtkBoundingBox::ContainsPoint(double p[3]) const
00306 {
00307 return this->ContainsPoint(p[0], p[1], p[2]);
00308 }
00309
00310 #endif