Skip to content

Conversation

@mattdawkins
Copy link
Member

Summary

  • Add support for multiple segmentation polygons per detection/track
  • Add support for holes within polygons
  • Enable selection and editing of individual polygons within a detection

Features

  • Multiple polygons per detection: Each detection can now have multiple independent polygon segmentations, internally keyed ('', '1', '2', etc.)
  • Hole support: Polygons can contain holes (cutouts) which are rendered with a darker shade
  • Polygon selection: Right-click or left-click on any polygon to select and edit it
  • Independent deletion: Delete individual polygons or holes without affecting others
  • Bounding box: Auto-generated bounding box encompasses all polygons in the detection

VIAME CSV Format

Updated format for multi-polygon and hole support:

  • Polygons: (poly) x y x y...
  • Holes: (hole) x y x y...
  • Multiple (poly) entries per row supported
  • Holes are associated with the preceding polygon

Technical Changes

  • PolygonLayer.ts: Render holes with darker color, always emit polygon selection events
  • EditAnnotationLayer.ts: Support polygon key selection
  • LayerManager.vue: Handle polygon selection events, prevent selection during hole drawing
  • polygonbase.ts: Calculate bounds from all polygons, support hole/polygon creation modes
  • track.ts: Add methods for managing multiple polygons and holes
  • viame.py / viame.ts: Updated serialization for new format

Test plan

  • Create a detection with multiple polygons using "Add Polygon" button
  • Create holes in polygons using "Add Hole" button
  • Verify right-click selects the correct polygon for editing
  • Verify left-click switches between polygons when already editing
  • Verify bounding box encompasses all polygons
  • Export to CSV and verify format: (poly) and (hole) entries
  • Import CSV with multiple polygons and holes

🤖 Generated with Claude Code

mattdawkins and others added 12 commits January 24, 2026 22:46
- Add CSV format extension for multiple polygons and holes per detection
  - Format: (poly[:key][:hole[:index]]) coordinates
  - Backward compatible with existing (poly) format
- Add UI buttons for "Add Hole" and "Add Polygon" in polygon edit mode
- Fix polygon key matching to properly handle empty string keys
- Add selectedKeyRef to LayerManager watcher for proper layer updates
- Add track methods: getPolygonFeatures, addHoleToPolygon, removeHoleFromPolygon
- Add auto-hole detection using ray casting algorithm
- Support clicking on individual polygons to select for editing

Still needs testing for:
- Polygon merge for overlapping polygons
- Boolean difference for holes partially outside polygons

Co-Authored-By: Claude Opus 4.5 <[email protected]>
- Always emit polygon-clicked/polygon-right-clicked events regardless of
  drawingOther flag, enabling polygon selection when rectangles are visible
- Add polygon-right-clicked handler in LayerManager to properly set the
  selected key and update layers
- Preserve selected key when deselecting handles to prevent key reset
- Calculate bounding box from ALL polygons in detection, not just edited one

Co-Authored-By: Claude Opus 4.5 <[email protected]>
- Fix hole drawing by skipping polygon selection in creation mode
- Render holes with darker color (50% darkened fill/stroke, 50% opacity)
- Update VIAME CSV format:
  - Polygons: (poly) x y x y...
  - Holes: (hole) x y x y...
  - No labels/keys in output
  - Multiple (poly) entries auto-keyed internally when parsing
  - Holes associated with most recent polygon when parsing

Co-Authored-By: Claude Opus 4.5 <[email protected]>
- Change (poly:1) to (poly) for multiple polygons
- Change (poly:hole:0) to (hole) for holes
- Update expected key from "2" to "" since keys are now auto-generated

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Update test expectations to match the actual implementation which uses
the simple (poly) and (hole) format as documented in the PR description,
rather than the complex format with keys like (poly:1) and (poly:hole:0).

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Change coordinate parsing to use lists instead of tuples from zip()
to ensure consistent JSON serialization with the Pydantic model
expectations.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Print full actual vs expected JSON when test fails to identify
the exact difference.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Reorder Union[bool, float, str] to Union[str, float, bool] in
GeoJSONFeature.properties to prevent Pydantic from coercing
numeric-looking strings like "1" to boolean True.

Also remove debug output from test file.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Swap order of add polygon/add hole buttons so add polygon comes first.
Recalculate bounding box from remaining polygons when deleting one.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Changes:
- Return polygon data with hole included instead of modifying track
  directly, making the update flow consistent with add polygon mode
- Use === undefined checks to distinguish "no key change" from "change
  to empty key" for proper mode transitions
- Allow right-click to cancel creation and select polygons/holes
- Add polygon-right-clicked-outside event for finalizing when clicking
  outside polygons
- Add cancelCreation handler and update Handler interface

This makes hole mode and polygon mode behave identically for:
- Right-click finalization
- Selection (click or right-click on polygons/holes)
- Editing and deletion

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Left-clicks in creation mode should be handled by the edit layer for
placing polygon/hole vertices. Only right-click should cancel creation
mode and allow polygon selection.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
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.

1 participant