OSG::BoxVolume Class Reference

#include <OSGBoxVolume.h>

Inheritance diagram for OSG::BoxVolume:

OSG::Volume List of all members.

Operators



const BoxVolumeoperator= (const BoxVolume &b1)
 Assignment operator.
OSG_BASE_DLLMAPPING bool operator== (const BoxVolume &b1, const BoxVolume &b2)
 Equality comparisons.

Public Member Functions

bool operator== (const Volume &other) const
bool operator!= (const Volume &other) const
Constructors


 BoxVolume (void)
 BoxVolume (Real xmin, Real ymin, Real zmin, Real xmax, Real ymax, Real zmax)
 BoxVolume (const Pnt3r &min, const Pnt3r &max)
 BoxVolume (const BoxVolume &obj)
Destructors


 ~BoxVolume ()
Get


const Pnt3rgetMin (void) const
const Pnt3rgetMax (void) const
virtual void getCenter (Pnt3r &center) const
 Returns the center of a box.
virtual Real getScalarVolume (void) const
 Gives the volume of the box (0 for an empty box).
virtual void getBounds (Pnt3r &min, Pnt3r &max) const
void getBounds (Real &xmin, Real &ymin, Real &zmin, Real &xmax, Real &ymax, Real &zmax) const
void getOrigin (Real &originX, Real &originY, Real &originZ) const
void getSize (Real &sizeX, Real &sizeY, Real &sizeZ) const
void getSize (Vec3r &vec) const
Set


void setBounds (Real w, Real h, Real d)
void setBounds (Real xmin, Real ymin, Real zmin, Real xmax, Real ymax, Real zmax)
void setBounds (const Pnt3r &min, const Pnt3r &max)
void setBoundsByCenterAndSize (const Pnt3r &center, const Vec3r &size)
 set method
Extend


virtual void extendBy (const Pnt3r &pt)
 Extends Box3f (if necessary) to contain given 3D point.
virtual void extendBy (const Volume &volume)
 Extends Box3f (if necessary) to contain given 3D point.
void extendBy (const BoxVolume &bb)
 Extends Box3f (if necessary) to contain given 3D point.
Intersect


virtual bool intersect (const Pnt3r &point) const
 Returns true if intersection of given point and Box3f is not empty.
virtual bool intersect (const Line &line) const
virtual bool intersect (const Line &line, Real &min, Real &max) const
virtual bool intersect (const Volume &volume) const
 Returns true if intersection of given point and Box3f is not empty.
bool intersect (const BoxVolume &bb) const
 Returns true if intersection of given point and Box3f is not empty.
virtual bool isOnSurface (const Pnt3r &point) const
 Returns true if intersection of given point and Box3f is not empty.
Transform


virtual void transform (const Matrixr &m)
 Transforms Box3f by matrix, enlarging Box3f to contain result.
Output


virtual void dump (UInt32 uiIndent=0, const BitVector bvFlags=0) const
 print the volume
State


void setValid (const bool value=true)
bool isValid (void) const
void setEmpty (const bool value=true)
bool isEmpty (void) const
void setStatic (const bool value=true)
bool isStatic (void) const
void setInfinite (const bool value=true)
bool isInfinite (void) const
bool isUntouchable (void) const
UInt16 getState (void) const
void setState (UInt16 state)

Protected Types

typedef Volume Inherited

Protected Attributes

UInt16 _state

Private Attributes

Pnt3r _min
Pnt3r _max

Detailed Description

3D box defined by min and max point.

Definition at line 53 of file OSGBoxVolume.h.


Member Typedef Documentation

typedef Volume OSG::BoxVolume::Inherited [protected]

Definition at line 190 of file OSGBoxVolume.h.


Constructor & Destructor Documentation

OSG::BoxVolume::BoxVolume ( void   )  [inline]

Definition at line 37 of file OSGBoxVolume.inl.

00037                          : 
00038      Inherited(             ),
00039     _min      (0.f, 0.f, 0.f), 
00040     _max      (0.f, 0.f, 0.f)
00041 {
00042 }

