custom_trajectory_2d_parallel#

diffct.geometry.custom_trajectory_2d_parallel(n_views, ray_dir_fn, det_origin_fn, start_angle=0.0, device='cuda', dtype=torch.float32)[source]#

Generate custom trajectory geometry for 2D parallel-beam CT using user-defined functions.

Creates a trajectory based on user-provided functions that define the ray direction and detector origin as functions of angle.

Parameters:
  • n_views (int) – Number of projection views.

  • ray_dir_fn (Callable[[torch.Tensor], torch.Tensor]) – Function that takes angles and returns ray directions (n_views, 2).

  • det_origin_fn (Callable[[torch.Tensor], torch.Tensor]) – Function that takes angles and returns detector origins (n_views, 2).

  • start_angle (float, optional) – Starting angle in radians (default: 0.0).

  • device (str or torch.device, optional) – Device for tensors (default: ‘cuda’).

  • dtype (torch.dtype, optional) – Data type for tensors (default: torch.float32).

Returns:

  • ray_dir (torch.Tensor) – Ray direction unit vectors for each view, shape (n_views, 2).

  • det_origin (torch.Tensor) – Detector origin positions for each view, shape (n_views, 2).

  • det_u_vec (torch.Tensor) – Detector u-direction unit vectors for each view, shape (n_views, 2).

Examples

>>> # Define custom trajectory functions
>>> def ray_dirs(angles):
...     dirs = torch.zeros((len(angles), 2), device=angles.device, dtype=angles.dtype)
...     dirs[:, 0] = torch.cos(angles)
...     dirs[:, 1] = torch.sin(angles)
...     return dirs
>>>
>>> def det_origins(angles):
...     origins = torch.zeros((len(angles), 2), device=angles.device, dtype=angles.dtype)
...     return origins
>>>
>>> ray_dir, det_origin, det_u_vec = custom_trajectory_2d_parallel(
...     n_views=180, ray_dir_fn=ray_dirs, det_origin_fn=det_origins
... )