ConeBackprojectorFunction#

class diffct.ConeBackprojectorFunction(*args, **kwargs)[source]#

Bases: Function

Summary#

PyTorch autograd function for differentiable 3D cone beam backprojection.

Notes

Provides a differentiable interface to the CUDA-accelerated Siddon ray-tracing method with a cell-constant voxel basis for 3D cone beam backprojection. The forward pass computes a 3D reconstruction from cone beam projection data using backprojection as the adjoint operation. The backward pass computes gradients via 3D cone beam forward projection. Requires CUDA-capable hardware and consistent device placements.

This operation may be memory- and computationally-intensive due to 3D geometry. Consider using gradient checkpointing, smaller volumes, or distributed computing for large-scale applications, and ensure sufficient GPU memory is available.

Examples

>>> import torch
>>> from diffct import ConeBackprojectorFunction, circular_trajectory_3d
>>>
>>> projections = torch.randn(360, 256, 256, 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')
>>> volume = ConeBackprojectorFunction.apply(
...     projections, src_pos, det_center, det_u_vec, det_v_vec, 128, 128, 128, 1.0, 1.0
... )
>>> volume.sum().backward()
>>> projections.grad.shape
torch.Size([360, 256, 256])
static backward(ctx, grad_output)[source]#
static forward(ctx, sinogram, src_pos, det_center, det_u_vec, det_v_vec, D, H, W, du, dv, voxel_spacing=1.0, native_layout=False)[source]#

Compute the 3D cone beam backprojection with arbitrary trajectories using CUDA acceleration.

Parameters:
  • sinogram (torch.Tensor) – Floating-point CUDA cone sinogram of shape (n_views, det_u, det_v), 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).

  • D (int) – Depth (z-dimension) of the output reconstruction volume.

  • H (int) – Height (y-dimension) of the output reconstruction volume.

  • W (int) – Width (x-dimension) of the output reconstruction volume.

  • 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).

  • native_layout (bool, optional) – If True, return a (D, H, W) tensor with the kernel’s native (W, H, D)-contiguous strides instead of a contiguous copy (default: False). Projections accept such tensors without a copy.

Returns:

vol – 3D tensor of shape (D, H, W) containing the reconstructed volume on the same device as sinogram.

Return type:

torch.Tensor

Notes

  • Geometry tensors are moved to the sinogram’s CUDA device and converted to float32.

  • Data derivatives support higher orders; geometry derivatives are first-order only.

  • Supports arbitrary source and detector trajectories.

  • Uses the adjoint of cell-constant Siddon ray tracing.

Examples

>>> projections = torch.randn(360, 256, 256, device='cuda', requires_grad=True)
>>> src_pos, det_center, det_u_vec, det_v_vec = circular_trajectory_3d(360, 1000.0, 1500.0, device='cuda')
>>> vol = ConeBackprojectorFunction.apply(
...     projections, src_pos, det_center, det_u_vec, det_v_vec, 128, 128, 128, 1.0, 1.0
... )
Parameters:
  • args (Any)

  • kwargs (Any)

Return type:

Any