copper3d 3.0.1 → 3.0.2

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 (98) hide show
  1. package/README.md +195 -28
  2. package/dist/Utils/segmentation/CommToolsData.d.ts +24 -9
  3. package/dist/Utils/segmentation/CommToolsData.js +65 -139
  4. package/dist/Utils/segmentation/CommToolsData.js.map +1 -1
  5. package/dist/Utils/segmentation/DragOperator.d.ts +10 -2
  6. package/dist/Utils/segmentation/DragOperator.js +14 -4
  7. package/dist/Utils/segmentation/DragOperator.js.map +1 -1
  8. package/dist/Utils/segmentation/DrawToolCore.d.ts +23 -16
  9. package/dist/Utils/segmentation/DrawToolCore.js +218 -401
  10. package/dist/Utils/segmentation/DrawToolCore.js.map +1 -1
  11. package/dist/Utils/segmentation/NrrdTools.d.ts +152 -10
  12. package/dist/Utils/segmentation/NrrdTools.js +599 -202
  13. package/dist/Utils/segmentation/NrrdTools.js.map +1 -1
  14. package/dist/Utils/segmentation/core/MaskVolume.d.ts +1 -1
  15. package/dist/Utils/segmentation/core/MaskVolume.js +24 -3
  16. package/dist/Utils/segmentation/core/MaskVolume.js.map +1 -1
  17. package/dist/Utils/segmentation/core/UndoManager.d.ts +1 -1
  18. package/dist/Utils/segmentation/core/UndoManager.js +1 -1
  19. package/dist/Utils/segmentation/core/index.d.ts +0 -2
  20. package/dist/Utils/segmentation/core/index.js +0 -1
  21. package/dist/Utils/segmentation/core/index.js.map +1 -1
  22. package/dist/Utils/segmentation/core/types.js +24 -24
  23. package/dist/Utils/segmentation/core/types.js.map +1 -1
  24. package/dist/Utils/segmentation/coreTools/GuiState.d.ts +22 -0
  25. package/dist/Utils/segmentation/coreTools/GuiState.js +48 -0
  26. package/dist/Utils/segmentation/coreTools/GuiState.js.map +1 -0
  27. package/dist/Utils/segmentation/coreTools/NrrdState.d.ts +25 -0
  28. package/dist/Utils/segmentation/coreTools/NrrdState.js +85 -0
  29. package/dist/Utils/segmentation/coreTools/NrrdState.js.map +1 -0
  30. package/dist/Utils/segmentation/coreTools/coreType.d.ts +88 -62
  31. package/dist/Utils/segmentation/coreTools/coreType.js.map +1 -1
  32. package/dist/Utils/segmentation/coreTools/divControlTools.js +1 -1
  33. package/dist/Utils/segmentation/coreTools/divControlTools.js.map +1 -1
  34. package/dist/Utils/segmentation/coreTools/gui.d.ts +12 -12
  35. package/dist/Utils/segmentation/coreTools/gui.js +81 -107
  36. package/dist/Utils/segmentation/coreTools/gui.js.map +1 -1
  37. package/dist/Utils/segmentation/eventRouter/EventRouter.d.ts +2 -1
  38. package/dist/Utils/segmentation/eventRouter/EventRouter.js +15 -10
  39. package/dist/Utils/segmentation/eventRouter/EventRouter.js.map +1 -1
  40. package/dist/Utils/segmentation/eventRouter/types.d.ts +3 -3
  41. package/dist/Utils/segmentation/tools/BaseTool.d.ts +8 -5
  42. package/dist/Utils/segmentation/tools/BaseTool.js +1 -2
  43. package/dist/Utils/segmentation/tools/BaseTool.js.map +1 -1
  44. package/dist/Utils/segmentation/tools/CrosshairTool.js +25 -25
  45. package/dist/Utils/segmentation/tools/CrosshairTool.js.map +1 -1
  46. package/dist/Utils/segmentation/tools/DragSliceTool.d.ts +2 -0
  47. package/dist/Utils/segmentation/tools/DragSliceTool.js +63 -53
  48. package/dist/Utils/segmentation/tools/DragSliceTool.js.map +1 -1
  49. package/dist/Utils/segmentation/tools/DrawingTool.d.ts +93 -0
  50. package/dist/Utils/segmentation/tools/DrawingTool.js +222 -0
  51. package/dist/Utils/segmentation/tools/DrawingTool.js.map +1 -0
  52. package/dist/Utils/segmentation/tools/EraserTool.js +8 -8
  53. package/dist/Utils/segmentation/tools/EraserTool.js.map +1 -1
  54. package/dist/Utils/segmentation/tools/ImageStoreHelper.d.ts +11 -28
  55. package/dist/Utils/segmentation/tools/ImageStoreHelper.js +39 -82
  56. package/dist/Utils/segmentation/tools/ImageStoreHelper.js.map +1 -1
  57. package/dist/Utils/segmentation/tools/PanTool.d.ts +53 -0
  58. package/dist/Utils/segmentation/tools/PanTool.js +90 -0
  59. package/dist/Utils/segmentation/tools/PanTool.js.map +1 -0
  60. package/dist/Utils/segmentation/tools/SphereTool.d.ts +208 -1
  61. package/dist/Utils/segmentation/tools/SphereTool.js +456 -45
  62. package/dist/Utils/segmentation/tools/SphereTool.js.map +1 -1
  63. package/dist/Utils/segmentation/tools/ZoomTool.js +3 -3
  64. package/dist/Utils/segmentation/tools/ZoomTool.js.map +1 -1
  65. package/dist/Utils/segmentation/tools/index.d.ts +6 -2
  66. package/dist/Utils/segmentation/tools/index.js +4 -1
  67. package/dist/Utils/segmentation/tools/index.js.map +1 -1
  68. package/dist/bundle.esm.js +2452 -1492
  69. package/dist/bundle.umd.js +2452 -1492
  70. package/dist/index.d.ts +6 -3
  71. package/dist/index.js +1 -1
  72. package/dist/index.js.map +1 -1
  73. package/dist/types/Utils/segmentation/CommToolsData.d.ts +24 -9
  74. package/dist/types/Utils/segmentation/DragOperator.d.ts +10 -2
  75. package/dist/types/Utils/segmentation/DrawToolCore.d.ts +23 -16
  76. package/dist/types/Utils/segmentation/NrrdTools.d.ts +152 -10
  77. package/dist/types/Utils/segmentation/core/MaskVolume.d.ts +1 -1
  78. package/dist/types/Utils/segmentation/core/UndoManager.d.ts +1 -1
  79. package/dist/types/Utils/segmentation/core/index.d.ts +0 -2
  80. package/dist/types/Utils/segmentation/coreTools/GuiState.d.ts +22 -0
  81. package/dist/types/Utils/segmentation/coreTools/NrrdState.d.ts +25 -0
  82. package/dist/types/Utils/segmentation/coreTools/coreType.d.ts +88 -62
  83. package/dist/types/Utils/segmentation/coreTools/gui.d.ts +12 -12
  84. package/dist/types/Utils/segmentation/eventRouter/EventRouter.d.ts +2 -1
  85. package/dist/types/Utils/segmentation/eventRouter/types.d.ts +3 -3
  86. package/dist/types/Utils/segmentation/tools/BaseTool.d.ts +8 -5
  87. package/dist/types/Utils/segmentation/tools/DragSliceTool.d.ts +2 -0
  88. package/dist/types/Utils/segmentation/tools/DrawingTool.d.ts +93 -0
  89. package/dist/types/Utils/segmentation/tools/ImageStoreHelper.d.ts +11 -28
  90. package/dist/types/Utils/segmentation/tools/PanTool.d.ts +53 -0
  91. package/dist/types/Utils/segmentation/tools/SphereTool.d.ts +208 -1
  92. package/dist/types/Utils/segmentation/tools/index.d.ts +6 -2
  93. package/dist/types/index.d.ts +6 -3
  94. package/package.json +1 -1
  95. package/dist/Utils/segmentation/core/MigrationUtils.d.ts +0 -97
  96. package/dist/Utils/segmentation/core/MigrationUtils.js +0 -163
  97. package/dist/Utils/segmentation/core/MigrationUtils.js.map +0 -1
  98. package/dist/types/Utils/segmentation/core/MigrationUtils.d.ts +0 -97
