Ignore points in the 3d window when using enable_point_picking #1894
-
Hi, the docs for
I know that I can set each mesh/point cloud to be pickable or not (using the |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
At the moment this is not implemented and I don't think it is easily supported by VTK. AFIAK, the What we could do is implement an option in diff --git a/pyvista/plotting/picking.py b/pyvista/plotting/picking.py
index 54d90991..e09fcea1 100644
--- a/pyvista/plotting/picking.py
+++ b/pyvista/plotting/picking.py
@@ -230,7 +230,7 @@ class PickingHelper:
def enable_point_picking(self, callback=None, show_message=True,
font_size=18, color='pink', point_size=10,
use_mesh=False, show_point=True, tolerance=0.025,
- **kwargs):
+ limit_to_actors=False, **kwargs):
"""Enable picking at points.
Enable picking a point at the mouse location in the render
@@ -276,6 +276,10 @@ class PickingHelper:
is specified as fraction of rendering window
size. Rendering window size is measured across diagonal.
+ limit_to_actors : bool, optional
+ When true, prevent picking points that do not intersect pickable
+ actors in the scene
+
**kwargs : dict, optional
All remaining keyword arguments are used to control how
the picked point is interactively displayed.
@@ -286,6 +290,8 @@ class PickingHelper:
self.picked_point = np.array(picker.GetPickPosition())
self.picked_mesh = picker.GetDataSet()
self.picked_point_id = picker.GetPointId()
+ if not self.picked_point_id >= 0 and limit_to_actors:
+ return
if show_point:
self.add_mesh(self.picked_point, color=color,
point_size=point_size, name='_picked_point', I got this to work reliably when paired with import pyvista as pv
p = pv.Plotter(notebook=0)
actor = p.add_mesh(pv.Sphere())
p.enable_point_picking(limit_to_actors=True)
picker = p.iren.get_picker()
picker.SetPickFromList(True)
picker.AddPickList(actor)
p.show() |
Beta Was this translation helpful? Give feedback.
At the moment this is not implemented and I don't think it is easily supported by VTK. AFIAK, the
vtkPointPicker
we are using doesn't have a way to turn this off easily. However, it'sSetPickFromList
method seems like a good start to better limit what is pickable.. I played with this and did get it to prevent picking in the window.What we could do is implement an option in
enable_point_picking()
to prevent our internal picking callbacks unless an actor was picked. I was this would be easy but its proving actually kind of flaky/difficult to implement. Here is the diff if you want to pick up where I left off:diff --git a/pyvista/plotting/picking.py b/pyvista/plotting/picking.py index 54d9…