.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/repair_planar.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_repair_planar.py: Partial Fill Holes ------------------ This example fills all but the largest holes in a planar mesh. .. GENERATED FROM PYTHON SOURCE LINES 7-16 .. code-block:: Python # sphinx_gallery_thumbnail_number = 1 import numpy as np import pyvista as pv from pymeshfix import MeshFix from pymeshfix._meshfix import PyTMesh from pymeshfix.examples import planar_mesh .. GENERATED FROM PYTHON SOURCE LINES 17-18 plot the holes on the original mesh .. GENERATED FROM PYTHON SOURCE LINES 18-32 .. code-block:: Python orig_mesh = pv.read(planar_mesh) # orig_mesh.plot_boundaries() meshfix = MeshFix(orig_mesh) holes = meshfix.extract_holes() # Render the mesh and outline the holes plotter = pv.Plotter() plotter.add_mesh(orig_mesh, color=True) plotter.add_mesh(holes, color="r", line_width=5) plotter.enable_eye_dome_lighting() # helps depth perception _ = plotter.show() .. image-sg:: /examples/images/sphx_glr_repair_planar_001.png :alt: repair planar :srcset: /examples/images/sphx_glr_repair_planar_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 33-34 This example uses the lower level C interface to the TMesh object. .. GENERATED FROM PYTHON SOURCE LINES 34-43 .. code-block:: Python mfix = PyTMesh(False) # False removes extra verbose output mfix.load_file(planar_mesh) # Fills all the holes having at at most 'nbe' boundary edges. If # 'refine' is true, adds inner vertices to reproduce the sampling # density of the surroundings. Returns number of holes patched. If # 'nbe' is 0 (default), all the holes are patched. mfix.fill_small_boundaries(nbe=100, refine=True) .. rst-class:: sphx-glr-script-out .. code-block:: none 16 .. GENERATED FROM PYTHON SOURCE LINES 44-45 Convert back to a pyvista mesh .. GENERATED FROM PYTHON SOURCE LINES 45-52 .. code-block:: Python vert, faces = mfix.return_arrays() triangles = np.empty((faces.shape[0], 4), dtype=faces.dtype) triangles[:, -3:] = faces triangles[:, 0] = 3 mesh = pv.PolyData(vert, triangles) .. GENERATED FROM PYTHON SOURCE LINES 53-58 Plot the repaired mesh along with the original holes Note: It seems there is a limit to the repair algorithm whereby some of the holes that include only a single point are not filled. These boundary holes are not detected by VTK's hole repair algorithm either. .. GENERATED FROM PYTHON SOURCE LINES 58-64 .. code-block:: Python plotter = pv.Plotter() plotter.add_mesh(mesh, color=True) plotter.add_mesh(holes, color="r", line_width=5) plotter.enable_eye_dome_lighting() # helps depth perception _ = plotter.show() .. image-sg:: /examples/images/sphx_glr_repair_planar_002.png :alt: repair planar :srcset: /examples/images/sphx_glr_repair_planar_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.698 seconds) .. _sphx_glr_download_examples_repair_planar.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: repair_planar.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: repair_planar.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_