8000 Fix bounding_box extent for case of 3D multiscale layer by psobolewskiPhD · Pull Request #7545 · napari/napari · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix bounding_box extent for case of 3D multiscale layer #7545

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

Merged
merged 7 commits into from
Mar 12, 2025

Conversation

psobolewskiPhD
Copy link
Member

References and relevant issues

Closes: #7543

Description

3D multiscale layers use the lowest resolution when displayed in 3D.
The bounding_box overlay uses the data_level of the layer prior to ndisplay change finishing, so if you're looking at a higher rez 2D slice, then the 3D bounding box will mismatch the displayed data.
In this PR I add a test that fails when the actual vertexes of the bounding box don't match those that would be expected of the lowest resolution level.
Then, for the overlay I add a check to see if the layer is 3D and multiscale, and if so use the lowest resolution bounding box (augmented).

@github-actions github-actions bot added the tests Something related to our tests label Jan 21, 2025
@psobolewskiPhD psobolewskiPhD added bug Something isn't working as expected and removed tests Something related to our tests labels Jan 21, 2025
Copy link
codecov bot commented Jan 21, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 92.84%. Comparing base (09f0e89) to head (14e66ce).
Report is 5 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7545      +/-   ##
==========================================
- Coverage   92.88%   92.84%   -0.04%     
==========================================
  Files         632      633       +1     
  Lines       59258    59278      +20     
==========================================
- Hits        55042    55039       -3     
- Misses       4216     4239      +23     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jni jni added this to the 0.6.0 milestone Jan 21, 2025
# and we need the augmented bounding box
bounds = self.layer._display_bounding_box_at_level(
self.layer._slice_input.displayed, len(self.layer.data) - 1 < 10000 /td>
) + np.array([[-0.5, 0.5]])
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you add a comment about the -0.5, 0.5 part?

Copy link
Collaborator

Choose a reason for hiding this comment

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

This is cased by putting (0,0) in the middle of the upper-left corner. So the upper-left corner is in (-0.5, -0.5).

Copy link
Member Author

Choose a reason for hiding this comment

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

That's the "augmented" part, to match the existing code.

Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason why you're not using simply layer._display_bounding_box_augmented? IIRC it should do exactly what you want, since there's also layer._display_bounding_box_augmented_data_level`?

Copy link
Member Author

Choose a reason for hiding this comment

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

_display_bounding_box_augmented_data_level should work and then we wouldnt need this PR -- it's what the code uses -- but it ends up using the data_level from the 2D view when the overlay is updated. I did some testing in the issue, at some point after display = 3 _display_bounding_box_augmented_data_level is updated and correct, but not when the overlay is updated.

_display_bounding_box_augmented doesn't allow you to specify the data_level.

So the easiest thing was to use the method that does allow one to specify the level and then augment it manually.

Copy link
Member Author
@psobolewskiPhD psobolewskiPhD Jan 22, 2025

Choose a reason for hiding this comment

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

That's what I do here? len(self.layer.data) - 1 is the lowest level.
Unless I'm missing something.

Or do you meant to add a callback to dims.ndisplay in ViewerModel to update the overlay?

Copy link
Member

Choose a reason for hiding this comment

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

We shouldn't need data level, I think @brisvag is saying that layer._display_bounding_box_augmented is in world coordinates so should work regardless? We know the layer extents in world coordinates which would make data levels moot.

Copy link
Member Author

Choose a reason for hiding this comment

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

using layer._display_bounding_box_augmented returns the data_level 0 bounding box regardless of 2d/3d, zoom, etc. so that option is always wrong 😞

Copy link
Contributor

Choose a reason for hiding this comment

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

But that should be correct in 3d, no? Or at least, it should... I'm testing stuff manually a bit and none of this behaves like I expect 😢

Copy link
Member Author

Choose a reason for hiding this comment

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

No, in 3D multiscale uses the lowest pyramid level -- 0 is the highest.
Currently, the overlay uses the level currently displayed, which actually does work some of the time -- like when you are zoomed out so that the lowest level is displayed.

@github-actions github-actions bot added the tests Something related to our tests label Feb 6, 2025
@Czaki Czaki added bugfix PR with bugfix ready to merge Last chance for comments! Will be merged in ~24h and removed bug Something isn't working as expected labels Feb 17, 2025
@Czaki Czaki merged commit 9338c58 into napari:main Mar 12, 2025
35 checks passed
@github-actions github-actions bot removed the ready to merge Last chance for comments! Will be merged in ~24h label Mar 12, 2025
Czaki pushed a commit that referenced this pull request Mar 14, 2025
# Description

This PR skips a flaky test on Windows. The test #7545 was introduced
recently and is intermittently failing on Windows.

This should unblock #7686 and #7632

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix PR with bugfix tests Something related to our tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Layer.bounding_box does not properly handle 3D, multiscale
4 participants
0