affine#
- voxel.affine.translation_matrix(translation) AffineMatrix#
Compute a 3D translation matrix from translation vector.
- Parameters:
translation (Tensor) – Translation vector.
- Returns:
AffineMatrix – Translation affine matrix.
- voxel.affine.angles_to_rotation_matrix(rotation, degrees=True, dtype=torch.float32) AffineMatrix#
Compute a 3D rotation matrix from rotation angles, following the standard right-handed convention.
- Parameters:
rotation (Tensor) – Rotation angles (x, y, z). If
degreesis True, the angles are in degrees, otherwise they are in radians.degrees (bool, optional) – Whether the angles are defined as degrees or, alternatively, as radians.
dtype (dtype, optional) – Data type of the generated matrix. Defaults to
float32. Usefloat64to retain full-precision gradients.
- Returns:
AffineMatrix – Rotation affine matrix.
- voxel.affine.quaternion_to_rotation_matrix(quaternion, dtype=torch.float32) AffineMatrix#
Compute a 3D rotation matrix from a quaternion.
The quaternion is expected in scalar-first
(w, x, y, z)order and is normalized to unit length before the matrix is built, so any non-unit input still yields a valid rotation.- Parameters:
quaternion (Tensor) – Quaternion of shape (4,) in
(w, x, y, z)order. It need not be normalized.dtype (dtype, optional) – Data type of the generated matrix. Defaults to
float32. Usefloat64to retain full-precision gradients.
- Returns:
AffineMatrix – Rotation affine matrix.
- voxel.affine.compose_affine(translation=None, rotation=None, scale=None, shear=None, degrees=True, device=None, dtype=torch.float32) AffineMatrix#
Composes an affine matrix from a set of translation, rotation, scale, and shear transform components.
- Parameters:
translation (Tensor, optional) – Translation vector.
rotation (Tensor, optional) – Rotation, given either as euler angles of shape (3,) or as a scalar-first
(w, x, y, z)quaternion.scale (Tensor, optional) – Scaling factors.
shear (Tensor, optional) – Shearing factors.
degrees (bool, optional) – Whether the rotation angles are in degrees.
device (device, optional) – Device of the generated matrix.
dtype (dtype, optional) – Data type of the generated matrix. Defaults to
float32. Usefloat64to retain full-precision gradients.
- Returns:
AffineMatrix – Composed affine matrix.
- voxel.affine.random_affine(max_translation=0, max_rotation=0, max_scaling=0, device=None) AffineMatrix#
Generate a random affine transformation matrix.
- Parameters:
- Returns:
AffineMatrix – Random affine matrix.
- voxel.affine.least_squares_alignment(source, target, weights=None, regularization=1e-6) AffineMatrix#
Compute an affine least squares alignment between two 3D point sets.