public final class BoundingBox extends Object implements 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.
Constructor and Description |
---|
BoundingBox(Extent extent)
Constructs a bounding-box to cover the entirety of a certain extent.
|
Modifier and Type | Method and Description |
---|---|
boolean |
atBorder(Extent extent)
Does the bounding-box have an edge at the border of an image of size
extent ? |
boolean |
atBorderXY(Extent extent)
Like
atBorder(Extent) but considers only the X- and Y- dimensions. |
boolean |
atBorderZ(Extent extent)
Like
atBorder(Extent) but considers only the Z-dimension. |
ReadableTuple3i |
calculateCornerMaxExclusive()
The maximum (right-most) point just outside the box.
|
ReadableTuple3i |
calculateCornerMaxInclusive()
The maximum (right-most) point inside the box.
|
Point3i |
centerOfGravity()
A mid-point in the bounding-box, corresponding to the mean of all points inside the box.
|
BoundingBox |
changeExtent(Extent extent)
Creates a copied
BoundingBox but with a different extent. |
BoundingBox |
changeExtent(java.util.function.UnaryOperator<Extent> extentOperator)
Creates a copied
BoundingBox but with a different extent. |
BoundingBox |
changeExtentZ(int extentZ)
Creates a copied
BoundingBox but with a different extent in the Z-dimension. |
BoundingBox |
changeZ(int cornerZ,
int extentZ)
Creates a copied
BoundingBox but with a different corner and extent in the
Z-dimension. |
BoundingBox |
clampTo(Extent extent)
Ensures that the box fits inside a
Extent by reducing any values to their limits in
the respective dimension. |
int |
compareTo(BoundingBox other) |
BoundingBoxContains |
contains()
For evaluating whether this bounding-box contains other points, boxes etc.?
|
ReadableTuple3i |
cornerMin()
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 - duplicating
cornerMin . |
static BoundingBox |
createDuplicate(ReadableTuple3i cornerMinInclusive,
ReadableTuple3i cornerMaxInclusive)
Creates from two
int points (a minimum corner and a maximum corner) - reusing cornerMinInclusive internally. |
static BoundingBox |
createReuse(Point3d cornerMinInclusive,
Point3d cornerMaxInclusive)
Creates from two
double 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 - reusing
cornerMin internally. |
static BoundingBox |
createReuse(ReadableTuple3i cornerMinInclusive,
ReadableTuple3i cornerMaxInclusive)
Creates from two
int points (a minimum corner and a maximum corner) - reusing cornerMinInclusive internally. |
boolean |
equals(Object o) |
Extent |
extent()
Dimensions in pixels needed to represent the bounding box.
|
BoundingBox |
flattenZ()
Collapses the z-dimension of the box to a single voxel depth, and a corner at
0
voxels. |
BoundingBox |
growBy(Tuple3i toAdd,
Extent containingExtent)
Grow the bounding-box by
toAdd amount in each dimension in both positive and negative
directions. |
int |
hashCode() |
BoundingBoxIntersection |
intersection()
For evaluating the intersection between this bounding-box and others.
|
Point3d |
midpoint()
A mid-point in the bounding box, corresponding to the exact half-way point between
(corner+extent)/2 . |
BoundingBox |
reflectThroughOrigin()
Reflects the bounding box through the origin.
|
Point3i |
relativePositionTo(BoundingBox other)
The relative position of the corner to another bounding box.
|
BoundingBox |
relativePositionToBox(BoundingBox other)
A new bounding-box using relative position coordinates to another box.
|
BoundingBox |
scale(ScaleFactor scaleFactor)
Scales the bounding-box, both the corner-point and the extent.
|
BoundingBox |
scale(ScaleFactor scaleFactor,
Extent extentToAssign)
Scales the bounding-box corner-point, and assigns a new extent.
|
BoundingBox |
scaleClampTo(ScaleFactor scaleFactor,
Extent clampTo)
Scales the bounding-box, both the corner-point and the extent - ensuring it remains inside a
containing-extent.
|
BoundingBox |
shiftBackBy(ReadableTuple3i shift)
Shifts the bounding-box backwards.
|
BoundingBox |
shiftBy(ReadableTuple3i shift)
Shifts the bounding-box forwards.
|
BoundingBox |
shiftTo(ReadableTuple3i cornerMinToAssign)
Assigns a new corner-location to the bounding-box.
|
BoundingBox |
shiftToOrigin()
Moves the bounding-box to the origin (0,0,0) but preserves the extent.
|
BoundingBox |
shiftToZ(int cornerZToAssign)
Assigns a new z-slice corner-location to the bounding-box.
|
String |
toString() |
BoundingBoxUnion |
union()
For performing a union between this bounding-box and another.
|
public BoundingBox(Extent extent)
extent
- the extent.public static BoundingBox createReuse(ReadableTuple3i cornerMin, Extent extent)
cornerMin
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 duplicates
cornerMin
.
cornerMin
- the corner that is the minimum point in all dimensions for the bounding-box.extent
- the size of the bounding-box emanating from cornerMin
.BoundingBox
.public static BoundingBox createDuplicate(ReadableTuple3i cornerMin, Extent extent)
cornerMin
.
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
duplicate cornerMin
.
cornerMin
- the corner that is the minimum point in all dimensions for the bounding-box.extent
- the size of the bounding-box emanating from cornerMin
.BoundingBox
.public static BoundingBox createReuse(ReadableTuple3i cornerMinInclusive, ReadableTuple3i cornerMaxInclusive)
int
points (a minimum corner and a maximum corner) - reusing cornerMinInclusive
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.
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).BoundingBox
.public static BoundingBox createDuplicate(ReadableTuple3i cornerMinInclusive, ReadableTuple3i cornerMaxInclusive)
int
points (a minimum corner and a maximum corner) - reusing cornerMinInclusive
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.
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).BoundingBox
.public static BoundingBox createReuse(Point3d cornerMinInclusive, Point3d cornerMaxInclusive)
double
points (a minimum corner and a maximum corner).
Neither cornerMinInclusive
or cornerMaxInclusive
are used internally, and
can be modified as necessary after the call.
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).BoundingBox
.public Point3d midpoint()
(corner+extent)/2
.
It may not be integral, possibly ending with 0.5
public Point3i centerOfGravity()
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.
public BoundingBox flattenZ()
0
voxels.BoundingBox
with identical X and Y values, but with the Z
dimension flattened.public BoundingBox changeExtent(Extent extent)
BoundingBox
but with a different extent.extent
- the extent to assign.BoundingBox
that has a changed extent, but is otherwise
identical.public BoundingBox changeExtent(java.util.function.UnaryOperator<Extent> extentOperator)
BoundingBox
but with a different extent.extentOperator
- an operator that changes the extent.BoundingBox
that has a changed extent, but is otherwise
identical.public BoundingBox changeZ(int cornerZ, int extentZ)
BoundingBox
but with a different corner and extent in the
Z-dimension.cornerZ
- the corner to assign in the z-dimension.extentZ
- the extent to assign in the z-dimension.BoundingBox
that has a changed extent and corner in the
Z-dimension, but is otherwise identical.public BoundingBox changeExtentZ(int extentZ)
BoundingBox
but with a different extent in the Z-dimension.extentZ
- the extent to assign in the z-dimension.BoundingBox
that has a changed extent in the Z-dimension, but
is otherwise identical.public boolean atBorder(Extent extent)
extent
?
The border of the image is defined as the exterior including all voxels that are a minimum or maximum in any given dimension.
extent
- the size of the image.public boolean atBorderXY(Extent extent)
atBorder(Extent)
but considers only the X- and Y- dimensions.extent
- the size of the image.public boolean atBorderZ(Extent extent)
atBorder(Extent)
but considers only the Z-dimension.extent
- the size of the image.public BoundingBox growBy(Tuple3i toAdd, Extent containingExtent)
toAdd
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.
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.BoundingBox
as per the above.public ReadableTuple3i cornerMin()
public ReadableTuple3i calculateCornerMaxInclusive()
This means that iterators should be <= calculateCornerMax()
.
Point3i
, indicating the maximum point inside the box in each
dimension.public ReadableTuple3i calculateCornerMaxExclusive()
It is equivalent to < calculateCornerMax()
plus 1
in each dimension.
This means that iterators should be < calculateCornerMaxExclusive()
.
public BoundingBox clampTo(Extent extent)
Extent
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.
extent
- the extent the box is made fit inside.public Point3i relativePositionTo(BoundingBox other)
other
- the other box, against whom we consider our coordinates relatively.other bounding-box's corner - this
bounding-box's corner
.public BoundingBox relativePositionToBox(BoundingBox other)
other
- the other box, against whom we consider our coordinates relatively.public BoundingBoxContains contains()
public BoundingBoxIntersection intersection()
public BoundingBoxUnion union()
public BoundingBox shiftToOrigin()
public BoundingBox shiftBy(ReadableTuple3i shift)
i.e. adds a vector to the corner position.
shift
- what to add to the corner position.public BoundingBox shiftBackBy(ReadableTuple3i shift)
i.e. subtracts a vector from the corner position.
shift
- what to subtract from the corner position.public BoundingBox shiftTo(ReadableTuple3i cornerMinToAssign)
cornerMinToAssign
- the new corner, which is used internally in the created BoundingBox
. It should therefore not be modified subsequently externally.public BoundingBox shiftToZ(int cornerZToAssign)
cornerZToAssign
- the new value in Z for the corner.public BoundingBox reflectThroughOrigin()
i.e. x, y, z
becomes -x, -y, -z
.
public BoundingBox scale(ScaleFactor scaleFactor)
scaleFactor
- the scaling-factor.public BoundingBox scaleClampTo(ScaleFactor scaleFactor, Extent clampTo)
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).public BoundingBox scale(ScaleFactor scaleFactor, Extent extentToAssign)
scaleFactor
- scaling-factor.extentToAssign
- extent to assign.public int compareTo(BoundingBox other)
compareTo
in interface Comparable<BoundingBox>
public Extent extent()
This emanates in a positive direction from cornerMin
to define the complete box.
Copyright © 2010–2023 Owen Feehan, ETH Zurich, University of Zurich, Hoffmann-La Roche. All rights reserved.