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 \((\text{batch_size}, \text{num_vertices}, 3)\).

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

Returns

average length of each edges in a face, of shape \((\text{batch_size}, \text{num_faces})\).

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, face_vertices)

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.

Note

The calculated distance is the squared, unsigned Euclidean distance.

\[d^2(P, \mathcal{M}) = \min_{T \in \mathcal{M}} \| P - \Pi_T(P) \|_2^2\]

Distance-type codes:

  • 0 - projection lies inside the triangle (face distance)

  • 1 - nearest to vertex 0

  • 2 - nearest to vertex 1

  • 3 - nearest to vertex 2

  • 4 - nearest to edge 0-1

  • 5 - nearest to edge 1-2

  • 6 - nearest to edge 2-0

Parameters
  • pointclouds (torch.Tensor) – pointclouds, of shape \((\text{batch_size}, \text{num_points}, 3)\).

  • face_vertices (torch.Tensor) – vertices of each face of meshes, of shape \((\text{batch_size}, \text{num_faces}, 3, 3)\).

Returns

  • Squared distances between pointclouds and meshes, of shape \((\text{batch_size}, \text{num_points})\).

  • Face indices selected, of shape \((\text{batch_size}, \text{num_points})\).

  • Distance types, of shape \((\text{batch_size}, \text{num_points})\).

Return type

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

Example

>>> from kaolin.ops.mesh import index_vertices_by_faces
>>> point = torch.tensor([[[0.5, 0.5, 0.5],
...                        [3., 4., 5.]]], device='cuda')
>>> vertices = torch.tensor([[[0., 0., 0.],
...                           [0., 1., 0.],
...                           [0., 0., 1.]]], device='cuda')
>>> faces = torch.tensor([[0, 1, 2]], dtype=torch.long, device='cuda')
>>> face_vertices = index_vertices_by_faces(vertices, faces)
>>> distance, index, dist_type = point_to_mesh_distance(point, face_vertices)
>>> distance
tensor([[ 0.2500, 41.0000]], device='cuda:0')
>>> index
tensor([[0, 0]], device='cuda:0')
>>> dist_type
tensor([[5, 5]], 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]]])
Morty Proxy This is a proxified and sanitized view of the page, visit original site.