de.grogra.vecmath.geom
Class BoundingBox

java.lang.Object
  extended by de.grogra.vecmath.geom.VolumeBase
      extended by de.grogra.vecmath.geom.BoundingBox
All Implemented Interfaces:
Volume

public class BoundingBox
extends VolumeBase

This class represents an axis-aligned bounding box. It contains all points between the corners min and max.

Author:
Ole Kniemeyer

Field Summary
static int ABOVE
          Return value for testParallelogram(javax.vecmath.Tuple3d, javax.vecmath.Tuple3d, javax.vecmath.Tuple3d, javax.vecmath.Tuple3d, javax.vecmath.Matrix3d, javax.vecmath.Vector3d, javax.vecmath.Vector3d) indicating that this bounding box lies completely above the plane of the quad.
static int BELOW
          Return value for testParallelogram(javax.vecmath.Tuple3d, javax.vecmath.Tuple3d, javax.vecmath.Tuple3d, javax.vecmath.Tuple3d, javax.vecmath.Matrix3d, javax.vecmath.Vector3d, javax.vecmath.Vector3d) indicating that this bounding box lies completely below the plane of the quad.
static int INTERSECTION
          Return value for testParallelogram(javax.vecmath.Tuple3d, javax.vecmath.Tuple3d, javax.vecmath.Tuple3d, javax.vecmath.Tuple3d, javax.vecmath.Matrix3d, javax.vecmath.Vector3d, javax.vecmath.Vector3d) indicating an intersection.
 Point3d max
          The maximum coordinates of this box.
 Point3d min
          The minimum coordinates of this box.
static int NO_INTERSECTION
          Return value for testParallelogram(javax.vecmath.Tuple3d, javax.vecmath.Tuple3d, javax.vecmath.Tuple3d, javax.vecmath.Tuple3d, javax.vecmath.Matrix3d, javax.vecmath.Vector3d, javax.vecmath.Vector3d) indicating no intersection.
 
Constructor Summary
BoundingBox(Point3d min, Point3d max)
           
 
Method Summary
 boolean boxContainsBoundary(BoundingBox box, Tuple3d center, double radius, Variables temp)
          Returns true if the specified box contains (part of) the boundary surface of this volume.
 boolean computeIntersections(Line line, int which, IntersectionList list, Intersection excludeStart, Intersection excludeEnd)
          Computes intersections between the boundary surface of this object and the specified line.
static boolean computeIntersections(Volume box, Tuple3d min, Tuple3d max, Line line, boolean all, IntersectionList list, int excludeStartFace, int excludeEndFace)
          Computes the intersections (or the first thereof, if all is false) between the faces of the bounding box [min, max] and the specified line, see also the general method Volume.computeIntersections(de.grogra.vecmath.geom.Line, int, de.grogra.vecmath.geom.IntersectionList, de.grogra.vecmath.geom.Intersection, de.grogra.vecmath.geom.Intersection).
 void computeNormal(Intersection is, Vector3d normal)
          This method computes the unit normal vector of an intersection is which has been computed previously by the invocation of Volume.computeIntersections(de.grogra.vecmath.geom.Line, int, de.grogra.vecmath.geom.IntersectionList, de.grogra.vecmath.geom.Intersection, de.grogra.vecmath.geom.Intersection) on this volume.
 void computeTangents(Intersection is, Vector3d dpdu, Vector3d dpdv)
          This method computes the derivatives of the surface point (as function of the uv-coordinates, see Volume.computeUV(de.grogra.vecmath.geom.Intersection, javax.vecmath.Vector2d)) with respect to u and v at the intersection point.
 void computeUV(Intersection is, Vector2d uv)
          This method computes the uv-coordinates of an intersection point is which has been computed previously by the invocation of Volume.computeIntersections(de.grogra.vecmath.geom.Line, int, de.grogra.vecmath.geom.IntersectionList, de.grogra.vecmath.geom.Intersection, de.grogra.vecmath.geom.Intersection) on this volume.
 boolean contains(Tuple3d point, boolean open)
          Determines if the given point lies within this object.
 boolean contains(Tuple3d point, int excludedCoordinate)
           
 void getExtent(Tuple3d min, Tuple3d max, Variables temp)
          Computes the extent of this volume, i.e., an axis-aligned bounding box between min and max.
 int testParallelogram(Tuple3d a, Tuple3d b, Tuple3d c, Tuple3d d, Matrix3d inv, Vector3d normal, Vector3d v)
          Determines if the specified parallelogram intersects this bounding box.
 java.lang.String toString()
           
 
