pyFM.mesh.geometry

Functions

compute_faces_areas(vertices, faces)

Compute per-face areas of a triangular mesh

compute_normals(vertices, faces)

Compute face normals of a triangular mesh

compute_vertex_areas(vertices, faces[, ...])

Compute per-vertex areas of a triangular mesh.

div_f(f, vertices, faces, normals[, ...])

Compute the divergence of a vector field on a mesh.

edges_from_faces(faces)

Compute all edges in the mesh

farthest_point_sampling(d, k[, random_init, ...])

Samples points using farthest point sampling using either a complete distance matrix or a function giving distances to a given index i

farthest_point_sampling_call(d_func, k[, ...])

Samples points using farthest point sampling, initialized randomly

farthest_point_sampling_call_sub(d_func, k, ...)

Samples points using farthest point sampling on a mesh but reduced on a set of samples.

farthest_point_sampling_distmat(D, k[, ...])

Samples points using farthest point sampling using a complete distance matrix

geodesic_distmat_dijkstra(vertices, faces)

Compute geodesic distance matrix using Dijkstra algorithm.

get_orientation_op(grad_field, vertices, ...)

Compute the linear orientation operator associated to a gradient field grad(f).

grad_f(f, vertices, faces, normals[, ...])

Compute the gradient of one or multiple functions on a mesh

grad_mat(vertices, faces[, normals, ...])

Returns gradient in the shape of a 3*n_faces * n_vertices matrix G.

heat_geodesic_from(inds, vertices, faces, ...)

Computes geodesic distances between vertices of index inds and all other vertices using the Heat Method

heat_geodmat(vertices, faces, normals, A, W)

Computes geodesic distances between all pairs of vertices using the Heat Method

heat_geodmat_robust(vertices, faces[, verbose])

Compute the geodesic distance matrix using the Heat Method, with robust computation.

neigh_faces(faces)

Return the indices of neighbor faces for each vertex.

per_vertex_normal(vertices, faces[, ...])

Compute per-vertex normals of a triangular mesh, with a chosen weighting scheme.

per_vertex_normal_area(vertices, faces)

Compute per-vertex normals of a triangular mesh, weighted by the area of adjacent faces.

per_vertex_normal_uniform(vertices, faces[, ...])

Compute per-vertex normals of a triangular mesh, weighted by the area of adjacent faces.

pyFM.mesh.geometry.edges_from_faces(faces)

Compute all edges in the mesh

Parameters:

faces (np.ndarray) – (m,3) array defining faces with vertex indices

Returns:

edges – (p,2) array of all edges defined by vertex indices with no particular order

Return type:

np.ndarray

pyFM.mesh.geometry.compute_faces_areas(vertices, faces)

Compute per-face areas of a triangular mesh

Parameters:
  • vertices (np.ndarray) – (n,3) array of vertices coordinates

  • faces (np.ndarray) – (m,3) array of vertex indices defining faces

Returns:

faces_areas – (m,) array of per-face areas

Return type:

np.ndarray

pyFM.mesh.geometry.compute_vertex_areas(vertices, faces, faces_areas=None)

Compute per-vertex areas of a triangular mesh. Area of a vertex, approximated as one third of the sum of the area of its adjacent triangles.

Parameters:
  • vertices (np.ndarray) – (n,3) array of vertices coordinates

  • faces (np.ndarray) – (m,3) array of vertex indices defining faces

  • faces_areas (np.ndarray, optional) – (m,) array of per-face areas

Returns:

vert_areas – (n,) array of per-vertex areas

Return type:

np.ndarray

pyFM.mesh.geometry.compute_normals(vertices, faces)

Compute face normals of a triangular mesh

Parameters:
  • vertices (np.ndarray) – (n,3) array of vertices coordinates

  • faces (np.ndarray) – (m,3) array of vertex indices defining faces

Returns:

normals – (m,3) array of normalized per-face normals

Return type:

np.ndarray

pyFM.mesh.geometry.per_vertex_normal(vertices, faces, face_normals=None, weighting='uniform')

Compute per-vertex normals of a triangular mesh, with a chosen weighting scheme.

Parameters:
  • vertices – (n,3) array of vertices coordinates

  • faces – m,3) array of vertex indices defining faces

  • face_normals – (m,3) array of per-face normals

  • weighting (str) – ‘area’ or ‘uniform’.

Returns:

vert_areas – (n,) array of per-vertex areas

Return type:

np.ndarray

pyFM.mesh.geometry.per_vertex_normal_area(vertices, faces)

Compute per-vertex normals of a triangular mesh, weighted by the area of adjacent faces.

Parameters:
  • vertices – (n,3) array of vertices coordinates

  • faces – (m,3) array of vertex indices defining faces

Returns:

