mudbox::AxisAlignedBoundingBox Class Reference

#include <math.h>

List of all members.


Detailed Description

Represents a bounding box whose axes are aligned with the coordinate system.

The box is usually referred by two corners, the start corner means the one whose coordinates are the smallest, while the end corner means the opposite.


Public Member Functions

  AxisAlignedBoundingBox (void)
  Creates an empty bounding box.
  AxisAlignedBoundingBox (const Vector &vStart, const Vector &vEnd)
  Creates an object by specifying two corners of the box.
  AxisAlignedBoundingBox (const Vector &vCenter, float fSize)
  Creates an object by specifying the center of it and the distance of the sides from the center.
  AxisAlignedBoundingBox (const AxisAlignedBoundingBox &cA)
  Creates an object by cloning another one.
AxisAlignedBoundingBox operator= (const AxisAlignedBoundingBox &cBB)
  Assigns the value of a box object to another one.
AxisAlignedBoundingBox operator+= (const AxisAlignedBoundingBox &cBB)
  Extends the box to contain another one.
bool  operator== (const AxisAlignedBoundingBox &cBB) const
  Returns true if two boxes are identical, false otherwise.
void  Reset (void)
  Makes the box empty.
void  Serialize (Stream &s)
  Writes/reads the object data to/from a stream.
bool  operator!= (const AxisAlignedBoundingBox &cBox) const
  returns true if the two boxes are different, false otherwise.
void  Extend (const Vector &)
  Extends the box to contain the passed point.
void  Extend (const AxisAlignedBoundingBox &bb)
  Extends the box to contain another one.
void  Transform (const class Matrix &mMatrix)
  Transforms the box with the passed-in matrix, and returns the smallest box which contains the result.
Vector  operator[] (int iCornerIndex) const
  Returns the corners of the box. Valid indexes are 0-7.
float  Size (void) const
  Returns the maximum edge length of the box.
float  XSize (void) const
  Returns the length of the box along the X axis.
float  YSize (void) const
  Returns the length of the box along the Y axis.
float  ZSize (void) const
  Returns the length of the box along the Y axis.
float  Volume (void) const
  Returns the volume of the box.
Vector  Center (void) const
  Returns the center of the box.
bool  IsPartOf (const AxisAlignedBoundingBox &cBB) const
  Returns true if the passed-in box contains this box.
bool  IsTouching (const AxisAlignedBoundingBox &cBB) const
  Returns true if the two boxes intersect at all.
bool  IsTouching (const Vector &vStart, const Vector &vEnd, float &fPlace) const
  Returns true if the box intersects any part of a specified line.
bool  IsContaining (const Vector &cV) const
  Returns true if the box contains the specified point.
bool  IsContaining (const AxisAlignedBoundingBox &b) const
  Returns true if the box contains the specified box.
bool  IsEmpty (void) const
  Returns true if the box is empy.
AxisAlignedBoundingBox  operator * (float fFactor)
  Multiplies the box coordinates with a scalar value.

Public Attributes

Vector  m_vStart
Vector  m_vEnd

Constructor & Destructor Documentation

mudbox::AxisAlignedBoundingBox::AxisAlignedBoundingBox void   )  [inline]
 

Creates an empty bounding box.

00533 { Reset(); };
mudbox::AxisAlignedBoundingBox::AxisAlignedBoundingBox const Vector vStart,
const Vector vEnd
[inline]
 

Creates an object by specifying two corners of the box.

00536                                                                        :
00537         m_vStart( vStart ),
00538         m_vEnd( vEnd ) {};

mudbox::AxisAlignedBoundingBox::AxisAlignedBoundingBox const Vector vCenter,
float  fSize
[inline]
 

Creates an object by specifying the center of it and the distance of the sides from the center.

This will be a cube.

00543     {
00544         Vector v( fSize, fSize, fSize );
00545         m_vStart = vCenter-v;
00546         m_vEnd   = vCenter+v;
00547     };
mudbox::AxisAlignedBoundingBox::AxisAlignedBoundingBox const AxisAlignedBoundingBox cA  )  [inline]
 

Creates an object by cloning another one.