Methods inherited from class de.grogra.vecmath.geom.VolumeBase
addConvexIntersections, getId, operator$and, operator$com, operator$or, operator$sub, setId
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ABOVE

public static final int ABOVE
Return value for testParallelogram(javax.vecmath.Tuple3d, javax.vecmath.Tuple3d, javax.vecmath.Tuple3d, javax.vecmath.Tuple3d, javax.vecmath.Matrix3d, javax.vecmath.Vector3d, javax.vecmath.Vector3d) indicating that this bounding box lies completely above the plane of the quad.

See Also:
Constant Field Values

BELOW

public static final int BELOW
Return value for testParallelogram(javax.vecmath.Tuple3d, javax.vecmath.Tuple3d, javax.vecmath.Tuple3d, javax.vecmath.Tuple3d, javax.vecmath.Matrix3d, javax.vecmath.Vector3d, javax.vecmath.Vector3d) indicating that this bounding box lies completely below the plane of the quad.

See Also:
Constant Field Values

INTERSECTION

public static final int INTERSECTION
Return value for testParallelogram(javax.vecmath.Tuple3d, javax.vecmath.Tuple3d, javax.vecmath.Tuple3d, javax.vecmath.Tuple3d, javax.vecmath.Matrix3d, javax.vecmath.Vector3d, javax.vecmath.Vector3d) indicating an intersection.

See Also:
Constant Field Values

max

public Point3d max
The maximum coordinates of this box.


min

public Point3d min
The minimum coordinates of this box.


NO_INTERSECTION

public static final int NO_INTERSECTION
Return value for testParallelogram(javax.vecmath.Tuple3d, javax.vecmath.Tuple3d, javax.vecmath.Tuple3d, javax.vecmath.Tuple3d, javax.vecmath.Matrix3d, javax.vecmath.Vector3d, javax.vecmath.Vector3d) indicating no intersection.

See Also:
Constant Field Values
Constructor Detail

BoundingBox

public BoundingBox(Point3d min,
                   Point3d max)
Method Detail

boxContainsBoundary

public boolean boxContainsBoundary(BoundingBox box,
                                   Tuple3d center,
                                   double radius,
                                   Variables temp)
Description copied from interface: Volume
Returns true if the specified box contains (part of) the boundary surface of this volume. Otherwise, if box and boundary do not overlap, this method should return false, but may also return true if an exact computation would be too expensive or complicated.

Note that a box contains the boundary of a closed set S iff both have a non-empty intersection and the box is not contained in the open set of S.

Parameters:
box - bounding box
center - center coordinates of box
radius - radius of enclosing sphere
temp - has to be provided by the invoker, may be used in implementations
Returns:
true if box contains (part of) the boundary of this volume

computeIntersections

public boolean computeIntersections(Line line,
                                    int which,
                                    IntersectionList list,
                                    Intersection excludeStart,
                                    Intersection excludeEnd)
Description copied from interface: Volume
Computes intersections between the boundary surface of this object and the specified line. The intersections are added to list in ascending order of distance (i.e., of Intersection.parameter), where the parameter has to lie between line.start and line.end. Implementations of this method must not clear or modify the existing intersections in list.

The parameter which has to be one of Intersection.ALL, Intersection.CLOSEST, Intersection.ANY. It determines if all intersections have to be added to the list, only the closest (minimal value of Intersection.parameter), or an arbitrary of the set of all intersections. Only in case of ALL, the return value of this method is precise.

If specific intersection points should be excluded from the list of computed intersections, they have to be specified in excludeStart and excludeEnd. The intersection point of excludeStart has to be the starting point of line, the intersection point of excludeEnd has to be the end point of line. The exclusion of intersections is a useful feature for ray-tracing, e.g., when a ray is re-emitted at an intersection point in another direction.

Parameters:
line - a line
which - one of Intersection.ALL, Intersection.CLOSEST, Intersection.ANY, this determines which intersections have to be added to list
list - the intersections are added to this list
excludeStart - intersection at start point which shall be excluded, or null
excludeEnd - intersection at end point which shall be excluded, or null
Returns:
true iff the beginning of the line lies within the volume (i.e., if the line starts within the volume or enters the volume at the starting point); however note that the returned value is valid only if which == Intersection.ALL

computeIntersections