@@ -1,6 +1,43 @@
1
1
  /**
2
2
  * SphereTool - Sphere drawing and calculator sphere operations
3
3
  *
4
+ * Provides 3D sphere placement across multiple slice views.
5
+ * Supports 4 sphere types: tumour, skin, nipple, ribcage.
6
+ * Each type maps to a specific layer and channel for future MaskVolume integration.
7
+ *
8
+ * ## Interaction Flow
9
+ * 1. Sphere mode activated (gui_states.sphere = true)
10
+ * - Draw mode (Shift key) is disabled
11
+ * - Crosshair toggle is disabled
12
+ * 2. Left-click down: record sphere center (mouseX, mouseY, sliceIndex)
13
+ * - Remove zoom/slice wheel event
14
+ * - Bind sphere wheel event
15
+ * - Draw preview circle on sphereCanvas
16
+ * 3. While holding left-click, scroll wheel adjusts sphereRadius [1, 50]
17
+ * 4. Left-click up:
18
+ * - Fire getSphere / getCalculateSpherePositions callbacks
19
+ * - (Plan B) Draw 3D sphere across x/y/z axes into sphereMaskVolume
20
+ * - Remove sphere wheel event
21
+ * - Restore zoom/slice wheel event
22
+ *
23
+ * ## Channel Mapping
24
+ * Each sphere type defaults to layer1 with a specific channel:
25
+ * - tumour → layer1, channel 1
26
+ * - ribcage → layer1, channel 3
27
+ * - skin → layer1, channel 4
28
+ * - nipple → layer1, channel 5
29
+ *
30
+ * ## SphereMaskVolume
31
+ * Sphere 3D data is stored in a dedicated MaskVolume (nrrd_states.sphereMaskVolume)
32
+ * separate from the layer draw mask volumes, to avoid polluting layer1's draw data.
33
+ * This volume is created in setAllSlices() and cleared in reset().
34
+ *
35
+ * ## Future: Writing to Layer MaskVolume
36
+ * Currently sphere data does NOT write to layer1's MaskVolume.
37
+ * The channel mapping and interfaces are reserved for future integration.
38
+ * When enabled, use SPHERE_CHANNEL_MAP to determine the target layer & channel,
39
+ * then call volume.setVoxel() or similar to persist sphere data.
40
+ *
4
41
  * Extracted from DrawToolCore.ts:
5
42
  * - drawSphere / drawSphereCore / clearSphereCanvas
6
43
  * - drawSphereOnEachViews / drawCalculatorSphereOnEachViews
@@ -10,27 +47,197 @@
10
47
  */
