
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "tutorial/08_widgets/e_plane-widget.py"
.. LINE NUMBERS ARE GIVEN BELOW.

.. only:: html

    .. note::
        :class: sphx-glr-download-link-note

        :ref:`Go to the end <sphx_glr_download_tutorial_08_widgets_e_plane-widget.py>`
        to download the full example code. or to run this example in your browser via Binder

.. rst-class:: sphx-glr-example-title

.. _sphx_glr_tutorial_08_widgets_e_plane-widget.py:


.. _plane_widget_example:

Plane Widget
~~~~~~~~~~~~

The plane widget can be enabled and disabled by the
:func:`pyvista.Plotter.add_plane_widget` and
:func:`pyvista.Plotter.clear_plane_widgets` methods respectively.
As with all widgets, you must provide a custom callback method to utilize that
plane. Considering that planes are most commonly used for clipping and slicing
meshes, we have included two helper methods for doing those tasks!

Let's use a plane to clip a mesh:

.. GENERATED FROM PYTHON SOURCE LINES 16-26

.. code-block:: Python


    import pyvista as pv
    from pyvista import examples

    vol = examples.download_brain()

    pl = pv.Plotter()
    pl.add_mesh_clip_plane(vol)
    pl.show()








.. tab-set::



   .. tab-item:: Static Scene



            
     .. image-sg:: /tutorial/08_widgets/images/sphx_glr_e_plane-widget_001.png
        :alt: e plane widget
        :srcset: /tutorial/08_widgets/images/sphx_glr_e_plane-widget_001.png
        :class: sphx-glr-single-img
     


   .. tab-item:: Interactive Scene



       .. offlineviewer:: /home/runner/work/pyvista-tutorial/pyvista-tutorial/doc/source/tutorial/08_widgets/images/sphx_glr_e_plane-widget_001.vtksz






.. GENERATED FROM PYTHON SOURCE LINES 28-29

After interacting with the scene, the clipped mesh is available as:

.. GENERATED FROM PYTHON SOURCE LINES 29-31

.. code-block:: Python

    pl.plane_clipped_meshes





.. rst-class:: sphx-glr-script-out

 .. code-block:: none


    [UnstructuredGrid (0x7f4fac5eb340)
      N Cells:    3538080
      N Points:   3613484
      X Bounds:   9.000e+01, 1.800e+02
      Y Bounds:   0.000e+00, 2.160e+02
      Z Bounds:   0.000e+00, 1.800e+02
      N Arrays:   2]



.. GENERATED FROM PYTHON SOURCE LINES 32-35

And here is a screen capture of a user interacting with this

.. image:: ../../images/gifs/plane-clip.gif

.. GENERATED FROM PYTHON SOURCE LINES 37-38

Or you could slice a mesh using the plane widget:

.. GENERATED FROM PYTHON SOURCE LINES 38-42

.. code-block:: Python


    pl = pv.Plotter()
    pl.add_mesh_slice(vol)
    pl.show()







.. tab-set::



   .. tab-item:: Static Scene



            
     .. image-sg:: /tutorial/08_widgets/images/sphx_glr_e_plane-widget_002.png
        :alt: e plane widget
        :srcset: /tutorial/08_widgets/images/sphx_glr_e_plane-widget_002.png
        :class: sphx-glr-single-img
     


   .. tab-item:: Interactive Scene



       .. offlineviewer:: /home/runner/work/pyvista-tutorial/pyvista-tutorial/doc/source/tutorial/08_widgets/images/sphx_glr_e_plane-widget_002.vtksz






.. GENERATED FROM PYTHON SOURCE LINES 43-44

After interacting with the scene, the slice is available as:

.. GENERATED FROM PYTHON SOURCE LINES 44-46

.. code-block:: Python

    pl.plane_sliced_meshes





.. rst-class:: sphx-glr-script-out

 .. code-block:: none


    [PolyData (0x7f4fac5eafe0)
      N Cells:    38880
      N Points:   39277
      N Strips:   0
      X Bounds:   9.000e+01, 9.000e+01
      Y Bounds:   0.000e+00, 2.160e+02
      Z Bounds:   0.000e+00, 1.800e+02
      N Arrays:   1]



.. GENERATED FROM PYTHON SOURCE LINES 47-50

And here is a screen capture of a user interacting with this

.. image:: ../../images/gifs/plane-slice.gif

.. GENERATED FROM PYTHON SOURCE LINES 52-56

Or you could leverage the plane widget for some custom task like glyphing a
vector field along that plane. Note that we have to pass a ``name`` when
calling ``add_mesh`` to ensure that there is only one set of glyphs plotted
at a time.

.. GENERATED FROM PYTHON SOURCE LINES 56-77

.. code-block:: Python


    import pyvista as pv
    from pyvista import examples

    mesh = examples.download_carotid()

    pl = pv.Plotter()
    pl.add_mesh(mesh.contour(8).extract_largest(), opacity=0.5)


    def my_plane_func(normal, origin) -> None:
        slc = mesh.slice(normal=normal, origin=origin)
        arrows = slc.glyph(orient="vectors", scale="scalars", factor=0.01)
        pl.add_mesh(arrows, name="arrows")


    pl.add_plane_widget(my_plane_func)
    pl.show_grid()
    pl.add_axes()
    pl.show()