OSG::BoxVolume::BoxVolume ( Real  xmin,
Real  ymin,
Real  zmin,
Real  xmax,
Real  ymax,
Real  zmax 
) [inline]

Definition at line 46 of file OSGBoxVolume.inl.

References OSG::Volume::setEmpty().

00047                                                       :
00048      Inherited(                ), 
00049     _min      (xmin, ymin, zmin), 
00050     _max      (xmax, ymax, zmax)
00051 { 
00052     setEmpty(false);
00053 }

OSG::BoxVolume::BoxVolume ( const Pnt3r min,
const Pnt3r max 
) [inline]

Definition at line 57 of file OSGBoxVolume.inl.

References OSG::Volume::setEmpty().

00057                                                        :
00058      Inherited(   ), 
00059     _min      (min), 
00060     _max      (max)
00061 { 
00062     setEmpty(false); 
00063 }

OSG::BoxVolume::BoxVolume ( const BoxVolume obj  )  [inline]

Definition at line 67 of file OSGBoxVolume.inl.

00067                                          :
00068      Inherited(obj     ), 
00069     _min      (obj._min), 
00070     _max      (obj._max) 
00071 {
00072 }

OSG::BoxVolume::~BoxVolume (  )  [inline]

Definition at line 76 of file OSGBoxVolume.inl.

00077 {
00078 }


Member Function Documentation

const Pnt3r & OSG::BoxVolume::getMin ( void   )  const [inline]

Reimplemented from OSG::Volume.

Definition at line 82 of file OSGBoxVolume.inl.

References _min.

Referenced by OSG::ParticleBSPTree::doBuild(), OSG::extend(), and OSG::intersect().

00083 {
00084     return _min;
00085 }

const Pnt3r & OSG::BoxVolume::getMax ( void   )  const [inline]

Reimplemented from OSG::Volume.

Definition at line 89 of file OSGBoxVolume.inl.

References _max.

Referenced by OSG::ParticleBSPTree::doBuild(), OSG::extend(), and OSG::intersect().

00090 {
00091     return _max;
00092 }

void BoxVolume::getCenter ( Pnt3r center  )  const [virtual]

Implements OSG::Volume.

Definition at line 66 of file OSGBoxVolume.cpp.

References _max, _min, and OSG::Volume::isEmpty().

00067 {
00068     if(isEmpty() == true)
00069     {
00070         center.setValues(0.0f, 0.0f, 0.0f);
00071     }
00072     else
00073     {
00074         center = _min + (_max - _min) * .5f;
00075     }
00076 }

Real BoxVolume::getScalarVolume ( void   )  const [virtual]

Implements OSG::Volume.

Definition at line 80 of file OSGBoxVolume.cpp.

References _max, _min, and OSG::Volume::isEmpty().

00081 {
00082     return (isEmpty() == true) ? 0.0f : (_max[0] - _min[0]) *
00083                                         (_max[1] - _min[1]) *
00084                                         (_max[2] - _min[2]);
00085 }

void BoxVolume::getBounds ( Pnt3r min,
Pnt3r max 
) const [virtual]

Implements OSG::Volume.

Definition at line 88 of file OSGBoxVolume.cpp.

References _max, and _min.

Referenced by OSG::drawVolume(), OSG::extend(), OSG::intersect(), and OSG::Line::intersect().

00089 {
00090     min = _min;
00091     max = _max;
00092 }

void OSG::BoxVolume::getBounds ( Real xmin,
Real ymin,
Real zmin,
Real xmax,
Real ymax,
Real zmax 
) const [inline]

Definition at line 96 of file OSGBoxVolume.inl.

References _max, and _min.

00102 {
00103     _min.getSeparateValues(xmin, ymin, zmin);
00104     _max.getSeparateValues(xmax, ymax, zmax);
00105 }

void OSG::BoxVolume::getOrigin ( Real originX,
Real originY,
Real originZ 
) const [inline]

Definition at line 109 of file OSGBoxVolume.inl.

References _min.

00112 {
00113     originX = _min[0];
00114     originY = _min[1];
00115     originZ = _min[2];
00116 }

