copper3d 3.11.3 → 3.11.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/README.md +50 -3
  2. package/ai-index/guides/nrrd-tools.md +127 -5
  3. package/ai-index/guides/segmentation-module.md +146 -3
  4. package/ai-index/manifest.json +5 -5
  5. package/ai-index/symbols.json +1 -1
  6. package/dist/Utils/segmentation/CanvasState.js +0 -1
  7. package/dist/Utils/segmentation/CanvasState.js.map +1 -1
  8. package/dist/Utils/segmentation/DragOperator.d.ts +6 -0
  9. package/dist/Utils/segmentation/DragOperator.js +9 -0
  10. package/dist/Utils/segmentation/DragOperator.js.map +1 -1
  11. package/dist/Utils/segmentation/DrawToolCore.js +0 -14
  12. package/dist/Utils/segmentation/DrawToolCore.js.map +1 -1
  13. package/dist/Utils/segmentation/NrrdTools.d.ts +38 -1
  14. package/dist/Utils/segmentation/NrrdTools.js +105 -2
  15. package/dist/Utils/segmentation/NrrdTools.js.map +1 -1
  16. package/dist/Utils/segmentation/RenderingUtils.d.ts +5 -9
  17. package/dist/Utils/segmentation/RenderingUtils.js +10 -116
  18. package/dist/Utils/segmentation/RenderingUtils.js.map +1 -1
  19. package/dist/Utils/segmentation/contourPaint.d.ts +37 -0
  20. package/dist/Utils/segmentation/contourPaint.js +128 -0
  21. package/dist/Utils/segmentation/contourPaint.js.map +1 -0
  22. package/dist/Utils/segmentation/core/types.d.ts +0 -1
  23. package/dist/Utils/segmentation/eventRouter/EventRouter.js +0 -1
  24. package/dist/Utils/segmentation/eventRouter/EventRouter.js.map +1 -1
  25. package/dist/Utils/segmentation/eventRouter/types.d.ts +0 -1
  26. package/dist/Utils/segmentation/tools/DragSliceTool.js +5 -0
  27. package/dist/Utils/segmentation/tools/DragSliceTool.js.map +1 -1
  28. package/dist/Utils/segmentation/tools/MaskMirror.d.ts +42 -0
  29. package/dist/Utils/segmentation/tools/MaskMirror.js +165 -0
  30. package/dist/Utils/segmentation/tools/MaskMirror.js.map +1 -0
  31. package/dist/Utils/segmentation/tools/SliceRenderPipeline.js +5 -0
  32. package/dist/Utils/segmentation/tools/SliceRenderPipeline.js.map +1 -1
  33. package/dist/Utils/segmentation/tools/ToolHost.d.ts +10 -2
  34. package/dist/Utils/segmentation/tools/ZoomTool.js +32 -2
  35. package/dist/Utils/segmentation/tools/ZoomTool.js.map +1 -1
  36. package/dist/bundle.esm.js +450 -130
  37. package/dist/bundle.umd.js +450 -130
  38. package/dist/types/Utils/segmentation/DragOperator.d.ts +6 -0
  39. package/dist/types/Utils/segmentation/NrrdTools.d.ts +38 -1
  40. package/dist/types/Utils/segmentation/RenderingUtils.d.ts +5 -9
  41. package/dist/types/Utils/segmentation/contourPaint.d.ts +37 -0
  42. package/dist/types/Utils/segmentation/core/types.d.ts +0 -1
  43. package/dist/types/Utils/segmentation/eventRouter/types.d.ts +0 -1
  44. package/dist/types/Utils/segmentation/tools/MaskMirror.d.ts +42 -0
  45. package/dist/types/Utils/segmentation/tools/ToolHost.d.ts +10 -2
  46. package/package.json +1 -1
package/README.md CHANGED
@@ -352,6 +352,24 @@ write — the package ships without a UI and does not reach into yours. Point it
352
352
  nrrdTools.notifyUser = (message, level) => toast[level](message); // 'error' | 'warning' | 'info'
