Notebook source code:
notebooks/how_to/16_vis_basic.ipynb
Run it yourself on binder
How to plot a mesh?#
In [1]:
from geomfum.dataset import NotebooksDataset
from geomfum.laplacian import LaplacianFinder, LaplacianSpectrumFinder, ScipyEigsh
from geomfum.plot import MeshPlotter
from geomfum.shape import TriangleMesh
In [2]:
dataset = NotebooksDataset()
mesh = TriangleMesh.from_file(dataset.get_filename("cat-00"))
mesh.n_vertices, mesh.n_faces
Out [2]:
(7207, 14410)
With plotly
.
In [3]:
plotter = MeshPlotter.from_registry(which="plotly")
plotter.add_mesh(mesh)
plotter.show()
Data type cannot be displayed: application/vnd.plotly.v1+json
With pyvista
.
In [4]:
plotter = MeshPlotter.from_registry(which="pyvista")
plotter.add_mesh(mesh)
plotter.show()
With polyscope
.
In [5]:
plotter = MeshPlotter.from_registry(which="polyscope")
plotter.add_mesh(mesh)
plotter.show()
[polyscope] Backend: openGL3_glfw -- Loaded openGL version: 4.6 (Core Profile) Mesa 23.3.2-1pop0~1704238321~22.04~36f1d0e
How to visualize a function?#
We can visualize scalar function on the surface of the mesh, e.g. we can visualize the LBO basis.
In [6]:
spectrum_finder = LaplacianSpectrumFinder(
nonzero=True,
fix_sign=False,
laplacian_finder=LaplacianFinder.from_registry(which="robust"),
eig_solver=ScipyEigsh(spectrum_size=2, sigma=-0.01),
)
eigvals, eigvecs = spectrum_finder(mesh, as_basis=False)
(eigvals.shape, eigvecs.shape)
Out [6]:
((1,), (7207, 1))
With plotly
.
In [7]:
plotter = MeshPlotter.from_registry(colormap="RdBu", which="plotly")
plotter.add_mesh(mesh)
plotter.set_vertex_scalars(eigvecs[:, 0])
plotter.show()
Data type cannot be displayed: application/vnd.plotly.v1+json
With pyvista
.
In [8]:
plotter = MeshPlotter.from_registry(which="pyvista")
plotter.add_mesh(mesh)
plotter.set_vertex_scalars(eigvecs[:, 0])
plotter.show()
With polyscope
.
In [9]:
plotter = MeshPlotter.from_registry(which="polyscope")
plotter.add_mesh(mesh)
plotter.set_vertex_scalars(eigvecs[:, 0])
plotter.show()