11
48
  import { BaseTool } from "./BaseTool";
12
49
  import type { ToolContext } from "./BaseTool";
50
+ /** The 4 supported sphere marker types. */
51
+ export type SphereType = 'tumour' | 'skin' | 'nipple' | 'ribcage';
52
+ /**
53
+ * Default layer and channel for each sphere type.
54
+ *
55
+ * This mapping is used to:
56
+ * 1. Determine the color for sphere preview rendering
57
+ * 2. (Future) Write sphere data into the corresponding layer's MaskVolume channel
58
+ *
59
+ * @example
60
+ * ```ts
61
+ * const { layer, channel } = SPHERE_CHANNEL_MAP['tumour'];
62
+ * // layer = 'layer1', channel = 1
63
+ * ```
64
+ */
65
+ export declare const SPHERE_CHANNEL_MAP: Record<SphereType, {
66
+ layer: string;
67
+ channel: number;
68
+ }>;
69
+ /**
70
+ * Label values for sphere types stored in sphereMaskVolume.
71
+ * Regular sphere mode uses SPHERE_LABEL (1).
72
+ * Calculator mode uses type-specific labels (1-4).
73
+ */
74
+ export declare const SPHERE_LABELS: Record<SphereType | 'default', number>;
13
75
  /**
14
76
  * Callbacks that DrawToolCore must provide for sphere operations.
77
+ * These are internal canvas manipulation callbacks, NOT external data callbacks.
78
+ *
79
+ * External data output uses:
80
+ * - annotationCallbacks.onSphereChanged(origin, radius) — sphere mode
81
+ * - annotationCallbacks.onCalculatorPositionsChanged(...) — calculator mode
15
82
  */
