maspack.geometry
Class OBB

java.lang.Object
  extended by maspack.geometry.BVNode
      extended by maspack.geometry.OBB
All Implemented Interfaces:
GLRenderable

public class OBB
extends BVNode


Nested Class Summary
static class OBB.Method
          Method used to generate an OBB from a set of boundables
 
Field Summary
static double defaultTolerance
           
 
Fields inherited from interface maspack.render.GLRenderable
TRANSLUCENT, TWO_DIMENSIONAL
 
Constructor Summary
OBB()
           
OBB(double wx, double wy, double wz)
           
OBB(double wx, double wy, double wz, RigidTransform3d X)
           
OBB(MeshBase mesh)
           
OBB(Vector3d widths, RigidTransform3d X)
           
 
Method Summary
 boolean containsPoint(Point3d pnt)
          Returns true if this bounding volume contains a prescribed point.
 double distanceAlongLine(Point3d origin, Vector3d dir, double min, double max)
          Code is modified from "An Efficient and Robust Ray-Box Intersection Algorithm", Amy Williams, Steve Barrus, R.
 double distanceToPoint(Point3d pnt)
          Returns the distance of a point to this bounding volume, or 0 if the point is on or inside it.
 void getCenter(Vector3d center)
          Returns a center point for this bounding volume.
 Vector3d getHalfWidths()
          Gets the half-widths for this OBB.
 void getHalfWidths(Vector3d halfWidths)
          Sets the half-widths for this OBB.
 double getRadius()
          Returns an approximate "radius" for this bounding volume.
 void getSortedAxes(Vector3d[] axes)
          Returns the axes of the box, sorted in order from largest to smallest.
 RigidTransform3d getTransform()
          Returns the transform associated with this OBB.
 void getTransform(RigidTransform3d XObbToRef)
          Gets the transform associated with this OBB.
 void getWidths(Vector3d widths)
          Gets the widths for this OBB.
 boolean intersectsLine(double[] lam, Point3d origin, Vector3d dir, double min, double max)
          Returns true if this bounding volume intersects a line.
 boolean intersectsLineSegment(Point3d p1, Point3d p2)
          Returns true if this bounding volume intersects a line segment.
 boolean intersectsPlane(Vector3d n, double d)
          Returns true if this bounding volume intersects a plane described by
 boolean intersectsSphere(Point3d pnt, double r)
          Returns true if this bounding volume intersects a sphere.
 boolean isContained(Boundable[] boundables, double tol)
          Returns true if an entire set of elements is contained within this bounding volume.
 void prerender(RenderList list)
          Prepare for rendering, and potentially add itself to a list to be drawn by a GLRenderer.
 void render(GLRenderer renderer, int flags)
          Render this object using Open GL via the JOGL.
 void set(Boundable[] elems, int num, double margin, OBB.Method method)
           
 void set(MeshBase mesh, double margin, OBB.Method method)
          Sets this OBB to contain the points for a mesh.
 void set(Point3d[] pnts, double margin, OBB.Method method)
           
 void setHalfWidths(Vector3d hw)
           
 void setTransform(RigidTransform3d XObbToRef)
          Sets the transform associated with this OBB.
 void setWidths(double wx, double wy, double wz)
          Sets the widths for this OBB.
 void setWidths(Vector3d widths)
          Sets the widths for this OBB.
 void update(double margin)
           
 void updateBounds(Point3d pmin, Point3d pmax)
          Update the minimum and maximum points for this object.
 
Methods inherited from class maspack.geometry.BVNode
addChild, getDepth, getElements, getFirstChild, getNext, getNumber, getNumElements, getParent, getRenderHints, isLeaf, numChildren, setElements, setNumber, setParent
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

defaultTolerance

public static double defaultTolerance
Constructor Detail

OBB

public OBB()

OBB

public OBB(double wx,
           double wy,
           double wz,
           RigidTransform3d X)

OBB

public OBB(double wx,
           double wy,
           double wz)

