copper3d 2.2.3 → 3.0.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 (111) hide show
  1. package/README.md +1056 -5
  2. package/dist/Scene/copperScene.d.ts +3 -0
  3. package/dist/Scene/copperScene.js +13 -0
  4. package/dist/Scene/copperScene.js.map +1 -1
  5. package/dist/Utils/segmentation/CommToolsData.d.ts +109 -6
  6. package/dist/Utils/segmentation/CommToolsData.js +314 -50
  7. package/dist/Utils/segmentation/CommToolsData.js.map +1 -1
  8. package/dist/Utils/segmentation/DragOperator.d.ts +13 -7
  9. package/dist/Utils/segmentation/DragOperator.js +51 -165
  10. package/dist/Utils/segmentation/DragOperator.js.map +1 -1
  11. package/dist/Utils/segmentation/DrawToolCore.d.ts +57 -76
  12. package/dist/Utils/segmentation/DrawToolCore.js +368 -878
  13. package/dist/Utils/segmentation/DrawToolCore.js.map +1 -1
  14. package/dist/Utils/segmentation/NrrdTools.d.ts +277 -15
  15. package/dist/Utils/segmentation/NrrdTools.js +594 -232
  16. package/dist/Utils/segmentation/NrrdTools.js.map +1 -1
  17. package/dist/Utils/segmentation/core/MaskVolume.d.ts +477 -0
  18. package/dist/Utils/segmentation/core/MaskVolume.js +1238 -0
  19. package/dist/Utils/segmentation/core/MaskVolume.js.map +1 -0
  20. package/dist/Utils/segmentation/core/MigrationUtils.d.ts +97 -0
  21. package/dist/Utils/segmentation/core/MigrationUtils.js +163 -0
  22. package/dist/Utils/segmentation/core/MigrationUtils.js.map +1 -0
  23. package/dist/Utils/segmentation/core/UndoManager.d.ts +47 -0
  24. package/dist/Utils/segmentation/core/UndoManager.js +86 -0
  25. package/dist/Utils/segmentation/core/UndoManager.js.map +1 -0
  26. package/dist/Utils/segmentation/core/index.d.ts +76 -0
  27. package/dist/Utils/segmentation/core/index.js +75 -0
  28. package/dist/Utils/segmentation/core/index.js.map +1 -0
  29. package/dist/Utils/segmentation/core/types.d.ts +106 -0
  30. package/dist/Utils/segmentation/core/types.js +98 -0
  31. package/dist/Utils/segmentation/core/types.js.map +1 -0
  32. package/dist/Utils/segmentation/coreTools/coreType.d.ts +55 -36
  33. package/dist/Utils/segmentation/coreTools/coreType.js.map +1 -1
  34. package/dist/Utils/segmentation/coreTools/gui.d.ts +6 -16
  35. package/dist/Utils/segmentation/coreTools/gui.js +23 -27
  36. package/dist/Utils/segmentation/coreTools/gui.js.map +1 -1
  37. package/dist/Utils/segmentation/eventRouter/EventRouter.d.ts +144 -0
  38. package/dist/Utils/segmentation/eventRouter/EventRouter.js +369 -0
  39. package/dist/Utils/segmentation/eventRouter/EventRouter.js.map +1 -0
  40. package/dist/Utils/segmentation/eventRouter/index.d.ts +7 -0
  41. package/dist/Utils/segmentation/eventRouter/index.js +7 -0
  42. package/dist/Utils/segmentation/eventRouter/index.js.map +1 -0
  43. package/dist/Utils/segmentation/eventRouter/types.d.ts +70 -0
  44. package/dist/Utils/segmentation/eventRouter/types.js +7 -0
  45. package/dist/Utils/segmentation/eventRouter/types.js.map +1 -0
  46. package/dist/Utils/segmentation/tools/BaseTool.d.ts +25 -0
  47. package/dist/Utils/segmentation/tools/BaseTool.js +18 -0
  48. package/dist/Utils/segmentation/tools/BaseTool.js.map +1 -0
  49. package/dist/Utils/segmentation/tools/ContrastTool.d.ts +26 -0
  50. package/dist/Utils/segmentation/tools/ContrastTool.js +118 -0
  51. package/dist/Utils/segmentation/tools/ContrastTool.js.map +1 -0
  52. package/dist/Utils/segmentation/tools/CrosshairTool.d.ts +30 -0
  53. package/dist/Utils/segmentation/tools/CrosshairTool.js +157 -0
  54. package/dist/Utils/segmentation/tools/CrosshairTool.js.map +1 -0
  55. package/dist/Utils/segmentation/tools/DragSliceTool.d.ts +44 -0
  56. package/dist/Utils/segmentation/tools/DragSliceTool.js +170 -0
  57. package/dist/Utils/segmentation/tools/DragSliceTool.js.map +1 -0
  58. package/dist/Utils/segmentation/tools/EraserTool.d.ts +16 -0
  59. package/dist/Utils/segmentation/tools/EraserTool.js +92 -0
  60. package/dist/Utils/segmentation/tools/EraserTool.js.map +1 -0
  61. package/dist/Utils/segmentation/tools/ImageStoreHelper.d.ts +65 -0
  62. package/dist/Utils/segmentation/tools/ImageStoreHelper.js +174 -0
  63. package/dist/Utils/segmentation/tools/ImageStoreHelper.js.map +1 -0
  64. package/dist/Utils/segmentation/tools/SphereTool.d.ts +38 -0
  65. package/dist/Utils/segmentation/tools/SphereTool.js +193 -0
  66. package/dist/Utils/segmentation/tools/SphereTool.js.map +1 -0
  67. package/dist/Utils/segmentation/tools/ZoomTool.d.ts +20 -0
  68. package/dist/Utils/segmentation/tools/ZoomTool.js +59 -0
  69. package/dist/Utils/segmentation/tools/ZoomTool.js.map +1 -0
  70. package/dist/Utils/segmentation/tools/index.d.ts +22 -0
  71. package/dist/Utils/segmentation/tools/index.js +23 -0
  72. package/dist/Utils/segmentation/tools/index.js.map +1 -0
  73. package/dist/bundle.esm.js +4740 -1979
  74. package/dist/bundle.umd.js +4743 -1978
  75. package/dist/index.d.ts +5 -3
  76. package/dist/index.js +4 -2
  77. package/dist/index.js.map +1 -1
  78. package/dist/types/Renderer/copperRenderer.d.ts +1 -1
  79. package/dist/types/Renderer/copperRendererOnDemond.d.ts +1 -1
  80. package/dist/types/Scene/copperScene.d.ts +3 -0
  81. package/dist/types/Utils/segmentation/CommToolsData.d.ts +109 -6
  82. package/dist/types/Utils/segmentation/DragOperator.d.ts +13 -7
  83. package/dist/types/Utils/segmentation/DrawToolCore.d.ts +57 -76
  84. package/dist/types/Utils/segmentation/NrrdTools.d.ts +277 -15
  85. package/dist/types/Utils/segmentation/core/MaskVolume.d.ts +477 -0
  86. package/dist/types/Utils/segmentation/core/MigrationUtils.d.ts +97 -0
  87. package/dist/types/Utils/segmentation/core/UndoManager.d.ts +47 -0
  88. package/dist/types/Utils/segmentation/core/index.d.ts +76 -0
  89. package/dist/types/Utils/segmentation/core/types.d.ts +106 -0
  90. package/dist/types/Utils/segmentation/coreTools/coreType.d.ts +55 -36
  91. package/dist/types/Utils/segmentation/coreTools/gui.d.ts +6 -16
  92. package/dist/types/Utils/segmentation/eventRouter/EventRouter.d.ts +144 -0
  93. package/dist/types/Utils/segmentation/eventRouter/index.d.ts +7 -0
  94. package/dist/types/Utils/segmentation/eventRouter/types.d.ts +70 -0
  95. package/dist/types/Utils/segmentation/tools/BaseTool.d.ts +25 -0
  96. package/dist/types/Utils/segmentation/tools/ContrastTool.d.ts +26 -0
  97. package/dist/types/Utils/segmentation/tools/CrosshairTool.d.ts +30 -0
  98. package/dist/types/Utils/segmentation/tools/DragSliceTool.d.ts +44 -0
  99. package/dist/types/Utils/segmentation/tools/EraserTool.d.ts +16 -0
  100. package/dist/types/Utils/segmentation/tools/ImageStoreHelper.d.ts +65 -0
  101. package/dist/types/Utils/segmentation/tools/SphereTool.d.ts +38 -0
  102. package/dist/types/Utils/segmentation/tools/ZoomTool.d.ts +20 -0
  103. package/dist/types/Utils/segmentation/tools/index.d.ts +22 -0
  104. package/dist/types/index.d.ts +5 -3
  105. package/dist/types/types/types.d.ts +3 -3
  106. package/dist/types/types.d.ts +3 -3
  107. package/package.json +1 -1
  108. package/dist/Utils/segmentation/coreTools/archive.d.ts +0 -1
  109. package/dist/Utils/segmentation/coreTools/archive.js +0 -23
  110. package/dist/Utils/segmentation/coreTools/archive.js.map +0 -1
  111. package/dist/types/Utils/segmentation/coreTools/archive.d.ts +0 -1
