kaolin.metrics.trianglemesh

API

kaolin.metrics.trianglemesh.average_edge_length(vertices, faces)

Returns the average length of each faces in a mesh.

Parameters
  • vertices (torch.Tensor) – Batched vertices of shape (B, V, 3) of a Mesh

  • faces (torch.LongTensor) – Faces of shape (F, 3) of a Mesh

Returns

average length of each edges in a face of shape (B, F)

Return type

(torch.Tensor)

Example

>>> vertices = torch.tensor([[[1, 0, 0],
...                           [0, 1, 0],
...                           [0, 0, 1]]], dtype=torch.float)
>>> faces = torch.tensor([[0, 1, 2]])
>>> average_edge_length(vertices, faces)
tensor([[1.4142]])
kaolin.metrics.trianglemesh.point_to_mesh_distance(pointclouds, vertices, faces)

Computes the distances from pointclouds to meshes (represented by vertices and faces.) For each point in the pointcloud, it finds the nearest triangle in the mesh, and calculated its distance to that triangle. There are three kind of distances. Type 0 to 2 indicates which edge the point is closest to. Type 3 indicates the distance is from a point on the surface of the triangle, not an edge.

Parameters
  • pointclouds (torch.Tensor) – pointclouds of shape (B, P, 3)

  • vertices (torch.Tensor) – vertices of meshes of shape (B, V, 3)

  • faces (torch.LongTensor) – faces of meshes of shape (F, 3)

Returns

distance between pointclouds and meshes of shape (B, P),

corresponding indices of shape (B, P) in faces, and type of shape (B, P) of distances.

Return type

(torch.Tensor, torch.LongTensor, torch.IntTensor)

Example

>>> vertices = torch.tensor([[[0, 0, 0],
...                           [0, 1, 0],
...                           [0, 0, 1]]], device='cuda', dtype=torch.float)
>>> faces = torch.tensor([[0, 1, 2]], dtype=torch.long, device='cuda')
>>> point = torch.tensor([[[0.5, 0.5, 0.5],
...                        [3, 4, 5]]], device='cuda', dtype=torch.float)
>>> distance, index, dist_type = point_to_mesh_distance(point, vertices, faces)
>>> distance
tensor([[ 0.2500, 41.0000]], device='cuda:0')
>>> index
tensor([[0, 0]], device='cuda:0')
>>> dist_type
tensor([[1, 1]], device='cuda:0', dtype=torch.int32)
kaolin.metrics.trianglemesh.uniform_laplacian_smoothing(vertices, faces)

Calculates the uniform laplacian smoothing of meshes. The position of updated vertices is defined as \(V_i = \frac{1}{N} * \sum^{N}_{j=1}V_j\), where \(N\) is the number of neighbours of \(V_i\), \(V_j\) is the position of the j-th adjacent vertex.

Parameters
  • vertices (torch.Tensor) – Vertices of the meshes, of shape \((\text{batch_size}, \text{num_vertices}, 3)\).

  • faces (torch.LongTensor) – Faces of the meshes, of shape \((\text{num_faces}, \text{face_size})\).

Returns

smoothed vertices, of shape \((\text{batch_size}, \text{num_vertices}, 3)\).

Return type

(torch.FloatTensor)

Example

>>> vertices = torch.tensor([[[1, 0, 0],
...                           [0, 1, 0],
...                           [0, 0, 1]]], dtype=torch.float)
>>> faces = torch.tensor([[0, 1, 2]])
>>> uniform_laplacian_smoothing(vertices, faces)
tensor([[[0.0000, 0.5000, 0.5000],
         [0.5000, 0.0000, 0.5000],
         [0.5000, 0.5000, 0.0000]]])