ConeProjectorFunction#
- class diffct.ConeProjectorFunction(*args, **kwargs)[source]#
Bases:
FunctionSummary#
PyTorch autograd function for differentiable 3D cone beam forward projection.
Notes
Provides a differentiable interface to the CUDA-accelerated Siddon ray-tracing method with a cell-constant voxel basis for 3D cone beam geometry. Rays emanate from a point X-ray source to a 2D detector array capturing volumetric projection data. The forward pass computes 3D projections, and the backward pass computes gradients via adjoint 3D backprojection. Requires significant GPU memory.
Examples
>>> import torch >>> from diffct import ConeProjectorFunction, circular_trajectory_3d >>> >>> volume = torch.randn(128, 128, 128, device='cuda', requires_grad=True) >>> src_pos, det_center, det_u_vec, det_v_vec = circular_trajectory_3d(360, sid=1000.0, sdd=1500.0, device='cuda') >>> projections = ConeProjectorFunction.apply( ... volume, src_pos, det_center, det_u_vec, det_v_vec, 256, 256, 1.0, 1.0 ... ) >>> projections.sum().backward() >>> volume.grad.shape torch.Size([128, 128, 128])
- static forward(ctx, volume, src_pos, det_center, det_u_vec, det_v_vec, det_u, det_v, du, dv, voxel_spacing=1.0)[source]#
Compute the 3D cone beam forward projection with arbitrary trajectories using CUDA acceleration.
- Parameters:
volume (torch.Tensor) – Floating-point CUDA volume of shape (D, H, W), converted to float32 for execution.
src_pos (torch.Tensor) – Source positions for each view, shape (n_views, 3), in physical units.
det_center (torch.Tensor) – Detector center positions for each view, shape (n_views, 3), in physical units.
det_u_vec (torch.Tensor) – Detector u-direction unit vectors for each view, shape (n_views, 3).
det_v_vec (torch.Tensor) – Detector v-direction unit vectors for each view, shape (n_views, 3).
det_u (int) – Number of detector elements along the u-axis (width).
det_v (int) – Number of detector elements along the v-axis (height).
du (float) – Physical spacing between detector elements along the u-axis.
dv (float) – Physical spacing between detector elements along the v-axis.
voxel_spacing (float, optional) – Physical size of one voxel (in same units as positions, default: 1.0).
- Returns:
sino – 3D tensor of shape (n_views, det_u, det_v) containing the cone beam projections on the same device as volume.
- Return type:
torch.Tensor
Notes
Geometry tensors are moved to the volume’s CUDA device and converted to float32.
Data derivatives support higher orders; geometry derivatives are first-order only.
Supports arbitrary source and detector trajectories, not limited to circular orbits.
Uses cell-constant Siddon ray tracing.
Examples
>>> volume = torch.randn(128, 128, 128, device='cuda', requires_grad=True) >>> # Create circular trajectory >>> src_pos, det_center, det_u_vec, det_v_vec = circular_trajectory_3d(360, 1000.0, 1500.0, device='cuda') >>> sino = ConeProjectorFunction.apply( ... volume, src_pos, det_center, det_u_vec, det_v_vec, 256, 256, 1.0, 1.0 ... )
- Parameters:
args (Any)
kwargs (Any)
- Return type:
Any