.. tab-set::



   .. tab-item:: Static Scene



            
     .. image-sg:: /tutorial/08_widgets/images/sphx_glr_e_plane-widget_003.png
        :alt: e plane widget
        :srcset: /tutorial/08_widgets/images/sphx_glr_e_plane-widget_003.png
        :class: sphx-glr-single-img
     


   .. tab-item:: Interactive Scene



       .. offlineviewer:: /home/runner/work/pyvista-tutorial/pyvista-tutorial/doc/source/tutorial/08_widgets/images/sphx_glr_e_plane-widget_003.vtksz






.. GENERATED FROM PYTHON SOURCE LINES 78-81

And here is a screen capture of a user interacting with this

.. image:: ../../images/gifs/plane-glyph.gif

.. GENERATED FROM PYTHON SOURCE LINES 84-88

Further, a user can disable the arrow vector by setting the
``normal_rotation`` argument to ``False``. For example, here we
programmatically set the normal vector on which we want to translate the
plane and we disable the arrow to prevent its rotation.

.. GENERATED FROM PYTHON SOURCE LINES 88-93

.. code-block:: Python


    pl = pv.Plotter()
    pl.add_mesh_slice(vol, normal=(1, 1, 1), normal_rotation=False)
    pl.show()








.. tab-set::



   .. tab-item:: Static Scene



            
     .. image-sg:: /tutorial/08_widgets/images/sphx_glr_e_plane-widget_004.png
        :alt: e plane widget
        :srcset: /tutorial/08_widgets/images/sphx_glr_e_plane-widget_004.png
        :class: sphx-glr-single-img
     


   .. tab-item:: Interactive Scene



       .. offlineviewer:: /home/runner/work/pyvista-tutorial/pyvista-tutorial/doc/source/tutorial/08_widgets/images/sphx_glr_e_plane-widget_004.vtksz






.. GENERATED FROM PYTHON SOURCE LINES 94-96

The vector is also forcibly disabled anytime the ``assign_to_axis`` argument
is set.

.. GENERATED FROM PYTHON SOURCE LINES 96-101

.. code-block:: Python

    pl = pv.Plotter()
    pl.add_mesh_slice(vol, assign_to_axis="z")
    pl.show()









.. tab-set::



   .. tab-item:: Static Scene



            
     .. image-sg:: /tutorial/08_widgets/images/sphx_glr_e_plane-widget_005.png
        :alt: e plane widget
        :srcset: /tutorial/08_widgets/images/sphx_glr_e_plane-widget_005.png
        :class: sphx-glr-single-img
     


   .. tab-item:: Interactive Scene



       .. offlineviewer:: /home/runner/work/pyvista-tutorial/pyvista-tutorial/doc/source/tutorial/08_widgets/images/sphx_glr_e_plane-widget_005.vtksz






.. GENERATED FROM PYTHON SOURCE LINES 102-106

Additionally, users can modify the interaction event that triggers the
callback functions handled by the different plane widget helpers through the
``interaction_event`` keyword argument when available. For example,
we can have continuous slicing by using the ``InteractionEvent`` observer.

.. GENERATED FROM PYTHON SOURCE LINES 106-112

.. code-block:: Python

    import vtk

    pl = pv.Plotter()
    pl.add_mesh_slice(vol, assign_to_axis="z", interaction_event=vtk.vtkCommand.InteractionEvent)
    pl.show()








.. tab-set::



   .. tab-item:: Static Scene



            
     .. image-sg:: /tutorial/08_widgets/images/sphx_glr_e_plane-widget_006.png
        :alt: e plane widget
        :srcset: /tutorial/08_widgets/images/sphx_glr_e_plane-widget_006.png
        :class: sphx-glr-single-img
     


   .. tab-item:: Interactive Scene



       .. offlineviewer:: /home/runner/work/pyvista-tutorial/pyvista-tutorial/doc/source/tutorial/08_widgets/images/sphx_glr_e_plane-widget_006.vtksz






.. GENERATED FROM PYTHON SOURCE LINES 113-117

And here is a screen capture of a user interacting with this continuously via
the ``InteractionEvent`` observer:

.. image:: ../../images/gifs/plane-slice-continuous.gif

.. GENERATED FROM PYTHON SOURCE LINES 119-126

.. raw:: html

    <center>
      <a target="_blank" href="https://colab.research.google.com/github/pyvista/pyvista-tutorial/blob/gh-pages/notebooks/tutorial/08_widgets/e_plane-widget.ipynb">
        <img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/ width="150px">
      </a>
    </center>


.. rst-class:: sphx-glr-timing

   **Total running time of the script:** (0 minutes 12.874 seconds)


.. _sphx_glr_download_tutorial_08_widgets_e_plane-widget.py:

.. only:: html

  .. container:: sphx-glr-footer sphx-glr-footer-example

    .. container:: binder-badge

      .. image:: images/binder_badge_logo.svg
        :target: https://mybinder.org/v2/gh/pyvista/pyvista-tutorial/gh-pages?urlpath=lab/tree/notebooks/tutorial/08_widgets/e_plane-widget.ipynb
        :alt: Launch binder
        :width: 150 px

    .. container:: sphx-glr-download sphx-glr-download-jupyter

      :download:`Download Jupyter notebook: e_plane-widget.ipynb <e_plane-widget.ipynb>`

    .. container:: sphx-glr-download sphx-glr-download-python

      :download:`Download Python source code: e_plane-widget.py <e_plane-widget.py>`

    .. container:: sphx-glr-download sphx-glr-download-zip

      :download:`Download zipped: e_plane-widget.zip <e_plane-widget.zip>`


.. only:: html

 .. rst-class:: sphx-glr-signature

    `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_
