Moby
Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
Moby::OBB Class Reference

An oriented bounding box that optionally allows building an OBB tree. More...

#include <OBB.h>

Inheritance diagram for Moby::OBB:
Moby::BV

Public Member Functions

 OBB (const OBB &obb)
 
 OBB (const Point3d &center, const Ravelin::Matrix3d &R, const Ravelin::Vector3d &l)
 
 OBB (const OBB &o, const Ravelin::Vector3d &v)
 
OBBoperator= (const OBB &obb)
 Copies an OBB. More...
 
virtual void transform (const Ravelin::Transform3d &T, BV *result) const
 Transforms the OBB using the given transform.
 
virtual BVPtr calc_swept_BV (CollisionGeometryPtr g, const Ravelin::SVelocityd &v) const
 Calculates the velocity-expanded OBB for a body.
 
virtual bool intersects (const LineSeg3 &seg, double &tmin, double tmax, Point3d &q) const
 Determines whether a line segment intersects the bounding volume.
 
virtual bool outside (const Point3d &point, double tol=NEAR_ZERO) const
 Determines whether a point is outside the bounding volume.
 
virtual std::ostream & to_vrml (std::ostream &out, const Ravelin::Pose3d &T) const
 Outputs the OBB in VRML format to the given stream.
 
unsigned calc_size () const
 Constructs an OBB from a triangle mesh using the mesh inertia method [Ericson, 2003]. More...
 
XMLTreePtr save_to_xml_tree () const
 Saves a OBB hiearchy to a XMLTree.
 
virtual boost::shared_ptr
< const Ravelin::Pose3d > 
get_relative_pose () const
 Gets the associated pose for this bounding volume.
 
virtual Point3d get_lower_bounds () const
 Gets the lower bounds on the OBB.
 
virtual Point3d get_upper_bounds () const
 Gets the upper bounds on the OBB.
 
template<class ForwardIterator >
void expand_to_fit (ForwardIterator begin, ForwardIterator end)
 Expands this OBB (if necessary) to fit the given points. More...
 
template<class ForwardIterator >
 OBB (ForwardIterator begin, ForwardIterator end)
 Computes an OBB from a set of points. More...
 
template<class OutputIterator >
OutputIterator get_vertices (OutputIterator begin) const
 Gets the eight vertices of the bounding box. More...
 
virtual double calc_volume () const
 Calculates 1/8th of the volume of the bounding box.
 
template<class ForwardIterator >
OBB calc_low_dim_OBB (ForwardIterator begin, ForwardIterator end)
 Computes the minimum OBB from a set of lower dimensional (< 3d) points. More...
 
template<class ForwardIterator >
OBB calc_min_volume_OBB (ForwardIterator begin, ForwardIterator end)
 Computes the minimum OBB from a set of points. More...
 
template<class ForwardIterator >
 OBB (ForwardIterator begin, ForwardIterator end)
 Computes an OBB from a set of points. More...
 
template<class ForwardIterator >
void expand_to_fit (ForwardIterator begin, ForwardIterator end)
 Expands this OBB (if necessary) to fit the given points. More...
 
template<class ForwardIterator >
void align (ForwardIterator begin, ForwardIterator end, const Ravelin::Vector3d &d1, Ravelin::Vector3d &d2)
 Aligns this OBB with the minimum area bounding rectangle projected along the first dimension of the OBB.
 
template<class OutputIterator >
OutputIterator get_vertices (OutputIterator begin) const
 Gets the eight vertices of the bounding box. More...
 
template<class ForwardIterator >
void calc_lengths (const Ravelin::Vector3d &d1, const Ravelin::Vector3d &d2, const Ravelin::Vector3d &d3, const Point3d &center, ForwardIterator begin, ForwardIterator end, double lengths[3])
 
- Public Member Functions inherited from Moby::BV
BVPtr get_this ()
 
boost::shared_ptr< const BVget_this () const
 
bool is_leaf () const
 
template<class OutputIterator >
OutputIterator get_all_BVs (OutputIterator begin) const
 Gets all BV nodes. More...
 
template<class OutputIterator >
OutputIterator get_all_leafs (OutputIterator begin) const
 Gets all leaf nodes.
 
template<class OutputIterator >
OutputIterator get_all_BVs (OutputIterator begin) const
 Gets all BV nodes. More...
 
