copper3d 3.0.2 → 3.1.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.
Files changed (106) hide show
  1. package/README.md +183 -1028
  2. package/dist/Utils/segmentation/CanvasState.d.ts +31 -0
  3. package/dist/Utils/segmentation/CanvasState.js +168 -0
  4. package/dist/Utils/segmentation/CanvasState.js.map +1 -0
  5. package/dist/Utils/segmentation/DragOperator.d.ts +1 -1
  6. package/dist/Utils/segmentation/DragOperator.js +2 -4
  7. package/dist/Utils/segmentation/DragOperator.js.map +1 -1
  8. package/dist/Utils/segmentation/DrawToolCore.d.ts +49 -27
  9. package/dist/Utils/segmentation/DrawToolCore.js +275 -344
  10. package/dist/Utils/segmentation/DrawToolCore.js.map +1 -1
  11. package/dist/Utils/segmentation/NrrdTools.d.ts +92 -467
  12. package/dist/Utils/segmentation/NrrdTools.js +499 -1341
  13. package/dist/Utils/segmentation/NrrdTools.js.map +1 -1
  14. package/dist/Utils/segmentation/RenderingUtils.d.ts +73 -0
  15. package/dist/Utils/segmentation/RenderingUtils.js +186 -0
  16. package/dist/Utils/segmentation/RenderingUtils.js.map +1 -0
  17. package/dist/Utils/segmentation/core/MaskVolume.d.ts +1 -1
  18. package/dist/Utils/segmentation/core/MaskVolume.js +1 -1
  19. package/dist/Utils/segmentation/core/index.d.ts +1 -1
  20. package/dist/Utils/segmentation/core/index.js.map +1 -1
  21. package/dist/Utils/segmentation/core/types.d.ts +386 -0
  22. package/dist/Utils/segmentation/core/types.js +1 -0
  23. package/dist/Utils/segmentation/core/types.js.map +1 -1
  24. package/dist/Utils/segmentation/coreTools/GuiState.d.ts +1 -1
  25. package/dist/Utils/segmentation/coreTools/GuiState.js +1 -0
  26. package/dist/Utils/segmentation/coreTools/GuiState.js.map +1 -1
  27. package/dist/Utils/segmentation/coreTools/NrrdState.d.ts +1 -1
  28. package/dist/Utils/segmentation/coreTools/divControlTools.d.ts +1 -1
  29. package/dist/Utils/segmentation/coreTools/gui.d.ts +1 -1
  30. package/dist/Utils/segmentation/tools/BaseTool.d.ts +1 -1
  31. package/dist/Utils/segmentation/tools/ContrastTool.d.ts +3 -6
  32. package/dist/Utils/segmentation/tools/ContrastTool.js.map +1 -1
  33. package/dist/Utils/segmentation/tools/CrosshairTool.d.ts +11 -1
  34. package/dist/Utils/segmentation/tools/CrosshairTool.js +25 -0
  35. package/dist/Utils/segmentation/tools/CrosshairTool.js.map +1 -1
  36. package/dist/Utils/segmentation/tools/DataLoader.d.ts +33 -0
  37. package/dist/Utils/segmentation/tools/DataLoader.js +159 -0
  38. package/dist/Utils/segmentation/tools/DataLoader.js.map +1 -0
  39. package/dist/Utils/segmentation/tools/DragSliceTool.d.ts +3 -12
  40. package/dist/Utils/segmentation/tools/DragSliceTool.js.map +1 -1
  41. package/dist/Utils/segmentation/tools/DrawingTool.d.ts +18 -26
  42. package/dist/Utils/segmentation/tools/DrawingTool.js +48 -0
  43. package/dist/Utils/segmentation/tools/DrawingTool.js.map +1 -1
  44. package/dist/Utils/segmentation/tools/ImageStoreHelper.d.ts +2 -5
  45. package/dist/Utils/segmentation/tools/ImageStoreHelper.js.map +1 -1
  46. package/dist/Utils/segmentation/tools/LayerChannelManager.d.ts +56 -0
  47. package/dist/Utils/segmentation/tools/LayerChannelManager.js +188 -0
  48. package/dist/Utils/segmentation/tools/LayerChannelManager.js.map +1 -0
  49. package/dist/Utils/segmentation/tools/PanTool.d.ts +2 -8
  50. package/dist/Utils/segmentation/tools/PanTool.js.map +1 -1
  51. package/dist/Utils/segmentation/tools/SliceRenderPipeline.d.ts +80 -0
  52. package/dist/Utils/segmentation/tools/SliceRenderPipeline.js +355 -0
  53. package/dist/Utils/segmentation/tools/SliceRenderPipeline.js.map +1 -0
  54. package/dist/Utils/segmentation/tools/SphereTool.d.ts +25 -19
  55. package/dist/Utils/segmentation/tools/SphereTool.js +61 -7
  56. package/dist/Utils/segmentation/tools/SphereTool.js.map +1 -1
  57. package/dist/Utils/segmentation/tools/ToolHost.d.ts +74 -0
  58. package/dist/Utils/segmentation/tools/ToolHost.js +10 -0
  59. package/dist/Utils/segmentation/tools/ToolHost.js.map +1 -0
  60. package/dist/Utils/segmentation/tools/ZoomTool.d.ts +2 -6
  61. package/dist/Utils/segmentation/tools/ZoomTool.js.map +1 -1
  62. package/dist/Utils/segmentation/tools/index.d.ts +5 -7
  63. package/dist/Utils/segmentation/tools/index.js +6 -0
  64. package/dist/Utils/segmentation/tools/index.js.map +1 -1
  65. package/dist/Utils/workers/reformatSaveDataWorker.d.ts +1 -1
  66. package/dist/bundle.esm.js +2146 -2359
  67. package/dist/bundle.umd.js +2146 -2359
  68. package/dist/index.d.ts +3 -3
  69. package/dist/index.js +1 -1
  70. package/dist/types/Utils/segmentation/CanvasState.d.ts +31 -0
  71. package/dist/types/Utils/segmentation/DragOperator.d.ts +1 -1
  72. package/dist/types/Utils/segmentation/DrawToolCore.d.ts +49 -27
  73. package/dist/types/Utils/segmentation/NrrdTools.d.ts +92 -467
  74. package/dist/types/Utils/segmentation/RenderingUtils.d.ts +73 -0
  75. package/dist/types/Utils/segmentation/core/MaskVolume.d.ts +1 -1
  76. package/dist/types/Utils/segmentation/core/index.d.ts +1 -1
  77. package/dist/types/Utils/segmentation/core/types.d.ts +386 -0
  78. package/dist/types/Utils/segmentation/coreTools/GuiState.d.ts +1 -1
  79. package/dist/types/Utils/segmentation/coreTools/NrrdState.d.ts +1 -1
  80. package/dist/types/Utils/segmentation/coreTools/divControlTools.d.ts +1 -1
  81. package/dist/types/Utils/segmentation/coreTools/gui.d.ts +1 -1
  82. package/dist/types/Utils/segmentation/tools/BaseTool.d.ts +1 -1
  83. package/dist/types/Utils/segmentation/tools/ContrastTool.d.ts +3 -6
  84. package/dist/types/Utils/segmentation/tools/CrosshairTool.d.ts +11 -1
  85. package/dist/types/Utils/segmentation/tools/DataLoader.d.ts +33 -0
  86. package/dist/types/Utils/segmentation/tools/DragSliceTool.d.ts +3 -12
  87. package/dist/types/Utils/segmentation/tools/DrawingTool.d.ts +18 -26
  88. package/dist/types/Utils/segmentation/tools/ImageStoreHelper.d.ts +2 -5
  89. package/dist/types/Utils/segmentation/tools/LayerChannelManager.d.ts +56 -0
  90. package/dist/types/Utils/segmentation/tools/PanTool.d.ts +2 -8
  91. package/dist/types/Utils/segmentation/tools/SliceRenderPipeline.d.ts +80 -0
  92. package/dist/types/Utils/segmentation/tools/SphereTool.d.ts +25 -19
  93. package/dist/types/Utils/segmentation/tools/ToolHost.d.ts +74 -0
  94. package/dist/types/Utils/segmentation/tools/ZoomTool.d.ts +2 -6
  95. package/dist/types/Utils/segmentation/tools/index.d.ts +5 -7
  96. package/dist/types/Utils/workers/reformatSaveDataWorker.d.ts +1 -1
  97. package/dist/types/index.d.ts +3 -3
  98. package/package.json +1 -1
  99. package/dist/Utils/segmentation/CommToolsData.d.ts +0 -192
  100. package/dist/Utils/segmentation/CommToolsData.js +0 -474
  101. package/dist/Utils/segmentation/CommToolsData.js.map +0 -1
  102. package/dist/Utils/segmentation/coreTools/coreType.d.ts +0 -389
  103. package/dist/Utils/segmentation/coreTools/coreType.js +0 -3
  104. package/dist/Utils/segmentation/coreTools/coreType.js.map +0 -1
  105. package/dist/types/Utils/segmentation/CommToolsData.d.ts +0 -192
  106. package/dist/types/Utils/segmentation/coreTools/coreType.d.ts +0 -389
