.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "../../docs/source/_gallery/example_mesh_simple_workflow.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_.._.._docs_source__gallery_example_mesh_simple_workflow.py: .. _example_mesh_simple_workflow: Simple mesh workflow ===================================== .. contents:: Table of Contents :local: :depth: 2 :backlinks: top This example demonstrates a simple workflow for creating, manipulating, and visualizing a mesh using the ``pysdic`` library. .. seealso:: :class:`pysdic.Mesh` - Official documentation for the Mesh class. .. GENERATED FROM PYTHON SOURCE LINES 23-30 Creating a Mesh --------------------------- To create a mesh, we first need to give the coordinates of the vertices and the connectivity. Additionally some convenience methods are provided to save and load point clouds from files. .. GENERATED FROM PYTHON SOURCE LINES 30-42 .. code-block:: Python from pysdic import create_triangle_3_heightmap import numpy as np surface_mesh = create_triangle_3_heightmap( height_function=lambda x, y: 0.5 * np.sin(np.pi * x) * np.cos(np.pi * y), x_bounds=(-1.0, 1.0), y_bounds=(-1.0, 1.0), n_x=50, n_y=50, ) .. GENERATED FROM PYTHON SOURCE LINES 43-50 Add some point properties --------------------------- We can add properties to the vertices in the mesh. Here, we add a random scalar property to each point. Each property can be multi-dimensional, e.g., a vector or tensor associated with each point. All the properties are stored in a dictionary-like structure with shape :math:`(N_p, A)`. .. GENERATED FROM PYTHON SOURCE LINES 50-55 .. code-block:: Python heigth = surface_mesh.points[:, 2] # Get the height (z-coordinate) of each point intensity = (heigth - heigth.min()) / (heigth.max() - heigth.min()) # Normalize height to [0, 1] for intensity surface_mesh.vertices["intensity"] = intensity # Add intensity as a point property .. GENERATED FROM PYTHON SOURCE LINES 56-65 Visualize the Mesh (Several options available) ------------------------------------------------ The point cloud can be visualized using the built-in visualization method with ``pyvista``. .. seealso:: :meth:`pysdic.Mesh.visualize` - Official documentation for the visualize method. .. GENERATED FROM PYTHON SOURCE LINES 65-76 .. code-block:: Python surface_mesh.visualize( face_color=None, title="Example Point Cloud with Texture", vertex_size=10, bounds_grid="back", property_cmap="inferno", vertex_property="intensity", show_vertices=False, show_edges=True, ) .. image-sg:: /_gallery/images/sphx_glr_example_mesh_simple_workflow_001.png :alt: example mesh simple workflow :srcset: /_gallery/images/sphx_glr_example_mesh_simple_workflow_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.343 seconds) .. _sphx_glr_download_.._.._docs_source__gallery_example_mesh_simple_workflow.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: example_mesh_simple_workflow.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: example_mesh_simple_workflow.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: example_mesh_simple_workflow.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_