Saving and loading surfaces#

In this notebook we will save a surface to disk and reload it from there using vedo.

See also

import napari_process_points_and_surfaces as nppas
import vedo

from branchoid import branchoid

Starting point is again the surface of the simulated branchoid.

binary_image = branchoid()
surface = nppas.all_labels_to_surface(binary_image)
surface
nppas.SurfaceTuple
origin (z/y/x)[0. 0. 0.]
center of mass(z/y/x)50.000,46.575,42.589
scale(z/y/x)1.000,1.000,1.000
bounds (z/y/x)25.500...74.500
2.500...88.500
2.500...83.500
average size31.277
number of vertices19040
number of faces38076

Saving surfaces to disk#

The vedo library functions for saving and loading surfaces meshes. To convert them from/to napari-compatible surface-tuples, we use napari-process-points-and-surfaces (nppas).

mesh = nppas.to_vedo_mesh(surface)

filename = "../../data/branchoid.ply"

_ = vedo.write(mesh, filename)

Loading meshes from disk#

new_mesh = vedo.load(filename)
new_mesh

vedo.mesh.Mesh
(../../data/branchoid.ply)
bounds
(x/y/z)
25.50 ... 74.50
2.500 ... 88.50
2.500 ... 83.50
center of mass (50.0, 46.6, 42.6)
average size 31.277
nr. points / faces 19040 / 38076
new_surface = nppas.to_napari_surface_data(new_mesh)
new_surface
nppas.SurfaceTuple
origin (z/y/x)[0. 0. 0.]
center of mass(z/y/x)50.000,46.575,42.589
scale(z/y/x)1.000,1.000,1.000
bounds (z/y/x)25.500...74.500
2.500...88.500
2.500...83.500
average size31.277
number of vertices19040
number of faces38076