.. 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 ` 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 p = pv.Plotter() p.add_mesh_clip_box(mesh, color='white') p.show(cpos=[-1, -1, 0.2]) .. 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 .. 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 p.box_clipped_meshes .. rst-class:: sphx-glr-script-out .. code-block:: none [UnstructuredGrid (0x7f16f4cd6740) 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
Open In Colab
.. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 13.813 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 ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: a_box-widget.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_