353
353
  ```
354
354
 
355
+ **Previewing one slice before the volume loads**
356
+
357
+ ```typescript
358
+ // Put one plane on screen immediately, positioned as slice `index` of the full stack
359
+ nrrdTools.showPreviewSlice(header, slice, index, async (target) => {
360
+ const next = await fetchSinglePlane(caseId, target); // `target` is already clamped
361
+ nrrdTools.showPreviewSlice(header, next, target, onSliceMove);
362
+ });
363
+
364
+ // Later, when the real volume arrives — keeps the previewed index
365
+ nrrdTools.switchSlicesPreservingView(allSlices);
366
+ ```
367
+
368
+ While previewing, wheel/keys/drag do **not** move the display — the shown slice has depth 1,
369
+ so the target index is handed to your callback to fetch instead. `header` is the full volume's
370
+ geometry, not the plane's. Axial only. `isPreviewing()` reports the state; it ends on
371
+ `switchSlicesPreservingView`, `setAllSlices` or `reset`.
372
+
355
373
  **Contrast series**
356
374
 
357
375
  A case is a series of contrasts. `addSkip` / `removeSkip` index the **full** contrast list;
@@ -509,6 +527,28 @@ leave outline mode to annotate.
509
527
 
510
528
  ---
511
529
 
530
+ ### Mask mirroring — show one viewer's masks on another
531
+
532
+ ```typescript
533
+ // `reference` draws `primary`'s masks over its own image
534
+ reference.setMaskMirror(primary);
535
+
536
+ // with a row-major 4×4 mapping reference's voxel (x, y, z, 1) → primary's voxel
537
+ reference.setMaskMirror(primary, mirrorToSource);
538
+
539
+ reference.setMaskMirror(null); // detach
540
+ ```
541
+
542
+ Everything is read live from the source — volumes, channel colours, layer and channel
543
+ visibility, per-layer opacity, fill/outline mode — so changing any of them on the source
544
+ updates the mirror on the next frame. It is display only: nothing is written to either
545
+ viewer's masks, and the mirror holds no mask data of its own.
546
+
547
+ A mirroring viewer needs no layers, so `{ layers: [] }` pairs naturally with this. `dispose()`
548
+ breaks the link from both ends.
549
+
550
+ ---
551
+
512
552
  ### Zoom range — showing below 1:1
513
553
 
514
554
  The zoom factor used to bottom out at `1`. Lower the floor and a large volume can be fitted
@@ -606,9 +646,13 @@ window.addEventListener('keydown', (e) => {
606
646
  | Redo | `y` |
607
647
  | Contrast adjust | `Ctrl` / `Meta` (hold) |
608
648
  | Crosshair | `s` |
609
- | Sphere mode | `q` |
610
649
  | Mouse wheel | Zoom |
611
650
 
651
+ > **Breaking:** sphere mode no longer has a shortcut. `sphere: "q"` is gone and `sphere` has
652
+ > been removed from `IKeyBoardSettings` — it toggled the mode behind the host's back, clearing
653
+ > the masks from the view while the host's UI still showed its own tool as selected. Enter it
654
+ > with `setMode('sphere')` and bind your own key if you want one.
655
+
612
656
  ```typescript
613
657
  nrrdTools.setKeyboardSettings({ undo: 'u', mouseWheel: 'Scroll:Slice' });
614
658
  const settings = nrrdTools.getKeyboardSettings();
@@ -663,8 +707,10 @@ yourself. It throws on an unknown layer, or a channel outside `[1, 255]`.
663
707
  | | `commitSeriesLoad(slices, entries, i)` | Case-load completion — one refresh |
664
708
  | | `switchAllSlicesArrayData(slices)` | Swap the series (resets view state) |
665
709
  | | `switchSlicesPreservingView(slices)` | Swap the series, keep slice index / zoom / pan |
710
+ | **Preview** | `showPreviewSlice(header, slice, i, cb)` | Show one depth-1 slice as slice `i` of the not-yet-loaded stack; slice moves go to `cb` instead of moving the display. Axial only |
711
+ | | `isPreviewing()` | Whether a preview slice is shown |
666
712
  | **Render** | `start` | Frame callback — pass to render loop |
667
- | **Lifecycle** | `dispose()` | Release the event router's listeners, a pending slice step and the drawing-flag timer. Instance unusable afterwards; safe to call twice |
713
+ | **Lifecycle** | `dispose()` | Release the event router's listeners, a pending slice step, the drawing-flag timer and any mask-mirror link (from both ends). Instance unusable afterwards; safe to call twice |
668
714
  | **Layer** | `setActiveLayer(id)` | Switch drawing target layer |
669
715
  | | `getActiveLayer()` | Read current layer |
670
716
  | | `setLayerVisible(id, bool)` | Toggle layer in composite view |
@@ -677,6 +723,8 @@ yourself. It throws on an unknown layer, or a channel outside `[1, 255]`.
677
723
  | | `setLayerOpacity(id, opacity)` | Set per-layer opacity (0.1–1.0), triggers re-render |
678
724
  | | `getLayerOpacity(id)` | Read one layer's opacity |
679
725
  | | `getLayerOpacityMap()` | All per-layer opacity values |
726
+ | **Mirror** | `setMaskMirror(src, m?)` | Draw another viewer's masks, read live. `m` = row-major 4×4 voxel→voxel; `null` detaches. Display only |
727
+ | | `getMaskMirrorSource()` | The viewer being mirrored, or `null` |
680
728
  | **Sphere** | `setActiveSphereType(type)` | Set active sphere type, updates brush color |
681
729
  | | `getActiveSphereType()` | Read current sphere type |
682
730
  | | `setCalculateDistanceSphere(x, y, slice, type)` | Programmatically place a calculator sphere |
