pyRadPlan.raytracer package#

Base class#

class RayTracerBase(cubes)[source]#

Bases: ABC

Base class for all ray tracers.

Attributes:
cubes

CT or other arbitrary cubes of similar resolution to be traced.

Methods

trace_cubes(beam)

Automatically calculate depth by tracing rays through cubes.

trace_ray(isocenter, source_points, ...)

Trace a single ray through cubes.

trace_rays(isocenter, source_points, ...)

Trace multiple rays through a cube.

property cubes#

CT or other arbitrary cubes of similar resolution to be traced.

fixed_ray_spacing_range: float | None#
lateral_cut_off: float#
precision: dtype#
trace_cubes(beam)[source]#

Automatically calculate depth by tracing rays through cubes.

Set up ray matrix with appropriate spacing to trace through all cubes, resulting in a cumulative sum of values in every voxel relative to the source. Will calculate cumulative sum on all of the supplied images.

Return type:

list[Image]

abstractmethod trace_ray(isocenter, source_points, target_points)[source]#

Trace a single ray through cubes.

Abstract Method to be implemented in subclasses.

Return type:

tuple[ndarray, ndarray, list[ndarray], ndarray, ndarray]

trace_rays(isocenter, source_points, target_points)[source]#

Trace multiple rays through a cube.

Parameters:
  • isocenter (Union[list, ndarray]) – Isocenter coordinates (1x3) array or list

  • source_points (Union[list, ndarray]) – Source points coordinates. (nx3) array or list

  • target_points (Union[list, ndarray]) – Target points coordinates. (nx3) array or list

Return type:

tuple[ndarray, ndarray, list[ndarray], ndarray, ndarray]

Returns:

  • alphas (ndarray) – Array of alpha values for each ray

  • lengths (ndarray) – Array of lengths for each ray

  • rho (list[ndarray]) – Array of rho values for each ray and each cube

  • d12 (ndarray) – Array of full length of each ray

  • ix (ndarray) – Linear indices (in numpy ordering) of the voxels intersected by each ray

Notes

The default implementation loops over the trace_ray function. The separate implementation is here to enable more performant implementations for specific ray tracers, e.g. through vectorization.

Siddon Ray Tracer#

class RayTracerSiddon(cubes)[source]#

Bases: RayTracerBase

Siddon Ray Tracing Algorithm through voxelized geometry.

Attributes:
cubes

CT or other arbitrary cubes of similar resolution to be traced.

Methods

trace_cubes(beam)

Automatically calculate depth by tracing rays through cubes.

trace_ray(isocenter, source_points, ...)

Trace an individual ray.

trace_rays(isocenter, source_points, ...)

Vectorized Implementation of RayTracing.

debug_core_performance: bool#
trace_ray(isocenter, source_points, target_points)[source]#

Trace an individual ray.

Return type:

tuple[ndarray, ndarray, list[ndarray], ndarray, ndarray]

trace_rays(isocenter, source_points, target_points)[source]#

Vectorized Implementation of RayTracing.

Uses padding to create matrices of ray information.

Return type:

tuple[ndarray, ndarray, list[ndarray], ndarray, ndarray]

Notes

Currently, the vectorized implementation uses padding with NaN values. This is not the most efficient way to handle the different lengths of the rays. A more efficient way would be to use more performant padding values (e.g. an unrealistically large value like the respective maximum floating point value)

use_gpu: bool#

Helper functions#