copper3d 3.10.2 → 3.10.4

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 (41) hide show
  1. package/README.md +40 -4
  2. package/dist/Utils/segmentation/DrawToolCore.d.ts +8 -0
  3. package/dist/Utils/segmentation/DrawToolCore.js +12 -0
  4. package/dist/Utils/segmentation/DrawToolCore.js.map +1 -1
  5. package/dist/Utils/segmentation/NrrdTools.d.ts +21 -1
  6. package/dist/Utils/segmentation/NrrdTools.js +25 -0
  7. package/dist/Utils/segmentation/NrrdTools.js.map +1 -1
  8. package/dist/Utils/segmentation/RenderingUtils.d.ts +32 -0
  9. package/dist/Utils/segmentation/RenderingUtils.js +107 -12
  10. package/dist/Utils/segmentation/RenderingUtils.js.map +1 -1
  11. package/dist/Utils/segmentation/core/MarchingSquares.d.ts +26 -0
  12. package/dist/Utils/segmentation/core/MarchingSquares.js +113 -0
  13. package/dist/Utils/segmentation/core/MarchingSquares.js.map +1 -1
  14. package/dist/Utils/segmentation/core/UndoManager.d.ts +12 -1
  15. package/dist/Utils/segmentation/core/UndoManager.js +33 -17
  16. package/dist/Utils/segmentation/core/UndoManager.js.map +1 -1
  17. package/dist/Utils/segmentation/core/index.d.ts +2 -2
  18. package/dist/Utils/segmentation/core/index.js +1 -1
  19. package/dist/Utils/segmentation/core/index.js.map +1 -1
  20. package/dist/Utils/segmentation/core/types.d.ts +10 -0
  21. package/dist/Utils/segmentation/core/types.js.map +1 -1
  22. package/dist/Utils/segmentation/coreTools/GuiState.js +2 -0
  23. package/dist/Utils/segmentation/coreTools/GuiState.js.map +1 -1
  24. package/dist/Utils/segmentation/tools/DrawingTool.d.ts +19 -2
  25. package/dist/Utils/segmentation/tools/DrawingTool.js +30 -6
  26. package/dist/Utils/segmentation/tools/DrawingTool.js.map +1 -1
  27. package/dist/Utils/segmentation/tools/ToolHost.d.ts +7 -1
  28. package/dist/bundle.esm.js +324 -37
  29. package/dist/bundle.umd.js +324 -37
  30. package/dist/index.d.ts +2 -2
  31. package/dist/types/Utils/segmentation/DrawToolCore.d.ts +8 -0
  32. package/dist/types/Utils/segmentation/NrrdTools.d.ts +21 -1
  33. package/dist/types/Utils/segmentation/RenderingUtils.d.ts +32 -0
  34. package/dist/types/Utils/segmentation/core/MarchingSquares.d.ts +26 -0
  35. package/dist/types/Utils/segmentation/core/UndoManager.d.ts +12 -1
  36. package/dist/types/Utils/segmentation/core/index.d.ts +2 -2
  37. package/dist/types/Utils/segmentation/core/types.d.ts +10 -0
  38. package/dist/types/Utils/segmentation/tools/DrawingTool.d.ts +19 -2
  39. package/dist/types/Utils/segmentation/tools/ToolHost.d.ts +7 -1
  40. package/dist/types/index.d.ts +2 -2
  41. package/package.json +1 -1
