osg::SphereVolume Class Reference
[Volume]

#include <OSGSphereVolume.h>

Inheritance diagram for osg::SphereVolume:
osg::Volume

List of all members.

Public Member Functions

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



 SphereVolume (void)
 SphereVolume (const SphereVolume &obj)
 SphereVolume (const Pnt3f &c, Real32 r)
Destructor



 ~SphereVolume (void)
Set Values



void setValue (const Pnt3f &c, Real32 r)
void setCenter (const Pnt3f &c)
void setRadius (Real32 r)
Get Values



const Pnt3fgetCenter (void) const
Real32 getRadius (void) const
virtual void getCenter (Pnt3f &center) const
virtual Real32 getScalarVolume (void) const
virtual void getBounds (Pnt3f &min, Pnt3f &max) const
Extending



virtual void extendBy (const Pnt3f &pt)
virtual void extendBy (const Volume &volume)
void extendBy (const SphereVolume &bb)
Intersection



virtual bool intersect (const Pnt3f &point) const
virtual bool intersect (const Line &line) const
virtual bool intersect (const Line &line, Real32 &enter, Real32 &exit) const
virtual bool intersect (const Volume &volume) const
bool intersect (const SphereVolume &sphere) const
virtual bool isOnSurface (const Pnt3f &point) const
Transformation



virtual void transform (const Matrix &mat)
Output



virtual void dump (UInt32 uiIndent=0, const BitVector bvFlags=0) const
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)
Get Values



Pnt3f getMin (void) const
Pnt3f getMax (void) const

Protected Attributes

UInt16 _state

Private Attributes

Pnt3f _center
Real32 _radius

Operators



SphereVolumeoperator= (const SphereVolume &source)
bool operator== (const SphereVolume &lhs, const SphereVolume &rhs)

Detailed Description

Sphere in 3D space defined by center and radius.

Definition at line 53 of file OSGSphereVolume.h.


Constructor & Destructor Documentation

osg::SphereVolume::SphereVolume ( void   )  [inline]

Definition at line 50 of file OSGSphereVolume.inl.

00050                                : 
00051      Volume(             ),
00052     _center(0.f, 0.f, 0.f),
00053     _radius(0            ) 
00054 {
00055 }

osg::SphereVolume::SphereVolume ( const SphereVolume obj  )  [inline]

Definition at line 58 of file OSGSphereVolume.inl.

References osg::Volume::setEmpty().

00058                                                   :
00059      Volume(           ),    
00060     _center(obj._center), 
00061     _radius(obj._radius) 
00062 {
00063     setEmpty(false);
00064 }

osg::SphereVolume::SphereVolume ( const Pnt3f c,
Real32  r 
) [inline]

Definition at line 67 of file OSGSphereVolume.inl.

References osg::Volume::setEmpty().

00067                                                    :
00068      Volume( ), 
00069     _center(c), 
00070     _radius(r)
00071 {
00072     setEmpty(false);
00073 }

osg::SphereVolume::~SphereVolume ( void   )  [inline]

Definition at line 76 of file OSGSphereVolume.inl.

00077 {
00078 }


Member Function Documentation

SphereVolume & SphereVolume::operator= ( const SphereVolume source  ) 

Definition at line 74 of file OSGSphereVolume.cpp.

References _center, and _radius.

00075 {
00076     if(this == &source)
00077         return *this;
00078 
00079     _center = source._center;
00080     _radius = source._radius;
00081     
00082     return *this;
00083 }

void osg::SphereVolume::setValue ( const Pnt3f c,
Real32  r 
) [inline]

Change the center and radius

Definition at line 85 of file OSGSphereVolume.inl.

References _center, _radius, and osg::Volume::setEmpty().

Referenced by osg::DynamicVolume::morphToType().

00086 {
00087     setEmpty(false);
00088 
00089     _center = c;
00090     _radius = r;
00091 }

void osg::SphereVolume::setCenter ( const Pnt3f c  )  [inline]

set just the center

Definition at line 97 of file OSGSphereVolume.inl.

References _center.

Referenced by osg::FieldDataTraits< DynamicVolume >::copyFromBin(), and osg::FieldDataTraits< DynamicVolume >::getFromString().

00098 {
00099     _center = c;
00100 }

void osg::SphereVolume::setRadius ( Real32  r  )  [inline]

set just the radius

Definition at line 105 of file OSGSphereVolume.inl.

References _radius.

Referenced by osg::FieldDataTraits< DynamicVolume >::copyFromBin(), and osg::FieldDataTraits< DynamicVolume >::getFromString().

00106 {
00107     _radius = r;
00108 }

const Pnt3f & osg::SphereVolume::getCenter ( void   )  const [inline]

Returns the center

Definition at line 115 of file OSGSphereVolume.inl.

References _center.

Referenced by osg::FieldDataTraits< DynamicVolume >::copyToBin(), osg::Line::intersect(), and osg::FieldDataTraits< DynamicVolume >::putToString().

