Notebook source code: notebooks/how_to/01_mesh_laplacian.ipynb
Run it yourself on binder Binder badge

How to compute the mesh Laplacian?#

 In [1]:
from geomfum.dataset import NotebooksDataset
from geomfum.laplacian import LaplacianFinder
from geomfum.shape import TriangleMesh
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
Cell In[1], line 3
      1 from geomfum.dataset import NotebooksDataset
      2 from geomfum.laplacian import LaplacianFinder
----> 3 from geomfum.shape import TriangleMesh

File ~/giulio_vigano/geomfum_proj/geomfum/geomfum/shape/__init__.py:1
----> 1 from ._base import Shape
      2 from .mesh import TriangleMesh
      3 from .point_cloud import PointCloud

File ~/giulio_vigano/geomfum_proj/geomfum/geomfum/shape/_base.py:8
      4 import logging
      6 import gsops.backend as gs
----> 8 from geomfum.operator import Gradient, Laplacian
     11 class Shape(abc.ABC):
     12     def __init__(self, is_mesh):

File ~/giulio_vigano/geomfum_proj/geomfum/geomfum/operator.py:14
      7 from geomfum._registry import (
      8     FaceDivergenceOperatorRegistry,
      9     FaceOrientationOperatorRegistry,
     10     FaceValuedGradientRegistry,
     11     WhichRegistryMixins,
     12 )
     13 from geomfum.laplacian import LaplacianFinder, LaplacianSpectrumFinder
---> 14 from geomfum.shape.shape_utils import compute_gradient_matrix_fem
     17 # TODO: remove functional; simply use operator
     18 class FunctionalOperator(abc.ABC):

File ~/giulio_vigano/geomfum_proj/geomfum/geomfum/shape/shape_utils.py:5
      1 """Utility functions for shape computations."""
      3 import geomstats.backend as gs
----> 5 import geomfum.backend as xgs
      8 def compute_tangent_frames(vertices, normals):
      9     """Compute tangent frames for vertices.
     10
     11     Parameters
   (...)     21         Tangent frames.
     22     """

ModuleNotFoundError: No module named 'geomfum.backend'

Load a mesh.

 In [ ]:
dataset = NotebooksDataset()
mesh = TriangleMesh.from_file(dataset.get_filename("cat-00"))

Find Laplacian.

 In [ ]:
laplacian_finder = LaplacianFinder()
 In [ ]:
stiffness_matrix, mass_matrix = laplacian_finder(mesh)

(stiffness_matrix.shape, mass_matrix.shape)
((7207, 7207), (7207, 7207))

Tip: different algorithms can be used by changing which (check docs for possibilities).

Syntax sugar:

 In [ ]:
mesh.laplacian.find(laplacian_finder=laplacian_finder, recompute=False)

(mesh.laplacian.stiffness_matrix.shape, mesh.laplacian.mass_matrix.shape)
((7207, 7207), (7207, 7207))

Note: For pointcloud we have laplacian from Robust laplacian library

 In [ ]:
laplacian_finder = LaplacianFinder.from_registry(mesh=False, which="robust")

Further reading#