BoundingBox¶
voxel.BoundingBox(center=None, rotation=None, extent=None)
¶
An oriented 3D bounding box defined by a center, rotation, and half-length extent. Instances are immutable: all modifying operations return new boxes, and the corner points are computed lazily and cached.
Parameters:
-
center(Tensor, default:None) –Box center of shape (3,). Defaults to the origin.
-
rotation(Tensor, default:None) –Box rotation matrix of shape (3, 3). Defaults to the identity.
-
extent(Tensor, default:None) –Non-negative box half-lengths of shape (3,). Defaults to ones.
center: torch.Tensor
property
¶
Box center coordinate of shape (3,).
rotation: torch.Tensor
property
¶
Box rotation matrix of shape (3, 3), with columns as box axes.
extent: torch.Tensor
property
¶
Box half-lengths of shape (3,) along each box axis.
device: torch.device
property
¶
Device of the box parameters.
from_min_max(min_point, max_point) -> BoundingBox
classmethod
¶
Construct an axis-aligned bounding box from lower and upper corner coordinates.
Parameters:
-
min_point(Tensor) –Lower corner coordinate of shape (3,).
-
max_point(Tensor) –Upper corner coordinate of shape (3,).
Returns:
-
BoundingBox–Axis-aligned bounding box.
from_points(points) -> BoundingBox
classmethod
¶
Construct an axis-aligned bounding box enclosing a point cloud.
Parameters:
-
points(Tensor) –Coordinate point cloud of shape (N, 3).
Returns:
-
BoundingBox–Axis-aligned bounding box.
to(device) -> BoundingBox
¶
Move all bounding box parameters to a device.
Parameters:
-
device(device) –The target device.
Returns:
-
BoundingBox–A new bounding box instance.
cpu() -> BoundingBox
¶
cuda() -> BoundingBox
¶
detach() -> BoundingBox
¶
Detach all bounding box parameters from the current graph.
Returns:
-
BoundingBox–A new bounding box instance.
save(filename) -> None
¶
Save the bounding box to file.
Parameters:
-
filename(Path) –File destination.
corner_points() -> torch.Tensor
¶
Compute the corner points of the bounding box. The result is cached after the first call.
Returns:
-
Tensor–Corner point tensor of shape (8, 3).
min_max_coords() -> tuple[torch.Tensor, torch.Tensor]
¶
Compute the minimum and maximum coordinates of the bounding box.
Returns:
-
tuple–Minimum and maximum coordinates.
mesh() -> vx.Mesh
¶
Construct a rectangular box mesh with outward-facing windings from the bounding box.
Returns:
-
Mesh–Rectangular box mesh.
geometry(spacing=None, *components) -> vx.AcquisitionGeometry
¶
Construct an acquisition geometry from the bounding box.
Parameters:
-
spacing(float or Tensor, default:None) –Desired voxel spacing of the geometry. Defaults to ones.
-
*components(float, default:()) –Additional components of
spacing, allowing values to be passed as separate positional arguments, e.g.geometry(1, 1, 2).
Returns:
-
AcquisitionGeometry–Acquisition geometry.
shift(delta, *components) -> BoundingBox
¶
Translate the bounding box center.
Parameters:
-
delta(float or Tensor) –Translation delta, as a scalar or (3,) tensor, applied in the ambient coordinate frame.
-
*components(float, default:()) –Additional components of
delta, allowing values to be passed as separate positional arguments, e.g.shift(1, 0, 0).
Returns:
-
BoundingBox–Shifted bounding box.
scale(factor, *components) -> BoundingBox
¶
Scale the bounding box extent about its center.
Parameters:
-
factor(float or Tensor) –Scaling factor, as a scalar or (3,) tensor of per-axis factors in the box frame.
-
*components(float, default:()) –Additional components of
factor, allowing values to be passed as separate positional arguments, e.g.scale(1, 1, 2).
Returns:
-
BoundingBox–Scaled bounding box.
pad(margin, *components) -> BoundingBox
¶
Pad (or shrink) the bounding box sides by a margin.
Parameters:
-
margin(float or Tensor) –Margin delta for each side of the box, in box-frame units. Can be a scalar, a (3,) tensor of per-axis margins, or a (3, 2) tensor of per-side (lower, upper) margins. Negative values shrink the box.
-
*components(float, default:()) –Additional components of
margin, allowing values to be passed as separate positional arguments, e.g.pad(1, 2, 3).
Returns:
-
BoundingBox–Padded bounding box.
trim(margin, *components) -> BoundingBox
¶
Trim the bounding box sides by a margin. This is the inverse of pad.
Parameters:
-
margin(float or Tensor) –Margin delta for each side of the box, in box-frame units. Can be a scalar, a (3,) tensor of per-axis margins, or a (3, 2) tensor of per-side (lower, upper) margins.
-
*components(float, default:()) –Additional components of
margin, allowing values to be passed as separate positional arguments, e.g.trim(1, 2, 3).
Returns:
-
BoundingBox–Trimmed bounding box.
rotate(rotation, *components, degrees=True) -> BoundingBox
¶
Applies a rotation to the bounding box.
Parameters:
-
rotation(Tensor) –Rotation angles. If
degreesis True, the angles are in degrees, otherwise they are in radians. -
*components(float, default:()) –Additional components of
rotation, allowing angles to be passed as separate positional arguments, e.g.rotate(0, 0, 45). -
degrees(bool, default:True) –Whether the angles are defined as degrees or, alternatively, as radians.
Returns:
-
BoundingBox–Rotated bounding box.
transform(matrix) -> BoundingBox
¶
Transform the bounding box through an affine matrix. This is exact as long as the box axes remain orthogonal under the transform (any rotation combined with scaling along the box axes), and an approximation under shear.
Parameters:
-
matrix(AffineMatrix) –Affine transform to apply.
Returns:
-
BoundingBox–Transformed bounding box.
fit_extent(points) -> BoundingBox
¶
Fit the extent of the bounding box to a set of points, keeping the current rotation.
Parameters:
-
points(Tensor, BoundingBox, Mesh, or AcquisitionGeometry) –Coordinate point cloud of shape (N, 3), or an object defining one.
Returns:
-
BoundingBox–Bounding box with refit extent.
fine_tune(points) -> BoundingBox
¶
Orient the bounding box to minimize the volume of the box enclosing a point cloud.
Parameters:
-
points(Tensor) –Coordinate point cloud of shape (N, 3).
Returns:
-
BoundingBox–Fine-tuned bounding box.