copper3d 3.0.1 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (134) hide show
  1. package/README.md +197 -875
  2. package/dist/Utils/segmentation/CanvasState.d.ts +31 -0
  3. package/dist/Utils/segmentation/CanvasState.js +167 -0
  4. package/dist/Utils/segmentation/CanvasState.js.map +1 -0
  5. package/dist/Utils/segmentation/DragOperator.d.ts +10 -2
  6. package/dist/Utils/segmentation/DragOperator.js +16 -8
  7. package/dist/Utils/segmentation/DragOperator.js.map +1 -1
  8. package/dist/Utils/segmentation/DrawToolCore.d.ts +64 -35
  9. package/dist/Utils/segmentation/DrawToolCore.js +332 -584
  10. package/dist/Utils/segmentation/DrawToolCore.js.map +1 -1
  11. package/dist/Utils/segmentation/NrrdTools.d.ts +117 -353
  12. package/dist/Utils/segmentation/NrrdTools.js +622 -1081
  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 +180 -0
  16. package/dist/Utils/segmentation/RenderingUtils.js.map +1 -0
  17. package/dist/Utils/segmentation/core/MaskVolume.js +23 -2
  18. package/dist/Utils/segmentation/core/MaskVolume.js.map +1 -1
  19. package/dist/Utils/segmentation/core/UndoManager.d.ts +1 -1
  20. package/dist/Utils/segmentation/core/UndoManager.js +1 -1
  21. package/dist/Utils/segmentation/core/index.d.ts +1 -3
  22. package/dist/Utils/segmentation/core/index.js +0 -1
  23. package/dist/Utils/segmentation/core/index.js.map +1 -1
  24. package/dist/Utils/segmentation/core/types.d.ts +384 -0
  25. package/dist/Utils/segmentation/core/types.js +25 -24
  26. package/dist/Utils/segmentation/core/types.js.map +1 -1
  27. package/dist/Utils/segmentation/coreTools/GuiState.d.ts +22 -0
  28. package/dist/Utils/segmentation/coreTools/GuiState.js +48 -0
  29. package/dist/Utils/segmentation/coreTools/GuiState.js.map +1 -0
  30. package/dist/Utils/segmentation/coreTools/NrrdState.d.ts +25 -0
  31. package/dist/Utils/segmentation/coreTools/NrrdState.js +85 -0
  32. package/dist/Utils/segmentation/coreTools/NrrdState.js.map +1 -0
  33. package/dist/Utils/segmentation/coreTools/divControlTools.d.ts +1 -1
  34. package/dist/Utils/segmentation/coreTools/divControlTools.js +1 -1
  35. package/dist/Utils/segmentation/coreTools/divControlTools.js.map +1 -1
  36. package/dist/Utils/segmentation/coreTools/gui.d.ts +12 -12
  37. package/dist/Utils/segmentation/coreTools/gui.js +81 -107
  38. package/dist/Utils/segmentation/coreTools/gui.js.map +1 -1
  39. package/dist/Utils/segmentation/eventRouter/EventRouter.d.ts +2 -1
  40. package/dist/Utils/segmentation/eventRouter/EventRouter.js +15 -10
  41. package/dist/Utils/segmentation/eventRouter/EventRouter.js.map +1 -1
  42. package/dist/Utils/segmentation/eventRouter/types.d.ts +3 -3
  43. package/dist/Utils/segmentation/tools/BaseTool.d.ts +8 -5
  44. package/dist/Utils/segmentation/tools/BaseTool.js +1 -2
  45. package/dist/Utils/segmentation/tools/BaseTool.js.map +1 -1
  46. package/dist/Utils/segmentation/tools/ContrastTool.d.ts +3 -6
  47. package/dist/Utils/segmentation/tools/ContrastTool.js.map +1 -1
  48. package/dist/Utils/segmentation/tools/CrosshairTool.d.ts +11 -1
  49. package/dist/Utils/segmentation/tools/CrosshairTool.js +50 -25
  50. package/dist/Utils/segmentation/tools/CrosshairTool.js.map +1 -1
  51. package/dist/Utils/segmentation/tools/DataLoader.d.ts +33 -0
  52. package/dist/Utils/segmentation/tools/DataLoader.js +159 -0
  53. package/dist/Utils/segmentation/tools/DataLoader.js.map +1 -0
  54. package/dist/Utils/segmentation/tools/DragSliceTool.d.ts +3 -10
  55. package/dist/Utils/segmentation/tools/DragSliceTool.js +63 -53
  56. package/dist/Utils/segmentation/tools/DragSliceTool.js.map +1 -1
  57. package/dist/Utils/segmentation/tools/DrawingTool.d.ts +85 -0
  58. package/dist/Utils/segmentation/tools/DrawingTool.js +270 -0
  59. package/dist/Utils/segmentation/tools/DrawingTool.js.map +1 -0
  60. package/dist/Utils/segmentation/tools/EraserTool.js +8 -8
  61. package/dist/Utils/segmentation/tools/EraserTool.js.map +1 -1
  62. package/dist/Utils/segmentation/tools/ImageStoreHelper.d.ts +13 -33
  63. package/dist/Utils/segmentation/tools/ImageStoreHelper.js +39 -82
  64. package/dist/Utils/segmentation/tools/ImageStoreHelper.js.map +1 -1
  65. package/dist/Utils/segmentation/tools/LayerChannelManager.d.ts +52 -0
  66. package/dist/Utils/segmentation/tools/LayerChannelManager.js +175 -0
  67. package/dist/Utils/segmentation/tools/LayerChannelManager.js.map +1 -0
  68. package/dist/Utils/segmentation/tools/PanTool.d.ts +47 -0
  69. package/dist/Utils/segmentation/tools/PanTool.js +90 -0
  70. package/dist/Utils/segmentation/tools/PanTool.js.map +1 -0
  71. package/dist/Utils/segmentation/tools/SliceRenderPipeline.d.ts +80 -0
  72. package/dist/Utils/segmentation/tools/SliceRenderPipeline.js +355 -0
  73. package/dist/Utils/segmentation/tools/SliceRenderPipeline.js.map +1 -0
  74. package/dist/Utils/segmentation/tools/SphereTool.d.ts +223 -10
  75. package/dist/Utils/segmentation/tools/SphereTool.js +512 -47
  76. package/dist/Utils/segmentation/tools/SphereTool.js.map +1 -1
  77. package/dist/Utils/segmentation/tools/ToolHost.d.ts +74 -0
  78. package/dist/Utils/segmentation/tools/ToolHost.js +10 -0
  79. package/dist/Utils/segmentation/tools/ToolHost.js.map +1 -0
  80. package/dist/Utils/segmentation/tools/ZoomTool.d.ts +2 -6
  81. package/dist/Utils/segmentation/tools/ZoomTool.js +3 -3
  82. package/dist/Utils/segmentation/tools/ZoomTool.js.map +1 -1
  83. package/dist/Utils/segmentation/tools/index.d.ts +8 -6
  84. package/dist/Utils/segmentation/tools/index.js +10 -1
  85. package/dist/Utils/segmentation/tools/index.js.map +1 -1
  86. package/dist/Utils/workers/reformatSaveDataWorker.d.ts +1 -1
  87. package/dist/bundle.esm.js +3729 -3017
  88. package/dist/bundle.umd.js +3729 -3017
  89. package/dist/index.d.ts +6 -3
  90. package/dist/index.js +1 -1
  91. package/dist/index.js.map +1 -1
  92. package/dist/types/Utils/segmentation/CanvasState.d.ts +31 -0
  93. package/dist/types/Utils/segmentation/DragOperator.d.ts +10 -2
  94. package/dist/types/Utils/segmentation/DrawToolCore.d.ts +64 -35
  95. package/dist/types/Utils/segmentation/NrrdTools.d.ts +117 -353
  96. package/dist/types/Utils/segmentation/RenderingUtils.d.ts +73 -0
  97. package/dist/types/Utils/segmentation/core/UndoManager.d.ts +1 -1
  98. package/dist/types/Utils/segmentation/core/index.d.ts +1 -3
  99. package/dist/types/Utils/segmentation/core/types.d.ts +384 -0
  100. package/dist/types/Utils/segmentation/coreTools/GuiState.d.ts +22 -0
  101. package/dist/types/Utils/segmentation/coreTools/NrrdState.d.ts +25 -0
  102. package/dist/types/Utils/segmentation/coreTools/divControlTools.d.ts +1 -1
  103. package/dist/types/Utils/segmentation/coreTools/gui.d.ts +12 -12
  104. package/dist/types/Utils/segmentation/eventRouter/EventRouter.d.ts +2 -1
  105. package/dist/types/Utils/segmentation/eventRouter/types.d.ts +3 -3
  106. package/dist/types/Utils/segmentation/tools/BaseTool.d.ts +8 -5
  107. package/dist/types/Utils/segmentation/tools/ContrastTool.d.ts +3 -6
  108. package/dist/types/Utils/segmentation/tools/CrosshairTool.d.ts +11 -1
  109. package/dist/types/Utils/segmentation/tools/DataLoader.d.ts +33 -0
  110. package/dist/types/Utils/segmentation/tools/DragSliceTool.d.ts +3 -10
  111. package/dist/types/Utils/segmentation/tools/DrawingTool.d.ts +85 -0
  112. package/dist/types/Utils/segmentation/tools/ImageStoreHelper.d.ts +13 -33
  113. package/dist/types/Utils/segmentation/tools/LayerChannelManager.d.ts +52 -0
  114. package/dist/types/Utils/segmentation/tools/PanTool.d.ts +47 -0
  115. package/dist/types/Utils/segmentation/tools/SliceRenderPipeline.d.ts +80 -0
  116. package/dist/types/Utils/segmentation/tools/SphereTool.d.ts +223 -10
  117. package/dist/types/Utils/segmentation/tools/ToolHost.d.ts +74 -0
  118. package/dist/types/Utils/segmentation/tools/ZoomTool.d.ts +2 -6
  119. package/dist/types/Utils/segmentation/tools/index.d.ts +8 -6
  120. package/dist/types/Utils/workers/reformatSaveDataWorker.d.ts +1 -1
  121. package/dist/types/index.d.ts +6 -3
  122. package/package.json +1 -1
  123. package/dist/Utils/segmentation/CommToolsData.d.ts +0 -177
  124. package/dist/Utils/segmentation/CommToolsData.js +0 -548
  125. package/dist/Utils/segmentation/CommToolsData.js.map +0 -1
  126. package/dist/Utils/segmentation/core/MigrationUtils.d.ts +0 -97
  127. package/dist/Utils/segmentation/core/MigrationUtils.js +0 -163
  128. package/dist/Utils/segmentation/core/MigrationUtils.js.map +0 -1
  129. package/dist/Utils/segmentation/coreTools/coreType.d.ts +0 -363
  130. package/dist/Utils/segmentation/coreTools/coreType.js +0 -3
  131. package/dist/Utils/segmentation/coreTools/coreType.js.map +0 -1
  132. package/dist/types/Utils/segmentation/CommToolsData.d.ts +0 -177
  133. package/dist/types/Utils/segmentation/core/MigrationUtils.d.ts +0 -97
  134. package/dist/types/Utils/segmentation/coreTools/coreType.d.ts +0 -363
