Transforms

class diffinytrace.transforms.Transform[source]

Bases: SemiFunctionalModule

Base class for coordinate transformations.

This class provides interfaces to transform directions and positions between local and global coordinate systems using homogeneous coordinates.

get_functional_param_args()[source]

Return parameters required for the transformation.

functional(O, *params)[source]

Apply transformation in functional style.

get_transformation_matrix()[source]

Return the 4x4 transformation matrix.

to_global_dir(direction)[source]

Transform direction to global space.

to_local_dir(direction)[source]

Transform direction to local space.

to_global_pos(position)[source]

Transform position to global space.

to_local_pos(position)[source]

Transform position to local space.

get_functional_param_args()[source]

Return parameters required for the transformation which constructs the surfaces through the functional.

Returns:

List of parameters required for the functional which constructs the surfaces.

Return type:

list

static functional(O, *params) Tensor[source]

Apply transformation in functional style. This is global to local.

Parameters:
  • O (torch.Tensor) – Input tensor to be transformed.

  • *params – Parameters for the transformation.

get_transformation_matrix(device=None, dtype=None) Tensor[source]

Return the 4x4 transformation matrix.

Parameters:
  • device (torch.device, optional) – Device for the matrix.

  • dtype (torch.dtype, optional) – Data type for the matrix.

Returns:

4x4 transformation matrix.

Return type:

torch.Tensor

get_transform()[source]

Returns itself.

to_global_dir(direction: Tensor) Tensor[source]

Transform direction to global space. :param direction: Direction vector in local space. :type direction: torch.Tensor

Returns:

Direction vector in global space.

Return type:

torch.Tensor

to_local_dir(direction: Tensor) Tensor[source]

Transform direction to local space. :param direction: Direction vector in global space. :type direction: torch.Tensor

Returns:

Direction vector in local space.

Return type:

torch.Tensor

to_global_pos(position: Tensor) Tensor[source]

Transform position to global space. :param position: Position vector in local space. :type position: torch.Tensor

Returns:

Position vector in global space.

Return type:

torch.Tensor

to_local_pos(position: Tensor) Tensor[source]

Transform position to local space. :param position: Position vector in global space. :type position: torch.Tensor

Returns:

Position vector in local space.

Return type:

torch.Tensor

class diffinytrace.transforms.Identity[source]

Bases: Transform

Identity transformation that returns input positions unchanged.

Example

>>> import diffinytrace as dit
>>> transf1 = dit.transforms.Identity()
get_functional_param_args()[source]

Return parameters required for the transformation which constructs the surfaces through the functional.

Returns:

List of parameters required for the functional which constructs the surfaces.

Return type:

list

static functional(O: Tensor) Tensor[source]

Apply transformation in functional style. This is global to local.

Parameters:
  • O (torch.Tensor) – Input tensor to be transformed.

  • *params – Parameters for the transformation.

get_transformation_matrix(device=None, dtype=None) Tensor[source]

Return the 4x4 transformation matrix.

Parameters:
  • device (torch.device, optional) – Device for the matrix.

  • dtype (torch.dtype, optional) – Data type for the matrix.

Returns:

4x4 transformation matrix.

Return type:

torch.Tensor

class diffinytrace.transforms.Compose(transform_list)[source]

Bases: Transform

Compose multiple transforms in sequence.

Parameters:

transform_list (list[Transform]) – List of transformations to apply in order.

get_functional_param_args()[source]

Return parameters required for the transformation which constructs the surfaces through the functional.

Returns:

List of parameters required for the functional which constructs the surfaces.

Return type:

list

get_transformation_matrix(device=None, dtype=None) Tensor[source]

Return the 4x4 transformation matrix.

Parameters:
  • device (torch.device, optional) – Device for the matrix.

  • dtype (torch.dtype, optional) – Data type for the matrix.

Returns:

4x4 transformation matrix.

Return type:

torch.Tensor

class diffinytrace.transforms.Offset(pos, parent_transform=Identity())[source]

Bases: Transform

Translation transform using an offset vector.

The offset transformation shifts a position by a specified vector ( vec{w} = (w_x, w_y, w_z) ). The transformation matrix ( M ) for an offset transformation is:

\[\begin{split}M^{offset}(w_x, w_y, w_z) = \begin{bmatrix} 1 & 0 & 0 & w_x \\ 0 & 1 & 0 & w_y \\ 0 & 0 & 1 & w_z \\ 0 & 0 & 0 & 1 \end{bmatrix}\end{split}\]

Example

>>> import diffinytrace as dit
>>> transf1 = dit.transforms.Identity()
>>> transf2 = dit.transforms.Offset([1.0, 2.0, 3.0], parent_transform=transf1)
Parameters:
  • pos (Tensor or list or float) – The offset position as a 3D vector.

  • parent_transform (Transform, optional) – Optional parent transformation.

get_functional_param_args()[source]

Return parameters required for the transformation which constructs the surfaces through the functional.

Returns:

List of parameters required for the functional which constructs the surfaces.

Return type:

list

functional(O: Tensor, pos: Tensor, *parent_param_args) Tensor[source]

