lapy.conformal¶
Computes spherical conformal mappings of triangle meshes.
Functions are adopted from Matlab code at https://github.com/garyptchoi/spherical-conformal-map with this Copyright (c) 2013-2020, Gary Pui-Tung Choi https://math.mit.edu/~ptchoi and has been distributed with the Apache 2 License.
Notes¶
If you use this code in your own work, please cite the following paper:
[1] P. T. Choi, K. C. Lam, and L. M. Lui, “FLASH: Fast Landmark Aligned Spherical Harmonic Parameterization for Genus-0 Closed Brain Surfaces.” SIAM Journal on Imaging Sciences, vol. 8, no. 1, pp. 67-94, 2015.
- lapy.conformal.beltrami_coefficient(tria, mapping)[source]¶
Compute the Beltrami coefficient of a given mapping.
The Beltrami coefficient is a complex-valued function that characterizes the distortion of a mapping in terms of conformality.
- Parameters:
- tria
TriaMesh Genus-0 closed triangle mesh. Should be planar mapping on complex plane.
- mapping
np.ndarray Vertex coordinates of shape (n_vertices, 3) representing the spherical conformal parameterization.
- tria
- Returns:
np.ndarrayComplex Beltrami coefficient per triangle, shape (n_triangles,).
- Raises:
ValueErrorIf mesh is not planar.
- lapy.conformal.inverse_stereographic(u)[source]¶
Compute mapping from the complex plane to the sphere using inverse stereographic projection.
- Parameters:
- u
np.ndarray Input points in the complex plane. Can be: - Array of shape (n_points, 2), representing real and imaginary parts. - Array of complex numbers of shape (n_points,).
- u
- Returns:
np.ndarrayMapped points on the sphere as (x, y, z) coordinates, shape (n_points, 3).
- lapy.conformal.linear_beltrami_solver(tria, mu, landmark, target, use_cholmod=False)[source]¶
Solve the Linear Beltrami equation for a given mesh and target.
- Parameters:
- tria
TriaMesh Genus-0 closed triangle mesh. Should be planar mapping on complex plane.
- mu
np.ndarray Beltrami coefficients describing distortion at each triangle, shape (n_triangles,).
- landmark
np.ndarray Indices of fixed landmark vertices, shape (n_landmarks,).
- target
np.ndarray 2D target positions for the landmark vertices, shape (n_landmarks, 2).
- use_cholmod
bool, default=False Which solver to use. If True, use Cholesky decomposition from scikit-sparse cholmod. If False, use spsolve (LU decomposition).
- tria
- Returns:
np.ndarrayMapping of all vertices to 2D coordinates, shape (n_vertices, 2), aligned to the given landmarks.
- Raises:
ValueErrorIf mesh is not planar. If triangle areas are degenerate. If Beltrami denominator is close to zero.
ImportErrorIf use_cholmod is True but scikit-sparse is not installed.
- lapy.conformal.mobius_area_correction_spherical(tria, mapping)[source]¶
Find an improved Mobius transformation to reduce distortion.
This helps reducing the area distortion of a spherical conformal parameterization using the method in Choi et al, SIAM Journal on Imaging Sciences, 2020.
- Parameters:
- tria
TriaMesh Genus-0 closed triangle mesh.
- mapping
np.ndarray Vertex coordinates of shape (n_vertices, 3) representing a spherical conformal parameterization.
- tria
- Returns:
- map_mobius
np.ndarray Vertex coordinates of shape (n_vertices, 3) updated to minimize area distortion.
- result
object Optimization result object containing optimal parameters (x) for the Mobius transformation, where
\[f(z) = \frac{az+b}{cz+d} = \frac{(x[0]+x[1]*1j)*z+(x[2]+x[3]*1j)}{(x[4]+x[5]*1j)*z+(x[6]+x[7]*1j)}.\]
- map_mobius
- lapy.conformal.spherical_conformal_map(tria, use_cholmod=False)[source]¶
Linear method for computing spherical conformal map of a genus-0 closed surface.
- Parameters:
- Returns:
np.ndarrayVertex coordinates of shape (n_vertices, 3) of the spherical conformal parameterization.
- Raises:
ValueErrorIf mesh is not genus-0 (Euler characteristic != 2). If edge lengths are degenerate. If projection contains NaN values.
ImportErrorIf use_cholmod is True but scikit-sparse is not installed.
- lapy.conformal.stereographic(u)[source]¶
Map points on a sphere to the complex plane using the stereographic projection.
- Parameters:
- u
np.ndarray Points on the sphere as (x, y, z) coordinates, shape (n_points, 3).
- u
- Returns:
np.ndarrayMapped points as complex numbers on the complex plane, shape (n_points,).
- Raises:
ValueErrorIf stereographic denominator (1 - z) is close to zero.