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)¶
Compute divergence of a vertex function f.
- Parameters:
- Returns:
- vfunc
array
Scalar function of divergence at vertices.
- vfunc
- Raises:
ValueError
If unknown geometry type.
- lapy.diffgeo.compute_geodesic_f(geom, vfunc)¶
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.
- lapy.diffgeo.compute_gradient(geom, vfunc)¶
Compute gradient of a vertex function f.
- Parameters:
- Returns:
- tfunc
array
3d gradient vector at each element.
- tfunc
- Raises:
ValueError
If unknown geometry type.
- lapy.diffgeo.compute_rotated_f(geom, vfunc)¶
Compute function whose level sets are orthgonal to the ones of vfunc.
- Parameters:
- Returns:
- vfunc
array
Rotated function at vertices.
- vfunc
- Raises:
ValueError
If unknown geometry type.
- lapy.diffgeo.tet_compute_divergence(tet, tfunc)¶
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:
- Returns:
- vfunc:
array
Scalar function of divergence at vertices.
- vfunc:
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)¶
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:
- Returns:
- tfunc
array
of shape (n, 3) 3d gradient vector at tetras.
- tfunc
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)¶
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:
- Returns:
- vfunc:
array
Scalar function of divergence at vertices.
- vfunc:
Notes
Numexpr could speed up this functions if necessary.
- lapy.diffgeo.tria_compute_divergence2(tria, tfunc)¶
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:
- Returns:
- vfunc:
array
Scalar function of divergence at vertices.
- vfunc:
Notes
Numexpr could speed-up this functions if necessary.
- lapy.diffgeo.tria_compute_geodesic_f(tria, vfunc)¶
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”.
- lapy.diffgeo.tria_compute_gradient(tria, vfunc)¶
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:
- Returns:
- tfunc:
array
3d gradient vector at triangles.
- tfunc:
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)¶
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:
- Returns:
- vfunc:
array
Rotated scalar function at vertices.
- vfunc:
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)¶
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:
- tria
TriaMesh
Triangle mesh.
- max_iter
int
, default=30 Maximal number of steps.
- stop_eps
float
, default=1e-13 Stopping threshold.
- step
float
, default=1.0 Euler step size.
- use_cholmod
bool
, default=False - Which solver to use:
True : Use Cholesky decomposition from scikit-sparse cholmod.
False: Use spsolve (LU decomposition).
- tria
- Returns:
- tria
TriaMesh
Triangle mesh after flow.
- tria
Notes
Numexpr could speed up this functions if necessary.
- lapy.diffgeo.tria_spherical_project(tria, flow_iter=3, debug=False)¶
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:
- Returns:
- tria:
TriaMesh
Triangle mesh.
- tria:
Notes
Numexpr could speed up this functions if necessary.