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
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 euclidean distance.
Type 0 indicates the distance is from a point on the surface of the triangle.
Type 1 to 3 indicates the distance is from a point to a vertices.
Type 4 to 6 indicates the distance is from a point to an edge.
- 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
Distances between pointclouds and meshes, of shape \((\text{batch_size}, \text{num_points})\).
face indices selected, of shape \((\text{batch_size}, \text{num_points})\).
Types of distance 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]]])