@@ -769,7 +817,6 @@ interface IKeyBoardSettings {
769
817
  redo: string;
770
818
  contrast: string[];
771
819
  crosshair: string;
772
- sphere: string;
773
820
  mouseWheel: 'Scroll:Zoom' | 'Scroll:Slice';
774
821
  }
775
822
 
@@ -344,6 +344,51 @@ nrrdTools.switchAllSlicesArrayData(allSlices);
344
344
  nrrdTools.switchSlicesPreservingView(allSlices);
345
345
  ```
346
346
 
347
+ #### 3.4 Previewing one slice before the volume loads <Badge type="tip" text="3.11.6" />
348
+
349
+ A large volume takes seconds to arrive. `showPreviewSlice` puts **one** slice on screen
350
+ immediately, positioned as slice `index` of the full stack, and lets the reader scrub while
351
+ the rest is still downloading:
352
+
353
+ ```typescript
354
+ nrrdTools.showPreviewSlice(header, slice, index, async (target) => {
355
+ // `target` is the clamped slice the reader asked for — fetch and show it
356
+ const next = await fetchSinglePlane(caseId, target);
357
+ nrrdTools.showPreviewSlice(header, next, target, onSliceMove);
358
+ });
359
+
360
+ nrrdTools.isPreviewing(); // → true until a full volume takes over
361
+ ```
362
+
363
+ | Parameter | What it is |
364
+ |-----------|------------|
365
+ | `header` | The **full** volume's geometry (`NrrdHeaderLike`: dimensions, spacing, space_origin) — not the single plane's |
366
+ | `slice` | A depth-1 slice triple built from one plane's voxels |
367
+ | `index` | Which slice of the full stack this plane is |
368
+ | `onSliceMove` | Receives the clamped target index for every slice move while previewing |
369
+
370
+ **While previewing, slice moves do not move the display.** Wheel, keys, drag and
371
+ `setSliceMoving` are all intercepted and handed to `onSliceMove` with the clamped target
372
+ instead — the displayed slice has depth 1, so moving it would paint blank. Fetching that
373
+ plane and calling `showPreviewSlice` again is what advances the view.
374
+
375
+ Geometry is re-initialised only when `header` differs from the current one, so calling it
376
+ repeatedly while scrubbing is cheap. It writes no mask data.
377
+
378
+ **Handing over to the real volume:**
379
+
380
+ ```typescript
381
+ const allSlices = await loadFullVolume(caseId);
382
+ nrrdTools.switchSlicesPreservingView(allSlices); // keeps the previewed index, ends previewing
383
+ ```
384
+
385
+ Previewing also ends on `setAllSlices()` and `reset()`.
386
+
387
+ ::: warning Axial only
388
+ `showPreviewSlice` does not switch orientation — it shows a `z` plane. Sagittal and coronal
389
+ need the full volume.
390
+ :::
391
+
347
392
  ---
348
393
 
349
394
  ### 4. Render Loop Integration
@@ -387,6 +432,7 @@ is torn down can actually be garbage-collected:
387
432
  | The event router's listeners | Its window `blur` listener closes over the router, which reaches the whole engine graph — one live listener pins the entire instance |
388
433
  | A pending slice step | The `requestAnimationFrame` `setSliceMoving` coalesces into |
389
434
  | The drawing-flag timer | The pending `setIsDrawFalse` timeout |
435
+ | Any mask-mirror link | Broken from **both** ends, so neither viewer keeps the other alive. Disposing a source detaches its mirrors and repaints them empty (see §6.7) |
390
436
 
391
437
  The instance must not be used afterwards. It is safe to call more than once, so an unmount
392
438
  hook that may run twice needs no guard.
@@ -522,7 +568,7 @@ const type = nrrdTools.getActiveSphereType();
522
568
  ##### Interaction Flow
523
569
 
524
570
  ```
525
- Sphere mode activated (gui_states.mode.sphere = true, keyboard shortcut: 'q'):
571
+ Sphere mode activated (gui_states.mode.sphere = true, via setMode("sphere")):
526
572
  ├─ Shift key DISABLED (no draw mode)
527
573
  ├─ Crosshair toggle allowed (S key)
528
574
  │
@@ -920,7 +966,55 @@ upload flow, say) is expected to persist the new volume. The callback fires only
920
966
  clinician undoes or redoes the replacement, because at that point the backend holds the newer
921
967
  volume and has to be told to fall back.
922
968
 
