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.
Angles follow the standard right-handed convention (a positive rotation
about x carries +y toward +z) and are composed as Rx @ Ry @ Rz,
i.e. intrinsic x-y-z order, consistent with
quaternion_to_rotation_matrix and scipy's Rotation.from_euler('XYZ').
Parameters:
-
rotation(Tensor) –Rotation angles (x, y, z). If
degreesis True, the angles are in degrees, otherwise they are in radians. -
degrees(bool, default:True) –Whether the angles are defined as degrees or, alternatively, as radians.
-
dtype(dtype, default:float32) –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, default:float32) –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, default:None) –Translation vector.
-
rotation(Tensor, default:None) –Rotation, given either as euler angles of shape (3,) or as a scalar-first
(w, x, y, z)quaternion. -
scale(Tensor, default:None) –Scaling factors.
-
shear(Tensor, default:None) –Shearing factors.
-
degrees(bool, default:True) –Whether the rotation angles are in degrees.
-
device(device, default:None) –Device of the generated matrix.
-
dtype(dtype, default:float32) –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:
-
max_translation(float, default:0) –Maximum translation in each direction.
-
max_rotation(float, default:0) –Maximum rotation in each direction.
-
max_scaling(float, default:0) –Maximum fractional scaling in each direction.
-
device(device, default:None) –Device of the generated affine matrix.
Returns:
-
AffineMatrix–Random affine matrix.
voxel.affine.least_squares_alignment(source, target, weights=None, regularization=1e-06) -> AffineMatrix
¶
Compute an affine least squares alignment between two 3D point sets.
Parameters:
-
source(Tensor or Mesh) –Source point set.
-
target(Tensor or Mesh) –Target point set.
-
weights(Tensor, default:None) –Weights for each point in the source set.
-
regularization(float, default:1e-06) –Regularization scale. Default is 1e-6.
Returns:
-
AffineMatrix–Affine alignment matrix.