How to compute the Euclidean distance between meshes in correspondence?#

[1]:
import pyvista as pv

from polpo.plot.pyvista import RegisteredMeshesColoredPlotter
from polpo.preprocessing.load.pregnancy.random import get_two_random_meshes
from polpo.surface_mesh.euclidean import EuclideanSurfaces
from polpo.surface_mesh.qoi import centroid2farthest_vertex
[2]:
STATIC_VIZ = True
VIZ = 1

if STATIC_VIZ:
    pv.set_jupyter_backend("static")
[3]:
# TODO: create two blobs instead?
meshes = get_two_random_meshes(
    target_reduction=0,
    as_pv_surface=True,
)

mesh_a, mesh_b = meshes
[4]:
if VIZ > 1:
    pl = pv.Plotter(border=False)

    for mesh in meshes:
        pl.add_mesh(mesh.as_pv(), show_edges=True, opacity=0.6)

    pl.show()
[5]:
space = EuclideanSurfaces(mesh_a.faces)
[6]:
space.metric.squared_dist(mesh_a, mesh_b)
[6]:
np.float64(2.144286760119555)
[7]:
if VIZ > 0:
    ref_dist = centroid2farthest_vertex([mesh_a])[0]

    pl = RegisteredMeshesColoredPlotter()

    pl.add_mesh(mesh_b.as_pv(), show_edges=True, opacity=0.25)

    pl.add_meshes(
        mesh_a.as_pv(),
        mesh_b.as_pv(),
        ref_dist=ref_dist,
        show_edges=True,
        opacity=0.8,
        name="vertex diffs / ref",
        cmap="coolwarm",
    )

    pl.show()
../../../_images/_generated_notebooks_how_to_mesh_euclidean_7_0.png