vert_areas – (n,) array of per-vertex areas

Return type:

np.ndarray

pyFM.mesh.geometry.per_vertex_normal_uniform(vertices, faces, face_normals=None)

Compute per-vertex normals of a triangular mesh, weighted by the area of adjacent faces.

Parameters:
  • vertices – (n,3) array of vertices coordinates

  • faces – (m,3) array of vertex indices defining faces

Returns:

vert_areas – (n,) array of per-vertex areas

Return type:

np.ndarray

pyFM.mesh.geometry.neigh_faces(faces)

Return the indices of neighbor faces for each vertex. This supposed all vertices appear in the face list.

Parameters:

faces – (m,3) list of faces

Returns:

neighbors – (n,) list of list of indices of neighbor faces for each vertex

Return type:

list

pyFM.mesh.geometry.grad_mat(vertices, faces, normals=None, face_areas=None, order_style='C')

Returns gradient in the shape of a 3*n_faces * n_vertices matrix G.

Returns a ‘flatten’ version of the gradient. Given a function f of shape (n,), the gradient is given by (G@f).reshape(order=order_style)

Parameters:
  • vertices – (n,3) coordinates of vertices

  • faces – (m,3) indices of vertices for each face

  • normals – (m,3) normals coordinate for each face

  • face_areas – (m,) - Optional, array of per-face area, for faster computation

  • order_style (str, optional) – ‘C’ or ‘F’, order style to use for reshape

Returns:

G – (3*m,n) matrix of gradient

Return type:

sparse.csr_matrix

pyFM.mesh.geometry.grad_f(f, vertices, faces, normals, face_areas=None, use_sym=False, grads=None)

Compute the gradient of one or multiple functions on a mesh

Takes a function defined on each vertex and returns per-face gradient