void OSG::BoxVolume::getSize ( Real sizeX,
Real sizeY,
Real sizeZ 
) const [inline]

Definition at line 120 of file OSGBoxVolume.inl.

References _max, and _min.

Referenced by OSG::SortLastWindow::splitDrawables().

00123 {
00124     sizeX = _max[0] - _min[0];
00125     sizeY = _max[1] - _min[1];
00126     sizeZ = _max[2] - _min[2];
00127 }

void OSG::BoxVolume::getSize ( Vec3r vec  )  const [inline]

Definition at line 131 of file OSGBoxVolume.inl.

References _max, and _min.

00132 {
00133     vec.setValues(_max[0] - _min[0], _max[1] - _min[1], _max[2] - _min[2]);
00134 }

void OSG::BoxVolume::setBounds ( Real  w,
Real  h,
Real  d 
) [inline]

Definition at line 138 of file OSGBoxVolume.inl.

References _max, _min, OSG::Volume::setEmpty(), OSG::Volume::setInfinite(), and OSG::Volume::setValid().

Referenced by OSG::extend(), and OSG::DynamicVolume::morphToType().

00139 {
00140     _min.setValues(-w / 2.0f, -h / 2.0f, -d / 2.0f);
00141     _max.setValues( w / 2.0f,  h / 2.0f,  d / 2.0f);
00142 
00143     Volume::setValid   (true );
00144     Volume::setEmpty   (false);
00145     Volume::setInfinite(false);
00146 }

void OSG::BoxVolume::setBounds ( Real  xmin,
Real  ymin,
Real  zmin,
Real  xmax,
Real  ymax,
Real  zmax 
) [inline]

Definition at line 150 of file OSGBoxVolume.inl.

References _max, _min, OSG::Volume::setEmpty(), OSG::Volume::setInfinite(), and OSG::Volume::setValid().

00156 {
00157     _min.setValues(xmin, ymin, zmin);
00158     _max.setValues(xmax, ymax, zmax);
00159 
00160     Volume::setValid   (true );
00161     Volume::setEmpty   (false);
00162     Volume::setInfinite(false);
00163 }

void OSG::BoxVolume::setBounds ( const Pnt3r min,
const Pnt3r max 
) [inline]

Definition at line 167 of file OSGBoxVolume.inl.

References _max, _min, OSG::Volume::setEmpty(), OSG::Volume::setInfinite(), and OSG::Volume::setValid().

00168 {
00169     _min = min; 
00170     _max = max;
00171 
00172     Volume::setValid   (true );
00173     Volume::setEmpty   (false);
00174     Volume::setInfinite(false);
00175 }

void BoxVolume::setBoundsByCenterAndSize ( const Pnt3r center,
const Vec3r size 
)

Definition at line 96 of file OSGBoxVolume.cpp.

References _max, _min, OSG::Volume::setEmpty(), OSG::Volume::setInfinite(), OSG::Volume::setValid(), and size.

00098 {
00099     _min.setValues(center.x() - size.x() / 2.0f,
00100                    center.y() - size.y() / 2.0f,
00101                    center.z() - size.z() / 2.0f);
00102     _max.setValues(center.x() + size.x() / 2.0f,
00103                    center.y() + size.y() / 2.0f,
00104                    center.z() + size.z() / 2.0f);
00105 
00106     Volume::setValid   (true);
00107     Volume::setEmpty   (size.isZero());
00108     Volume::setInfinite(false);
00109 }

void BoxVolume::extendBy ( const Pnt3r pt  )  [virtual]

Implements OSG::Volume.

Definition at line 116 of file OSGBoxVolume.cpp.

References _max, _min, OSG::Volume::isEmpty(), OSG::Volume::isUntouchable(), and OSG::Volume::setEmpty().

Referenced by OSG::ParticleBSPTree::doBuild(), and OSG::SortLastWindow::splitDrawables().

