-
Notifications
You must be signed in to change notification settings - Fork 7
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
feat: Add ROI selection tool #23
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #23 +/- ##
==========================================
- Coverage 83.24% 77.77% -5.47%
==========================================
Files 13 13
Lines 1259 1813 +554
==========================================
+ Hits 1048 1410 +362
- Misses 211 403 +192 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Super clear ❤️. I like where this is going
b71c998
to
d0eaa45
Compare
writing future wishes as I have them here. don't need to be in this PR:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i like where this is going. The behavior is lovely.
I want to spend a little more time thinking about the implementation. It does "get the thing done", but it's mixing together some concerns that i would prefer to keep separate (in an ideal world).
As we discussed, I think much of it would be made cleaner (and easier on your end) if ndv
provided you more existing infrastructure to communicate mouse clicks and canvas coordinates to the backends. So, if it's ok with you, i'd like to pause and think about that bit, specifically with this PR in mind.
9efbd76
to
9ea9254
Compare
|
||
|
||
# TODO Need a better name :) | ||
class PHandleHandle(CanvasElement, Protocol): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😂
203babd
to
508dbe6
Compare
508dbe6
to
08b3663
Compare
08b3663
to
4a18520
Compare
wow, this is really shaping up nicely! just pulled and played with it. really feels nice, and I think I like the new Still digging through it now, but could you add docstrings to also: amazing that you have the pygfx backend working too. I did see a slight inconsistency with the handle box. In pygfx, the "threshold" for how far your mouse can be from the cursor seems to be in data coordinates rather than canavs coords (or something like that) ... if you zoom in, it gets too easy to select the handle: Untitled.mov |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, I'm very excited about how the _viewer.py
looks here!
I know i still need to dig into the backend implementations, but how are you feeling about all this? As far as you're concerned is it just waiting for review? I want to have this in :)
@@ -290,6 +318,31 @@ def set_data( | |||
# update the data info label | |||
self._data_info_label.setText(self._data_wrapper.summary_info()) | |||
|
|||
def set_roi( | |||
self, | |||
vertices: list[tuple[float, float]] | None = None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would be fun to think of ways to overload this method, so you could also pass something like any indexing expression (even something like np.s_[1:20, 30:60]
) and get an roi.
also.. I expected the to see something about the number of vertices allowed, either in the type hint or the docs. I eventually found later in the vispy code:
if len(vertices) != 4 or any(len(v) != 2 for v in vertices):
raise Exception("Only 2D rectangles are currently supported")
should that be enforced here for now? or is there an alternate path that does currently support other than 4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would be fun to think of ways to overload this method, so you could also pass something like any indexing expression (even something like
np.s_[1:20, 30:60]
) and get an roi.
Sure! I can't say I have the experience to know what would be nice here, though...
also.. I expected the to see something about the number of vertices allowed, either in the type hint or the docs. I eventually found later in the vispy code:
if len(vertices) != 4 or any(len(v) != 2 for v in vertices): raise Exception("Only 2D rectangles are currently supported")should that be enforced here for now? or is there an alternate path that does currently support other than 4
I personally prefer the check within the backend(s), because I wouldn't be surprised if some backends could support more ROI shapes than others later on. We could make the error message more specific, though...
Since we're talking about this method, do you think that the specification is general enough? For example, if we later want elliptical ROIs, how could we use viewer.set_roi
to accomplish that? Similarly, how might we differentiate between polygons and polylines?
🥳
Added!
Yup, as I mentioned privately there's a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
going in! Thank you so much for all the work on this @gselzer ... really great stuff.
This PR adds tooling for drawing (rectangular) ROIs onto the
NDViewer
. There are still many things left to do (list follows below), but I'm writing this PR to foster discussion and revision.ROIPrototype.mp4
TODO/Wishlist
Backend
Features
Bugs
canvas.visuals_at
, but I haven't investigated. I'm not sure how it handles order, either)