.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/trifaces.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_trifaces.py: Face Markers and Surface Data ----------------------------- Demonstrate the usage of several attributes of :class:`tetgen.TetGen`. You can access faces and edges from an instance of :class:`tetgen.TetGen` from the :attr:`tetgen.TetGen.trifaces` and :attr:`tetgen.TetGen.edges` attributes. .. GENERATED FROM PYTHON SOURCE LINES 11-17 .. code-block:: Python # sphinx_gallery_thumbnail_number = 1 import numpy as np import pyvista as pv import tetgen .. GENERATED FROM PYTHON SOURCE LINES 18-19 First, let's tetrahedralize a sphere. .. GENERATED FROM PYTHON SOURCE LINES 19-25 .. code-block:: Python sphere = pv.Icosphere(nsub=1) tet = tetgen.TetGen(sphere) tet.tetrahedralize(order=1, mindihedral=20, minratio=1.5, regionattrib=True) tet.grid .. raw:: html
UnstructuredGridInformation
N Cells80
N Points43
X Bounds-1.000e+00, 1.000e+00
Y Bounds-1.000e+00, 1.000e+00
Z Bounds-1.000e+00, 1.000e+00
N Arrays0


.. GENERATED FROM PYTHON SOURCE LINES 26-28 Next, let's construct a :class:`pyvista.PolyData` from the triangular faces, accessible from the :attr:`tetgen.TetGen.trifaces` attribute. .. GENERATED FROM PYTHON SOURCE LINES 28-34 .. code-block:: Python # mesh containing both exterior and interior elements trimesh = pv.PolyData.from_regular_faces(tet.node, tet.trifaces) trimesh .. raw:: html
PolyDataInformation
N Cells200
N Points43
N Strips0
X Bounds-1.000e+00, 1.000e+00
Y Bounds-1.000e+00, 1.000e+00
Z Bounds-1.000e+00, 1.000e+00
N Arrays0


.. GENERATED FROM PYTHON SOURCE LINES 35-37 Interior faces are marked by the :attr:`tetgen.TetGen.triface_markers` attribute. We can plot this using PyVista. .. GENERATED FROM PYTHON SOURCE LINES 37-50 .. code-block:: Python pl = pv.Plotter() pl.add_mesh( trimesh.explode(0.3), scalars=tet.triface_markers, show_edges=True, show_scalar_bar=False, ) pl.enable_ssao(radius=0.1) pl.enable_anti_aliasing("ssaa") pl.camera.zoom(1.5) pl.show() .. image-sg:: /examples/images/sphx_glr_trifaces_001.png :alt: trifaces :srcset: /examples/images/sphx_glr_trifaces_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 51-53 Interior faces are denoted with 0 and exterior faces are marked as -1 within the :attr:`tetgen.TetGen.triface_markers` array. .. GENERATED FROM PYTHON SOURCE LINES 53-57 .. code-block:: Python tet.triface_markers .. rst-class:: sphx-glr-script-out .. code-block:: none array([ 0, 0, 0, -1, 0, 0, 0, -1, 0, 0, 0, -1, 0, 0, 0, -1, 0, 0, 0, -1, 0, 0, 0, -1, 0, 0, -1, -1, 0, 0, -1, 0, 0, -1, -1, 0, 0, -1, -1, 0, -1, 0, 0, -1, 0, 0, -1, 0, -1, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, -1, 0, 0, -1, 0, -1, 0, 0, 0, -1, 0, 0, -1, 0, -1, 0, -1, 0, 0, -1, 0, -1, 0, -1, 0, 0, -1, 0, -1, 0, -1, 0, 0, -1, 0, 0, -1, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, -1, 0, 0, 0, -1, 0, 0, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, 0, -1, 0, 0, 0, -1, 0, -1, 0, -1, 0, 0, -1, 0, 0, -1, -1, 0, 0, -1, 0, 0, -1, 0, -1, 0, 0, 0, -1, -1, 0, 0, -1, 0, -1, 0, -1, 0, -1, 0, 0, -1, 0, -1, -1, 0, 0, -1, 0, -1, 0, -1, 0, 0, -1, -1, 0, 0, -1, 0, -1, -1, 0, -1, 0, -1, 0, -1, -1, 0, -1, -1], dtype=int32) .. GENERATED FROM PYTHON SOURCE LINES 58-60 Finally, create an edges :class:`pyvista.PolyData` from the :attr:`tetgen.TetGen.edges` attribute. .. GENERATED FROM PYTHON SOURCE LINES 60-74 .. code-block:: Python # construct a VTK style edges array n_edges = tet.edges.shape[0] edges = np.empty((n_edges, 3), dtype=int) edges[:, 0] = 2 edges[:, 1:] = tet.edges # mesh containing both exterior and interior elements edgemesh = pv.PolyData() edgemesh.points = tet.node edgemesh.lines = edges edgemesh .. raw:: html
PolyDataInformation
N Cells162
N Points43
N Strips0
X Bounds-1.000e+00, 1.000e+00
Y Bounds-1.000e+00, 1.000e+00
Z Bounds-1.000e+00, 1.000e+00
N Arrays0


.. GENERATED FROM PYTHON SOURCE LINES 75-76 Plot the edges with ``pyvista`` and color the interior and exterior edges. .. GENERATED FROM PYTHON SOURCE LINES 76-85 .. code-block:: Python edgemesh.plot( scalars=tet.edge_markers, cmap="bwr", line_width=10, render_lines_as_tubes=True, show_scalar_bar=False, zoom=1.5, ) .. image-sg:: /examples/images/sphx_glr_trifaces_002.png :alt: trifaces :srcset: /examples/images/sphx_glr_trifaces_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 20.295 seconds) .. _sphx_glr_download_examples_trifaces.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: trifaces.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: trifaces.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: trifaces.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_