@@ -1,17 +1,33 @@
1
1
  import { nrrdSliceType, storeExportPaintImageType, loadingBarType } from "../../types/types";
2
2
  import { GUI } from "dat.gui";
3
- import { IPaintImages, IStoredPaintImages, IMaskData, IDragOpts, IGuiParameterSettings } from "./coreTools/coreType";
3
+ import { IMaskData, IDragOpts, IGuiParameterSettings, IKeyBoardSettings } from "./coreTools/coreType";
4
4
  import { DragOperator } from "./DragOperator";
5
5
  import { DrawToolCore } from "./DrawToolCore";
6
+ import type { ChannelValue, RGBAColor, ChannelColorMap } from "./core";
7
+ /**
8
+ * Core NRRD annotation tool for medical image segmentation.
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * // Default 3 layers: layer1, layer2, layer3
13
+ * const tools = new NrrdTools(container);
14
+ *
15
+ * // Custom layers
16
+ * const tools = new NrrdTools(container, { layers: ["layer1", "layer2"] });
17
+ * ```
18
+ */
6
19
  export declare class NrrdTools extends DrawToolCore {
7
20
  container: HTMLDivElement;
8
21
  dragOperator: DragOperator;
9
- storedPaintImages: IStoredPaintImages | undefined;
10
22
  private paintedImage;
11
23
  private initState;
12
24
  private preTimer;
13
25
  private guiParameterSettings;
14
- constructor(container: HTMLDivElement);
26
+ private _sliceRAFId;
27
+ private _pendingSliceStep;
28
+ constructor(container: HTMLDivElement, options?: {
29
+ layers?: string[];
30
+ });
15
31
  /**
16
32
  * core function for drag slices
17
33
  * @param opts
@@ -37,6 +53,250 @@ export declare class NrrdTools extends DrawToolCore {
37
53
  guiState: import("./coreTools/coreType").IGUIStates;
38
54
  guiSetting: IGuiParameterSettings | undefined;
39
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
+ /**
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
+ */
197
+ 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
+ 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
+ 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
+ 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
+ setContrastShortcutEnabled(enabled: boolean): void;
257
+ /**
258
+ * Returns whether the contrast shortcut is currently enabled.
259
+ */
260
+ 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
+ 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
+ getKeyboardSettings(): IKeyBoardSettings;
40
300
  /**
41
301
  * A initialise function for nrrd_tools
42
302
  */
@@ -54,21 +314,24 @@ export declare class NrrdTools extends DrawToolCore {
54
314
 
55
315
  */
56
316
  setAllSlices(allSlices: Array<nrrdSliceType>): void;
57
- private loadingMaskByLabel;
317
+ private loadingMaskByLayer;
58
318
  setMasksData(masksData: storeExportPaintImageType, loadingBar?: loadingBarType): void;
319
+ /**
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
327
+ */
328
+ setMasksFromNIfTI(layerVoxels: Map<string, Uint8Array>, loadingBar?: loadingBarType): void;
59
329
  private setShowInMainArea;
60
330
  getCurrentImageDimension(): number[];
61
331
  getVoxelSpacing(): number[];
62
332
  getSpaceOrigin(): number[];
63
333
  getMaskData(): IMaskData;
64
334
  setCalculateDistanceSphere(x: number, y: number, sliceIndex: number, cal_position: "tumour" | "skin" | "nipple" | "ribcage"): void;
65
- private getSharedPlace;
66
- /**
67
- * init all painted images for store images
68
- * @param dimensions
69
- */
70
- private initPaintImages;
71
- createEmptyPaintImage(dimensions: Array<number>, paintImages: IPaintImages): void;
72
335
  /**
73
336
  * Switch all contrast slices' orientation
74
337
  * @param {string} aixs:"x" | "y" | "z"
@@ -135,11 +398,10 @@ export declare class NrrdTools extends DrawToolCore {
135
398
  */
136
399
  resizePaintArea(factor: number): void;
137
400
  /**
138
- * Used to init the mask on each label and reload
139
- * @param paintImages
140
- * @param ctx
401
+ * Phase 3: Reload all mask layers from MaskVolume using buffer reuse
402
+ * Replaces the old reloadMaskToLayer approach
141
403
  */
142
- private reloadMaskToLabel;
404
+ private reloadMasksFromVolume;
143
405
  /**
144
406
  * flip the canvas to a correct position.
145
407
  * This is because the slice canvas from threejs is not in a correct 2D postion.