00117 {
00118     if(isUntouchable() == true)
00119         return;
00120 
00121     if(isEmpty() == true)
00122     {
00123         _min[0] = _max[0] = pt[0];
00124         _min[1] = _max[1] = pt[1];
00125         _min[2] = _max[2] = pt[2];
00126 
00127         setEmpty(false);
00128 
00129         return;
00130     }
00131 
00132     if(pt[0] < _min[0])
00133     {
00134         _min[0] = pt[0];
00135     }
00136     else
00137     {
00138         if(pt[0] > _max[0])
00139             _max[0] = pt[0];
00140     }
00141 
00142     if(pt[1] < _min[1])
00143     {
00144         _min[1] = pt[1];
00145     }
00146     else
00147     {
00148         if(pt[1] > _max[1])
00149             _max[1] = pt[1];
00150     }
00151 
00152     if(pt[2] < _min[2])
00153     {
00154         _min[2] = pt[2];
00155     }
00156     else
00157     {
00158         if(pt[2] > _max[2])
00159             _max[2] = pt[2];
00160     }
00161 }

void BoxVolume::extendBy ( const Volume volume  )  [virtual]

Implements OSG::Volume.

Definition at line 164 of file OSGBoxVolume.cpp.

References OSG::extend().

00165 {
00166     OSG::extend(*this,volume);
00167 }

void OSG::BoxVolume::extendBy ( const BoxVolume bb  )  [inline]

Definition at line 179 of file OSGBoxVolume.inl.

References OSG::extend().

00180 {
00181     OSG::extend(*this, volume);
00182 }

bool BoxVolume::intersect ( const Pnt3r point  )  const [virtual]

Implements OSG::Volume.

Definition at line 173 of file OSGBoxVolume.cpp.

References _max, _min, and OSG::Volume::isEmpty().

00174 {
00175     return 
00176         (!isEmpty()      &&
00177         (_min[0] < pt[0] && _max[0] > pt[0]) &&
00178         (_min[1] < pt[1] && _max[1] > pt[1]) &&
00179         (_min[2] < pt[2] && _max[2] > pt[2]));
00180 }

bool BoxVolume::intersect ( const Line line  )  const [virtual]

intersect the box with the given Line

Implements OSG::Volume.

Definition at line 184 of file OSGBoxVolume.cpp.

References OSG::Line::intersect().

00185 {
00186     Real enter;
00187     Real exit;
00188 
00189     return line.intersect(*this, enter, exit);
00190 }

bool BoxVolume::intersect ( const Line line,
Real min,
Real max 
) const [virtual]

intersect the box with the given Line

Implements OSG::Volume.

Definition at line 196 of file OSGBoxVolume.cpp.

References OSG::Line::intersect().

00199 {
00200     return line.intersect(*this, min, max);
00201 }

bool BoxVolume::intersect ( const Volume volume  )  const [virtual]

Implements OSG::Volume.

Definition at line 204 of file OSGBoxVolume.cpp.

References OSG::intersect().

00205 {
00206     return OSG::intersect(*this, volume);
00207 }

bool BoxVolume::intersect ( const BoxVolume bb  )  const

Definition at line 210 of file OSGBoxVolume.cpp.

References OSG::intersect().

00211 {
00212     return OSG::intersect(*this, volume);
00213 }

bool BoxVolume::isOnSurface ( const Pnt3r point  )  const [virtual]

Implements OSG::Volume.

Definition at line 216 of file OSGBoxVolume.cpp.

References _max, _min, OSG::Eps, and OSG::osgAbs().

00217 {
00218     if(((osgAbs(point[0] - _min[0]) < Eps           ||
00219          osgAbs(point[0] - _max[0]) < Eps             ) &&
00220         (point[1] >= _min[1] && point[1] <= _max[1] &&
00221          point[2] >= _min[2] && point[2] <= _max[2]   )   ) ||
00222 
00223        ((osgAbs(point[1] - _min[1]) < Eps           ||
00224          osgAbs(point[1] - _max[1]) < Eps             ) &&
00225         (point[0] >= _min[0] && point[0] <= _max[1] &&
00226          point[2] >= _min[2] && point[2] <= _max[2]   )   ) ||
00227 
00228        ((osgAbs(point[2] - _min[2]) < Eps           ||
00229          osgAbs(point[2] - _max[2]) < Eps             ) &&
00230         (point[1] >= _min[1] && point[1] <= _max[1] &&
00231          point[0] >= _min[0] && point[0] <= _max[0]   )   )   )
00232     {
00233         return true;
00234     }
00235     else
00236     {
00237         return false;
00238     }
00239 }