template<class OutputIterator >
OutputIterator get_all_leafs (OutputIterator begin) const
 Gets all leaf nodes.
 
template<class OutputIterator >
OutputIterator intersect_BV_trees (BVPtr a, BVPtr b, const Ravelin::Transform3d &aTb, const Ravelin::Transform3d &bTa, OutputIterator output_begin)
 Intersects two BV trees; returns list of all leaf-level intersecting BVs. More...
 

Static Public Member Functions

static double calc_sq_dist (const OBB &o, const Point3d &p)
 Computes the squared distance from a point to an OBB.
 
static double calc_dist (const OBB &a, const OBB &b, Point3d &cpa, Point3d &cpb)
 Determines the distance between two OBBs.
 
static double calc_dist (const OBB &a, const OBB &b, const Ravelin::Transform3d &aTb, Point3d &cpa, Point3d &cpb)
 
static bool intersects (const OBB &a, const OBB &b)
 Determines whether two OBBs intersect another. More...
 
static bool intersects (const OBB &a, const OBB &b, const Ravelin::Transform3d &aTb)
 
static bool intersects (const OBB &a, const LineSeg3 &seg, double &tmin, double tmax, Point3d &q)
 Determines whether an OBB and a line/ray/line segment intersect. More...
 
static bool outside (const OBB &a, const Point3d &point, double tol=NEAR_ZERO)
 Determines whether a point is outside a OBB to within the given tolerance.
 
static OBBPtr load_from_xml (boost::shared_ptr< const XMLTree > root)
 Loads an OBB hierarchy from a XML tree.
 
template<class ForwardIterator >
static OBB calc_min_volume_OBB (ForwardIterator begin, ForwardIterator end)
 Computes the minimum OBB from a set of points. More...
 
- Static Public Member Functions inherited from Moby::BV
static bool intersects (BVPtr a, BVPtr b)
 Convenience method.
 
static bool intersects (BVPtr a, BVPtr b, const Ravelin::Transform3d &T)
 Convenience method.
 
static double calc_distance (BVPtr a, BVPtr b, Point3d &cp1, Point3d &cp2)
 Convenience method.
 
static double calc_distance (BVPtr a, BVPtr b, const Ravelin::Transform3d &aTb, Point3d &cp1, Point3d &cp2)
 Convenience method.
 
static bool intersects (const BV *a, const BV *b)
 Computes whether two abstract bounding volumes intersect.
 
static bool intersects (const BV *a, const BV *b, const Ravelin::Transform3d &T)
 
static double calc_distance (const BV *a, const BV *b, Point3d &cp1, Point3d &cp2)
 Computes the distance between two abstract bounding volumes and stores the closest points. More...
 
static double calc_distance (const BV *a, const BV *b, const Ravelin::Transform3d &aTb, Point3d &cp1, Point3d &cp2)
 
template<class OutputIterator >
static OutputIterator intersect_BV_trees (BVPtr a, BVPtr b, const Ravelin::Transform3d &aTb, const Ravelin::Transform3d &bTa, OutputIterator output_begin)
 Intersects two BV trees; returns list of all leaf-level intersecting BVs. More...
 

Public Attributes

Point3d center
 Center of the bounding box.
 
Ravelin::Vector3d l
 Half-lengths of the OBBs in the three axes directions (i.e., in the box frame)
 
Ravelin::Matrix3d R
 Orientation of this OBB.
 
- Public Attributes inherited from Moby::BV
boost::shared_ptr< void > userdata
 Userdata for the BV.
 
CollisionGeometryPtr geom
 The collision geometry associated with this bounding volume.
 
std::list< BVPtrchildren
 The children of this BV.
 

Detailed Description

An oriented bounding box that optionally allows building an OBB tree.

Note
the OBB is generally constructed such that its frame is aligned with that of the underlying rigid body (or collision geometry). Therefore, the center of the OBB is computed relative to the center-of-mass of the body (or the center of the geometry). The orientation of the OBB will always be identical to the orientation of the rigid body (or collision geometry).

Constructor & Destructor Documentation

template<class ForwardIterator >
Moby::OBB::OBB ( ForwardIterator  begin,
ForwardIterator  end 
)

Computes an OBB from a set of points.

