open3d.ml.tf.ops.voxelize

open3d.ml.tf.ops.voxelize(points, row_splits, voxel_size, points_range_min, points_range_max, max_points_per_voxel=9223372036854775807, max_voxels=9223372036854775807, name=None)

Voxelization for point clouds.

The function returns the integer coordinates of the voxels that contain points and a compact list of the indices that associate the voxels to the points. Also supports variable length batching.

Minimal example:

import open3d.ml.tf as ml3d

points = [
    [0.1,0.1,0.1],
    [0.5,0.5,0.5],
    [1.7,1.7,1.7],
    [1.8,1.8,1.8],
    [9.3,9.4,9.4]]

row_splits = [0, 2, 5]

ml3d.ops.voxelize(points,
                  row_splits,
                  voxel_size=[1.0,1.0,1.0],
                  points_range_min=[0,0,0],
                  points_range_max=[2,2,2])

# returns the voxel coordinates  [[0, 0, 0],
#                                 [1, 1, 1]]
#
#         the point indices      [0, 1, 2, 3]
#
#         the point row splits   [0, 2, 4]
#
#         and the batch splits   [0, 1, 2]
# or with pytorch
import torch
import open3d.ml.torch as ml3d

points = torch.Tensor([
    [0.1,0.1,0.1],
    [0.5,0.5,0.5],
    [1.7,1.7,1.7],
    [1.8,1.8,1.8],
    [9.3,9.4,9.4]])

row_splits = torch.Tensor([0, 2, 5]).to(torch.int64)

ml3d.ops.voxelize(points,
                  row_splits,
                  voxel_size=torch.Tensor([1.0,1.0,1.0]),
                  points_range_min=torch.Tensor([0,0,0]),
                  points_range_max=torch.Tensor([2,2,2]))

# returns the voxel coordinates  [[0, 0, 0],
#                                 [1, 1, 1]]
#
#         the point indices      [0, 1, 2, 3]
#
#         the point row splits   [0, 2, 4]
#
#         and the batch splits   [0, 1, 2]
Parameters
  • points – A Tensor. Must be one of the following types: float32, float64. The point positions with shape [N,D] with N as the number of points and D as the number of dimensions, which must be 0 < D < 9.

  • row_splits – A Tensor of type int64. 1D vector with row splits information if points is batched. This vector is [0, num_points] if there is only 1 batch item.

  • voxel_size – A Tensor. Must have the same type as points. The voxel size with shape [D].

  • points_range_min – A Tensor. Must have the same type as points. The maximum range for valid points to be voxelized. This vector has shape [D].

  • points_range_max – A Tensor. Must have the same type as points.

  • max_points_per_voxel – An optional int. Defaults to 9223372036854775807. The maximum number of points to consider for a voxel.

  • max_voxels – An optional int. Defaults to 9223372036854775807. The maximum number of voxels to generate per batch.

  • name – A name for the operation (optional).

Returns

A tuple of Tensor objects (voxel_coords, voxel_point_indices, voxel_point_row_splits, voxel_batch_splits).

voxel_coords: A Tensor of type int32. The integer voxel coordinates.The shape of this tensor is [M, D]

with M as the number of voxels and D as the number of dimensions.

voxel_point_indices: A Tensor of type int64. A flat list of all the points that have been voxelized.

The start and end of each voxel is defined in voxel_point_row_splits.

voxel_point_row_splits: A Tensor of type int64. This is an exclusive prefix sum that includes the total

number of points in the last element. This can be used to find the start and end of the point indices for each voxel. The shape of this tensor is [M+1].

voxel_batch_splits: A Tensor of type int64. This is a prefix sum of number of voxels per batch. This can

be used to find voxel_coords and row_splits corresponding to any particular batch.