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,548 +0,0 @@
1
- import { MaskVolume } from "./core/index";
2
- import { switchPencilIcon } from "../utils";
3
- import { enableDownload } from "./coreTools/divControlTools";
4
- export class CommToolsData {
5
- constructor(container, mainAreaContainer, options) {
6
- var _a;
7
- this.baseCanvasesSize = 1;
8
- // Reusable ImageData buffer for zero-allocation slice rendering
9
- this._reusableSliceBuffer = null;
10
- this._reusableBufferWidth = 0;
11
- this._reusableBufferHeight = 0;
12
- /** Whether the keyboard-config dialog is open (suppresses all shortcuts). */
13
- this._configKeyBoard = false;
14
- /** Active keyboard shortcut bindings. */
15
- this._keyboardSettings = {
16
- draw: "Shift",
17
- undo: "z",
18
- redo: "y",
19
- contrast: ["Control", "Meta"],
20
- crosshair: "s",
21
- mouseWheel: "Scroll:Zoom",
22
- };
23
- this.nrrd_states = {
24
- originWidth: 0,
25
- originHeight: 0,
26
- nrrd_x_mm: 0,
27
- nrrd_y_mm: 0,
28
- nrrd_z_mm: 0,
29
- nrrd_x_pixel: 0,
30
- nrrd_y_pixel: 0,
31
- nrrd_z_pixel: 0,
32
- changedWidth: 0,
33
- changedHeight: 0,
34
- oldIndex: 0,
35
- currentIndex: 0,
36
- maxIndex: 0,
37
- minIndex: 0,
38
- RSARatio: 0,
39
- voxelSpacing: [],
40
- spaceOrigin: [],
41
- dimensions: [],
42
- loadMaskJson: false,
43
- ratios: { x: 1, y: 1, z: 1 },
44
- contrastNum: 0,
45
- showContrast: false,
46
- isCursorSelect: false,
47
- cursorPageX: 0,
48
- cursorPageY: 0,
49
- sphereOrigin: { x: [0, 0, 0], y: [0, 0, 0], z: [0, 0, 0] },
50
- tumourSphereOrigin: null,
51
- skinSphereOrigin: null,
52
- ribSphereOrigin: null,
53
- nippleSphereOrigin: null,
54
- tumourColor: "#00ff00",
55
- skinColor: "#FFEB3B",
56
- ribcageColor: "#2196F3",
57
- nippleColor: "#E91E63",
58
- spherePlanB: true,
59
- sphereRadius: 5,
60
- Mouse_Over_x: 0,
61
- Mouse_Over_y: 0,
62
- Mouse_Over: false,
63
- stepClear: 1,
64
- sizeFoctor: this.baseCanvasesSize,
65
- clearAllFlag: false,
66
- previousPanelL: -99999,
67
- previousPanelT: -99999,
68
- switchSliceFlag: false,
69
- layers: ["layer1", "layer2", "layer3"],
70
- getMask: (sliceData, layerId, channelId, sliceIndex, axis, width, height, clearFlag) => { },
71
- onClearLayerVolume: (layerId) => { },
72
- onChannelColorChanged: () => { },
73
- getSphere: (sphereOrigin, sphereRadius) => { },
74
- getCalculateSpherePositions: (tumourSphereOrigin, skinSphereOrigin, ribSphereOrigin, nippleSphereOrigin, aixs) => { },
75
- drawStartPos: { x: 1, y: 1 },
76
- };
77
- this.cursorPage = {
78
- x: {
79
- cursorPageX: 0,
80
- cursorPageY: 0,
81
- index: 0,
82
- updated: false,
83
- },
84
- y: {
85
- cursorPageX: 0,
86
- cursorPageY: 0,
87
- index: 0,
88
- updated: false,
89
- },
90
- z: {
91
- cursorPageX: 0,
92
- cursorPageY: 0,
93
- index: 0,
94
- updated: false,
95
- },
96
- };
97
- this.gui_states = {
98
- mainAreaSize: 3,
99
- dragSensitivity: 75,
100
- Eraser: false,
101
- globalAlpha: 0.6,
102
- lineWidth: 2,
103
- color: "#f50a33",
104
- pencil: true,
105
- fillColor: "#00ff00",
106
- brushColor: "#00ff00",
107
- brushAndEraserSize: 10,
108
- cursor: "dot",
109
- layer: "layer1",
110
- cal_distance: "tumour",
111
- sphere: false,
112
- calculator: false,
113
- readyToUpdate: true,
114
- defaultPaintCursor: switchPencilIcon("dot"),
115
- max_sensitive: 100,
116
- // EraserSize: 25,
117
- clear: () => {
118
- this.clearPaint();
119
- },
120
- clearAll: () => {
121
- const text = "Are you sure remove annotations on All slice?";
122
- if (confirm(text) === true) {
123
- this.nrrd_states.clearAllFlag = true;
124
- this.clearPaint();
125
- this.clearStoreImages();
126
- }
127
- this.nrrd_states.clearAllFlag = false;
128
- },
129
- undo: () => {
130
- this.undoLastPainting();
131
- },
132
- redo: () => {
133
- this.redoLastPainting();
134
- },
135
- downloadCurrentMask: () => {
136
- const config = {
137
- axis: this.protectedData.axis,
138
- currentIndex: this.nrrd_states.currentIndex,
139
- drawingCanvas: this.protectedData.canvases.drawingCanvas,
140
- originWidth: this.nrrd_states.originWidth,
141
- originHeight: this.nrrd_states.originHeight,
142
- };
143
- enableDownload(config);
144
- },
145
- resetZoom: () => {
146
- this.nrrd_states.sizeFoctor = this.baseCanvasesSize;
147
- this.gui_states.mainAreaSize = this.baseCanvasesSize;
148
- this.resizePaintArea(this.nrrd_states.sizeFoctor);
149
- this.resetPaintAreaUIPosition();
150
- },
151
- activeChannel: 1,
152
- layerVisibility: { layer1: true, layer2: true, layer3: true },
153
- channelVisibility: {
154
- layer1: { 1: true, 2: true, 3: true, 4: true, 5: true, 6: true, 7: true, 8: true },
155
- layer2: { 1: true, 2: true, 3: true, 4: true, 5: true, 6: true, 7: true, 8: true },
156
- layer3: { 1: true, 2: true, 3: true, 4: true, 5: true, 6: true, 7: true, 8: true },
157
- },
158
- };
159
- const layers = (_a = options === null || options === void 0 ? void 0 : options.layers) !== null && _a !== void 0 ? _a : ["layer1", "layer2", "layer3"];
160
- if (layers.length > 10) {
161
- console.warn(`CommToolsData: ${layers.length} layers requested; recommended maximum is 10.`);
162
- }
163
- // Override the default states with the actual layer list
164
- this.nrrd_states.layers = layers;
165
- this.gui_states.layerVisibility = Object.fromEntries(layers.map((id) => [id, true]));
166
- this.gui_states.channelVisibility = Object.fromEntries(layers.map((id) => [
167
- id,
168
- { 1: true, 2: true, 3: true, 4: true, 5: true, 6: true, 7: true, 8: true },
169
- ]));
170
- const systemCanvases = this.generateSystemCanvases();
171
- const layerTargets = this.generateLayerTargets(layers);
172
- // Get NRRD dimensions (will be set later when NRRD loads)
173
- // Default to 1x1x1 for now, will be re-initialized in NrrdTools when dimensions are known
174
- const dims = this.nrrd_states.dimensions;
175
- const [width, height, depth] = dims.length === 3 ? dims : [1, 1, 1];
176
- this.protectedData = {
177
- container,
178
- mainAreaContainer,
179
- allSlicesArray: [],
180
- displaySlices: [],
181
- backUpDisplaySlices: [],
182
- skipSlicesDic: {},
183
- currentShowingSlice: undefined,
184
- mainPreSlices: undefined,
185
- Is_Draw: false,
186
- axis: "z",
187
- maskData: {
188
- // Volumetric storage (Phase 3 — only storage mechanism)
189
- volumes: layers.reduce((acc, id) => {
190
- acc[id] = new MaskVolume(width, height, depth, 1);
191
- return acc;
192
- }, {}),
193
- },
194
- layerTargets,
195
- canvases: {
196
- /**
197
- * Caches raw image data from the current slice.
198
- * Used as a source for zoom/pan operations to avoid repeated decoding.
199
- * Initialized as null, set in NrrdTools.ts.
200
- */
201
- originCanvas: null,
202
- /**
203
- * Top-most interaction layer.
204
- * Captures mouse/pen events and displays real-time drawing strokes
205
- * before they are committed to a specific layer.
206
- */
207
- drawingCanvas: systemCanvases.drawingCanvas,
208
- /**
209
- * Background layer displaying the actual medical image slice (CT/MRI).
210
- * This is the "base" image the user sees.
211
- */
212
- displayCanvas: systemCanvases.displayCanvas,
213
- /**
214
- * Composite display layer.
215
- * Merges all segmentation layers for unified visualization
216
- * on top of the medical image.
217
- */
218
- drawingCanvasLayerMaster: systemCanvases.drawingCanvasLayerMaster,
219
- /**
220
- * Dedicated layer for 3D Sphere tool visualization.
221
- * Kept separate to allow independent rendering of sphere UI elements.
222
- */
223
- drawingSphereCanvas: systemCanvases.drawingSphereCanvas,
224
- /**
225
- * Off-screen scratchpad canvas.
226
- * Used for internal image processing, scaling, and format conversion.
227
- */
228
- emptyCanvas: systemCanvases.emptyCanvas,
229
- },
230
- ctxes: {
231
- drawingCtx: systemCanvases.drawingCanvas.getContext("2d"),
232
- displayCtx: systemCanvases.displayCanvas.getContext("2d"),
233
- drawingLayerMasterCtx: systemCanvases.drawingCanvasLayerMaster.getContext("2d"),
234
- drawingSphereCtx: systemCanvases.drawingSphereCanvas.getContext("2d"),
235
- emptyCtx: systemCanvases.emptyCanvas.getContext("2d", {
236
- willReadFrequently: true,
237
- }),
238
- },
239
- };
240
- }
241
- // ── Volume Accessor Helpers (Phase 2) ──────────────────────────────────
242
- /**
243
- * Get MaskVolume for a specific layer
244
- *
245
- * @param layer - Layer name: "layer1", "layer2", or "layer3"
246
- * @returns MaskVolume instance for the specified layer
247
- *
248
- * @example
249
- * ```ts
250
- * const volume = this.getVolumeForLayer("layer1");
251
- * volume.setVoxel(x, y, z, 255);
252
- * ```
253
- */
254
- getVolumeForLayer(layer) {
255
- const { volumes } = this.protectedData.maskData;
256
- const vol = volumes[layer];
257
- if (vol)
258
- return vol;
259
- const firstLayerId = this.nrrd_states.layers[0];
260
- console.warn(`CommToolsData: unknown layer "${layer}", falling back to "${firstLayerId}"`);
261
- return volumes[firstLayerId];
262
- }
263
- /**
264
- * Get MaskVolume for the currently active layer
265
- *
266
- * @returns MaskVolume instance for the current layer
267
- *
268
- * @example
269
- * ```ts
270
- * const volume = this.getCurrentVolume();
271
- * const slice = volume.getSliceImageData(50, 'z');
272
- * ```
273
- */
274
- getCurrentVolume() {
275
- return this.getVolumeForLayer(this.gui_states.layer);
276
- }
277
- /**
278
- * Get all three MaskVolume instances
279
- *
280
- * @returns Object containing all three layer volumes
281
- *
282
- * @example
283
- * ```ts
284
- * const { layer1, layer2, layer3 } = this.getAllVolumes();
285
- * layer1.clear();
286
- * ```
287
- */
288
- getAllVolumes() {
289
- return this.protectedData.maskData.volumes;
290
- }
291
- // ───────────────────────────────────────────────────────────────────────
292
- generateSystemCanvases() {
293
- return {
294
- drawingCanvas: document.createElement("canvas"),
295
- displayCanvas: document.createElement("canvas"),
296
- drawingCanvasLayerMaster: document.createElement("canvas"),
297
- drawingSphereCanvas: document.createElement("canvas"),
298
- emptyCanvas: document.createElement("canvas"),
299
- };
300
- }
301
- generateLayerTargets(layerIds) {
302
- const map = new Map();
303
- for (const id of layerIds) {
304
- const canvas = document.createElement("canvas");
305
- const ctx = canvas.getContext("2d");
306
- map.set(id, { canvas, ctx });
307
- }
308
- return map;
309
- }
310
- /**
311
- * Rewrite this {clearPaint} function under DrawToolCore
312
- */
313
- clearPaint() {
314
- throw new Error("Child class must implement abstract clearPaint, currently you can find it in DrawToolCore.");
315
- }
316
- /**
317
- * Rewrite this {undoLastPainting} function under DrawToolCore
318
- */
319
- undoLastPainting() {
320
- throw new Error("Child class must implement abstract undoLastPainting, currently you can find it in DrawToolCore.");
321
- }
322
- /**
323
- * Rewrite this {redoLastPainting} function under DrawToolCore
324
- */
325
- redoLastPainting() {
326
- throw new Error("Child class must implement abstract redoLastPainting, currently you can find it in DrawToolCore.");
327
- }
328
- /**
329
- * Rewrite this {clearStoreImages} function under NrrdTools
330
- */
331
- clearStoreImages() {
332
- throw new Error("Child class must implement abstract clearStoreImages, currently you can find it in NrrdTools.");
333
- }
334
- /**
335
- * Rewrite this {resizePaintArea} function under NrrdTools
336
- */
337
- resizePaintArea(factor) {
338
- throw new Error("Child class must implement abstract resizePaintArea, currently you can find it in NrrdTools.");
339
- }
340
- /**
341
- * Rewrite this {setIsDrawFalse} function under NrrdTools
342
- */
343
- setIsDrawFalse(target) {
344
- throw new Error("Child class must implement abstract setIsDrawFalse, currently you can find it in NrrdTools.");
345
- }
346
- /**
347
- * Rewrite this {updateOriginAndChangedWH} function under NrrdTools
348
- */
349
- updateOriginAndChangedWH() {
350
- throw new Error("Child class must implement abstract updateOriginAndChangedWH, currently you can find it in NrrdTools.");
351
- }
352
- /**
353
- * Rewrite this {flipDisplayImageByAxis} function under NrrdTools
354
- */
355
- flipDisplayImageByAxis() {
356
- throw new Error("Child class must implement abstract flipDisplayImageByAxis, currently you can find it in NrrdTools.");
357
- }
358
- /**
359
- * Rewrite this {resetPaintAreaUIPosition} function under NrrdTools
360
- */
361
- resetPaintAreaUIPosition(l, t) {
362
- throw new Error("Child class must implement abstract resetPaintAreaUIPosition, currently you can find it in NrrdTools.");
363
- }
364
- /**
365
- * Rewrite this {resetPaintAreaUIPosition} function under NrrdTools
366
- */
367
- setEmptyCanvasSize(axis) {
368
- throw new Error("Child class must implement abstract setEmptyCanvasSize, currently you can find it in NrrdTools.");
369
- }
370
- /**
371
- * Rewrite this {convertCursorPoint} function under NrrdTools
372
- */
373
- convertCursorPoint(from, to, cursorNumX, cursorNumY, currentSliceIndex) {
374
- throw new Error("Child class must implement abstract convertCursorPoint, currently you can find it in NrrdTools.");
375
- }
376
- /**
377
- * Rewrite this {resetLayerCanvas} function under NrrdTools
378
- */
379
- resetLayerCanvas() {
380
- throw new Error("Child class must implement abstract resetLayerCanvas, currently you can find it in NrrdTools.");
381
- }
382
- /**
383
- * Rewrite this {setSyncsliceNum} function under NrrdTools
384
- */
385
- setSyncsliceNum() {
386
- throw new Error("Child class must implement abstract setSyncsliceNum, currently you can find it in NrrdTools.");
387
- }
388
- /**
389
- * Rewrite this {redrawDisplayCanvas} function under NrrdTools
390
- */
391
- redrawDisplayCanvas() {
392
- throw new Error("Child class must implement abstract redrawDisplayCanvas, currently you can find it in NrrdTools.");
393
- }
394
- /**
395
- * Get a painted mask image based on current axis and input slice index.
396
- *
397
- * Phase 3: Reads directly from MaskVolume.
398
- *
399
- * @param axis "x" | "y" | "z"
400
- * @param sliceIndex number
401
- * @returns Object with index and image, or undefined
402
- */
403
- filterDrawedImage(axis, sliceIndex) {
404
- try {
405
- const volume = this.getCurrentVolume();
406
- if (volume) {
407
- const dims = volume.getDimensions();
408
- const [w, h] = axis === 'z' ? [dims.width, dims.height]
409
- : axis === 'y' ? [dims.width, dims.depth]
410
- // Sagittal: width = depth (Z), height = height (Y)
411
- : [dims.depth, dims.height];
412
- const imageData = new ImageData(w, h);
413
- const channelVis = this.gui_states.channelVisibility[this.gui_states.layer];
414
- volume.renderLabelSliceInto(sliceIndex, axis, imageData, channelVis);
415
- return { index: sliceIndex, image: imageData };
416
- }
417
- }
418
- catch (err) {
419
- // Volume not ready or slice out of bounds
420
- }
421
- return undefined;
422
- }
423
- /**
424
- * Get or create a reusable ImageData buffer for the given axis.
425
- *
426
- * Reuses the same buffer across multiple slice renders to avoid
427
- * allocating a new ImageData per layer per slice switch.
428
- * The buffer is only reallocated when slice dimensions change (axis switch).
429
- *
430
- * @param axis - Axis: "x", "y", or "z"
431
- * @returns Reusable ImageData buffer with correct dimensions
432
- */
433
- getOrCreateSliceBuffer(axis) {
434
- try {
435
- const vol = this.getVolumeForLayer(this.nrrd_states.layers[0]);
436
- const dims = vol.getDimensions();
437
- const [w, h] = axis === "z" ? [dims.width, dims.height] :
438
- axis === "y" ? [dims.width, dims.depth] :
439
- // Sagittal: width = depth (Z), height = height (Y)
440
- // Matches setEmptyCanvasSize('x') and MaskVolume.getSliceDimensions('x')
441
- [dims.depth, dims.height];
442
- if (!this._reusableSliceBuffer ||
443
- this._reusableBufferWidth !== w ||
444
- this._reusableBufferHeight !== h) {
445
- this._reusableSliceBuffer = new ImageData(w, h);
446
- this._reusableBufferWidth = w;
447
- this._reusableBufferHeight = h;
448
- }
449
- return this._reusableSliceBuffer;
450
- }
451
- catch (_a) {
452
- return null; // Volume not ready
453
- }
454
- }
455
- /**
456
- * Render a layer's slice into a reusable buffer and draw to the target canvas.
457
- *
458
- * Uses MaskVolume.renderLabelSliceInto() for zero-allocation rendering.
459
- * The caller should obtain the buffer via getOrCreateSliceBuffer() and reuse
460
- * it across multiple layer renders.
461
- *
462
- * @param layer - Layer name: "layer1", "layer2", or "layer3"
463
- * @param axis - Axis: "x", "y", or "z"
464
- * @param sliceIndex - Slice index
465
- * @param buffer - Reusable ImageData buffer (from getOrCreateSliceBuffer)
466
- * @param targetCtx - Canvas context to draw the result onto
467
- * @param scaledWidth - Target display width
468
- * @param scaledHeight - Target display height
469
- */
470
- renderSliceToCanvas(layer, axis, sliceIndex, buffer, targetCtx, scaledWidth, scaledHeight) {
471
- try {
472
- const volume = this.getVolumeForLayer(layer);
473
- if (!volume)
474
- return;
475
- // Get channel visibility for this layer
476
- const channelVis = this.gui_states.channelVisibility[layer];
477
- // Render label slice at full alpha — globalAlpha applied during compositeAllLayers
478
- volume.renderLabelSliceInto(sliceIndex, axis, buffer, channelVis, 1.0);
479
- this.setEmptyCanvasSize(axis);
480
- this.protectedData.ctxes.emptyCtx.putImageData(buffer, 0, 0);
481
- // No flip: MaskVolume stores in source coordinates matching the Three.js
482
- // slice convention. Applying a display flip here would invert cross-axis
483
- // slice indices (e.g. coronal 220 → 228 for a 448-slice volume).
484
- targetCtx.imageSmoothingEnabled = false;
485
- targetCtx.drawImage(this.protectedData.canvases.emptyCanvas, 0, 0, scaledWidth, scaledHeight);
486
- }
487
- catch (err) {
488
- // Slice out of bounds or volume not ready — skip silently
489
- }
490
- }
491
- /**
492
- * Invalidate the reusable buffer (e.g. when switching datasets).
493
- * The buffer will be lazily recreated on next use.
494
- */
495
- invalidateSliceBuffer() {
496
- this._reusableSliceBuffer = null;
497
- this._reusableBufferWidth = 0;
498
- this._reusableBufferHeight = 0;
499
- }
500
- /**
501
- * Apply the same flip transform used by flipDisplayImageByAxis() to any
502
- * canvas context. This ensures mask overlays align with the flipped CT image.
503
- *
504
- * The flip is its own inverse (applying twice = identity), so it works for
505
- * both directions: volume→display (rendering) and display→volume (storing).
506
- *
507
- * @param ctx Target 2D context (must be wrapped in save/restore by caller).
508
- * @param width Canvas width in pixels.
509
- * @param height Canvas height in pixels.
510
- * @param axis Current viewing axis.
511
- */
512
- applyMaskFlipForAxis(ctx, width, height, axis) {
513
- switch (axis) {
514
- case "x": // sagittal: flip both axes
515
- ctx.scale(-1, -1);
516
- ctx.translate(-width, -height);
517
- break;
518
- case "y": // coronal: flip vertically
519
- ctx.scale(1, -1);
520
- ctx.translate(0, -height);
521
- break;
522
- case "z": // axial: flip vertically
523
- ctx.scale(1, -1);
524
- ctx.translate(0, -height);
525
- break;
526
- }
527
- }
528
- /**
529
- * Composite all layer canvases to the master display canvas.
530
- * Only draws layers whose visibility is enabled.
531
- */
532
- compositeAllLayers() {
533
- const masterCtx = this.protectedData.ctxes.drawingLayerMasterCtx;
534
- const width = this.nrrd_states.changedWidth;
535
- const height = this.nrrd_states.changedHeight;
536
- masterCtx.clearRect(0, 0, width, height);
537
- // Master stores full-alpha composite; globalAlpha is applied once in
538
- // start() when drawing master to drawingCtx (single point of control).
539
- for (const layerId of this.nrrd_states.layers) {
540
- if (!this.gui_states.layerVisibility[layerId])
541
- continue;
542
- const target = this.protectedData.layerTargets.get(layerId);
543
- if (target)
544
- masterCtx.drawImage(target.canvas, 0, 0, width, height);
545
- }
546
- }
547
- }
548
- //# sourceMappingURL=CommToolsData.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"CommToolsData.js","sourceRoot":"","sources":["../../../src/Utils/segmentation/CommToolsData.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAC5C,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AAK,EAAE,MAAM,CAAC,CAAC;QAEzC,qEAAqE;QACrE,uEAAuE;QACvE,KAAK,MAAM,OAAO,IAAI,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE;YAC7C,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,eAAe,CAAC,OAAO,CAAC;gBAAE,SAAS;YACxD,MAAM,MAAM,GAAG,IAAI,CAAC,aAAa,CAAC,YAAY,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;YAC5D,IAAI,MAAM;gBAAE,SAAS,CAAC,SAAS,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;SACrE;IACH,CAAC;CACF"}
@@ -1,97 +0,0 @@
1
- /**
2
- * Migration Utilities for MaskVolume
3
- *
4
- * Provides bidirectional conversion between the legacy per-slice
5
- * ImageData storage (`IPaintImages`) and the new contiguous 3D
6
- * volumetric storage (`MaskVolume`).
7
- *
8
- * These utilities enable:
9
- * - **Forward migration**: Import existing annotation data into MaskVolume.
10
- * - **Rollback compatibility**: Export MaskVolume back to IPaintImages.
11
- *
12
- * @example
13
- * ```ts
14
- * // Forward: legacy → volume
15
- * const volume = convertIPaintImagesToVolume(paintImages, { width: 512, height: 512, depth: 100 });
16
- *
17
- * // Backward: volume → legacy
18
- * const legacy = convertVolumeToIPaintImages(volume);
19
- * ```
20
- */
21
- import type { Dimensions } from './types';
22
- import { MaskVolume } from './MaskVolume';
23
- /**
24
- * A single painted slice (legacy format).
25
- */
26
- export interface IPaintImage {
27
- index: number;
28
- image: ImageData;
29
- }
30
- /**
31
- * Per-axis collection of painted slices (legacy format).
32
- */
33
- export interface IPaintImages {
34
- x: IPaintImage[];
35
- y: IPaintImage[];
36
- z: IPaintImage[];
37
- }
38
- /**
39
- * Convert legacy per-slice ImageData storage into a MaskVolume.
40
- *
41
- * The function iterates over all three axes (`x`, `y`, `z`) and inserts
42
- * each slice into the volume using `setSliceFromImageData`.
43
- *
44
- * **Sparse data handling**: Slices that are absent from the arrays are
45
- * left as zero (the MaskVolume default). Duplicate indices are
46
- * overwritten in order (last wins).
47
- *
48
- * @param paintImages Legacy per-axis slice collection.
49
- * @param dimensions Volume dimensions (must match the ImageData sizes).
50
- * @param channel Target channel in the volume (default 0).
51
- *
52
- * @returns A new MaskVolume populated with the legacy data.
53
- *
54
- * @throws {Error} If a slice's ImageData dimensions don't match the
55
- * expected size for its axis.
56
- *
57
- * @example
58
- * ```ts
59
- * const volume = convertIPaintImagesToVolume(
60
- * maskData.paintImagesLayer1,
61
- * { width: 512, height: 512, depth: 100 },
62
- * );
63
- * ```
64
- */
65
- export declare function convertIPaintImagesToVolume(paintImages: IPaintImages, dimensions: Dimensions, channel?: number): MaskVolume;
66
- /**
67
- * Convert a MaskVolume back to legacy per-slice ImageData storage.
68
- *
69
- * Extracts **all** slices along the Z axis (axial) into an
70
- * `IPaintImages` structure. X and Y axes are left as empty arrays
71
- * since the legacy system can reconstruct them on demand.
72
- *
73
- * Only non-empty slices (those containing at least one non-zero pixel)
74
- * are included, matching the sparse behaviour of the original storage.
75
- *
76
- * @param volume The MaskVolume to export.
77
- * @param channel Channel to extract (default 0).
78
- * @param options Export options.
79
- * @param options.includeAllAxes If true, also export X and Y axis slices
80
- * (expensive — use only if needed for full
81
- * backward compatibility). Default: false.
82
- * @param options.includeEmpty If true, include slices that are entirely
83
- * zero. Default: false.
84
- *
85
- * @returns A legacy IPaintImages structure.
86
- *
87
- * @example
88
- * ```ts
89
- * const legacy = convertVolumeToIPaintImages(volume);
90
- * // legacy.z contains non-empty axial slices
91
- * // legacy.x and legacy.y are empty by default
92
- * ```
93
- */
94
- export declare function convertVolumeToIPaintImages(volume: MaskVolume, channel?: number, options?: {
95
- includeAllAxes?: boolean;
96
- includeEmpty?: boolean;
97
- }): IPaintImages;