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. ABoxis 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's2D convex hull in screen coordinates. The index to this table is a 6-bit code, where each bit denotes whether one of theBox'ssix 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'splanes can be visible at one time, there are a total of 26 unique vertex combinations that define aBox's2D convex hull in the viewport. Index codes that represent a valid combination of planes facing theViewresult 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'seight 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
Viewmap tonull.
-
-
Field Summary
Fields Modifier and Type Field Description Vec4bottomCenterprotected Vec4centerprotected Plane[]planesprotected static int[][]ProjectionHullTableprotected Vec4rprotected doublerLengthprotected Vec4ruprotected Vec4sprotected doublesLengthprotected Vec4suprotected Vec4tprotected doubletLengthVec4topCenterprotected Vec4tu
-
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.protectedBox(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 BoxcomputeBoundingBox(BufferWrapper coordinates, int stride)Computes aBoxthat bounds a specified buffer of points.static BoxcomputeBoundingBox(java.lang.Iterable<? extends Vec4> points)Compute aBoxthat bounds a specified list of points.protected intcomputeProjectionHullCode(View view)Computes an index into theProjectionHullTablefor thisBoxgiven the specifiedview.protected voiddrawBox(DrawContext dc, Vec4 a, Vec4 b, Vec4 c, Vec4 d)protected voiddrawOutline(DrawContext dc, Vec4 a, Vec4 b, Vec4 c, Vec4 d)booleanequals(java.lang.Object o)Vec4getBottomCenter()Returns the point corresponding to the center of the box side left-most along the R (first) axis.Vec4getCenter()Returns the box's center point.Vec4[]getCorners()Returns the eight corners of the box.doublegetDiameter()Returns the effective diameter of the box as if it were a sphere.doublegetEffectiveRadius(Plane plane)Computes the effective radius of the extent relative to a specified plane.protected doublegetEffectiveRadius2(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.doublegetProjectedArea(View view)Computes the area in square pixels of thisExtentafter it is projected into the specifiedview'sviewport.doublegetRadius()Returns the effective radius of the box as if it were a sphere.Vec4getRAxis()Returns the R (first) axis.doublegetRLength()Returns the length of the R axis.Vec4getSAxis()Returns the S (second) axis.doublegetSLength()Returns the length of the S axis.Vec4getTAxis()Returns the T (third) axis.doublegetTLength()Returns the length of the T axis.Vec4getTopCenter()Returns the point corresponding to the center of the box side right-most along the R (first) axis.Vec4getUnitRAxis()Returns the R (first) axis in unit length.Vec4getUnitSAxis()Returns the S (second) axis in unit length.Vec4getUnitTAxis()Returns the T (third) axis in unit length.inthashCode()Intersection[]intersect(Line line)Computes the intersections of this extent withline.booleanintersects(Frustum frustum)Determines whether or not thisExtentintersectsfrustum.booleanintersects(Line line)Determines whether or notlineintersects thisExtent.booleanintersects(Plane plane)Calculate whether or not thisExtentis intersected byplane.protected doubleintersects(Plane plane, double effectiveRadius)protected doubleintersectsAt(Plane plane, double effectiveRadius, Vec4[] endpoints)voidrender(DrawContext dc)Draws a representation of theBox.Boxtranslate(Vec4 point)static Boxunion(java.lang.Iterable<? extends Box> iterable)Computes aBoxthat 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:
getDiameterin 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 aBoxthat 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
Boxclass overview. - Throws:
java.lang.IllegalArgumentException- if the point list is null or empty.
-
computeBoundingBox
public static Box computeBoundingBox(BufferWrapper coordinates, int stride)
Computes aBoxthat 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
Boxclass 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 aBoxthat represents the union of one or moreBoxes. If the iterable has two or more non-nullBoxes, the returned encloses theBoxes. In this case axes and center point of the returnedBoxmay differ from theBoxes. If the iterable has only one non-nullBox, this returns that soleBox. This returnsnullif the iterable is empty or contains onlynullreferences.- Parameters:
iterable- an iterable ofBoxesto enclose.- Returns:
- a new
Boxthat encloses the specified iterable ofBoxes. - Throws:
java.lang.IllegalArgumentException- if theiterableis null.
-
intersects
public boolean intersects(Frustum frustum)
Determines whether or not thisExtentintersectsfrustum. Returns true if any part of these two objects intersect, including the case where either object wholly contains the other, false otherwise.- Specified by:
intersectsin interfaceExtent- Parameters:
frustum- theFrustumwith 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:
getEffectiveRadiusin 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 thisExtentis intersected byplane.- Specified by:
intersectsin interfaceExtent- Parameters:
plane- thePlanewith which to test for intersection.- Returns:
- true if
planeis 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.lineis considered to have infinite length in both directions.
-
intersects
public boolean intersects(Line line)
Determines whether or notlineintersects 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:
intersectsin interfaceExtent- Parameters:
line- theLinewith 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 thisExtentafter it is projected into the specifiedview'sviewport. The returned value is the screen area that thisExtentcovers in the infinite plane defined by theview'sviewport. This area is not limited to the size of theview'sviewport, and portions of thisExtentare not clipped by theview'sfrustum.This returns
Double.POSITIVE_INFINITYif theview'seye point is inside thisExtent, or if any portion of thisExtentis behind the eye point. In either case, thisExtenthas no finite projection on theview.- Specified by:
getProjectedAreain interfaceExtent- Parameters:
view- theViewfor which to compute a projected screen area.- Returns:
- the projected screen area of this
Extentin square pixels, orDouble.POSITIVE_INFINITYif theview'seye point is inside thisExtentor part of thisExtentis behind theview'seye point.
-
computeProjectionHullCode
protected int computeProjectionHullCode(View view)
Computes an index into theProjectionHullTablefor thisBoxgiven the specifiedview. The returned integer is a 6-bit code, where each bit denotes whether one of thisBox'ssix planes faces theView. See the documentation forfor details.ProjectionHullTableIf the
viewis inside thisBox, this returns 0 indicating that none of thisBox'splanes face theview.- Parameters:
view- theViewto 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:
renderin interfaceRenderable- Parameters:
dc- theDrawContextto 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:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
-