Ray Casting in a Voxel Block Grid#

Note

This is NOT ray casting for triangle meshes. Please refer to open3d.t.geometry.RaycastingScene 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 vbg from TSDF Integration, we can efficiently render the scene given the input depth as a rough range estimate.

68# examples/python/t_reconstruction_system/ray_casting.py
69        result = vbg.ray_cast(block_coords=frustum_block_coords,
70                              intrinsic=intrinsic,
71                              extrinsic=extrinsic,
72                              width=depth.columns,
73                              height=depth.rows,
74                              render_attributes=[
75                                  'depth', 'normal', 'color', 'index',
76                                  'interp_ratio'
77                              ],
78                              depth_scale=config.depth_scale,
79                              depth_min=config.depth_min,
80                              depth_max=config.depth_max,
81                              weight_threshold=1,
82                              range_map_down_factor=8)

The results could be directly obtained and visualized by

83# examples/python/t_reconstruction_system/ray_casting.py
84        fig, axs = plt.subplots(2, 2)
85        # Colorized depth
86        colorized_depth = o3d.t.geometry.Image(result['depth']).colorize_depth(
87            config.depth_scale, config.depth_min, config.depth_max)
88        axs[0, 0].imshow(colorized_depth.as_tensor().cpu().numpy())
89        axs[0, 0].set_title('depth')
90
91        axs[0, 1].imshow(result['normal'].cpu().numpy())
92        axs[0, 1].set_title('normal')
93
94        axs[1, 0].imshow(result['color'].cpu().numpy())
95        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:

90# examples/python/t_reconstruction_system/ray_casting.py
91        vbg_color = vbg.attribute('color').reshape((-1, 3))
92        nb_indices = result['index'].reshape((-1))
93        nb_interp_ratio = result['interp_ratio'].reshape((-1, 1))
94        nb_colors = vbg_color[nb_indices] * nb_interp_ratio
95        sum_colors = nb_colors.reshape((depth.rows, depth.columns, 8, 3)).sum(
96            (2)) / 255.0
97        axs[1, 1].imshow(sum_colors.cpu().numpy())
98        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 PyTorch I/O with DLPack memory map.