Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Picking in background plotter #133

Open
andrea-bistacchi opened this issue Feb 25, 2020 · 5 comments
Open

Picking in background plotter #133

andrea-bistacchi opened this issue Feb 25, 2020 · 5 comments
Labels
picking/selecting Topics around using interactive picking and selecting in renderers

Comments

@andrea-bistacchi
Copy link

Dear Bane, we have another problem with the background plotter. We are using enable_path_picking to pick lines in a plotter where we have some mesh. The meshes are in UTM coordinates, with very large numbers like [540169.0, 5094171.2, 2316.6] and I suspect that this is part of the problem since when we were testing on small objects the problem was less pronounced.

The problem is two-sided:

  1. The enable_path_picking tool returns nodes of the underlying mesh, and if the mesh has a coarse resolution, these points are very far apart. I tried to see if it is possible to use the use_mesh=False option as in the underlying method enable_point_picking, but it does not work.

  2. This is the part of the problem that I think is related to large coordinates: when using meshes in UTM the picking is even more erratic, and this results in completely messed up paths.

Thanks!

line1

line2

@andrea-bistacchi
Copy link
Author

One more question. Is there a method to click on an object and "select" it , or get the name of the actor?

@banesullivan banesullivan added the picking/selecting Topics around using interactive picking and selecting in renderers label Feb 25, 2020
@banesullivan
Copy link
Member

The enable_path_picking tool returns nodes of the underlying mesh, and if the mesh has a coarse resolution, these points are very far apart. I tried to see if it is possible to use the use_mesh=False option as in the underlying method enable_point_picking, but it does not work.

For this first, problem, perhaps try passing pickable=False on the add_mesh calls (the use_mesh option has nothing to do with this but is an option to control what is passed to the user-defined callback method). The pickable argument will make the mesh added not visible by the picker, so you'll be able to pick around in 3D space with the mouse regardless of the meshes in the scene (thereby ignoring their resolution). The picks won't be perfect as the picker struggles with picking the "correct" depth in the image.


This is the part of the problem that I think is related to large coordinates: when using meshes in UTM the picking is even more erratic, and this results in completely messed up paths.

Hm. I'm not sure I follow what the issue is here. Large values for the coordinates (i.e. scale) should not matter or affect the picker. I have a feeling this has to do with the coarse resolution of the meshes you currently have.


One more question. Is there a method to click on an object and "select" it , or get the name of the actor?

Sort of. You can use the point picking to do this and have the callback work some magic on the selected mesh with the use_mesh option. Here is a snippet to play around with. Pick a point on an individual mesh and the callback will be passed a pointer to that original mesh as well as the index of the selected point.

import pyvista as pv

p = pv.Plotter(notebook=0)
# add all your meshes to the scene
N = 5
for i in range(N):
    for j in range(N):
        center = (i, j, 0)
        mesh = pv.Sphere(center=center)
        p.add_mesh(mesh, color=True)
        
# Make a custom callback to handle picked meshes
def callback(mesh, idx):
    print(mesh.memory_address, idx)
    return

# Enable the use_mesh argument!
p.enable_point_picking(callback=callback, use_mesh=True)
p.show()

@andrea-bistacchi
Copy link
Author

Dear Bane, I’ve seen that the original VTK picker returns, in addition to the closer node that is what you are using now, also PCOORDS: parametric coordinates within the face (e.g. triangle) of a PolyData. Using these and the coordinates of the three nodes it is easy to obtain a better point picker. If you can give us some suggestions, we can try to expose also this method.

Thanks!!

@andrea-bistacchi
Copy link
Author

Hello, I attach a notebook and some very simple meshes to reproduce the problems I have with picking. You have to unzip both and run the notebook.

You will see that, in addition to the standard Background Plotter menus, you have a new "Interpretation" menu, with line and plane picking.

If you try them, you will see that:

  • line: it generally picks the closer node, but not always, and in any case this is not good if the mesh resolution is not so high.

  • plane: here picking appears completely random, sometimes it gets "locked"in a position for several planes, and then you rotate the view and it goes somewhere else, but not necessarily under the pointer.

I am really struggling with this!

Thanks very much!

test_picking.zip

test_meshes.zip

@andrea-bistacchi
Copy link
Author

Update: it is possible that the VTK picker that returns PCOORDS and all nodes of a triangle corresponds to enable_cell_picking in PyVista. Would it be possible to extract PCOORDS and absolute node coords from that?

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
picking/selecting Topics around using interactive picking and selecting in renderers
Projects
None yet
Development

No branches or pull requests

2 participants