← 返回首页
add rectangular region selector by clewis7 · Pull Request #576 · fastplotlib/fastplotlib · GitHub
Skip to content

Navigation Menu

Toggle navigation
Sign in
Appearance settings
Search or jump to...

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Include my email address so I can be contacted

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Resetting focus

add rectangular region selector#576

Merged
kushalkolar merged 24 commits into
mainfrom
rectangle_selector
Aug 24, 2024
Merged

add rectangular region selector#576
kushalkolar merged 24 commits into
mainfrom
rectangle_selector

Conversation

clewis7 commented Aug 2, 2024
edited
Loading

Copy link
Copy Markdown
Member

#142 Rectangle selector

  • rectangle selector implementation
  • add selector methods for graphics (e.g. LineGraphic, ImageGraphic, etc.)
  • get_selected_indices() and get_selected_data() methods
    • add a mode argument, one of "partial", "full", "ignore" that handles when selector is not covering part of graphic
  • add vertices on the corners

clewis7 commented Aug 2, 2024

Copy link
Copy Markdown
Member Author
rectangle-.2.mp4

Comment thread fastplotlib/graphics/selectors/_rectangle_region.py Outdated Show resolved Hide resolved

clewis7 commented Aug 5, 2024

Copy link
Copy Markdown
Member Author
rectangle_selection.mp4

Comment thread fastplotlib/graphics/image.py Outdated Show resolved Hide resolved

kushalkolar commented Aug 5, 2024
edited
Loading

Copy link
Copy Markdown
Member

I wonder if a method that returns a mask and then using the mask for get_selected_data() could be useful, since it is about 20% faster:

In [20]: %%timeit ...: a[(a > 50_000) & (a < 100_000)] ...: ...: 620 μs ± 7.79 μs per loop (mean ± std. dev. of 7 runs, 1,000 loops each) In [21]: %%timeit ...: a[np.where((a > 50_000) & (a < 100_000))] ...: ...: 747 μs ± 31.6 μs per loop (mean ± std. dev. of 7 runs, 1,000 loops each)

Comment thread fastplotlib/graphics/selectors/_rectangle.py Outdated Show resolved Hide resolved
)

for vertex in self.vertices:
vertex.world.z = -0.25

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality Hide comment

why -0.25 🤔

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality Hide comment

the edges get set to -0.5, so if the vertices are -0.25 then they will be on top of the edges

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality Hide comment

how does this scale with rectangle size and camera zoom?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality Hide comment

what do you mean?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality Hide comment

Sometimes world objects will have weird overlapping when the z-planes are close with very high or very low zoom, I just tried it and it seems fine within reasonable levels.

clewis7 marked this pull request as ready for review August 8, 2024 14:55

kushalkolar left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality Hide comment

Wondering if you tried the selector with different offsets for the parent graphic, does it return the correct selection, and correct arrays for get_selected_indices() and get_selected_data().

)

for vertex in self.vertices:
vertex.world.z = -0.25

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality Hide comment

how does this scale with rectangle size and camera zoom?

Comment thread fastplotlib/graphics/_features/_selection_features.py Outdated Show resolved Hide resolved
Comment thread fastplotlib/graphics/_features/_selection_features.py Outdated Show resolved Hide resolved
Comment thread fastplotlib/graphics/image.py Outdated Show resolved Hide resolved
Comment thread fastplotlib/graphics/image.py Outdated Show resolved Hide resolved
2 hidden conversations Load more…
Comment thread fastplotlib/graphics/selectors/_rectangle.py Outdated Show resolved Hide resolved
Comment thread fastplotlib/graphics/selectors/_rectangle.py Outdated Show resolved Hide resolved
Comment thread fastplotlib/graphics/selectors/_rectangle.py Outdated Show resolved Hide resolved
Comment thread fastplotlib/graphics/selectors/_rectangle.py Outdated Show resolved Hide resolved
Comment thread fastplotlib/graphics/selectors/_rectangle.py Outdated Show resolved Hide resolved

Copy link
Copy Markdown
Member

For collection a helper method that gets indices or returns graphics under the selection could be useful. Not hard to implement currently, we can think about and add more helper functions later 😄

line_collection = figure[0, 0].add_line_collection(circles, cmap="jet", thickness=5) rs = line_collection.add_rectangle_selector() @rs.add_event_handler("selection") def bah(ev): line_collection.cmap = "jet" ixs = ev.get_selected_indices() # iterate through each of the selected indices, if the array size > 0 that mean it's under the selection selected_line_ixs = [i for i in range(len(ixs)) if ixs[i].size > 0] line_collection[selected_line_ixs].colors = "w"
rectangle_selector-2024-08-08_23.43.52.mp4

Comment thread examples/desktop/selectors/rectangle_selector.py Show resolved Hide resolved
)

for vertex in self.vertices:
vertex.world.z = -0.25

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality Hide comment

Sometimes world objects will have weird overlapping when the z-planes are close with very high or very low zoom, I just tried it and it seems fine within reasonable levels.

Comment thread fastplotlib/graphics/selectors/_rectangle.py Outdated Show resolved Hide resolved
Comment thread fastplotlib/graphics/image.py Show resolved Hide resolved
Comment thread fastplotlib/graphics/image.py Show resolved Hide resolved

Copy link
Copy Markdown

Chiming in here because Kushal showed this to me IRL yesterday. Pretty cool!!!!

I had two comments:

  1. We once had pretty bad performance from pygfx_object.world.matrix so we ended up caching it ourselves.... maybe i should open an issue to pygfx on that. It made iterating through the list of "selectable objects" we had kinda slow.
  2. Bonus points for thinking about how to do this in 3D. We didn't get to that part either....
  3. Bonus points for doing this all on the GPU in WGSL and just make "highlighting" a property of your shaders ;)

Keep it going. I love to see these demos!

kushalkolar merged commit c12b2c8 into main Aug 24, 2024
kushalkolar deleted the rectangle_selector branch August 28, 2024 19:05
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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.

3 participants

Footer

© 2026 GitHub, Inc.