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

Add add_ruler to BasePlotter #2531

Merged
merged 8 commits into from
May 5, 2022
Merged

Add add_ruler to BasePlotter #2531

merged 8 commits into from
May 5, 2022

Conversation

MatthewFlamm
Copy link
Contributor

@MatthewFlamm MatthewFlamm commented Apr 29, 2022

Overview

This PR adds add_ruler functionality to the plotter using vtkAxisActor2D.

This is useful for adding customizable scale or measurements to the scene.

image

Edit: Updated image using flip_range.

TODO:

  • tests

@MatthewFlamm MatthewFlamm changed the title Add add_ruler to Plotter Add add_ruler to BasePlotter Apr 29, 2022
@github-actions github-actions bot added the enhancement Changes that enhance the library label Apr 29, 2022
ruler.SetMinorTickLength(minor_tick_length)
ruler.SetTickOffset(tick_label_offset)

self.add_actor(ruler, reset_camera=True, pickable=False)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I used reset_camera=True here, but it doesn't seem to do anything. If the users picks pointa and pointb to be outside the normal viewing area, it won't resize based on the choice here. Probably because of the 2D overlay nature of this actor.

If this can't be fixed, we can just put in a note in the docstring about this.

Copy link
Member

Choose a reason for hiding this comment

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

One way you could work around this is adding fictitious points and then removing them to get the camera to increase the bounds. If this is out of the scope of the PR or you feel it's too complex, you can just add a note in the docstring.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried this without success, so I added in a note.

tmp_points = pyvista.PolyData([pointa, pointb])
tmp_actor = self.add_mesh(tmp_points, reset_camera=True)
self.remove_actor(tmp_actor, reset_camera=False)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If I get rid of self.remove_actor then the camera does reset as expected, but then it leaves behind the fictituous points. It seems that reset_camera=False isn't working quite correctly in this case?

@codecov
Copy link

codecov bot commented Apr 29, 2022

Codecov Report

Merging #2531 (1850aca) into main (b6ab604) will decrease coverage by 0.00%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main    #2531      +/-   ##
==========================================
- Coverage   93.72%   93.71%   -0.01%     
==========================================
  Files          75       75              
  Lines       16116    16145      +29     
==========================================
+ Hits        15105    15131      +26     
- Misses       1011     1014       +3     

@MatthewFlamm MatthewFlamm marked this pull request as draft April 29, 2022 18:50
@MatthewFlamm
Copy link
Contributor Author

I had to use the functionality in vtkLegendScaleActor to wrap my head around how to correctly set the start and stop positions for this actor. This may be helpful if anyone wants to review that portion of the implementation.

I considered exposing the AdjustLabels and RulerMode options, but I found the behavior to be hard to understand. But this may be based on my lack of understanding on how they work.

@MatthewFlamm MatthewFlamm marked this pull request as ready for review April 29, 2022 20:15
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.

This is good as-is; you can choose to supplement the methods with docstrings for the limitations of the vtkAxisActor2D.

@MatthewFlamm MatthewFlamm merged commit 8158872 into main May 5, 2022
@MatthewFlamm MatthewFlamm deleted the feat/add-ruler branch May 5, 2022 18:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Changes that enhance the library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants