copper3d 4.1.4 → 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.
Files changed (43) hide show
  1. package/README.md +6 -0
  2. package/ai-index/guides/nrrd-tools.md +55 -0
  3. package/ai-index/guides/segmentation-module.md +31 -0
  4. package/ai-index/manifest.json +5 -5
  5. package/ai-index/symbols.json +1 -1
  6. package/dist/Utils/segmentation/DrawToolCore.d.ts +7 -0
  7. package/dist/Utils/segmentation/DrawToolCore.js +42 -8
  8. package/dist/Utils/segmentation/DrawToolCore.js.map +1 -1
  9. package/dist/Utils/segmentation/NrrdTools.d.ts +12 -0
  10. package/dist/Utils/segmentation/NrrdTools.js +58 -0
  11. package/dist/Utils/segmentation/NrrdTools.js.map +1 -1
  12. package/dist/Utils/segmentation/RenderingUtils.d.ts +3 -0
  13. package/dist/Utils/segmentation/RenderingUtils.js +20 -4
  14. package/dist/Utils/segmentation/RenderingUtils.js.map +1 -1
  15. package/dist/Utils/segmentation/core/types.d.ts +9 -0
  16. package/dist/Utils/segmentation/core/types.js.map +1 -1
  17. package/dist/Utils/segmentation/coreTools/GuiState.d.ts +4 -2
  18. package/dist/Utils/segmentation/coreTools/GuiState.js +3 -1
  19. package/dist/Utils/segmentation/coreTools/GuiState.js.map +1 -1
  20. package/dist/Utils/segmentation/tools/DragSliceTool.js +6 -1
  21. package/dist/Utils/segmentation/tools/DragSliceTool.js.map +1 -1
  22. package/dist/Utils/segmentation/tools/DrawingTool.js +9 -1
  23. package/dist/Utils/segmentation/tools/DrawingTool.js.map +1 -1
  24. package/dist/Utils/segmentation/tools/HeatmapOverlay.d.ts +37 -0
  25. package/dist/Utils/segmentation/tools/HeatmapOverlay.js +185 -0
  26. package/dist/Utils/segmentation/tools/HeatmapOverlay.js.map +1 -0
  27. package/dist/Utils/segmentation/tools/SliceRenderPipeline.js +6 -0
  28. package/dist/Utils/segmentation/tools/SliceRenderPipeline.js.map +1 -1
  29. package/dist/Utils/segmentation/tools/SphereTool.js +6 -0
  30. package/dist/Utils/segmentation/tools/SphereTool.js.map +1 -1
  31. package/dist/bundle.esm.mjs +511 -200
  32. package/dist/bundle.umd.js +511 -199
  33. package/dist/index.d.ts +2 -1
  34. package/dist/index.js +2 -1
  35. package/dist/index.js.map +1 -1
  36. package/dist/types/Utils/segmentation/DrawToolCore.d.ts +7 -0
  37. package/dist/types/Utils/segmentation/NrrdTools.d.ts +12 -0
  38. package/dist/types/Utils/segmentation/RenderingUtils.d.ts +3 -0
  39. package/dist/types/Utils/segmentation/core/types.d.ts +9 -0
  40. package/dist/types/Utils/segmentation/coreTools/GuiState.d.ts +4 -2
  41. package/dist/types/Utils/segmentation/tools/HeatmapOverlay.d.ts +37 -0
  42. package/dist/types/index.d.ts +2 -1
  43. package/package.json +1 -1
package/README.md CHANGED
@@ -818,6 +818,12 @@ yourself. It throws on an unknown layer, or a channel outside `[1, 255]`.
818
818
  | | `getPencilColor()` | Read current pencil color |
819
819
  | | `setMaskRenderMode(mode)` | `"fill"` or `"outline"` for every layer/channel; repaints immediately. Display only — the stored mask is unchanged |
820
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 |
821
827
  | **Contrast** | `setWindowHigh(value)` | Set window high |
822
828
  | | `setWindowLow(value)` | Set window low |
823
829
  | | `finishWindowAdjustment()` | Repaint all contrast slices after drag ends |
@@ -1495,6 +1495,55 @@ own tool that bakes a canvas back into a volume, it must render filled too (see
1495
1495
  [architecture guide](./segmentation-module)).
1496
1496
  :::
1497
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
+
1498
1547
  #### Canvas size scaling
1499
1548
 
1500
1549
  Set the base display size multiplier (1–8). Larger values use more GPU memory but give sharper annotations:
@@ -2096,6 +2145,12 @@ cap it below what the byte allows. Capping it lower is your product's call, not
2096
2145
  | | `getOpacity()` | Read current opacity |
2097
2146
  | | `setMaskRenderMode(mode)` | `"fill"` or `"outline"` for every layer/channel; repaints immediately. Display only — the stored mask is unchanged |
2098
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 |
2099
2154
  | | `setBrushSize(size)` | Set brush/eraser size [5, 50], updates cursor |
2100
2155
  | | `getBrushSize()` | Read current brush size |
2101
2156
  | | `setPencilColor(hex)` | Set pencil stroke color (hex string) |
@@ -781,6 +781,37 @@ GuiState groups 20 properties into 4 semantic sub-objects:
781
781
  | `channelVisibility` | `Record<string, Record<number, boolean>>` | Channel visibility map |
782
782
  | `layerOpacity` | `Record<string, number>` | Per-layer opacity map (0.1–1.0, default 1.0) |
783
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
+
784
815
  ### 3.3 protectedData (IProtected)
785
816
 
786
817
  Defined in `CanvasState.ts` constructor.
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "schemaVersion": 1,
3
- "copper3dVersion": "4.1.4",
4
- "generatedAt": "2026-11-10T07:12:41.579Z",
5
- "symbolCount": 1207,
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": 87023
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": 87754
133
+ "bytes": 89618
134
134
  },
135
135
  {
136
136
  "id": "surface-annotation-api",