← 返回首页
Implement PolygonSelector by almarklein · Pull Request #837 · 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

Implement PolygonSelector#837

Merged
kushalkolar merged 20 commits into
mainfrom
poly-select
Sep 3, 2025
Merged

Implement PolygonSelector#837
kushalkolar merged 20 commits into
mainfrom
poly-select

Conversation

almarklein commented May 26, 2025
edited
Loading

Copy link
Copy Markdown
Collaborator
  • Get it to draw a polygon.
  • Triangulation.
  • Selection.
  • Decide on interaction model.

Copy link
Copy Markdown

Next up, add morphing 😎

Copy link
Copy Markdown
Collaborator Author

add morphing

That's worthy of a separate lib :)

Copy link
Copy Markdown

You already have gfxmorph 🤣

Copy link
Copy Markdown
Collaborator Author

This is nearly done, but the ux needs some thought and work. I'm thinking something like this:

  • User clicks points to create the polygon. Optionally start with existing polygon.
  • Once created, vertices can be dragged.
  • Clicking on an edge will split it in two, creating an extra vertex.
  • Double-clicking on inside the polygon will delete and let the user create a new polygon.

kushalkolar commented Jun 29, 2025
edited
Loading

Copy link
Copy Markdown
Member

This is nearly done, but the ux needs some thought and work. I'm thinking something like this:

  • User clicks points to create the polygon. Optionally start with existing polygon.
  • Once created, vertices can be dragged.
  • Clicking on an edge will split it in two, creating an extra vertex.

All this sounds good to me!

  • Double-clicking on inside the polygon will delete and let the user create a new polygon.

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.

almarklein commented Jul 4, 2025
edited
Loading

Copy link
Copy Markdown
Collaborator Author

Interaction done! Slightly different than I said earlier:

  • Can initialize the tool with an initial selection.
  • If the initial selection is empty, enter polygon creation mode.
  • Can also call start_new_polygon() to clear the current polygon and draw a new one.
  • When creating a new polygon, clicking adds a vertex. Clicking on the first vertex again will finish the polygon.
  • When created, the vertices can be dragged. When dragged on top of a neighbouring polygon, it will be deleted.
  • When clicking/dragging on a line, a new vertex is inserted.

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.

almarklein marked this pull request as ready for review July 4, 2025 12:41

Copy link
Copy Markdown
Collaborator Author

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.

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/line.py Outdated Show resolved Hide resolved
Comment thread fastplotlib/graphics/selectors/_polygon.py Show resolved Hide resolved
Comment thread fastplotlib/graphics/selectors/_polygon.py Outdated Show resolved Hide resolved
1 hidden conversation Load more…
Comment thread fastplotlib/graphics/selectors/_polygon.py Show resolved Hide resolved
Comment thread fastplotlib/graphics/selectors/_polygon.py Show resolved Hide resolved
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

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

I do this often! Is 0.01 the best way to do it? I usually do 0.5

Copy link
Copy Markdown
Collaborator 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

It depends on the other z-values in your scene, and on the camera depth range settings. From what I understand FPL has layers that are 1.0 apart. I'll change the value above to 0.1; still close to it's original "layer".

Comment thread fastplotlib/graphics/selectors/_polygon.py Show resolved Hide resolved
Comment thread fastplotlib/graphics/selectors/_polygon.py Show resolved Hide resolved

Copy link
Copy Markdown
Member

Sorry for the delay in reviewing this, awesome work thanks a lot! 🥳 🥳 . Some minor comments and questions.

Copy link
Copy Markdown
Collaborator Author

I addressed all comments.

Copy link
Copy Markdown
Collaborator Author

Need to tweak alpha_mode for the worldObjects used in the selectors, but I propose we first merge this (if you're happy), and then in #873 I make those adjustments.

Copy link
Copy Markdown
Member

Thanks! I was traveling this weekend so it slipped through.

Hide details View details kushalkolar merged commit 0293fa3 into main Sep 3, 2025
1 of 52 checks passed

Copy link
Copy Markdown
Collaborator Author

Thanks! I was traveling this weekend so it slipped through.

No problem. My comment was mainly to suggest a sensible order of merging the prs.

almarklein deleted the poly-select branch September 3, 2025 08:03
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.