Ray Casting in a Voxel Block Grid

Note

This is NOT ray casting for triangle meshes. Please refer to /python_api/open3d.t.geometry.RayCastingScene.rst for that use case.

Ray casting can be performed in a voxel block grid to generate depth and color images at specific view points without extracting the entire surface. It is useful for frame-to-model tracking, and for differentiable volume rendering.

We provide optimized conventional rendering, and basic support for customized rendering that may be used in differentiable rendering. An example can be found at examples/python/t_reconstruction_system/ray_casting.py.

Conventional rendering

From a reconstructed voxel block grid from TSDF Integration, we can efficiently render the scene given the input depth as a rough range estimate.

76# examples/python/t_reconstruction_system/ray_casting.py
77        result = vbg.ray_cast(block_coords=frustum_block_coords,
78                              intrinsic=intrinsic,
79                              extrinsic=extrinsic,
80                              width=depth.columns,
81                              height=depth.rows,
82                              render_attributes=[
83                                  'depth', 'normal', 'color', 'index',
84                                  'interp_ratio'
85                              ],
86                              depth_scale=config.depth_scale,
87                              depth_min=config.depth_min,
88                              depth_max=config.depth_max,
89                              weight_threshold=1)
90
91        fig, axs = plt.subplots(2, 2)
92

The results could be directly obtained and visualized by

 90# examples/python/t_reconstruction_system/ray_casting.py
 91        fig, axs = plt.subplots(2, 2)
 92        # Colorized depth
 93        colorized_depth = o3d.t.geometry.Image(result['depth']).colorize_depth(
 94            config.depth_scale, config.depth_min, config.depth_max)
 95        axs[0, 0].imshow(colorized_depth.as_tensor().cpu().numpy())
 96        axs[0, 0].set_title('depth')
 97
 98        axs[0, 1].imshow(result['normal'].cpu().numpy())
 99        axs[0, 1].set_title('normal')
100
101        axs[1, 0].imshow(result['color'].cpu().numpy())
102        axs[1, 0].set_title('color via kernel')

Customized rendering

In customized rendering, we manually perform trilinear-interpolation by accessing properties at 8 nearest neighbor voxels with respect to the found surface point per pixel:

 97# examples/python/t_reconstruction_system/ray_casting.py
 98        vbg_color = vbg.attribute('color').reshape((-1, 3))
 99        nb_indices = result['index'].reshape((-1))
100        nb_interp_ratio = result['interp_ratio'].reshape((-1, 1))
101        nb_colors = vbg_color[nb_indices] * nb_interp_ratio
102        sum_colors = nb_colors.reshape((depth.rows, depth.columns, 8, 3)).sum(
103            (2)) / 255.0
104        axs[1, 1].imshow(sum_colors.cpu().numpy())
105        axs[1, 1].set_title('color via indexing')

Since the output is rendered via indices, the rendering process could be rewritten in differentiable engines like PyTorch seamlessly via /tutorial/core/tensor.ipynb#PyTorch-I/O-with-DLPack-memory-map.