torchvtk.rendering

VolumeRaycaster

class torchvtk.rendering.VolumeRaycaster(density_factor=100.0, ray_samples=256, resolution=(224, 224))

Bases: torch.nn.Module

__init__(density_factor=100.0, ray_samples=256, resolution=(224, 224))

Initializes differentiable raycasting layer

Parameters
  • density_factor (float) – scales the overall density

  • ray_samples (int) – Number of samples along the rays

  • resolution (int, (int, int)) – Tuple describing width and height of the render. A single int produces a square image

forward(vol, tf=None, view_mat=None, output_alpha=False)

Renders a volume (with given view matrix) using raycasting. :param vol: Batch of volumes to render. Shape (BS, C, D, H, W). C=1 if tf is given. :type vol: Tensor :param tf: Transfer Function (to apply to vol) either as texture (BS, C, W) or as lists of points [(N, C+1)] (len of list must match BS). If this is None, an RGBo vol is expected (default). :type tf: Tensor :param view_mat: A (BS, 4, 4) transformation matrix representing the view matrix.. :type view_mat: Tensor or function :param output_alpha: Whether to output RGBA instead of RGB. Default is False :type output_alpha: bool

Returns

Batch of raycast images of shape (BS, 3, H, W) with RGB (and optionally Alpha) channels

get_camera_matrix(look_from)
get_coord_grid(z, y, x, perspective=False, fovy=0.52, ar=1.0)

Computes the samples given linspaces of the correct sizes for each spatial dimension.

get_perspective_coord_grid(view_mat)