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,36 +1,249 @@
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
7
44
  * - storeSphereImages / setSphereCanvasSize
8
45
  * - drawCalculatorSphere / configMouseSphereWheel
9
- * - getSpherePosition / clearSpherePrintStoreImages
46
+ * - getSpherePosition
10
47
  */
11
48
  import { BaseTool } from "./BaseTool";
12
49
  import type { ToolContext } from "./BaseTool";
50
+ import type { SphereHostDeps } from "./ToolHost";
51
+ /** The 4 supported sphere marker types. */
52
+ export type SphereType = 'tumour' | 'skin' | 'nipple' | 'ribcage';
13
53
  /**
14
- * Callbacks that DrawToolCore must provide for sphere operations.
54
+ * Default layer and channel for each sphere type.
55
+ *
56
+ * This mapping is used to:
57
+ * 1. Determine the color for sphere preview rendering
58
+ * 2. (Future) Write sphere data into the corresponding layer's MaskVolume channel
59
+ *
60
+ * @example
61
+ * ```ts
62
+ * const { layer, channel } = SPHERE_CHANNEL_MAP['tumour'];
63
+ * // layer = 'layer1', channel = 1
64
+ * ```
15
65
  */
16
- export interface SphereCallbacks {
17
- setEmptyCanvasSize: (axis?: "x" | "y" | "z") => void;
18
- drawImageOnEmptyImage: (canvas: HTMLCanvasElement) => void;
19
- storeImageToAxis: (index: number, imageData: ImageData, axis?: "x" | "y" | "z") => void;
20
- }
66
+ export declare const SPHERE_CHANNEL_MAP: Record<SphereType, {
67
+ layer: string;
68
+ channel: number;
69
+ }>;
70
+ /**
71
+ * Label values for sphere types stored in sphereMaskVolume.
72
+ * Regular sphere mode uses SPHERE_LABEL (1).
73
+ * Calculator mode uses type-specific labels (1-4).
74
+ */
75
+ export declare const SPHERE_LABELS: Record<SphereType | 'default', number>;
21
76
  export declare class SphereTool extends BaseTool {
22
77
  private callbacks;
23
- constructor(ctx: ToolContext, callbacks: SphereCallbacks);
24
- setCallbacks(callbacks: SphereCallbacks): void;
78
+ constructor(ctx: ToolContext, callbacks: SphereHostDeps);
79
+ setCallbacks(callbacks: SphereHostDeps): void;
80
+ /**
81
+ * Get the channel number for a sphere type.
82
+ *
83
+ * @param type - Sphere type ('tumour', 'skin', 'ribcage', 'nipple')
84
+ * @returns Channel number (1-8) mapped to this sphere type
85
+ *
86
+ * @example
87
+ * ```ts
88
+ * sphereTool.getChannelForSphereType('tumour'); // → 1
89
+ * sphereTool.getChannelForSphereType('skin'); // → 4
90
+ * ```
91
+ */
92
+ getChannelForSphereType(type: SphereType): number;
93
+ /**
94
+ * Get the default layer for a sphere type.
95
+ *
96
+ * @param type - Sphere type
97
+ * @returns Layer ID (e.g. 'layer1')
98
+ */
99
+ getLayerForSphereType(type: SphereType): string;
100
+ /**
101
+ * Get the preview color for a sphere type.
102
+ *
103
+ * If a volume is available for the target layer, uses the volume's
104
+ * custom color map (respects per-layer color customization).
105
+ * Otherwise falls back to SPHERE_COLORS (derived from CHANNEL_HEX_COLORS).
106
+ *
107
+ * @param type - Sphere type
108
+ * @returns CSS color string (hex)
109
+ */
110
+ getColorForSphereType(type: SphereType): string;
25
111
  setSphereCanvasSize(axis?: "x" | "y" | "z"): void;
112
+ /**
113
+ * Draw a filled circle on the given context.
114
+ *
115
+ * @param ctx - Canvas 2D context
116
+ * @param x - Center X coordinate
117
+ * @param y - Center Y coordinate
118
+ * @param radius - Circle radius in pixels
119
+ * @param color - Fill color (CSS string)
120
+ */
26
121
  drawSphereCore(ctx: CanvasRenderingContext2D, x: number, y: number, radius: number, color: string): void;
27
122
  clearSphereCanvas(): [HTMLCanvasElement, CanvasRenderingContext2D];
123
+ /**
124
+ * Draw a sphere preview circle on the sphere canvas using the current
125
+ * gui_states.fillColor. Called during sphere mode pointer-down.
126
+ *
127
+ * NOTE: Does NOT composite to master canvas — the start() render loop
128
+ * draws the sphere canvas directly to drawingCtx for proper layering.
129
+ */
28
130
  drawSphere(mouseX: number, mouseY: number, radius: number): void;
131
+ /**
132
+ * Returns a wheel event handler that adjusts sphere radius while the user
133
+ * holds left-click in sphere mode.
134
+ *
135
+ * Radius is clamped to [1, 50].
136
+ */
29
137
  configMouseSphereWheel(): (e: WheelEvent) => void;
138
+ /**
139
+ * Store sphere slice image into SphereMaskVolume.
140
+ *
141
+ * Currently a no-op — sphere slice data is rendered as overlay only.
142
+ *
143
+ * TODO: Future — write sphere circle data into nrrd_states.sphereMaskVolume
144
+ * at the specified slice index and axis. Use SPHERE_CHANNEL_MAP to determine
145
+ * the target channel when integrating with layer MaskVolume.
146
+ */
30
147
  private storeSphereImages;
148
+ /**
149
+ * Draw a sphere cross-section at a given decay distance from center,
150
+ * for a specific axis view.
151
+ *
152
+ * Called for each decay value [0..sphereRadius] for all 3 axes,
153
+ * creating the 3D sphere effect.
154
+ *
155
+ * The sphere circle radius at each slice = sphereRadius - decay (linear decay).
156
+ *
157
+ * @param decay - Distance from sphere center slice
158
+ * @param axis - Axis to render on ('x', 'y', 'z')
159
+ */
31
160
  drawSphereOnEachViews(decay: number, axis: "x" | "y" | "z"): void;
32
161
  private getSpherePosition;
162
+ /**
163
+ * Draw all 4 calculator sphere types on each view axis.
164
+ *
165
+ * Groups sphere positions by their slice index so that spheres on the
166
+ * same slice are drawn together before storing.
167
+ *
168
+ * Uses SPHERE_COLORS for each sphere type instead of nrrd_states.*Color.
169
+ */
33
170
  drawCalculatorSphereOnEachViews(axis: "x" | "y" | "z"): void;
171
+ /**
172
+ * Draw all placed calculator spheres on the current slice.
173
+ *
174
+ * Called every frame to show existing sphere markers on the current view.
175
+ * Uses SPHERE_COLORS for consistent type-based coloring.
176
+ *
177
+ * @param radius - Sphere radius to draw
178
+ */
34
179
  drawCalculatorSphere(radius: number): void;
35
- clearSpherePrintStoreImages(): void;
180
+ /**
181
+ * Handle left-click in sphere mode — record origin, draw preview.
182
+ *
183
+ * Performs all data operations for sphere placement:
184
+ * 1. Record sphere origin for current axis
185
+ * 2. Convert origin to all three axes via setUpSphereOrigins
186
+ * 3. Store origin for the active sphere type
187
+ * 4. Enable crosshair at click position
188
+ * 5. Draw calculator sphere preview
189
+ *
190
+ * Event binding (wheel, pointerup) stays in DrawToolCore as orchestration.
191
+ */
192
+ onSphereClick(e: MouseEvent): void;
193
+ /**
194
+ * Handle pointer-up in sphere mode — write to volume, fire callbacks.
195
+ *
196
+ * Performs:
197
+ * 1. Write all placed calculator spheres to sphereMaskVolume
198
+ * 2. Refresh sphere canvas overlay from volume
199
+ * 3. Fire onSphereChanged and onCalculatorPositionsChanged callbacks
200
+ *
201
+ * Event cleanup (wheel, pointerup listener removal) stays in DrawToolCore.
202
+ */
203
+ onSpherePointerUp(): void;
204
+ /**
205
+ * Convert canvas (mm-space) coordinates to 3D voxel coordinates.
206
+ *
207
+ * @param canvasX - X position in canvas mm-space
208
+ * @param canvasY - Y position in canvas mm-space
209
+ * @param sliceIndex - Slice index along the viewing axis
210
+ * @param axis - Viewing axis where the sphere was placed
211
+ * @returns 3D voxel coordinates { x, y, z }
212
+ */
213
+ canvasToVoxelCenter(canvasX: number, canvasY: number, sliceIndex: number, axis: "x" | "y" | "z"): {
214
+ x: number;
215
+ y: number;
216
+ z: number;
217
+ };
218
+ /**
219
+ * Write a 3D solid sphere to sphereMaskVolume.
220
+ *
221
+ * Converts the sphere center from canvas mm-space to voxel coordinates,
222
+ * then iterates over a bounding box and sets voxels within the sphere.
223
+ * The sphere is an ellipsoid in voxel space to appear circular in
224
+ * physical (mm) space on all axis views.
225
+ *
226
+ * @param label - Label value to write (1-4, default 1)
227
+ */
228
+ write3DSphereToVolume(label?: number): void;
229
+ /**
230
+ * Write a calculator sphere type to sphereMaskVolume.
231
+ * Uses the stored origin for the specified sphere type.
232
+ *
233
+ * @param type - Sphere type ('tumour', 'skin', 'nipple', 'ribcage')
234
+ */
235
+ writeCalculatorSphereToVolume(type: SphereType): void;
236
+ /**
237
+ * Write all placed calculator spheres to the volume.
238
+ * Clears the volume first, then writes each placed sphere type.
239
+ */
240
+ writeAllCalculatorSpheresToVolume(): void;
241
+ /**
242
+ * Render the current slice of sphereMaskVolume to drawingSphereCanvas.
243
+ *
244
+ * Called after any operation that changes the view (slice, axis, zoom)
245
+ * to keep the sphere overlay visible. Uses the same render pipeline as
246
+ * layer masks (emptyCanvas → sphere canvas at display scale).
247
+ */
248
+ refreshSphereCanvas(): void;
36
249
  }