spectralbrain.BrainMesh#
- class spectralbrain.BrainMesh(vertices, faces, metadata=None)[source]#
Bases:
objectTriangle surface mesh for brain structures.
Implements the
GeometricObjectprotocol and provides the Laplacian construction → eigendecomposition → descriptor pipeline.- Parameters:
vertices (ndarray, shape (N, 3)) – Vertex coordinates in mm.
faces (ndarray, shape (F, 3)) – Triangle indices, 0-indexed.
metadata (dict, optional) – Provenance (subject, hemisphere, structure, …).
Examples
>>> verts, faces = sb.io.load_freesurfer_surface("lh.white") >>> mesh = BrainMesh(verts, faces, metadata={"structure": "cortex"}) >>> decomp = mesh.decompose(k=100)
Methods
__init__(vertices, faces[, metadata])Initialise from vertices and faces arrays.
Indices of boundary (non-manifold edge) vertices.
Casorati curvature — identical to curvedness.
compute_laplacian([method, ...])Construct the Laplacian and mass matrix.
Compute area-weighted per-vertex normals from face topology.
Koenderink Curvedness C ≥ 0.
decompose([k, laplacian_method, backend])Compute the spectral decomposition.
All edge lengths.
Euler characteristic χ = V − E + F.
Gaussian curvature via angle defect (Descartes–Euler).
genus()Genus g from χ = 2 − 2g (closed surfaces).
geodesic_distance(source_indices, *[, ...])Geodesic distance from source vertices to all others.
True if the mesh has no boundary.
laplacian_smooth([n_iterations, step_size])Laplacian smoothing (uniform weights).
Mean curvature via the Laplacian (Hn = ΔX / 2).
Principal curvatures κ₁ ≥ κ₂ from H and K.
Mesh quality summary.
Koenderink Shape Index S ∈ [−1, +1].
Total surface area in mm².
taubin_smooth([n_iterations, lambda_, mu])Taubin smoothing (shrinkage-free).
vertex_areas([method])Per-vertex area (Voronoi or barycentric lumped).
Number of edges incident to each vertex.
Local Willmore energy density H²(v).
Total Willmore energy ∫ H² dA.
Attributes
Return the vertex coordinates array.
Return the number of triangular faces.
Return the number of vertices (alias for n_vertices).
Return the number of vertices in the mesh.
- boundary_vertices()[source]#
Indices of boundary (non-manifold edge) vertices.
- Returns:
ndarray of int – Vertex indices on the mesh boundary.
- Return type:
- casorati_curvature()[source]#
Casorati curvature — identical to curvedness.
K_C = √((κ₁² + κ₂²) / 2)
Preferred over mean/Gaussian curvature for complexity quantification (Matsuyama et al. 2023).
- compute_laplacian(method='cotangent', *, robust_mollify_factor=1e-05)[source]#
Construct the Laplacian and mass matrix.
- Parameters:
- Returns:
L (SparseMatrix, shape (N, N)) – Stiffness (Laplacian) matrix — symmetric positive semi-definite.
M (MassMatrix, shape (N, N)) – Diagonal mass matrix.
- Return type:
- decompose(k=100, *, laplacian_method='cotangent', backend=None, **eigsh_kwargs)[source]#
Compute the spectral decomposition.
- Parameters:
k (int) – Number of eigenpairs to compute.
laplacian_method (str) – Passed to
compute_laplacian().backend (Backend, optional) – Compute backend. Defaults to
NumpyBackend.**eigsh_kwargs – Extra arguments to
backend.eigsh().
- Returns:
SpectralDecomposition
- Return type:
- gaussian_curvature()[source]#
Gaussian curvature via angle defect (Descartes–Euler).
K(v) = (2π − Σ θ_j) / A(v)
where θ_j are the face angles at vertex v and A(v) is the Voronoi area.
- geodesic_distance(source_indices, *, method='heat', t_factor=1.0)[source]#
Geodesic distance from source vertices to all others.
- Parameters:
- Returns:
distances (ndarray, shape (N,)) – Geodesic distance from the closest source vertex.
- Return type:
- mean_curvature()[source]#
Mean curvature via the Laplacian (Hn = ΔX / 2).
Requires the cotangent Laplacian and mass matrix.
- principal_curvatures()[source]#
Principal curvatures κ₁ ≥ κ₂ from H and K.
κ₁ = H + √(H² − K), κ₂ = H − √(H² − K)
- shape_index()[source]#
Koenderink Shape Index S ∈ [−1, +1].
S = (2/π) · arctan((κ₂ + κ₁) / (κ₂ − κ₁))
- taubin_smooth(n_iterations=10, lambda_=0.5, mu=-0.53)[source]#
Taubin smoothing (shrinkage-free).
Alternates positive and negative smoothing steps to avoid the volume shrinkage of pure Laplacian smoothing.
- vertex_valence()[source]#
Number of edges incident to each vertex.
- Returns:
ndarray, shape (N,), int
- Return type:
- willmore_density()[source]#
Local Willmore energy density H²(v).
The integral ∫ H² dA is the Willmore energy — conformally invariant, measures deviation from a sphere.