923
- #### 6.7 Erasing one channel — `clearChannel()` <Badge type="tip" text="3.10.2" />
969
+ #### 6.7 Mirroring another viewer's masks — `setMaskMirror()` <Badge type="tip" text="3.11.5" />
970
+
971
+ Draw a **different** viewer's masks on this one. The classic use is a side-by-side: annotate
972
+ on the left, and have the right-hand study show the same findings over its own image.
973
+
974
+ ```typescript
975
+ // `reference` draws `primary`'s masks
976
+ reference.setMaskMirror(primary);
977
+
978
+ // with a voxel→voxel transform between the two grids
979
+ reference.setMaskMirror(primary, mirrorToSource); // row-major 4×4
980
+
981
+ reference.setMaskMirror(null); // detach
982
+ const src = reference.getMaskMirrorSource(); // → primary | null
983
+ ```
984
+
985
+ **Everything is read live from the source** — its volumes, channel colours, layer and channel
986
+ visibility, per-layer opacity, and its fill/outline render mode. Change any of them on the
987
+ source and the mirror follows on the next frame. A mirroring viewer needs no layers of its
988
+ own; `layers: []` pairs naturally with this.
989
+
990
+ ::: warning Display only
991
+ Nothing is written to either viewer's masks. The mirror holds no mask data at all — it is a
992
+ view onto the source, so there is no copy to keep in sync and nothing to save.
993
+ :::
994
+
995
+ **The transform.** `mirrorToSource` is a row-major 4×4 mapping *this* viewer's voxel
996
+ `(x, y, z, 1)` to the source's voxel. Omit it for the identity, which is right when both
997
+ viewers share a grid.
998
+
999
+ | Case | Sampling |
1000
+ |------|----------|
1001
+ | Identity **and** identical dimensions | The source's own slice, unchanged |
1002
+ | Diagonal transform (axes agree; only scale and offset differ) | A mirror voxel coarser than the source shows the first label among every source voxel it spans — so a finding thinner than the mirror's slice still appears on the slice containing it |
1003
+ | Any other transform | Nearest source voxel |
1004
+
1005
+ A cell mapping outside the source reads as empty.
1006
+
1007
+ **Refresh and teardown.** Every visible mask change on the source ends in a composite, and
1008
+ each one schedules a repaint of its mirrors on the next animation frame; repeated changes
1009
+ coalesce into one. `dispose()` breaks the link from both ends, so neither viewer keeps the
1010
+ other alive — disposing the source detaches its mirrors and repaints them empty.
1011
+
1012
+ ::: tip Sphere mode hides it
1013
+ The source hides its own layers in sphere mode, so a mirror of it shows nothing while that
1014
+ mode is active — matching what the source itself displays.
1015
+ :::
1016
+
1017
+ #### 6.8 Erasing one channel — `clearChannel()` <Badge type="tip" text="3.10.2" />
924
1018
 
925
1019
  ```typescript
926
1020
  nrrdTools.clearChannel('layer1', 3); // finding 3 goes; 1, 2 and 4 stay
@@ -1181,11 +1275,29 @@ window.addEventListener('keydown', (e) => {
1181
1275
  | Redo | `y` |
1182
1276
  | Contrast adjust | `Ctrl` / `Meta` (hold) |
1183
1277
  | Crosshair | `s` |
1184
- | Sphere mode | `q` |
1185
1278
  | Mouse wheel | Zoom |
1186
1279
  | Scroll:Zoom shortcut | `Ctrl+1` |
1187
1280
  | Scroll:Slice shortcut | `Ctrl+2` |
1188
1281
 
1282
+ ::: warning Sphere mode no longer has a shortcut <Badge type="warning" text="breaking in 3.11.5" />
1283
+ The `sphere: "q"` binding is **gone**, and `sphere` has been removed from
1284
+ `IKeyBoardSettings`. Sphere mode is now entered only through `setMode("sphere")` — which is
1285
+ also how the calculator reaches it — so the host always knows which tool is active.
1286
+
1287
+ The shortcut toggled the mode behind the host's back: pressing `q` cleared the masks from the
1288
+ view while the host's own UI still showed whatever tool it thought was selected.
1289
+
1290
+ If you passed `sphere` to `setKeyboardSettings`, drop it — it is no longer part of the type:
1291
+
1292
+ ```typescript
1293
+ // before
1294
+ nrrdTools.setKeyboardSettings({ sphere: 'e', crosshair: 'x' });
1295
+ // after
1296
+ nrrdTools.setKeyboardSettings({ crosshair: 'x' });
1297
+ nrrdTools.setMode('sphere'); // bind your own key to this if you want one
1298
+ ```
1299
+ :::
1300
+
1189
1301
  #### Reading current settings
1190
1302
 
1191
1303
  ```typescript
@@ -1308,6 +1420,13 @@ Everything that moves the zoom respects it: `setMainAreaSize`, wheel zoom, and
1308
1420
  `NrrdState.setZoomFactor`. The `"mainAreaSize"` GUI slider's `min` is updated too, so a
1309
1421
  connected dat.GUI / lil-gui panel can reach the new range.
1310
1422
 
1423
+ ::: tip Wheel zoom follows scroll distance <Badge type="tip" text="3.11.4" />
1424
+ One notch (100px of scroll) zooms by 10%, and a single event is capped at 2×. Because the
1425
+ ratio comes from the distance scrolled rather than from the number of events, a trackpad's
1426
+ small deltas zoom smoothly, and a busy page — where the browser coalesces wheel events and
1427
+ sums their deltas — zooms at the same rate as an idle one. Nothing to configure.
1428
+ :::
1429
+
1311
1430
  If the current factor is **below** the new minimum it is raised to it and the view repaints
