Class BoundingBox
- All Implemented Interfaces:
Serializable
,Comparable<BoundingBox>
A bounding-box in two dimensions should always set it's z-dimension's extent to 1
.
This is an immutable class. No operation modifies the state of the existing object.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionBoundingBox
(Extent extent) Constructs a bounding-box to cover the entirety of a certain extent. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Does the bounding-box have an edge at the border of an image of sizeextent
?boolean
atBorderXY
(Extent extent) LikeatBorder(Extent)
but considers only the X- and Y- dimensions.boolean
LikeatBorder(Extent)
but considers only the Z-dimension.The maximum (right-most) point just outside the box.The maximum (right-most) point inside the box.A mid-point in the bounding-box, corresponding to the mean of all points inside the box.changeExtent
(UnaryOperator<Extent> extentOperator) Creates a copiedBoundingBox
but with a different extent.changeExtent
(Extent extent) Creates a copiedBoundingBox
but with a different extent.changeExtentZ
(int extentZ) Creates a copiedBoundingBox
but with a different extent in the Z-dimension.changeZ
(int cornerZ, int extentZ) Creates a copiedBoundingBox
but with a different corner and extent in the Z-dimension.Ensures that the box fits inside aExtent
by reducing any values to their limits in the respective dimension.int
compareTo
(BoundingBox other) contains()
For evaluating whether this bounding-box contains other points, boxes etc.?The minimum corner of the bounding box in each dimension.static BoundingBox
createDuplicate
(ReadableTuple3i cornerMin, Extent extent) Creates a bounding-box from a corner and an extent - duplicatingcornerMin
.static BoundingBox
createDuplicate
(ReadableTuple3i cornerMinInclusive, ReadableTuple3i cornerMaxInclusive) Creates from twoint
points (a minimum corner and a maximum corner) - reusingcornerMinInclusive
internally.static BoundingBox
createReuse
(Point3d cornerMinInclusive, Point3d cornerMaxInclusive) Creates from twodouble
points (a minimum corner and a maximum corner).static BoundingBox
createReuse
(ReadableTuple3i cornerMin, Extent extent) Creates a bounding-box from a corner and an extent - reusingcornerMin
internally.static BoundingBox
createReuse
(ReadableTuple3i cornerMinInclusive, ReadableTuple3i cornerMaxInclusive) Creates from twoint
points (a minimum corner and a maximum corner) - reusingcornerMinInclusive
internally.boolean
extent()
Dimensions in pixels needed to represent the bounding box.flattenZ()
Collapses the z-dimension of the box to a single voxel depth, and a corner at0
voxels.Grow the bounding-box bytoAdd
amount in each dimension in both positive and negative directions.int
hashCode()
For evaluating the intersection between this bounding-box and others.midpoint()
A mid-point in the bounding box, corresponding to the exact half-way point between(corner+extent)/2
.Reflects the bounding box through the origin.relativePositionTo
(BoundingBox other) The relative position of the corner to another bounding box.relativePositionToBox
(BoundingBox other) A new bounding-box using relative position coordinates to another box.scale
(ScaleFactor scaleFactor) Scales the bounding-box, both the corner-point and the extent.scale
(ScaleFactor scaleFactor, Extent extentToAssign) Scales the bounding-box corner-point, and assigns a new extent.scaleClampTo
(ScaleFactor scaleFactor, Extent clampTo) Scales the bounding-box, both the corner-point and the extent - ensuring it remains inside a containing-extent.shiftBackBy
(ReadableTuple3i shift) Shifts the bounding-box backwards.shiftBy
(ReadableTuple3i shift) Shifts the bounding-box forwards.shiftTo
(ReadableTuple3i cornerMinToAssign) Assigns a new corner-location to the bounding-box.Moves the bounding-box to the origin (0,0,0) but preserves the extent.shiftToZ
(int cornerZToAssign) Assigns a new z-slice corner-location to the bounding-box.toString()
union()
For performing a union between this bounding-box and another.
-
Constructor Details
-
BoundingBox
Constructs a bounding-box to cover the entirety of a certain extent.- Parameters:
extent
- the extent.
-
-
Method Details
-
createReuse
Creates a bounding-box from a corner and an extent - reusingcornerMin
internally.The
cornerMin
is not duplicated before being stored internally. It should not be subsequently modified externally.{code cornerMin} will also never be changed internally, so it is safe to pass a constant using this method.
See
createDuplicate(ReadableTuple3i, Extent)
for an alternative that duplicatescornerMin
.- Parameters:
cornerMin
- the corner that is the minimum point in all dimensions for the bounding-box.extent
- the size of the bounding-box emanating fromcornerMin
.- Returns:
- the newly created
BoundingBox
.
-
createDuplicate
Creates a bounding-box from a corner and an extent - duplicatingcornerMin
.The
cornerMin
is duplicated before being stored internally. This makes it safe to further modify it externally.See
createReuse(ReadableTuple3i, Extent)
for an alternative that does not duplicatecornerMin
.- Parameters:
cornerMin
- the corner that is the minimum point in all dimensions for the bounding-box.extent
- the size of the bounding-box emanating fromcornerMin
.- Returns:
- the newly created
BoundingBox
.
-
createReuse
public static BoundingBox createReuse(ReadableTuple3i cornerMinInclusive, ReadableTuple3i cornerMaxInclusive) Creates from twoint
points (a minimum corner and a maximum corner) - reusingcornerMinInclusive
internally.The
cornerMin
is not duplicated before being stored internally. It should not be subsequently modified externally.{code cornerMin} will also never be changed internally, so it is safe to pass a constant using this method.
- Parameters:
cornerMinInclusive
- minimum point in each dimension of the bounding-box (that exists inside the box).cornerMaxInclusive
- maximum point in each dimension of the bounding-box (that exists inside the box).- Returns:
- the newly created
BoundingBox
.
-
createDuplicate
public static BoundingBox createDuplicate(ReadableTuple3i cornerMinInclusive, ReadableTuple3i cornerMaxInclusive) Creates from twoint
points (a minimum corner and a maximum corner) - reusingcornerMinInclusive
internally.The
cornerMin
is not duplicated before being stored internally. It should not be subsequently modified externally.{code cornerMin} will also never be changed internally, so it is safe to pass a constant using this method.
- Parameters:
cornerMinInclusive
- minimum point in each dimension of the bounding-box (that exists inside the box).cornerMaxInclusive
- maximum point in each dimension of the bounding-box (that exists inside the box).- Returns:
- the newly created
BoundingBox
.
-
createReuse
Creates from twodouble
points (a minimum corner and a maximum corner).Neither
cornerMinInclusive
orcornerMaxInclusive
are used internally, and can be modified as necessary after the call.- Parameters:
cornerMinInclusive
- minimum point in each dimension of the bounding-box (that exists inside the box).cornerMaxInclusive
- maximum point in each dimension of the bounding-box (that exists inside the box).- Returns:
- the newly created
BoundingBox
.
-
midpoint
A mid-point in the bounding box, corresponding to the exact half-way point between(corner+extent)/2
.It may not be integral, possibly ending with
0.5
- Returns:
- a newly created point representing the mid-point.
-
centerOfGravity
A mid-point in the bounding-box, corresponding to the mean of all points inside the box.i.e. in each dimension, it is
(corner+extent-1)/2
It is guaranteed to be integral, by flooring.
This is similar to
midpoint()
but can be marginally shifted left.- Returns:
- the center-of-gravity.
-
flattenZ
Collapses the z-dimension of the box to a single voxel depth, and a corner at0
voxels.- Returns:
- a newly created
BoundingBox
with identical X and Y values, but with the Z dimension flattened.
-
changeExtent
Creates a copiedBoundingBox
but with a different extent.- Parameters:
extent
- the extent to assign.- Returns:
- a newly-created
BoundingBox
that has a changed extent, but is otherwise identical.
-
changeExtent
Creates a copiedBoundingBox
but with a different extent.- Parameters:
extentOperator
- an operator that changes the extent.- Returns:
- a newly-created
BoundingBox
that has a changed extent, but is otherwise identical.
-
changeZ
Creates a copiedBoundingBox
but with a different corner and extent in the Z-dimension.- Parameters:
cornerZ
- the corner to assign in the z-dimension.extentZ
- the extent to assign in the z-dimension.- Returns:
- a newly-created
BoundingBox
that has a changed extent and corner in the Z-dimension, but is otherwise identical.
-
changeExtentZ
Creates a copiedBoundingBox
but with a different extent in the Z-dimension.- Parameters:
extentZ
- the extent to assign in the z-dimension.- Returns:
- a newly-created
BoundingBox
that has a changed extent in the Z-dimension, but is otherwise identical.
-
atBorder
Does the bounding-box have an edge at the border of an image of sizeextent
?The border of the image is defined as the exterior including all voxels that are a minimum or maximum in any given dimension.
- Parameters:
extent
- the size of the image.- Returns:
- true iff the bounding box lies at the border.
-
atBorderXY
LikeatBorder(Extent)
but considers only the X- and Y- dimensions.- Parameters:
extent
- the size of the image.- Returns:
- true iff the bounding box lies at the border along the X-axis or Y-axis.
-
atBorderZ
LikeatBorder(Extent)
but considers only the Z-dimension.- Parameters:
extent
- the size of the image.- Returns:
- true iff the bounding box lies at the border along the Z-axis.
-
growBy
Grow the bounding-box bytoAdd
amount in each dimension in both positive and negative directions.The box will never be allowed grow larger than
containingExtent
.Unless constrained by the above, the bounding-box's corner and extent will typically both change.
This is an immutable operation and current state will not be affected.
- Parameters:
toAdd
- the number of voxels to grow by in each direction. Each component should be non-negative.containingExtent
- an extent the box must never grow beyond, in either the positive or negative directions.- Returns:
- a newly created grown
BoundingBox
as per the above.
-
cornerMin
The minimum corner of the bounding box in each dimension.- Returns:
- the point used internally as a corner (exposed read-only).
-
calculateCornerMaxInclusive
The maximum (right-most) point inside the box.This means that iterators should be
<= calculateCornerMax()
.- Returns:
- a newly created
Point3i
, indicating the maximum point inside the box in each dimension.
-
calculateCornerMaxExclusive
The maximum (right-most) point just outside the box.It is equivalent to
< calculateCornerMax()
plus1
in each dimension.This means that iterators should be
< calculateCornerMaxExclusive()
.- Returns:
- the maximum point inside the box in each dimension
-
clampTo
Ensures that the box fits inside aExtent
by reducing any values to their limits in the respective dimension.Values that are negative are forced to be 0.
Values that are larger than the corresponding dimension in
Extent
are reduced to the maximum permitted in that dimension.- Parameters:
extent
- the extent the box is made fit inside.- Returns:
- a newly created bounding-box, if any changes are needed. Otherwise the existing object is reused.
-
relativePositionTo
The relative position of the corner to another bounding box.- Parameters:
other
- the other box, against whom we consider our coordinates relatively.- Returns:
- the difference between corners i.e.
other bounding-box's corner - this bounding-box's corner
.
-
relativePositionToBox
A new bounding-box using relative position coordinates to another box.- Parameters:
other
- the other box, against whom we consider our coordinates relatively.- Returns:
- a newly created bounding box with relative coordinates.
-
contains
For evaluating whether this bounding-box contains other points, boxes etc.?- Returns:
- a newly-created class to evaluate the contains relationship.
-
intersection
For evaluating the intersection between this bounding-box and others.- Returns:
- a newly-created class to evaluate the intersection relationship.
-
union
For performing a union between this bounding-box and another.- Returns:
- a newly-created class to evaluate the union relationship.
-
toString
-
shiftToOrigin
Moves the bounding-box to the origin (0,0,0) but preserves the extent.- Returns:
- newly-created bounding box with shifted corner position (to the origin) and identical extent.
-
shiftBy
Shifts the bounding-box forwards.i.e. adds a vector to the corner position.
- Parameters:
shift
- what to add to the corner position.- Returns:
- newly created bounding-box with shifted corner position and identical extent.
-
shiftBackBy
Shifts the bounding-box backwards.i.e. subtracts a vector from the corner position.
- Parameters:
shift
- what to subtract from the corner position.- Returns:
- newly created bounding-box with shifted corner position and identical extent.
-
shiftTo
Assigns a new corner-location to the bounding-box.- Parameters:
cornerMinToAssign
- the new corner, which is used internally in the createdBoundingBox
. It should therefore not be modified subsequently externally.- Returns:
- a bounding-box with a new corner and the same extent.
-
shiftToZ
Assigns a new z-slice corner-location to the bounding-box.- Parameters:
cornerZToAssign
- the new value in Z for the corner.- Returns:
- a newly-created bounding-box with a new z-slice corner and the same extent.
-
reflectThroughOrigin
Reflects the bounding box through the origin.i.e.
x, y, z
becomes-x, -y, -z
.- Returns:
- a newly-created bounding-box reflected through the origin.
-
scale
Scales the bounding-box, both the corner-point and the extent.- Parameters:
scaleFactor
- the scaling-factor.- Returns:
- a new bounding-box with scaled corner-point and extent.
-
scaleClampTo
Scales the bounding-box, both the corner-point and the extent - ensuring it remains inside a containing-extent.- Parameters:
scaleFactor
- scaling-factor.clampTo
- clamps scaled-object's bounding-box to ensure it always fit inside (to catch any rounding errors that push the bounding box outside the scene-boundary).- Returns:
- a new bounding-box with scaled corner-point and extent.
-
scale
Scales the bounding-box corner-point, and assigns a new extent.- Parameters:
scaleFactor
- scaling-factor.extentToAssign
- extent to assign.- Returns:
- a new bounding-box with scaled corner-point and the specified extent.
-
compareTo
- Specified by:
compareTo
in interfaceComparable<BoundingBox>
-
equals
-
hashCode
public int hashCode() -
extent
Dimensions in pixels needed to represent the bounding box.This emanates in a positive direction from
cornerMin
to define the complete box.
-