-
Notifications
You must be signed in to change notification settings - Fork 55
Implement PolygonSelector #837
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
base: main
Are you sure you want to change the base?
Conversation
Next up, add morphing 😎 |
That's worthy of a separate lib :) |
You already have gfxmorph 🤣 |
This is nearly done, but the ux needs some thought and work. I'm thinking something like this:
|
All this sounds good to me!
I think this should be explicitly called, or via imgui right click menu. Or clicking on the fill area selects the polygon and presing the "Del" key deletes it. |
Interaction done! Slightly different than I said earlier:
edit: in the above, a snapping visualization is applied to help the user understand that the vertex will be "merged" with the vertex under the mouse. |
I just learned about bermuda, a triangulation lib implemented in Rust, a spin-off of the Napari project. We could try and see if it helps here. It would mean an extra dependency, so maybe not use it unless we need it. But we can at least do some quick benchmarks and add a note, so that in case we do need more speed, we know how to get it. |
# TODO: Update the fill mesh | ||
# selector.fill.geometry.positions = ... |
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.
seems like the fill mesh is updated here below?
Parameters | ||
---------- | ||
selection: List of positions, optional | ||
initial points for the polygon |
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.
add to docstring: If None
, start clicking to create the selection
selection: (float, float, float, float), optional | ||
initial (xmin, xmax, ymin, ymax) of the selection |
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.
can update by copying pasting the changes from the image docstring
|
||
mode: str | ||
index: int | ||
snap_index: int |
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.
comment for what this is
@property | ||
def selection(self) -> np.ndarray[float]: | ||
""" | ||
The polygon as an array of 3D points. |
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.
add to docstring: shape is [n_points, 2]
(I'm assuming)
positions=np.zeros((8, 3), np.float32), | ||
indices=np.zeros((8, 3), np.int32), |
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.
can you comment why this initialization shape
self.geometry.positions.draw_range = 0, 0 | ||
self.geometry.indices.draw_range = 0, 0 |
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.
what do the draw range do?
self.geometry, | ||
pygfx.PointsMaterial(size=vertex_size, color=vertex_color, pick_write=True), | ||
) | ||
self._points.local.z = 0.01 # move it slightly towards the camera |
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 do this often! Is 0.01
the best way to do it? I usually do 0.5
elif self._move_info.mode is None: | ||
# Maybe initiate a drag | ||
if ev.target is self._points: | ||
index = ev.pick_info["vertex_index"] | ||
self._start_move_mode("drag", index) | ||
elif ev.target is self._line: | ||
index = ev.pick_info["vertex_index"] | ||
if ev.pick_info["segment_coord"] > 0: | ||
index += 1 | ||
self._insert_polygon_vertex(index, world_pos) | ||
self._start_move_mode("drag", index) |
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.
if the target is the fill area, move the entire polygon?
|
||
for handler, event in handlers.items(): | ||
self._plot_area.renderer.remove_event_handler(handler, event) | ||
# Are we close to a point that we can snap to? |
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.
what exactly is the snapping 🤔
Sorry for the delay in reviewing this, awesome work thanks a lot! 🥳 🥳 . Some minor comments and questions. |
Uh oh!
There was an error while loading. Please reload this page.