import subprocess
import sys
if "google.colab" in sys.modules:
subprocess.run("apt-get update", shell=True, check=True)
subprocess.run("apt-get install -qq xvfb libgl1-mesa-glx", shell=True, check=True)
subprocess.run("pip install pyvista[all] -qq", shell=True, check=True)
import pyvista as pv
# Seems that only static plotting is supported by colab at the moment
pv.global_theme.jupyter_backend = "static"
pv.global_theme.notebook = True
pv.start_xvfb()
else:
%matplotlib inline
from pyvista import set_plot_theme
set_plot_theme("document")
The box widget can be enabled and disabled by the
pyvista.Plotter.add_box_widget
{.interpreted-text role="func"} and
pyvista.Plotter.clear_box_widgets
{.interpreted-text role="func"}
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
pyvista.Plotter.add_mesh_clip_box
{.interpreted-text role="func"}
method.
import pyvista as pv
from pyvista import examples
mesh = examples.download_nefertiti()
p = pv.Plotter()
p.add_mesh_clip_box(mesh, color='white')
p.show(cpos=[-1, -1, 0.2])
After interacting with the scene, the clipped mesh is available as:
p.box_clipped_meshes
{=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>