BoundingBox#
- class 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.
- classmethod from_min_max(min_point, max_point) BoundingBox#
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.
- classmethod from_points(points) BoundingBox#
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#
Move all bounding box parameters to the CPU.
- Returns:
BoundingBox – A new bounding box instance.
- cuda() BoundingBox#
Move all bounding box parameters to the GPU.
- Returns:
BoundingBox – A new bounding box instance.
- detach() BoundingBox#
Detach all bounding box parameters from the current graph.
- Returns:
BoundingBox – A new bounding box instance.
- corner_points() 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[Tensor, Tensor]#
Compute the minimum and maximum coordinates of the bounding box.
- Returns:
tuple – Minimum and maximum coordinates.
- mesh() Mesh#
Construct a rectangular box mesh with outward-facing windings from the bounding box.
- Returns:
Mesh – Rectangular box mesh.
- geometry(spacing=None, *components) VolumeGeometry#
Construct an acquisition geometry from the bounding box.
- shift(delta, *components) BoundingBox#
Translate the bounding box center.
- Parameters:
- Returns:
BoundingBox – Shifted bounding box.
- scale(factor, *components) BoundingBox#
Scale the bounding box extent about its center.
- Parameters:
- 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) – 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) – 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) – Additional components of
rotation, allowing angles to be passed as separate positional arguments, e.g.rotate(0, 0, 45).degrees (bool, optional) – 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 VolumeGeometry) – 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.