kaolin.ops.voxelgrid¶
API¶
- kaolin.ops.voxelgrid.downsample(voxelgrids, scale)¶
Downsamples a voxelgrids, given a (down)scaling factor for each dimension.
Note
The voxelgrids output is not thresholded.
- Parameters
voxelgrids (torch.Tensor) – voxelgrids of shape (N, X, Y, Z) to be downsampled
scale (list or tuple or int) – List or tuple of int of length 3 to scale each dimension down. or an int to scale down for every dimension.
- Returns
Downsampled voxelgrids.
- Return type
Example
>>> voxelgrids2 = torch.zeros((1, 4, 4, 4)) >>> voxelgrids2[0, 0] = 1 >>> voxelgrids2[0, 1] = 0.4 >>> voxelgrids2[0, 3] = 0.8 >>> downsample(voxelgrids2, 2) tensor([[[[0.7000, 0.7000], [0.7000, 0.7000]], [[0.4000, 0.4000], [0.4000, 0.4000]]]])
- kaolin.ops.voxelgrid.extract_odms(voxelgrids)¶
Extracts orthographic depth maps from voxelgrids.
- Parameters
voxelgrids (torch.Tensor) – Binary voxelgrids of shape (N, dim, dim, dim) from which odms are extracted.
- Returns
Batched ODMs of shape (N, 6, dim, dim) from the 6 primary viewing angles. The face order is z_neg, z_pos, y_neg, y_pos, x_neg, x_pos, denoting the axis and direction we are looking at.
- Return type
(torch.LongTensor)
Example
>>> voxelgrids = torch.ones((2, 2, 2, 2)) >>> voxelgrids[0, :, 0, :] = 0 # Set the front face to be zeros >>> output = extract_odms(voxelgrids) >>> output tensor([[[[2, 0], [2, 0]], [[2, 0], [2, 0]], [[0, 0], [0, 0]], [[1, 1], [1, 1]], [[2, 2], [0, 0]], [[2, 2], [0, 0]]], [[[0, 0], [0, 0]], [[0, 0], [0, 0]], [[0, 0], [0, 0]], [[0, 0], [0, 0]], [[0, 0], [0, 0]], [[0, 0], [0, 0]]]])
- kaolin.ops.voxelgrid.extract_surface(voxelgrids)¶
Removes any internal structure(s) from a voxelgrids.
- Parameters
voxelgrids (torch.Tensor) – Binary voxelgrids of shape (N, X, Y ,Z) from which to extract surface
- Returns
binary surface voxelgrids tensor
- Return type
torch.BoolTensor
Example
>>> voxelgrids = torch.ones((1, 3, 3, 3)) >>> output = extract_surface(voxelgrids) >>> output[0] tensor([[[ True, True, True], [ True, True, True], [ True, True, True]], [[ True, True, True], [ True, False, True], [ True, True, True]], [[ True, True, True], [ True, True, True], [ True, True, True]]])
- kaolin.ops.voxelgrid.fill(voxelgrids)¶
Fills the internal structures in a voxelgrids grid. Used to fill holes and ‘solidify’ objects.
Note
This function is not differentiable.
- Parameters
voxelgrids (torch.Tensor) – binary voxelgrids of size (N, X, Y, Z) to be filled.
- Returns
filled, binary voxelgrids array
- Return type
torch.BoolTensor
Example
>>> voxelgrids = torch.Tensor( ... [[[[0., 0., 0., 0., 0.], ... [0., 1., 1., 1., 1.], ... [0., 1., 1., 1., 1.], ... [0., 1., 1., 1., 1.]], ... [[0., 0., 0., 0., 0.], ... [0., 1., 1., 1., 1.], ... [0., 1., 0., 0., 1.], ... [0., 1., 1., 1., 1.]], ... [[0., 0., 0., 0., 0.], ... [0., 1., 1., 1., 1.], ... [0., 1., 1., 1., 1.], ... [0., 1., 1., 1., 1.]]]]) >>> fill(voxelgrids) tensor([[[[False, False, False, False, False], [False, True, True, True, True], [False, True, True, True, True], [False, True, True, True, True]], [[False, False, False, False, False], [False, True, True, True, True], [False, True, True, True, True], [False, True, True, True, True]], [[False, False, False, False, False], [False, True, True, True, True], [False, True, True, True, True], [False, True, True, True, True]]]])
- kaolin.ops.voxelgrid.project_odms(odms, voxelgrids=None, votes=1)¶
Projects orthographic depth map onto voxelgrids.
Note
If no voxelgrids is provided, we project onto a completely filled grids.
- Parameters
odms (torch.Tensor) – Batched ODMs of shape (N, 6, dim, dim) from the 6 primary viewing angles. The face order is z_neg, z_pos, y_neg, y_pos, x_neg, x_pos, denoting the axis and direction we are looking at.
voxelgrids (torch.Tensor) – Binary voxelgrids onto which ODMs are projected.
votes (int) – int from range(0, 7). Votes needed to substract a voxel to 0.
- Returns
Updated binary voxel grid.
- Return type
(torch.BoolTensor)
Example
>>> odms = torch.zeros((1, 6, 2, 2)) # empty odms >>> odms[0, 1, 1, 1] = 2 # Change z_pos surface >>> project_odms(odms) tensor([[[[ True, True], [ True, True]], [[ True, True], [False, False]]]]) >>> project_odms(odms, votes=2) tensor([[[[True, True], [True, True]], [[True, True], [True, True]]]])