Debian Codegraph @

examples/02-plot/element_picking.py

raw
1 """
2 .. _element_picking_example:
3
4 Picking elements of a mesh
5 ~~~~~~~~~~~~~~~~~~~~~~~~~~
6 This example demonstrates how to pick different elements on meshes using
7 :func:`enable_element_picking() <pyvista.Plotter.enable_element_picking>`.
8
9 The different elements of a mesh are:
10
11 * Mesh: pick the entire mesh (equivalent to
12 :func:`~pyvista.Plotter.enable_mesh_picking`.)
13 * Cell: pick a cell of the mesh (equivalent to
14 :func:`~pyvista.Plotter.enable_cell_picking`.)
15 * Face: pick a single face of a cell on the mesh
16 * Edge: pick a single edge of a cell on the mesh
17 * Point: pick a single point on the mesh
18
19 These types are captured in the :class:`pyvista.plotting.opts.ElementType` enum class.
20
21 """
22
23 # sphinx_gallery_thumbnail_number = 1
24 import pyvista as pv
25 from pyvista.plotting.opts import ElementType
26
27 # %%
28 # Pick Face on Voxel Cell
29 # +++++++++++++++++++++++
30 #
31 mesh = pv.Wavelet()
32
33 pl = pv.Plotter()
34 pl.add_mesh(mesh, show_edges=True, pickable=True)
35 pl.enable_element_picking(mode=ElementType.FACE)
36
37 pl.camera_position = pv.CameraPosition(
38 position=(13.523728057554308, 9.910583926360937, 11.827103195167833),
39 focal_point=(2.229008884793069, -2.782397236304676, 6.84282248642347),
40 viewup=(-0.17641568583704878, -0.21978122178947299, 0.9594653304520027),
41 )
42
43 pl.show(auto_close=False)
44
45 # Programmatically pick a face to make example look nice
46 try:
47 width, height = pl.window_size
48 pl.iren._mouse_right_button_press(419, 263)
49 pl.iren._mouse_right_button_release()
50 except AttributeError:
51 # ignore this section when manually closing the window
52 pass
53
54 # %%
55 # Pick an Edge of a Cell
56 # ++++++++++++++++++++++
57 #
58 sphere = pv.Sphere()
59
60 pl = pv.Plotter()
61 pl.add_mesh(sphere, show_edges=True, pickable=True)
62 pl.enable_element_picking(mode=ElementType.EDGE)
63
64 pl.camera_position = pv.CameraPosition(
65 position=(0.7896646029990011, 0.7520805261169909, 0.5148524767495051),
66 focal_point=(-0.014748048334009667, -0.0257133671899262, 0.07194025085895145),
67 viewup=(-0.26016740957025775, -0.2603941863919363, 0.9297891087180916),
68 )
69
70 pl.show(auto_close=False)
71
72 # Programmatically pick a face to make example look nice
73 try:
74 width, height = pl.window_size
75 pl.iren._mouse_right_button_press(480, 300)
76 pl.iren._mouse_right_button_release()
77 except AttributeError:
78 # ignore this section when manually closing the window
79 pass
80 # %%
81 # .. tags:: plot