@@ -31,6 +31,12 @@ export declare class RenderingUtils {
31
31
  * applied at fill time and intentionally *not* cached, so toggling them
32
32
  * needs no recompute.
33
33
  *
34
+ * The render mode is not in the key either. Fill paths and outline paths
35
+ * are built lazily and side by side under the same entry, so switching
36
+ * mode costs one extraction per visible label the first time and is a
37
+ * cache hit every time after — and a session that never leaves fill mode
38
+ * never builds an outline.
39
+ *
34
40
  * One entry per layer (the current slice). Switching slice/axis or
35
41
  * editing overwrites it.
36
42
  */
@@ -67,6 +73,15 @@ export declare class RenderingUtils {
67
73
  * allocating a new ImageData per layer per slice switch.
68
74
  */
69
75
  getOrCreateSliceBuffer(axis: "x" | "y" | "z"): ImageData | null;
76
+ /**
77
+ * Populate one cache entry's paths for one render mode.
78
+ *
79
+ * Split out because the two modes are built at different times: whichever is in use when
80
+ * a slice is first drawn, and the other one only if the clinician switches while still on
81
+ * that slice. Building both eagerly would make every slice scrub pay for a mode most
82
+ * sessions never turn on.
83
+ */
84
+ private buildPaths;
70
85
  /**
71
86
  * Render a layer's slice onto the target canvas as vector contours.
72
87
  *
@@ -79,6 +94,23 @@ export declare class RenderingUtils {
79
94
  * is no longer used on this path — callers may pass any valid ImageData.
80
95
  */
81
96
  renderSliceToCanvas(layer: string, axis: "x" | "y" | "z", sliceIndex: number, _buffer: ImageData, targetCtx: CanvasRenderingContext2D, scaledWidth: number, scaledHeight: number): void;
97
+ /**
98
+ * Render a layer's slice FILLED, whatever the clinician is currently looking at.
99
+ *
100
+ * For the tools that bake (`syncLayerSliceData` — pencil and eraser) the layer canvas is
101
+ * not a picture of the mask, it is the input the mask is rebuilt from: the bake replaces
102
+ * the whole slice in `MaskVolume` with whatever pixels it finds there.
103
+ *
104
+ * An outline is a lossy picture — it says where a mask ends, not what it contains — so
105
+ * baking one back writes rings and erases every interior on that slice, taking every other
106
+ * finding on the layer with it. One pencil stroke was enough.
107
+ *
108
+ * Hence a separate entry point rather than a flag threaded through the display path: a
109
+ * render that is about to be read back has a different requirement from one that is about
110
+ * to be looked at, and the two only coincided while there was one way to draw a mask.
111
+ */
112
+ renderSliceForBake(layer: string, axis: "x" | "y" | "z", sliceIndex: number, targetCtx: CanvasRenderingContext2D, scaledWidth: number, scaledHeight: number): void;
113
+ private drawSlice;
82
114
  /**
83
115
  * Invalidate the reusable buffer (e.g. when switching datasets).
84
116
  */
@@ -66,6 +66,32 @@ export declare function extractLabelPolygons(labels: Uint8Array, width: number,
66
66
  * visited so the contour closes correctly at the bbox edges.
67
67
  */
68
68
  export declare function extractLabelContours(labels: Uint8Array, width: number, height: number, targetLabel: number, stride?: number, channelOffset?: number, bbox?: ContourBBox): Path2D;
69
+ /**
70
+ * Emit the boundary of the region where `labels === targetLabel`, as open two-point segments.
71
+ *
72
+ * The counterpart to {@link extractLabelPolygons}: that one covers the region, this one traces
73
+ * its edge. Both walk the same cells with the same sampling, the same out-of-bounds rule and
74
+ * the same `+0.5` shift, so a renderer can fill one and stroke the other and have the mask end
75
+ * in exactly the same place either way.
76
+ *
77
+ * Segments are emitted per cell and left unjoined. Canvas rasterises a whole `Path2D` in one
78
+ * compositing pass, so segments meeting at a shared endpoint produce no seam and no doubled
79
+ * alpha where their round caps overlap — joining them into polylines would buy nothing and
80
+ * cost a chaining pass.
81
+ *
82
+ * Cost follows the perimeter, not the area: solid interior is case 15, which has no boundary.
83
+ *
84
+ * Parameters match {@link extractLabelContours}.
85
+ */
86
+ export declare function extractLabelBoundarySegments(labels: Uint8Array, width: number, height: number, targetLabel: number, stride?: number, channelOffset?: number, bbox?: ContourBBox): ContourPolygon[];
87
+ /**
88
+ * {@link extractLabelBoundarySegments} as a `Path2D`, ready to stroke.
89
+ *
90
+ * The outline counterpart to {@link extractLabelContours}. Stroke this; do not stroke the
91
+ * contour path — that one is per-cell polygons whose union is the silhouette, and stroking it
92
+ * draws every internal cell edge as well, covering the mask in a grid.
93
+ */
94
+ export declare function extractLabelOutline(labels: Uint8Array, width: number, height: number, targetLabel: number, stride?: number, channelOffset?: number, bbox?: ContourBBox): Path2D;
69
95
  /**
70
96
  * Detect the distinct non-zero labels present in a slice region.
71
97
  *
@@ -37,7 +37,18 @@ export declare class UndoManager {
37
37
  private undoStacks;
38
38
  private redoStacks;
39
39
  private activeLayer;
40
- constructor();
40
+ /**
41
+ * The stack for a layer, created on first use.
42
+ *
43
+ * Stacks used to be pre-created for exactly layer1/2/3, which broke in two ways at once for
44
+ * any other id -- and `NrrdTools`'s constructor has always accepted `options.layers`, so any
45
+ * other id is reachable. `push*` resolved with `?? get("layer1")` and silently appended to a
46
+ * different layer's history, so an undo later popped a stroke the user never made there;
47
+ * `undo`/`redo` asserted non-null on the same lookup and threw instead.
48
+ *
49
+ * Creating on demand removes both. Nothing else needs to know which layers exist.
50
+ */
51
+ private stackFor;
41
52
  /** Set the currently active layer (determines which stack undo/redo operates on). */
42
53
  setActiveLayer(layer: string): void;
43
54
  /** Push a single delta onto the active layer's undo stack and clear the redo stack. */
@@ -67,10 +67,10 @@
67
67
  * const legacy = convertVolumeToIPaintImages(volume);
68
68
  * ```
69
69
  */
70
- export type { Dimensions, RGBAColor, ChannelColorMap, SliceRenderOptions, LayerId, ChannelValue, ICommXYZ, ICommXY, ISkipSlicesDictType, ToolMode, IDragPrameters, IDrawingEvents, IContrastEvents, IPaintImages, IPaintImage, ILayerRenderTarget, IDownloadImageConfig, INewMaskData, IMaskData, IProtected, IToolModeState, IDrawingConfig, IViewConfig, ILayerChannelState, IGUIStates, IGuiMeta, IGuiParameterSettings, IImageMetadata, IViewState, IInteractionState, ISphereState, IInternalFlags, INrrdStates, IAnnotationCallbacks, IConvertObjType, ICursorPage, IDragOpts, IDrawOpts, IKeyBoardSettings, } from './types';
70
+ export type { Dimensions, RGBAColor, ChannelColorMap, SliceRenderOptions, LayerId, ChannelValue, ICommXYZ, ICommXY, ISkipSlicesDictType, ToolMode, IDragPrameters, IDrawingEvents, IContrastEvents, IPaintImages, IPaintImage, ILayerRenderTarget, IDownloadImageConfig, INewMaskData, IMaskData, IProtected, IToolModeState, IDrawingConfig, IViewConfig, ILayerChannelState, IGUIStates, IGuiMeta, IGuiParameterSettings, IImageMetadata, IViewState, IInteractionState, ISphereState, IInternalFlags, INrrdStates, IAnnotationCallbacks, IConvertObjType, ICursorPage, IDragOpts, IDrawOpts, IKeyBoardSettings, MaskRenderMode, } from './types';
71
71
  export { RenderMode, MAX_ENGINE_CHANNEL, MASK_CHANNEL_COLORS, MASK_CHANNEL_CSS_COLORS, CHANNEL_COLORS, CHANNEL_HEX_COLORS, AI_MASK_CHANNEL_COLORS, AI_CHANNEL_HEX_COLORS, rgbaToHex, rgbaToCss, } from './types';
72
72
  export { MaskVolume } from './MaskVolume';
73
73
  export type { MaskDelta, UndoEntry } from './UndoManager';
74
74
  export { UndoManager } from './UndoManager';
75
75
  export type { ContourBBox, ContourPolygon } from './MarchingSquares';
76
- export { extractLabelContours, extractLabelPolygons, findLabelsInSlice, } from './MarchingSquares';
76
+ export { extractLabelBoundarySegments, extractLabelContours, extractLabelOutline, extractLabelPolygons, findLabelsInSlice, } from './MarchingSquares';
@@ -240,6 +240,14 @@ export interface IToolModeState {
240
240
  activeSphereType: "tumour" | "skin" | "nipple" | "ribcage";
241
241
  }
242
242
  /** Drawing configuration — brush/pencil appearance and behavior */
243
+ /**
244
+ * How a mask is drawn onto the slice.
245
+ *
246
+ * `"fill"` paints the silhouette; `"outline"` strokes only its edge, leaving the interior
247
+ * clear so the image underneath stays readable. Purely a render-time choice — the mask stored
248
+ * in `MaskVolume`, uploaded, exported and undone is the same either way.
249
+ */
250
+ export type MaskRenderMode = "fill" | "outline";
243
251
  export interface IDrawingConfig {
244
252
  globalAlpha: number;
245
253
  lineWidth: number;
@@ -247,6 +255,8 @@ export interface IDrawingConfig {
247
255
  fillColor: string;
248
256
  brushColor: string;
249
257
  brushAndEraserSize: number;
258
+ /** Fill the mask or stroke only its boundary. Applies to every layer and channel at once. */
259
+ maskRenderMode: MaskRenderMode;
250
260
  }
251
261
  /** View configuration — UI layout and interaction parameters */
252
262
  export interface IViewConfig {
@@ -115,10 +115,27 @@ export declare class DrawingTool extends BaseTool {
115
115
  /** Push delta to UndoManager after drawing completes */
116
116
  private pushUndoDelta;
117
117
  /**
118
- * Redraws persisted layer data onto ctx before new pencil fill.
119
- * Delegates to the host's vector renderSliceToCanvas for consistency.
118
+ * Redraws persisted layer data onto ctx before the new pencil fill.
119
+ *
120
+ * Uses the BAKE renderer, not the display one. What lands on this canvas is about to be
121
+ * read straight back into the MaskVolume by `syncLayerSliceData`, which replaces the whole
122
+ * slice -- so this render is the data, not a picture of it. Drawing outlines here would
123
+ * bake rings and erase the interior of every mask on the layer.
120
124
  */
121
125
  private redrawPreviousImageToLayerCtx;
126
+ /**
127
+ * Put the active layer's canvas into the solid state the eraser and the bake both need.
128
+ *
129
+ * The eraser removes pixels matching the active channel's colour, and `syncLayerSliceData`
130
+ * then rebuilds the whole slice from what is left on the canvas. Against an outline there
131
+ * is nothing to match inside a mask, so a drag over a lesion erases nothing -- and the bake
132
+ * that follows writes the ring back and loses every interior on the layer.
133
+ *
134
+ * Unconditional rather than checked against the display mode: in fill mode this redraws
135
+ * what is already on screen, and a mode-dependent branch here is one more thing that can
136
+ * fall out of step with the renderer.
137
+ */
138
+ private solidifyLayerForErase;
122
139
  /** Draw a line segment on a layer canvas (pencil mode only) */
123
140
  private drawLinesOnLayer;
124
141
  /** Paint a segment on the current layer canvas and composite to master (pencil mode) */
@@ -18,6 +18,12 @@ export interface ToolHost {
18
18
  drawImageOnEmptyImage(canvas: HTMLCanvasElement): void;
19
19
  compositeAllLayers(): void;
20
20
  renderSliceToCanvas(layer: string, axis: "x" | "y" | "z", sliceIndex: number, buffer: ImageData, targetCtx: CanvasRenderingContext2D, scaledWidth: number, scaledHeight: number): void;
21
+ /**
22
+ * Render a layer's slice filled, whatever the display mode is. For tools that follow a
23
+ * render with `syncLayerSliceData`, which rebuilds the whole slice from the canvas: an
24
+ * outline would bake back as a ring and erase every mask interior on that slice.
25
+ */
26
+ renderSliceForBake(layer: string, axis: "x" | "y" | "z", sliceIndex: number, targetCtx: CanvasRenderingContext2D, scaledWidth: number, scaledHeight: number): void;
21
27
  getOrCreateSliceBuffer(axis: "x" | "y" | "z"): ImageData | null;
22
28
  flipDisplayImageByAxis(): void;
23
29
  redrawDisplayCanvas(): void;
@@ -71,7 +77,7 @@ export type ZoomHostDeps = Pick<ToolHost, 'resetPaintAreaUIPosition' | 'resizePa
71
77
  /** SphereTool host dependencies */
72
78
  export type SphereHostDeps = Pick<ToolHost, 'setEmptyCanvasSize' | 'drawImageOnEmptyImage' | 'enableCrosshair' | 'setUpSphereOrigins'>;
73
79
  /** DrawingTool host dependencies */
74
- export type DrawingHostDeps = Pick<ToolHost, 'setCurrentLayer' | 'compositeAllLayers' | 'syncLayerSliceData' | 'filterDrawedImage' | 'getVolumeForLayer' | 'pushUndoDelta' | 'renderSliceToCanvas' | 'getOrCreateSliceBuffer'>;
80
+ export type DrawingHostDeps = Pick<ToolHost, 'setCurrentLayer' | 'compositeAllLayers' | 'syncLayerSliceData' | 'filterDrawedImage' | 'getVolumeForLayer' | 'pushUndoDelta' | 'renderSliceToCanvas' | 'renderSliceForBake' | 'getOrCreateSliceBuffer'>;
75
81
  /** DragSliceTool host dependencies */
76
82
  export type DragSliceHostDeps = Pick<ToolHost, 'setSyncsliceNum' | 'setIsDrawFalse' | 'flipDisplayImageByAxis' | 'setEmptyCanvasSize' | 'getOrCreateSliceBuffer' | 'renderSliceToCanvas' | 'refreshSphereOverlay' | 'compositeAllLayers'>;
77
83
  /** LayerChannelManager host dependencies */
@@ -55,7 +55,7 @@ import { nrrdMeshesType, nrrdSliceType, SensorDecodedValue_kiwrious, SensorReadR
55
55
  import { IPaintImage, ICommXYZ, IGUIStates, IGuiParameterSettings, INrrdStates, IGuiMeta } from "./Utils/segmentation/core/types";
56
56
  import { NrrdState } from "./Utils/segmentation/coreTools/NrrdState";
57
57
  import { GuiState } from "./Utils/segmentation/coreTools/GuiState";
58
- import type { ToolMode, IAnnotationCallbacks } from "./Utils/segmentation/core/types";
58
+ import type { ToolMode, IAnnotationCallbacks, MaskRenderMode } from "./Utils/segmentation/core/types";
59
59
  import { CHANNEL_COLORS, CHANNEL_HEX_COLORS, AI_MASK_CHANNEL_COLORS, AI_CHANNEL_HEX_COLORS, rgbaToHex, rgbaToCss } from "./Utils/segmentation/core/index";
60
60
  import type { LayerId, ChannelValue } from "./Utils/segmentation/core/index";
61
61
  import { MAX_ENGINE_CHANNEL } from "./Utils/segmentation/core/index";
@@ -63,5 +63,5 @@ import type { AiPromptTool, AiPromptPoint, AiPromptPayload, AiMaskResult } from
63
63
  import "./css/style.css";
64
64
  export declare const REVISION: string;
65
65
  export { copperRenderer, copperRendererOnDemond, copperMSceneRenderer, setHDRFilePath, addLabelToScene, convert3DPostoScreenPos, convertScreenPosto3DPos, addBoxHelper, fullScreenListenner, configKiwriousHeart, copperScene, copperSceneOnDemond, copperMScene, CameraViewPoint, kiwrious, loadKiwrious, NrrdTools, registerNiftiMaskGrid, loading, Copper3dTrackballControls, Copper3dOrbitControls, createTexture2D_NRRD, MeshNodeTool, throttle, removeGuiFolderChilden, MAX_ENGINE_CHANNEL, CHANNEL_COLORS, CHANNEL_HEX_COLORS, AI_MASK_CHANNEL_COLORS, AI_CHANNEL_HEX_COLORS, rgbaToHex, rgbaToCss, GaussianSmoother, SurfaceAnnotator, exposureExponent, DEFAULT_TARGET_GREY, disposeObject3D, disposeMaterial, collectFadeTargets, setFade, restoreFade, createSceneBudget, defaultBudgetBytes, disposeScene, removeSceneFromMap, fitDistance, fitView, isRotateEnabled, setRotateEnabled, isPanEnabled, setPanEnabled, isZoomEnabled, setZoomEnabled, beginGesture, isGestureActive, setCameraPose, addVolumeBoundingBox, VOLUME_BOUNDS_NAME, DEFAULT_AXES, ensureAxisExtracted, copperGltfLoader, setDracoDecoderPath, setKTX2TranscoderPath, easeInOutCubic, viewPointToPose, rotateAroundAxis, interpolateFlightPose, poseDistance, orbitStepPose, zoomPose, orbitSwingAngle, installFastSliceRepaint, };
66
- export type { positionType, screenPosType, optsType, NrrdHeaderLike, GltfLoadOpts, nrrdMeshesType, nrrdSliceType, SensorDecodedValue_kiwrious, SensorReadResult_kiwrious, HeartRateResult_kiwrious, loadingBarType, IPaintImage, exportPaintImageType, IOptVTKLoader, aligned4DSurfaceType, aligned4DOptsType, Aligned4DController, raw4DVolumeTransformType, raw4DVolumeOptsType, Raw4DVolumeController, ICommXYZ, IGUIStates, IGuiParameterSettings, INrrdStates, NrrdState, GuiState, IGuiMeta, ToolMode, IAnnotationCallbacks, LayerId, ChannelValue, AiPromptTool, AiPromptPoint, AiPromptPayload, AiMaskResult, SurfaceAnnotatorOptions, Annotation, AnnotationMode, ExportOptions, ExposureVolume, DisposableObject3D, DisposableMaterial, FadeTarget, FadeableMaterial, SceneBudget, DisposableScene, SceneDisposalHost, FitBounds, FitViewScene, AxisGatedControls, GestureAxes, PosableScene, BoundingBoxHost, VolumeBoundingBoxOpts, NrrdAxis, Pose, };
66
+ export type { positionType, screenPosType, optsType, NrrdHeaderLike, GltfLoadOpts, nrrdMeshesType, nrrdSliceType, SensorDecodedValue_kiwrious, SensorReadResult_kiwrious, HeartRateResult_kiwrious, loadingBarType, IPaintImage, exportPaintImageType, IOptVTKLoader, aligned4DSurfaceType, aligned4DOptsType, Aligned4DController, raw4DVolumeTransformType, raw4DVolumeOptsType, Raw4DVolumeController, ICommXYZ, IGUIStates, IGuiParameterSettings, INrrdStates, NrrdState, GuiState, IGuiMeta, ToolMode, IAnnotationCallbacks, MaskRenderMode, LayerId, ChannelValue, AiPromptTool, AiPromptPoint, AiPromptPayload, AiMaskResult, SurfaceAnnotatorOptions, Annotation, AnnotationMode, ExportOptions, ExposureVolume, DisposableObject3D, DisposableMaterial, FadeTarget, FadeableMaterial, SceneBudget, DisposableScene, SceneDisposalHost, FitBounds, FitViewScene, AxisGatedControls, GestureAxes, PosableScene, BoundingBoxHost, VolumeBoundingBoxOpts, NrrdAxis, Pose, };
67
67
  export type { CameraViewPreset } from "./Controls/orbitFraming";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "copper3d",
3
3
  "description": "A 3d visualisation package base on threejs provides multiple scenes and Nrrd image load funtion.",
4
- "version": "3.10.2",
4
+ "version": "3.10.4",
5
5
  "main": "dist/bundle.umd.js",
6
6
  "moudle": "dist/bundle.esm.js",
7
7
  "types": "dist/types/index.d.ts",