copper3d 3.11.4 → 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.
- package/README.md +45 -1
- package/ai-index/guides/nrrd-tools.md +100 -2
- package/ai-index/guides/segmentation-module.md +108 -2
- package/ai-index/manifest.json +5 -5
- package/ai-index/symbols.json +1 -1
- package/dist/Utils/segmentation/DragOperator.d.ts +6 -0
- package/dist/Utils/segmentation/DragOperator.js +9 -0
- package/dist/Utils/segmentation/DragOperator.js.map +1 -1
- package/dist/Utils/segmentation/NrrdTools.d.ts +38 -1
- package/dist/Utils/segmentation/NrrdTools.js +105 -2
- package/dist/Utils/segmentation/NrrdTools.js.map +1 -1
- package/dist/Utils/segmentation/RenderingUtils.d.ts +5 -9
- package/dist/Utils/segmentation/RenderingUtils.js +10 -116
- package/dist/Utils/segmentation/RenderingUtils.js.map +1 -1
- package/dist/Utils/segmentation/contourPaint.d.ts +37 -0
- package/dist/Utils/segmentation/contourPaint.js +128 -0
- package/dist/Utils/segmentation/contourPaint.js.map +1 -0
- package/dist/Utils/segmentation/tools/DragSliceTool.js +5 -0
- package/dist/Utils/segmentation/tools/DragSliceTool.js.map +1 -1
- package/dist/Utils/segmentation/tools/MaskMirror.d.ts +42 -0
- package/dist/Utils/segmentation/tools/MaskMirror.js +165 -0
- package/dist/Utils/segmentation/tools/MaskMirror.js.map +1 -0
- package/dist/Utils/segmentation/tools/SliceRenderPipeline.js +5 -0
- package/dist/Utils/segmentation/tools/SliceRenderPipeline.js.map +1 -1
- package/dist/Utils/segmentation/tools/ToolHost.d.ts +10 -2
- package/dist/bundle.esm.js +418 -112
- package/dist/bundle.umd.js +418 -112
- package/dist/types/Utils/segmentation/DragOperator.d.ts +6 -0
- package/dist/types/Utils/segmentation/NrrdTools.d.ts +38 -1
- package/dist/types/Utils/segmentation/RenderingUtils.d.ts +5 -9
- package/dist/types/Utils/segmentation/contourPaint.d.ts +37 -0
- package/dist/types/Utils/segmentation/tools/MaskMirror.d.ts +42 -0
- package/dist/types/Utils/segmentation/tools/ToolHost.d.ts +10 -2
- 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
|
|
@@ -667,8 +707,10 @@ yourself. It throws on an unknown layer, or a channel outside `[1, 255]`.
|
|
|
667
707
|
| | `commitSeriesLoad(slices, entries, i)` | Case-load completion — one refresh |
|
|
668
708
|
| | `switchAllSlicesArrayData(slices)` | Swap the series (resets view state) |
|
|
669
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 |
|
|
670
712
|
| **Render** | `start` | Frame callback — pass to render loop |
|
|
671
|
-
| **Lifecycle** | `dispose()` | Release the event router's listeners, a pending slice step
|
|
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 |
|
|
672
714
|
| **Layer** | `setActiveLayer(id)` | Switch drawing target layer |
|
|
673
715
|
| | `getActiveLayer()` | Read current layer |
|
|
674
716
|
| | `setLayerVisible(id, bool)` | Toggle layer in composite view |
|
|
@@ -681,6 +723,8 @@ yourself. It throws on an unknown layer, or a channel outside `[1, 255]`.
|
|
|
681
723
|
| | `setLayerOpacity(id, opacity)` | Set per-layer opacity (0.1–1.0), triggers re-render |
|
|
682
724
|
| | `getLayerOpacity(id)` | Read one layer's opacity |
|
|
683
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` |
|
|
684
728
|
| **Sphere** | `setActiveSphereType(type)` | Set active sphere type, updates brush color |
|
|
685
729
|
| | `getActiveSphereType()` | Read current sphere type |
|
|
686
730
|
| | `setCalculateDistanceSphere(x, y, slice, type)` | Programmatically place a calculator sphere |
|
|
@@ -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.
|
|
@@ -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
|
|
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
|
|
@@ -1838,8 +1932,10 @@ cap it below what the byte allows. Capping it lower is your product's call, not
|
|
|
1838
1932
|
| | `commitSeriesLoad(slices, entries, i)` | Case-load completion: swap series + reconcile skips + land on contrast, one refresh |
|
|
1839
1933
|
| | `switchAllSlicesArrayData(slices)` | Swap the loaded series (resets slice index / zoom / pan) |
|
|
1840
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 |
|
|
1841
1937
|
| **Render** | `start` | Frame callback — pass to render loop |
|
|
1842
|
-
| **Lifecycle** | `dispose()` | Release the event router's listeners, a pending slice step
|
|
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 |
|
|
1843
1939
|
| **Layer** | `setActiveLayer(id)` | Switch drawing target layer |
|
|
1844
1940
|
| | `getActiveLayer()` | Read current layer |
|
|
1845
1941
|
| | `setLayerVisible(id, bool)` | Toggle layer in composite view |
|
|
@@ -1852,6 +1948,8 @@ cap it below what the byte allows. Capping it lower is your product's call, not
|
|
|
1852
1948
|
| | `setLayerOpacity(id, opacity)` | Set per-layer opacity (0.1–1.0), triggers re-render |
|
|
1853
1949
|
| | `getLayerOpacity(id)` | Get opacity for a specific layer |
|
|
1854
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` |
|
|
1855
1953
|
| **Sphere** | `setActiveSphereType(type)` | Set active sphere type (`'tumour'`/`'skin'`/`'nipple'`/`'ribcage'`), updates brush color |
|
|
1856
1954
|
| | `getActiveSphereType()` | Read current sphere type |
|
|
1857
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
|
|
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 |
|
package/ai-index/manifest.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"schemaVersion": 1,
|
|
3
|
-
"copper3dVersion": "3.11.
|
|
4
|
-
"generatedAt": "2026-09-
|
|
5
|
-
"symbolCount":
|
|
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":
|
|
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":
|
|
125
|
+
"bytes": 82753
|
|
126
126
|
},
|
|
127
127
|
{
|
|
128
128
|
"id": "surface-annotation-api",
|