lapy.diffgeo

Differential Geometry Functions for meshes.

This module includes gradient, divergence, curvature, geodesics, mean curvature flow etc.

Note, the interface is not yet final, some functions are split into tet and tria versions.

lapy.diffgeo.compute_divergence(geom, vfunc)[source]

Compute divergence of a vertex function f.

Parameters:
geomTriaMesh or TetMesh

Mesh geometry.

vfuncarray

Scalar function at vertices.

Returns:
vfuncarray

Scalar function of divergence at vertices.

Raises:
ValueError

If unknown geometry type.

lapy.diffgeo.compute_geodesic_f(geom, vfunc)[source]

Compute function with normalized gradient (geodesic distance).

Computes gradient, normalizes it and computes function with this normalized gradient by solving the Poisson equation with the divergence of grad. This idea is also described in the paper “Geodesics in Heat” for triangles.

Parameters:
geomTriaMesh, TetMesh

Mesh geometry.

vfuncarray

Scalar function at vertices.

Returns:
vfuncarray

Scalar geodesic function at vertices.

lapy.diffgeo.compute_gradient(geom, vfunc)[source]

Compute gradient of a vertex function f.

Parameters:
geomTriaMesh or TetMesh

Mesh geometry.

vfuncarray

Scalar function at vertices.

Returns:
tfuncarray

3d gradient vector at each element.

Raises:
ValueError

If unknown geometry type.

lapy.diffgeo.compute_rotated_f(geom, vfunc)[source]

Compute function whose level sets are orthgonal to the ones of vfunc.

Parameters:
geomTriaMesh

Mesh geometry.

vfuncarray

Scalar function at vertices.

Returns:
vfuncarray

Rotated function at vertices.

Raises:
ValueError

If unknown geometry type.

lapy.diffgeo.tet_compute_divergence(tet, tfunc)[source]

Compute integrated divergence of a 3d tetra function f (for each vertex).

Divergence is the flux density leaving or entering a point. It can be measured by summing the dot product of the vector field with the normals to the outer faces of the 1-ring tetras around a vertex. Summing < tfunc , n_tria_oposite_v >

Parameters:
tetTetMesh

Tetrahedral mesh.

tfuncarray

3d vector field on tets.

Returns:
vfunc: array

Scalar function of divergence at vertices.

Notes

This is the integrated divergence, you may want to multiply with B^-1 to get back the function in some applications.

lapy.diffgeo.tet_compute_gradient(tet, vfunc)[source]

Compute gradient of a vertex function f (for each tetra).

For a tetrahedron (vi,vj,vk,vh) with volume V we have:

\[\begin{split}grad(f) &= [ (f_j - f_i) (vi-vk) x (vh-vk) \\ & + (f_k - f_i) (vi-vh) x (vj-vh) \\ & + (f_h - f_i) (vk-vi) x (vj-vi) ] / (2 V) \\ &= [ f_i (?-?) x ( ? -?) \\ & + f_j (vi-vk) x (vh-vk) \\ & + f_k (vi-vh) x (vj-vh) \\ & + f_h (vk-vi) x (vj-vi) ] / (2 V).\end{split}\]
Parameters:
tetTetMesh

Tetraheral mesh.

vfuncarray

Scalar function at vertices.

Returns:
tfuncarray of shape (n, 3)

3d gradient vector at tetras.

Notes

Numexpr could speed up this functions if necessary. Good background to read: Mancinelli, Livesu, Puppo, Gradient Field Estimation on Triangle Meshes http://pers.ge.imati.cnr.it/livesu/papers/MLP18/MLP18.pdf http://dgd.service.tu-berlin.de/wordpress/vismathws10/2012/10/17/gradient-of-scalar-functions Desbrun et al.

lapy.diffgeo.tria_compute_divergence(tria, tfunc)[source]

Compute integrated divergence of a 3d triangle function f (for each vertex).

Divergence is the flux density leaving or entering a point. Note: this is the integrated divergence, you may want to multiply with B^-1 to get back the function in some applications

Parameters:
triaTriaMesh

Triangle mesh.

tfuncarray

3d vector field on triangles.

Returns:
vfunc: array

Scalar function of divergence at vertices.

Notes

Numexpr could speed up this functions if necessary.

lapy.diffgeo.tria_compute_divergence2(tria, tfunc)[source]

Compute integrated divergence of a 3d triangle function f (for each vertex).