1312
1431
  immediately, so you can lower and raise the floor freely without leaving the view in an
1313
1432
  invalid state.
@@ -1758,7 +1877,6 @@ interface IKeyBoardSettings {
1758
1877
  redo: string;
1759
1878
  contrast: string[]; // always an array, e.g. ["Control", "Meta"]
1760
1879
  crosshair: string;
1761
- sphere: string;
1762
1880
  mouseWheel: 'Scroll:Zoom' | 'Scroll:Slice';
1763
1881
  }
1764
1882
 
@@ -1814,8 +1932,10 @@ cap it below what the byte allows. Capping it lower is your product's call, not
1814
1932
  | | `commitSeriesLoad(slices, entries, i)` | Case-load completion: swap series + reconcile skips + land on contrast, one refresh |
1815
1933
  | | `switchAllSlicesArrayData(slices)` | Swap the loaded series (resets slice index / zoom / pan) |
1816
1934
  | | `switchSlicesPreservingView(slices)` | Swap the loaded series, keeping slice index, zoom and pan |
1935
+ | **Preview** | `showPreviewSlice(header, slice, i, cb)` | Show one depth-1 slice as slice `i` of the not-yet-loaded stack. While previewing, every slice move is handed to `cb` with the clamped target instead of moving the display. Axial only; ends on `switchSlicesPreservingView` / `setAllSlices` / `reset` |
1936
+ | | `isPreviewing()` | Whether a preview slice is shown in place of a loaded volume |
1817
1937
  | **Render** | `start` | Frame callback — pass to render loop |
1818
- | **Lifecycle** | `dispose()` | Release the event router's listeners, a pending slice step and the drawing-flag timer. Instance unusable afterwards; safe to call twice |
1938
+ | **Lifecycle** | `dispose()` | Release the event router's listeners, a pending slice step, the drawing-flag timer and any mask-mirror link (from both ends). Instance unusable afterwards; safe to call twice |
1819
1939
  | **Layer** | `setActiveLayer(id)` | Switch drawing target layer |
1820
1940
  | | `getActiveLayer()` | Read current layer |
1821
1941
  | | `setLayerVisible(id, bool)` | Toggle layer in composite view |
@@ -1828,6 +1948,8 @@ cap it below what the byte allows. Capping it lower is your product's call, not
1828
1948
  | | `setLayerOpacity(id, opacity)` | Set per-layer opacity (0.1–1.0), triggers re-render |
1829
1949
  | | `getLayerOpacity(id)` | Get opacity for a specific layer |
1830
1950
  | | `getLayerOpacityMap()` | Get all per-layer opacity values |
1951
+ | **Mirror** | `setMaskMirror(src, m?)` | Draw another viewer's masks, read live from it. `m` = row-major 4×4 mapping this viewer's voxel to the source's; `null` detaches. Display only — nothing is written to either viewer |
1952
+ | | `getMaskMirrorSource()` | The viewer being mirrored, or `null` |
1831
1953
  | **Sphere** | `setActiveSphereType(type)` | Set active sphere type (`'tumour'`/`'skin'`/`'nipple'`/`'ribcage'`), updates brush color |
1832
1954
  | | `getActiveSphereType()` | Read current sphere type |
1833
1955
  | **Channel** | `setActiveChannel(ch)` | Switch drawing target channel |
@@ -328,6 +328,8 @@ The `a` (alpha) field determines the base mask opacity. Usually set to `255`; ac
328
328
  | `setAllSlices` | `(allSlices: Array<nrrdSliceType>): void` | **Entry point**: Load NRRD slices and initialize all MaskVolumes to the correct dimensions |
329
329
  | `initFromHeader` | `(header: NrrdHeaderLike): void` | Size image metadata and MaskVolumes from volume geometry alone, before any pixel data exists. `allSlicesArray` is untouched |
330
330
  | `appendSlice` | `(slice: nrrdSliceType, order: number): void` | Append one already-loaded slice to the contrast series and refresh display slices / undo state |
331
+ | `showPreviewSlice` | `(header, slice, index, onSliceMove): void` *(NrrdTools)* | Show one depth-1 slice as slice `index` of the not-yet-loaded stack, and route slice moves to `onSliceMove` until a real volume takes over |
332
+ | `isPreviewing` | `(): boolean` *(NrrdTools)* | Whether a preview slice is shown |
331
333
  | `setMasksData` | `(masksData, loadingBar?): void` | Legacy loading method (deprecated, pending removal) |
332
334
  | `setMasksFromNIfTI` | `(layerVoxels: Map<string, Uint8Array>, loadingBar?): void` | Load mask data from NIfTI files into MaskVolume, validating each buffer's grid |