public static boolean computeIntersections(Volume box,
                                           Tuple3d min,
                                           Tuple3d max,
                                           Line line,
                                           boolean all,
                                           IntersectionList list,
                                           int excludeStartFace,
                                           int excludeEndFace)
Computes the intersections (or the first thereof, if all is false) between the faces of the bounding box [min, max] and the specified line, see also the general method Volume.computeIntersections(de.grogra.vecmath.geom.Line, int, de.grogra.vecmath.geom.IntersectionList, de.grogra.vecmath.geom.Intersection, de.grogra.vecmath.geom.Intersection).

If excludeStartFace is non-negative, it has to specify one of the faces of the box, see Cube.LEFT. The intersection of the line and the specified face is excluded from the set of computed intersections. In this case the starting point of the line has to lie on the specified face.

If excludeEndFace is non-negative, the same treatment as for excludeStartFace applies with the requirement, that the end point of the line has to lie on the specified face.

Parameters:
box - the box
min - minimum coordinates of box
max - maximum coordinates of box
line - a line
all - true for all intersections, false for only the first (closest) intersection has to be added to list
list - the intersections are added to this list
excludeStartFace - face which shall be excluded at start, or -1
excludeEndFace - face which shall be excluded at end, or -1
Returns:
true iff the beginning of the line lies within the box (i.e., if the line starts within the box or enters the box at the starting point)

computeNormal

public void computeNormal(Intersection is,
                          Vector3d normal)
Description copied from interface: Volume
This method computes the unit normal vector of an intersection is which has been computed previously by the invocation of Volume.computeIntersections(de.grogra.vecmath.geom.Line, int, de.grogra.vecmath.geom.IntersectionList, de.grogra.vecmath.geom.Intersection, de.grogra.vecmath.geom.Intersection) on this volume.

Parameters:
is - a previously computed intersection
normal - resulting unit vector is placed in here

computeTangents

public void computeTangents(Intersection is,
                            Vector3d dpdu,
                            Vector3d dpdv)
Description copied from interface: Volume
This method computes the derivatives of the surface point (as function of the uv-coordinates, see Volume.computeUV(de.grogra.vecmath.geom.Intersection, javax.vecmath.Vector2d)) with respect to u and v at the intersection point.

Parameters:
is - a previously computed intersection
dpdu - resulting derivative with respect to u
dpdv - resulting derivative with respect to v

computeUV

public void computeUV(Intersection is,
                      Vector2d uv)
Description copied from interface: Volume
This method computes the uv-coordinates of an intersection point is which has been computed previously by the invocation of Volume.computeIntersections(de.grogra.vecmath.geom.Line, int, de.grogra.vecmath.geom.IntersectionList, de.grogra.vecmath.geom.Intersection, de.grogra.vecmath.geom.Intersection) on this volume.

Parameters:
is - a previously computed intersection
uv - resulting uv-coordinates are placed in here

contains

public boolean contains(Tuple3d point,
                        boolean open)
Description copied from interface: Volume
Determines if the given point lies within this object. If open is true, the interior of the volume is considered (the largest open set contained in the volume, i.e., excluding the boundary), otherwise the closure of the volume.

Parameters:
point - a point in global world coordinates
open - consider open or closed set
Returns:
true iff point is an element of the set

contains

public boolean contains(Tuple3d point,
                        int excludedCoordinate)

getExtent

public void getExtent(Tuple3d min,
                      Tuple3d max,
                      Variables temp)
Description copied from interface: Volume
Computes the extent of this volume, i.e., an axis-aligned bounding box between min and max.

Parameters:
min - minimum coordinates of bounding box are placed in here
max - maximum coordinates of bounding box are placed in here
temp - has to be provided by the invoker, may be used in implementations

testParallelogram

public int testParallelogram(Tuple3d a,
                             Tuple3d b,
                             Tuple3d c,
                             Tuple3d d,
                             Matrix3d inv,
                             Vector3d normal,
                             Vector3d v)
Determines if the specified parallelogram intersects this bounding box. The parallelogram has to specified by the oriented list (a, b, c, d) of its corners.

Parameters:
a - first corner of parallelogram
b - second corner of parallelogram
c - third corner of parallelogram
d - fourth corner of parallelogram
inv - this matrix will be used internally by the method
normal - this vector will be used internally by the method
v - this vector will be used internally by the method
Returns:
one of INTERSECTION, NO_INTERSECTION, ABOVE, BELOW

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object