00116 {
00117     return _center;
00118 }

Real32 osg::SphereVolume::getRadius ( void   )  const [inline]

Returns the radius

Definition at line 123 of file OSGSphereVolume.inl.

References _radius.

Referenced by osg::FieldDataTraits< DynamicVolume >::copyToBin(), osg::Line::intersect(), and osg::FieldDataTraits< DynamicVolume >::putToString().

00124 {
00125     return _radius;
00126 }

void SphereVolume::getCenter ( Pnt3f center  )  const [virtual]

Returns the center

Implements osg::Volume.

Definition at line 87 of file OSGSphereVolume.cpp.

References _center.

00088 {
00089     center = _center;
00090 }

Real32 SphereVolume::getScalarVolume ( void   )  const [virtual]

Returns the center

Implements osg::Volume.

Definition at line 93 of file OSGSphereVolume.cpp.

References _radius, osg::Volume::isEmpty(), and osg::Pi.

00094 {
00095     return isEmpty() ? 0.0f : (4.f / 3.f * Pi * _radius * _radius * _radius);
00096 }

void SphereVolume::getBounds ( Pnt3f min,
Pnt3f max 
) const [virtual]

Returns the center

Implements osg::Volume.

Definition at line 99 of file OSGSphereVolume.cpp.

References _center, and _radius.

00100 {
00101     min.setValues(_center[0] - _radius,
00102                   _center[1] - _radius,
00103                   _center[2] - _radius);
00104     max.setValues(_center[0] + _radius,
00105                   _center[1] + _radius,
00106                   _center[2] + _radius);
00107 }

void SphereVolume::extendBy ( const Pnt3f pt  )  [virtual]

Implements osg::Volume.

Definition at line 110 of file OSGSphereVolume.cpp.

References _center, _radius, osg::Volume::isEmpty(), osg::Volume::isUntouchable(), and osg::Volume::setEmpty().

00111 {
00112     if(isUntouchable() == true)
00113         return;
00114     
00115     if(isEmpty() == true)
00116     {
00117         _center = pt;
00118         _radius = 0.f;
00119         
00120         setEmpty(false);
00121     }
00122     else
00123     {
00124         Real32 d = (_center - pt).length();
00125         
00126         if(d > _radius)
00127             _radius = d;
00128     }
00129 }

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

Definition at line 132 of file OSGSphereVolume.cpp.

References osg::extend().

00133 {
00134     OSG::extend(*this, volume);
00135 }

void osg::SphereVolume::extendBy ( const SphereVolume bb  )  [inline, virtual]

Implements osg::Volume.

Definition at line 131 of file OSGSphereVolume.inl.

References osg::extend().

00132 {
00133     OSG::extend(*this, volume);
00134 }

bool SphereVolume::intersect ( const Pnt3f point  )  const [virtual]

Returns true if intersection of given point and Volume is not empty

Implements osg::Volume.

Definition at line 141 of file OSGSphereVolume.cpp.

References _center, and _radius.

Referenced by intersect().

00142 {
00143     Real32 d = (_center - point).length();
00144 
00145     if(d <= _radius)
00146         return true;
00147     else
00148         return false;
00149 }

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

intersect the SphereVolume with the given Line

Implements osg::Volume.

Definition at line 153 of file OSGSphereVolume.cpp.

References osg::Line::intersect().

00154 {
00155     return line.intersect(*this);
00156 }

bool SphereVolume::intersect ( const Line line,
Real32 enter,
Real32 exit 
) const [virtual]

intersect the SphereVolume with the given Line

Implements osg::Volume.

Definition at line 160 of file OSGSphereVolume.cpp.

References osg::Line::intersect().

00163 {
00164     return line.intersect(*this, enter, exit);
00165 }

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

Returns true if intersection of given point and Volume is not empty

Definition at line 168 of file OSGSphereVolume.cpp.

References intersect().

00169 {
00170     return OSG::intersect(*this, volume);
00171 }

bool osg::SphereVolume::intersect ( const SphereVolume sphere  )  const [inline, virtual]

Returns true if intersection of given point and Volume is not empty

Implements osg::Volume.

Definition at line 139 of file OSGSphereVolume.inl.

References intersect().

00140 {
00141     return OSG::intersect(*this, volume);
00142 }

bool SphereVolume::isOnSurface ( const Pnt3f point  )  const [virtual]

Returns true if intersection of given point and Volume is not empty

Implements osg::Volume.

Definition at line 174 of file OSGSphereVolume.cpp.

References _center, _radius, osg::Eps, and osg::osgabs().

00175 {
00176     if(osgabs((point - _center).length() - _radius) < Eps)
00177         return true;
00178     else
00179         return false;
00180 }

void SphereVolume::transform ( const Matrix mat  )  [virtual]

Implements osg::Volume.