OBB

public OBB(Vector3d widths,
           RigidTransform3d X)

OBB

public OBB(MeshBase mesh)
Method Detail

getRadius

public double getRadius()
Description copied from class: BVNode
Returns an approximate "radius" for this bounding volume. This does not have to be precise, but should reflect roughly the maximum distance of the volume boundary from it's center.

Specified by:
getRadius in class BVNode
Returns:
approximate radius of the volume

getCenter

public void getCenter(Vector3d center)
Description copied from class: BVNode
Returns a center point for this bounding volume.

Specified by:
getCenter in class BVNode
Parameters:
center - returns to center point

setWidths

public void setWidths(double wx,
                      double wy,
                      double wz)
Sets the widths for this OBB. These are the extents of the OBB along each of its principal axes.

Parameters:
wx - new width value for the 'x' principal axis
wy - new width value for the 'y' principal axis
wz - new width value for the 'z' principal axis

setHalfWidths

public void setHalfWidths(Vector3d hw)

setWidths

public void setWidths(Vector3d widths)
Sets the widths for this OBB. These are the extents of the OBB along each of its principal axes.

Parameters:
widths - specifies new width values for this OBB

getWidths

public void getWidths(Vector3d widths)
Gets the widths for this OBB. These are the extents of the OBB along each of its principal axes.

Parameters:
widths - returns the width values for this OBB

getHalfWidths

public void getHalfWidths(Vector3d halfWidths)
Sets the half-widths for this OBB. These are 1/2 the extents of the OBB along each of its principal axes.

Parameters:
halfWidths - returns the half-width values for this OBB

getHalfWidths

public Vector3d getHalfWidths()
Gets the half-widths for this OBB. These are 1/2 the extents of the OBB along each of its principal axes.

Returns:
half-width values for this OBB (should not be modified).

setTransform

public void setTransform(RigidTransform3d XObbToRef)
Sets the transform associated with this OBB. This is the transform that maps from the coordinate from of the OBB into world coordinates.

Parameters:
XObbToRef - new transform value

getTransform

public void getTransform(RigidTransform3d XObbToRef)
Gets the transform associated with this OBB. This is the transform that maps from the coordinate from of the OBB into world coordinates.

Parameters:
XObbToRef - returns the transform value

getTransform

public RigidTransform3d getTransform()
Returns the transform associated with this OBB. The returned result should not be modified.

Returns:
transform associated with this OBB.

set

public void set(MeshBase mesh,
                double margin,
                OBB.Method method)
Sets this OBB to contain the points for a mesh. It does this by computing the OBB using the faces of the convex hull of the mesh points.

Parameters:
mesh - mesh to fit the OBB to
margin - extra distance by with the OBB should be grown. If less than 0, a default margin is computed.
method -

set

public void set(Point3d[] pnts,
                double margin,
                OBB.Method method)

getSortedAxes

public void getSortedAxes(Vector3d[] axes)
Returns the axes of the box, sorted in order from largest to smallest.


set

public void set(Boundable[] elems,
                int num,
                double margin,
                OBB.Method method)

containsPoint

public boolean containsPoint(Point3d pnt)
Description copied from class: BVNode
Returns true if this bounding volume contains a prescribed point.

Specified by:
containsPoint in class BVNode
Parameters:
pnt - point to be tested
Returns:
true if this bounding volume contains pnt.

intersectsSphere

public boolean intersectsSphere(Point3d pnt,
                                double r)
Description copied from class: BVNode
Returns true if this bounding volume intersects a sphere. By specifying a negative value for the radius, the method can be used as a test to see if the center point is located a certain distance within the bounding volume.

Specified by:
intersectsSphere in class BVNode
Parameters:
pnt - center point of the sphere
r - radius of the sphere
Returns:
true if this bounding volume intersects the sphere

intersectsLine

public boolean intersectsLine(double[] lam,
                              Point3d origin,
                              Vector3d dir,
                              double min,
                              double max)
