.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/plot_volume.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_auto_examples_plot_volume.py: Volume meshing ============== .. GENERATED FROM PYTHON SOURCE LINES 7-10 .. code-block:: Python import openturns as ot import otmeshing .. GENERATED FROM PYTHON SOURCE LINES 11-12 Generate a tetrahedron point cloud and build its convex hull surface .. GENERATED FROM PYTHON SOURCE LINES 12-20 .. code-block:: Python tetra_pts = ot.Sample( [[0.0, 0.0, 0.0], [1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0]] ) hull = otmeshing.ConvexHullMesher() surface = hull.build(tetra_pts) print("surface: vertices=", surface.getVerticesNumber(), "facets=", surface.getSimplicesNumber()) .. rst-class:: sphx-glr-script-out .. code-block:: none surface: vertices= 4 facets= 4 .. GENERATED FROM PYTHON SOURCE LINES 21-22 Tetrahedralize the surface with the centroid strategy .. GENERATED FROM PYTHON SOURCE LINES 22-29 .. code-block:: Python mesher = otmeshing.VolumeMesher() mesher.setApexStrategy(otmeshing.VolumeMesher.CENTROID) volume = mesher.build(surface) print("volume (centroid):", volume.getVerticesNumber(), "vertices,", volume.getSimplicesNumber(), "tets, volume=", volume.getVolume()) .. rst-class:: sphx-glr-script-out .. code-block:: none volume (centroid): 5 vertices, 4 tets, volume= 0.16666666666666666 .. GENERATED FROM PYTHON SOURCE LINES 30-31 First-vertex strategy produces the same volume but fewer tetrahedra .. GENERATED FROM PYTHON SOURCE LINES 31-37 .. code-block:: Python mesher.setApexStrategy(otmeshing.VolumeMesher.FIRST_VERTEX) volume_first = mesher.build(surface) print("volume (first):", volume_first.getVerticesNumber(), "vertices,", volume_first.getSimplicesNumber(), "tets, volume=", volume_first.getVolume()) .. rst-class:: sphx-glr-script-out .. code-block:: none volume (first): 4 vertices, 1 tets, volume= 0.16666666666666666 .. GENERATED FROM PYTHON SOURCE LINES 38-39 Cube example .. GENERATED FROM PYTHON SOURCE LINES 39-44 .. code-block:: Python cube_corners = ot.IntervalMesher([1] * 3).build(ot.Interval(3)).getVertices() cube_surface = hull.build(cube_corners) mesher.setApexStrategy(otmeshing.VolumeMesher.CENTROID) cube_volume = mesher.build(cube_surface) print("cube volume:", cube_volume.getSimplicesNumber(), "tets, volume=", cube_volume.getVolume()) .. rst-class:: sphx-glr-script-out .. code-block:: none cube volume: 12 tets, volume= 1.0 .. _sphx_glr_download_auto_examples_plot_volume.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_volume.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_volume.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_volume.zip `