.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/cow.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_cow.py: Cow ~~~ Tetrahedralize a cow mesh. .. GENERATED FROM PYTHON SOURCE LINES 7-13 .. code-block:: Python # sphinx_gallery_thumbnail_number = 3 import numpy as np import pyvista as pv from pyvista import examples import tetgen .. GENERATED FROM PYTHON SOURCE LINES 14-27 .. code-block:: Python cow_mesh = examples.download_cow().triangulate() cpos = [(13.0, 7.6, -13.85), (0.44, -0.4, -0.37), (-0.28, 0.9, 0.3)] cpos = [ (15.87144235049248, 4.879216382405231, -12.14248864876951), (1.1623113035352375, -0.7609060338348953, 0.3192320579894903), (-0.19477922834083672, 0.9593375398915212, 0.20428542963665386), ] cow_mesh.plot(cpos=cpos) .. image-sg:: /examples/images/sphx_glr_cow_001.png :alt: cow :srcset: /examples/images/sphx_glr_cow_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 28-35 .. code-block:: Python tet = tetgen.TetGen(cow_mesh) tet.make_manifold() tet.tetrahedralize() cow_grid = tet.grid .. GENERATED FROM PYTHON SOURCE LINES 36-41 .. code-block:: Python # plot half the cow mask = np.logical_or(cow_grid.points[:, 0] < 0, cow_grid.points[:, 0] > 4) half_cow = cow_grid.extract_points(mask) .. GENERATED FROM PYTHON SOURCE LINES 42-49 .. code-block:: Python plotter = pv.Plotter() plotter.add_mesh(half_cow, color="w", show_edges=True) plotter.add_mesh(cow_grid, color="r", style="wireframe", opacity=0.2) plotter.camera_position = cpos plotter.show() .. image-sg:: /examples/images/sphx_glr_cow_002.png :alt: cow :srcset: /examples/images/sphx_glr_cow_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 50-51 Make animation of the mesh construction .. GENERATED FROM PYTHON SOURCE LINES 51-69 .. code-block:: Python plotter = pv.Plotter(off_screen=True, window_size=[1000, 1000]) plotter.open_gif("cow.gif") plotter.add_mesh(cow_grid, color="r", style="wireframe", opacity=0.2) plotter.camera_position = cpos plotter.write_frame() nframe = 36 xb = np.array(cow_grid.bounds[0:2]) step = xb.ptp() / nframe for val in np.arange(xb[0] + step, xb[1] + step, step): mask = np.argwhere(cow_grid.cell_centers().points[:, 0] < val) half_cow = cow_grid.extract_cells(mask) plotter.add_mesh(half_cow, color="w", show_edges=True, name="building") plotter.update() plotter.write_frame() plotter.close() .. image-sg:: /examples/images/sphx_glr_cow_003.gif :alt: cow :srcset: /examples/images/sphx_glr_cow_003.gif :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 15.278 seconds) .. _sphx_glr_download_examples_cow.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: cow.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: cow.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_