copper3d 4.1.3 → 4.2.0
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 +15 -1
- package/ai-index/guides/nrrd-tools.md +105 -1
- package/ai-index/guides/segmentation-module.md +75 -1
- package/ai-index/manifest.json +5 -5
- package/ai-index/symbols.json +1 -1
- package/dist/Utils/segmentation/DrawToolCore.d.ts +18 -0
- package/dist/Utils/segmentation/DrawToolCore.js +63 -11
- package/dist/Utils/segmentation/DrawToolCore.js.map +1 -1
- package/dist/Utils/segmentation/NrrdTools.d.ts +29 -1
- package/dist/Utils/segmentation/NrrdTools.js +82 -1
- package/dist/Utils/segmentation/NrrdTools.js.map +1 -1
- package/dist/Utils/segmentation/RenderingUtils.d.ts +3 -0
- package/dist/Utils/segmentation/RenderingUtils.js +20 -4
- package/dist/Utils/segmentation/RenderingUtils.js.map +1 -1
- package/dist/Utils/segmentation/core/UndoManager.d.ts +18 -0
- package/dist/Utils/segmentation/core/UndoManager.js +19 -3
- package/dist/Utils/segmentation/core/UndoManager.js.map +1 -1
- package/dist/Utils/segmentation/core/index.d.ts +2 -2
- package/dist/Utils/segmentation/core/index.js +1 -1
- package/dist/Utils/segmentation/core/index.js.map +1 -1
- package/dist/Utils/segmentation/core/types.d.ts +9 -0
- package/dist/Utils/segmentation/core/types.js.map +1 -1
- package/dist/Utils/segmentation/coreTools/GuiState.d.ts +4 -2
- package/dist/Utils/segmentation/coreTools/GuiState.js +3 -1
- package/dist/Utils/segmentation/coreTools/GuiState.js.map +1 -1
- package/dist/Utils/segmentation/tools/DragSliceTool.js +6 -1
- package/dist/Utils/segmentation/tools/DragSliceTool.js.map +1 -1
- package/dist/Utils/segmentation/tools/DrawingTool.js +9 -1
- package/dist/Utils/segmentation/tools/DrawingTool.js.map +1 -1
- package/dist/Utils/segmentation/tools/HeatmapOverlay.d.ts +37 -0
- package/dist/Utils/segmentation/tools/HeatmapOverlay.js +185 -0
- package/dist/Utils/segmentation/tools/HeatmapOverlay.js.map +1 -0
- package/dist/Utils/segmentation/tools/SliceRenderPipeline.js +6 -0
- package/dist/Utils/segmentation/tools/SliceRenderPipeline.js.map +1 -1
- package/dist/Utils/segmentation/tools/SphereTool.js +6 -0
- package/dist/Utils/segmentation/tools/SphereTool.js.map +1 -1
- package/dist/bundle.esm.mjs +574 -206
- package/dist/bundle.umd.js +574 -205
- package/dist/index.d.ts +4 -3
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/types/Utils/segmentation/DrawToolCore.d.ts +18 -0
- package/dist/types/Utils/segmentation/NrrdTools.d.ts +29 -1
- package/dist/types/Utils/segmentation/RenderingUtils.d.ts +3 -0
- package/dist/types/Utils/segmentation/core/UndoManager.d.ts +18 -0
- package/dist/types/Utils/segmentation/core/index.d.ts +2 -2
- package/dist/types/Utils/segmentation/core/types.d.ts +9 -0
- package/dist/types/Utils/segmentation/coreTools/GuiState.d.ts +4 -2
- package/dist/types/Utils/segmentation/tools/HeatmapOverlay.d.ts +37 -0
- package/dist/types/index.d.ts +4 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -756,7 +756,8 @@ yourself. It throws on an unknown layer, or a channel outside `[1, 255]`.
|
|
|
756
756
|
| **Data** | `reset()` | Reset all volumes, undo histories, canvases, sphere data |
|
|
757
757
|
| | `clearActiveLayer()` | Clear active layer volume + undo history |
|
|
758
758
|
| | `clearActiveSlice()` | Clear current slice (undoable) |
|
|
759
|
-
| | `clearChannel(id, ch)` | Erase one channel across a whole layer (undoable); throws on unknown layer or channel outside [1, 255] |
|
|
759
|
+
| | `clearChannel(id, ch)` | Erase one channel across a whole layer (undoable); returns a `ChannelClear` handle, or `null` if the channel was empty; throws on unknown layer or channel outside [1, 255] |
|
|
760
|
+
| | `undoChannelClear(clear)` | Reverse that specific clear on its own layer, whatever layer is active; `false` if a later operation sits on it |
|
|
760
761
|
| | `setAllSlices(slices)` | Load NRRD slices, init MaskVolumes |
|
|
761
762
|
| | `setMasksFromNIfTI(map, bar?)` | Load saved NIfTI voxel data (grids must be registered first) |
|
|
762
763
|
| | `registerNiftiMaskGrid(data, dims)` | *(module export)* Record a mask buffer's NIfTI grid for validation |
|
|
@@ -817,6 +818,12 @@ yourself. It throws on an unknown layer, or a channel outside `[1, 255]`.
|
|
|
817
818
|
| | `getPencilColor()` | Read current pencil color |
|
|
818
819
|
| | `setMaskRenderMode(mode)` | `"fill"` or `"outline"` for every layer/channel; repaints immediately. Display only — the stored mask is unchanged |
|
|
819
820
|
| | `getMaskRenderMode()` | Read the current render mode |
|
|
821
|
+
| **Heatmap** | `setHeatmap(vol, dims)` | Canonical uint8 probabilities (p×255), x fastest; throws unless `dims` match the image and `vol.length === w*h*d`. `null` clears |
|
|
822
|
+
| | `setHeatmapVisible(bool)` | Draw it **instead of** every mask layer. While shown, nothing can write a mask |
|
|
823
|
+
| | `isHeatmapVisible()` | Query the heatmap view |
|
|
824
|
+
| | `setHeatmapThreshold(t)` | Probabilities below `t` (0–1) are not drawn; default `0.1` |
|
|
825
|
+
| | `setHeatmapOpacity(a)` | 0–1, default `0.5`; independent of the mask opacity |
|
|
826
|
+
| | `HEATMAP_COLORMAP` | *(module export)* 256-entry RGBA `Uint8ClampedArray` for a legend |
|
|
820
827
|
| **Contrast** | `setWindowHigh(value)` | Set window high |
|
|
821
828
|
| | `setWindowLow(value)` | Set window low |
|
|
822
829
|
| | `finishWindowAdjustment()` | Repaint all contrast slices after drag ends |
|
|
@@ -852,6 +859,13 @@ interface RGBAColor { r: number; g: number; b: number; a: number; } // 0-255
|
|
|
852
859
|
|
|
853
860
|
type ChannelColorMap = Record<number, RGBAColor>; // key = channel number, 1-255
|
|
854
861
|
|
|
862
|
+
// One channel clear, as clearChannel returns it, for undoChannelClear
|
|
863
|
+
interface ChannelClear {
|
|
864
|
+
readonly layerId: string;
|
|
865
|
+
readonly channel: number;
|
|
866
|
+
readonly entry: UndoEntry; // compared by identity
|
|
867
|
+
}
|
|
868
|
+
|
|
855
869
|
// What an undo or redo changed; getMaskData's last argument, set only for undo/redo
|
|
856
870
|
interface IMaskHistoryChange {
|
|
857
871
|
/** Channels whose voxels the undone or redone delta changed, ascending. */
|
|
@@ -1100,6 +1100,47 @@ Only slices that actually carry the label are touched, so a small annotation in
|
|
|
1100
1100
|
costs one scan and a handful of `getMaskData` callbacks rather than one callback per slice.
|
|
1101
1101
|
If the channel is empty, nothing is pushed and nothing fires.
|
|
1102
1102
|
|
|
1103
|
+
##### Reversing *that* clear — `undoChannelClear()` <Badge type="tip" text="4.1.4" />
|
|
1104
|
+
|
|
1105
|
+
`undo()` reverses the latest operation on the **active** layer. That is the wrong tool for an
|
|
1106
|
+
"Undo" affordance next to a deleted finding: by the time the user clicks it, the active layer
|
|
1107
|
+
may have moved on, and plain `undo()` would reverse something else entirely.
|
|
1108
|
+
|
|
1109
|
+
`clearChannel` now hands back a handle for exactly that:
|
|
1110
|
+
|
|
1111
|
+
```typescript
|
|
1112
|
+
const clear = nrrdTools.clearChannel('layer1', 3); // ChannelClear | null
|
|
1113
|
+
|
|
1114
|
+
// …the user switches to layer2, then clicks "Undo delete" on the toast
|
|
1115
|
+
if (clear && nrrdTools.undoChannelClear(clear)) {
|
|
1116
|
+
toast.dismiss(); // finding 3 is back on layer1
|
|
1117
|
+
}
|
|
1118
|
+
```
|
|
1119
|
+
|
|
1120
|
+
| | |
|
|
1121
|
+
|---|---|
|
|
1122
|
+
| Returns `null` | The channel held nothing, so there is nothing to undo |
|
|
1123
|
+
| `undoChannelClear` → `true` | The clear was reversed, on **its own** layer, whatever layer is active |
|
|
1124
|
+
| `undoChannelClear` → `false` | A later operation is stacked on it on that layer, or it was already undone |
|
|
1125
|
+
|
|
1126
|
+
::: tip It refuses rather than reaching past newer work
|
|
1127
|
+
A later edit on that layer is newer work, and reversing the clear underneath it would discard
|
|
1128
|
+
that edit silently. So `undoChannelClear` reverses the clear only while it is still that
|
|
1129
|
+
layer's latest operation; otherwise it changes nothing and returns `false`, and `undo()` is
|
|
1130
|
+
the way back — it steps through the stack in order.
|
|
1131
|
+
|
|
1132
|
+
Edits on a **different** layer do not block it; each layer has its own stack.
|
|
1133
|
+
:::
|
|
1134
|
+
|
|
1135
|
+
It is a once-only reversal, and it leaves the clear **redoable** exactly as `Ctrl+Z` does. The
|
|
1136
|
+
restored voxels are reported through `onMaskChanged` with their channels, like any other undo.
|
|
1137
|
+
|
|
1138
|
+
::: warning It repaints every slice, not just the visible one
|
|
1139
|
+
`undo()` repaints only the slice on screen when it lies on the undone delta's axis. A channel
|
|
1140
|
+
clear spans every slice carrying the label, so this repaints them all — the same work
|
|
1141
|
+
`clearChannel` itself does.
|
|
1142
|
+
:::
|
|
1143
|
+
|
|
1103
1144
|
::: warning Errors are thrown, not swallowed
|
|
1104
1145
|
- Unknown `layerId` → `Error` listing the known layers. It deliberately does **not** go
|
|
1105
1146
|
through `getVolumeForLayer`, which warns and falls back to the first layer; for a
|
|
@@ -1454,6 +1495,55 @@ own tool that bakes a canvas back into a volume, it must render filled too (see
|
|
|
1454
1495
|
[architecture guide](./segmentation-module)).
|
|
1455
1496
|
:::
|
|
1456
1497
|
|
|
1498
|
+
#### Probability heatmap <Badge type="tip" text="4.2.0" />
|
|
1499
|
+
|
|
1500
|
+
Show a model's per-voxel probabilities over the image, coloured on a navy → blue → cyan →
|
|
1501
|
+
yellow → red scale:
|
|
1502
|
+
|
|
1503
|
+
```typescript
|
|
1504
|
+
// Canonical uint8 probabilities (p × 255), x fastest, in the loaded image's dimensions
|
|
1505
|
+
nrrdTools.setHeatmap(probabilities, [w, h, d]);
|
|
1506
|
+
|
|
1507
|
+
nrrdTools.setHeatmapVisible(true);
|
|
1508
|
+
nrrdTools.setHeatmapThreshold(0.35); // below this, nothing is drawn
|
|
1509
|
+
nrrdTools.setHeatmapOpacity(0.6);
|
|
1510
|
+
|
|
1511
|
+
nrrdTools.isHeatmapVisible(); // → boolean
|
|
1512
|
+
nrrdTools.setHeatmap(null); // drop the volume
|
|
1513
|
+
nrrdTools.setHeatmapVisible(false); // back to the mask layers
|
|
1514
|
+
```
|
|
1515
|
+
|
|
1516
|
+
| | Default | |
|
|
1517
|
+
|---|---|---|
|
|
1518
|
+
| `visible` | `false` | Drawn **instead of** every mask layer, and instead of a mask mirror |
|
|
1519
|
+
| `threshold` | `0.1` | Clamped to 0–1; probabilities below it are not drawn |
|
|
1520
|
+
| `opacity` | `0.5` | Clamped to 0–1; the mask opacity does **not** dim it, it carries its own |
|
|
1521
|
+
|
|
1522
|
+
::: warning The volume must match the image exactly
|
|
1523
|
+
`setHeatmap` throws if `dims` differ from `getCurrentImageDimension()`, or if
|
|
1524
|
+
`volume.length !== w * h * d`. It is refused rather than stretched or cropped — a heatmap on
|
|
1525
|
+
the wrong grid would point at the wrong voxels, which is worse than no heatmap.
|
|
1526
|
+
:::
|
|
1527
|
+
|
|
1528
|
+
::: danger Nothing can write a mask while the heatmap is shown
|
|
1529
|
+
This is the rule the whole feature is built on: what is on screen is not a mask, so an edit
|
|
1530
|
+
would be applied to something the clinician cannot see. Every write path returns early —
|
|
1531
|
+
|
|
1532
|
+
- drawing (pencil, brush, eraser, sphere brush/eraser) and sphere placement,
|
|
1533
|
+
- `executeAction(...)` for everything except `"resetZoom"` and `"downloadCurrentMask"`,
|
|
1534
|
+
- `clearActiveLayer()` and `setCalculateDistanceSphere(...)`.
|
|
1535
|
+
|
|
1536
|
+
They are **silent no-ops**, not errors. Your UI should reflect that — disable the tools, or
|
|
1537
|
+
hide the heatmap first. `setHeatmapVisible(false)` restores everything immediately.
|
|
1538
|
+
:::
|
|
1539
|
+
|
|
1540
|
+
Slice scrubbing, axis switching, zoom and pan all work normally and repaint the heatmap. Just
|
|
1541
|
+
after an axis switch the slice index is clamped to the new axis's range, so a stale index
|
|
1542
|
+
cannot read past the end.
|
|
1543
|
+
|
|
1544
|
+
`HEATMAP_COLORMAP` is exported if you need to draw a matching legend — a `Uint8ClampedArray`
|
|
1545
|
+
of 256 RGBA entries, indexed by the probability byte.
|
|
1546
|
+
|
|
1457
1547
|
#### Canvas size scaling
|
|
1458
1548
|
|
|
1459
1549
|
Set the base display size multiplier (1–8). Larger values use more GPU memory but give sharper annotations:
|
|
@@ -1946,6 +2036,13 @@ interface IKeyBoardSettings {
|
|
|
1946
2036
|
}
|
|
1947
2037
|
|
|
1948
2038
|
// 3D coordinate (used in sphere position callbacks)
|
|
2039
|
+
// One channel clear, as clearChannel returns it, for undoChannelClear
|
|
2040
|
+
interface ChannelClear {
|
|
2041
|
+
readonly layerId: string;
|
|
2042
|
+
readonly channel: number;
|
|
2043
|
+
readonly entry: UndoEntry; // compared by identity
|
|
2044
|
+
}
|
|
2045
|
+
|
|
1949
2046
|
// What an undo or redo changed; passed as getMaskData's last argument
|
|
1950
2047
|
interface IMaskHistoryChange {
|
|
1951
2048
|
/** Channels whose voxels the undone or redone delta changed, ascending. */
|
|
@@ -1990,7 +2087,8 @@ cap it below what the byte allows. Capping it lower is your product's call, not
|
|
|
1990
2087
|
| **Data** | `reset()` | Reset all volumes, undo histories, canvases, and sphere data |
|
|
1991
2088
|
| | `clearActiveLayer()` | Clear annotations and undo history for the *currently active layer* |
|
|
1992
2089
|
| | `clearActiveSlice()` | Clear annotations exclusively on the *currently viewed slice* of the active layer |
|
|
1993
|
-
| | `clearChannel(id, ch)` | Erase one channel across a whole layer, undoably. Throws on an unknown layer or a channel outside [1, 255] |
|
|
2090
|
+
| | `clearChannel(id, ch)` | Erase one channel across a whole layer, undoably. Returns a `ChannelClear` handle, or `null` if the channel was empty. Throws on an unknown layer or a channel outside [1, 255] |
|
|
2091
|
+
| | `undoChannelClear(clear)` | Reverse that specific clear on its own layer, whatever layer is active. `false` if a later operation sits on it, or it was already undone |
|
|
1994
2092
|
| | `setAllSlices(slices)` | Load NRRD slices, init MaskVolumes |
|
|
1995
2093
|
| | `setMasksFromNIfTI(map, bar?)` | Load saved NIfTI voxel data (each buffer must be registered via `registerNiftiMaskGrid` first, or it is refused) |
|
|
1996
2094
|
| | `registerNiftiMaskGrid(data, dims)` | *(module export, not a method)* Record a mask buffer's NIfTI voxel grid so `setMasksFromNIfTI` can validate it |
|
|
@@ -2047,6 +2145,12 @@ cap it below what the byte allows. Capping it lower is your product's call, not
|
|
|
2047
2145
|
| | `getOpacity()` | Read current opacity |
|
|
2048
2146
|
| | `setMaskRenderMode(mode)` | `"fill"` or `"outline"` for every layer/channel; repaints immediately. Display only — the stored mask is unchanged |
|
|
2049
2147
|
| | `getMaskRenderMode()` | Read the current render mode |
|
|
2148
|
+
| **Heatmap** | `setHeatmap(vol, dims)` | Canonical uint8 probabilities (p×255), x fastest; throws unless `dims` match the image and `vol.length === w*h*d`. `null` clears |
|
|
2149
|
+
| | `setHeatmapVisible(bool)` | Draw it **instead of** every mask layer. While shown, nothing can write a mask |
|
|
2150
|
+
| | `isHeatmapVisible()` | Query the heatmap view |
|
|
2151
|
+
| | `setHeatmapThreshold(t)` | Probabilities below `t` (0–1) are not drawn; default `0.1` |
|
|
2152
|
+
| | `setHeatmapOpacity(a)` | 0–1, default `0.5`; independent of the mask opacity |
|
|
2153
|
+
| | `HEATMAP_COLORMAP` | *(module export)* 256-entry RGBA `Uint8ClampedArray` for a legend |
|
|
2050
2154
|
| | `setBrushSize(size)` | Set brush/eraser size [5, 50], updates cursor |
|
|
2051
2155
|
| | `getBrushSize()` | Read current brush size |
|
|
2052
2156
|
| | `setPencilColor(hex)` | Set pencil stroke color (hex string) |
|
|
@@ -118,7 +118,8 @@ protectedData.maskData.volumes = {
|
|
|
118
118
|
|--------|-----------|-------------|
|
|
119
119
|
| `setActiveLayer` | `(layerId: string): void` | Set the active Layer; also updates fillColor/brushColor |
|
|
120
120
|
| `setActiveChannel` | `(channel: ChannelValue): void` | Set the active Channel (1–`MAX_ENGINE_CHANNEL`); updates brush color |
|
|
121
|
-
| `clearChannel` | `(layerId
|
|
121
|
+
| `clearChannel` | `(layerId, channel): ChannelClear \| null` | Erase one label across a whole layer, undoably. Returns the clear as a handle for `undoChannelClear`, or `null` when the channel held nothing. Throws on an unknown layer (deliberately not via `getVolumeForLayer`, whose fallback would erase a different layer) or a channel outside [1, 255] |
|
|
122
|
+
| `undoChannelClear` | `(clear: ChannelClear): boolean` | Reverse that clear on **its own** layer, whatever layer is active, and only while it is still that layer's latest operation. `false` when a later operation is stacked on it or it was already undone. Repaints every slice, since a clear spans them all |
|
|
122
123
|
| `setCurrentLayer` | `(): { ctx, canvas } \| null` *(ToolHost)* | The layer canvas drawing should target. **Returns `null`** when the instance has no layers at all — `new NrrdTools(el, { layers: [] })`, a read-only reference viewer. Every caller must skip its work on `null` rather than dereference |
|
|
123
124
|
| `getLayerVolume` | `(layerId: string): Uint8Array \| null` | A **copy** of the layer's voxel buffer — not the live array, which a caller could mutate with nothing invalidating the slice cache. Delegates to `DrawToolCore.getLayerVolume` |
|
|
124
125
|
| `replaceLayerVolume` | `(layerId, data, opts?): void` | Replace the whole buffer. `{ undoable: true }` pushes one `VolumeSnapshot`. Does **not** fire `onLayerVolumeReplaced` itself — that fires only on a later undo/redo, when the backend holds the newer volume and must be told to fall back |
|
|
@@ -780,6 +781,37 @@ GuiState groups 20 properties into 4 semantic sub-objects:
|
|
|
780
781
|
| `channelVisibility` | `Record<string, Record<number, boolean>>` | Channel visibility map |
|
|
781
782
|
| `layerOpacity` | `Record<string, number>` | Per-layer opacity map (0.1–1.0, default 1.0) |
|
|
782
783
|
|
|
784
|
+
#### gui_states.heatmap (IHeatmapViewState) <Badge type="tip" text="4.2.0" />
|
|
785
|
+
|
|
786
|
+
| Field | Type | Default | Description |
|
|
787
|
+
|-------|------|---------|-------------|
|
|
788
|
+
| `visible` | `boolean` | `false` | While true the heatmap is drawn **instead of** every layer and the mirror |
|
|
789
|
+
| `threshold` | `number` | `0.1` | 0–1; probabilities below it are not drawn |
|
|
790
|
+
| `opacity` | `number` | `0.5` | 0–1; independent of the mask `globalAlpha` |
|
|
791
|
+
|
|
792
|
+
`isHeatmapShown(state)` is the single predicate every call site uses. It reads
|
|
793
|
+
`gui_states.heatmap?.visible === true` defensively, because older state fakes in tests carry
|
|
794
|
+
no `heatmap` at all.
|
|
795
|
+
|
|
796
|
+
**It gates the composite and every write.** `compositeAllLayers` returns right after painting
|
|
797
|
+
the heatmap, so no layer and no mirror is drawn; and the write paths return early:
|
|
798
|
+
|
|
799
|
+
| Where | What it blocks |
|
|
800
|
+
|-------|----------------|
|
|
801
|
+
| `DrawToolCore.writesBlocked()` | Drawing — the same gate `annotationSuspended` uses, now `annotationSuspended \|\| isHeatmapShown(...)` |
|
|
802
|
+
| `DrawToolCore` keydown / undo / redo / clear paths | Six early returns covering the history and clear operations |
|
|
803
|
+
| `SphereTool` click and pointer-up | Sphere placement |
|
|
804
|
+
| `NrrdTools.executeAction` | Everything except `"resetZoom"` and `"downloadCurrentMask"`, which only read |
|
|
805
|
+
| `NrrdTools.clearActiveLayer`, `setCalculateDistanceSphere` | Both write, so both refuse |
|
|
806
|
+
|
|
807
|
+
The reason is one sentence: what is on screen is not a mask, so an edit would land on
|
|
808
|
+
something the clinician cannot see.
|
|
809
|
+
|
|
810
|
+
Two display details worth knowing. `DrawToolCore` sets `drawingCtx.globalAlpha = 1` before
|
|
811
|
+
compositing while the heatmap is shown, so the mask opacity cannot dim it — it carries its
|
|
812
|
+
own. And `RenderingUtils` clamps the slice index to the heatmap's extent for the current axis,
|
|
813
|
+
because just after an axis switch the index may still belong to the previous one.
|
|
814
|
+
|
|
783
815
|
### 3.3 protectedData (IProtected)
|
|
784
816
|
|
|
785
817
|
Defined in `CanvasState.ts` constructor.
|
|
@@ -1524,6 +1556,48 @@ broke in two different ways for any other id — and `NrrdTools`'s constructor h
|
|
|
1524
1556
|
needs to know which layers exist, and `clearAll()` now iterates the maps rather than a fixed
|
|
1525
1557
|
id list.
|
|
1526
1558
|
|
|
1559
|
+
### Undoing a named entry <Badge type="tip" text="4.1.4" />
|
|
1560
|
+
|
|
1561
|
+
`undo()` always acts on the *active* layer's top entry. Reversing one specific earlier
|
|
1562
|
+
operation — a channel clear the host offered an "Undo" button for — needs to address the entry
|
|
1563
|
+
itself, which is what these add:
|
|
1564
|
+
|
|
1565
|
+
| Member | Does |
|
|
1566
|
+
|--------|------|
|
|
1567
|
+
| `undoOn(layerId)` | Like `undo()`, but on the layer named rather than the active one. The entry moves to that layer's redo stack just the same |
|
|
1568
|
+
| `peek(layerId)` | The entry an undo on that layer *would* take next, left in place |
|
|
1569
|
+
| `entryLayer(entry)` | The layer an entry belongs to — `entry[0].layerId` for a delta group, `entry.layerId` for a volume snapshot |
|
|
1570
|
+
|
|
1571
|
+
```ts
|
|
1572
|
+
interface ChannelClear {
|
|
1573
|
+
readonly layerId: string;
|
|
1574
|
+
readonly channel: number;
|
|
1575
|
+
/** The undo entry the clear pushed; compared by identity. */
|
|
1576
|
+
readonly entry: UndoEntry;
|
|
1577
|
+
}
|
|
1578
|
+
```
|
|
1579
|
+
|
|
1580
|
+
`DrawToolCore.undoEntry(entry)` is the guard that makes this safe:
|
|
1581
|
+
|
|
1582
|
+
```
|
|
1583
|
+
undoEntry(entry)
|
|
1584
|
+
├─ layerId = entryLayer(entry) → undefined? refuse
|
|
1585
|
+
├─ undoManager.peek(layerId) !== entry → refuse ◀ a later op is stacked on it
|
|
1586
|
+
├─ undoManager.undoOn(layerId)
|
|
1587
|
+
└─ applyUndo(entry) → write "before" back, repaint, report
|
|
1588
|
+
```
|
|
1589
|
+
|
|
1590
|
+
The identity comparison in `peek(layerId) !== entry` is the whole mechanism: it reverses the
|
|
1591
|
+
entry only while it is still the top of its layer's stack. A later edit there is newer work,
|
|
1592
|
+
and silently reversing underneath it would discard that edit — so it refuses and returns
|
|
1593
|
+
`false`, leaving `undo()` to step back through the stack in order. It is also what makes a
|
|
1594
|
+
second call a no-op: after the first, the entry has moved to the redo stack and is no longer
|
|
1595
|
+
the top of the undo stack.
|
|
1596
|
+
|
|
1597
|
+
`applyUndo` was split out of `undoLastPainting` so both paths share one implementation: the
|
|
1598
|
+
write-back, the repaint and the `onMaskChanged` report are identical whichever way the entry
|
|
1599
|
+
was chosen.
|
|
1600
|
+
|
|
1527
1601
|
**Undo flow:**
|
|
1528
1602
|
|
|
1529
1603
|
```
|
package/ai-index/manifest.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"schemaVersion": 1,
|
|
3
|
-
"copper3dVersion": "4.
|
|
4
|
-
"generatedAt": "2026-11-
|
|
5
|
-
"symbolCount":
|
|
3
|
+
"copper3dVersion": "4.2.0",
|
|
4
|
+
"generatedAt": "2026-11-17T09:42:12.959Z",
|
|
5
|
+
"symbolCount": 1218,
|
|
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": 89923
|
|
94
94
|
},
|
|
95
95
|
{
|
|
96
96
|
"id": "on-demand-controls",
|
|
@@ -130,7 +130,7 @@
|
|
|
130
130
|
"title": "Segmentation Module Documentation",
|
|
131
131
|
"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…",
|
|
132
132
|
"lang": "en",
|
|
133
|
-
"bytes":
|
|
133
|
+
"bytes": 89618
|
|
134
134
|
},
|
|
135
135
|
{
|
|
136
136
|
"id": "surface-annotation-api",
|