333
335
  | `registerNiftiMaskGrid` | `(data: Uint8Array, dims: number[]): void` *(module export)* | Record a mask buffer's NIfTI voxel grid, keyed by buffer identity, for `setMasksFromNIfTI` to check |
@@ -351,6 +353,41 @@ The split exists so a progressive loader can size everything from a backend head
351
353
  (`{ dimensions, spacing, space_origin }` as JSON — the same `NrrdHeaderLike` shape) and then
352
354
  feed slices in one at a time with `appendSlice` as they arrive.
353
355
 
356
+ #### Preview slices <Badge type="tip" text="3.11.6" />
357
+
358
+ `NrrdTools.showPreviewSlice(header, slice, index, onSliceMove)` is the progressive path's
359
+ front end, and it is built from the two pieces above:
360
+
361
+ ```
362
+ showPreviewSlice(header, slice, index, onSliceMove)
363
+ │
364
+ ├─ geometry differs from the current one? → dataLoader.initFromHeader(header)
365
+ │ (compared field-by-field on dimensions / spacing / space_origin, so repeated
366
+ │ calls while scrubbing re-initialise nothing)
367
+ │
368
+ ├─ slice.z.initIndex = index ◀ the full-stack index lives here, NOT in the
369
+ │ depth-1 slice's own `index`, where it would
370
+ │ be out of range
371
+ ├─ allSlicesArray.length = 0
372
+ ├─ sliceRenderPipeline.resetInitState()
373
+ ├─ dataLoader.appendSlice(slice, 0) ◀ one slice, so appendSlice is the right call here
374
+ └─ _previewSliceMove = onSliceMove
375
+ ```
376
+
377
+ **The slice-move interception.** While `_previewSliceMove` is set, `DragSliceTool` clamps the
378
+ requested index to `[minIndex, maxIndex]` and offers it to `previewSliceMove(target)`; a
379
+ `true` return means the move was consumed and the tool returns without touching the display.
380
+ The displayed slice has depth 1, so moving it would paint blank — the host is expected to
381
+ fetch that plane and call `showPreviewSlice` again.
382
+
383
+ The hook reaches `DragSliceTool` as a `ToolHost` dependency
384
+ (`DragSliceHostDeps` gained `previewSliceMove`), wired through
385
+ `DragOperator.setPreviewSliceMove`. Before `NrrdTools` sets it, the default returns `false`,
386
+ so every move proceeds normally.
387
+
388
+ `_previewSliceMove` is cleared by `setAllSlices`, `switchSlicesPreservingView` and `reset` —
389
+ the three ways a real volume takes over. `isPreviewing()` reports whether it is set.
390
+
354
391
  ::: warning `appendSlice` is not a loop-friendly substitute for `setAllSlices`
355
392
  It calls `setDisplaySlicesBaseOnAxis()` per slice, which rebuilds the display-slice list from
356
393
  a still-growing `allSlicesArray`, and whose `skipSlicesDic` bookkeeping assumes it is seeing
@@ -447,6 +484,15 @@ mode it redraws what is already on screen, and a mode-dependent branch there is
447
484
  that can fall out of step with the renderer. The display mode returns at pointer-up, via
448
485
  `refreshLayerFromVolume`.
449
486
 
487
+ ::: tip Both live in `contourPaint.ts` <Badge type="tip" text="3.11.5" />
488
+ The cache entry, the path building and the painting were extracted out of `RenderingUtils`
489
+ into `contourPaint.ts` so `MaskMirror` (§2.7) can paint a source viewer's masks with exactly
490
+ the same code — same cache shape, same fill/outline choice, same stroke geometry. Its exports
491
+ are `ContourEntry`, `LabelSlice`, `contourEntry(...)`, `paintContours(...)` and
492
+ `OUTLINE_WIDTH_PX`. `RenderingUtils` keeps the slice buffer, the compositing and the
493
+ per-layer cache map.
494
+ :::
495
+
450
496
  ##### Path cache
451
497
 
452
498
  The render mode is **not** part of the cache key. Each entry holds two lazily-built maps:
@@ -527,14 +573,74 @@ nrrdTools.setCalculateDistanceSphere(120, 95, 42, 'tumour');
527
573
  nrrdTools.setCalculateDistanceSphere(200, 150, 42, 'skin');
