Debian Codegraph @

examples/03-widgets/box_widget.py

raw
1 """
2 .. _box_widget_example:
3
4 Box Widget
5 ~~~~~~~~~~
6
7 The box widget can be enabled and disabled by the
8 :func:`pyvista.Plotter.add_box_widget` and
9 :func:`pyvista.Plotter.clear_box_widgets` methods respectively.
10 When enabling the box widget, you must provide a custom callback function
11 otherwise the box would appear and do nothing - the callback functions are
12 what allow us to leverage the widget to perform a task like clipping/cropping.
13
14 Considering that using a box to clip/crop a mesh is one of the most common use
15 cases, we have included a helper method that will allow you to add a mesh to a
16 scene with a box widget that controls its extent, the
17 :func:`pyvista.Plotter.add_mesh_clip_box` method.
18
19 """
20
21 # sphinx_gallery_start_ignore
22 # widgets do not work in interactive examples
23 PYVISTA_GALLERY_FORCE_STATIC_IN_DOCUMENT = True
24 # sphinx_gallery_end_ignore
25
26
27 import pyvista as pv
28 from pyvista import examples
29
30 mesh = examples.download_washington_bust()
31
32 # %%
33
34 pl = pv.Plotter()
35 pl.add_mesh_clip_box(mesh, color='white')
36 pl.show()
37
38
39 # %%
40 # After interacting with the scene, the clipped mesh is available as:
41 pl.widgets.box_clipped_meshes
42 # %%
43 # .. tags:: widgets