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

Masking boundaries #1569

Merged
merged 25 commits into from
Sep 20, 2023
Merged

Masking boundaries #1569

merged 25 commits into from
Sep 20, 2023

Conversation

bnmajor
Copy link
Collaborator

@bnmajor bnmajor commented Sep 6, 2023

NEEDS:

  • Re-test LLNL workflow to make sure InteractiveTemplate changes have not broken anything
  • Re-test mask regions by rectangle/ellipse
    • Toggle tabbed mode while masking
    • Toggle view mode while masking
    • Saving/loading state files with masks

KNOWN ISSUES:

  • In the raw, untabbed view mode rotation does not work (the template disappears) on any detector that is not the first. Rotation by arrow key works, translate works, and everything works in tabbed mode.
  • Rotation in the polar view skews the template
  • Create template(s) -> interact w/ another dialog (i.e. mask manager) -> try to draw another mask -> nothing happens (works again if the shape is toggled and then mask is drawn)
  • Draw template(s) in raw -> switch to tabbed view -> draw template but do not save it -> switch to polar view -> cannot immediately draw on canvas

Decouples the InteractiveTemplate class from the LLNL import tool so that it
can be used more broadly across the application. The class can now accept a
list of vertices in raw coordinates and create a polygon, rectangle, or
ellipse. If the static_mode attribute is set to False the user can translate or
rotate the shape.

Signed-off-by: Brianna Major <brianna.major@kitware.com>
Once a user draws the bounding rectangle or ellipse for the region they'd like
to mask they are able to translate and rotate the shape just like they can in
the LLNL import tool. Right-click will complete the current patch and allow
starting a new one.

Signed-off-by: Brianna Major <brianna.major@kitware.com>
If the canvas is changed (by tab, tab mode or image mode) complete the current
masks.

Signed-off-by: Brianna Major <brianna.major@kitware.com>
Signed-off-by: Brianna Major <brianna.major@kitware.com>
Signed-off-by: Brianna Major <brianna.major@kitware.com>
@bnmajor
Copy link
Collaborator Author

bnmajor commented Sep 6, 2023

@psavery @saransh13 While I wrap this branch up I'd welcome any thoughts or opinions on the best way to interact with the rectangle/ellipse masking. Right now the user:

  1. Selects the shape
  2. Draws the bounds
  3. Translates/rotates the bounds
  4. Right-clicks to complete the current mask and enable drawing the next

Do we need an additional or different option for indicating that the current mask is complete? Something that indicates that the template is in "interactive" (can be moved) mode still? I was thinking about the current mask being drawn in red and completed masks being drawn in black or something along those lines.

mask_region_dialog

Copy link
Collaborator

@psavery psavery left a comment

Choose a reason for hiding this comment

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

Looking really nice so far! I have mostly minor suggestions for the code. I'll give it a try soon too.

hexrd/ui/hexrd_config.py Outdated Show resolved Hide resolved
hexrd/ui/interactive_template.py Outdated Show resolved Hide resolved
hexrd/ui/interactive_template.py Outdated Show resolved Hide resolved
hexrd/ui/interactive_template.py Outdated Show resolved Hide resolved
hexrd/ui/interactive_template.py Outdated Show resolved Hide resolved
hexrd/ui/interactive_template.py Outdated Show resolved Hide resolved
hexrd/ui/interactive_template.py Outdated Show resolved Hide resolved
hexrd/ui/interactive_template.py Show resolved Hide resolved
hexrd/ui/mask_regions_dialog.py Outdated Show resolved Hide resolved
hexrd/ui/mask_regions_dialog.py Outdated Show resolved Hide resolved
Instead, update the current canvas on image mode or tab mode change with
signals. This behavior now matches the HandDrawnMaskDialog.

Signed-off-by: Brianna Major <brianna.major@kitware.com>
Signed-off-by: Brianna Major <brianna.major@kitware.com>
Signed-off-by: Brianna Major <brianna.major@kitware.com>
Renamed: patch(es) -> interactive_template(s), raw_axes -> axis,
kwargs -> polygon_kwargs

Signed-off-by: Brianna Major <brianna.major@kitware.com>
Signed-off-by: Brianna Major <brianna.major@kitware.com>
Signed-off-by: Brianna Major <brianna.major@kitware.com>
Signed-off-by: Brianna Major <brianna.major@kitware.com>
@psavery
Copy link
Collaborator

psavery commented Sep 6, 2023

@bnmajor Did you try rotating the masks in the polar view? The behavior appears a little odd.

Ellipses in the raw view don't look as smooth as they used to. Do you know why?

If I draw a mask and then right-click to save it, then click "Undo Last Selection", I get an exception.

Also, can we make sure all of the signals get disconnected when the mask manager is hidden? It looks to me that if I use the mask manager several times in one session, the program slows down.

Also, we should get feedback from @saransh13, but it might be more intuitive to change the clicking behavior to be like this:

  1. If the user left-clicks inside any template, then translate that template
  2. If the user left-clicks outside of any template, then save the previous template and start a new template
  3. Right-click won't do anything