Description copied from class: BVNode
Returns true if this bounding volume intersects a line. The line is described by a point and a direction, such that points x along the line can be described by a parameter s according to
 x = origin + s dir
 
The line can be given finite bounds by specifying maximum and minimum bounds for s.

Specified by:
intersectsLine in class BVNode
Parameters:
lam - if non-null, returns the lower and upper values of s that define the intersection region
origin - originating point for the line
dir - direction of the line
min - minimum s value for the line, or -infinity if there is no minimum value
max - maximum s value for the line, or +infinity if there is no maximum value
Returns:
true if this bounding volume intersects the line

update

public void update(double margin)

isContained

public boolean isContained(Boundable[] boundables,
                           double tol)
Description copied from class: BVNode
Returns true if an entire set of elements is contained within this bounding volume. This method is mainly intended for diagnostic purposes.

Specified by:
isContained in class BVNode
Parameters:
boundables - set of boundable elements to check
tol - specifies the minimum amount by which each element must be inside

distanceToPoint

public double distanceToPoint(Point3d pnt)
Description copied from class: BVNode
Returns the distance of a point to this bounding volume, or 0 if the point is on or inside it.

Specified by:
distanceToPoint in class BVNode
Parameters:
pnt - point to check distance for
Returns:
distance of pnt to this volume

distanceAlongLine

public double distanceAlongLine(Point3d origin,
                                Vector3d dir,
                                double min,
                                double max)
Code is modified from "An Efficient and Robust Ray-Box Intersection Algorithm", Amy Williams, Steve Barrus, R. Keith Morley, Peter Shirley, University of Utah.

Specified by:
distanceAlongLine in class BVNode
Parameters:
origin - originating point for the line
dir - direction of the line
min - minimum s value for the line, or -infinity if there is no minimum value
max - maximum s value for the line, or +infinity if there is no maximum value
Returns:
distance of the point to the volume along the line

updateBounds

public void updateBounds(Point3d pmin,
                         Point3d pmax)
Description copied from interface: GLRenderable
Update the minimum and maximum points for this object. In an x-y-z coordinate system with x directed to the right and y directed upwards, the minimum and maximum points can be thought of as defining the left-lower-far and right-upper-near corners of a bounding cube. This method should only reduce the elements of the minimum point and increase the elements of the maximum point, since it may be used as part of an iteration to determine the bounding cube for several different objects.

Parameters:
pmin - minimum point
pmax - maximum point

render

public void render(GLRenderer renderer,
                   int flags)
Description copied from interface: GLRenderable
Render this object using Open GL via the JOGL.

Parameters:
renderer - renderer object which is used to perform the rendering. Provides pointers to GL and GLU, along with helper functions.
flags - supplies flags that may be used to control different aspects of the rendering. Flags are defined in GLRenderer and currently include GLRenderer.SELECTED, GLRenderer.VERTEX_COLORING, GLRenderer.HSV_COLOR_INTERPOLATION, GLRenderer.SORT_FACES, and GLRenderer.CLEAR_MESH_DISPLAY_LISTS.

prerender

public void prerender(RenderList list)
Description copied from interface: GLRenderable
Prepare for rendering, and potentially add itself to a list to be drawn by a GLRenderer.


intersectsLineSegment

public boolean intersectsLineSegment(Point3d p1,
                                     Point3d p2)
Description copied from class: BVNode
Returns true if this bounding volume intersects a line segment.

Specified by:
intersectsLineSegment in class BVNode
Parameters:
p1 - first segment end point
p2 - second segment end point
Returns:
true if this bounding volume intersects the line segment.

intersectsPlane

public boolean intersectsPlane(Vector3d n,
                               double d)
Description copied from class: BVNode
Returns true if this bounding volume intersects a plane described by
 n^T x = d
 

Specified by:
intersectsPlane in class BVNode
Parameters:
n - normal direction of the plane
d - dot product offset
Returns:
true if this bounding volume intersects the plane