16
83
  export interface SphereCallbacks {
17
84
  setEmptyCanvasSize: (axis?: "x" | "y" | "z") => void;
18
85
  drawImageOnEmptyImage: (canvas: HTMLCanvasElement) => void;
19
- storeImageToAxis: (index: number, imageData: ImageData, axis?: "x" | "y" | "z") => void;
20
86
  }
21
87
  export declare class SphereTool extends BaseTool {
22
88
  private callbacks;
23
89
  constructor(ctx: ToolContext, callbacks: SphereCallbacks);
24
90
  setCallbacks(callbacks: SphereCallbacks): void;
91
+ /**
92
+ * Get the channel number for a sphere type.
93
+ *
94
+ * @param type - Sphere type ('tumour', 'skin', 'ribcage', 'nipple')
95
+ * @returns Channel number (1-8) mapped to this sphere type
96
+ *
97
+ * @example
98
+ * ```ts
99
+ * sphereTool.getChannelForSphereType('tumour'); // → 1
100
+ * sphereTool.getChannelForSphereType('skin'); // → 4
101
+ * ```
102
+ */
103
+ getChannelForSphereType(type: SphereType): number;
104
+ /**
105
+ * Get the default layer for a sphere type.
106
+ *
107
+ * @param type - Sphere type
108
+ * @returns Layer ID (e.g. 'layer1')
109
+ */
110
+ getLayerForSphereType(type: SphereType): string;
111
+ /**
112
+ * Get the preview color for a sphere type.
113
+ *
114
+ * If a volume is available for the target layer, uses the volume's
115
+ * custom color map (respects per-layer color customization).
116
+ * Otherwise falls back to SPHERE_COLORS (derived from CHANNEL_HEX_COLORS).
117
+ *
118
+ * @param type - Sphere type
119
+ * @returns CSS color string (hex)
120
+ */
121
+ getColorForSphereType(type: SphereType): string;
25
122
  setSphereCanvasSize(axis?: "x" | "y" | "z"): void;
123
+ /**
124
+ * Draw a filled circle on the given context.
125
+ *
126
+ * @param ctx - Canvas 2D context
127
+ * @param x - Center X coordinate
128
+ * @param y - Center Y coordinate
129
+ * @param radius - Circle radius in pixels
130
+ * @param color - Fill color (CSS string)
131
+ */
26
132
  drawSphereCore(ctx: CanvasRenderingContext2D, x: number, y: number, radius: number, color: string): void;
27
133
  clearSphereCanvas(): [HTMLCanvasElement, CanvasRenderingContext2D];
134
+ /**
135
+ * Draw a sphere preview circle on the sphere canvas using the current
136
+ * gui_states.fillColor. Called during sphere mode pointer-down.
137
+ *
138
+ * NOTE: Does NOT composite to master canvas — the start() render loop
139
+ * draws the sphere canvas directly to drawingCtx for proper layering.
140
+ */
28
141
  drawSphere(mouseX: number, mouseY: number, radius: number): void;
142
+ /**
143
+ * Returns a wheel event handler that adjusts sphere radius while the user
144
+ * holds left-click in sphere mode.
145
+ *
146
+ * Radius is clamped to [1, 50].
147
+ */
29
148
  configMouseSphereWheel(): (e: WheelEvent) => void;
149
+ /**
150
+ * Store sphere slice image into SphereMaskVolume.
151
+ *
152
+ * Currently a no-op — sphere slice data is rendered as overlay only.
153
+ *
154
+ * TODO: Future — write sphere circle data into nrrd_states.sphereMaskVolume
155
+ * at the specified slice index and axis. Use SPHERE_CHANNEL_MAP to determine
156
+ * the target channel when integrating with layer MaskVolume.
157
+ */
30
158
  private storeSphereImages;
159
+ /**
160
+ * Draw a sphere cross-section at a given decay distance from center,
161
+ * for a specific axis view.
162
+ *
163
+ * Called for each decay value [0..sphereRadius] for all 3 axes,
164
+ * creating the 3D sphere effect.
165
+ *
166
+ * The sphere circle radius at each slice = sphereRadius - decay (linear decay).
167
+ *
168
+ * @param decay - Distance from sphere center slice
169
+ * @param axis - Axis to render on ('x', 'y', 'z')
170
+ */
31
171
  drawSphereOnEachViews(decay: number, axis: "x" | "y" | "z"): void;
32
172
  private getSpherePosition;
173
+ /**
174
+ * Draw all 4 calculator sphere types on each view axis.
175
+ *
176
+ * Groups sphere positions by their slice index so that spheres on the
177
+ * same slice are drawn together before storing.
178
+ *
179
+ * Uses SPHERE_COLORS for each sphere type instead of nrrd_states.*Color.
180
+ */
33
181
  drawCalculatorSphereOnEachViews(axis: "x" | "y" | "z"): void;
182
+ /**
183
+ * Draw all placed calculator spheres on the current slice.
184
+ *
185
+ * Called every frame to show existing sphere markers on the current view.
186
+ * Uses SPHERE_COLORS for consistent type-based coloring.
187
+ *
188
+ * @param radius - Sphere radius to draw
189
+ */
34
190
  drawCalculatorSphere(radius: number): void;
191
+ /**
192
+ * Clear sphere overlay images.
193
+ *
194
+ * No-op in current implementation — sphere data is rendered as overlay
195
+ * and stored in the dedicated sphereMaskVolume (not in layer volumes).
196
+ */
35
197
  clearSpherePrintStoreImages(): void;
198
+ /**
199
+ * Convert canvas (mm-space) coordinates to 3D voxel coordinates.
200
+ *
201
+ * @param canvasX - X position in canvas mm-space
202
+ * @param canvasY - Y position in canvas mm-space
203
+ * @param sliceIndex - Slice index along the viewing axis
204
+ * @param axis - Viewing axis where the sphere was placed
205
+ * @returns 3D voxel coordinates { x, y, z }
206
+ */
207
+ canvasToVoxelCenter(canvasX: number, canvasY: number, sliceIndex: number, axis: "x" | "y" | "z"): {
208
+ x: number;
209
+ y: number;
210
+ z: number;
211
+ };
212
+ /**
213
+ * Write a 3D solid sphere to sphereMaskVolume.
214
+ *
215
+ * Converts the sphere center from canvas mm-space to voxel coordinates,
216
+ * then iterates over a bounding box and sets voxels within the sphere.
217
+ * The sphere is an ellipsoid in voxel space to appear circular in
218
+ * physical (mm) space on all axis views.
219
+ *
220
+ * @param label - Label value to write (1-4, default 1)
221
+ */
222
+ write3DSphereToVolume(label?: number): void;
223
+ /**
224
+ * Write a calculator sphere type to sphereMaskVolume.
225
+ * Uses the stored origin for the specified sphere type.
226
+ *
227
+ * @param type - Sphere type ('tumour', 'skin', 'nipple', 'ribcage')
228
+ */
229
+ writeCalculatorSphereToVolume(type: SphereType): void;
230
+ /**
231
+ * Write all placed calculator spheres to the volume.
232
+ * Clears the volume first, then writes each placed sphere type.
233
+ */
234
+ writeAllCalculatorSpheresToVolume(): void;
235
+ /**
236
+ * Render the current slice of sphereMaskVolume to drawingSphereCanvas.
237
+ *
238
+ * Called after any operation that changes the view (slice, axis, zoom)
239
+ * to keep the sphere overlay visible. Uses the same render pipeline as
240
+ * layer masks (emptyCanvas → sphere canvas at display scale).
241
+ */
242
+ refreshSphereCanvas(): void;
36
243
  }
