kaolin.transforms

class Compose(transforms: Iterable)[source]

Composes (chains) multiple transforms sequentially. Identical to torchvision.transforms.Compose.

Parameters

tforms (list) – List of transforms to compose.

TODO: Example.

class CacheCompose(transforms: Iterable, cache_dir: str = 'cache')[source]

Caches the results of the provided compose pipeline to disk. If the pipeline is already cached, data is returned from disk, otherwise, data is converted following the provided transforms.

Args:

transforms (Iterable): List of transforms to compose. cache_dir (str): Directory where objects will be cached. Default

to ‘cache’.

class NumpyToTensor[source]

Converts a np.ndarray object to a torch.Tensor object.

class ScalePointCloud(scf: Union[int, float, torch.Tensor], inplace: Optional[bool] = True)[source]

Scale a pointcloud with a fixed scaling factor. Given a scale factor scf, this transform will scale each point in the pointcloud, i.e., cloud = scf * cloud

Parameters
  • scf (int or float or torch.Tensor) – Scale factor by which input clouds are to be scaled (Note: if passing in a torch.Tensor type, only one-element tensors are allowed).

  • inplace (bool, optional) – Whether or not the transformation should be in-place (default: True).

TODO: Example.

class RotatePointCloud(rotmat: torch.Tensor, inplace: Optional[bool] = True)[source]

Rotate a pointcloud with a given rotation matrix. Given a \(3 \times 3\) rotation matrix, this transform will rotate each point in the cloud by the rotation matrix specified.

Parameters
  • rotmat (torch.Tensor) – Rotation matrix that specifies the rotation to be applied to the pointcloud (shape: \(3 \times 3\)).

  • inplace (bool, optional) – Bool to make this operation in-place.

TODO: Example.

class RealignPointCloud(tgt: Union[torch.Tensor, kaolin.rep.PointCloud.PointCloud], inplace: Optional[bool] = True)[source]

Re-align a src pointcloud such that it fits in an axis-aligned bounding box whose size matches the tgt pointcloud.

Parameters
  • tgt (torch.Tensor or PointCloud) – Target pointcloud, to whose dimensions the source pointcloud must be aligned.

  • inplace (bool, optional) – Bool to make this operation in-place.

TODO: Example.

class NormalizePointCloud(inplace: Optional[bool] = True)[source]

Normalize a pointcloud such that it is centered at the orgin and has unit standard deviation.

Parameters

inplace (bool, optional) – Bool to make this operation in-place.

TODO: Example.

class DownsampleVoxelGrid(scale: List[int], inplace=True)[source]

Downsamples a voxelgrid, given a (down)scaling factor for each dimension.

Note

The voxel output is not thresholded.

Parameters
  • scale (list) – List of tensors to scale each dimension down by (length: 3).

  • inplace (bool, optional) – Bool to make the operation in-place.

TODO: Example.

class UpsampleVoxelGrid(dim: int)[source]

Upsamples a voxelgrid, given a target dimensionality (this target dimensionality is homogeneously applied to all three axes).

Note

The output voxels are not thresholded to contain values in the range [0, 1].

Parameters

dim (int) – New dimensionality (number of voxels along each dimension in the resulting voxel grid).

TODO: Example.

class ThresholdVoxelGrid(thresh: float, inplace: Optional[bool] = True)[source]

Binarizes the voxel array using a specified threshold.

Parameters
  • thresh (float) – Threshold with which to binarize.

  • inplace (bool, optional) – Bool to make the operation in-place.

class FillVoxelGrid(thresh: float)[source]

Fills the internal structures in a voxel grid. Used to fill holds and ‘solidify’ objects.

Parameters

thresh (float) – Threshold to use for binarization of the grid.

class ExtractSurfaceVoxels(thresh: float)[source]

Removes any inernal structure(s) from a voxel array.

Parameters

thresh (float) – threshold with which to binarize

class ExtractOdmsFromVoxelGrid[source]

Extracts a set of orthographic depth maps from a voxel grid.

class ExtractProjectOdmsFromVoxelGrid[source]

Extracts a set of orthographic depth maps (odms) from a voxel grid and then projects the odms onto a voxel grid.

class SampleTriangleMesh(num_samples: int, eps: Optional[float] = 1e-10)[source]

Sample points uniformly over the surface of a triangle mesh.

Parameters
  • num_samples (int) – Number of points to sample from the mesh.

  • eps (float, optional) – A small number to prevent division by zero for small surface areas.

class NormalizeMesh(inplace: Optional[bool] = True)[source]

Normalize a mesh such that it is centered at the orgin and has unit standard deviation.

Parameters

inplace (bool, optional) – Bool to make this operation in-place.

TODO: Example.

class ScaleMesh(scf: Union[float, int, Iterable], inplace: Optional[bool] = True)[source]

Scale a mesh given a specified scaling factor. A scalar scaling factor can be provided, in which case it is applied isotropically to all dims. Optionally, a list/tuple of anisotropic scale factors can be provided per dimension.

Parameters
  • scf (float or iterable) – Scaling factor per dimension. If only a single scaling factor is provided (or a list of size 1 is provided), it is isotropically applied to all dimensions. Else, a list/tuple of 3 scaling factors is expected, which are applied to the X, Y, and Z directions respectively.

  • inplace (bool, optional) – Bool to make this operation in-place.