528
574
  ```
529
575
 
530
- ### 2.7 Other APIs
576
+ ### 2.7 Mask Mirroring <Badge type="tip" text="3.11.5" />
577
+
578
+ > **Implementation**: `tools/MaskMirror.ts`, painting through `contourPaint.ts`.
579
+
580
+ | Method | Signature | Description |
581
+ |--------|-----------|-------------|
582
+ | `setMaskMirror` | `(source: NrrdTools \| null, mirrorToSource?: ArrayLike<number>): void` | Draw `source`'s masks on this viewer. `null` — or passing this viewer itself — detaches |
583
+ | `getMaskMirrorSource` | `(): NrrdTools \| null` | The viewer being mirrored |
584
+
585
+ **`MaskMirror` holds no mask data.** Every paint reads the source's `CanvasState` live:
586
+ volumes, channel colours, layer/channel visibility, per-layer opacity and `maskRenderMode`.
587
+ There is no copy, so there is nothing to keep in sync and nothing to invalidate on an edit.
588
+
589
+ ```
590
+ NrrdTools A (source) NrrdTools B (mirror)
591
+ renderer.onComposited ──┐ renderer.mirror = MaskMirror(B.state, A.state, m)
592
+ │ │
593
+ A.scheduleMirrorRefresh() │
594
+ └─ rAF, coalesced ─────┴──► B.compositeAllLayers() ─┘
595
+ └─ …B's own layers, then mirror.paint(masterCtx, w, h)
596
+ ```
597
+
598
+ `compositeAllLayers` calls `this.mirror?.paint(...)` after the viewer's own layers, then fires
599
+ `onComposited`. So a mirror is painted **on top of** whatever the mirroring viewer has of its
600
+ own — usually nothing, since such a viewer is typically constructed with `layers: []`.
601
+
602
+ `SliceRenderPipeline` short-circuits to a plain `compositeAllLayers()` when
603
+ `hasMaskMirror()` is true: a mirroring viewer has no layers of its own to render.
604
+
605
+ #### Sampling — `mirrorSliceLabels`
606
+
607
+ The transform is a row-major 4×4 from **this** viewer's voxel `(x, y, z, 1)` to the source's.
608
+ Slices are built in `MaskVolume.getSliceUint8`'s layout for this viewer's own grid, so the
609
+ shared paint code draws them unchanged, flips included.
610
+
611
+ | Case | Path |
612
+ |------|------|
613
+ | `isIdentity(m)` **and** matching dimensions | Returns the source's own slice directly — no resampling |
614
+ | `isDiagonal(m)` (each axis maps onto its own) | `coveredRanges` gives, per mirror index, the inclusive source range it spans. A mirror voxel **coarser** than the source takes the first label among every source voxel it covers |
615
+ | Otherwise | Nearest source voxel |
616
+
617
+ The coarse-voxel rule is the one worth knowing: it means a finding thinner than the mirror's
618
+ slice still appears on the slice that contains it, instead of falling between samples. A cell
619
+ mapping outside the source reads as `0`.
620
+
621
+ #### Cache and failure handling
622
+
623
+ One `ContourEntry` per source layer, keyed `axis:index:volume.getVersion()`. The mirror also
624
+ tracks which `MaskVolume` object each entry came from and drops the entry when it changes — a
625
+ case load replaces the object, and the version counter alone would not notice.
626
+
627
+ A new transform means a **new `MaskMirror` instance**, so a cache can never hold contours
628
+ built under a different transform.
629
+
630
+ `paint` is defensive at two levels: the per-layer `try` swallows a source that is not ready
631
+ for this slice (nothing drawn for that layer), and a `finally` restores the canvas so a throw
632
+ cannot leave a layer's `globalAlpha` or transform on the master canvas. It also returns early
633
+ when the source is in sphere mode, which hides the source's own layers — so the mirror shows
634
+ what the source shows.
635
+
636
+ ### 2.8 Other APIs
531
637
 
532
638
  > **Implementation**: Directly in the NrrdTools Facade (section 5 View Control, section 6 Data Getters).
533
639
 
534
640
  | Method | Description |
535
641
  |--------|-------------|
536
642
  | `drag(opts?)` | Enable drag-to-scroll slice navigation |
537
- | `dispose()` | Teardown: `eventRouter.unbindAll()`, cancel the pending slice-step `requestAnimationFrame`, clear the `setIsDrawFalse` timer. Releases only what the instance attached outside its own DOM subtree — the window `blur` listener is the one that pins the whole engine graph. Instance unusable afterwards; idempotent |
643
+ | `dispose()` | Teardown: `eventRouter.unbindAll()`, cancel the pending slice-step `requestAnimationFrame`, clear the `setIsDrawFalse` timer, and break any mask-mirror link from both ends (disposing a source detaches its mirrors and repaints them empty). Releases only what the instance attached outside its own DOM subtree — the window `blur` listener is the one that pins the whole engine graph. Instance unusable afterwards; idempotent |
538
644
  | `setAnnotationSuspended(bool)` | Block every input that can write into a mask, at `DrawToolCore.onCanvasPointerDown`. Slice scrubbing, zoom, pan and the crosshair stay live (see 7.1) |
539
645
  | `isAnnotationSuspended()` | Query the suspension state |
540
646
  | `setSliceOrientation(axis)` | Switch viewing axis. Calls `ensureAxisExtracted` for every loaded contrast first, so a narrowed-axes load can still switch planes |
@@ -1284,6 +1390,30 @@ EventRouter permanently binds all pointer/keyboard/wheel events to the drawingCa
1284
1390
  | `'sphereBrush'` | Set by sphereBrush/sphereEraser mouseDown | `handleSphereBrushWheel` (adjusts `sphereBrushRadius`) |
1285
1391
  | `'none'` | Set by mouseDown in draw mode | No-op (wheel suppressed) |
1286
1392
 
1393
+ #### Wheel zoom ratio <Badge type="tip" text="3.11.4" />
1394
+
1395
+ `ZoomTool`'s `wheelZoomRatio(e)` derives the zoom ratio for one wheel event from **how far it
1396
+ scrolled**, not from the fact that it happened. It replaces a flat `±10%` per event.
1397
+
1398
+ ```
1399
+ 100px scrolled = one notch = ×1.1 (LOG_STEP_PER_PIXEL = ln(1.1) / 100)
1400
+ deltaMode 1 × 33px (lines, Firefox)
1401
+ deltaMode 2 × 800px (pages)
1402
+ no deltaY → one notch, direction from `detail` / `wheelDelta` (legacy events)
1403
+ ```
1404
+
1405
+ Positive `deltaY` (scrolling down) zooms out. The ratio is computed in log space and clamped
1406
+ to `MAX_RATIO_PER_EVENT = 2`, so a single runaway delta cannot jump the view.
1407
+
1408
+ **Why distance rather than event count.** A busy page makes the browser coalesce wheel events
1409
+ and sum their deltas. Counting events therefore zoomed a heavy view *slower* than a light one —
1410
+ the same physical scroll produced less zoom exactly when the app was under load. Following the
1411
+ distance zooms both alike, and it is what lets a trackpad's many small deltas zoom smoothly
1412
+ instead of in 10% jumps.
1413
+
1414
+ The result still passes through the `[minSizeFactor, 8]` clamp and the same
1415
+ `requestAnimationFrame` coalescing as before; only the per-event ratio changed.
1416
+
1287
1417
  ### 8.4 Default Keyboard Settings
1288
1418
 
1289
1419
  ```ts