void BoxVolume::transform ( const Matrixr m  )  [virtual]

Implements OSG::Volume.

Definition at line 244 of file OSGBoxVolume.cpp.

References _max, _min, and OSG::Volume::isEmpty().

00245 {
00246     Real xmin;
00247     Real ymin;
00248     Real zmin;
00249     Real xmax;
00250     Real ymax;
00251     Real zmax;
00252     Real a;
00253     Real b;
00254 
00255     if(isEmpty() == true)
00256         return;
00257 
00258     xmin = xmax = m[3][0];
00259     ymin = ymax = m[3][1];
00260     zmin = zmax = m[3][2];
00261 
00262     //
00263     // calculate xmin and xmax of new tranformed BBox
00264     //
00265 
00266     a = _max[0] * m[0][0];
00267     b = _min[0] * m[0][0];
00268 
00269     if(a >= b)
00270     {
00271         xmax += a;
00272         xmin += b;
00273     }
00274     else
00275     {
00276         xmax += b;
00277         xmin += a;
00278     }
00279 
00280     a = _max[1] * m[1][0];
00281     b = _min[1] * m[1][0];
00282 
00283     if(a >= b) 
00284     {
00285         xmax += a;
00286         xmin += b;
00287     }
00288     else
00289     {
00290         xmax += b;
00291         xmin += a;
00292     }
00293     
00294     a = _max[2] * m[2][0];
00295     b = _min[2] * m[2][0];
00296 
00297     if(a >= b)
00298     {
00299         xmax += a;
00300         xmin += b;
00301     }
00302     else
00303     {
00304         xmax += b;
00305         xmin += a;
00306     }
00307 
00308     //
00309     // calculate ymin and ymax of new tranformed BBox
00310     //
00311 
00312     a = _max[0] * m[0][1];
00313     b = _min[0] * m[0][1];
00314 
00315     if(a >= b)
00316     {
00317         ymax += a;
00318         ymin += b;
00319     }
00320     else
00321     {
00322         ymax += b;
00323         ymin += a;
00324     }
00325 
00326     a = _max[1] * m[1][1];
00327     b = _min[1] * m[1][1];
00328 
00329     if(a >= b)
00330     {
00331         ymax += a;
00332         ymin += b;
00333     }
00334     else
00335     {
00336         ymax += b;
00337         ymin += a;
00338     }
00339 
00340     a = _max[2] * m[2][1];
00341     b = _min[2] * m[2][1];
00342 
00343     if(a >= b)
00344     {
00345         ymax += a;
00346         ymin += b;
00347     }
00348     else
00349     {
00350         ymax += b;
00351         ymin += a;
00352     }
00353 
00354     //
00355     // calculate zmin and zmax of new tranformed BBox
00356     //
00357 
00358     a = _max[0] * m[0][2];
00359     b = _min[0] * m[0][2];
00360 
00361     if(a >= b) 
00362     {
00363         zmax += a;
00364         zmin += b;
00365     }
00366     else
00367     {
00368         zmax += b;
00369         zmin += a;
00370     }
00371 
00372     a = _max[1] * m[1][2];
00373     b = _min[1] * m[1][2];
00374 
00375     if(a >= b)
00376     {
00377         zmax += a;
00378         zmin += b;
00379     }
00380     else
00381     {
00382         zmax += b;
00383         zmin += a;
00384     }
00385 
00386     a = _max[2] * m[2][2];
00387     b = _min[2] * m[2][2];
00388 
00389     if(a >= b)
00390     {
00391         zmax += a;
00392         zmin += b;
00393     }
00394     else
00395     {
00396         zmax += b;
00397         zmin += a;
00398     }
00399 
00400     _min.setValues(xmin, ymin, zmin);
00401     _max.setValues(xmax, ymax, zmax);
00402 }