@@ -9,10 +9,14 @@
9
9
  export { BaseTool } from "./BaseTool";
10
10
  export type { ToolContext } from "./BaseTool";
11
11
  export { EraserTool } from "./EraserTool";
12
+ export { DrawingTool } from "./DrawingTool";
13
+ export type { DrawingCallbacks } from "./DrawingTool";
14
+ export { PanTool } from "./PanTool";
15
+ export type { PanCallbacks } from "./PanTool";
12
16
  export { ZoomTool } from "./ZoomTool";
13
17
  export type { ZoomCallbacks } from "./ZoomTool";
14
- export { SphereTool } from "./SphereTool";
15
- export type { SphereCallbacks } from "./SphereTool";
18
+ export { SphereTool, SPHERE_CHANNEL_MAP } from "./SphereTool";
19
+ export type { SphereCallbacks, SphereType } from "./SphereTool";
16
20
  export { CrosshairTool } from "./CrosshairTool";
17
21
  export { ContrastTool } from "./ContrastTool";
18
22
  export type { ContrastCallbacks } from "./ContrastTool";
@@ -17,10 +17,13 @@ import { Copper3dTrackballControls } from "./Controls/Copper3dTrackballControls"
17
17
  import { MeshNodeTool } from "./Utils/MeshNodeTool";