Divergence is the flux density leaving or entering a point. It can be measured by summing the dot product of the vector field with the normals to the outer edges of the 1-ring triangles around a vertex. Summing < tfunc , e_ij cross n > Note: this is the integrated divergence, you may want to multiply with B^-1 to get back the function in some applications

Parameters:
triaTriaMesh

Triangle mesh.

tfuncarray

3d vector field on triangles.

Returns:
vfunc: array

Scalar function of divergence at vertices.

Notes

Numexpr could speed-up this functions if necessary.

lapy.diffgeo.tria_compute_geodesic_f(tria, vfunc)[source]

Compute function with normalized gradient (geodesic distance).

Computes gradient, normalizes it and computes function with this normalized gradient by solving the Poisson equation with the divergence of grad. This idea is also described in the paper “Geodesics in Heat”.

Parameters:
triaTriaMesh

Triangle mesh.

vfuncarray

Scalar function at vertices.

Returns:
vfunc: array

Scalar geodesic function at vertices.

lapy.diffgeo.tria_compute_gradient(tria, vfunc)[source]

Compute gradient of a vertex function f (for each triangle).

\[\begin{split}grad(f) &= [ (f_j - f_i) (vi-vk)' + (f_k - f_i) (vj-vi)' ] / (2 A) \\ &= [ f_i (vk-vj)' + f_j (vi-vk)' + f_k (vj-vi)' ] / (2 A)\end{split}\]

for triangle (vi,vj,vk) with area A, where (.)’ is 90 degrees rotated edge, which is equal to cross(n,vec).

Parameters:
triaTriaMesh

Triangle mesh.

vfuncarray

Scalar function at vertices.

Returns:
tfunc: array

3d gradient vector at triangles.

Notes

Numexpr could speed up this functions if necessary. Good background to read: http://dgd.service.tu-berlin.de/wordpress/vismathws10/2012/10/17/gradient-of-scalar-functions/ Mancinelli, Livesu, Puppo, Gradient Field Estimation on Triangle Meshes http://pers.ge.imati.cnr.it/livesu/papers/MLP18/MLP18.pdf Desbrun …

lapy.diffgeo.tria_compute_rotated_f(tria, vfunc)[source]

Compute function whose level sets are orthgonal to the ones of vfunc.

This is done by rotating the gradient around the normal by 90 degrees, then solving the Poisson equations with the divergence of rotated grad.

Parameters:
triaTriaMesh

Triangle mesh.

vfuncarray

Scalar function at vertices.

Returns:
vfunc: array

Rotated scalar function at vertices.

Notes

Numexpr could speed up this functions if necessary.

lapy.diffgeo.tria_mean_curvature_flow(tria, max_iter=30, stop_eps=1e-13, step=1.0, use_cholmod=False)[source]

Flow a triangle mesh along the mean curvature normal.

mean_curvature_flow iteratively flows a triangle mesh along mean curvature normal (non-singular, see Kazhdan 2012). This uses the algorithm described in Kazhdan 2012 “Can mean curvature flow be made non-singular” which uses the Laplace-Beltrami operator but keeps the stiffness matrix (A) fixed and only adjusts the mass matrix (B) during the steps. It will normalize surface area of the mesh and translate the barycenter to the origin. Closed meshes will map to the unit sphere.

Parameters:
triaTriaMesh

Triangle mesh.

max_iterint, default=30

Maximal number of steps.

stop_epsfloat, default=1e-13

Stopping threshold.

stepfloat, default=1.0

Euler step size.

use_cholmodbool, default=False
Which solver to use:
  • True : Use Cholesky decomposition from scikit-sparse cholmod.

  • False: Use spsolve (LU decomposition).

Returns:
triaTriaMesh

Triangle mesh after flow.

Notes

Numexpr could speed up this functions if necessary.

lapy.diffgeo.tria_spherical_project(tria, flow_iter=3, debug=False)[source]

Compute the first 3 non-constant eigenfunctions and project the spectral embedding onto a sphere.

Computes the first three non-constant eigenfunctions and then projects the spectral embedding onto a sphere. This works when the first functions have a single closed zero level set, splitting the mesh into two domains each. Depending on the original shape triangles could get inverted. We also flip the functions according to the axes that they are aligned with for the special case of brain surfaces in FreeSurfer coordinates.

Parameters:
triaTriaMesh

Triangle mesh.

flow_iterint, default=3

Mean curv flow iterations (3 should be enough).

debugbool, default=False

Prints debug values if True.

Returns:
tria: TriaMesh

Triangle mesh.

Notes

Numexpr could speed up this functions if necessary.