.. 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 Mesh Repair --------------- Repair a mesh of a cow. .. GENERATED FROM PYTHON SOURCE LINES 7-16 .. code-block:: Python import numpy as np # sphinx_gallery_thumbnail_number = 1 import pyvista as pv from pyvista import examples import pymeshfix as mf .. GENERATED FROM PYTHON SOURCE LINES 17-24 .. code-block:: Python cow = examples.download_cow() # Add holes and cast to triangulated PolyData cow["random"] = np.random.rand(cow.n_cells) cow_w_holes = cow.threshold(0.9, invert=True).extract_geometry().triangulate() print(cow_w_holes) .. rst-class:: sphx-glr-script-out .. code-block:: none /home/runner/work/pymeshfix/pymeshfix/examples/cow.py:21: PyVistaDeprecationWarning: `extract_geometry` is deprecated. Use `extract_surface(algorithm=None)` instead. cow_w_holes = cow.threshold(0.9, invert=True).extract_geometry().triangulate() PolyData (0x7fe5ac241c00) N Cells: 5233 N Points: 2903 N Strips: 0 X Bounds: -4.446e+00, 5.998e+00 Y Bounds: -3.637e+00, 2.760e+00 Z Bounds: -1.701e+00, 1.701e+00 N Arrays: 1 .. GENERATED FROM PYTHON SOURCE LINES 25-43 .. code-block:: Python # A nice camera location to view the cow cpos = [(6.56, 8.73, 22.03), (0.77, -0.44, 0.0), (-0.13, 0.93, -0.35)] meshfix = mf.MeshFix(cow_w_holes, verbose=True) holes = meshfix.extract_holes() # Render the mesh and outline the holes p = pv.Plotter() p.add_mesh(cow_w_holes, color=True, smooth_shading=True, split_sharp_edges=True) p.add_mesh(holes, color="r", line_width=8) p.camera_position = cpos p.camera.zoom(1.5) p.enable_eye_dome_lighting() # helps depth perception p.enable_anti_aliasing("ssaa") p.show() .. 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 44-45 Repair the cow mesh .. GENERATED FROM PYTHON SOURCE LINES 45-48 .. code-block:: Python meshfix.repair() .. GENERATED FROM PYTHON SOURCE LINES 49-50 Show the repaired result .. GENERATED FROM PYTHON SOURCE LINES 50-54 .. code-block:: Python repaired = meshfix.mesh print(repaired) .. rst-class:: sphx-glr-script-out .. code-block:: none PolyData (0x7fe5ac241f60) N Cells: 5448 N Points: 2726 N Strips: 0 X Bounds: -3.696e+00, 5.998e+00 Y Bounds: -3.637e+00, 2.760e+00 Z Bounds: -1.701e+00, 1.701e+00 N Arrays: 0 .. GENERATED FROM PYTHON SOURCE LINES 55-56 .. code-block:: Python repaired.plot(cpos=cpos, zoom=1.5, smooth_shading=True, split_sharp_edges=True) .. image-sg:: /examples/images/sphx_glr_cow_002.png :alt: cow :srcset: /examples/images/sphx_glr_cow_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 1.401 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 ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: cow.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_