
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "tutorial/08_widgets/a_box-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_a_box-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_a_box-widget.py:


.. _box_widget_example:

Box Widget
~~~~~~~~~~

The box widget can be enabled and disabled by the
:func:`pyvista.Plotter.add_box_widget` and
:func:`pyvista.Plotter.clear_box_widgets` methods respectively.
When enabling the box widget, you must provide a custom callback function
otherwise the box would appear and do nothing - the callback functions are
what allow us to leverage the widget to perform a task like clipping/cropping.

Considering that using a box to clip/crop a mesh is one of the most common use
cases, we have included a helper method that will allow you to add a mesh to a
scene with a box widget that controls its extent, the
:func:`pyvista.Plotter.add_mesh_clip_box` method.

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

.. GENERATED FROM PYTHON SOURCE LINES 21-27

.. code-block:: Python


    import pyvista as pv
    from pyvista import examples

    mesh = examples.download_nefertiti()








.. GENERATED FROM PYTHON SOURCE LINES 28-34

.. code-block:: Python


    pl = pv.Plotter()
    pl.add_mesh_clip_box(mesh, color="white")
    pl.show(cpos=[-1, -1, 0.2])









.. tab-set::



   .. tab-item:: Static Scene



            
     .. image-sg:: /tutorial/08_widgets/images/sphx_glr_a_box-widget_001.png
        :alt: a box widget
        :srcset: /tutorial/08_widgets/images/sphx_glr_a_box-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_a_box-widget_001.vtksz






.. GENERATED FROM PYTHON SOURCE LINES 35-36

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

.. GENERATED FROM PYTHON SOURCE LINES 36-38

.. code-block:: Python

    pl.box_clipped_meshes





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

 .. code-block:: none


    [UnstructuredGrid (0x7f4fac536d40)
      N Cells:    2018232
      N Points:   1009118
      X Bounds:   -1.194e+02, 1.194e+02
      Y Bounds:   -1.813e+02, 1.813e+02
      Z Bounds:   -2.473e+02, 2.473e+02
      N Arrays:   1]



.. GENERATED FROM PYTHON SOURCE LINES 39-46

.. raw:: html

    <center>
      <a target="_blank" href="https://colab.research.google.com/github/pyvista/pyvista-tutorial/blob/gh-pages/notebooks/tutorial/08_widgets/a_box-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 15.104 seconds)


.. _sphx_glr_download_tutorial_08_widgets_a_box-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/a_box-widget.ipynb
        :alt: Launch binder
        :width: 150 px

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

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

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

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

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

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


.. only:: html

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

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