kaolin.conversions.voxelgridconversions

voxelgrid_to_pointcloud(voxel: torch.Tensor, num_points: int, thresh: float = 0.5, mode: str = 'full', normalize: bool = True)[source]

Converts passed voxel to a pointcloud

Parameters
  • voxel (torch.Tensor) – voxel array

  • num_points (int) – number of points in converted point cloud

  • thresh (float) – threshold from which to make voxel binary

  • mode (str) – -‘full’: sample the whole voxel model -‘surface’: sample only the surface voxels

  • normalize (bool) – whether to scale the array to (-.5,.5)

Returns

converted pointcloud

Return type

(torch.Tensor)

Example

>>> voxel = torch.ones([32,32,32])
>>> points = voxelgrid_to_pointcloud(voxel, 10)
>>> points
tensor([[0.5674, 0.8994, 0.8606],
        [0.2669, 0.9445, 0.5501],
        [0.2252, 0.9674, 0.8198],
        [0.5127, 0.9347, 0.4470],
        [0.7981, 0.1645, 0.5405],
        [0.7384, 0.4255, 0.6084],
        [0.9881, 0.3629, 0.2747],
        [0.1690, 0.2880, 0.4849],
        [0.8844, 0.3866, 0.0557],
        [0.4829, 0.0413, 0.6700]])
>>> points.shape
torch.Size([10, 3])
voxelgrid_to_trianglemesh(voxel: torch.Tensor, thresh: int = 0.5, mode: str = 'marching_cubes', normalize: bool = True)[source]

Converts passed voxel to a mesh

Parameters
  • voxel (torch.Tensor) – voxel array

  • thresh (float) – threshold from which to make voxel binary

  • mode (str) – -‘exact’: exect mesh conversion -‘marching_cubes’: marching cubes is applied to passed voxel

  • normalize (bool) – whether to scale the array to (-.5,.5)

Returns

computed mesh properties

Return type

(torch.Tensor)

Example

>>> voxel = torch.ones([32,32,32])
>>> verts, faces = voxelgrid_to_trianglemesh(voxel)
>>> [verts.shape, faces.shape]
[torch.Size([6144, 3]), torch.Size([12284, 3])]
voxelgrid_to_quadmesh(voxel: torch.Tensor, thresh: str = 0.5, normalize: bool = True)[source]

Converts passed voxel to quad mesh

Parameters
  • voxel (torch.Tensor) – voxel array

  • thresh (float) – threshold from which to make voxel binary

  • normalize (bool) – whether to scale the array to (-.5,.5)

Returns

converted mesh properties

Return type

(torch.Tensor)

Example

>>> voxel = torch.ones([32,32,32])
>>> verts, faces = voxelgrid_to_quadmesh(voxel)
>>> [verts.shape, faces.shape]
[torch.Size([6144, 3]), torch.Size([6142, 4])]
voxelgrid_to_sdf(voxel: torch.Tensor, thresh: float = 0.5, normalize: bool = True)[source]

Converts passed voxel to a signed distance function

Parameters
  • voxel (torch.Tensor) – voxel array

  • thresh (float) – threshold from which to make voxel binary

  • normalize (bool) – whether to scale the array to (0,1)

Returns

a signed distance function

Example

>>> voxel = torch.ones([32,32,32])
>>> sdf = voxelgrid_to_sdf(voxel)
>>> distances = sdf(torch.rand(100,3))