.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/1_data/plot_pyvista.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_1_data_plot_pyvista.py: PolyData conversion from and to PyVista or Vedo =============================================== `PyVista `_ is a Python library for 3D visualization and mesh manipulation. It is a python wrapper of the `VTK `_ library. PyVista is used in scikit-shapes as a backend to load and save meshes in various formats. `Vedo `_ is another Python library for 3D visualization. It is also a python wrapper of the VTK library. It is used in scikit-shapes for interactive visualization. Scikit-shapes [PolyData](skshsapes.data.polydata.PolyData) can be exported to PyVista PolyData or Vedo Mesh, and vice versa. This allows to leverage the visualization and mesh manipulation capabilities of both libraries. In addition to the mesh geometry, the signals and landmarks are encoded in the PyVista or Vedo mesh, and are preserved when the mesh is loaded back from PyVista. .. GENERATED FROM PYTHON SOURCE LINES 23-28 Load a mesh from PyVista's examples ----------------------------------- We load a quadrangulated cow mesh from PyVista. As scikit-shapes meshes are triangular, an automatic triangulation is performed when importing the mesh. .. GENERATED FROM PYTHON SOURCE LINES 28-40 .. code-block:: Python import pyvista as pv import torch from pyvista import examples import skshapes as sks mesh_pyvista = examples.download_cow() mesh_sks = sks.PolyData(mesh_pyvista) assert mesh_pyvista.n_points == mesh_sks.n_points .. GENERATED FROM PYTHON SOURCE LINES 41-51 Preservation of signals and landmarks ------------------------------------- The methods `.to_pyvista()` and `.to_vedo()` allow to convert a `PolyData` object to a PyVista or Vedo mesh. The point data and landmarks are preserved during the conversion: if the mesh is loaded back from PyVista or Vedo, the signals and landmarks are still there. The following illustrates the preservation of signals and landmarks when converting a `PolyData` object to PyVista and back. .. GENERATED FROM PYTHON SOURCE LINES 51-94 .. code-block:: Python mesh_sks.point_data["signal"] = mesh_sks.points[:, 0] # Now, export the mesh to PyVista mesh_pv2 = mesh_sks.to_pyvista() # The signal is transferred to the PyVista mesh as a point data array # with the same name and can be plotted mesh_pv2.plot(scalars="signal", cpos="xy") # Back to scikit-shapes, the signal is preserved mesh_sks_back = sks.PolyData(mesh_pv2) assert torch.allclose( mesh_sks_back.point_data["signal"], mesh_sks.point_data["signal"] ) # Set some landmarks landmarks_indices = [0, 10, 154, 125, 1544, 187, 32, 252, 1214] mesh_sks.landmark_indices = landmarks_indices # Export to PyVista mesh_pv3 = mesh_sks.to_pyvista() # The landmarks are stored in the field data of the PyVista mesh # there can ba accessed as a 3D point cloud with the name "landmark_points" plotter = pv.Plotter() plotter.add_mesh(mesh_pv3, color="w") plotter.add_points( mesh_pv3.field_data["landmark_points"], color="r", point_size=10, label="landmarks", ) plotter.add_legend() plotter.view_xy() plotter.show() # Back to scikit-shapes, the landmarks are preserved mesh_sks_back = sks.PolyData(mesh_pv3) assert torch.allclose( mesh_sks_back.landmark_indices, mesh_sks.landmark_indices ) .. tab-set:: .. tab-item:: Static Scene .. image-sg:: /auto_examples/1_data/images/sphx_glr_plot_pyvista_001.png :alt: plot pyvista :srcset: /auto_examples/1_data/images/sphx_glr_plot_pyvista_001.png :class: sphx-glr-single-img .. tab-item:: Interactive Scene .. offlineviewer:: /home/runner/work/scikit-shapes/scikit-shapes/doc/source/auto_examples/1_data/images/sphx_glr_plot_pyvista_001.vtksz .. tab-set:: .. tab-item:: Static Scene .. image-sg:: /auto_examples/1_data/images/sphx_glr_plot_pyvista_002.png :alt: plot pyvista :srcset: /auto_examples/1_data/images/sphx_glr_plot_pyvista_002.png :class: sphx-glr-single-img .. tab-item:: Interactive Scene .. offlineviewer:: /home/runner/work/scikit-shapes/scikit-shapes/doc/source/auto_examples/1_data/images/sphx_glr_plot_pyvista_002.vtksz .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 1.553 seconds) .. _sphx_glr_download_auto_examples_1_data_plot_pyvista.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_pyvista.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_pyvista.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_