Plane Widget

The plane widget can be enabled and disabled by the pyvista.WidgetHelper.add_plane_widget() and pyvista.WidgetHelper.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:

# sphinx_gallery_thumbnail_number = 2
import pyvista as pv
from pyvista import examples

vol = examples.download_brain()

p = pv.Plotter()
p.add_mesh_clip_plane(vol)
p.show()
plane widget

Out:

[(578.7093647107201, 596.7093628033715, 578.7093628033715),
 (90.00000190734863, 108.0, 90.0),
 (0.0, 0.0, 1.0)]

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

p.plane_clipped_meshes

Out:

[UnstructuredGrid (0x7f623a669ec0)
  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: 1
]

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

../../_images/plane-clip.gif

Or you could slice a mesh using the plane widget:

p = pv.Plotter()
p.add_mesh_slice(vol)
p.show()
plane widget

Out:

[(578.7093647107201, 596.7093628033715, 578.7093628033715),
 (90.00000190734863, 108.0, 90.0),
 (0.0, 0.0, 1.0)]

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

p.plane_sliced_meshes

Out:

[PolyData (0x7f623a757440)
  N Cells:  38880
  N Points: 39277
  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
]

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

../../_images/plane-slice.gif

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.

import pyvista as pv
from pyvista import examples

mesh = examples.download_carotid()

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

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

p.add_plane_widget(my_plane_func)
p.show_grid()
p.add_axes()
p.show()
plane widget

Out:

[(275.9751053451392, 242.47510534513918, 161.47510534513918),
 (137.5, 104.0, 23.0),
 (0.0, 0.0, 1.0)]

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

../../_images/plane-glyph.gif

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

Gallery generated by Sphinx-Gallery