18
18
  import { removeGuiFolderChilden } from "./Utils/segmentation/coreTools/gui";
19
19
  import { nrrdMeshesType, nrrdSliceType, SensorDecodedValue_kiwrious, SensorReadResult_kiwrious, HeartRateResult_kiwrious, loadingBarType, exportPaintImageType, IOptVTKLoader } from "./types/types";
20
- import { IPaintImage, ICommXYZ, IGUIStates, IGuiParameterSettings, INrrdStates } from "./Utils/segmentation/coreTools/coreType";
20
+ import { IPaintImage, ICommXYZ, IGUIStates, IGuiParameterSettings, INrrdStates, IGuiMeta } from "./Utils/segmentation/coreTools/coreType";
21
+ import { NrrdState } from "./Utils/segmentation/coreTools/NrrdState";
22
+ import { GuiState } from "./Utils/segmentation/coreTools/GuiState";
23
+ import type { ToolMode, IAnnotationCallbacks } from "./Utils/segmentation/coreTools/coreType";
21
24
  import { CHANNEL_COLORS, CHANNEL_HEX_COLORS, rgbaToHex, rgbaToCss } from "./Utils/segmentation/core/index";
22
25
  import type { LayerId, ChannelValue } from "./Utils/segmentation/core/index";
23
26
  import "./css/style.css";
24
- export declare const REVISION = "v3.0.1-beta";
27
+ export declare const REVISION = "v3.0.2-beta";
25
28
  export { copperRenderer, copperRendererOnDemond, copperMSceneRenderer, setHDRFilePath, addLabelToScene, convert3DPostoScreenPos, convertScreenPosto3DPos, addBoxHelper, fullScreenListenner, configKiwriousHeart, copperScene, copperSceneOnDemond, copperMScene, CameraViewPoint, kiwrious, NrrdTools, loading, Copper3dTrackballControls, createTexture2D_NRRD, MeshNodeTool, throttle, removeGuiFolderChilden, CHANNEL_COLORS, CHANNEL_HEX_COLORS, rgbaToHex, rgbaToCss, };
26
- export type { positionType, screenPosType, optsType, nrrdMeshesType, nrrdSliceType, SensorDecodedValue_kiwrious, SensorReadResult_kiwrious, HeartRateResult_kiwrious, loadingBarType, IPaintImage, exportPaintImageType, IOptVTKLoader, ICommXYZ, IGUIStates, IGuiParameterSettings, INrrdStates, LayerId, ChannelValue, };
29
+ export type { positionType, screenPosType, optsType, nrrdMeshesType, nrrdSliceType, SensorDecodedValue_kiwrious, SensorReadResult_kiwrious, HeartRateResult_kiwrious, loadingBarType, IPaintImage, exportPaintImageType, IOptVTKLoader, ICommXYZ, IGUIStates, IGuiParameterSettings, INrrdStates, NrrdState, GuiState, IGuiMeta, ToolMode, IAnnotationCallbacks, LayerId, ChannelValue, };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "copper3d",
3
3
  "description": "A 3d visualisation package base on threejs provides multiple scenes and Nrrd image load funtion.",
