densemaps.torch.point_to_triangle¶
Note
- Torch and cuda-compatible implementation of:
[1] - “Deblurring and Denoising of Maps between Shapes”, by Danielle Ezuz and Mirela Ben-Chen.
Functions
|
Computes the maximum edge length per triangle |
|
Given a vertex in the pointcloud and each face on the surface, gives the minimum distance to between the vertex and each of the 3 points of the triangle. |
|
Compute pairwise euclidean distance between two collections of vectors in a k-dimensional space |
|
Project a pointcloud on a p-dimensional triangle mesh |
|
Project a pointcloud on a set of triangles in p-dimension. |
|
Project a pointcloud on a p-dimensional triangle mesh |
Classes
Torch implementation of the projection of points a set of triangles in p-dimension. |
- densemaps.torch.point_to_triangle.nn_query_precise_torch(vert_emb, faces, points_emb, return_dist=False, batch_size=None, clear_cache=True, use_keops=None)¶
Project a pointcloud on a p-dimensional triangle mesh
- Parameters:
vert_emb – (n1, p) coordinates of the mesh vertices
faces – (m1, 3) faces of the mesh defined as indices of vertices
points_emb – (n2, p) coordinates of the pointcloud
return_dist (bool) – Whether to return the distance to the nearest vertex
batch_size (int, optional) – If precompute_dmin is False, projects batches of points on the surface
clear_cache (bool) – Whether to clear cache after computation
use_keops (bool, optional) – Passed through for the Delta_min query (see
project_pc_to_triangles()). Set False to skip KeOps and use plain torch.
- Returns:
face_match (torch.Tensor) – (n2,) - indices of the face assigned to each point.
bary_coord (torch.Tensor) – (n2,3) - barycentric coordinates of each point within the face.
- densemaps.torch.point_to_triangle.project_pc_to_triangles(vert_emb, faces, points_emb, precompute_dmin=True, batch_size=None, verbose=False, use_keops=None)¶
Project a pointcloud on a set of triangles in p-dimension. Projection is defined as barycentric coordinates on one of the triangle.
Line i for the output has 3 non-zero values at indices j,k and l of the vertices of the triangle point i is projected on.
Note
This picks the closest face per point (an argmin), so it is not differentiable. It always runs under
torch.no_grad(), so it never keeps a gradient graph on its large temporary(n_points, n_faces)tensors, whatever the caller’s grad setting.- Parameters:
vert_emb (torch.Tensor) – (n1, p) coordinates of the mesh vertices
faces (torch.Tensor) – (m1, 3) faces of the mesh defined as indices of vertices
points_emb (torch.Tensor) – (n2, p) coordinates of the pointcloud
precompute_dmin (bool) – Whether to precompute all the values of delta_min. Faster but heavier in memory.
batch_size (int, optional) – If precompute_dmin is False, projects batches of points on the surface
use_keops (bool, optional) – Passed to
nn_query_dist()for the Delta_min query. If None, KeOps is used when available and the problem is large enough. Set False to skip KeOps and use plain torch (handy to check whether KeOps is the one holding onto GPU memory).
- Returns:
face_match (torch.Tensor) – (n2,) - indices of the face assigned to each point.
bary_coord (torch.Tensor) – (n2,3) - barycentric coordinates of each point within the face.
- densemaps.torch.point_to_triangle.compute_per_tri_max_edge_length(vert_emb, faces)¶
Computes the maximum edge length per triangle
- Parameters:
vert_emb – (n1, p) coordinates of the mesh vertices
faces – (m1, 3) faces of the mesh defined as indices of vertices
- Returns:
lmax – (m1,) maximum edge length
- Return type:
torch.Tensor
- densemaps.torch.point_to_triangle.mycdist(X, Y, sqnormX=None, sqnormY=None, squared=False)¶
Compute pairwise euclidean distance between two collections of vectors in a k-dimensional space
- Parameters:
X – (n1, k) first collection
Y – (n2, k) second collection or (k,) if single point
squared (bool) – whether to compute the squared euclidean distance
- Returns:
distmat – (n1, n2) or (n2,) distance matrix
- Return type:
torch.Tensor
- densemaps.torch.point_to_triangle.compute_per_triangle_min_dist(vert_emb, faces, points_emb, vert_sqnorm=None, points_sqnorm=None)¶
Given a vertex in the pointcloud and each face on the surface, gives the minimum distance to between the vertex and each of the 3 points of the triangle.
For a given face on the source shape and vertex on the target shape: \(\delta_min = \min_{i=1\cdots 3} \|A_{c_i,*} - b\|_2\) with notations from “Deblurring and Denoising of Maps between Shapes”.
- Parameters:
vert_emb – (n1, p) coordinates of the mesh vertices
faces – (m1, 3) faces of the mesh defined as indices of vertices
points_emb – (n2, p) coordinates of the pointcloud
vertind – index of the vertex for which to compute dmin
vert_sqnorm – (n1,) squared norm of each vertex
points_sqnorm – (n2,) squared norm of each point
- Returns:
delta_min – (m1,n2) delta_min for each face on the source shape.
- Return type:
torch.Tensor
- densemaps.torch.point_to_triangle.project_to_mesh_multi(vert_emb, faces, points_emb, vertinds, lmax, Deltamin, dmin=None, dmin_params=None)¶
Project a pointcloud on a p-dimensional triangle mesh
- Parameters:
vert_emb – (n1, p) coordinates of the mesh vertices
faces – (m1, 3) faces of the mesh defined as indices of vertices
points_emb – (n2, p) coordinates of the pointcloud
vertinds – (l,) - indices of the vertices to project
lmax – (m1,) value of lmax (max edge length for each face)
Deltamin – (n2,) or (l,) value of Deltamin (distance to nearest vertex)
dmin –
- (m1,n2) or (m1, l) - optional - values of dmin (distance to the nearest vertex of each face
for each vertex). Can be computed on the fly
dmin_params (dict, optional) – if dmin is None, stores ‘vert_sqnorm’ a (n1,) array of squared norms of vertices embeddings, and ‘points_sqnorm’ a (n2,) array of squared norms of points embeddings. Helps speed up computation of dmin
- Returns:
min_faceind – (l,) index of the face on which the vertex is projected
min_bary – (l, 3,) - barycentric coordinates on the chosen face
- class densemaps.torch.point_to_triangle.PointsTriangleProjLayer¶
Torch implementation of the projection of points a set of triangles in p-dimension. Face pre-selection must be done beforehand, this is bruteforce.
Note
- The notations (and the algorithm) are inspired from:
[1] “David Eberly, ‘Distance Between Point and Triangle in 3D’, Geometric Tools, LLC, (1999)”
- forward(triangles=None, points=None, min_only=True, return_bary=True, return_dist=True, return_proj=True, verbose=False)¶
returns in order: [final_dists, projections, barycentric_coordinates, argmin_proj]
If return_dist is True, output contains the distances
If return_proj is True, output contains the projections
If return_bary is True, output contains the barycentric coordinates
If min_only is True, output contains the index of the closest triangle
- Parameters:
triangles – (m, 3, p) coordinates of the mesh triangles
points – (n, p) coordinates of the points to project
min_only (bool) – whether to return results only for closest point on the triangle
return_bary (bool) – whether to return the barycentric coordinates
return_dist (bool) – whether to return the distances
return_proj (bool) – whether to return the projections
verbose (bool) – whether to print debug information
- Returns:
final_dists – (n,) or (n,m) distances between the points and the triangles. (n,) if min_only is True
projections – (n,p) or (n,m,p) projections of the points on the triangles. (n,p) if min_only is True
barycentric_coordinates – (n,3) or (n,m,3) barycentric coordinates of the projections. (n,3) if min_only is True
argmin_proj – (n,) index of the closest triangle. Only if min_only is True