Class Box
- java.lang.Object
-
- gov.nasa.worldwind.geom.Box
-
- All Implemented Interfaces:
Extent
,Renderable
public class Box extends java.lang.Object implements Extent, Renderable
An arbitrarily oriented box, typically used as a oriented bounding volume for a collection of points or shapes. ABox
is defined by three orthogonal axes and two positions along each of those axes. Each of the positions specifies the location of a box side along the respective axis. The three axes are named by convention "R", "S" and "T", and are ordered by decreasing length -- R is the longest axis, followed by S and then T.The static class field,
ProjectionHullTable
, defines a table of all possible vertex combinations representing aBox's
2D convex hull in screen coordinates. The index to this table is a 6-bit code, where each bit denotes whether one of theBox's
six planes faces theView
. This code is organized as follows:Bit Mapping Bit 5 4 3 2 1 0 Code left right back front bottom top Since at most three of a
Box's
planes can be visible at one time, there are a total of 26 unique vertex combinations that define aBox's
2D convex hull in the viewport. Index codes that represent a valid combination of planes facing theView
result in an array of 4 or 6 integers (depending on whether one, two or three planes face theView
), where each element in the array is an index for one of theBox's
eight vertices as follows:Index Mapping Index 0 1 2 3 4 5 6 7 Vertex bottom-lower-left bottom-lower-right bottom-upper-right bottom-upper-left top-lower-left top-lower-right top-upper-right top-upper-left The vertices are organized so that they appear in counter-clockwise order on the screen. Index codes that represent an invalid combination of planes facing the
View
map tonull
.
-
-
Field Summary
Fields Modifier and Type Field Description Vec4
bottomCenter
protected Vec4
center
protected Plane[]
planes
protected static int[][]
ProjectionHullTable
protected Vec4
r
protected double
rLength
protected Vec4
ru
protected Vec4
s
protected double
sLength
protected Vec4
su
protected Vec4
t
protected double
tLength
Vec4
topCenter
protected Vec4
tu
-
Constructor Summary
Constructors Modifier Constructor Description Box(Vec4 point)
Construct a unit-length cube centered at a specified point.Box(Vec4[] axes, double rMin, double rMax, double sMin, double sMax, double tMin, double tMax)
Construct a box from three specified unit axes and the locations of the box faces relative to those axes.protected
Box(Vec4 bottomCenter, Vec4 topCenter, Vec4 center, Vec4 r, Vec4 s, Vec4 t, Vec4 ru, Vec4 su, Vec4 tu, double rlength, double sLength, double tLength, Plane[] planes)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static Box
computeBoundingBox(BufferWrapper coordinates, int stride)
Computes aBox
that bounds a specified buffer of points.static Box
computeBoundingBox(java.lang.Iterable<? extends Vec4> points)
Compute aBox
that bounds a specified list of points.protected int
computeProjectionHullCode(View view)
Computes an index into theProjectionHullTable
for thisBox
given the specifiedview
.protected void
drawBox(DrawContext dc, Vec4 a, Vec4 b, Vec4 c, Vec4 d)
protected void
drawOutline(DrawContext dc, Vec4 a, Vec4 b, Vec4 c, Vec4 d)
boolean
equals(java.lang.Object o)
Vec4
getBottomCenter()
Returns the point corresponding to the center of the box side left-most along the R (first) axis.Vec4
getCenter()
Returns the box's center point.Vec4[]
getCorners()
Returns the eight corners of the box.double
getDiameter()
Returns the effective diameter of the box as if it were a sphere.double
getEffectiveRadius(Plane plane)
Computes the effective radius of the extent relative to a specified plane.protected double
getEffectiveRadius2(Plane plane)
Returns the effective radius of this box relative to a specified plane, using only this box's S and T axes.Plane[]
getPlanes()
Returns the six planes of the box.double
getProjectedArea(View view)
Computes the area in square pixels of thisExtent
after it is projected into the specifiedview's
viewport.double
getRadius()
Returns the effective radius of the box as if it were a sphere.Vec4
getRAxis()
Returns the R (first) axis.double
getRLength()
Returns the length of the R axis.Vec4
getSAxis()
Returns the S (second) axis.double
getSLength()
Returns the length of the S axis.Vec4
getTAxis()
Returns the T (third) axis.double
getTLength()
Returns the length of the T axis.Vec4
getTopCenter()
Returns the point corresponding to the center of the box side right-most along the R (first) axis.Vec4
getUnitRAxis()
Returns the R (first) axis in unit length.Vec4
getUnitSAxis()
Returns the S (second) axis in unit length.Vec4
getUnitTAxis()
Returns the T (third) axis in unit length.int
hashCode()
Intersection[]
intersect(Line line)
Computes the intersections of this extent withline
.boolean
intersects(Frustum frustum)
Determines whether or not thisExtent
intersectsfrustum
.boolean
intersects(Line line)
Determines whether or notline
intersects thisExtent
.boolean
intersects(Plane plane)
Calculate whether or not thisExtent
is intersected byplane
.protected double
intersects(Plane plane, double effectiveRadius)
protected double
intersectsAt(Plane plane, double effectiveRadius, Vec4[] endpoints)
void
render(DrawContext dc)
Draws a representation of theBox
.Box
translate(Vec4 point)
static Box
union(java.lang.Iterable<? extends Box> iterable)
Computes aBox
that represents the union of one or moreBoxes
.
-
-
-
Field Detail
-
ProjectionHullTable
protected static final int[][] ProjectionHullTable
-
bottomCenter
public Vec4 bottomCenter
-
topCenter
public Vec4 topCenter
-
center
protected final Vec4 center
-
r
protected final Vec4 r
-
s
protected final Vec4 s
-
t
protected final Vec4 t
-
ru
protected final Vec4 ru
-
su
protected final Vec4 su
-
tu
protected final Vec4 tu
-
rLength
protected final double rLength
-
sLength
protected final double sLength
-
tLength
protected final double tLength
-
planes
protected final Plane[] planes
-
-
Constructor Detail
-
Box
protected Box(Vec4 bottomCenter, Vec4 topCenter, Vec4 center, Vec4 r, Vec4 s, Vec4 t, Vec4 ru, Vec4 su, Vec4 tu, double rlength, double sLength, double tLength, Plane[] planes)
-
Box
public Box(Vec4[] axes, double rMin, double rMax, double sMin, double sMax, double tMin, double tMax)
Construct a box from three specified unit axes and the locations of the box faces relative to those axes. The box faces are specified by two scalar locations along each axis, each location indicating a face. The non-unit length of an axis is the distance between its respective two locations. The longest side is specified first, followed by the second longest side and then the shortest side.The axes are normally principal axes computed from a collection of points in order to form an oriented bounding volume. See
WWMath.computePrincipalAxes(Iterable)
.Note: No check is made to ensure the order of the face locations.
- Parameters:
axes
- the unit-length axes.rMin
- the location along the first axis corresponding to the left-most box side relative to the axis.rMax
- the location along the first axis corresponding to the right-most box side relative to the axis.sMin
- the location along the second axis corresponding to the left-most box side relative to the axis.sMax
- the location along the second axis corresponding to the right-most box side relative to the axis.tMin
- the location along the third axis corresponding to the left-most box side relative to the axis.tMax
- the location along the third axis corresponding to the right-most box side relative to the axis.- Throws:
java.lang.IllegalArgumentException
- if the axes array or one of its entries is null.
-
Box
public Box(Vec4 point)
Construct a unit-length cube centered at a specified point.- Parameters:
point
- the center of the cube.- Throws:
java.lang.IllegalArgumentException
- if the point is null.
-
-
Method Detail
-
getCenter
public Vec4 getCenter()
Returns the box's center point.
-
getBottomCenter
public Vec4 getBottomCenter()
Returns the point corresponding to the center of the box side left-most along the R (first) axis.- Returns:
- the bottom-center point.
-
getTopCenter
public Vec4 getTopCenter()
Returns the point corresponding to the center of the box side right-most along the R (first) axis.- Returns:
- the top-center point.
-
getRAxis
public Vec4 getRAxis()
Returns the R (first) axis. The axis length is the distance between the box sides perpendicular to the axis.- Returns:
- the R axis.
-
getSAxis
public Vec4 getSAxis()
Returns the S (second) axis. The axis length is the distance between the box sides perpendicular to the axis.- Returns:
- the S axis.
-
getTAxis
public Vec4 getTAxis()
Returns the T (third) axis. The axis length is the distance between the box sides perpendicular to the axis.- Returns:
- the T axis.
-
getUnitRAxis
public Vec4 getUnitRAxis()
Returns the R (first) axis in unit length.- Returns:
- the unit R axis.
-
getUnitSAxis
public Vec4 getUnitSAxis()
Returns the S (second) axis in unit length.- Returns:
- the unit S axis.
-
getUnitTAxis
public Vec4 getUnitTAxis()
Returns the T (third) axis in unit length.- Returns:
- the unit T axis.
-
getCorners
public Vec4[] getCorners()
Returns the eight corners of the box.- Returns:
- the eight box corners in the order bottom-lower-left, bottom-lower-right, bottom-upper-right, bottom-upper-left, top-lower-left, top-lower-right, top-upper-right, top-upper-left.
-
getPlanes
public Plane[] getPlanes()
Returns the six planes of the box. The plane normals are directed outwards from the box.- Returns:
- the six box planes in the order R-min, R-max, S-min, S-max, T-min, T-max.
-
getRLength
public double getRLength()
Returns the length of the R axis.- Returns:
- the length of the R axis.
-
getSLength
public double getSLength()
Returns the length of the S axis.- Returns:
- the length of the S axis.
-
getTLength
public double getTLength()
Returns the length of the T axis.- Returns:
- the length of the T axis.
-
getDiameter
public double getDiameter()
Returns the effective diameter of the box as if it were a sphere. The length returned is the square root of the sum of the squares of axis lengths.- Specified by:
getDiameter
in interfaceExtent
- Returns:
- the effective diameter of the box.
-
getRadius
public double getRadius()
Returns the effective radius of the box as if it were a sphere. The length returned is half the square root of the sum of the squares of axis lengths.
-
computeBoundingBox
public static Box computeBoundingBox(java.lang.Iterable<? extends Vec4> points)
Compute aBox
that bounds a specified list of points. Principal axes are computed for the points and used to form aBox
.- Parameters:
points
- the points for which to compute a bounding volume.- Returns:
- the bounding volume, with axes lengths consistent with the conventions described in the
Box
class overview. - Throws:
java.lang.IllegalArgumentException
- if the point list is null or empty.
-
computeBoundingBox
public static Box computeBoundingBox(BufferWrapper coordinates, int stride)
Computes aBox
that bounds a specified buffer of points. Principal axes are computed for the points and used to form aBox
.The buffer must contain XYZ coordinate tuples which are either tightly packed or offset by the specified stride. The stride specifies the number of buffer elements between the first coordinate of consecutive tuples. For example, a stride of 3 specifies that each tuple is tightly packed as XYZXYZXYZ, whereas a stride of 5 specifies that there are two elements between each tuple as XYZabXYZab (the elements "a" and "b" are ignored). The stride must be at least 3. If the buffer's length is not evenly divisible into stride-sized tuples, this ignores the remaining elements that follow the last complete tuple.
- Parameters:
coordinates
- the buffer containing the point coordinates for which to compute a bounding volume.stride
- the number of elements between the first coordinate of consecutive points. If stride is 3, this interprets the buffer has having tightly packed XYZ coordinate tuples.- Returns:
- the bounding volume, with axes lengths consistent with the conventions described in the
Box
class overview. - Throws:
java.lang.IllegalArgumentException
- if the buffer is null or empty, or if the stride is less than three.
-
union
public static Box union(java.lang.Iterable<? extends Box> iterable)
Computes aBox
that represents the union of one or moreBoxes
. If the iterable has two or more non-null
Boxes
, the returned encloses theBoxes
. In this case axes and center point of the returnedBox
may differ from theBoxes
. If the iterable has only one non-null
Box
, this returns that soleBox
. This returnsnull
if the iterable is empty or contains onlynull
references.- Parameters:
iterable
- an iterable ofBoxes
to enclose.- Returns:
- a new
Box
that encloses the specified iterable ofBoxes
. - Throws:
java.lang.IllegalArgumentException
- if theiterable
is null.
-
intersects
public boolean intersects(Frustum frustum)
Determines whether or not thisExtent
intersectsfrustum
. Returns true if any part of these two objects intersect, including the case where either object wholly contains the other, false otherwise.- Specified by:
intersects
in interfaceExtent
- Parameters:
frustum
- theFrustum
with which to test for intersection.- Returns:
- true if there is an intersection, false otherwise.
-
getEffectiveRadius2
protected double getEffectiveRadius2(Plane plane)
Returns the effective radius of this box relative to a specified plane, using only this box's S and T axes. This is an optimization available when using the effective radius to test the distance from a plane to the line segment along this box's R axis, as is done in this class'intersects(Frustum)
method. See Lengyel, 2 Ed, Section 7.2.4.- Parameters:
plane
- the plane in question.- Returns:
- the effective radius of this box relative to the specified plane, using only this box's S and T axes to determine the effective radius.
-
getEffectiveRadius
public double getEffectiveRadius(Plane plane)
Computes the effective radius of the extent relative to a specified plane.- Specified by:
getEffectiveRadius
in interfaceExtent
- Parameters:
plane
- the plane.- Returns:
- the effective radius, or 0 if the plane is null.
-
intersects
public boolean intersects(Plane plane)
Calculate whether or not thisExtent
is intersected byplane
.- Specified by:
intersects
in interfaceExtent
- Parameters:
plane
- thePlane
with which to test for intersection.- Returns:
- true if
plane
is found to intersect thisExtent
.
-
intersects
protected double intersects(Plane plane, double effectiveRadius)
-
intersect
public Intersection[] intersect(Line line)
Computes the intersections of this extent withline
. The returned array may be either null or of zero length if no intersections are discovered. It does not contain null elements. Tangential intersections are marked as such.line
is considered to have infinite length in both directions.
-
intersects
public boolean intersects(Line line)
Determines whether or notline
intersects thisExtent
. This method may be faster than checking the size of the array returned byintersect(Line)
. Implementing methods must ensure that this method returns true if and only ifintersect(Line)
returns a non-null array containing at least one element.- Specified by:
intersects
in interfaceExtent
- Parameters:
line
- theLine
with which to test for intersection.- Returns:
- true if an intersection is found, false otherwise.
-
getProjectedArea
public double getProjectedArea(View view)
Computes the area in square pixels of thisExtent
after it is projected into the specifiedview's
viewport. The returned value is the screen area that thisExtent
covers in the infinite plane defined by theview's
viewport. This area is not limited to the size of theview's
viewport, and portions of thisExtent
are not clipped by theview's
frustum.This returns
Double.POSITIVE_INFINITY
if theview's
eye point is inside thisExtent
, or if any portion of thisExtent
is behind the eye point. In either case, thisExtent
has no finite projection on theview
.- Specified by:
getProjectedArea
in interfaceExtent
- Parameters:
view
- theView
for which to compute a projected screen area.- Returns:
- the projected screen area of this
Extent
in square pixels, orDouble.POSITIVE_INFINITY
if theview's
eye point is inside thisExtent
or part of thisExtent
is behind theview's
eye point.
-
computeProjectionHullCode
protected int computeProjectionHullCode(View view)
Computes an index into theProjectionHullTable
for thisBox
given the specifiedview
. The returned integer is a 6-bit code, where each bit denotes whether one of thisBox's
six planes faces theView
. See the documentation for
for details.ProjectionHullTable
If the
view
is inside thisBox
, this returns 0 indicating that none of thisBox's
planes face theview
.- Parameters:
view
- theView
to compute a lookup index for.- Returns:
- an integer who's first 6 bits define an index into the
ProjectionHullTable
.
-
render
public void render(DrawContext dc)
Draws a representation of theBox
.- Specified by:
render
in interfaceRenderable
- Parameters:
dc
- theDrawContext
to be used.- See Also:
DrawContext
-
drawBox
protected void drawBox(DrawContext dc, Vec4 a, Vec4 b, Vec4 c, Vec4 d)
-
drawOutline
protected void drawOutline(DrawContext dc, Vec4 a, Vec4 b, Vec4 c, Vec4 d)
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
-