.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/00-basic-pyvista-examples/picker.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_00-basic-pyvista-examples_picker.py: .. _ref_picker: =================== Activate the picker =================== This example shows how to activate the picker, which is the tool that you use to select an object in the plotter and get its name. .. GENERATED FROM PYTHON SOURCE LINES 36-38 Relate ``CustomObject`` class with a PyVista mesh ================================================= .. GENERATED FROM PYTHON SOURCE LINES 38-64 .. code-block:: Python import pyvista as pv # Note that the ``CustomObject`` class must have a way to get the mesh # and a name or ID. class CustomObject: def __init__(self): self.name = "CustomObject" self.mesh = pv.Cube(center=(1, 1, 0)) def get_mesh(self): return self.mesh def name(self): return self.name # Create a custom object custom_cube = CustomObject() custom_cube.name = "CustomCube" custom_sphere = CustomObject() custom_sphere.mesh = pv.Sphere(center=(0, 0, 5)) custom_sphere.name = "CustomSphere" .. GENERATED FROM PYTHON SOURCE LINES 65-67 Create two ``MeshObjectPlot`` instances ======================================= .. GENERATED FROM PYTHON SOURCE LINES 67-75 .. code-block:: Python from ansys.tools.visualization_interface import MeshObjectPlot # Create an instance mesh_object_cube = MeshObjectPlot(custom_cube, custom_cube.get_mesh()) mesh_object_sphere = MeshObjectPlot(custom_sphere, custom_sphere.get_mesh()) .. GENERATED FROM PYTHON SOURCE LINES 76-78 Activate the picking capabilities ================================= .. GENERATED FROM PYTHON SOURCE LINES 78-88 .. code-block:: Python from ansys.tools.visualization_interface import Plotter from ansys.tools.visualization_interface.backends.pyvista import PyVistaBackend pv_backend = PyVistaBackend(allow_picking=True, plot_picked_names=True) pl = Plotter(backend=pv_backend) pl.plot(mesh_object_cube) pl.plot(mesh_object_sphere) pl.show() .. tab-set:: .. tab-item:: Static Scene .. image-sg:: /examples/00-basic-pyvista-examples/images/sphx_glr_picker_001.png :alt: picker :srcset: /examples/00-basic-pyvista-examples/images/sphx_glr_picker_001.png :class: sphx-glr-single-img .. tab-item:: Interactive Scene .. offlineviewer:: /home/runner/work/ansys-tools-visualization-interface/ansys-tools-visualization-interface/doc/source/examples/00-basic-pyvista-examples/images/sphx_glr_picker_001.vtksz .. GENERATED FROM PYTHON SOURCE LINES 89-91 Activate the hover capabilities =============================== .. GENERATED FROM PYTHON SOURCE LINES 91-102 .. code-block:: Python from ansys.tools.visualization_interface import Plotter from ansys.tools.visualization_interface.backends.pyvista import PyVistaBackend pv_backend = PyVistaBackend(allow_hovering=True) pl = Plotter(backend=pv_backend) pl.plot(mesh_object_cube) pl.plot(mesh_object_sphere) pl.show() .. tab-set:: .. tab-item:: Static Scene .. image-sg:: /examples/00-basic-pyvista-examples/images/sphx_glr_picker_002.png :alt: picker :srcset: /examples/00-basic-pyvista-examples/images/sphx_glr_picker_002.png :class: sphx-glr-single-img .. tab-item:: Interactive Scene .. offlineviewer:: /home/runner/work/ansys-tools-visualization-interface/ansys-tools-visualization-interface/doc/source/examples/00-basic-pyvista-examples/images/sphx_glr_picker_002.vtksz .. GENERATED FROM PYTHON SOURCE LINES 103-105 Using StructuredGrid mesh ========================== .. GENERATED FROM PYTHON SOURCE LINES 105-133 .. code-block:: Python import numpy as np class CustomStructuredObject: def __init__(self): self.name = "CustomObject" xrng = np.arange(-10, 10, 2, dtype=np.float32) yrng = np.arange(-10, 10, 5, dtype=np.float32) zrng = np.arange(-10, 10, 1, dtype=np.float32) x, y, z = np.meshgrid(xrng, yrng, zrng, indexing='ij') grid = pv.StructuredGrid(x, y, z) self.mesh = grid def get_mesh(self): return self.mesh def name(self): return self.name pv_backend = PyVistaBackend() pl = Plotter(backend=pv_backend) structured_object = CustomStructuredObject() mo_plot = MeshObjectPlot(structured_object, structured_object.get_mesh()) pl.plot(mo_plot) pl.show() .. tab-set:: .. tab-item:: Static Scene .. image-sg:: /examples/00-basic-pyvista-examples/images/sphx_glr_picker_003.png :alt: picker :srcset: /examples/00-basic-pyvista-examples/images/sphx_glr_picker_003.png :class: sphx-glr-single-img .. tab-item:: Interactive Scene .. offlineviewer:: /home/runner/work/ansys-tools-visualization-interface/ansys-tools-visualization-interface/doc/source/examples/00-basic-pyvista-examples/images/sphx_glr_picker_003.vtksz .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.842 seconds) .. _sphx_glr_download_examples_00-basic-pyvista-examples_picker.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: picker.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: picker.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: picker.zip `