00550                                                                :
00551     m_vStart( cA.m_vStart ),
00552     m_vEnd( cA.m_vEnd ) {};


Member Function Documentation

AxisAlignedBoundingBox& mudbox::AxisAlignedBoundingBox::operator= const AxisAlignedBoundingBox cBB  )  [inline]
 

Assigns the value of a box object to another one.

00556     {
00557         m_vStart = cBB.m_vStart;
00558         m_vEnd = cBB.m_vEnd;
00559         return *this;
00560     };
AxisAlignedBoundingBox& mudbox::AxisAlignedBoundingBox::operator+= const AxisAlignedBoundingBox cBB  )  [inline]
 

Extends the box to contain another one.

00564     {
00565         for ( int i = 0; i < 8; i++ ) Extend( cBB[i] );
00566         return *this;
00567     };
bool mudbox::AxisAlignedBoundingBox::operator== const AxisAlignedBoundingBox cBB  )  const [inline]
 

Returns true if two boxes are identical, false otherwise.

00571     {
00572         return m_vStart == cBB.m_vStart && m_vEnd == cBB.m_vEnd;
00573     };
void mudbox::AxisAlignedBoundingBox::Reset void   )  [inline]
 

Makes the box empty.

00577     {
00578         m_vStart.Set( 0, 0, 0 );
00579         m_vEnd.Set( -1, -1, -1 );
00580     };
void mudbox::AxisAlignedBoundingBox::Serialize Stream s  ) 
 

Writes/reads the object data to/from a stream.

bool mudbox::AxisAlignedBoundingBox::operator!= const AxisAlignedBoundingBox cBox  )  const [inline]
 

returns true if the two boxes are different, false otherwise.

00588         { return !(operator ==(cBox)); };
void mudbox::AxisAlignedBoundingBox::Extend const Vector  ) 
 

Extends the box to contain the passed point.

void mudbox::AxisAlignedBoundingBox::Extend const AxisAlignedBoundingBox bb  )  [inline]
 

Extends the box to contain another one.

00596     {
00597         if ( !bb.IsEmpty() ) {
00598             Extend( bb.m_vStart );
00599             Extend( bb.m_vEnd );
00600         };
00601     };
void mudbox::AxisAlignedBoundingBox::Transform const class Matrix mMatrix  ) 
 

Transforms the box with the passed-in matrix, and returns the smallest box which contains the result.

This is usually larger than the original box, because the transformation might rotate the box out of axis alignment.

Vector mudbox::AxisAlignedBoundingBox::operator[] int  iCornerIndex  )  const
 

Returns the corners of the box. Valid indexes are 0-7.

float mudbox::AxisAlignedBoundingBox::Size void   )  const [inline]
 

Returns the maximum edge length of the box.

00614 { return Max( Max( XSize(), YSize() ), ZSize() ); };
float mudbox::AxisAlignedBoundingBox::XSize void   )  const [inline]
 

Returns the length of the box along the X axis.

00617 { return m_vEnd.m_fX-m_vStart.m_fX; };
float mudbox::AxisAlignedBoundingBox::YSize void   )  const [inline]
 

Returns the length of the box along the Y axis.

00620 { return m_vEnd.m_fY-m_vStart.m_fY; };
float mudbox::AxisAlignedBoundingBox::ZSize void   )  const [inline]
 

Returns the length of the box along the Y axis.

00623 { return m_vEnd.m_fZ-m_vStart.m_fZ; };
float mudbox::AxisAlignedBoundingBox::Volume void   )  const [inline]
 

Returns the volume of the box.

00626 { return XSize()*YSize()*ZSize(); };
Vector mudbox::AxisAlignedBoundingBox::Center void   )  const [inline]
 

Returns the center of the box.

00629 { return (m_vStart+m_vEnd)*0.5f; };
bool mudbox::AxisAlignedBoundingBox::IsPartOf const AxisAlignedBoundingBox cBB  )  const [inline]
 

Returns true if the passed-in box contains this box.