class TranslateMesh(trans: Iterable, inplace: Optional[bool] = True)[source]

Translate a mesh given a (3D) translation vector.

Parameters
  • trans (torch.Tensor or iterable) – Translation vector (shape: torch.Tensor or iterable must have exactly 3 elements).

  • inplace (bool, optional) – Bool to make this operation in-place.

class RotateMesh(rotmat: torch.Tensor, inplace: Optional[bool] = True)[source]

Rotate a mesh given a 3 x 3 rotation matrix.

Parameters
  • rotmat (torch.Tensor) – Rotation matrix (shape: \(3 \times 3\)).

  • inplace (bool, optional) – Bool to make this operation in-place.

class TriangleMeshToPointCloud(num_samples: int, eps: Optional[float] = 1e-10)[source]

Converts a triange mesh to a pointcloud with a specified number of points. Uniformly samples points over the surface of the mesh.

Parameters
  • num_samples (int) – Number of points to sample from the mesh.

  • eps (float, optional) – A small number to prevent division by zero for small surface areas.

class TriangleMeshToVoxelGrid(resolution: int, normalize: bool = True, vertex_offset: float = 0.0)[source]

Converts a triangle mesh to a voxel grid with a specified reolution. The resolution of the voxel grid is assumed to be homogeneous along all three dimensions (X, Y, Z axes).

Parameters
  • resolution (int) – Desired resolution of generated voxel grid.

  • normalize (bool) – Determines whether to normalize vertices to a unit cube centered at the origin.

  • vertex_offset (float) – Offset applied to all vertices after normalizing.

class TriangleMeshToSDF(num_samples: int = 10000, noise: float = 0.05)[source]

Converts a triangle mesh to a non-parameteric (point-based) signed distance function (SDF).

Parameters
  • num_samples (int) – Number of points to sample on the surface of the triangle mesh.

  • noise (float) – Fraction of distance from the surface from which the SDF is sampled (Eg. a value of 0.05 samples points that are at a 5% fraction outside/inside the surface).

class MeshLaplacianSmoothing(iterations: int)[source]

Applies laplacian smoothing to the mesh.

Parameters

iterations (int) – number of iterations to run the algorithm for.

class RealignMesh(target: Union[torch.Tensor, kaolin.rep.PointCloud.PointCloud])[source]

Aligns the vertices to be in the same (axis-aligned) bounding box as that of target vertices or point cloud.

Parameters
  • target (torch.Tensor or PointCloud) – Target pointcloud to which src`is to be transformed (The `src cloud is transformed to the axis-aligned bounding box that the target cloud maps to). This cloud must have the same number of dimensions \(D\) as in the source cloud. (shape: \(\cdots \times \cdots \times D\)).

  • inplace (bool, optional) – Bool to make the transform in-place.

Returns

Pointcloud src realigned to fit in the (axis-aligned)

bounding box of the tgt cloud.

Return type

(torch.Tensor)

class SDFToTriangleMesh(bbox_center: float, bbox_dim: float, resolution: int, upsampling_steps: int)[source]

Converts an SDF function to a mesh

Parameters
  • bbox_center (float) – Center of the surface’s bounding box.

  • bbox_dim (float) – Largest dimension of the surface’s bounding box.

  • resolution (int) – The initial resolution of the voxel, should be large enough to properly define the surface.

  • upsampling_steps (int) – Number of times the initial resolution will be doubled. The returned resolution will be resolution * (2 ^ upsampling_steps).

class SDFToPointCloud(bbox_center: float, bbox_dim: float, resolution: int, upsampling_steps: int, num_points: int)[source]

Converts an SDF fucntion to a point cloud

Parameters
  • bbox_center (float) – Center of the surface’s bounding box.

  • bbox_dim (float) – Largest dimension of the surface’s bounding box.

  • resolution (int) – The initial resolution of the voxel, should be large enough to properly define the surface.

  • upsampling_steps (int) – Number of times the initial resolution will be doubled. The returned resolution will be resolution * (2 ^ upsampling_steps).

  • num_points (int) – Number of points in computed point cloud.

class SDFToVoxelGrid(bbox_center: float, bbox_dim: float, resolution: int, upsampling_steps: int, num_points: int)[source]

Converts an SDF function to a to a voxel grid

Parameters
  • bbox_center (float) – Center of the surface’s bounding box.

  • bbox_dim (float) – Largest dimension of the surface’s bounding box.

  • resolution (int) – The initial resolution of the voxel, should be large enough to properly define the surface.

  • upsampling_steps (int) – Number of times the initial resolution will be doubled. The returned resolution will be resolution * (2 ^ upsampling_steps).

class VoxelGridToTriangleMesh(threshold, mode, normalize)[source]

Converts passed voxel to a mesh

Parameters
  • 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)

class VoxelGridToQuadMesh(threshold: float, normalize: bool)[source]

Converts passed voxel to quad mesh

Parameters
  • threshold (float) – Threshold from which to make voxel binary.

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

class VoxelGridToPointCloud(num_points: int, threshold: float, mode: str, normalize: bool)[source]

Converts passed voxel to a pointcloud

Parameters
  • 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).

class VoxelGridToSDF(threshold: float, normalize: bool)[source]

Converts passed voxel to a signed distance fucntion.

Parameters
  • voxel (torch.Tensor) – Voxel grid

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

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

Returns

a signed distance fucntion