kaolin.metrics.mesh

chamfer_distance(mesh1: kaolin.rep.Mesh.Mesh, mesh2: kaolin.rep.Mesh.Mesh, w1: float = 1.0, w2: float = 1.0, num_points=3000)[source]

computes the chamfer distance bewteen two meshes by sampling the two surfaces :param mesh1: (Mesh): first mesh :param mesh2: (Mesh): second mesh :param w1: (float): weighting of forward direction :param w2: (float): weighting of backward direction :param num_points: number of points to sample on each mesh

Returns

chamfer distance

Return type

chamfer_distance (torch.Tensor)

Example

>>> mesh1 = TriangleMesh.from_obj(file1)
>>> mesh2 = TriangleMesh.from_obj(file2)
>>> distance = chamfer_distance(mesh1, mesh2, 500)
edge_length(mesh: kaolin.rep.Mesh.Mesh)[source]

Returns the average length of a face in a mesh

Parameters

mesh (Mesh) – mesh over which to calcuale edge length

Returns

averge lenght of mesh edge

Return type

edge_length (torch.Tensor)

Example

>>> mesh  = TriangleMesh.from_obj(file)
>>> length = edge_length(mesh)
laplacian_loss(mesh1: kaolin.rep.Mesh.Mesh, mesh2: kaolin.rep.Mesh.Mesh)[source]

Returns the change in laplacian over two meshes

Parameters
  • mesh1 (Mesh) – first mesh

  • mesh2 – (Mesh): second mesh

Returns

laplacian change over the mesh

Return type

lap_loss (torch.Tensor)

Example

>>> mesh1 = TriangleMesh.from_obj(file)
>>> mesh2 = TriangleMesh.from_obj(file)
>>> mesh2.vertices = mesh2.vertices * 1.05
>>> lap = laplacian_loss(mesh1, mesh2)
point_to_surface(points: torch.Tensor, mesh: kaolin.rep.Mesh.Mesh)[source]

Computes the minimum distances from a set of points to a mesh

Parameters
  • points (torch.Tensor) – set of points

  • mesh (Mesh) – mesh to calculate distance

Returns

mean distance between points and surface

Return type

distance

Example

>>> mesh = TriangleMesh.from_obj(file)
>>> points = torch.rand(1000,3)
>>> loss = point_to_surface(points, mesh)