copper3d 3.6.13 → 3.7.1
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/dist/Controls/Copper3dOrbitControls.d.ts +54 -0
- package/dist/Controls/Copper3dOrbitControls.js +134 -0
- package/dist/Controls/Copper3dOrbitControls.js.map +1 -0
- package/dist/Controls/Copper3dTrackballControls.d.ts +45 -45
- package/dist/Controls/Copper3dTrackballControls.js.map +1 -1
- package/dist/Controls/copperControls.d.ts +17 -17
- package/dist/Controls/copperControls.js.map +1 -1
- package/dist/Controls/orbitFraming.d.ts +71 -0
- package/dist/Controls/orbitFraming.js +94 -0
- package/dist/Controls/orbitFraming.js.map +1 -0
- package/dist/Loader/copperDicomLoader.d.ts +13 -13
- package/dist/Loader/copperDicomLoader.js +6 -1
- package/dist/Loader/copperDicomLoader.js.map +1 -1
- package/dist/Loader/copperGltfLoader.d.ts +3 -3
- package/dist/Loader/copperNrrdLoader.d.ts +13 -13
- package/dist/Loader/copperNrrdLoader.js.map +1 -1
- package/dist/Loader/copperOBJLoader.d.ts +3 -3
- package/dist/Loader/copperRaw4DVolumeLoader.d.ts +10 -0
- package/dist/Loader/copperRaw4DVolumeLoader.js +270 -0
- package/dist/Loader/copperRaw4DVolumeLoader.js.map +1 -0
- package/dist/Loader/copperVtkLoader.d.ts +8 -8
- package/dist/Loader/copperVtkLoader.js.map +1 -1
- package/dist/Loader/mhdParser.d.ts +83 -0
- package/dist/Loader/mhdParser.js +130 -0
- package/dist/Loader/mhdParser.js.map +1 -0
- package/dist/Renderer/baseRenderer.d.ts +32 -33
- package/dist/Renderer/baseRenderer.js +1 -1
- package/dist/Renderer/baseRenderer.js.map +1 -1
- package/dist/Renderer/copperMSceneRenderer.d.ts +24 -24
- package/dist/Renderer/copperMSceneRenderer.js.map +1 -1
- package/dist/Renderer/copperRenderer.d.ts +20 -20
- package/dist/Renderer/copperRenderer.js.map +1 -1
- package/dist/Renderer/copperRendererOnDemond.d.ts +12 -12
- package/dist/Renderer/copperRendererOnDemond.js.map +1 -1
- package/dist/Scene/baseScene.d.ts +38 -38
- package/dist/Scene/baseScene.js.map +1 -1
- package/dist/Scene/commonSceneMethod.d.ts +50 -49
- package/dist/Scene/commonSceneMethod.js +4 -19
- package/dist/Scene/commonSceneMethod.js.map +1 -1
- package/dist/Scene/copperMScene.d.ts +42 -42
- package/dist/Scene/copperMScene.js +2 -15
- package/dist/Scene/copperMScene.js.map +1 -1
- package/dist/Scene/copperScene.d.ts +64 -58
- package/dist/Scene/copperScene.js +14 -2
- package/dist/Scene/copperScene.js.map +1 -1
- package/dist/Scene/copperSceneOnDemond.d.ts +13 -13
- package/dist/Scene/copperSceneOnDemond.js.map +1 -1
- package/dist/Scene/preRenderRegistry.d.ts +33 -0
- package/dist/Scene/preRenderRegistry.js +44 -0
- package/dist/Scene/preRenderRegistry.js.map +1 -0
- package/dist/Utils/MeshNodeTool.d.ts +41 -41
- package/dist/Utils/MeshNodeTool.js.map +1 -1
- package/dist/Utils/add3DLabel.d.ts +18 -18
- package/dist/Utils/add3DLabel.js.map +1 -1
- package/dist/Utils/colormapData.d.ts +9 -0
- package/dist/Utils/colormapData.js +39 -0
- package/dist/Utils/colormapData.js.map +1 -0
- package/dist/Utils/convet.d.ts +1 -1
- package/dist/Utils/convet.js.map +1 -1
- package/dist/Utils/download.d.ts +1 -1
- package/dist/Utils/download.js.map +1 -1
- package/dist/Utils/getVOILUT.d.ts +13 -13
- package/dist/Utils/getVOILUT.js.map +1 -1
- package/dist/Utils/kiwrious/configKiwrious.d.ts +4 -4
- package/dist/Utils/kiwrious/configKiwrious.js.map +1 -1
- package/dist/Utils/raycaster.d.ts +8 -8
- package/dist/Utils/raycaster.js.map +1 -1
- package/dist/Utils/segmentation/CanvasState.d.ts +31 -31
- package/dist/Utils/segmentation/CanvasState.js.map +1 -1
- package/dist/Utils/segmentation/DragOperator.d.ts +45 -45
- package/dist/Utils/segmentation/DragOperator.js.map +1 -1
- package/dist/Utils/segmentation/DrawToolCore.d.ts +168 -168
- package/dist/Utils/segmentation/DrawToolCore.js.map +1 -1
- package/dist/Utils/segmentation/NrrdTools.d.ts +334 -334
- package/dist/Utils/segmentation/NrrdTools.js +1 -1
- package/dist/Utils/segmentation/NrrdTools.js.map +1 -1
- package/dist/Utils/segmentation/RenderingUtils.d.ts +96 -96
- package/dist/Utils/segmentation/RenderingUtils.js.map +1 -1
- package/dist/Utils/segmentation/core/GaussianSmoother.d.ts +55 -55
- package/dist/Utils/segmentation/core/GaussianSmoother.js.map +1 -1
- package/dist/Utils/segmentation/core/MarchingSquares.d.ts +80 -80
- package/dist/Utils/segmentation/core/MarchingSquares.js.map +1 -1
- package/dist/Utils/segmentation/core/MaskVolume.d.ts +471 -471
- package/dist/Utils/segmentation/core/MaskVolume.js.map +1 -1
- package/dist/Utils/segmentation/core/UndoManager.d.ts +51 -51
- package/dist/Utils/segmentation/core/UndoManager.js.map +1 -1
- package/dist/Utils/segmentation/core/index.d.ts +76 -76
- package/dist/Utils/segmentation/core/types.d.ts +505 -505
- package/dist/Utils/segmentation/core/types.js +36 -36
- package/dist/Utils/segmentation/core/types.js.map +1 -1
- package/dist/Utils/segmentation/coreTools/GuiState.d.ts +22 -22
- package/dist/Utils/segmentation/coreTools/NrrdState.d.ts +25 -25
- package/dist/Utils/segmentation/coreTools/divControlTools.d.ts +19 -19
- package/dist/Utils/segmentation/coreTools/gui.d.ts +42 -42
- package/dist/Utils/segmentation/coreTools/gui.js.map +1 -1
- package/dist/Utils/segmentation/eventRouter/EventRouter.d.ts +157 -157
- package/dist/Utils/segmentation/eventRouter/EventRouter.js.map +1 -1
- package/dist/Utils/segmentation/eventRouter/index.d.ts +7 -7
- package/dist/Utils/segmentation/eventRouter/types.d.ts +71 -71
- package/dist/Utils/segmentation/tools/AiAssistTool.d.ts +249 -249
- package/dist/Utils/segmentation/tools/AiAssistTool.js.map +1 -1
- package/dist/Utils/segmentation/tools/BaseTool.d.ts +31 -31
- package/dist/Utils/segmentation/tools/ContrastTool.d.ts +23 -23
- package/dist/Utils/segmentation/tools/ContrastTool.js.map +1 -1
- package/dist/Utils/segmentation/tools/CrosshairTool.d.ts +40 -40
- package/dist/Utils/segmentation/tools/CrosshairTool.js.map +1 -1
- package/dist/Utils/segmentation/tools/DataLoader.d.ts +33 -33
- package/dist/Utils/segmentation/tools/DataLoader.js.map +1 -1
- package/dist/Utils/segmentation/tools/DragSliceTool.d.ts +33 -33
- package/dist/Utils/segmentation/tools/DragSliceTool.js.map +1 -1
- package/dist/Utils/segmentation/tools/DrawingTool.d.ts +126 -126
- package/dist/Utils/segmentation/tools/DrawingTool.js.map +1 -1
- package/dist/Utils/segmentation/tools/EraserTool.d.ts +16 -16
- package/dist/Utils/segmentation/tools/EraserTool.js.map +1 -1
- package/dist/Utils/segmentation/tools/ImageStoreHelper.d.ts +42 -42
- package/dist/Utils/segmentation/tools/ImageStoreHelper.js.map +1 -1
- package/dist/Utils/segmentation/tools/LayerChannelManager.d.ts +56 -56
- package/dist/Utils/segmentation/tools/LayerChannelManager.js.map +1 -1
- package/dist/Utils/segmentation/tools/PanTool.d.ts +47 -47
- package/dist/Utils/segmentation/tools/PanTool.js.map +1 -1
- package/dist/Utils/segmentation/tools/SliceRenderPipeline.d.ts +85 -85
- package/dist/Utils/segmentation/tools/SliceRenderPipeline.js.map +1 -1
- package/dist/Utils/segmentation/tools/SphereBrushTool.d.ts +204 -204
- package/dist/Utils/segmentation/tools/SphereBrushTool.js.map +1 -1
- package/dist/Utils/segmentation/tools/SphereTool.d.ts +249 -249
- package/dist/Utils/segmentation/tools/SphereTool.js.map +1 -1
- package/dist/Utils/segmentation/tools/ToolHost.d.ts +76 -76
- package/dist/Utils/segmentation/tools/ZoomTool.d.ts +16 -16
- package/dist/Utils/segmentation/tools/ZoomTool.js.map +1 -1
- package/dist/Utils/segmentation/tools/index.d.ts +25 -25
- package/dist/Utils/surfaceAnnotation/MeshGraph.d.ts +46 -46
- package/dist/Utils/surfaceAnnotation/MeshGraph.js.map +1 -1
- package/dist/Utils/surfaceAnnotation/SurfaceAnnotator.d.ts +213 -213
- package/dist/Utils/surfaceAnnotation/SurfaceAnnotator.js.map +1 -1
- package/dist/Utils/surfaceAnnotation/annotationStore.d.ts +32 -32
- package/dist/Utils/surfaceAnnotation/annotationStore.js.map +1 -1
- package/dist/Utils/surfaceAnnotation/contourRender.d.ts +7 -7
- package/dist/Utils/surfaceAnnotation/geodesicContour.d.ts +59 -59
- package/dist/Utils/surfaceAnnotation/geodesicContour.js.map +1 -1
- package/dist/Utils/surfaceAnnotation/index.d.ts +3 -3
- package/dist/Utils/surfaceAnnotation/pointMarkers.d.ts +16 -16
- package/dist/Utils/surfaceAnnotation/raycastSurface.d.ts +8 -8
- package/dist/Utils/surfaceAnnotation/raycastSurface.js.map +1 -1
- package/dist/Utils/surfaceAnnotation/strokeContour.d.ts +29 -29
- package/dist/Utils/surfaceAnnotation/strokeContour.js.map +1 -1
- package/dist/Utils/surfaceAnnotation/types.d.ts +47 -47
- package/dist/Utils/texture2d.d.ts +14 -12
- package/dist/Utils/texture2d.js +7 -1
- package/dist/Utils/texture2d.js.map +1 -1
- package/dist/Utils/utils.d.ts +37 -37
- package/dist/Utils/utils.js.map +1 -1
- package/dist/Utils/volumeColormap.d.ts +6 -0
- package/dist/Utils/volumeColormap.js +14 -0
- package/dist/Utils/volumeColormap.js.map +1 -0
- package/dist/Utils/volumeShader.d.ts +7 -0
- package/dist/Utils/volumeShader.js +98 -0
- package/dist/Utils/volumeShader.js.map +1 -0
- package/dist/Utils/workers/reformatSaveDataWorker.d.ts +13 -13
- package/dist/Utils/workers/reformatSaveDataWorker.js.map +1 -1
- package/dist/bundle.esm.js +64928 -43706
- package/dist/bundle.umd.js +64945 -43722
- package/dist/index.d.ts +35 -33
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/lib/dicom_pharser_dictionary.d.ts +1 -1
- package/dist/lib/environment/index.d.ts +8 -8
- package/dist/lib/three-vignette.d.ts +11 -11
- package/dist/lib/three-vignette.js.map +1 -1
- package/dist/types/Controls/Copper3dOrbitControls.d.ts +54 -0
- package/dist/types/Controls/orbitFraming.d.ts +71 -0
- package/dist/types/Loader/copperDicomLoader.d.ts +1 -1
- package/dist/types/Loader/copperRaw4DVolumeLoader.d.ts +10 -0
- package/dist/types/Loader/mhdParser.d.ts +83 -0
- package/dist/types/Renderer/baseRenderer.d.ts +0 -1
- package/dist/types/Scene/commonSceneMethod.d.ts +1 -0
- package/dist/types/Scene/copperScene.d.ts +8 -2
- package/dist/types/Scene/preRenderRegistry.d.ts +33 -0
- package/dist/types/Utils/colormapData.d.ts +9 -0
- package/dist/types/Utils/convet.d.ts +1 -1
- package/dist/types/Utils/segmentation/core/MaskVolume.d.ts +1 -1
- package/dist/types/Utils/texture2d.d.ts +2 -0
- package/dist/types/Utils/volumeColormap.d.ts +6 -0
- package/dist/types/Utils/volumeShader.d.ts +7 -0
- package/dist/types/Utils/workers/reformatSaveDataWorker.d.ts +1 -1
- package/dist/types/index.d.ts +5 -3
- package/dist/types/types/types.d.ts +82 -2
- package/dist/types/types.d.ts +310 -230
- package/package.json +4 -4
|
@@ -1,249 +1,249 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* AiAssistTool — interactive prompt-based segmentation (experimental).
|
|
3
|
-
*
|
|
4
|
-
* The clinician left-clicks foreground / background points (or drags a box /
|
|
5
|
-
* scribbles) on the current slice; a backend model returns a region mask that
|
|
6
|
-
* is written into an INDEPENDENT scratch MaskVolume (`aiAssistMaskVolume`,
|
|
7
|
-
* registered as `maskData.volumes['aiScratch']`) — never the validated layers.
|
|
8
|
-
*
|
|
9
|
-
* Network lives in the app layer: this tool only (a) maps screen → voxel-slice
|
|
10
|
-
* coordinates, (b) accumulates the prompt for the current slice, (c) fires
|
|
11
|
-
* `onPrompt` so the app can call the backend, and (d) applies the returned mask
|
|
12
|
-
* via `applyMask`. The app's `useAiAssist` composable wires (c)→(d).
|
|
13
|
-
*
|
|
14
|
-
* Sandbox: snapshot on enter (`snapshot`), then on exit either `discard`
|
|
15
|
-
* (restore snapshot) or merge is handled by NrrdTools (clone + pushGroup).
|
|
16
|
-
*
|
|
17
|
-
* Coordinate mapping supports all three views (axial/sagittal/coronal); it
|
|
18
|
-
* inverts the per-axis display transform of RenderingUtils.renderSliceToCanvas
|
|
19
|
-
* (only coronal 'y' is vertically flipped). Merge captures painted voxels from
|
|
20
|
-
* any view (the scratch is a full 3D volume).
|
|
21
|
-
*/
|
|
22
|
-
import { BaseTool } from "./BaseTool";
|
|
23
|
-
import type { ToolContext } from "./BaseTool";
|
|
24
|
-
import { MaskVolume } from "../core";
|
|
25
|
-
import type { SliceRenderHostDeps } from "./ToolHost";
|
|
26
|
-
/** Scratch volume key in maskData.volumes — kept OUT of image.layers so
|
|
27
|
-
* compositeAllLayers ignores it (we render it ourselves in start()). */
|
|
28
|
-
export declare const AI_SCRATCH_LAYER = "aiScratch";
|
|
29
|
-
export type AiPromptTool = "point" | "box" | "scribble" | "lasso";
|
|
30
|
-
export interface AiPromptPoint {
|
|
31
|
-
x: number;
|
|
32
|
-
y: number;
|
|
33
|
-
z?: number;
|
|
34
|
-
label: number;
|
|
35
|
-
}
|
|
36
|
-
export interface AiPromptPayload {
|
|
37
|
-
axis: "x" | "y" | "z";
|
|
38
|
-
sliceIndex: number;
|
|
39
|
-
width: number;
|
|
40
|
-
height: number;
|
|
41
|
-
points: AiPromptPoint[];
|
|
42
|
-
box?: {
|
|
43
|
-
x0: number;
|
|
44
|
-
y0: number;
|
|
45
|
-
x1: number;
|
|
46
|
-
y1: number;
|
|
47
|
-
label: number;
|
|
48
|
-
};
|
|
49
|
-
scribble?: AiPromptPoint[];
|
|
50
|
-
scribbleRadius?: number;
|
|
51
|
-
/** Closed-contour lasso: ordered contour points (implicitly closed — the
|
|
52
|
-
* backend connects the last point back to the first). One contour per gesture. */
|
|
53
|
-
lasso?: AiPromptPoint[];
|
|
54
|
-
}
|
|
55
|
-
export interface AiMaskResult {
|
|
56
|
-
axis: "x" | "y" | "z";
|
|
57
|
-
sliceIndex: number;
|
|
58
|
-
width: number;
|
|
59
|
-
height: number;
|
|
60
|
-
rle: number[];
|
|
61
|
-
/** 3D result (engine B / nnInteractive): inclusive [lo,hi] slice span + one RLE per slice. */
|
|
62
|
-
sliceRange?: [number, number];
|
|
63
|
-
slices?: number[][];
|
|
64
|
-
}
|
|
65
|
-
type AiAssistHostDeps = Pick<SliceRenderHostDeps, "renderSliceToCanvas" | "getOrCreateSliceBuffer">;
|
|
66
|
-
export declare class AiAssistTool extends BaseTool {
|
|
67
|
-
private host;
|
|
68
|
-
/** Independent scratch volume (also registered at maskData.volumes['aiScratch']). */
|
|
69
|
-
private scratchVol;
|
|
70
|
-
/** Snapshot of the scratch buffer taken on enter (for discard). */
|
|
71
|
-
private snapshotData;
|
|
72
|
-
/** Frozen regions ("New region" commits here). Pixels recorded here survive a
|
|
73
|
-
* later re-prediction — even on the SAME channel — so multiple separate regions
|
|
74
|
-
* can be drawn without the newest prediction wiping the previous ones. Null =
|
|
75
|
-
* nothing frozen yet (applySliceRle then behaves as a single live region). */
|
|
76
|
-
private committedVol;
|
|
77
|
-
private promptTool;
|
|
78
|
-
private polarity;
|
|
79
|
-
/** The label value (1-255) the AI currently paints into = the active Segmentation.
|
|
80
|
-
* Each Segmentation is a label value in the single-channel scratch volume; its
|
|
81
|
-
* colour lives in the volume's colorMap (set via setSegmentColor). */
|
|
82
|
-
private activeLabel;
|
|
83
|
-
/** Scribble brush radius (px), user-adjustable via slider. */
|
|
84
|
-
private scribbleSize;
|
|
85
|
-
/** Accumulated prompts for the CURRENT slice; reset on slice/axis change. */
|
|
86
|
-
private points;
|
|
87
|
-
private scribble;
|
|
88
|
-
/** Lasso contour sent to the backend (densified along the curve at finish). */
|
|
89
|
-
private lasso;
|
|
90
|
-
private box;
|
|
91
|
-
private activeSlice;
|
|
92
|
-
/** Placed lasso vertices (voxel + screen + polarity). Empty = not editing. */
|
|
93
|
-
private lassoVerts;
|
|
94
|
-
/** Undo / redo snapshot stacks of the vertex list (for Ctrl+Z / Ctrl+Y). */
|
|
95
|
-
private lassoUndo;
|
|
96
|
-
private lassoRedo;
|
|
97
|
-
/** Index of the vertex currently hovered (shows a red ✕; click removes it). −1 = none. */
|
|
98
|
-
private lassoHoverIdx;
|
|
99
|
-
/** Screen-pixel radius for hit-testing a hovered vertex. */
|
|
100
|
-
private static readonly LASSO_HIT_R;
|
|
101
|
-
/** Double-click detection (a dbl-click finishes the lasso). */
|
|
102
|
-
private lastLassoDownTime;
|
|
103
|
-
private lastLassoDownPos;
|
|
104
|
-
private dragging;
|
|
105
|
-
private dragStart;
|
|
106
|
-
private dragScreenStart;
|
|
107
|
-
private dragScreen;
|
|
108
|
-
private screenScribble;
|
|
109
|
-
private hoverScreen;
|
|
110
|
-
/** Hide the point seed markers once a prediction has painted (only the mask
|
|
111
|
-
* should remain). A new point click re-shows them until its mask returns. */
|
|
112
|
-
private hidePointMarkers;
|
|
113
|
-
/** Fired when a prompt gesture completes — app calls backend, then applyMask(). */
|
|
114
|
-
onPrompt: ((payload: AiPromptPayload) => void) | null;
|
|
115
|
-
/** Fired whenever the lasso vertex set changes (add/delete/undo/redo/finish/cancel),
|
|
116
|
-
* so the panel can reactively show the Finish button + vertex count. */
|
|
117
|
-
onLassoChange: ((count: number, editing: boolean) => void) | null;
|
|
118
|
-
constructor(ctx: ToolContext, host: AiAssistHostDeps);
|
|
119
|
-
setPromptTool(tool: AiPromptTool): void;
|
|
120
|
-
setPolarity(label: number): void;
|
|
121
|
-
setScribbleSize(size: number): void;
|
|
122
|
-
/** Select the active Segmentation by its label value (1-255). Switching starts a
|
|
123
|
-
* fresh prompt set — otherwise accumulated prompts would be re-predicted and
|
|
124
|
-
* repainted into the new label, recolouring the previous segmentation's region. */
|
|
125
|
-
setActiveSegment(label: number): void;
|
|
126
|
-
getActiveLabel(): number;
|
|
127
|
-
/** Set a Segmentation's colour (its label's entry in the scratch volume colorMap).
|
|
128
|
-
* The 2D overlay repaints next frame (copper3d's render loop re-reads the map). */
|
|
129
|
-
setSegmentColor(label: number, color: {
|
|
130
|
-
r: number;
|
|
131
|
-
g: number;
|
|
132
|
-
b: number;
|
|
133
|
-
a: number;
|
|
134
|
-
}): void;
|
|
135
|
-
/** "New segmentation": freeze the current regions (so they persist) and switch to
|
|
136
|
-
* a fresh label, exactly like the old "New region" but targeting a new label. */
|
|
137
|
-
newSegment(label: number): void;
|
|
138
|
-
/** Delete a Segmentation: erase every voxel painted with its label from BOTH the
|
|
139
|
-
* live scratch and the frozen (committed) volume, so the region disappears from
|
|
140
|
-
* the view (otherwise orphaned label voxels would render with the wrong colour).
|
|
141
|
-
* Goes via setRawData so the volume's version counter bumps (overlay repaints). */
|
|
142
|
-
clearSegment(label: number): void;
|
|
143
|
-
getScratchVolume(): MaskVolume | null;
|
|
144
|
-
/** Serialize the scratch volume as per-z-slice RLE (only NON-empty slices),
|
|
145
|
-
* for persisting to ai_generated_nii_LPS on the backend. Binary (any channel →
|
|
146
|
-
* 1); RLE is alternating run lengths starting with a 0-run — the exact format
|
|
147
|
-
* the backend's rle_decode expects. Uses getSliceUint8 (the same path the
|
|
148
|
-
* clinician layer's /api/mask/replace uses) so orientation matches. */
|
|
149
|
-
getScratchSlices(): {
|
|
150
|
-
axis: "z";
|
|
151
|
-
width: number;
|
|
152
|
-
height: number;
|
|
153
|
-
slices: {
|
|
154
|
-
sliceIndex: number;
|
|
155
|
-
rle: number[];
|
|
156
|
-
}[];
|
|
157
|
-
} | null;
|
|
158
|
-
/** Per-SEGMENTATION serialization for the 3D build: one binary RLE per non-empty
|
|
159
|
-
* z-slice PER label (no binarize-merge), so the backend writes a multi-label
|
|
160
|
-
* NIfTI and colours the GLB per segmentation. Includes both live and frozen
|
|
161
|
-
* regions (both live in scratchVol). */
|
|
162
|
-
getScratchSegments(): {
|
|
163
|
-
axis: "z";
|
|
164
|
-
width: number;
|
|
165
|
-
height: number;
|
|
166
|
-
segments: {
|
|
167
|
-
label: number;
|
|
168
|
-
slices: {
|
|
169
|
-
sliceIndex: number;
|
|
170
|
-
rle: number[];
|
|
171
|
-
}[];
|
|
172
|
-
}[];
|
|
173
|
-
} | null;
|
|
174
|
-
/** Create (or reuse) the scratch volume sized to the layer grid and register
|
|
175
|
-
* it under maskData.volumes['aiScratch']. Snapshots the empty buffer. */
|
|
176
|
-
enter(): void;
|
|
177
|
-
/** Remove the scratch volume from the registry and drop references. */
|
|
178
|
-
exit(): void;
|
|
179
|
-
/** Discard everything painted since enter() — restore the snapshot. */
|
|
180
|
-
discard(): void;
|
|
181
|
-
/** "New region": freeze every voxel painted so far so it survives later
|
|
182
|
-
* re-predictions (even on the same channel), then start a fresh prompt set.
|
|
183
|
-
* This is what makes drawing multiple separate regions actually work — without
|
|
184
|
-
* it the next prediction's same-channel cleanup erases the previous region. */
|
|
185
|
-
commitRegion(): void;
|
|
186
|
-
/** Clear the in-progress prompt set (e.g. slice/axis change). Does NOT freeze —
|
|
187
|
-
* use commitRegion() for the "New region" action. */
|
|
188
|
-
resetPrompts(): void;
|
|
189
|
-
/** Drop the in-progress lasso vertices + undo/redo history (does not touch a
|
|
190
|
-
* prediction already painted from a finished lasso). */
|
|
191
|
-
private clearLassoEditing;
|
|
192
|
-
/** Tell the app layer the lasso vertex set changed (drives the Finish button). */
|
|
193
|
-
private notifyLasso;
|
|
194
|
-
/** Voxel-slice (width,height) for the current axis. */
|
|
195
|
-
private sliceDims;
|
|
196
|
-
/** Screen offset → voxel-slice (vx,vy) for the current axis. */
|
|
197
|
-
private toVoxel;
|
|
198
|
-
/** Voxel-slice (vx,vy) → screen offset (px). Exact inverse of toVoxel, so
|
|
199
|
-
* markers / lasso curves drawn from voxel coords track pan AND zoom each frame
|
|
200
|
-
* (the freehand previews store screen px directly; persistent overlays don't). */
|
|
201
|
-
private voxelToScreen;
|
|
202
|
-
onPointerDown(e: MouseEvent): void;
|
|
203
|
-
/** Lasso click: double-click finishes; click on a vertex deletes it; otherwise
|
|
204
|
-
* add a vertex. Nothing is sent to the backend until finishLasso(). */
|
|
205
|
-
private onLassoPointerDown;
|
|
206
|
-
onPointerMove(e: MouseEvent): void;
|
|
207
|
-
onPointerUp(_e: MouseEvent): void;
|
|
208
|
-
/** Reset the accumulated prompt set when the user scrubs to a new slice. */
|
|
209
|
-
private syncSlice;
|
|
210
|
-
private emit;
|
|
211
|
-
/** Index of the lasso vertex under (sx,sy) within the hit radius, else −1.
|
|
212
|
-
* Uses live voxel→screen so it tracks pan/zoom. Topmost (latest) wins. */
|
|
213
|
-
private lassoVertAt;
|
|
214
|
-
/** Snapshot the vertex list for undo (clears redo). */
|
|
215
|
-
private pushLassoUndo;
|
|
216
|
-
/** Public: undo the last add/delete of a lasso vertex (Ctrl+Z while editing). */
|
|
217
|
-
lassoUndoAction(): void;
|
|
218
|
-
/** Public: redo (Ctrl+Y / Ctrl+Shift+Z while editing). */
|
|
219
|
-
lassoRedoAction(): void;
|
|
220
|
-
/** Public: abandon the in-progress lasso (Esc). */
|
|
221
|
-
cancelLasso(): void;
|
|
222
|
-
/** Public: true while the user is placing lasso vertices (≥1 vertex). */
|
|
223
|
-
isLassoEditing(): boolean;
|
|
224
|
-
/** Public: number of placed lasso vertices (drives the Finish button label/enable). */
|
|
225
|
-
getLassoVertCount(): number;
|
|
226
|
-
/** Vertices ordered by polar angle around their centroid, so the closed curve is
|
|
227
|
-
* a SIMPLE (non-self-intersecting) loop regardless of click order — otherwise
|
|
228
|
-
* connecting points in click order + closing easily produces a bow-tie crossing.
|
|
229
|
-
* Trade-off: deep concavities collapse to their star-shaped hull, which is fine
|
|
230
|
-
* for a "rough loop around a blob". */
|
|
231
|
-
private orderedLassoVerts;
|
|
232
|
-
/** Public: close the curve, densify it, and send it to the backend as the lasso
|
|
233
|
-
* contour. Needs ≥3 vertices (a real area). Then clears the editing state. */
|
|
234
|
-
finishLasso(): void;
|
|
235
|
-
/** Sample a smooth CLOSED Catmull-Rom spline through `pts` → denser polyline.
|
|
236
|
-
* `segs` samples per control-point span. <3 pts → returns a copy unchanged. */
|
|
237
|
-
private sampleClosedSpline;
|
|
238
|
-
applyMask(result: AiMaskResult): void;
|
|
239
|
-
/** Merge one RLE-encoded predicted slice into the scratch volume at sliceIndex.
|
|
240
|
-
* Predicted pixels → current channel; stale current-channel pixels cleared
|
|
241
|
-
* UNLESS they belong to a frozen (committed) region; OTHER channels preserved. */
|
|
242
|
-
private applySliceRle;
|
|
243
|
-
renderOverlay(targetCtx: CanvasRenderingContext2D): void;
|
|
244
|
-
/** A seed marker (small filled dot + ring) for point prompts. */
|
|
245
|
-
private drawSeedMarker;
|
|
246
|
-
/** Render the lasso editing overlay (curve + fill + vertices + hover ✕). */
|
|
247
|
-
private renderLassoOverlay;
|
|
248
|
-
}
|
|
249
|
-
export {};
|
|
1
|
+
/**
|
|
2
|
+
* AiAssistTool — interactive prompt-based segmentation (experimental).
|
|
3
|
+
*
|
|
4
|
+
* The clinician left-clicks foreground / background points (or drags a box /
|
|
5
|
+
* scribbles) on the current slice; a backend model returns a region mask that
|
|
6
|
+
* is written into an INDEPENDENT scratch MaskVolume (`aiAssistMaskVolume`,
|
|
7
|
+
* registered as `maskData.volumes['aiScratch']`) — never the validated layers.
|
|
8
|
+
*
|
|
9
|
+
* Network lives in the app layer: this tool only (a) maps screen → voxel-slice
|
|
10
|
+
* coordinates, (b) accumulates the prompt for the current slice, (c) fires
|
|
11
|
+
* `onPrompt` so the app can call the backend, and (d) applies the returned mask
|
|
12
|
+
* via `applyMask`. The app's `useAiAssist` composable wires (c)→(d).
|
|
13
|
+
*
|
|
14
|
+
* Sandbox: snapshot on enter (`snapshot`), then on exit either `discard`
|
|
15
|
+
* (restore snapshot) or merge is handled by NrrdTools (clone + pushGroup).
|
|
16
|
+
*
|
|
17
|
+
* Coordinate mapping supports all three views (axial/sagittal/coronal); it
|
|
18
|
+
* inverts the per-axis display transform of RenderingUtils.renderSliceToCanvas
|
|
19
|
+
* (only coronal 'y' is vertically flipped). Merge captures painted voxels from
|
|
20
|
+
* any view (the scratch is a full 3D volume).
|
|
21
|
+
*/
|
|
22
|
+
import { BaseTool } from "./BaseTool";
|
|
23
|
+
import type { ToolContext } from "./BaseTool";
|
|
24
|
+
import { MaskVolume } from "../core";
|
|
25
|
+
import type { SliceRenderHostDeps } from "./ToolHost";
|
|
26
|
+
/** Scratch volume key in maskData.volumes — kept OUT of image.layers so
|
|
27
|
+
* compositeAllLayers ignores it (we render it ourselves in start()). */
|
|
28
|
+
export declare const AI_SCRATCH_LAYER = "aiScratch";
|
|
29
|
+
export type AiPromptTool = "point" | "box" | "scribble" | "lasso";
|
|
30
|
+
export interface AiPromptPoint {
|
|
31
|
+
x: number;
|
|
32
|
+
y: number;
|
|
33
|
+
z?: number;
|
|
34
|
+
label: number;
|
|
35
|
+
}
|
|
36
|
+
export interface AiPromptPayload {
|
|
37
|
+
axis: "x" | "y" | "z";
|
|
38
|
+
sliceIndex: number;
|
|
39
|
+
width: number;
|
|
40
|
+
height: number;
|
|
41
|
+
points: AiPromptPoint[];
|
|
42
|
+
box?: {
|
|
43
|
+
x0: number;
|
|
44
|
+
y0: number;
|
|
45
|
+
x1: number;
|
|
46
|
+
y1: number;
|
|
47
|
+
label: number;
|
|
48
|
+
};
|
|
49
|
+
scribble?: AiPromptPoint[];
|
|
50
|
+
scribbleRadius?: number;
|
|
51
|
+
/** Closed-contour lasso: ordered contour points (implicitly closed — the
|
|
52
|
+
* backend connects the last point back to the first). One contour per gesture. */
|
|
53
|
+
lasso?: AiPromptPoint[];
|
|
54
|
+
}
|
|
55
|
+
export interface AiMaskResult {
|
|
56
|
+
axis: "x" | "y" | "z";
|
|
57
|
+
sliceIndex: number;
|
|
58
|
+
width: number;
|
|
59
|
+
height: number;
|
|
60
|
+
rle: number[];
|
|
61
|
+
/** 3D result (engine B / nnInteractive): inclusive [lo,hi] slice span + one RLE per slice. */
|
|
62
|
+
sliceRange?: [number, number];
|
|
63
|
+
slices?: number[][];
|
|
64
|
+
}
|
|
65
|
+
type AiAssistHostDeps = Pick<SliceRenderHostDeps, "renderSliceToCanvas" | "getOrCreateSliceBuffer">;
|
|
66
|
+
export declare class AiAssistTool extends BaseTool {
|
|
67
|
+
private host;
|
|
68
|
+
/** Independent scratch volume (also registered at maskData.volumes['aiScratch']). */
|
|
69
|
+
private scratchVol;
|
|
70
|
+
/** Snapshot of the scratch buffer taken on enter (for discard). */
|
|
71
|
+
private snapshotData;
|
|
72
|
+
/** Frozen regions ("New region" commits here). Pixels recorded here survive a
|
|
73
|
+
* later re-prediction — even on the SAME channel — so multiple separate regions
|
|
74
|
+
* can be drawn without the newest prediction wiping the previous ones. Null =
|
|
75
|
+
* nothing frozen yet (applySliceRle then behaves as a single live region). */
|
|
76
|
+
private committedVol;
|
|
77
|
+
private promptTool;
|
|
78
|
+
private polarity;
|
|
79
|
+
/** The label value (1-255) the AI currently paints into = the active Segmentation.
|
|
80
|
+
* Each Segmentation is a label value in the single-channel scratch volume; its
|
|
81
|
+
* colour lives in the volume's colorMap (set via setSegmentColor). */
|
|
82
|
+
private activeLabel;
|
|
83
|
+
/** Scribble brush radius (px), user-adjustable via slider. */
|
|
84
|
+
private scribbleSize;
|
|
85
|
+
/** Accumulated prompts for the CURRENT slice; reset on slice/axis change. */
|
|
86
|
+
private points;
|
|
87
|
+
private scribble;
|
|
88
|
+
/** Lasso contour sent to the backend (densified along the curve at finish). */
|
|
89
|
+
private lasso;
|
|
90
|
+
private box;
|
|
91
|
+
private activeSlice;
|
|
92
|
+
/** Placed lasso vertices (voxel + screen + polarity). Empty = not editing. */
|
|
93
|
+
private lassoVerts;
|
|
94
|
+
/** Undo / redo snapshot stacks of the vertex list (for Ctrl+Z / Ctrl+Y). */
|
|
95
|
+
private lassoUndo;
|
|
96
|
+
private lassoRedo;
|
|
97
|
+
/** Index of the vertex currently hovered (shows a red ✕; click removes it). −1 = none. */
|
|
98
|
+
private lassoHoverIdx;
|
|
99
|
+
/** Screen-pixel radius for hit-testing a hovered vertex. */
|
|
100
|
+
private static readonly LASSO_HIT_R;
|
|
101
|
+
/** Double-click detection (a dbl-click finishes the lasso). */
|
|
102
|
+
private lastLassoDownTime;
|
|
103
|
+
private lastLassoDownPos;
|
|
104
|
+
private dragging;
|
|
105
|
+
private dragStart;
|
|
106
|
+
private dragScreenStart;
|
|
107
|
+
private dragScreen;
|
|
108
|
+
private screenScribble;
|
|
109
|
+
private hoverScreen;
|
|
110
|
+
/** Hide the point seed markers once a prediction has painted (only the mask
|
|
111
|
+
* should remain). A new point click re-shows them until its mask returns. */
|
|
112
|
+
private hidePointMarkers;
|
|
113
|
+
/** Fired when a prompt gesture completes — app calls backend, then applyMask(). */
|
|
114
|
+
onPrompt: ((payload: AiPromptPayload) => void) | null;
|
|
115
|
+
/** Fired whenever the lasso vertex set changes (add/delete/undo/redo/finish/cancel),
|
|
116
|
+
* so the panel can reactively show the Finish button + vertex count. */
|
|
117
|
+
onLassoChange: ((count: number, editing: boolean) => void) | null;
|
|
118
|
+
constructor(ctx: ToolContext, host: AiAssistHostDeps);
|
|
119
|
+
setPromptTool(tool: AiPromptTool): void;
|
|
120
|
+
setPolarity(label: number): void;
|
|
121
|
+
setScribbleSize(size: number): void;
|
|
122
|
+
/** Select the active Segmentation by its label value (1-255). Switching starts a
|
|
123
|
+
* fresh prompt set — otherwise accumulated prompts would be re-predicted and
|
|
124
|
+
* repainted into the new label, recolouring the previous segmentation's region. */
|
|
125
|
+
setActiveSegment(label: number): void;
|
|
126
|
+
getActiveLabel(): number;
|
|
127
|
+
/** Set a Segmentation's colour (its label's entry in the scratch volume colorMap).
|
|
128
|
+
* The 2D overlay repaints next frame (copper3d's render loop re-reads the map). */
|
|
129
|
+
setSegmentColor(label: number, color: {
|
|
130
|
+
r: number;
|
|
131
|
+
g: number;
|
|
132
|
+
b: number;
|
|
133
|
+
a: number;
|
|
134
|
+
}): void;
|
|
135
|
+
/** "New segmentation": freeze the current regions (so they persist) and switch to
|
|
136
|
+
* a fresh label, exactly like the old "New region" but targeting a new label. */
|
|
137
|
+
newSegment(label: number): void;
|
|
138
|
+
/** Delete a Segmentation: erase every voxel painted with its label from BOTH the
|
|
139
|
+
* live scratch and the frozen (committed) volume, so the region disappears from
|
|
140
|
+
* the view (otherwise orphaned label voxels would render with the wrong colour).
|
|
141
|
+
* Goes via setRawData so the volume's version counter bumps (overlay repaints). */
|
|
142
|
+
clearSegment(label: number): void;
|
|
143
|
+
getScratchVolume(): MaskVolume | null;
|
|
144
|
+
/** Serialize the scratch volume as per-z-slice RLE (only NON-empty slices),
|
|
145
|
+
* for persisting to ai_generated_nii_LPS on the backend. Binary (any channel →
|
|
146
|
+
* 1); RLE is alternating run lengths starting with a 0-run — the exact format
|
|
147
|
+
* the backend's rle_decode expects. Uses getSliceUint8 (the same path the
|
|
148
|
+
* clinician layer's /api/mask/replace uses) so orientation matches. */
|
|
149
|
+
getScratchSlices(): {
|
|
150
|
+
axis: "z";
|
|
151
|
+
width: number;
|
|
152
|
+
height: number;
|
|
153
|
+
slices: {
|
|
154
|
+
sliceIndex: number;
|
|
155
|
+
rle: number[];
|
|
156
|
+
}[];
|
|
157
|
+
} | null;
|
|
158
|
+
/** Per-SEGMENTATION serialization for the 3D build: one binary RLE per non-empty
|
|
159
|
+
* z-slice PER label (no binarize-merge), so the backend writes a multi-label
|
|
160
|
+
* NIfTI and colours the GLB per segmentation. Includes both live and frozen
|
|
161
|
+
* regions (both live in scratchVol). */
|
|
162
|
+
getScratchSegments(): {
|
|
163
|
+
axis: "z";
|
|
164
|
+
width: number;
|
|
165
|
+
height: number;
|
|
166
|
+
segments: {
|
|
167
|
+
label: number;
|
|
168
|
+
slices: {
|
|
169
|
+
sliceIndex: number;
|
|
170
|
+
rle: number[];
|
|
171
|
+
}[];
|
|
172
|
+
}[];
|
|
173
|
+
} | null;
|
|
174
|
+
/** Create (or reuse) the scratch volume sized to the layer grid and register
|
|
175
|
+
* it under maskData.volumes['aiScratch']. Snapshots the empty buffer. */
|
|
176
|
+
enter(): void;
|
|
177
|
+
/** Remove the scratch volume from the registry and drop references. */
|
|
178
|
+
exit(): void;
|
|
179
|
+
/** Discard everything painted since enter() — restore the snapshot. */
|
|
180
|
+
discard(): void;
|
|
181
|
+
/** "New region": freeze every voxel painted so far so it survives later
|
|
182
|
+
* re-predictions (even on the same channel), then start a fresh prompt set.
|
|
183
|
+
* This is what makes drawing multiple separate regions actually work — without
|
|
184
|
+
* it the next prediction's same-channel cleanup erases the previous region. */
|
|
185
|
+
commitRegion(): void;
|
|
186
|
+
/** Clear the in-progress prompt set (e.g. slice/axis change). Does NOT freeze —
|
|
187
|
+
* use commitRegion() for the "New region" action. */
|
|
188
|
+
resetPrompts(): void;
|
|
189
|
+
/** Drop the in-progress lasso vertices + undo/redo history (does not touch a
|
|
190
|
+
* prediction already painted from a finished lasso). */
|
|
191
|
+
private clearLassoEditing;
|
|
192
|
+
/** Tell the app layer the lasso vertex set changed (drives the Finish button). */
|
|
193
|
+
private notifyLasso;
|
|
194
|
+
/** Voxel-slice (width,height) for the current axis. */
|
|
195
|
+
private sliceDims;
|
|
196
|
+
/** Screen offset → voxel-slice (vx,vy) for the current axis. */
|
|
197
|
+
private toVoxel;
|
|
198
|
+
/** Voxel-slice (vx,vy) → screen offset (px). Exact inverse of toVoxel, so
|
|
199
|
+
* markers / lasso curves drawn from voxel coords track pan AND zoom each frame
|
|
200
|
+
* (the freehand previews store screen px directly; persistent overlays don't). */
|
|
201
|
+
private voxelToScreen;
|
|
202
|
+
onPointerDown(e: MouseEvent): void;
|
|
203
|
+
/** Lasso click: double-click finishes; click on a vertex deletes it; otherwise
|
|
204
|
+
* add a vertex. Nothing is sent to the backend until finishLasso(). */
|
|
205
|
+
private onLassoPointerDown;
|
|
206
|
+
onPointerMove(e: MouseEvent): void;
|
|
207
|
+
onPointerUp(_e: MouseEvent): void;
|
|
208
|
+
/** Reset the accumulated prompt set when the user scrubs to a new slice. */
|
|
209
|
+
private syncSlice;
|
|
210
|
+
private emit;
|
|
211
|
+
/** Index of the lasso vertex under (sx,sy) within the hit radius, else −1.
|
|
212
|
+
* Uses live voxel→screen so it tracks pan/zoom. Topmost (latest) wins. */
|
|
213
|
+
private lassoVertAt;
|
|
214
|
+
/** Snapshot the vertex list for undo (clears redo). */
|
|
215
|
+
private pushLassoUndo;
|
|
216
|
+
/** Public: undo the last add/delete of a lasso vertex (Ctrl+Z while editing). */
|
|
217
|
+
lassoUndoAction(): void;
|
|
218
|
+
/** Public: redo (Ctrl+Y / Ctrl+Shift+Z while editing). */
|
|
219
|
+
lassoRedoAction(): void;
|
|
220
|
+
/** Public: abandon the in-progress lasso (Esc). */
|
|
221
|
+
cancelLasso(): void;
|
|
222
|
+
/** Public: true while the user is placing lasso vertices (≥1 vertex). */
|
|
223
|
+
isLassoEditing(): boolean;
|
|
224
|
+
/** Public: number of placed lasso vertices (drives the Finish button label/enable). */
|
|
225
|
+
getLassoVertCount(): number;
|
|
226
|
+
/** Vertices ordered by polar angle around their centroid, so the closed curve is
|
|
227
|
+
* a SIMPLE (non-self-intersecting) loop regardless of click order — otherwise
|
|
228
|
+
* connecting points in click order + closing easily produces a bow-tie crossing.
|
|
229
|
+
* Trade-off: deep concavities collapse to their star-shaped hull, which is fine
|
|
230
|
+
* for a "rough loop around a blob". */
|
|
231
|
+
private orderedLassoVerts;
|
|
232
|
+
/** Public: close the curve, densify it, and send it to the backend as the lasso
|
|
233
|
+
* contour. Needs ≥3 vertices (a real area). Then clears the editing state. */
|
|
234
|
+
finishLasso(): void;
|
|
235
|
+
/** Sample a smooth CLOSED Catmull-Rom spline through `pts` → denser polyline.
|
|
236
|
+
* `segs` samples per control-point span. <3 pts → returns a copy unchanged. */
|
|
237
|
+
private sampleClosedSpline;
|
|
238
|
+
applyMask(result: AiMaskResult): void;
|
|
239
|
+
/** Merge one RLE-encoded predicted slice into the scratch volume at sliceIndex.
|
|
240
|
+
* Predicted pixels → current channel; stale current-channel pixels cleared
|
|
241
|
+
* UNLESS they belong to a frozen (committed) region; OTHER channels preserved. */
|
|
242
|
+
private applySliceRle;
|
|
243
|
+
renderOverlay(targetCtx: CanvasRenderingContext2D): void;
|
|
244
|
+
/** A seed marker (small filled dot + ring) for point prompts. */
|
|
245
|
+
private drawSeedMarker;
|
|
246
|
+
/** Render the lasso editing overlay (curve + fill + vertices + hover ✕). */
|
|
247
|
+
private renderLassoOverlay;
|
|
248
|
+
}
|
|
249
|
+
export {};
|