napari / napari

napari: a fast, interactive, multi-dimensional image viewer for python
https://napari.org
BSD 3-Clause "New" or "Revised" License
2.07k stars 410 forks source link

Shift camera when drawing #6885

Open melonora opened 2 weeks ago

melonora commented 2 weeks ago

🚀 Feature

When drawing rois for large regions using the Shapes layer, if you are zoomed in and the region extends beyond the canvas shift the camera when the cursor gets close to the canvas edge.

Motivation

Pathologist can annotate large regions in whole slide imaging and still want to be annotating the regions accurately (meaning the regions do not have regularly shaped boundaries, for example anatomical regions). This would mean that they are zooming in and part of the image data would extend beyond the canvas. It can be that a region to be annotated in this case also extends beyond the canvas. Currently panning / zooming while drawing is not supported, making it not possible to draw rois this way.

Pitch

I would have 3 proposals to make the shift of the camera happen while drawing rois.

  1. Similar to selecting text in word while simultaneously scrolling, if the cursor gets close to an edge of the canvas the camera would be shifted in that direction. The speed of the shift is determined by how close the cursor is to the edge, with the shift happening only when the cursor is a certain amount of pixels away from the center.
  2. Arrow keys can be pressed to shift the camera while drawing. The cursor would stay at the current position in data space and drawing is not cancelled. After release of the arrow key the user can resume drawing of the shape.
  3. Currently space finishes drawing a region in shapes. We could instead have the behaviour that this would not cancel the drawing and just as in shapes it would allow us to pan instead with the cursor staying locked at the same position in data space.

Personally, I think approach 2, 3 (3 has preference) might be easier to implement, but I would welcome any input before investigating this.

Note: this work is possibly a motivator for a refactor to reuse the tooling across different layers (shapes and labels).

melonora commented 2 weeks ago

@isabela-pf Maybe if you have some ideas about UX:)

psobolewskiPhD commented 2 weeks ago

Note that you can zoom while drawing, but not pan. This is tricky with the drag based tools, rather than click to place vertex. In the later option 3 would be perfect. Place a vertex, spacebar to pan/zoom, place vertex, continue. But the line, ellipse, rectangle, and lasso are click-n-drag so hard to envision how they would work -- could switch them to click to start click to finish.

Edit: I just checked and the napari behavior is largely similar to QuPath. Can't draw out side of field-of-view and spacebar -- which also toggles pan -- kills drawing shapes, but zoom works. Oh and brush lets you brush out of field of view/out of viewer just like napari elipse/rectangle 🤣 The brush tool is easy to restart after a pan though, so it's less of an issue.