However, I wonder if it will be difficult to allow the user to translate templates that were already saved (like allow them to translate any template they have already created). If that would be difficult, maybe we can skip that part.

Overall, it is looking very nice, though!

Signed-off-by: Brianna Major <brianna.major@kitware.com>
@bnmajor
Copy link
Collaborator Author

bnmajor commented Sep 8, 2023

@bnmajor Did you try rotating the masks in the polar view? The behavior appears a little odd.

I did not test rotate in the polar view but there is indeed some strange behavior... Rotation causes some strange skewing. I will get that sorted out.

Ellipses in the raw view don't look as smooth as they used to. Do you know why?

We're now drawing the ellipses with the more generic patches.Polygon in the interactive template. We still use the Eliipses polygon for the initial drawing so that we can easily draw the shape and then grab the coordinates from it. The InteractiveTemplate uses Polygon for everything to stay as general as possible.

Also, can we make sure all of the signals get disconnected when the mask manager is hidden? It looks to me that if I use the mask manager several times in one session, the program slows down.

I've added a commit with a lot more precautionary disconnect calls that will hopefully help with this problem!

@bnmajor
Copy link
Collaborator Author

bnmajor commented Sep 8, 2023

If I draw a mask and then right-click to save it, then click "Undo Last Selection", I get an exception.

Also, we should get feedback from @saransh13, but it might be more intuitive to change the clicking behavior to be like this:

  1. If the user left-clicks inside any template, then translate that template
  2. If the user left-clicks outside of any template, then save the previous template and start a new template
  3. Right-click won't do anything

However, I wonder if it will be difficult to allow the user to translate templates that were already saved (like allow them to translate any template they have already created). If that would be difficult, maybe we can skip that part.

I think that this is all much smoother now! I've made a few updates and the behavior is now as follows:

  1. User draws a shape in a region
  2. Any existing template can be manipulated by selecting it
      1. Click on a template and it will turn red if selected
    1. Translate and rotate as before
  3. Click away from the selected template or simply begin drawing to create a new template shape
  4. All templates can be undone now, not just interactive templates

Signed-off-by: Brianna Major <brianna.major@kitware.com>
Signed-off-by: Brianna Major <brianna.major@kitware.com>
Signed-off-by: Brianna Major <brianna.major@kitware.com>
Signed-off-by: Brianna Major <brianna.major@kitware.com>
Signed-off-by: Brianna Major <brianna.major@kitware.com>
@pep8speaks
Copy link

pep8speaks commented Sep 20, 2023

Hello @bnmajor! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2023-09-20 20:23:49 UTC

This makes the ellipses in the polar view appear much smoother.

Signed-off-by: Patrick Avery <patrick.avery@kitware.com>
psavery and others added 3 commits September 20, 2023 12:30
This aspect ratio takes into account both the extent and the canvas
aspect ratio.

Signed-off-by: Patrick Avery <patrick.avery@kitware.com>
We only need to confirm that we are in the correct detector in the raw image
mode.

Signed-off-by: Brianna Major <brianna.major@kitware.com>
I accidentally inverted this...

Signed-off-by: Patrick Avery <patrick.avery@kitware.com>
Copy link
Collaborator

@psavery psavery 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 working well for me, thanks @bnmajor!

The one thing we might want to do in a future PR: if users are interacting with these masks on a high-resolution polar canvas, we probably want to animate the interactions so that they are much faster. But we will work on that only if someone requests it.

@saransh13, can you try this out and let us know if you have any suggested changes?

@saransh13
Copy link
Member

saransh13 commented Sep 20, 2023 via email

@bnmajor bnmajor marked this pull request as ready for review September 20, 2023 18:20
@bnmajor
Copy link
Collaborator Author

bnmajor commented Sep 20, 2023

After speaking with @saransh13 this branch needs the following:

  • Larger step size for rotate by arrow key. This should only apply to masking, not the LLNL import tool
  • Bug fix: in polar view draw mask A -> move mask A -> draw mask B -> move mask B -> mask A moves as well

@saransh13
Copy link
Member

saransh13 commented Sep 20, 2023 via email

Signed-off-by: Brianna Major <brianna.major@kitware.com>
@bnmajor
Copy link
Collaborator Author

bnmajor commented Sep 20, 2023

  • Larger step size for rotate by arrow key. This should only apply to masking, not the LLNL import tool
  • Bug fix: in polar view draw mask A -> move mask A -> draw mask B -> move mask B -> mask A moves as well

These are both fixed, although the angle of rotation was bumped an arbitrary amount. This value can be set to anything here. @saransh13 @psavery

Copy link
Collaborator

@psavery psavery left a comment

Choose a reason for hiding this comment

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

Feel free to merge when ready. We will animate the interactive template in a separate PR, and fix any more issues we encounter in future PRs.

Signed-off-by: Brianna Major <brianna.major@kitware.com>
Signed-off-by: Brianna Major <brianna.major@kitware.com>
@bnmajor bnmajor merged commit ba1880b into HEXRD:master Sep 20, 2023
9 checks passed
@bnmajor bnmajor deleted the masking-boundaries branch September 20, 2023 21:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants