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

Ignore the window when picking points #1908

Merged
merged 16 commits into from Dec 23, 2021
Merged

Conversation

p-j-smith
Copy link
Contributor

Overview

Fixes #1907
This PR is based on @banesullivan's solution to the discussion of this topic in #1894

Allows points in the 3D window to be ignored after enabling point picking.

Details

  • A window_pickable keyword has been added to pyvista.plotting.picking.PickingHelper.enable_point_picking(). If False, all points in the 3D window will be ignored by the _end_pick_event callback. If True (the default), the points in the window are pickable (the current behaviour).

  • A basic example of point picking and ignoring the 3D window has been added to examples/02-plot/point-picking. I can either flesh out the example if it's desirable, or just remove the file if you prefer

@codecov
Copy link

codecov bot commented Dec 1, 2021

Codecov Report

Merging #1908 (a107395) into main (06b1ac0) will decrease coverage by 0.02%.
The diff coverage is 22.72%.

@@            Coverage Diff             @@
##             main    #1908      +/-   ##
==========================================
- Coverage   30.86%   30.84%   -0.03%     
==========================================
  Files          74       74              
  Lines       15371    15394      +23     
==========================================
+ Hits         4744     4748       +4     
- Misses      10627    10646      +19     

Comment on lines 17 to 20
sphere_actor = p.add_mesh(sphere, pickable=False)

p.enable_point_picking(pickable_window=False)
sphere_actor.SetPickable(True)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a huge fan of this... I'd like to avoid having any examples directly utilize the underlying VTK methods if possible (albeit, one of PyVista's selling points is direct access back to VTK when you want to do something more sophisticated).

Either way, this doesn't feel all that Pythonic/PyVista-ish to me

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah it's not particularly Pythonic. How about creating a method p.set_pickable_actors that takes a list of vtk actors to make pickable? Also, should the fine grained control of pickable actors be addressed by a separate issue/PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @banesullivan , I've added a new property pickable_actors to the BasePlotter. It can be used to set and retrieve the pickable actors of a given plotter. This means the 3d window can be made pickable independently of which actors are pickable, e.g. if a limit_to_actors argument were added to enable_point_picking, then it would not be possible to make the 3d window pickable and all actors unpickable. I've also added tests for the new property. Do you think this is a reasonable approach to take? Also, I wasn't sure where to add things, so let me know if you want me to move stuff around.

pyvista/plotting/picking.py Outdated Show resolved Hide resolved
@tkoyama010 tkoyama010 added the feature-request Please add this cool feature! label Dec 5, 2021
@banesullivan banesullivan self-requested a review December 20, 2021 06:18
@akaszynski
Copy link
Member

I'd like to see full coverage for this new feature. Can we get additional unit tests for this?

@p-j-smith
Copy link
Contributor Author

p-j-smith commented Dec 23, 2021

I'd like to see full coverage for this new feature. Can we get additional unit tests for this?

I think something strange is going on with codecov. It reports that the total coverage of pyvista is 30.86%, but when I run the tests with coverage locally (pytest -vv --cov-report=html --cov-config=.coveragerc --cov pyvista) I get the following:

     	Statements  Missing	Excluded Coverage
Total	15393	    1375	975	 91%

Also, codecov shows that none of enable_point_picking is covered (lines 288-319). However, even before this PR there is a test (tests/tests_pickling.py:test_point_picking) that covers this function.

The reports I've generated locally show that all lines I've modified or added are covered by unit tests - see lines 288-319 of d_ec8005e13284025b_picking_py.html and lines 1274-1308 of d_ec8005e13284025b_plotting_py.html, both of which are in coverage.zip.

Do you have any ideas why codevoc might be under-reporting by so much (91% vs 30.84%)?

Edit

Fix the formatting that I messed up when adding coverage.zip

@p-j-smith
Copy link
Contributor Author

It looks like codecov has been wildly inaccurate for the past few weeks. This is where total coverage dropped by over 65%: https://codecov.io/gh/pyvista/pyvista/commit/b76c8ce08424d16c893248537f042fe1d60c98d6 But it's not obvious why it dropped here

@akaszynski
Copy link
Member

Thanks for looking into this. It's difficult to say if this is a pyvista or upstream issue.

I'm checking out this PR locally and will test and review it.

Copy link
Member

@akaszynski akaszynski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made some final changes to the docstrings as the setter docstring isn't rendered in our autodocumentation. Also added some examples and links.

Overall this is good work. Thanks for your contribution!

@akaszynski akaszynski merged commit dc60a8d into pyvista:main Dec 23, 2021
@p-j-smith
Copy link
Contributor Author

Thank you both for the reviews!

@akaszynski akaszynski mentioned this pull request Jan 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request Please add this cool feature!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ignore points in the 3d window when using enable_point_picking
4 participants