@@ -1293,7 +1423,6 @@ IKeyBoardSettings = {
1293
1423
  redo: "y",
1294
1424
  contrast: ["Control", "Meta"],
1295
1425
  crosshair: "s",
1296
- sphere: "q",
1297
1426
  mouseWheel: "Scroll:Zoom", // or "Scroll:Slice"
1298
1427
  }
1299
1428
 
@@ -1302,6 +1431,20 @@ IKeyBoardSettings = {
1302
1431
  // Ctrl+2 → switch to Scroll:Slice
1303
1432
  ```
1304
1433
 
1434
+ ::: warning No `sphere` key <Badge type="warning" text="breaking in 3.11.5" />
1435
+ `sphere: "q"` has been removed from `IKeyBoardSettings`, from `EventRouter`'s
1436
+ `DEFAULT_KEYBOARD_SETTINGS`, and the toggle branch is gone from `DrawToolCore`'s keydown
1437
+ handler.
1438
+
1439
+ Sphere mode is entered only through `setMode("sphere")` — the path the calculator already
1440
+ uses — so the active tool is always something the host chose. The shortcut changed
1441
+ `gui_states.mode.sphere` directly, which runs `enterSphereMode()` and clears the masks from
1442
+ the view, while the host's UI still reported its own tool as selected. There was no event to
1443
+ tell it otherwise.
1444
+
1445
+ A host that wants a key for it binds one itself and calls `setMode`.
1446
+ :::
1447
+
1305
1448
  ---
1306
1449
 
1307
1450
  ## 9. Undo/Redo System
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "schemaVersion": 1,
3
- "copper3dVersion": "3.11.3",
4
- "generatedAt": "2026-09-30T00:54:40.159Z",
5
- "symbolCount": 1199,
3
+ "copper3dVersion": "3.11.5",
4
+ "generatedAt": "2026-09-30T23:00:30.674Z",
5
+ "symbolCount": 1202,
6
6
  "guides": [
7
7
  {
8
8
  "id": "4D-MRI-LV-rendering",
@@ -90,7 +90,7 @@
90
90
  "title": "NrrdTools Usage Guide",
91
91
  "summary": "Copper3D `NrrdTools` — Medical Image Segmentation Annotation Engine",
92
92
  "lang": "en",
93
- "bytes": 74550
93
+ "bytes": 81036
94
94
  },
95
95
  {
96
96
  "id": "on-demand-controls",
@@ -122,7 +122,7 @@
122
122
  "title": "Segmentation Module Documentation",
123
123
  "summary": "⚠️ **Note**: All line number references in this document are from historical versions. After multiple rounds of refactoring (State Management Refactor, NrrdTools God Class Split, inheritance → composition refactor), these references are ou…",
124
124
  "lang": "en",
125
- "bytes": 74638
125
+ "bytes": 82753
126
126
  },
127
127
  {
128
128
  "id": "surface-annotation-api",