maspack.geometry
Class BVNode

java.lang.Object
  extended by maspack.geometry.BVNode
All Implemented Interfaces:
GLRenderable
Direct Known Subclasses:
AABB, OBB

public abstract class BVNode
extends java.lang.Object
implements GLRenderable

Base class for bounding volumes such as oriented and axis-aligned bounding boxes. It contains infrastructure that allows these bounding volumes to be assembled into a hierarchy.


Field Summary
 
Fields inherited from interface maspack.render.GLRenderable
TRANSLUCENT, TWO_DIMENSIONAL
 
Constructor Summary
BVNode()
           
 
Method Summary
 void addChild(BVNode child)
          Adds a child volume to this bounding volume.
abstract  boolean containsPoint(Point3d pnt)
          Returns true if this bounding volume contains a prescribed point.
abstract  double distanceAlongLine(Point3d origin, Vector3d dir, double min, double max)
          Returns the distance of this bounding volume along a line from a point.
abstract  double distanceToPoint(Point3d pnt)
          Returns the distance of a point to this bounding volume, or 0 if the point is on or inside it.
abstract  void getCenter(Vector3d center)
          Returns a center point for this bounding volume.
 int getDepth()
          Returns the depth of this bounding volume within a tree.
 Boundable[] getElements()
          Returns the boundable elements directly contained by this bounding volume.
 BVNode getFirstChild()
          Returns the first child volume, if any, associated with this bounding volume
 BVNode getNext()
          Returns the next sibling volume, if any, associated with the bounding volume.
 int getNumber()
          Returns the number of this bounding volume.
 int getNumElements()
          Returns the number of boundable elements directly contained by this bounding volume.
 BVNode getParent()
          Gets the parent volume, if any, for this bounding volume.
abstract  double getRadius()
          Returns an approximate "radius" for this bounding volume.
 int getRenderHints()
          Returns a bit code giving rendering hints about this renderable.
abstract  boolean intersectsLine(double[] lam, Point3d origin, Vector3d dir, double min, double max)
          Returns true if this bounding volume intersects a line.
abstract  boolean intersectsLineSegment(Point3d p1, Point3d p2)
          Returns true if this bounding volume intersects a line segment.
abstract  boolean intersectsPlane(Vector3d n, double d)
          Returns true if this bounding volume intersects a plane described by
abstract  boolean intersectsSphere(Point3d center, double r)
          Returns true if this bounding volume intersects a sphere.
abstract  boolean isContained(Boundable[] elements, double tol)
          Returns true if an entire set of elements is contained within this bounding volume.
 boolean isLeaf()
          Returns true if this bounding volume is a leaf node; i.e., if it has no children.
 int numChildren()
          Returns the number of child volumes contained by this bounding volume.
 void setElements(Boundable[] elements)
          Sets the boundable elements directly contained by this bounding volume.
 void setNumber(int num)
          Sets the number of this bounding volume.
 void setParent(BVNode parent)
          Sets the parent volume for this bounding volume.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface maspack.render.GLRenderable
prerender, render, updateBounds
 

Constructor Detail

BVNode

public BVNode()
Method Detail

addChild

public void addChild(BVNode child)
Adds a child volume to this bounding volume.

Parameters:
child - child to be added

getFirstChild

public BVNode getFirstChild()
Returns the first child volume, if any, associated with this bounding volume

Returns:
first child

getNext

public BVNode getNext()
Returns the next sibling volume, if any, associated with the bounding volume.

Returns:
next sibling

getNumber

public int getNumber()
Returns the number of this bounding volume. Numbers can be assigned, usually in depth first order, after a bounding volume tree has been built. Numbers exist for diagnostic purposes only.

Returns:
current number of this bounding volume.

setNumber

public void setNumber(int num)
Sets the number of this bounding volume. Numbers can be assigned, usually in depth first order, after a bounding volume tree has been built. Numbers exists for diagnostic purposes only.

Parameters:
num - number

getRadius

public abstract double getRadius()
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.

Returns:
approximate radius of the volume

getCenter

public abstract void getCenter(Vector3d center)
Returns a center point for this bounding volume.

Parameters:
center - returns to center point

numChildren

public int numChildren()
Returns the number of child volumes contained by this bounding volume.

Returns:
number of child volumes

getElements

public Boundable[] getElements()
Returns the boundable elements directly contained by this bounding volume. Generally, a bounding volume will only contain elements if it is a leaf volume.

Returns:
boundable elements contained by this bounding volume.

getNumElements

public int getNumElements()
Returns the number of boundable elements directly contained by this bounding volume. Generally, a bounding volume will only contain elements if it is a leaf volume.

Returns:
number of boundable elements contained by this bounding volume.

setElements

public void setElements(Boundable[] elements)
Sets the boundable elements directly contained by this bounding volume. Generally, a bounding volume will only contain elements if it is a leaf volume. The array specified is used directly; it is not copied.

Parameters:
elements - boundable elements to be contained

getParent

public BVNode getParent()
Gets the parent volume, if any, for this bounding volume.

Returns:
parent volume

setParent

public void setParent(BVNode parent)
Sets the parent volume for this bounding volume.

Parameters:
parent - parent volume

isLeaf

public boolean isLeaf()
Returns true if this bounding volume is a leaf node; i.e., if it has no children.

Returns:
true if this bounding volume is a leaf node

containsPoint

public abstract boolean containsPoint(Point3d pnt)
Returns true if this bounding volume contains a prescribed point.

Parameters:
pnt - point to be tested
Returns:
true if this bounding volume contains pnt.

intersectsLine

public abstract boolean intersectsLine(double[] lam,
                                       Point3d origin,
                                       Vector3d dir,
                                       double min,
                                       double max)
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.

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

intersectsSphere

public abstract boolean intersectsSphere(Point3d center,
                                         double r)
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.

Parameters:
center - center point of the sphere
r - radius of the sphere
Returns:
true if this bounding volume intersects the sphere

intersectsPlane

public abstract boolean intersectsPlane(Vector3d n,
                                        double d)
Returns true if this bounding volume intersects a plane described by
 n^T x = d
 

Parameters:
n - normal direction of the plane
d - dot product offset
Returns:
true if this bounding volume intersects the plane

intersectsLineSegment

public abstract boolean intersectsLineSegment(Point3d p1,
                                              Point3d p2)
Returns true if this bounding volume intersects a line segment.

Parameters:
p1 - first segment end point
p2 - second segment end point
Returns:
true if this bounding volume intersects the line segment.

distanceToPoint

public abstract double distanceToPoint(Point3d pnt)
Returns the distance of a point to this bounding volume, or 0 if the point is on or inside it.

Parameters:
pnt - point to check distance for
Returns:
distance of pnt to this volume

distanceAlongLine

public abstract double distanceAlongLine(Point3d origin,
                                         Vector3d dir,
                                         double min,
                                         double max)
Returns the distance of this bounding volume along a line from a point. If the point is on or inside the bounding volume, then 0 is returned. 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.

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

isContained

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

Parameters:
elements - set of boundable elements to check
tol - specifies the minimum amount by which each element must be inside

getRenderHints

public int getRenderHints()
Returns a bit code giving rendering hints about this renderable. Current bit codes include TRANSLUCENT.

Specified by:
getRenderHints in interface GLRenderable
Returns:
bit code of rendering hints.

getDepth

public int getDepth()
Returns the depth of this bounding volume within a tree. A depth of 0 indicates the root of the tree.

Returns:
depth of this bounding volume within a tree