Skip to content

add rectangular region selector #576

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 24 commits into from
Aug 24, 2024
Merged

add rectangular region selector #576

merged 24 commits into from
Aug 24, 2024

Conversation

clewis7
Copy link
Member

@clewis7 clewis7 commented Aug 2, 2024

#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
Copy link
Member Author

clewis7 commented Aug 2, 2024

rectangle-.2.mp4

@clewis7
Copy link
Member Author

clewis7 commented Aug 5, 2024

rectangle_selection.mp4

@kushalkolar
Copy link
Member

kushalkolar commented Aug 5, 2024

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)

)

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

Choose a reason for hiding this comment

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

why -0.25 🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

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
Member

Choose a reason for hiding this comment

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

how does this scale with rectangle size and camera zoom?

Copy link
Member Author

Choose a reason for hiding this comment

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

what do you mean?

Copy link
Member

Choose a reason for hiding this comment

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

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 clewis7 marked this pull request as ready for review August 8, 2024 14:55
Copy link
Member

@kushalkolar kushalkolar left a comment

Choose a reason for hiding this comment

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

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
Member

Choose a reason for hiding this comment

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

how does this scale with rectangle size and camera zoom?

@kushalkolar
Copy link
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

)

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

Choose a reason for hiding this comment

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

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.

@hmaarrfk
Copy link

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 kushalkolar merged commit c12b2c8 into main Aug 24, 2024
10 checks passed
@kushalkolar kushalkolar deleted the rectangle_selector branch August 28, 2024 19:05
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
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy