This page was generated from: notebooks/examples/how_to_pad_a_3d_mesh.ipynb


[1]:
%load_ext autoreload
%autoreload 2
%config InlineBackend.rc = {'figure.figsize': (10,6)}
%matplotlib inline

Pad a 3D mesh

This notebook shows how to pad a 3D mesh. Note that padding a 3D mesh is done on the contour (before tetrahedralization).

[2]:
from nanomesh import Image
from nanomesh.data import binary_blobs3d

Generate some data

This cell generates a 3D data set with some feature blobs.

If you want to use your own data, any numpy array can be passed to into a `Image <https://nanomesh.readthedocs.io/en/latest/nanomesh.volume.html#nanomesh.volume.Volume>`__ object. Data stored as .npy can be loaded using Image.load().

[3]:
data = binary_blobs3d(seed=2020)

vol = Image(data)
vol.show_slice()
../_images/examples_examples_pad_a_3d_mesh_4_0.png
[3]:
<nanomesh.image._utils.SliceViewer at 0x263f0f987c0>

Generating the contour

[4]:
from nanomesh import Mesher

mesher = Mesher(vol)
mesher.generate_contour()
mesher.plot_contour(jupyter_backend='static', show_edges=True)
../_images/examples_examples_pad_a_3d_mesh_6_0.png

Padding different sides

The mesh can be padded using a similar API as 2d meshes. Each side (top/bottom, left/right, front/back) can be padded. A width must be specified.

Regions are labeled with a number. If no label is given, an arbitrary number is assigned. This is used to identify different regions in the mesh.

Note that tetgen will assign a different label for physically separate regions, even when they are given the same label/name.

[5]:
mesher.pad_contour(side='left', width=5, name='inner pad')
mesher.pad_contour(side='left', width=10, name='outer pad')
mesher.pad_contour(side='right', width=5, name='inner pad')
mesher.pad_contour(side='right', width=10, name='outer pad')

mesher.pad_contour(side='front', width=8, name='front pad')
mesher.pad_contour(side='back', width=8, name='back pad')
mesher.plot_contour(jupyter_backend='static', show_edges=True)
../_images/examples_examples_pad_a_3d_mesh_8_0.png

Generate tetrahedral mesh

Finally, generate the tetrahedral mesh. Notice that the inner and outer pads have the same label, because we assigned the same name in Mesher.pad_contour().

[6]:
tetras = mesher.tetrahedralize(opts='-pAq -a10000')
tetras.plot_pyvista(jupyter_backend='static', show_edges=True)
../_images/examples_examples_pad_a_3d_mesh_10_0.png

Generated by nbsphinx from a Jupyter notebook.