1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
"""
.. _surface_point_picking_example:
Picking a Point on the Surface of a Mesh
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This example demonstrates how to pick meshes using
:func:`enable_surface_point_picking() <pyvista.Plotter.enable_surface_point_picking>`.
This allows you to pick points on the surface of a mesh.
"""
from __future__ import annotations
import pyvista as pv
# sphinx_gallery_start_ignore
# picking does not work on interactive examples
PYVISTA_GALLERY_FORCE_STATIC_IN_DOCUMENT = True
# sphinx_gallery_end_ignore
# %%
# Create a mesh and enable picking using the default settings.
cube = pv.Cube()
pl = pv.Plotter()
pl.add_mesh(cube, show_edges=True)
pl.enable_surface_point_picking()
pl.show()
# %%
# Enable a callback that creates a cube at the right-clicked point and add a
# label at the point as well it.
def callback(point):
"""Create a cube and a label at the click point."""
mesh = pv.Cube(center=point, x_length=0.05, y_length=0.05, z_length=0.05)
pl.add_mesh(mesh, style='wireframe', color='r')
pl.add_point_labels(point, [f"{point[0]:.2f}, {point[1]:.2f}, {point[2]:.2f}"])
pl = pv.Plotter()
pl.add_mesh(cube, show_edges=True)
pl.enable_surface_point_picking(callback=callback, show_point=False)
pl.show()
|