Definition at line 189 of file OSGSphereVolume.cpp.

References _center, _radius, and osg::TransformationMatrix< ValueTypeT >::mult().

00190 {
00191     // assume uniform scaling, otherways we get an ellipsoid
00192     Pnt3f hull(_center);
00193     hull += Vec3f(0, _radius, 0);
00194 
00195     mat.mult(_center, _center);
00196     mat.mult(hull,    hull   );
00197     _radius = (hull - _center).length();
00198 
00199 /*
00200     Vec3f translation, scaleFactor;
00201     Quaternion rotation, scaleOrientation;
00202     
00203     mat.mult(_center);
00204     mat.getTransform(translation, rotation, scaleFactor, scaleOrientation);
00205     _radius *= scaleFactor[0];
00206 */
00207 }

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

print the volume

Implements osg::Volume.

Definition at line 214 of file OSGSphereVolume.cpp.

References _center, _radius, and PLOG.

00216 {
00217     PLOG << "Sphere(" << _center << "|" << _radius << ")";
00218 }

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 96 of file OSGVolume.inl.

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

Referenced by osg::Group::intersect(), osg::Geometry::intersect(), osg::DVRVolume::intersect(), and osg::Node::invalidateVolume().

00097 {
00098     return (_state & OSGVALID) ? true : false;
00099 }

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

Reimplemented in osg::DynamicVolume.

Definition at line 63 of file OSGVolume.inl.

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

00064 {
00065     if(value == true)
00066         _state |= OSGSTATIC;
00067     else
00068         _state &= ~OSGSTATIC;
00069 }

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

Checks if the volume is static

Definition at line 74 of file OSGVolume.inl.

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

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

00075 {
00076     return (_state & OSGSTATIC) ? true : false;
00077 }

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

set the volume to be infinite

Reimplemented in osg::DynamicVolume.

Definition at line 129 of file OSGVolume.inl.

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

Referenced by osg::BoxVolume::setBounds(), and osg::BoxVolume::setBoundsByCenterAndSize().

00130 {
00131     if(value == true)
00132     {
00133         _state |=  OSGINFINITE;
00134         _state |=  OSGVALID;
00135         _state &= ~OSGEMPTY;
00136     }
00137     else
00138     {
00139         _state &= ~OSGINFINITE;
00140     }
00141 }

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

Checks if the volume is infinite

Definition at line 146 of file OSGVolume.inl.

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

00147 {
00148     return (_state & OSGINFINITE) ? true : false;
00149 }

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 157 of file OSGVolume.inl.

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

Referenced by extendBy(), and osg::BoxVolume::extendBy().

00158 {
00159     return (_state & (OSGINFINITE | OSGVALID | OSGSTATIC)) != OSGVALID;
00160 }

UInt16 osg::Volume::getState ( void   )  const [inline, inherited]

get the volume's state

Definition at line 166 of file OSGVolume.inl.

References osg::Volume::_state.

Referenced by osg::FieldDataTraits< BoxVolume >::copyToBin(), osg::FieldDataTraits< DynamicVolume >::copyToBin(), and osg::DynamicVolume::instanceChanged().

00167 {
00168     return _state;
00169 }

void osg::Volume::setState ( UInt16  val  )  [inline, inherited]
Pnt3f osg::Volume::getMin ( void   )  const [inline, inherited]

Return the lowest point of the volume. Just a convience wrapper for getBounds()

Reimplemented in osg::BoxVolume.

Definition at line 184 of file OSGVolume.inl.

References osg::Volume::getBounds().

00185 {
00186     Pnt3f pmin; 
00187     Pnt3f pmax;
00188 
00189     getBounds(pmin, pmax);
00190 
00191     return pmin;
00192 }

Pnt3f osg::Volume::getMax ( void   )  const [inline, inherited]

Return the highest point of the volume. Just a convience wrapper for getBounds()

Reimplemented in osg::BoxVolume.

Definition at line 199 of file OSGVolume.inl.

References osg::Volume::getBounds().

00200 {
00201     Pnt3f pmin;
00202     Pnt3f pmax;
00203 
00204     getBounds(pmin, pmax);
00205 
00206     return pmax;
00207 }

bool Volume::operator== ( const Volume other  )  const [inherited]

Definition at line 53 of file OSGVolume.cpp.

References osg::Volume::_state.

00054 {
00055     return _state == other._state;
00056 }

bool Volume::operator!= ( const Volume other  )  const [inherited]

Definition at line 58 of file OSGVolume.cpp.

00059 {
00060     return !(*this == other);
00061 }


Friends And Related Function Documentation

bool operator== ( const SphereVolume lhs,
const SphereVolume rhs 
) [friend]

Member Data Documentation

UInt16 osg::Volume::_state [protected, inherited]

The documentation for this class was generated from the following files:

Generated on 8 Feb 2010 for OpenSG by  doxygen 1.6.1