Parameters:
  • f – (n,p) or (n,) functions value on each vertex

  • vertices – (n,3) coordinates of vertices

  • faces – (m,3) indices of vertices for each face

  • normals – (m,3) normals coordinate for each face

  • face_areas (Optional) – (m,) array of per-face area, for faster computation

  • use_sym (bool) –

    If true, uses the (slower but) symmetric expression

    of the gradient

  • grads

    iterable of size 3 containing arrays of size (m,3) giving gradient directions

    for all faces (see function _get_grad_dir.

Returns:

gradient – (m,p,3) or (n,3) gradient of f on the mesh

Return type:

np.ndarray

pyFM.mesh.geometry.div_f(f, vertices, faces, normals, vert_areas=None, grads=None, face_areas=None)

Compute the divergence of a vector field on a mesh.

Takes a per-face vector field and returns per-vertex divergence

Parameters:
  • f – (m,3) vector field on each face

  • vertices – (n,3) coordinates of vertices

  • faces – (m,3) indices of vertices for each face

  • normals – (m,3) normals coordinate for each face

  • vert_areas – (m,) - Optional, array of per-vertex area, for faster computation

  • grads

    iterable of size 3 containing arrays of size (m,3) giving gradient directions

    for all faces

  • face_areas

    (m,) - Optional, array of per-face area, for faster computation

    ONLY USED IF grads is given

Returns:

divergence – (n,) divergence of f on the mesh

Return type:

np.ndarray

pyFM.mesh.geometry.geodesic_distmat_dijkstra(vertices, faces)

Compute geodesic distance matrix using Dijkstra algorithm. Not very efficient, but works.

Parameters:
  • vertices – (n,3) coordinates of vertices

  • faces – (m,3) indices of vertices for each face

Returns:

geod_dist – (n,n) geodesic distance matrix

Return type:

np.ndarray

pyFM.mesh.geometry.heat_geodmat_robust(vertices, faces, verbose=False)

Compute the geodesic distance matrix using the Heat Method, with robust computation.

Parameters:
  • vertices – (n,3) coordinates of vertices

  • faces – (m,3) indices of vertices for each face

Returns:

distmat – (n,n) geodesic distance matrix

Return type:

np.ndarray

pyFM.mesh.geometry.heat_geodesic_from(inds, vertices, faces, normals, A, W=None, t=0.001, face_areas=None, vert_areas=None, grads=None, solver_heat=None, solver_lap=None)

Computes geodesic distances between vertices of index inds and all other vertices using the Heat Method

Parameters:
  • inds – int or (p,) array of ints - index of the source vertex (or vertices)

  • vertices – (n,3) vertices coordinates

  • faces – (m,3) triangular faces defined by 3 vertices index

  • normals – (m,3) per-face normals

  • A – (n,n) sparse - area matrix of the mesh so that the laplacian L = A^-1 W

  • W

    (n,n) sparse - stiffness matrix so that the laplacian L = A^-1 W.

    Optional if solvers are given !

  • t (float) – time parameter for which to solve the heat equation

  • face_area (np.ndarray, optional) – (m,) - Optional, array of per-face area, for faster computation

  • vert_areas (np.ndarray, optional) – (n,) - Optional, array of per-vertex area, for faster computation

  • grads (list) – list of size 3, each give per-face gradient directions (output of _get_grad_dir())

  • solver_heat (callable, optional) – solver for (A + tW)x = b given b

  • solver_lap (callable, optional) – solver for Wx = b given b

Returns:

geod_dist – (n,) or (n,p) geodesic distance for each vertex in inds

Return type:

np.ndarray

pyFM.mesh.geometry.heat_geodmat(vertices, faces, normals, A, W, t=0.001, face_areas=None, vert_areas=None, batch_size=None, verbose=False)

Computes geodesic distances between all pairs of vertices using the Heat Method

Parameters:
  • vertices – (n,3) vertices coordinates

  • faces – (m,3) triangular faces defined by 3 vertices index

  • normals – (m,3) per-face normals

  • A – (n,n) sparse - area matrix of the mesh so that the laplacian L = A^-1 W

  • W – (n,n) sparse - stiffness matrix so that the laplacian L = A^-1 W

  • t (float) – time parameter for which to solve the heat equation

  • face_areas (optional) – (m,) - Optional, array of per-face area, for faster computation

  • vert_areas (optional) – (n,) - Optional, array of per-vertex area, for faster computation

  • batch_size (int) – size of batches to use for computation. None means full shape

Returns:

distmat – (n,n) geodesic distance matrix

Return type:

np.ndarray

pyFM.mesh.geometry.farthest_point_sampling(d, k, random_init=True, n_points=None, verbose=False)

Samples points using farthest point sampling using either a complete distance matrix or a function giving distances to a given index i

Parameters:
  • d – (n,n) array or callable - Either a distance matrix between points or a function computing geodesic distance from a given index.

  • k – int - number of points to sample

  • random_init – Whether to sample the first point randomly or to take the furthest away from all the other ones. Only used if d is a distance matrix

  • n_points – In the case where d is callable, specifies the size of the output

Returns:

fps – (k,) array of indices of sampled points

Return type:

np.ndarray

pyFM.mesh.geometry.farthest_point_sampling_distmat(D, k, random_init=True, verbose=False)

Samples points using farthest point sampling using a complete distance matrix

Parameters:
  • D – (n,n) distance matrix between points

  • k (int) – number of points to sample

  • random_init

    Whether to sample the first point randomly or to

    take the furthest away from all the other ones

Returns:

fps – (k,) array of indices of sampled points

Return type:

np.ndarray

pyFM.mesh.geometry.farthest_point_sampling_call(d_func, k, n_points=None, verbose=False)

Samples points using farthest point sampling, initialized randomly

Parameters:
  • d_func (callable) – for index i, d_func(i) is a (n_points,) array of geodesic distance to other points

  • k (int) – number of points to sample

  • n_points (int, optional) – Number of points. If not specified, checks d_func(0)

Returns:

fps – (k,) array of indices of sampled points

Return type:

np.ndarray

pyFM.mesh.geometry.farthest_point_sampling_call_sub(d_func, k, sub_points, return_sub_inds=False, random_init=True, verbose=False)

Samples points using farthest point sampling on a mesh but reduced on a set of samples.

Parameters:
  • d_func (callable) –

    for index i, d_func(i) is a (n_points,) array of geodesic distance to

    other points

  • k (int) – number of points to sample

  • sub_points ((m,)) – indices of vertices in the subsample

  • return_sub_inds (bool) – wether to return indices of fps inside the subsample

  • random_init (bool) – whether to sample the first point randomly or to take the furthest away

Returns:

  • fps (np.ndarray) – (k,) array of indices of sampled points (as seen from the full set of points)

  • fps_sub (optional) – If return_sub_inds is True. (k,) array of indices of sampled points (as seen from inside sub_points)

pyFM.mesh.geometry.get_orientation_op(grad_field, vertices, faces, normals, per_vert_area, rotated=False)

Compute the linear orientation operator associated to a gradient field grad(f).

This operator computes g -> < grad(f) x grad(g), n> (given at each vertex) for any function g In practice, we compute < n x grad(f), grad(g) > for simpler computation.

Parameters:
  • grad_field – (n_f,3) gradient field on the mesh

  • vertices – (n_v,3) coordinates of vertices

  • faces – (n_f,3) indices of vertices for each face

  • normals – (n_f,3) normals coordinate for each face

  • per_vert_area – (n_v,) voronoi area for each vertex

  • rotated (bool) – whether gradient field is already rotated by n x grad(f)

Returns:

operator – (n_v,n_v) orientation operator.

Return type:

sparse.csc_matrix