const BoxVolume & BoxVolume::operator= ( const BoxVolume b1  ) 

Definition at line 406 of file OSGBoxVolume.cpp.

References _max, _min, and OSG::Volume::_state.

00407 {
00408     if(&b1 == this)
00409         return *this;
00410 
00411     _min   = b1._min;
00412     _max   = b1._max;
00413     _state = b1._state;
00414 
00415     return *this;
00416 }

void BoxVolume::dump ( UInt32  uiIndent = 0,
const BitVector  bvFlags = 0 
) const [virtual]

Implements OSG::Volume.

Definition at line 420 of file OSGBoxVolume.cpp.

References _max, _min, and PLOG.

00422 {
00423     PLOG << "Box(" << _min << "|" << _max << ")";
00424 }

void OSG::Volume::setValid ( const bool  value = true  )  [inline, inherited]

bool OSG::Volume::isValid ( void   )  const [inline, inherited]

Checks if the volume is valid

Definition at line 87 of file OSGVolume.inl.

References OSG::Volume::_state, and OSG::Volume::OSGVALID.

Referenced by OSG::extend(), OSG::Group::intersect(), OSG::Geometry::intersect(), and OSG::Node::invalidateVolume().

00088 {
00089     return (_state & OSGVALID) ? true : false;
00090 }

void OSG::Volume::setEmpty ( const bool  value = true  )  [inline, inherited]

bool OSG::Volume::isEmpty ( void   )  const [inline, inherited]

void OSG::Volume::setStatic ( const bool  value = true  )  [inline, inherited]

set the volume to be static

Definition at line 54 of file OSGVolume.inl.

References OSG::Volume::_state, and OSG::Volume::OSGSTATIC.

00055 {
00056     if(value == true)
00057         _state |= OSGSTATIC;
00058     else
00059         _state &= ~OSGSTATIC;
00060 }

bool OSG::Volume::isStatic ( void   )  const [inline, inherited]

Checks if the volume is static

Definition at line 65 of file OSGVolume.inl.

References OSG::Volume::_state, and OSG::Volume::OSGSTATIC.

Referenced by OSG::extend(), OSG::Node::invalidateVolume(), and OSG::Volume::setValid().

00066 {
00067     return (_state & OSGSTATIC) ? true : false;
00068 }

void OSG::Volume::setInfinite ( const bool  value = true  )  [inline, inherited]

set the volume to be infinite

Definition at line 120 of file OSGVolume.inl.

References OSG::Volume::_state, OSG::Volume::OSGEMPTY, OSG::Volume::OSGINFINITE, and OSG::Volume::OSGVALID.

Referenced by OSG::extend(), setBounds(), and setBoundsByCenterAndSize().

00121 {
00122     if(value == true)
00123     {
00124         _state |=  OSGINFINITE;
00125         _state |=  OSGVALID;
00126         _state &= ~OSGEMPTY;
00127     }
00128     else
00129     {
00130         _state &= ~OSGINFINITE;
00131     }
00132 }

bool OSG::Volume::isInfinite ( void   )  const [inline, inherited]

Checks if the volume is infinite

Definition at line 137 of file OSGVolume.inl.

References OSG::Volume::_state, and OSG::Volume::OSGINFINITE.

Referenced by OSG::extend(), and OSG::intersect().

00138 {
00139     return (_state & OSGINFINITE) ? true : false;
00140 }

bool OSG::Volume::isUntouchable ( void   )  const [inline, inherited]

Checks if the volume is untouchable, i.e. it's values should not be changed. Mainly used internally to speed up early outs in extendBy().

Definition at line 148 of file OSGVolume.inl.

References OSG::Volume::_state, OSG::Volume::OSGINFINITE, OSG::Volume::OSGSTATIC, and OSG::Volume::OSGVALID.

Referenced by OSG::SphereVolume::extendBy(), and extendBy().

00149 {
00150     return (_state & (OSGINFINITE | OSGVALID |