Skip to content

add: mask drawing tools (brush/rectangle/line), undo/redo, and edit mode - #135

Open
Osayi-ANL wants to merge 10 commits into
mainfrom
add/mask-drawing
Open

add: mask drawing tools (brush/rectangle/line), undo/redo, and edit mode#135
Osayi-ANL wants to merge 10 commits into
mainfrom
add/mask-drawing

Conversation

@Osayi-ANL

Copy link
Copy Markdown
Collaborator

Adds interactive mask editing to the mask viewer: brush, rectangle, and line
tools with undo/redo, an edit mode toggle, and orientation-aware display so
the mask lines up with the diffraction image regardless of transpose/rotate
state.

  • Brush/Rectangle/Line tools, undo/redo, and edit mode in the mask editor
  • Edit Mask button replaces Show Mask; opens the editor with a blank mask if none is loaded
  • Clamp mask-editor strokes to the image bounds so drawing past an edge fills up to it instead of the shape vanishing
  • Full redraw (not just the overlay) after undo/redo across a transpose or rotate, so the mask doesn't render stretched
  • Prompt to save or discard changes when closing the mask editor

Test Plan

  • Open area detector viewer and click edit mask -- try the functionality

… editor

add: qtawesome icons for undo/redo, a Clear button, and a two-row controls layout

fix: scale mask overlay and initial view range to the detector image size
…k mask if none is loaded

fix: set mask viewer checkboxes before show() so showEvent sees the correct state
… edge fills up to it instead of the shape vanishing
…y instead of just the overlay, so the mask overlay doesn't render stretched against the base image
@Osayi-ANL
Osayi-ANL requested a review from pecomyint August 7, 2026 22:28

@pecomyint pecomyint left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nice feature — the paint helpers are clean and detector-agnostic, the commits are well-split, and ruff passes. The separate red ImageItem overlay is the right call for cheap live drawing.

Blockers

  1. Close prompt's "Save" doesn't save (mask_viewer.py:219-232). QMessageBox.Save is the default button and falls through to event.accept()_save_mask() is never called. Harmless today only because _on_mask_edited saves on every emit.
  2. Save button then close still prompts "unsaved changes"_save_mask (:460-476) never refreshes self._original_mask. One line.
  3. _display_to_native is now in the mouse-move path (:330-350). The probe-array + np.argwhere reverse-map costs 9 ms/call on a 2048² mask, and _event_native now calls it on every move during a drag — ~12 ms/move for the brush, ~28 ms for a long line preview, scaling to 50-110 ms on a 4096² detector (visible lag, skipped pixels). transpose+rot90 is a closed-form index permutation, so this can be pure arithmetic instead of building and scanning an array. Hoisting the three _get_display_mask() copies and the per-move np.sum picks up the rest.

Worth fixing here

  1. "Size" means different things per tool — at 3, brush paints 5 px but rectangle and line paint 3 px. _paint_disk reads the value as a radius (diameter 2R-1); _paint_line already compensates with (thickness + 1) / 2, the brush should too.
  2. Opening the editor writes to diskedit_mask_clicked (area_det_viewer.py:718-731) creates an all-False mask and immediately saves it, so just opening the window flips mask_manager.mask off None and the user needs "Clear Mask" to undo it. Can the create+save wait for the first real edit?

Minor: _get_parent_display_settings's colormap return is now dead (:410); the Redo tooltip says Ctrl+Y but QKeySequence.Redo is Cmd+Shift+Z on macOS; MASK_UNDO_MAX = 20 bounds snapshot count, not bytes (~360 MB on an Eiger 16M) despite the comment. The paint helpers fit the fake-self pattern in tests/unit/test_roi_visibility.py — cheap tests there would lock in 3 and 4.

Fixes save-on-close, stale mask, slow coordinate inverse, inconsistent tool sizing, blank mask on open.
Defer view fit until dialog has real geometry instead of fitting too early.
Stops the live-plot timer during edits so large detectors don't starve the editor's repaint.
Resamples the mask overlay to match the image's resolution and warns when they differ.
@Osayi-ANL
Osayi-ANL requested a review from pecomyint August 20, 2026 16:04
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.

2 participants