@@ -1,13 +1,21 @@
1
1
  import { nrrdSliceType, storeExportPaintImageType, loadingBarType } from "../../types/types";
2
2
  import { GUI } from "dat.gui";
3
- import { IMaskData, IDragOpts, IKeyBoardSettings, ToolMode, IGuiMeta } from "./coreTools/coreType";
3
+ import { IMaskData, IDragOpts, IKeyBoardSettings, ToolMode, IGuiMeta } from "./core/types";
4
4
  import { DragOperator } from "./DragOperator";
5
- import { DrawToolCore } from "./DrawToolCore";
6
5
  import type { ChannelValue, RGBAColor, ChannelColorMap } from "./core";
7
6
  import type { SphereType } from "./tools/SphereTool";
8
7
  /**
9
8
  * Core NRRD annotation tool for medical image segmentation.
10
9
  *
10
+ * Acts as a **Facade** that delegates to composed modules:
11
+ * - {@link CanvasState} — pure state container
12
+ * - {@link DrawToolCore} — tool orchestration, event routing
13
+ * - {@link LayerChannelManager} — layer/channel/sphere-type management
14
+ * - {@link SliceRenderPipeline} — slice rendering, canvas flip, mask reload
15
+ * - {@link DataLoader} — NRRD slice loading, legacy mask loading, NIfTI loading
16
+ *
17
+ * No longer extends DrawToolCore — uses composition instead.
18
+ *
11
19
  * @example
12
20
  * ```ts
13
21
  * // Default 3 layers: layer1, layer2, layer3
@@ -17,38 +25,41 @@ import type { SphereType } from "./tools/SphereTool";
17
25
  * const tools = new NrrdTools(container, { layers: ["layer1", "layer2"] });
18
26
  * ```
19
27
  */