Parameters
beginan iterator to type Point3d
endan iterator to type Point3d Algorithm taken from [Ericson, 2005]
template<class ForwardIterator >
Moby::OBB::OBB ( ForwardIterator  begin,
ForwardIterator  end 
)

Computes an OBB from a set of points.

Parameters
beginan iterator to type Point3d
endan iterator to type Point3d Algorithm taken from [Ericson, 2005]

References Moby::IndexedTri::a, Moby::IndexedTri::b, and Moby::IndexedTri::c.

Member Function Documentation

template<class ForwardIterator >
OBB Moby::OBB::calc_low_dim_OBB ( ForwardIterator  begin,
ForwardIterator  end 
)

Computes the minimum OBB from a set of lower dimensional (< 3d) points.

Parameters
beginan iterator to type Point3d
endan iterator to type Point3d

References center, l, and R.

template<class ForwardIterator >
OBB Moby::OBB::calc_min_volume_OBB ( ForwardIterator  begin,
ForwardIterator  end 
)
static

Computes the minimum OBB from a set of points.

Parameters
beginan iterator to type Point3d
endan iterator to type Point3d Algorithm taken from http://www.geometrictools.com - thanks Dave Eberly!
template<class ForwardIterator >
OBB Moby::OBB::calc_min_volume_OBB ( ForwardIterator  begin,
ForwardIterator  end 
)

Computes the minimum OBB from a set of points.

Parameters
beginan iterator to type Point3d
endan iterator to type Point3d Algorithm taken from http://www.geometrictools.com - thanks Dave Eberly!

References calc_volume(), center, Moby::IndexedTriArray::determine_edge_facet_map(), Moby::IndexedTriArray::determine_vertex_edge_map(), Moby::IndexedTriArray::get_triangle(), Moby::IndexedTriArray::get_vertices(), Moby::IndexedTriArray::is_coplanar(), l, and R.

unsigned OBB::calc_size ( ) const

Constructs an OBB from a triangle mesh using the mesh inertia method [Ericson, 2003].

Requires a O(n) operation to compute the inertial properties of the triangle meshCalculates the size (number of elements in) of an OBB tree

template<class ForwardIterator >
void Moby::OBB::expand_to_fit ( ForwardIterator  begin,
ForwardIterator  end 
)

Expands this OBB (if necessary) to fit the given points.

Parameters
beginan iterator to the beginning of a container of type Ravelin:Point3d:
endan iterator to the end of a container of type Point3d
template<class ForwardIterator >
void Moby::OBB::expand_to_fit ( ForwardIterator  begin,
ForwardIterator  end 
)

Expands this OBB (if necessary) to fit the given points.

Parameters
beginan iterator to the beginning of a container of type Ravelin:Point3d:
endan iterator to the end of a container of type Point3d
template<class OutputIterator >
OutputIterator Moby::OBB::get_vertices ( OutputIterator  begin) const

Gets the eight vertices of the bounding box.

Note
vertices are output in no particular order
template<class OutputIterator >
OutputIterator Moby::OBB::get_vertices ( OutputIterator  begin) const

Gets the eight vertices of the bounding box.

Note
vertices are output in no particular order
bool OBB::intersects ( const OBB a,
const OBB b 
)
static

Determines whether two OBBs intersect another.

Code adapted from [Ericson, 2005]

References get_relative_pose().

Referenced by intersects().

bool OBB::intersects ( const OBB a,
const LineSeg3 seg,
double &  tmin,
double  tmax,
Point3d q 
)
static

Determines whether an OBB and a line/ray/line segment intersect.

When intersecting, return intersection distance tmin and point q of intersection.

Parameters
athe OBB to check for intersection
segthe line segment to check for intersection
tminon entry, contains the minimum value of the line parameter- for a line segment, this will generally be 0; when an intersection occurs, this will contain the distance of intersection from the tmin that was input on return
tmaxthe maximum value of the line parameter- for a line segment, this will generally be 1
qcontains the point of intersection, if any, on return
Returns
true if the OBB and line intersect, false otherwise
Note
code adapted from [Ericson, 2005], pp. 180-181

References center, get_relative_pose(), and R.

OBB & OBB::operator= ( const OBB obb)

Copies an OBB.

Note
userdata and node info (children) are not copied

References center, Moby::BV::geom, l, and R.


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