4
- "version": "3.0.1",
4
+ "version": "3.0.2",
5
5
  "main": "dist/bundle.umd.js",
6
6
  "moudle": "dist/bundle.esm.js",
7
7
  "types": "dist/types/index.d.ts",
@@ -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;
@@ -1,163 +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 { MaskVolume } from './MaskVolume';
22
- // ── Forward migration: IPaintImages → MaskVolume ────────────────────────
23
- /**
24
- * Convert legacy per-slice ImageData storage into a MaskVolume.
25
- *
26
- * The function iterates over all three axes (`x`, `y`, `z`) and inserts
27
- * each slice into the volume using `setSliceFromImageData`.
28
- *
29
- * **Sparse data handling**: Slices that are absent from the arrays are
30
- * left as zero (the MaskVolume default). Duplicate indices are
31
- * overwritten in order (last wins).
32
- *
33
- * @param paintImages Legacy per-axis slice collection.
34
- * @param dimensions Volume dimensions (must match the ImageData sizes).
35
- * @param channel Target channel in the volume (default 0).
36
- *
37
- * @returns A new MaskVolume populated with the legacy data.
38
- *
39
- * @throws {Error} If a slice's ImageData dimensions don't match the
40
- * expected size for its axis.
41
- *
42
- * @example
43
- * ```ts
44
- * const volume = convertIPaintImagesToVolume(
45
- * maskData.paintImagesLayer1,
46
- * { width: 512, height: 512, depth: 100 },
47
- * );
48
- * ```
49
- */
50
- export function convertIPaintImagesToVolume(paintImages, dimensions, channel = 0) {
51
- if (!paintImages) {
52
- throw new Error('paintImages is null or undefined');
53
- }
54
- if (dimensions.width < 1 ||
55
- dimensions.height < 1 ||
56
- dimensions.depth < 1) {
57
- throw new RangeError(`Dimensions must be ≥ 1, got (${dimensions.width}, ${dimensions.height}, ${dimensions.depth})`);
58
- }
59
- const volume = new MaskVolume(dimensions.width, dimensions.height, dimensions.depth);
60
- // Process each axis
61
- const axes = [
62
- { key: 'z', axis: 'z' },
63
- { key: 'y', axis: 'y' },
64
- { key: 'x', axis: 'x' },
65
- ];
66
- for (const { key, axis } of axes) {
67
- const slices = paintImages[key];
68
- if (!slices || !Array.isArray(slices))
69
- continue;
70
- for (const paintImage of slices) {
71
- if (!paintImage || paintImage.image == null)
72
- continue;
73
- const { index, image } = paintImage;
74
- // Validate slice index bounds
75
- const maxIndex = axis === 'x' ? dimensions.width :
76
- axis === 'y' ? dimensions.height :
77
- dimensions.depth;
78
- if (index < 0 || index >= maxIndex) {
79
- continue; // Skip out-of-bounds slices silently
80
- }
81
- volume.setSliceFromImageData(index, image, axis, channel);
82
- }
83
- }
84
- return volume;
85
- }
86
- // ── Backward migration: MaskVolume → IPaintImages ───────────────────────
87
- /**
88
- * Convert a MaskVolume back to legacy per-slice ImageData storage.
89
- *
90
- * Extracts **all** slices along the Z axis (axial) into an
91
- * `IPaintImages` structure. X and Y axes are left as empty arrays
92
- * since the legacy system can reconstruct them on demand.
93
- *
94
- * Only non-empty slices (those containing at least one non-zero pixel)
95
- * are included, matching the sparse behaviour of the original storage.
96
- *
97
- * @param volume The MaskVolume to export.
98
- * @param channel Channel to extract (default 0).
99
- * @param options Export options.
100
- * @param options.includeAllAxes If true, also export X and Y axis slices
101
- * (expensive — use only if needed for full
102
- * backward compatibility). Default: false.
103
- * @param options.includeEmpty If true, include slices that are entirely
104
- * zero. Default: false.
105
- *
106
- * @returns A legacy IPaintImages structure.
107
- *
108
- * @example
109
- * ```ts
110
- * const legacy = convertVolumeToIPaintImages(volume);
111
- * // legacy.z contains non-empty axial slices
112
- * // legacy.x and legacy.y are empty by default
113
- * ```
114
- */
115
- export function convertVolumeToIPaintImages(volume, channel = 0, options = {}) {
116
- if (!volume) {
117
- throw new Error('volume is null or undefined');
118
- }
119
- const { includeAllAxes = false, includeEmpty = false } = options;
120
- const dims = volume.getDimensions();
121
- const result = { x: [], y: [], z: [] };
122
- const renderOpts = { channel };
123
- // Always export Z axis (axial slices — most commonly used)
124
- for (let z = 0; z < dims.depth; z++) {
125
- const imageData = volume.getSliceImageData(z, 'z', renderOpts);
126
- if (includeEmpty || hasNonZeroPixels(imageData)) {
127
- result.z.push({ index: z, image: imageData });
128
- }
129
- }
130
- // Optionally export X and Y axes
131
- if (includeAllAxes) {
132
- for (let y = 0; y < dims.height; y++) {
133
- const imageData = volume.getSliceImageData(y, 'y', renderOpts);
134
- if (includeEmpty || hasNonZeroPixels(imageData)) {
135
- result.y.push({ index: y, image: imageData });
136
- }
137
- }
138
- for (let x = 0; x < dims.width; x++) {
139
- const imageData = volume.getSliceImageData(x, 'x', renderOpts);
140
- if (includeEmpty || hasNonZeroPixels(imageData)) {
141
- result.x.push({ index: x, image: imageData });
142
- }
143
- }
144
- }
145
- return result;
146
- }
147
- // ── Helpers ──────────────────────────────────────────────────────────────
148
- /**
149
- * Check whether an ImageData has any non-zero pixel data.
150
- *
151
- * Only checks the R channel (index 0 of every 4-byte group) since
152
- * MaskVolume stores grayscale values in the R channel.
153
- */
154
- function hasNonZeroPixels(imageData) {
155
- const data = imageData.data;
156
- // Check R channel of each pixel (stride 4)
157
- for (let i = 0; i < data.length; i += 4) {
158
- if (data[i] !== 0)
159
- return true;
160
- }
161
- return false;
162
- }
163
- //# sourceMappingURL=MigrationUtils.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"MigrationUtils.js","sourceRoot":"","sources":["../../../../src/Utils/segmentation/core/MigrationUtils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAGH,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAyB1C,2EAA2E;AAE3E;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,UAAU,2BAA2B,CACzC,WAAyB,EACzB,UAAsB,EACtB,OAAO,GAAG,CAAC;IAEX,IAAI,CAAC,WAAW,EAAE;QAChB,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAC;KACrD;IACD,IACE,UAAU,CAAC,KAAK,GAAG,CAAC;QACpB,UAAU,CAAC,MAAM,GAAG,CAAC;QACrB,UAAU,CAAC,KAAK,GAAG,CAAC,EACpB;QACA,MAAM,IAAI,UAAU,CAClB,gCAAgC,UAAU,CAAC,KAAK,KAAK,UAAU,CAAC,MAAM,KAAK,UAAU,CAAC,KAAK,GAAG,CAC/F,CAAC;KACH;IAED,MAAM,MAAM,GAAG,IAAI,UAAU,CAC3B,UAAU,CAAC,KAAK,EAChB,UAAU,CAAC,MAAM,EACjB,UAAU,CAAC,KAAK,CACjB,CAAC;IAEF,oBAAoB;IACpB,MAAM,IAAI,GAA8D;QACtE,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE;QACvB,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE;QACvB,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE;KACxB,CAAC;IAEF,KAAK,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,IAAI,EAAE;QAChC,MAAM,MAAM,GAAG,WAAW,CAAC,GA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;GAKG;AACH,SAAS,gBAAgB,CAAC,SAAoB;IAC5C,MAAM,IAAI,GAAG,SAAS,CAAC,IAAI,CAAC;IAC5B,2CAA2C;IAC3C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE;QACvC,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC;YAAE,OAAO,IAAI,CAAC;KAChC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
@@ -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;