Apply transformation in functional style. This is global to local.

Parameters:
  • O (torch.Tensor) – Input tensor to be transformed.

  • *params – Parameters for the transformation.

get_transformation_matrix(device=None, dtype=None) Tensor[source]

Return the 4x4 transformation matrix.

Parameters:
  • device (torch.device, optional) – Device for the matrix.

  • dtype (torch.dtype, optional) – Data type for the matrix.

Returns:

4x4 transformation matrix.

Return type:

torch.Tensor

class diffinytrace.transforms.Distance(distance, axis=2, parent_transform=Identity())[source]

Bases: Transform

Applies a translation along a specific axis by a given distance.

The distance transformation applies a translation by a specific distance along a given axis (e.g., ( x )-, ( y )-, or ( z )-axis). The transformation matrix ( M ) for a distance transformation along the ( z )-axis is given by:

\[\begin{split}M^{dist}_z(d) = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & d \\ 0 & 0 & 0 & 1 \end{bmatrix},\end{split}\]

where ( d ) represents the distance of translation along the ( z )-axis.

Parameters:
  • distance (float or Tensor) – Distance to translate.

  • axis (int) – Axis along which translation is applied (0=X, 1=Y, 2=Z).

  • parent_transform (Transform) – Optional parent transformation.

Example

>>> import diffinytrace as dit
>>> transf1 = dit.transforms.Identity()
>>> transf2 = dit.transforms.Distance(10.0,axis=2,parent_transform=transf1)

Notes

For the local to global transformation it applies the following transformation:

\[\mathbf{x}_\text{local} = \mathbf{x}_\text{parent} + d \cdot \mathbf{e}_i\]
get_functional_param_args()[source]

Return parameters required for the transformation which constructs the surfaces through the functional.

Returns:

List of parameters required for the functional which constructs the surfaces.

Return type:

list

functional(O: Tensor, distance: Tensor, unit_vec: Tensor, *parent_param_args) Tensor[source]

Apply transformation in functional style. This is global to local.

Parameters:
  • O (torch.Tensor) – Input tensor to be transformed.

  • *params – Parameters for the transformation.

get_transformation_matrix(device=None, dtype=None) Tensor[source]

Return the 4x4 transformation matrix.

Parameters:
  • device (torch.device, optional) – Device for the matrix.

  • dtype (torch.dtype, optional) – Data type for the matrix.

Returns:

4x4 transformation matrix.

Return type:

torch.Tensor

class diffinytrace.transforms.Rotation(angle: float, axis: int, parent_transform=Identity())[source]

Bases: Transform

Applies a 3D rotation around a principal axis.

The rotational transformation rotates a point or direction around a specific axis (e.g., ( x )-, ( y )-, and ( z )-axis). For example, the rotation matrix around the ( z )-axis is:

\[\begin{split}M^{rot}_z(\theta_z) = \begin{bmatrix} \cos \theta_z & -\sin \theta_z & 0 & 0 \\ \sin \theta_z & \cos \theta_z & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix}\end{split}\]
Parameters:
  • angle (float or Tensor) – Rotation angle in degrees.

  • axis (int) – Axis index (0=X, 1=Y, 2=Z).

  • parent_transform (Transform, optional) – Optional parent transformation.

Example

>>> import diffinytrace as dit
>>> transf1 = dit.transforms.Identity()
>>> transf2 = dit.transforms.Distance(10.0,axis=2,parent_transform=transf1)
>>> transf3 = dit.transforms.Rotation(45.,axis=0,parent_transform=transf2)
get_functional_param_args()[source]

Return parameters required for the transformation which constructs the surfaces through the functional.

Returns:

List of parameters required for the functional which constructs the surfaces.

Return type:

list

functional(O: Tensor, angle: Tensor, *parent_param_args) Tensor[source]

Apply transformation in functional style. This is global to local.

Parameters:
  • O (torch.Tensor) – Input tensor to be transformed.

  • *params – Parameters for the transformation.

get_transformation_matrix(device=None, dtype=None) Tensor[source]

Return the 4x4 transformation matrix.

Parameters:
  • device (torch.device, optional) – Device for the matrix.

  • dtype (torch.dtype, optional) – Data type for the matrix.

Returns:

4x4 transformation matrix.

Return type:

torch.Tensor

diffinytrace.transforms.rotation_matrix_x(angle: Tensor) Tensor[source]

Construct a 3x3 rotation matrix around the X-axis.

Parameters:

angle (Tensor) – Angle in degrees.

Returns:

3x3 rotation matrix.

Return type:

Tensor

diffinytrace.transforms.rotation_matrix_y(angle: Tensor) Tensor[source]

Construct a 3x3 rotation matrix around the Y-axis.

Parameters:

angle (Tensor) – Angle in degrees.

Returns:

3x3 rotation matrix.

Return type:

Tensor

diffinytrace.transforms.rotation_matrix_z(angle: Tensor) Tensor[source]

Construct a 3x3 rotation matrix around the Z-axis.

Parameters:

angle (Tensor) – Angle in degrees.

Returns:

3x3 rotation matrix.

Return type:

Tensor