20
- export declare class NrrdTools extends DrawToolCore {
28
+ export declare class NrrdTools {
21
29
  container: HTMLDivElement;
30
+ /** Shared state container. */
31
+ private state;
32
+ /** Core drawing tool orchestrator. */
33
+ private drawCore;
34
+ /** Drag operator for slice navigation. */
22
35
  dragOperator: DragOperator;
23
- private paintedImage;
24
- private initState;
25
36
  private preTimer;
26
37
  private guiParameterSettings;
27
38
  private _sliceRAFId;
28
39
  private _pendingSliceStep;
29
40
  /** Whether calculator mode is active (not part of gui_states interface) */
30
41
  private _calculatorActive;
42
+ /** Layer/channel management (extracted module) */
43
+ private layerChannelManager;
44
+ /** Slice rendering pipeline (extracted module) */
45
+ private sliceRenderPipeline;
46
+ /** Data loading (extracted module) */
47
+ private dataLoader;
31
48
  /** Stored closure callbacks from gui.ts setupGui() */
32
49
  private guiCallbacks;
33
50
  constructor(container: HTMLDivElement, options?: {
34
51
  layers?: string[];
35
52
  });
36
53
  /**
37
- * core function for drag slices
38
- * @param opts
54
+ * Wire DrawToolCore's overridable methods to NrrdTools implementations.
55
+ * This replaces the old inheritance approach.
39
56
  */
40
- drag(opts?: IDragOpts): void;
41
- /**
42
- * Set the Draw Display Canvas base size
43
- * @param size number
44
- */
45
- setBaseDrawDisplayCanvasesSize(size: number): void;
46
- setDisplaySliceIndexPanel(panel: HTMLDivElement): void;
57
+ private wireDrawCoreMethods;
47
58
  /**
48
- * Enable the drag function for contrast images window center and window high.
49
- * @param callback
59
+ * A initialise function for nrrd_tools
50
60
  */
51
- enableContrastDragEvents(callback: (step: number, towards: "horizental" | "vertical") => void): void;
61
+ private init;
62
+ private initNrrdToolsModules;
52
63
  /**
53
64
  * Set up GUI for drawing panel
54
65
  * @param gui GUI
@@ -56,407 +67,61 @@ export declare class NrrdTools extends DrawToolCore {
56
67
  setupGUI(gui: GUI): void;
57
68
  /**
58
69
  * Sync guiParameterSettings with current volume metadata.
59
- * Called internally when slices are loaded or switched.
60
70
  */
61
71
  private syncGuiParameterSettings;
62
72
  /**
63
- * Set the active layer and update fillColor/brushColor to match the active channel.
64
- */
65
- setActiveLayer(layerId: string): void;
66
- /**
67
- * Set the active channel (1-8) and update fillColor/brushColor.
68
- */
69
- setActiveChannel(channel: ChannelValue): void;
70
- /**
71
- * Set the active sphere type for the SphereTool.
72
- * Replaces direct mutation of `gui_states.activeSphereType`.
73
- *
74
- * @example
75
- * ```ts
76
- * nrrdTools.setActiveSphereType('nipple');
77
- * ```
78
- */
79
- setActiveSphereType(type: SphereType): void;
80
- /**
81
- * Get the currently active sphere type.
82
- */
83
- getActiveSphereType(): SphereType;
84
- /**
85
- * Set the current tool mode. Handles deactivation of the previous mode
86
- * and activation of the new mode, including all gui.ts side-effects.
87
- *
88
- * Replaces direct mutation of `guiSettings.value.guiState["pencil"]` etc.
89
- * from Vue components.
73
+ * Set the current tool mode.
90
74
  */
91
75
  setMode(mode: ToolMode): void;
92
- /**
93
- * Get the current tool mode based on gui_states flags.
94
- */
95
76
  getMode(): ToolMode;
96
- /**
97
- * Check if calculator mode is active.
98
- */
99
77
  isCalculatorActive(): boolean;
100
- /**
101
- * Set mask overlay opacity.
102
- * @param value Opacity value [0.1, 1]
103
- */
104
78
  setOpacity(value: number): void;
105
- /**
106
- * Get the current mask overlay opacity.
107
- */
108
79
  getOpacity(): number;
109
- /**
110
- * Set brush and eraser size, and trigger cursor update.
111
- * @param size Brush size [5, 50]
112
- */
113
80
  setBrushSize(size: number): void;
114
- /**
115
- * Get the current brush/eraser size.
116
- */
117
81
  getBrushSize(): number;
118
- /**
119
- * Set window high (image contrast) value.
120
- * Call finishWindowAdjustment() when the user finishes dragging.
121
- */
122
82
  setWindowHigh(value: number): void;
123
- /**
124
- * Set window low (image center) value.
125
- * Call finishWindowAdjustment() when the user finishes dragging.
126
- */
127
83
  setWindowLow(value: number): void;
128
- /**
129
- * Finish a window/contrast adjustment (repaint all contrast slices).
130
- */
131
84
  finishWindowAdjustment(): void;
132
- /**
133
- * Adjust contrast by delta, used for drag-based contrast adjustment.
134
- * @param type "windowHigh" or "windowLow"
135
- * @param delta Delta amount to adjust
136
- */
137
85
  adjustContrast(type: "windowHigh" | "windowLow", delta: number): void;
138
- /**
139
- * Get slider metadata for UI configuration.
140
- * @param key Slider key: "globalAlpha", "brushAndEraserSize", "windowHigh", "windowLow"
141
- * @returns IGuiMeta with min, max, step, and current value
142
- */
143
86
  getSliderMeta(key: string): IGuiMeta | null;
144
- /**
145
- * Set the pencil stroke color.
146
- */
147
87
  setPencilColor(hex: string): void;
148
- /**
149
- * Get the current pencil stroke color.
150
- */
151
88
  getPencilColor(): string;
152
- /**
153
- * Execute a named UI action.
154
- * @param action Action name
155
- *
156
- * Renamed from original gui_states methods:
157
- * - "clearActiveSliceMask" (was "clear") — clear annotations on current slice
158
- * - "clearActiveLayerMask" (was "clearAll") — clear annotations on all slices for active layer
159
- */
160
89
  executeAction(action: "undo" | "redo" | "clearActiveSliceMask" | "clearActiveLayerMask" | "resetZoom" | "downloadCurrentMask"): void;
161
- /**
162
- * Sync brush/fill color from the active layer's volume color map.
163
- * Falls back to global CHANNEL_HEX_COLORS if volume not available.
164
- */
165
- private syncBrushColor;
166
- /**
167
- * Get the currently active layer id.
168
- */
169
- getActiveLayer(): string;
170
- /**
171
- * Get the currently active channel value.
172
- */
173
- getActiveChannel(): number;
174
- /**
175
- * Set visibility of a layer and re-render.
176
- */
177
- setLayerVisible(layerId: string, visible: boolean): void;
178
- /**
179
- * Check if a layer is visible.
180
- */
181
- isLayerVisible(layerId: string): boolean;
182
- /**
183
- * Set visibility of a specific channel within a layer and re-render.
184
- */
185
- setChannelVisible(layerId: string, channel: ChannelValue, visible: boolean): void;
186
- /**
187
- * Check if a specific channel within a layer is visible.
188
- */
189
- isChannelVisible(layerId: string, channel: ChannelValue): boolean;
190
- /**
191
- * Get the full layer visibility map.
192
- */
193
- getLayerVisibility(): Record<string, boolean>;
194
- /**
195
- * Get the full channel visibility map.
196
- */
197
- getChannelVisibility(): Record<string, Record<number, boolean>>;
198
- /**
199
- * Check if a specific layer contains any non-zero mask data.
200
- *
201
- * This is useful for determining if a layer has actual annotations
202
- * before saving or exporting to avoid processing empty layers.
203
- *
204
- * @param layerId - The layer to check ('layer1', 'layer2', or 'layer3')
205
- * @returns True if the layer has any non-zero voxel data, false if empty
206
- *
207
- * @example
208
- * ```ts
209
- * if (nrrdTools.hasLayerData('layer1')) {
210
- * await useSaveMasks(caseId, 'layer1');
211
- * }
212
- * ```
213
- */
214
- hasLayerData(layerId: string): boolean;
215
- /**
216
- * Set a custom color for a specific channel in a specific layer.
217
- * Only affects this layer; other layers remain unchanged.
218
- *
219
- * @param layerId Layer to customize (e.g. 'layer1', 'layer2')
220
- * @param channel Channel label (1-8)
221
- * @param color RGBAColor object { r, g, b, a } (each 0-255)
222
- *
223
- * @example
224
- * ```ts
225
- * // Make channel 2 in layer2 orange
226
- * nrrdTools.setChannelColor('layer2', 2, { r: 255, g: 128, b: 0, a: 255 });
227
- * ```
228
- */
229
- setChannelColor(layerId: string, channel: number, color: RGBAColor): void;
230
- /**
231
- * Get the current color for a specific channel in a specific layer.
232
- *
233
- * @param layerId Layer to query
234
- * @param channel Channel label (1-8)
235
- * @returns RGBAColor object (copy, safe to mutate)
236
- */
237
- getChannelColor(layerId: string, channel: number): RGBAColor;
238
- /**
239
- * Get a hex color string for a channel in a layer (e.g. '#ff8000').
240
- */
241
- getChannelHexColor(layerId: string, channel: number): string;
242
- /**
243
- * Get a CSS rgba() color string for a channel in a layer.
244
- */
245
- getChannelCssColor(layerId: string, channel: number): string;
246
- /**
247
- * Batch-set multiple channel colors for a single layer (single re-render).
248
- *
249
- * @param layerId Layer to customize
250
- * @param colorMap Partial map of channel -> RGBAColor
251
- *
252
- * @example
253
- * ```ts
254
- * nrrdTools.setChannelColors('layer2', {
255
- * 2: { r: 255, g: 128, b: 0, a: 255 },
256
- * 3: { r: 100, g: 200, b: 50, a: 255 },
257
- * });
258
- * ```
259
- */
260
- setChannelColors(layerId: string, colorMap: Partial<ChannelColorMap>): void;
261
- /**
262
- * Set the same color for a specific channel across ALL layers (single re-render).
263
- *
264
- * @param channel Channel label (1-8)
265
- * @param color RGBAColor object
266
- */
267
- setAllLayersChannelColor(channel: number, color: RGBAColor): void;
268
- /**
269
- * Reset channel colors to system defaults.
270
- *
271
- * @param layerId Optional. If omitted, resets all layers.
272
- * @param channel Optional. If omitted, resets all channels in the layer(s).
273
- *
274
- * @example
275
- * ```ts
276
- * nrrdTools.resetChannelColors('layer2', 2); // Reset only ch2 in layer2
277
- * nrrdTools.resetChannelColors('layer2'); // Reset all channels in layer2
278
- * nrrdTools.resetChannelColors(); // Reset all layers
279
- * ```
280
- */
281
- resetChannelColors(layerId?: string, channel?: number): void;
282
- /**
283
- * Programmatically trigger an undo operation.
284
- *
285
- * Equivalent to pressing Ctrl+Z. Reverts the most recent drawing stroke
286
- * on the currently active layer and syncs the result to the backend via
287
- * the `getMask` callback.
288
- *
289
- * @example
290
- * ```ts
291
- * undoBtn.addEventListener('click', () => nrrdTools.undo());
292
- * ```
293
- */
294
90
  undo(): void;
295
- /**
296
- * Programmatically trigger a redo operation.
297
- *
298
- * Equivalent to pressing Ctrl+Y. Re-applies the most recently undone
299
- * drawing stroke on the currently active layer and syncs the result to
300
- * the backend via the `getMask` callback.
301
- *
302
- * @example
303
- * ```ts
304
- * redoBtn.addEventListener('click', () => nrrdTools.redo());
305
- * ```
306
- */
307
91
  redo(): void;
308
- /**
309
- * Enter keyboard-configuration mode.
310
- *
311
- * While active, every keydown/keyup handler in DrawToolCore and DragOperator
312
- * is suppressed so the user can press arbitrary keys in the settings dialog
313
- * without accidentally triggering drawing, undo, or contrast shortcuts.
314
- *
315
- * Always pair with {@link exitKeyboardConfig} when the dialog closes.
316
- *
317
- * @example
318
- * ```ts
319
- * dialog.addEventListener('open', () => nrrdTools.enterKeyboardConfig());
320
- * ```
321
- */
322
92
  enterKeyboardConfig(): void;
323
- /**
324
- * Exit keyboard-configuration mode and resume normal shortcut handling.
325
- *
326
- * @example
327
- * ```ts
328
- * dialog.addEventListener('close', () => nrrdTools.exitKeyboardConfig());
329
- * ```
330
- */
331
93
  exitKeyboardConfig(): void;
332
- /**
333
- * Enable or disable the contrast window/level shortcut (Ctrl/Meta key).
334
- *
335
- * When disabled:
336
- * - Holding Ctrl no longer enters contrast mode
337
- * - If contrast mode is currently active it is immediately exited
338
- * - All other Ctrl-based shortcuts (Ctrl+Z undo, Ctrl+Y redo) are
339
- * unaffected because they are checked in the keydown handler before
340
- * the contrast guard runs
341
- *
342
- * @param enabled - Pass `false` to disable, `true` to re-enable.
343
- *
344
- * @example
345
- * ```ts
346
- * // Disable contrast when sphere tool is active
347
- * nrrdTools.setContrastShortcutEnabled(false);
348
- *
349
- * // Re-enable when returning to draw mode
350
- * nrrdTools.setContrastShortcutEnabled(true);
351
- * ```
352
- */
353
94
  setContrastShortcutEnabled(enabled: boolean): void;
354
- /**
355
- * Returns whether the contrast shortcut is currently enabled.
356
- */
357
95
  isContrastShortcutEnabled(): boolean;
358
- /**
359
- * Update keyboard shortcut bindings.
360
- *
361
- * Synchronises both the internal class field (read by every keydown handler)
362
- * and the EventRouter's internal copy (used for modifier-key mode tracking)
363
- * so the two never drift apart. If `mouseWheel` is changed the wheel event
364
- * listener is automatically re-bound via {@link updateMouseWheelEvent}.
365
- *
366
- * Only the fields you supply are updated; omitted fields keep their
367
- * current values.
368
- *
369
- * @param settings - Partial keyboard settings to override.
370
- *
371
- * @example
372
- * ```ts
373
- * nrrdTools.setKeyboardSettings({
374
- * undo: 'z',
375
- * redo: 'y',
376
- * crosshair: 'c',
377
- * mouseWheel: 'Scroll:Slice',
378
- * });
379
- * ```
380
- */
381
96
  setKeyboardSettings(settings: Partial<IKeyBoardSettings>): void;
382
- /**
383
- * Get a snapshot of the current keyboard shortcut bindings.
384
- *
385
- * Returns a shallow copy so callers cannot accidentally mutate internal
386
- * state. To update settings use {@link setKeyboardSettings} instead.
387
- *
388
- * @returns Current keyboard settings.
389
- *
390
- * @example
391
- * ```ts
392
- * const { undo, redo } = nrrdTools.getKeyboardSettings();
393
- * console.log(`Undo: Ctrl+${undo}, Redo: Ctrl+${redo}`);
394
- * ```
395
- */
396
97
  getKeyboardSettings(): IKeyBoardSettings;
98
+ drag(opts?: IDragOpts): void;
397
99
  /**
398
- * A initialise function for nrrd_tools
399
- */
400
- private init;
401
- /**
402
- *
403
- * entry function
404
- * * {
405
- * x:slice,
406
- * y:slice,
407
- * z:slice
408
- * }
409
- *
410
- * @param allSlices - all nrrd contrast slices
411
-
412
- */
413
- setAllSlices(allSlices: Array<nrrdSliceType>): void;
414
- private loadingMaskByLayer;
415
- setMasksData(masksData: storeExportPaintImageType, loadingBar?: loadingBarType): void;
416
- /**
417
- * Load raw voxel data into MaskVolume layers.
418
- *
419
- * Expects pre-extracted voxel bytes (e.g. from useNiftiVoxelData).
420
- *
421
- * @param layerVoxels Map of layer ID to raw voxel Uint8Array
422
- * Keys should be 'layer1', 'layer2', 'layer3'
423
- * @param loadingBar Optional loading bar UI
100
+ * Core drawing entry point.
424
101
  */
425
- setMasksFromNIfTI(layerVoxels: Map<string, Uint8Array>, loadingBar?: loadingBarType): void;
426
- private setShowInMainArea;
427
- getCurrentImageDimension(): number[];
428
- getVoxelSpacing(): number[];
429
- getSpaceOrigin(): number[];
430
- getMaskData(): IMaskData;
102
+ draw(opts?: any): void;
431
103
  /**
432
- * Programmatically place a calculator sphere at the given position.
433
- *
434
- * Replicates the full mouse-down → mouse-up flow (handleSphereClick + pointerup)
435
- * so that backend-supplied sphere data is stored identically to a manual click.
436
- *
437
- * @param x - X coordinate in unscaled (original) image space
438
- * @param y - Y coordinate in unscaled (original) image space
439
- * @param sliceIndex - Target slice index (z-axis)
440
- * @param cal_position - Sphere type to place
104
+ * Set the Draw Display Canvas base size
441
105
  */
442
- setCalculateDistanceSphere(x: number, y: number, sliceIndex: number, cal_position: "tumour" | "skin" | "nipple" | "ribcage"): void;
106
+ setBaseDrawDisplayCanvasesSize(size: number): void;
107
+ setDisplaySliceIndexPanel(panel: HTMLDivElement): void;
108
+ enableContrastDragEvents(callback: (step: number, towards: "horizental" | "vertical") => void): void;
109
+ setEraserUrls(urls: string[]): void;
110
+ setPencilIconUrls(urls: string[]): void;
443
111
  /**
444
112
  * Switch all contrast slices' orientation
445
- * @param {string} aixs:"x" | "y" | "z"
446
- * */
113
+ */
447
114
  setSliceOrientation(axisTo: "x" | "y" | "z"): void;
448
115
  addSkip(index: number): void;
449
116
  removeSkip(index: number): void;
450
- /**
451
- * Reset the entire NrrdTools instance comprehensively.
452
- * This clears ALL data across ALL layers globally, resets the Canvas visuals,
453
- * undo/redo history, volume models, index parameters, and sphere overlays.
454
- * Primarily used when switching cases/datasets or when a completely fresh state is needed.
455
- * It is heavier than `clearActiveLayer` or `clearActiveSlice`.
456
- */
457
- reset(): void;
458
117
  setSliceMoving(step: number): void;
459
118
  setMainAreaSize(factor: number): void;
119
+ switchAllSlicesArrayData(allSlices: Array<nrrdSliceType>): void;
120
+ appendLoadingbar(loadingbar: HTMLDivElement): void;
121
+ getCurrentImageDimension(): number[];
122
+ getVoxelSpacing(): number[];
123
+ getSpaceOrigin(): number[];
124
+ getMaskData(): IMaskData;
460
125
  getContainer(): HTMLElement;
461
126
  getDrawingCanvas(): HTMLCanvasElement;
462
127
  getNrrdToolsSettings(): import("./coreTools/NrrdState").NrrdState;
@@ -467,109 +132,69 @@ export declare class NrrdTools extends DrawToolCore {
467
132
  };
468
133
  getCurrentSliceIndex(): number;
469
134
  getIsShowContrastState(): boolean;
470
- /**
471
- * Give a delay time to finish the last drawing before upcoming interrupt opreations.
472
- * Give a delay time number (ms) to disable the draw function,
473
- * After your interrupt opeartion, you should enable the draw fucntion.
474
- * @param target number
475
- */
476
- setIsDrawFalse(target: number): void;
477
- private setDisplaySlicesBaseOnAxis;
478
- private loadDisplaySlicesArray;
479
- switchAllSlicesArrayData(allSlices: Array<nrrdSliceType>): void;
480
- private resetDisplaySlicesStatus;
481
- private setupConfigs;
482
- private setMainPreSlice;
483
- private setOriginCanvasAndPre;
484
- private afterLoadSlice;
485
- private updateMaxIndex;
486
- /**
487
- * Update the original canvas size, allow set to threejs load one (pixel distance not the mm).
488
- * Then update the changedWidth and changedHeight based on the sizeFactor.
489
- */
135
+ setActiveLayer(layerId: string): void;
136
+ getActiveLayer(): string;
137
+ setActiveChannel(channel: ChannelValue): void;
138
+ getActiveChannel(): number;
139
+ setActiveSphereType(type: SphereType): void;
140
+ getActiveSphereType(): SphereType;
141
+ setLayerVisible(layerId: string, visible: boolean): void;
142
+ isLayerVisible(layerId: string): boolean;
143
+ setChannelVisible(layerId: string, channel: ChannelValue, visible: boolean): void;
144
+ isChannelVisible(layerId: string, channel: ChannelValue): boolean;
145
+ getLayerVisibility(): Record<string, boolean>;
146
+ getChannelVisibility(): Record<string, Record<number, boolean>>;
147
+ hasLayerData(layerId: string): boolean;
148
+ setChannelColor(layerId: string, channel: number, color: RGBAColor): void;
149
+ getChannelColor(layerId: string, channel: number): RGBAColor;
150
+ getChannelHexColor(layerId: string, channel: number): string;
151
+ getChannelCssColor(layerId: string, channel: number): string;
152
+ setChannelColors(layerId: string, colorMap: Partial<ChannelColorMap>): void;
153
+ setAllLayersChannelColor(channel: number, color: RGBAColor): void;
154
+ resetChannelColors(layerId?: string, channel?: number): void;
155
+ setLayerOpacity(layerId: string, opacity: number): void;
156
+ getLayerOpacity(layerId: string): number;
157
+ getLayerOpacityMap(): Record<string, number>;
490
158
  updateOriginAndChangedWH(): void;
491
- /**
492
- * Keep all contrast slice index to same.
493
- * Synchronize the slice indexes of all the contrasts so that they are consistent with the main slice's index.
494
- */
495
159
  setSyncsliceNum(): void;
496
- appendLoadingbar(loadingbar: HTMLDivElement): void;
497
- /**
498
- * Clear all annotations on the currently active layer across its entire 3D volume.
499
- * This resets all voxels globally for the active layer's `MaskVolume` (depth, width, height)
500
- * and triggers the `onClearLayerVolume` event to sync the wiped volume to the backend.
501
- * It also clears the undo/redo stack for the active layer ONLY.
502
- * Other background layers are not impacted by this operation.
503
- */
504
- clearActiveLayer(): void;
505
- /**
506
- * Reset the draw and display canvases layout after mouse pan.
507
- * If no params in, then center the draw and display canvases.
508
- * @param l number, Offset to the left
509
- * @param t number, Offset to the top
510
- */
511
160
  resetPaintAreaUIPosition(l?: number, t?: number): void;
161
+ resetLayerCanvas(): void;
162
+ redrawMianPreOnDisplayCanvas(): void;
163
+ resizePaintArea(factor: number): void;
164
+ flipDisplayImageByAxis(): void;
165
+ setEmptyCanvasSize(axis?: "x" | "y" | "z"): void;
166
+ redrawDisplayCanvas(): void;
167
+ private reloadMasksFromVolume;
168
+ setAllSlices(allSlices: Array<nrrdSliceType>): void;
169
+ setMasksData(masksData: storeExportPaintImageType, loadingBar?: loadingBarType): void;
170
+ setMasksFromNIfTI(layerVoxels: Map<string, Uint8Array>, loadingBar?: loadingBarType): void;
171
+ setCalculateDistanceSphere(x: number, y: number, sliceIndex: number, cal_position: "tumour" | "skin" | "nipple" | "ribcage"): void;
512
172
  /**
513
- * Clear masks on drawingCanvas layers.
173
+ * Refresh sphere canvas from sphereMaskVolume for the current slice/axis.
514
174
  */
515
- resetLayerCanvas(): void;
175
+ private refreshSphereOverlay;
516
176
  /**
517
177
  * Enter sphere mode.
518
- *
519
- * Clears all layer canvases and the master composite canvas so that
520
- * only the sphere overlay is visible. Does NOT touch MaskVolume data.
521
- * Also disables drag mode to prevent slice dragging conflicts.
522
- *
523
- * Called when sphere mode is toggled on (keyboard shortcut or GUI).
524
178
  */
525
179
  enterSphereMode(): void;
526
180
  /**
527
181
  * Exit sphere mode.
528
- *
529
- * Clears sphere overlay, restores all layer MaskVolume data onto
530
- * their canvases by temporarily lifting the sphere guard in
531
- * reloadMasksFromVolume and calling it.
532
- *
533
- * Called when sphere mode is toggled off (keyboard shortcut or GUI).
534
182
  */
535
183
  exitSphereMode(): void;
536
- redrawMianPreOnDisplayCanvas(): void;
537
- /**
538
- * Resize the draw and display canvas size based on the input size factor number.
539
- * @param factor number
540
- */
541
- resizePaintArea(factor: number): void;
542
- /**
543
- * Phase 3: Reload all mask layers from MaskVolume using buffer reuse
544
- * Replaces the old reloadMaskToLayer approach
545
- */
546
- private reloadMasksFromVolume;
547
- /**
548
- * flip the canvas to a correct position.
549
- * This is because the slice canvas from threejs is not in a correct 2D postion.
550
- * Thus, everytime when we redraw the display canvas, we need to flip to draw the origin canvas from threejs.
551
- * Under different axis(sagittal, Axial, Coronal), the flip orientation is different.
552
- */
553
- flipDisplayImageByAxis(): void;
184
+ clearActiveLayer(): void;
185
+ reset(): void;
186
+ configMouseSliceWheel(): (e: WheelEvent) => void;
187
+ updateMouseWheelEvent(): void;
188
+ setIsDrawFalse(target: number): void;
189
+ private setShowInMainArea;
554
190
  private clearDictionary;
555
191
  /**
556
- * Set the empty canvas width and height based on the axis (pixel distance not the mm), to reduce duplicate codes.
557
- *
558
- * @param axis
192
+ * Get the DrawToolCore's start() render loop callback.
193
+ * This is called by DragSliceTool's requestAnimationFrame loop.
559
194
  */
560
- setEmptyCanvasSize(axis?: "x" | "y" | "z"): void;
561
- /******************************** redraw display canvas ***************************************/
195
+ get start(): () => void;
562
196
  /**
563
- * Redraw current contrast image to display canvas.
564
- * It is more related to change the contrast slice image's window width or center.
197
+ * Expose drawCalculatorSphereOnEachViews for external use.
565
198
  */
566
- redrawDisplayCanvas(): void;
567
- /**
568
- * Config mouse slice wheel event.
569
- */
570
- configMouseSliceWheel(): (e: WheelEvent) => void;
571
- /**
572
- * Update mouse wheel event.
573
- */
574
- updateMouseWheelEvent(): void;
199
+ drawCalculatorSphereOnEachViews(axis: "x" | "y" | "z"): void;
575
200
  }