00633     {
00634         return (
00635             m_vStart.m_fX >= cBB.m_vStart.m_fX && m_vEnd.m_fX <= cBB.m_vEnd.m_fX &&
00636             m_vStart.m_fY >= cBB.m_vStart.m_fY && m_vEnd.m_fY <= cBB.m_vEnd.m_fY &&
00637             m_vStart.m_fZ >= cBB.m_vStart.m_fZ && m_vEnd.m_fZ <= cBB.m_vEnd.m_fZ );
00638     };
bool mudbox::AxisAlignedBoundingBox::IsTouching const AxisAlignedBoundingBox cBB  )  const [inline]
 

Returns true if the two boxes intersect at all.

00642     {
00643         return !(
00644             m_vStart.m_fX >= cBB.m_vEnd.m_fX || m_vEnd.m_fX <= cBB.m_vStart.m_fX ||
00645             m_vStart.m_fY >= cBB.m_vEnd.m_fY || m_vEnd.m_fY <= cBB.m_vStart.m_fY ||
00646             m_vStart.m_fZ >= cBB.m_vEnd.m_fZ || m_vEnd.m_fZ <= cBB.m_vStart.m_fZ );
00647     };
bool mudbox::AxisAlignedBoundingBox::IsTouching const Vector vStart,
const Vector vEnd,
float &  fPlace
const
 

Returns true if the box intersects any part of a specified line.

If there is an intersection, then a point guaranteed to be inside the box is returned in the third argument (fPlace). That argument represents a location along the line from vStart to vEnd. (Location = vStart + fPlace*vEnd)

Parameters:
vStart  [in] A point (represented as a Vector) defining the start of the line
vEnd  [in] A point (represented as a Vector) defining the end of the line
fPlace  [out] A number between 0.0 and 1.0, defining a position along the line that is guaranteed to be inside the box (if true was returned).
bool mudbox::AxisAlignedBoundingBox::IsContaining const Vector cV  )  const [inline]
 

Returns true if the box contains the specified point.

00665     {
00666         return (
00667             m_vStart.m_fX <= cV.m_fX && m_vEnd.m_fX >= cV.m_fX &&
00668             m_vStart.m_fY <= cV.m_fY && m_vEnd.m_fY >= cV.m_fY &&
00669             m_vStart.m_fZ <= cV.m_fZ && m_vEnd.m_fZ >= cV.m_fZ );
00670     };
bool mudbox::AxisAlignedBoundingBox::IsContaining const AxisAlignedBoundingBox b  )  const [inline]
 

Returns true if the box contains the specified box.

00675         { return IsContaining( b.m_vStart ) && IsContaining( b.m_vEnd ); };
bool mudbox::AxisAlignedBoundingBox::IsEmpty void   )  const [inline]
 

Returns true if the box is empy.

Note that when the start and end corners are equal then the box is not treated as empty.

00680 { return m_vStart.x > m_vEnd.x; };
AxisAlignedBoundingBox mudbox::AxisAlignedBoundingBox::operator * float  fFactor  )  [inline]
 

Multiplies the box coordinates with a scalar value.

00684     {
00685         return AxisAlignedBoundingBox( m_vStart*fFactor, m_vEnd*fFactor );
00686     };

Member Data Documentation

Vector mudbox::AxisAlignedBoundingBox::m_vStart
 
Vector mudbox::AxisAlignedBoundingBox::m_vEnd
 

mudbox::AxisAlignedBoundingBox mudbox::AxisAlignedBoundingBox mudbox::AxisAlignedBoundingBox mudbox::AxisAlignedBoundingBox mudbox::AxisAlignedBoundingBox mudbox::AxisAlignedBoundingBox mudbox::AxisAlignedBoundingBox mudbox::AxisAlignedBoundingBox mudbox::AxisAlignedBoundingBox mudbox::AxisAlignedBoundingBox
mudbox::AxisAlignedBoundingBox mudbox::AxisAlignedBoundingBox mudbox::AxisAlignedBoundingBox mudbox::AxisAlignedBoundingBox mudbox::AxisAlignedBoundingBox mudbox::AxisAlignedBoundingBox mudbox::AxisAlignedBoundingBox mudbox::AxisAlignedBoundingBox mudbox::AxisAlignedBoundingBox mudbox::AxisAlignedBoundingBox