custom_trajectory_2d_fan#
- diffct.geometry.custom_trajectory_2d_fan(n_views, sid, sdd, source_path_fn, start_angle=0.0, device='cuda', dtype=torch.float32)[source]#
Generate custom trajectory geometry for 2D fan-beam CT using user-defined function.
Creates a trajectory based on a user-provided function that defines the source position as a function of angle and SID.
- Parameters:
n_views (int) – Number of projection views.
sid (float) – Source-to-Isocenter Distance (SID), in physical units.
sdd (float) – Source-to-Detector Distance (SDD), in physical units.
source_path_fn (Callable[[torch.Tensor, float], torch.Tensor]) – Function that takes (angles, sid) and returns source positions (n_views, 2). The function signature should be: f(angles: torch.Tensor, sid: float) -> torch.Tensor where angles has shape (n_views,) and output has shape (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:
src_pos (torch.Tensor) – Source positions, shape (n_views, 2).
det_center (torch.Tensor) – Detector center positions, shape (n_views, 2).
det_u_vec (torch.Tensor) – Detector u-direction unit vectors, shape (n_views, 2).
Examples
>>> # Define a custom elliptical trajectory >>> def ellipse_path(angles, sid): ... src_pos = torch.zeros((len(angles), 2), device=angles.device, dtype=angles.dtype) ... src_pos[:, 0] = -sid * 1.5 * torch.sin(angles) # wider in x ... src_pos[:, 1] = sid * torch.cos(angles) ... return src_pos >>> >>> src_pos, det_center, det_u_vec = custom_trajectory_2d_fan( ... n_views=360, sid=1000.0, sdd=1500.0, source_path_fn=ellipse_path ... )