@@ -1,12 +1,21 @@
1
1
  import { nrrdSliceType, storeExportPaintImageType, loadingBarType } from "../../types/types";
2
2
  import { GUI } from "dat.gui";
3
- import { IMaskData, IDragOpts, IGuiParameterSettings, IKeyBoardSettings } 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";
6
+ import type { SphereType } from "./tools/SphereTool";
7
7
  /**
8
8
  * Core NRRD annotation tool for medical image segmentation.
9
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
+ *
10
19
  * @example
11
20
  * ```ts
12
21
  * // Default 3 layers: layer1, layer2, layer3
@@ -16,418 +25,173 @@ import type { ChannelValue, RGBAColor, ChannelColorMap } from "./core";
16
25
  * const tools = new NrrdTools(container, { layers: ["layer1", "layer2"] });
17
26
  * ```
18
27
  */
19
- export declare class NrrdTools extends DrawToolCore {
28
+ export declare class NrrdTools {
20
29
  container: HTMLDivElement;
30
+ /** Shared state container. */
31
+ private state;
32
+ /** Core drawing tool orchestrator. */
33
+ private drawCore;
34
+ /** Drag operator for slice navigation. */
21
35
  dragOperator: DragOperator;
22
- private paintedImage;
23
- private initState;
24
36
  private preTimer;
25
37
  private guiParameterSettings;
26
38
  private _sliceRAFId;
27
39
  private _pendingSliceStep;
40
+ /** Whether calculator mode is active (not part of gui_states interface) */
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;
48
+ /** Stored closure callbacks from gui.ts setupGui() */
49
+ private guiCallbacks;
28
50
  constructor(container: HTMLDivElement, options?: {
29
51
  layers?: string[];
30
52
  });
31
53
  /**
32
- * core function for drag slices
33
- * @param opts
54
+ * Wire DrawToolCore's overridable methods to NrrdTools implementations.
55
+ * This replaces the old inheritance approach.
34
56
  */
35
- drag(opts?: IDragOpts): void;
57
+ private wireDrawCoreMethods;
36
58
  /**
37
- * Set the Draw Display Canvas base size
38
- * @param size number
39
- */
40
- setBaseDrawDisplayCanvasesSize(size: number): void;
41
- setDisplaySliceIndexPanel(panel: HTMLDivElement): void;
42
- /**
43
- * Enable the drag function for contrast images window center and window high.
44
- * @param callback
59
+ * A initialise function for nrrd_tools
45
60
  */
46
- enableContrastDragEvents(callback: (step: number, towards: "horizental" | "vertical") => void): void;
61
+ private init;
62
+ private initNrrdToolsModules;
47
63
  /**
48
64
  * Set up GUI for drawing panel
49
65
  * @param gui GUI
50
66
  */
51
67
  setupGUI(gui: GUI): void;
52
- getGuiSettings(): {
53
- guiState: import("./coreTools/coreType").IGUIStates;
54
- guiSetting: IGuiParameterSettings | undefined;
55
- };
56
- /**
57
- * Set the active layer and update fillColor/brushColor to match the active channel.
58
- */
59
- setActiveLayer(layerId: string): void;
60
- /**
61
- * Set the active channel (1-8) and update fillColor/brushColor.
62
- */
63
- setActiveChannel(channel: ChannelValue): void;
64
- /**
65
- * Sync brush/fill color from the active layer's volume color map.
66
- * Falls back to global CHANNEL_HEX_COLORS if volume not available.
67
- */
68
- private syncBrushColor;
69
- /**
70
- * Get the currently active layer id.
71
- */
72
- getActiveLayer(): string;
73
- /**
74
- * Get the currently active channel value.
75
- */
76
- getActiveChannel(): number;
77
- /**
78
- * Set visibility of a layer and re-render.
79
- */
80
- setLayerVisible(layerId: string, visible: boolean): void;
81
- /**
82
- * Check if a layer is visible.
83
- */
84
- isLayerVisible(layerId: string): boolean;
85
- /**
86
- * Set visibility of a specific channel within a layer and re-render.
87
- */
88
- setChannelVisible(layerId: string, channel: ChannelValue, visible: boolean): void;
89
- /**
90
- * Check if a specific channel within a layer is visible.
91
- */
92
- isChannelVisible(layerId: string, channel: ChannelValue): boolean;
93
- /**
94
- * Get the full layer visibility map.
95
- */
96
- getLayerVisibility(): Record<string, boolean>;
97
68
  /**
98
- * Get the full channel visibility map.
99
- */
100
- getChannelVisibility(): Record<string, Record<number, boolean>>;
101
- /**
102
- * Check if a specific layer contains any non-zero mask data.
103
- *
104
- * This is useful for determining if a layer has actual annotations
105
- * before saving or exporting to avoid processing empty layers.
106
- *
107
- * @param layerId - The layer to check ('layer1', 'layer2', or 'layer3')
108
- * @returns True if the layer has any non-zero voxel data, false if empty
109
- *
110
- * @example
111
- * ```ts
112
- * if (nrrdTools.hasLayerData('layer1')) {
113
- * await useSaveMasks(caseId, 'layer1');
114
- * }
115
- * ```
116
- */
117
- hasLayerData(layerId: string): boolean;
118
- /**
119
- * Set a custom color for a specific channel in a specific layer.
120
- * Only affects this layer; other layers remain unchanged.
121
- *
122
- * @param layerId Layer to customize (e.g. 'layer1', 'layer2')
123
- * @param channel Channel label (1-8)
124
- * @param color RGBAColor object { r, g, b, a } (each 0-255)
125
- *
126
- * @example
127
- * ```ts
128
- * // Make channel 2 in layer2 orange
129
- * nrrdTools.setChannelColor('layer2', 2, { r: 255, g: 128, b: 0, a: 255 });
130
- * ```
131
- */
132
- setChannelColor(layerId: string, channel: number, color: RGBAColor): void;
133
- /**
134
- * Get the current color for a specific channel in a specific layer.
135
- *
136
- * @param layerId Layer to query
137
- * @param channel Channel label (1-8)
138
- * @returns RGBAColor object (copy, safe to mutate)
139
- */
140
- getChannelColor(layerId: string, channel: number): RGBAColor;
141
- /**
142
- * Get a hex color string for a channel in a layer (e.g. '#ff8000').
143
- */
144
- getChannelHexColor(layerId: string, channel: number): string;
145
- /**
146
- * Get a CSS rgba() color string for a channel in a layer.
147
- */
148
- getChannelCssColor(layerId: string, channel: number): string;
149
- /**
150
- * Batch-set multiple channel colors for a single layer (single re-render).
151
- *
152
- * @param layerId Layer to customize
153
- * @param colorMap Partial map of channel -> RGBAColor
154
- *
155
- * @example
156
- * ```ts
157
- * nrrdTools.setChannelColors('layer2', {
158
- * 2: { r: 255, g: 128, b: 0, a: 255 },
159
- * 3: { r: 100, g: 200, b: 50, a: 255 },
160
- * });
161
- * ```
162
- */
163
- setChannelColors(layerId: string, colorMap: Partial<ChannelColorMap>): void;
164
- /**
165
- * Set the same color for a specific channel across ALL layers (single re-render).
166
- *
167
- * @param channel Channel label (1-8)
168
- * @param color RGBAColor object
169
- */
170
- setAllLayersChannelColor(channel: number, color: RGBAColor): void;
171
- /**
172
- * Reset channel colors to system defaults.
173
- *
174
- * @param layerId Optional. If omitted, resets all layers.
175
- * @param channel Optional. If omitted, resets all channels in the layer(s).
176
- *
177
- * @example
178
- * ```ts
179
- * nrrdTools.resetChannelColors('layer2', 2); // Reset only ch2 in layer2
180
- * nrrdTools.resetChannelColors('layer2'); // Reset all channels in layer2
181
- * nrrdTools.resetChannelColors(); // Reset all layers
182
- * ```
183
- */
184
- resetChannelColors(layerId?: string, channel?: number): void;
185
- /**
186
- * Programmatically trigger an undo operation.
187
- *
188
- * Equivalent to pressing Ctrl+Z. Reverts the most recent drawing stroke
189
- * on the currently active layer and syncs the result to the backend via
190
- * the `getMask` callback.
191
- *
192
- * @example
193
- * ```ts
194
- * undoBtn.addEventListener('click', () => nrrdTools.undo());
195
- * ```
196
- */
69
+ * Sync guiParameterSettings with current volume metadata.
70
+ */
71
+ private syncGuiParameterSettings;
72
+ /**
73
+ * Set the current tool mode.
74
+ */
75
+ setMode(mode: ToolMode): void;
76
+ getMode(): ToolMode;
77
+ isCalculatorActive(): boolean;
78
+ setOpacity(value: number): void;
79
+ getOpacity(): number;
80
+ setBrushSize(size: number): void;
81
+ getBrushSize(): number;
82
+ setWindowHigh(value: number): void;
83
+ setWindowLow(value: number): void;
84
+ finishWindowAdjustment(): void;
85
+ adjustContrast(type: "windowHigh" | "windowLow", delta: number): void;
86
+ getSliderMeta(key: string): IGuiMeta | null;
87
+ setPencilColor(hex: string): void;
88
+ getPencilColor(): string;
89
+ executeAction(action: "undo" | "redo" | "clearActiveSliceMask" | "clearActiveLayerMask" | "resetZoom" | "downloadCurrentMask"): void;
197
90
  undo(): void;
198
- /**
199
- * Programmatically trigger a redo operation.
200
- *
201
- * Equivalent to pressing Ctrl+Y. Re-applies the most recently undone
202
- * drawing stroke on the currently active layer and syncs the result to
203
- * the backend via the `getMask` callback.
204
- *
205
- * @example
206
- * ```ts
207
- * redoBtn.addEventListener('click', () => nrrdTools.redo());
208
- * ```
209
- */
210
91
  redo(): void;
211
- /**
212
- * Enter keyboard-configuration mode.
213
- *
214
- * While active, every keydown/keyup handler in DrawToolCore and DragOperator
215
- * is suppressed so the user can press arbitrary keys in the settings dialog
216
- * without accidentally triggering drawing, undo, or contrast shortcuts.
217
- *
218
- * Always pair with {@link exitKeyboardConfig} when the dialog closes.
219
- *
220
- * @example
221
- * ```ts
222
- * dialog.addEventListener('open', () => nrrdTools.enterKeyboardConfig());
223
- * ```
224
- */
225
92
  enterKeyboardConfig(): void;
226
- /**
227
- * Exit keyboard-configuration mode and resume normal shortcut handling.
228
- *
229
- * @example
230
- * ```ts
231
- * dialog.addEventListener('close', () => nrrdTools.exitKeyboardConfig());
232
- * ```
233
- */
234
93
  exitKeyboardConfig(): void;
235
- /**
236
- * Enable or disable the contrast window/level shortcut (Ctrl/Meta key).
237
- *
238
- * When disabled:
239
- * - Holding Ctrl no longer enters contrast mode
240
- * - If contrast mode is currently active it is immediately exited
241
- * - All other Ctrl-based shortcuts (Ctrl+Z undo, Ctrl+Y redo) are
242
- * unaffected because they are checked in the keydown handler before
243
- * the contrast guard runs
244
- *
245
- * @param enabled - Pass `false` to disable, `true` to re-enable.
246
- *
247
- * @example
248
- * ```ts
249
- * // Disable contrast when sphere tool is active
250
- * nrrdTools.setContrastShortcutEnabled(false);
251
- *
252
- * // Re-enable when returning to draw mode
253
- * nrrdTools.setContrastShortcutEnabled(true);
254
- * ```
255
- */
256
94
  setContrastShortcutEnabled(enabled: boolean): void;
257
- /**
258
- * Returns whether the contrast shortcut is currently enabled.
259
- */
260
95
  isContrastShortcutEnabled(): boolean;
261
- /**
262
- * Update keyboard shortcut bindings.
263
- *
264
- * Synchronises both the internal class field (read by every keydown handler)
265
- * and the EventRouter's internal copy (used for modifier-key mode tracking)
266
- * so the two never drift apart. If `mouseWheel` is changed the wheel event
267
- * listener is automatically re-bound via {@link updateMouseWheelEvent}.
268
- *
269
- * Only the fields you supply are updated; omitted fields keep their
270
- * current values.
271
- *
272
- * @param settings - Partial keyboard settings to override.
273
- *
274
- * @example
275
- * ```ts
276
- * nrrdTools.setKeyboardSettings({
277
- * undo: 'z',
278
- * redo: 'y',
279
- * crosshair: 'c',
280
- * mouseWheel: 'Scroll:Slice',
281
- * });
282
- * ```
283
- */
284
96
  setKeyboardSettings(settings: Partial<IKeyBoardSettings>): void;
285
- /**
286
- * Get a snapshot of the current keyboard shortcut bindings.
287
- *
288
- * Returns a shallow copy so callers cannot accidentally mutate internal
289
- * state. To update settings use {@link setKeyboardSettings} instead.
290
- *
291
- * @returns Current keyboard settings.
292
- *
293
- * @example
294
- * ```ts
295
- * const { undo, redo } = nrrdTools.getKeyboardSettings();
296
- * console.log(`Undo: Ctrl+${undo}, Redo: Ctrl+${redo}`);
297
- * ```
298
- */
299
97
  getKeyboardSettings(): IKeyBoardSettings;
98
+ drag(opts?: IDragOpts): void;
300
99
  /**
301
- * A initialise function for nrrd_tools
302
- */
303
- private init;
304
- /**
305
- *
306
- * entry function
307
- * * {
308
- * x:slice,
309
- * y:slice,
310
- * z:slice
311
- * }
312
- *
313
- * @param allSlices - all nrrd contrast slices
314
-
100
+ * Core drawing entry point.
315
101
  */
316
- setAllSlices(allSlices: Array<nrrdSliceType>): void;
317
- private loadingMaskByLayer;
318
- setMasksData(masksData: storeExportPaintImageType, loadingBar?: loadingBarType): void;
102
+ draw(opts?: any): void;
319
103
  /**
320
- * Load raw voxel data into MaskVolume layers.
321
- *
322
- * Expects pre-extracted voxel bytes (e.g. from useNiftiVoxelData).
323
- *
324
- * @param layerVoxels Map of layer ID to raw voxel Uint8Array
325
- * Keys should be 'layer1', 'layer2', 'layer3'
326
- * @param loadingBar Optional loading bar UI
104
+ * Set the Draw Display Canvas base size
327
105
  */
328
- setMasksFromNIfTI(layerVoxels: Map<string, Uint8Array>, loadingBar?: loadingBarType): void;
329
- private setShowInMainArea;
330
- getCurrentImageDimension(): number[];
331
- getVoxelSpacing(): number[];
332
- getSpaceOrigin(): number[];
333
- getMaskData(): IMaskData;
334
- 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;
335
111
  /**
336
112
  * Switch all contrast slices' orientation
337
- * @param {string} aixs:"x" | "y" | "z"
338
- * */
113
+ */
339
114
  setSliceOrientation(axisTo: "x" | "y" | "z"): void;
340
115
  addSkip(index: number): void;
341
116
  removeSkip(index: number): void;
342
- clear(): void;
343
117
  setSliceMoving(step: number): void;
344
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;
345
125
  getContainer(): HTMLElement;
346
126
  getDrawingCanvas(): HTMLCanvasElement;
347
- getNrrdToolsSettings(): import("./coreTools/coreType").INrrdStates;
127
+ getNrrdToolsSettings(): import("./coreTools/NrrdState").NrrdState;
348
128
  getMaxSliceNum(): number[];
349
129
  getCurrentSlicesNumAndContrastNum(): {
350
- currentIndex: number;
130
+ currentSliceIndex: number;
351
131
  contrastIndex: number;
352
132
  };
353
133
  getCurrentSliceIndex(): number;
354
134
  getIsShowContrastState(): boolean;
355
- /**
356
- * Give a delay time to finish the last drawing before upcoming interrupt opreations.
357
- * Give a delay time number (ms) to disable the draw function,
358
- * After your interrupt opeartion, you should enable the draw fucntion.
359
- * @param target number
360
- */
361
- setIsDrawFalse(target: number): void;
362
- private setDisplaySlicesBaseOnAxis;
363
- private loadDisplaySlicesArray;
364
- switchAllSlicesArrayData(allSlices: Array<nrrdSliceType>): void;
365
- private resetDisplaySlicesStatus;
366
- private setupConfigs;
367
- private setMainPreSlice;
368
- private setOriginCanvasAndPre;
369
- private afterLoadSlice;
370
- private updateMaxIndex;
371
- /**
372
- * Update the original canvas size, allow set to threejs load one (pixel distance not the mm).
373
- * Then update the changedWidth and changedHeight based on the sizeFoctor.
374
- */
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;
375
155
  updateOriginAndChangedWH(): void;
376
- /**
377
- * Keep all contrast slice index to same.
378
- * Synchronize the slice indexes of all the contrasts so that they are consistent with the main slice's index.
379
- */
380
156
  setSyncsliceNum(): void;
381
- appendLoadingbar(loadingbar: HTMLDivElement): void;
382
- clearStoreImages(): void;
383
- /**
384
- * Reset the draw and display canvases layout after mouse pan.
385
- * If no params in, then center the draw and display canvases.
386
- * @param l number, Offset to the left
387
- * @param t number, Offset to the top
388
- */
389
157
  resetPaintAreaUIPosition(l?: number, t?: number): void;
390
- /**
391
- * Clear masks on drawingCanvas layers.
392
- */
393
158
  resetLayerCanvas(): void;
394
159
  redrawMianPreOnDisplayCanvas(): void;
395
- /**
396
- * Resize the draw and display canvas size based on the input size factor number.
397
- * @param factor number
398
- */
399
160
  resizePaintArea(factor: number): void;
400
- /**
401
- * Phase 3: Reload all mask layers from MaskVolume using buffer reuse
402
- * Replaces the old reloadMaskToLayer approach
403
- */
161
+ flipDisplayImageByAxis(): void;
162
+ setEmptyCanvasSize(axis?: "x" | "y" | "z"): void;
163
+ redrawDisplayCanvas(): void;
404
164
  private reloadMasksFromVolume;
165
+ setAllSlices(allSlices: Array<nrrdSliceType>): void;
166
+ setMasksData(masksData: storeExportPaintImageType, loadingBar?: loadingBarType): void;
167
+ setMasksFromNIfTI(layerVoxels: Map<string, Uint8Array>, loadingBar?: loadingBarType): void;
168
+ setCalculateDistanceSphere(x: number, y: number, sliceIndex: number, cal_position: "tumour" | "skin" | "nipple" | "ribcage"): void;
405
169
  /**
406
- * flip the canvas to a correct position.
407
- * This is because the slice canvas from threejs is not in a correct 2D postion.
408
- * Thus, everytime when we redraw the display canvas, we need to flip to draw the origin canvas from threejs.
409
- * Under different axis(sagittal, Axial, Coronal), the flip orientation is different.
170
+ * Refresh sphere canvas from sphereMaskVolume for the current slice/axis.
410
171
  */
411
- flipDisplayImageByAxis(): void;
412
- private clearDictionary;
172
+ private refreshSphereOverlay;
413
173
  /**
414
- * Set the empty canvas width and height based on the axis (pixel distance not the mm), to reduce duplicate codes.
415
- *
416
- * @param axis
174
+ * Enter sphere mode.
417
175
  */
418
- setEmptyCanvasSize(axis?: "x" | "y" | "z"): void;
419
- /******************************** redraw display canvas ***************************************/
176
+ enterSphereMode(): void;
420
177
  /**
421
- * Redraw current contrast image to display canvas.
422
- * It is more related to change the contrast slice image's window width or center.
178
+ * Exit sphere mode.
423
179
  */
424
- redrawDisplayCanvas(): void;
180
+ exitSphereMode(): void;
181
+ clearActiveLayer(): void;
182
+ reset(): void;
183
+ configMouseSliceWheel(): (e: WheelEvent) => void;
184
+ updateMouseWheelEvent(): void;
185
+ setIsDrawFalse(target: number): void;
186
+ private setShowInMainArea;
187
+ private clearDictionary;
425
188
  /**
426
- * Config mouse slice wheel event.
189
+ * Get the DrawToolCore's start() render loop callback.
190
+ * This is called by DragSliceTool's requestAnimationFrame loop.
427
191
  */
428
- configMouseSliceWheel(): (e: WheelEvent) => void;
192
+ get start(): () => void;
429
193
  /**
430
- * Update mouse wheel event.
194
+ * Expose drawCalculatorSphereOnEachViews for external use.
431
195
  */
432
- updateMouseWheelEvent(): void;
196
+ drawCalculatorSphereOnEachViews(axis: "x" | "y" | "z"): void;
433
197
  }
@@ -0,0 +1,73 @@
1
+ import type { INewMaskData } from "./core/types";
2
+ import type { MaskVolume } from "./core/index";
3
+ import type { CanvasState } from "./CanvasState";
4
+ /**
5
+ * RenderingUtils — Rendering / slice-buffer helper methods.
6
+ *
7
+ * Extracted from CommToolsData. All methods operate on the shared
8
+ * {@link CanvasState} reference — no independent state is held here
9
+ * except the reusable ImageData slice buffer.
10
+ *
11
+ * The `setEmptyCanvasSize` callback is injected by the owner (DrawToolCore
12
+ * or NrrdTools) because it lives in SliceRenderPipeline, not here.
13
+ */
14
+ export declare class RenderingUtils {
15
+ private state;
16
+ /** Injected callback — set by owner after construction. */
17
+ setEmptyCanvasSize: (axis?: "x" | "y" | "z") => void;
18
+ private _reusableSliceBuffer;
19
+ private _reusableBufferWidth;
20
+ private _reusableBufferHeight;
21
+ constructor(state: CanvasState);
22
+ /**
23
+ * Get MaskVolume for a specific layer
24
+ *
25
+ * @param layer - Layer name: "layer1", "layer2", or "layer3"
26
+ * @returns MaskVolume instance for the specified layer
27
+ */
28
+ getVolumeForLayer(layer: string): MaskVolume;
29
+ /**
30
+ * Get MaskVolume for the currently active layer
31
+ */
32
+ getCurrentVolume(): MaskVolume;
33
+ /**
34
+ * Get all MaskVolume instances
35
+ */
36
+ getAllVolumes(): INewMaskData;
37
+ /**
38
+ * Get a painted mask image based on current axis and input slice index.
39
+ *
40
+ * Reads directly from MaskVolume.
41
+ */
42
+ filterDrawedImage(axis: "x" | "y" | "z", sliceIndex: number): {
43
+ index: number;
44
+ image: ImageData;
45
+ } | undefined;
46
+ /**
47
+ * Get or create a reusable ImageData buffer for the given axis.
48
+ *
49
+ * Reuses the same buffer across multiple slice renders to avoid
50
+ * allocating a new ImageData per layer per slice switch.
51
+ */
52
+ getOrCreateSliceBuffer(axis: "x" | "y" | "z"): ImageData | null;
53
+ /**
54
+ * Render a layer's slice into a reusable buffer and draw to the target canvas.
55
+ *
56
+ * Uses MaskVolume.renderLabelSliceInto() for zero-allocation rendering.
57
+ */
58
+ renderSliceToCanvas(layer: string, axis: "x" | "y" | "z", sliceIndex: number, buffer: ImageData, targetCtx: CanvasRenderingContext2D, scaledWidth: number, scaledHeight: number): void;
59
+ /**
60
+ * Invalidate the reusable buffer (e.g. when switching datasets).
61
+ */
62
+ invalidateSliceBuffer(): void;
63
+ /**
64
+ * Apply the same flip transform used by flipDisplayImageByAxis() to any
65
+ * canvas context.
66
+ */
67
+ applyMaskFlipForAxis(ctx: CanvasRenderingContext2D, width: number, height: number, axis: "x" | "y" | "z"): void;
68
+ /**
69
+ * Composite all layer canvases to the master display canvas.
70
+ * Only draws layers whose visibility is enabled.
71
+ */
72
+ compositeAllLayers(): void;
73
+ }
@@ -40,7 +40,7 @@ export declare class UndoManager {
40
40
  redo(): MaskDelta | undefined;
41
41
  canUndo(): boolean;
42
42
  canRedo(): boolean;
43
- /** Clear undo and redo stacks for a specific layer (called on clearStoreImages). */
43
+ /** Clear undo and redo stacks for a specific layer (called on clearActiveLayer). */
44
44
  clearLayer(layer: string): void;
45
45
  /** Clear all stacks for all layers (called on full dataset reload). */
46
46
  clearAll(): void;
@@ -67,10 +67,8 @@
67
67
  * const legacy = convertVolumeToIPaintImages(volume);
68
68
  * ```
69
69
  */
70
- export type { Dimensions, RGBAColor, ChannelColorMap, SliceRenderOptions, LayerId, ChannelValue, } 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, } from './types';
71
71
  export { RenderMode, MASK_CHANNEL_COLORS, MASK_CHANNEL_CSS_COLORS, CHANNEL_COLORS, CHANNEL_HEX_COLORS, rgbaToHex, rgbaToCss, } from './types';
72
72
  export { MaskVolume } from './MaskVolume';
73
- export type { IPaintImage, IPaintImages } from './MigrationUtils';
74
- export { convertIPaintImagesToVolume, convertVolumeToIPaintImages, } from './MigrationUtils';
75
73
  export type { MaskDelta } from './UndoManager';
76
74
  export { UndoManager } from './UndoManager';