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.
- package/README.md +197 -875
- package/dist/Utils/segmentation/CanvasState.d.ts +31 -0
- package/dist/Utils/segmentation/CanvasState.js +167 -0
- package/dist/Utils/segmentation/CanvasState.js.map +1 -0
- package/dist/Utils/segmentation/DragOperator.d.ts +10 -2
- package/dist/Utils/segmentation/DragOperator.js +16 -8
- package/dist/Utils/segmentation/DragOperator.js.map +1 -1
- package/dist/Utils/segmentation/DrawToolCore.d.ts +64 -35
- package/dist/Utils/segmentation/DrawToolCore.js +332 -584
- package/dist/Utils/segmentation/DrawToolCore.js.map +1 -1
- package/dist/Utils/segmentation/NrrdTools.d.ts +117 -353
- package/dist/Utils/segmentation/NrrdTools.js +622 -1081
- package/dist/Utils/segmentation/NrrdTools.js.map +1 -1
- package/dist/Utils/segmentation/RenderingUtils.d.ts +73 -0
- package/dist/Utils/segmentation/RenderingUtils.js +180 -0
- package/dist/Utils/segmentation/RenderingUtils.js.map +1 -0
- package/dist/Utils/segmentation/core/MaskVolume.js +23 -2
- package/dist/Utils/segmentation/core/MaskVolume.js.map +1 -1
- package/dist/Utils/segmentation/core/UndoManager.d.ts +1 -1
- package/dist/Utils/segmentation/core/UndoManager.js +1 -1
- package/dist/Utils/segmentation/core/index.d.ts +1 -3
- package/dist/Utils/segmentation/core/index.js +0 -1
- package/dist/Utils/segmentation/core/index.js.map +1 -1
- package/dist/Utils/segmentation/core/types.d.ts +384 -0
- package/dist/Utils/segmentation/core/types.js +25 -24
- package/dist/Utils/segmentation/core/types.js.map +1 -1
- package/dist/Utils/segmentation/coreTools/GuiState.d.ts +22 -0
- package/dist/Utils/segmentation/coreTools/GuiState.js +48 -0
- package/dist/Utils/segmentation/coreTools/GuiState.js.map +1 -0
- package/dist/Utils/segmentation/coreTools/NrrdState.d.ts +25 -0
- package/dist/Utils/segmentation/coreTools/NrrdState.js +85 -0
- package/dist/Utils/segmentation/coreTools/NrrdState.js.map +1 -0
- package/dist/Utils/segmentation/coreTools/divControlTools.d.ts +1 -1
- package/dist/Utils/segmentation/coreTools/divControlTools.js +1 -1
- package/dist/Utils/segmentation/coreTools/divControlTools.js.map +1 -1
- package/dist/Utils/segmentation/coreTools/gui.d.ts +12 -12
- package/dist/Utils/segmentation/coreTools/gui.js +81 -107
- package/dist/Utils/segmentation/coreTools/gui.js.map +1 -1
- package/dist/Utils/segmentation/eventRouter/EventRouter.d.ts +2 -1
- package/dist/Utils/segmentation/eventRouter/EventRouter.js +15 -10
- package/dist/Utils/segmentation/eventRouter/EventRouter.js.map +1 -1
- package/dist/Utils/segmentation/eventRouter/types.d.ts +3 -3
- package/dist/Utils/segmentation/tools/BaseTool.d.ts +8 -5
- package/dist/Utils/segmentation/tools/BaseTool.js +1 -2
- package/dist/Utils/segmentation/tools/BaseTool.js.map +1 -1
- package/dist/Utils/segmentation/tools/ContrastTool.d.ts +3 -6
- package/dist/Utils/segmentation/tools/ContrastTool.js.map +1 -1
- package/dist/Utils/segmentation/tools/CrosshairTool.d.ts +11 -1
- package/dist/Utils/segmentation/tools/CrosshairTool.js +50 -25
- package/dist/Utils/segmentation/tools/CrosshairTool.js.map +1 -1
- package/dist/Utils/segmentation/tools/DataLoader.d.ts +33 -0
- package/dist/Utils/segmentation/tools/DataLoader.js +159 -0
- package/dist/Utils/segmentation/tools/DataLoader.js.map +1 -0
- package/dist/Utils/segmentation/tools/DragSliceTool.d.ts +3 -10
- package/dist/Utils/segmentation/tools/DragSliceTool.js +63 -53
- package/dist/Utils/segmentation/tools/DragSliceTool.js.map +1 -1
- package/dist/Utils/segmentation/tools/DrawingTool.d.ts +85 -0
- package/dist/Utils/segmentation/tools/DrawingTool.js +270 -0
- package/dist/Utils/segmentation/tools/DrawingTool.js.map +1 -0
- package/dist/Utils/segmentation/tools/EraserTool.js +8 -8
- package/dist/Utils/segmentation/tools/EraserTool.js.map +1 -1
- package/dist/Utils/segmentation/tools/ImageStoreHelper.d.ts +13 -33
- package/dist/Utils/segmentation/tools/ImageStoreHelper.js +39 -82
- package/dist/Utils/segmentation/tools/ImageStoreHelper.js.map +1 -1
- package/dist/Utils/segmentation/tools/LayerChannelManager.d.ts +52 -0
- package/dist/Utils/segmentation/tools/LayerChannelManager.js +175 -0
- package/dist/Utils/segmentation/tools/LayerChannelManager.js.map +1 -0
- package/dist/Utils/segmentation/tools/PanTool.d.ts +47 -0
- package/dist/Utils/segmentation/tools/PanTool.js +90 -0
- package/dist/Utils/segmentation/tools/PanTool.js.map +1 -0
- package/dist/Utils/segmentation/tools/SliceRenderPipeline.d.ts +80 -0
- package/dist/Utils/segmentation/tools/SliceRenderPipeline.js +355 -0
- package/dist/Utils/segmentation/tools/SliceRenderPipeline.js.map +1 -0
- package/dist/Utils/segmentation/tools/SphereTool.d.ts +223 -10
- package/dist/Utils/segmentation/tools/SphereTool.js +512 -47
- package/dist/Utils/segmentation/tools/SphereTool.js.map +1 -1
- package/dist/Utils/segmentation/tools/ToolHost.d.ts +74 -0
- package/dist/Utils/segmentation/tools/ToolHost.js +10 -0
- package/dist/Utils/segmentation/tools/ToolHost.js.map +1 -0
- package/dist/Utils/segmentation/tools/ZoomTool.d.ts +2 -6
- package/dist/Utils/segmentation/tools/ZoomTool.js +3 -3
- package/dist/Utils/segmentation/tools/ZoomTool.js.map +1 -1
- package/dist/Utils/segmentation/tools/index.d.ts +8 -6
- package/dist/Utils/segmentation/tools/index.js +10 -1
- package/dist/Utils/segmentation/tools/index.js.map +1 -1
- package/dist/Utils/workers/reformatSaveDataWorker.d.ts +1 -1
- package/dist/bundle.esm.js +3729 -3017
- package/dist/bundle.umd.js +3729 -3017
- package/dist/index.d.ts +6 -3
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/types/Utils/segmentation/CanvasState.d.ts +31 -0
- package/dist/types/Utils/segmentation/DragOperator.d.ts +10 -2
- package/dist/types/Utils/segmentation/DrawToolCore.d.ts +64 -35
- package/dist/types/Utils/segmentation/NrrdTools.d.ts +117 -353
- package/dist/types/Utils/segmentation/RenderingUtils.d.ts +73 -0
- package/dist/types/Utils/segmentation/core/UndoManager.d.ts +1 -1
- package/dist/types/Utils/segmentation/core/index.d.ts +1 -3
- package/dist/types/Utils/segmentation/core/types.d.ts +384 -0
- package/dist/types/Utils/segmentation/coreTools/GuiState.d.ts +22 -0
- package/dist/types/Utils/segmentation/coreTools/NrrdState.d.ts +25 -0
- package/dist/types/Utils/segmentation/coreTools/divControlTools.d.ts +1 -1
- package/dist/types/Utils/segmentation/coreTools/gui.d.ts +12 -12
- package/dist/types/Utils/segmentation/eventRouter/EventRouter.d.ts +2 -1
- package/dist/types/Utils/segmentation/eventRouter/types.d.ts +3 -3
- package/dist/types/Utils/segmentation/tools/BaseTool.d.ts +8 -5
- package/dist/types/Utils/segmentation/tools/ContrastTool.d.ts +3 -6
- package/dist/types/Utils/segmentation/tools/CrosshairTool.d.ts +11 -1
- package/dist/types/Utils/segmentation/tools/DataLoader.d.ts +33 -0
- package/dist/types/Utils/segmentation/tools/DragSliceTool.d.ts +3 -10
- package/dist/types/Utils/segmentation/tools/DrawingTool.d.ts +85 -0
- package/dist/types/Utils/segmentation/tools/ImageStoreHelper.d.ts +13 -33
- package/dist/types/Utils/segmentation/tools/LayerChannelManager.d.ts +52 -0
- package/dist/types/Utils/segmentation/tools/PanTool.d.ts +47 -0
- package/dist/types/Utils/segmentation/tools/SliceRenderPipeline.d.ts +80 -0
- package/dist/types/Utils/segmentation/tools/SphereTool.d.ts +223 -10
- package/dist/types/Utils/segmentation/tools/ToolHost.d.ts +74 -0
- package/dist/types/Utils/segmentation/tools/ZoomTool.d.ts +2 -6
- package/dist/types/Utils/segmentation/tools/index.d.ts +8 -6
- package/dist/types/Utils/workers/reformatSaveDataWorker.d.ts +1 -1
- package/dist/types/index.d.ts +6 -3
- package/package.json +1 -1
- package/dist/Utils/segmentation/CommToolsData.d.ts +0 -177
- package/dist/Utils/segmentation/CommToolsData.js +0 -548
- package/dist/Utils/segmentation/CommToolsData.js.map +0 -1
- package/dist/Utils/segmentation/core/MigrationUtils.d.ts +0 -97
- package/dist/Utils/segmentation/core/MigrationUtils.js +0 -163
- package/dist/Utils/segmentation/core/MigrationUtils.js.map +0 -1
- package/dist/Utils/segmentation/coreTools/coreType.d.ts +0 -363
- package/dist/Utils/segmentation/coreTools/coreType.js +0 -3
- package/dist/Utils/segmentation/coreTools/coreType.js.map +0 -1
- package/dist/types/Utils/segmentation/CommToolsData.d.ts +0 -177
- package/dist/types/Utils/segmentation/core/MigrationUtils.d.ts +0 -97
- package/dist/types/Utils/segmentation/coreTools/coreType.d.ts +0 -363
|
@@ -1,14 +1,84 @@
|
|
|
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
|
|
46
|
+
* - getSpherePosition
|
|
10
47
|
*/
|
|
11
48
|
import { BaseTool } from "./BaseTool";
|
|
49
|
+
import { CHANNEL_HEX_COLORS } from "../core";
|
|
50
|
+
/**
|
|
51
|
+
* Default layer and channel for each sphere type.
|
|
52
|
+
*
|
|
53
|
+
* This mapping is used to:
|
|
54
|
+
* 1. Determine the color for sphere preview rendering
|
|
55
|
+
* 2. (Future) Write sphere data into the corresponding layer's MaskVolume channel
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```ts
|
|
59
|
+
* const { layer, channel } = SPHERE_CHANNEL_MAP['tumour'];
|
|
60
|
+
* // layer = 'layer1', channel = 1
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
export const SPHERE_CHANNEL_MAP = {
|
|
64
|
+
tumour: { layer: 'layer1', channel: 1 },
|
|
65
|
+
nipple: { layer: 'layer1', channel: 2 },
|
|
66
|
+
ribcage: { layer: 'layer1', channel: 3 },
|
|
67
|
+
skin: { layer: 'layer1', channel: 4 },
|
|
68
|
+
};
|
|
69
|
+
// SPHERE_COLORS was removed to enforce dynamic color lookups.
|
|
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 const SPHERE_LABELS = {
|
|
76
|
+
default: 1,
|
|
77
|
+
tumour: 1,
|
|
78
|
+
nipple: 2,
|
|
79
|
+
ribcage: 3,
|
|
80
|
+
skin: 4,
|
|
81
|
+
};
|
|
12
82
|
export class SphereTool extends BaseTool {
|
|
13
83
|
constructor(ctx, callbacks) {
|
|
14
84
|
super(ctx);
|
|
@@ -17,25 +87,84 @@ export class SphereTool extends BaseTool {
|
|
|
17
87
|
setCallbacks(callbacks) {
|
|
18
88
|
this.callbacks = callbacks;
|
|
19
89
|
}
|
|
90
|
+
// ===== Sphere Type Helpers =====
|
|
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) {
|
|
104
|
+
return SPHERE_CHANNEL_MAP[type].channel;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Get the default layer for a sphere type.
|
|
108
|
+
*
|
|
109
|
+
* @param type - Sphere type
|
|
110
|
+
* @returns Layer ID (e.g. 'layer1')
|
|
111
|
+
*/
|
|
112
|
+
getLayerForSphereType(type) {
|
|
113
|
+
return SPHERE_CHANNEL_MAP[type].layer;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Get the preview color for a sphere type.
|
|
117
|
+
*
|
|
118
|
+
* If a volume is available for the target layer, uses the volume's
|
|
119
|
+
* custom color map (respects per-layer color customization).
|
|
120
|
+
* Otherwise falls back to SPHERE_COLORS (derived from CHANNEL_HEX_COLORS).
|
|
121
|
+
*
|
|
122
|
+
* @param type - Sphere type
|
|
123
|
+
* @returns CSS color string (hex)
|
|
124
|
+
*/
|
|
125
|
+
getColorForSphereType(type) {
|
|
126
|
+
const { layer, channel } = SPHERE_CHANNEL_MAP[type];
|
|
127
|
+
const volumes = this.ctx.protectedData.maskData.volumes;
|
|
128
|
+
const volume = volumes[layer];
|
|
129
|
+
if (volume) {
|
|
130
|
+
// Use per-layer custom color if available
|
|
131
|
+
const rgba = volume.getChannelColor(channel);
|
|
132
|
+
// Convert RGBA to hex
|
|
133
|
+
const r = rgba.r.toString(16).padStart(2, '0');
|
|
134
|
+
const g = rgba.g.toString(16).padStart(2, '0');
|
|
135
|
+
const b = rgba.b.toString(16).padStart(2, '0');
|
|
136
|
+
return `#${r}${g}${b}`;
|
|
137
|
+
}
|
|
138
|
+
return CHANNEL_HEX_COLORS[channel];
|
|
139
|
+
}
|
|
20
140
|
// ===== Sphere Canvas Size =====
|
|
21
141
|
setSphereCanvasSize(axis) {
|
|
22
142
|
const nrrd = this.ctx.nrrd_states;
|
|
23
143
|
switch (axis !== null && axis !== void 0 ? axis : this.ctx.protectedData.axis) {
|
|
24
144
|
case "x":
|
|
25
|
-
this.ctx.protectedData.canvases.drawingSphereCanvas.width = nrrd.nrrd_z_mm;
|
|
26
|
-
this.ctx.protectedData.canvases.drawingSphereCanvas.height = nrrd.nrrd_y_mm;
|
|
145
|
+
this.ctx.protectedData.canvases.drawingSphereCanvas.width = nrrd.image.nrrd_z_mm;
|
|
146
|
+
this.ctx.protectedData.canvases.drawingSphereCanvas.height = nrrd.image.nrrd_y_mm;
|
|
27
147
|
break;
|
|
28
148
|
case "y":
|
|
29
|
-
this.ctx.protectedData.canvases.drawingSphereCanvas.width = nrrd.nrrd_x_mm;
|
|
30
|
-
this.ctx.protectedData.canvases.drawingSphereCanvas.height = nrrd.nrrd_z_mm;
|
|
149
|
+
this.ctx.protectedData.canvases.drawingSphereCanvas.width = nrrd.image.nrrd_x_mm;
|
|
150
|
+
this.ctx.protectedData.canvases.drawingSphereCanvas.height = nrrd.image.nrrd_z_mm;
|
|
31
151
|
break;
|
|
32
152
|
case "z":
|
|
33
|
-
this.ctx.protectedData.canvases.drawingSphereCanvas.width = nrrd.nrrd_x_mm;
|
|
34
|
-
this.ctx.protectedData.canvases.drawingSphereCanvas.height = nrrd.nrrd_y_mm;
|
|
153
|
+
this.ctx.protectedData.canvases.drawingSphereCanvas.width = nrrd.image.nrrd_x_mm;
|
|
154
|
+
this.ctx.protectedData.canvases.drawingSphereCanvas.height = nrrd.image.nrrd_y_mm;
|
|
35
155
|
break;
|
|
36
156
|
}
|
|
37
157
|
}
|
|
38
158
|
// ===== Core Sphere Drawing =====
|
|
159
|
+
/**
|
|
160
|
+
* Draw a filled circle on the given context.
|
|
161
|
+
*
|
|
162
|
+
* @param ctx - Canvas 2D context
|
|
163
|
+
* @param x - Center X coordinate
|
|
164
|
+
* @param y - Center Y coordinate
|
|
165
|
+
* @param radius - Circle radius in pixels
|
|
166
|
+
* @param color - Fill color (CSS string)
|
|
167
|
+
*/
|
|
39
168
|
drawSphereCore(ctx, x, y, radius, color) {
|
|
40
169
|
ctx.beginPath();
|
|
41
170
|
ctx.arc(x, y, radius, 0, 2 * Math.PI);
|
|
@@ -57,50 +186,84 @@ export class SphereTool extends BaseTool {
|
|
|
57
186
|
this.ctx.protectedData.ctxes.drawingSphereCtx,
|
|
58
187
|
];
|
|
59
188
|
}
|
|
189
|
+
/**
|
|
190
|
+
* Draw a sphere preview circle on the sphere canvas using the current
|
|
191
|
+
* gui_states.fillColor. Called during sphere mode pointer-down.
|
|
192
|
+
*
|
|
193
|
+
* NOTE: Does NOT composite to master canvas — the start() render loop
|
|
194
|
+
* draws the sphere canvas directly to drawingCtx for proper layering.
|
|
195
|
+
*/
|
|
60
196
|
drawSphere(mouseX, mouseY, radius) {
|
|
61
|
-
const [
|
|
62
|
-
|
|
63
|
-
|
|
197
|
+
const [, ctx] = this.clearSphereCanvas();
|
|
198
|
+
const color = this.getColorForSphereType(this.ctx.gui_states.mode.activeSphereType);
|
|
199
|
+
drawSphereCore(ctx, mouseX, mouseY, radius, color);
|
|
64
200
|
}
|
|
65
201
|
// ===== Sphere Wheel =====
|
|
202
|
+
/**
|
|
203
|
+
* Returns a wheel event handler that adjusts sphere radius while the user
|
|
204
|
+
* holds left-click in sphere mode.
|
|
205
|
+
*
|
|
206
|
+
* Radius is clamped to [1, 50].
|
|
207
|
+
*/
|
|
66
208
|
configMouseSphereWheel() {
|
|
67
209
|
return (e) => {
|
|
68
210
|
e.preventDefault();
|
|
69
211
|
if (e.deltaY < 0) {
|
|
70
|
-
this.ctx.nrrd_states.sphereRadius += 1;
|
|
212
|
+
this.ctx.nrrd_states.sphere.sphereRadius += 1;
|
|
71
213
|
}
|
|
72
214
|
else {
|
|
73
|
-
this.ctx.nrrd_states.sphereRadius -= 1;
|
|
215
|
+
this.ctx.nrrd_states.sphere.sphereRadius -= 1;
|
|
74
216
|
}
|
|
75
|
-
this.ctx.nrrd_states.sphereRadius = Math.max(1, Math.min(this.ctx.nrrd_states.sphereRadius, 50));
|
|
76
|
-
const mouseX = this.ctx.nrrd_states.sphereOrigin[this.ctx.protectedData.axis][0];
|
|
77
|
-
const mouseY = this.ctx.nrrd_states.sphereOrigin[this.ctx.protectedData.axis][1];
|
|
78
|
-
this.drawSphere(mouseX, mouseY, this.ctx.nrrd_states.sphereRadius);
|
|
217
|
+
this.ctx.nrrd_states.sphere.sphereRadius = Math.max(1, Math.min(this.ctx.nrrd_states.sphere.sphereRadius, 50));
|
|
218
|
+
const mouseX = this.ctx.nrrd_states.sphere.sphereOrigin[this.ctx.protectedData.axis][0];
|
|
219
|
+
const mouseY = this.ctx.nrrd_states.sphere.sphereOrigin[this.ctx.protectedData.axis][1];
|
|
220
|
+
this.drawSphere(mouseX, mouseY, this.ctx.nrrd_states.sphere.sphereRadius);
|
|
79
221
|
};
|
|
80
222
|
}
|
|
81
223
|
// ===== Store Sphere Images =====
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
224
|
+
/**
|
|
225
|
+
* Store sphere slice image into SphereMaskVolume.
|
|
226
|
+
*
|
|
227
|
+
* Currently a no-op — sphere slice data is rendered as overlay only.
|
|
228
|
+
*
|
|
229
|
+
* TODO: Future — write sphere circle data into nrrd_states.sphereMaskVolume
|
|
230
|
+
* at the specified slice index and axis. Use SPHERE_CHANNEL_MAP to determine
|
|
231
|
+
* the target channel when integrating with layer MaskVolume.
|
|
232
|
+
*/
|
|
233
|
+
storeSphereImages(_index, _axis) {
|
|
234
|
+
// No-op: sphere slice storage is rendered as overlay.
|
|
235
|
+
// Future: write to nrrd_states.sphereMaskVolume here.
|
|
87
236
|
}
|
|
88
237
|
// ===== Multi-View Sphere =====
|
|
238
|
+
/**
|
|
239
|
+
* Draw a sphere cross-section at a given decay distance from center,
|
|
240
|
+
* for a specific axis view.
|
|
241
|
+
*
|
|
242
|
+
* Called for each decay value [0..sphereRadius] for all 3 axes,
|
|
243
|
+
* creating the 3D sphere effect.
|
|
244
|
+
*
|
|
245
|
+
* The sphere circle radius at each slice = sphereRadius - decay (linear decay).
|
|
246
|
+
*
|
|
247
|
+
* @param decay - Distance from sphere center slice
|
|
248
|
+
* @param axis - Axis to render on ('x', 'y', 'z')
|
|
249
|
+
*/
|
|
89
250
|
drawSphereOnEachViews(decay, axis) {
|
|
90
251
|
this.setSphereCanvasSize(axis);
|
|
91
|
-
const mouseX = this.ctx.nrrd_states.sphereOrigin[axis][0];
|
|
92
|
-
const mouseY = this.ctx.nrrd_states.sphereOrigin[axis][1];
|
|
93
|
-
const originIndex = this.ctx.nrrd_states.sphereOrigin[axis][2];
|
|
252
|
+
const mouseX = this.ctx.nrrd_states.sphere.sphereOrigin[axis][0];
|
|
253
|
+
const mouseY = this.ctx.nrrd_states.sphere.sphereOrigin[axis][1];
|
|
254
|
+
const originIndex = this.ctx.nrrd_states.sphere.sphereOrigin[axis][2];
|
|
94
255
|
const preIndex = originIndex - decay;
|
|
95
256
|
const nextIndex = originIndex + decay;
|
|
96
257
|
const ctx = this.ctx.protectedData.ctxes.drawingSphereCtx;
|
|
97
258
|
const canvas = this.ctx.protectedData.canvases.drawingSphereCanvas;
|
|
259
|
+
// Use the dynamic type color instead of the static fillColor
|
|
260
|
+
const color = this.getColorForSphereType(this.ctx.gui_states.mode.activeSphereType);
|
|
98
261
|
if (preIndex === nextIndex) {
|
|
99
|
-
this.drawSphereCore(ctx, mouseX, mouseY, this.ctx.nrrd_states.sphereRadius,
|
|
262
|
+
this.drawSphereCore(ctx, mouseX, mouseY, this.ctx.nrrd_states.sphere.sphereRadius, color);
|
|
100
263
|
this.storeSphereImages(preIndex, axis);
|
|
101
264
|
}
|
|
102
265
|
else {
|
|
103
|
-
this.drawSphereCore(ctx, mouseX, mouseY, this.ctx.nrrd_states.sphereRadius - decay,
|
|
266
|
+
this.drawSphereCore(ctx, mouseX, mouseY, this.ctx.nrrd_states.sphere.sphereRadius - decay, color);
|
|
104
267
|
this.callbacks.drawImageOnEmptyImage(canvas);
|
|
105
268
|
this.storeSphereImages(preIndex, axis);
|
|
106
269
|
this.storeSphereImages(nextIndex, axis);
|
|
@@ -115,22 +278,31 @@ export class SphereTool extends BaseTool {
|
|
|
115
278
|
z: position[axis][2],
|
|
116
279
|
};
|
|
117
280
|
}
|
|
281
|
+
/**
|
|
282
|
+
* Draw all 4 calculator sphere types on each view axis.
|
|
283
|
+
*
|
|
284
|
+
* Groups sphere positions by their slice index so that spheres on the
|
|
285
|
+
* same slice are drawn together before storing.
|
|
286
|
+
*
|
|
287
|
+
* Uses SPHERE_COLORS for each sphere type instead of nrrd_states.*Color.
|
|
288
|
+
*/
|
|
118
289
|
drawCalculatorSphereOnEachViews(axis) {
|
|
119
290
|
this.setSphereCanvasSize(axis);
|
|
120
291
|
const ctx = this.ctx.protectedData.ctxes.drawingSphereCtx;
|
|
121
292
|
const canvas = this.ctx.protectedData.canvases.drawingSphereCanvas;
|
|
122
293
|
const nrrd = this.ctx.nrrd_states;
|
|
123
|
-
|
|
124
|
-
|
|
294
|
+
// Build position list with dynamic sphere type colors
|
|
295
|
+
const tumourPosition = nrrd.sphere.tumourSphereOrigin
|
|
296
|
+
? Object.assign(this.getSpherePosition(nrrd.sphere.tumourSphereOrigin, axis), { color: this.getColorForSphereType('tumour') })
|
|
125
297
|
: null;
|
|
126
|
-
const skinPosition = nrrd.skinSphereOrigin
|
|
127
|
-
? Object.assign(this.getSpherePosition(nrrd.skinSphereOrigin, axis), { color:
|
|
298
|
+
const skinPosition = nrrd.sphere.skinSphereOrigin
|
|
299
|
+
? Object.assign(this.getSpherePosition(nrrd.sphere.skinSphereOrigin, axis), { color: this.getColorForSphereType('skin') })
|
|
128
300
|
: null;
|
|
129
|
-
const ribcagePosition = nrrd.ribSphereOrigin
|
|
130
|
-
? Object.assign(this.getSpherePosition(nrrd.ribSphereOrigin, axis), { color:
|
|
301
|
+
const ribcagePosition = nrrd.sphere.ribSphereOrigin
|
|
302
|
+
? Object.assign(this.getSpherePosition(nrrd.sphere.ribSphereOrigin, axis), { color: this.getColorForSphereType('ribcage') })
|
|
131
303
|
: null;
|
|
132
|
-
const nipplePosition = nrrd.nippleSphereOrigin
|
|
133
|
-
? Object.assign(this.getSpherePosition(nrrd.nippleSphereOrigin, axis), { color:
|
|
304
|
+
const nipplePosition = nrrd.sphere.nippleSphereOrigin
|
|
305
|
+
? Object.assign(this.getSpherePosition(nrrd.sphere.nippleSphereOrigin, axis), { color: this.getColorForSphereType('nipple') })
|
|
134
306
|
: null;
|
|
135
307
|
const positionGroup = [];
|
|
136
308
|
if (tumourPosition)
|
|
@@ -162,32 +334,325 @@ export class SphereTool extends BaseTool {
|
|
|
162
334
|
});
|
|
163
335
|
rePositionGroup.forEach((group) => {
|
|
164
336
|
group.forEach((p) => {
|
|
165
|
-
this.drawSphereCore(ctx, p.x, p.y, nrrd.sphereRadius, p.color);
|
|
337
|
+
this.drawSphereCore(ctx, p.x, p.y, nrrd.sphere.sphereRadius, p.color);
|
|
166
338
|
});
|
|
167
339
|
this.storeSphereImages(group[0].z, axis);
|
|
168
340
|
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
|
169
341
|
});
|
|
170
342
|
}
|
|
343
|
+
/**
|
|
344
|
+
* Draw all placed calculator spheres on the current slice.
|
|
345
|
+
*
|
|
346
|
+
* Called every frame to show existing sphere markers on the current view.
|
|
347
|
+
* Uses SPHERE_COLORS for consistent type-based coloring.
|
|
348
|
+
*
|
|
349
|
+
* @param radius - Sphere radius to draw
|
|
350
|
+
*/
|
|
171
351
|
drawCalculatorSphere(radius) {
|
|
172
|
-
const [
|
|
352
|
+
const [, ctx] = this.clearSphereCanvas();
|
|
173
353
|
const nrrd = this.ctx.nrrd_states;
|
|
174
354
|
const axis = this.ctx.protectedData.axis;
|
|
175
|
-
if (nrrd.tumourSphereOrigin && nrrd.tumourSphereOrigin[axis][2] === nrrd.
|
|
176
|
-
this.drawSphereCore(ctx, nrrd.tumourSphereOrigin[axis][0], nrrd.tumourSphereOrigin[axis][1], radius,
|
|
355
|
+
if (nrrd.sphere.tumourSphereOrigin && nrrd.sphere.tumourSphereOrigin[axis][2] === nrrd.view.currentSliceIndex) {
|
|
356
|
+
this.drawSphereCore(ctx, nrrd.sphere.tumourSphereOrigin[axis][0], nrrd.sphere.tumourSphereOrigin[axis][1], radius, this.getColorForSphereType('tumour'));
|
|
177
357
|
}
|
|
178
|
-
if (nrrd.skinSphereOrigin && nrrd.skinSphereOrigin[axis][2] === nrrd.
|
|
179
|
-
this.drawSphereCore(ctx, nrrd.skinSphereOrigin[axis][0], nrrd.skinSphereOrigin[axis][1], radius,
|
|
358
|
+
if (nrrd.sphere.skinSphereOrigin && nrrd.sphere.skinSphereOrigin[axis][2] === nrrd.view.currentSliceIndex) {
|
|
359
|
+
this.drawSphereCore(ctx, nrrd.sphere.skinSphereOrigin[axis][0], nrrd.sphere.skinSphereOrigin[axis][1], radius, this.getColorForSphereType('skin'));
|
|
180
360
|
}
|
|
181
|
-
if (nrrd.ribSphereOrigin && nrrd.ribSphereOrigin[axis][2] === nrrd.
|
|
182
|
-
this.drawSphereCore(ctx, nrrd.ribSphereOrigin[axis][0], nrrd.ribSphereOrigin[axis][1], radius,
|
|
361
|
+
if (nrrd.sphere.ribSphereOrigin && nrrd.sphere.ribSphereOrigin[axis][2] === nrrd.view.currentSliceIndex) {
|
|
362
|
+
this.drawSphereCore(ctx, nrrd.sphere.ribSphereOrigin[axis][0], nrrd.sphere.ribSphereOrigin[axis][1], radius, this.getColorForSphereType('ribcage'));
|
|
183
363
|
}
|
|
184
|
-
if (nrrd.nippleSphereOrigin && nrrd.nippleSphereOrigin[axis][2] === nrrd.
|
|
185
|
-
this.drawSphereCore(ctx, nrrd.nippleSphereOrigin[axis][0], nrrd.nippleSphereOrigin[axis][1], radius,
|
|
364
|
+
if (nrrd.sphere.nippleSphereOrigin && nrrd.sphere.nippleSphereOrigin[axis][2] === nrrd.view.currentSliceIndex) {
|
|
365
|
+
this.drawSphereCore(ctx, nrrd.sphere.nippleSphereOrigin[axis][0], nrrd.sphere.nippleSphereOrigin[axis][1], radius, this.getColorForSphereType('nipple'));
|
|
186
366
|
}
|
|
187
|
-
|
|
367
|
+
// NOTE: Does NOT composite to master canvas — the start() render loop
|
|
368
|
+
// draws the sphere canvas directly to drawingCtx for proper layering.
|
|
188
369
|
}
|
|
189
|
-
|
|
190
|
-
|
|
370
|
+
// ===== Sphere Click & PointerUp (extracted from DrawToolCore) =====
|
|
371
|
+
/**
|
|
372
|
+
* Handle left-click in sphere mode — record origin, draw preview.
|
|
373
|
+
*
|
|
374
|
+
* Performs all data operations for sphere placement:
|
|
375
|
+
* 1. Record sphere origin for current axis
|
|
376
|
+
* 2. Convert origin to all three axes via setUpSphereOrigins
|
|
377
|
+
* 3. Store origin for the active sphere type
|
|
378
|
+
* 4. Enable crosshair at click position
|
|
379
|
+
* 5. Draw calculator sphere preview
|
|
380
|
+
*
|
|
381
|
+
* Event binding (wheel, pointerup) stays in DrawToolCore as orchestration.
|
|
382
|
+
*/
|
|
383
|
+
onSphereClick(e) {
|
|
384
|
+
const mouseX = e.offsetX / this.ctx.nrrd_states.view.sizeFactor;
|
|
385
|
+
const mouseY = e.offsetY / this.ctx.nrrd_states.view.sizeFactor;
|
|
386
|
+
const axis = this.ctx.protectedData.axis;
|
|
387
|
+
// Record sphere origin for current axis
|
|
388
|
+
this.ctx.nrrd_states.sphere.sphereOrigin[axis] = [
|
|
389
|
+
mouseX,
|
|
390
|
+
mouseY,
|
|
391
|
+
this.ctx.nrrd_states.view.currentSliceIndex,
|
|
392
|
+
];
|
|
393
|
+
this.callbacks.setUpSphereOrigins(mouseX, mouseY, this.ctx.nrrd_states.view.currentSliceIndex);
|
|
394
|
+
// Store origin for the active sphere type
|
|
395
|
+
const originCopy = JSON.parse(JSON.stringify(this.ctx.nrrd_states.sphere.sphereOrigin));
|
|
396
|
+
switch (this.ctx.gui_states.mode.activeSphereType) {
|
|
397
|
+
case "tumour":
|
|
398
|
+
this.ctx.nrrd_states.sphere.tumourSphereOrigin = originCopy;
|
|
399
|
+
break;
|
|
400
|
+
case "skin":
|
|
401
|
+
this.ctx.nrrd_states.sphere.skinSphereOrigin = originCopy;
|
|
402
|
+
break;
|
|
403
|
+
case "nipple":
|
|
404
|
+
this.ctx.nrrd_states.sphere.nippleSphereOrigin = originCopy;
|
|
405
|
+
break;
|
|
406
|
+
case "ribcage":
|
|
407
|
+
this.ctx.nrrd_states.sphere.ribSphereOrigin = originCopy;
|
|
408
|
+
break;
|
|
409
|
+
}
|
|
410
|
+
// Enable crosshair at click position
|
|
411
|
+
this.ctx.nrrd_states.interaction.cursorPageX = mouseX;
|
|
412
|
+
this.ctx.nrrd_states.interaction.cursorPageY = mouseY;
|
|
413
|
+
this.callbacks.enableCrosshair();
|
|
414
|
+
// Draw calculator sphere preview
|
|
415
|
+
this.drawCalculatorSphere(this.ctx.nrrd_states.sphere.sphereRadius);
|
|
416
|
+
}
|
|
417
|
+
/**
|
|
418
|
+
* Handle pointer-up in sphere mode — write to volume, fire callbacks.
|
|
419
|
+
*
|
|
420
|
+
* Performs:
|
|
421
|
+
* 1. Write all placed calculator spheres to sphereMaskVolume
|
|
422
|
+
* 2. Refresh sphere canvas overlay from volume
|
|
423
|
+
* 3. Fire onSphereChanged and onCalculatorPositionsChanged callbacks
|
|
424
|
+
*
|
|
425
|
+
* Event cleanup (wheel, pointerup listener removal) stays in DrawToolCore.
|
|
426
|
+
*/
|
|
427
|
+
onSpherePointerUp() {
|
|
428
|
+
this.writeAllCalculatorSpheresToVolume();
|
|
429
|
+
this.refreshSphereCanvas();
|
|
430
|
+
this.ctx.callbacks.onSphereChanged(this.ctx.nrrd_states.sphere.sphereOrigin.z, this.ctx.nrrd_states.sphere.sphereRadius /
|
|
431
|
+
this.ctx.nrrd_states.view.sizeFactor);
|
|
432
|
+
this.ctx.callbacks.onCalculatorPositionsChanged(this.ctx.nrrd_states.sphere.tumourSphereOrigin, this.ctx.nrrd_states.sphere.skinSphereOrigin, this.ctx.nrrd_states.sphere.ribSphereOrigin, this.ctx.nrrd_states.sphere.nippleSphereOrigin, this.ctx.protectedData.axis);
|
|
191
433
|
}
|
|
434
|
+
// ===== 3D Sphere Volume Write =====
|
|
435
|
+
/**
|
|
436
|
+
* Convert canvas (mm-space) coordinates to 3D voxel coordinates.
|
|
437
|
+
*
|
|
438
|
+
* @param canvasX - X position in canvas mm-space
|
|
439
|
+
* @param canvasY - Y position in canvas mm-space
|
|
440
|
+
* @param sliceIndex - Slice index along the viewing axis
|
|
441
|
+
* @param axis - Viewing axis where the sphere was placed
|
|
442
|
+
* @returns 3D voxel coordinates { x, y, z }
|
|
443
|
+
*/
|
|
444
|
+
canvasToVoxelCenter(canvasX, canvasY, sliceIndex, axis) {
|
|
445
|
+
const nrrd = this.ctx.nrrd_states;
|
|
446
|
+
switch (axis) {
|
|
447
|
+
case 'z':
|
|
448
|
+
return {
|
|
449
|
+
x: canvasX * nrrd.image.nrrd_x_pixel / nrrd.image.nrrd_x_mm,
|
|
450
|
+
y: canvasY * nrrd.image.nrrd_y_pixel / nrrd.image.nrrd_y_mm,
|
|
451
|
+
z: sliceIndex,
|
|
452
|
+
};
|
|
453
|
+
case 'y':
|
|
454
|
+
return {
|
|
455
|
+
x: canvasX * nrrd.image.nrrd_x_pixel / nrrd.image.nrrd_x_mm,
|
|
456
|
+
y: sliceIndex,
|
|
457
|
+
z: (nrrd.image.nrrd_z_mm - canvasY) * nrrd.image.nrrd_z_pixel / nrrd.image.nrrd_z_mm,
|
|
458
|
+
};
|
|
459
|
+
case 'x':
|
|
460
|
+
return {
|
|
461
|
+
x: sliceIndex,
|
|
462
|
+
y: canvasY * nrrd.image.nrrd_y_pixel / nrrd.image.nrrd_y_mm,
|
|
463
|
+
z: canvasX * nrrd.image.nrrd_z_pixel / nrrd.image.nrrd_z_mm,
|
|
464
|
+
};
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
/**
|
|
468
|
+
* Write a 3D solid sphere to sphereMaskVolume.
|
|
469
|
+
*
|
|
470
|
+
* Converts the sphere center from canvas mm-space to voxel coordinates,
|
|
471
|
+
* then iterates over a bounding box and sets voxels within the sphere.
|
|
472
|
+
* The sphere is an ellipsoid in voxel space to appear circular in
|
|
473
|
+
* physical (mm) space on all axis views.
|
|
474
|
+
*
|
|
475
|
+
* @param label - Label value to write (1-4, default 1)
|
|
476
|
+
*/
|
|
477
|
+
write3DSphereToVolume(label = SPHERE_LABELS.default) {
|
|
478
|
+
const vol = this.ctx.nrrd_states.sphere.sphereMaskVolume;
|
|
479
|
+
if (!vol)
|
|
480
|
+
return;
|
|
481
|
+
const nrrd = this.ctx.nrrd_states;
|
|
482
|
+
const axis = this.ctx.protectedData.axis;
|
|
483
|
+
const dims = vol.getDimensions();
|
|
484
|
+
const origin = nrrd.sphere.sphereOrigin[axis];
|
|
485
|
+
const center = this.canvasToVoxelCenter(origin[0], origin[1], origin[2], axis);
|
|
486
|
+
const radius = nrrd.sphere.sphereRadius;
|
|
487
|
+
// Convert mm radius to voxels in each direction
|
|
488
|
+
const rx = radius * nrrd.image.nrrd_x_pixel / nrrd.image.nrrd_x_mm;
|
|
489
|
+
const ry = radius * nrrd.image.nrrd_y_pixel / nrrd.image.nrrd_y_mm;
|
|
490
|
+
const rz = radius * nrrd.image.nrrd_z_pixel / nrrd.image.nrrd_z_mm;
|
|
491
|
+
// Bounding box clamped to volume
|
|
492
|
+
const minX = Math.max(0, Math.floor(center.x - rx));
|
|
493
|
+
const maxX = Math.min(dims.width - 1, Math.ceil(center.x + rx));
|
|
494
|
+
const minY = Math.max(0, Math.floor(center.y - ry));
|
|
495
|
+
const maxY = Math.min(dims.height - 1, Math.ceil(center.y + ry));
|
|
496
|
+
const minZ = Math.max(0, Math.floor(center.z - rz));
|
|
497
|
+
const maxZ = Math.min(dims.depth - 1, Math.ceil(center.z + rz));
|
|
498
|
+
for (let z = minZ; z <= maxZ; z++) {
|
|
499
|
+
for (let y = minY; y <= maxY; y++) {
|
|
500
|
+
for (let x = minX; x <= maxX; x++) {
|
|
501
|
+
const dx = rx > 0 ? (x - center.x) / rx : 0;
|
|
502
|
+
const dy = ry > 0 ? (y - center.y) / ry : 0;
|
|
503
|
+
const dz = rz > 0 ? (z - center.z) / rz : 0;
|
|
504
|
+
if (dx * dx + dy * dy + dz * dz <= 1.0) {
|
|
505
|
+
vol.setVoxel(x, y, z, label);
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
/**
|
|
512
|
+
* Write a calculator sphere type to sphereMaskVolume.
|
|
513
|
+
* Uses the stored origin for the specified sphere type.
|
|
514
|
+
*
|
|
515
|
+
* @param type - Sphere type ('tumour', 'skin', 'nipple', 'ribcage')
|
|
516
|
+
*/
|
|
517
|
+
writeCalculatorSphereToVolume(type) {
|
|
518
|
+
const nrrd = this.ctx.nrrd_states;
|
|
519
|
+
const vol = nrrd.sphere.sphereMaskVolume;
|
|
520
|
+
if (!vol)
|
|
521
|
+
return;
|
|
522
|
+
let origin = null;
|
|
523
|
+
switch (type) {
|
|
524
|
+
case 'tumour':
|
|
525
|
+
origin = nrrd.sphere.tumourSphereOrigin;
|
|
526
|
+
break;
|
|
527
|
+
case 'skin':
|
|
528
|
+
origin = nrrd.sphere.skinSphereOrigin;
|
|
529
|
+
break;
|
|
530
|
+
case 'nipple':
|
|
531
|
+
origin = nrrd.sphere.nippleSphereOrigin;
|
|
532
|
+
break;
|
|
533
|
+
case 'ribcage':
|
|
534
|
+
origin = nrrd.sphere.ribSphereOrigin;
|
|
535
|
+
break;
|
|
536
|
+
}
|
|
537
|
+
if (!origin)
|
|
538
|
+
return;
|
|
539
|
+
const dims = vol.getDimensions();
|
|
540
|
+
const radius = nrrd.sphere.sphereRadius;
|
|
541
|
+
// Use z-axis representation for consistent voxel mapping
|
|
542
|
+
const cx = origin.z[0] * nrrd.image.nrrd_x_pixel / nrrd.image.nrrd_x_mm;
|
|
543
|
+
const cy = origin.z[1] * nrrd.image.nrrd_y_pixel / nrrd.image.nrrd_y_mm;
|
|
544
|
+
const cz = origin.z[2];
|
|
545
|
+
const rx = radius * nrrd.image.nrrd_x_pixel / nrrd.image.nrrd_x_mm;
|
|
546
|
+
const ry = radius * nrrd.image.nrrd_y_pixel / nrrd.image.nrrd_y_mm;
|
|
547
|
+
const rz = radius * nrrd.image.nrrd_z_pixel / nrrd.image.nrrd_z_mm;
|
|
548
|
+
const label = SPHERE_LABELS[type];
|
|
549
|
+
const minX = Math.max(0, Math.floor(cx - rx));
|
|
550
|
+
const maxX = Math.min(dims.width - 1, Math.ceil(cx + rx));
|
|
551
|
+
const minY = Math.max(0, Math.floor(cy - ry));
|
|
552
|
+
const maxY = Math.min(dims.height - 1, Math.ceil(cy + ry));
|
|
553
|
+
const minZ = Math.max(0, Math.floor(cz - rz));
|
|
554
|
+
const maxZ = Math.min(dims.depth - 1, Math.ceil(cz + rz));
|
|
555
|
+
for (let z = minZ; z <= maxZ; z++) {
|
|
556
|
+
for (let y = minY; y <= maxY; y++) {
|
|
557
|
+
for (let x = minX; x <= maxX; x++) {
|
|
558
|
+
const dx = rx > 0 ? (x - cx) / rx : 0;
|
|
559
|
+
const dy = ry > 0 ? (y - cy) / ry : 0;
|
|
560
|
+
const dz = rz > 0 ? (z - cz) / rz : 0;
|
|
561
|
+
if (dx * dx + dy * dy + dz * dz <= 1.0) {
|
|
562
|
+
vol.setVoxel(x, y, z, label);
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
/**
|
|
569
|
+
* Write all placed calculator spheres to the volume.
|
|
570
|
+
* Clears the volume first, then writes each placed sphere type.
|
|
571
|
+
*/
|
|
572
|
+
writeAllCalculatorSpheresToVolume() {
|
|
573
|
+
const nrrd = this.ctx.nrrd_states;
|
|
574
|
+
const vol = nrrd.sphere.sphereMaskVolume;
|
|
575
|
+
if (!vol)
|
|
576
|
+
return;
|
|
577
|
+
vol.clear();
|
|
578
|
+
if (nrrd.sphere.tumourSphereOrigin)
|
|
579
|
+
this.writeCalculatorSphereToVolume('tumour');
|
|
580
|
+
if (nrrd.sphere.skinSphereOrigin)
|
|
581
|
+
this.writeCalculatorSphereToVolume('skin');
|
|
582
|
+
if (nrrd.sphere.nippleSphereOrigin)
|
|
583
|
+
this.writeCalculatorSphereToVolume('nipple');
|
|
584
|
+
if (nrrd.sphere.ribSphereOrigin)
|
|
585
|
+
this.writeCalculatorSphereToVolume('ribcage');
|
|
586
|
+
}
|
|
587
|
+
// ===== Sphere Overlay Rendering from Volume =====
|
|
588
|
+
/**
|
|
589
|
+
* Render the current slice of sphereMaskVolume to drawingSphereCanvas.
|
|
590
|
+
*
|
|
591
|
+
* Called after any operation that changes the view (slice, axis, zoom)
|
|
592
|
+
* to keep the sphere overlay visible. Uses the same render pipeline as
|
|
593
|
+
* layer masks (emptyCanvas → sphere canvas at display scale).
|
|
594
|
+
*/
|
|
595
|
+
refreshSphereCanvas() {
|
|
596
|
+
const vol = this.ctx.nrrd_states.sphere.sphereMaskVolume;
|
|
597
|
+
const sphereCtx = this.ctx.protectedData.ctxes.drawingSphereCtx;
|
|
598
|
+
const sphereCanvas = this.ctx.protectedData.canvases.drawingSphereCanvas;
|
|
599
|
+
const nrrd = this.ctx.nrrd_states;
|
|
600
|
+
const axis = this.ctx.protectedData.axis;
|
|
601
|
+
// Set sphere canvas to origin (mm) dimensions — matches preview approach
|
|
602
|
+
this.setSphereCanvasSize(axis);
|
|
603
|
+
if (!vol)
|
|
604
|
+
return;
|
|
605
|
+
const sliceIndex = nrrd.view.currentSliceIndex;
|
|
606
|
+
try {
|
|
607
|
+
const dims = vol.getDimensions();
|
|
608
|
+
const maxSlice = axis === 'x' ? dims.width : axis === 'y' ? dims.height : dims.depth;
|
|
609
|
+
if (sliceIndex < 0 || sliceIndex >= maxSlice)
|
|
610
|
+
return;
|
|
611
|
+
// Get slice dimensions (voxel space)
|
|
612
|
+
const [sliceW, sliceH] = axis === 'z' ? [dims.width, dims.height]
|
|
613
|
+
: axis === 'y' ? [dims.width, dims.depth]
|
|
614
|
+
: [dims.depth, dims.height];
|
|
615
|
+
const imageData = new ImageData(sliceW, sliceH);
|
|
616
|
+
vol.renderLabelSliceInto(sliceIndex, axis, imageData, undefined, 1.0);
|
|
617
|
+
// Quick check if any data on this slice
|
|
618
|
+
let hasContent = false;
|
|
619
|
+
for (let i = 3; i < imageData.data.length; i += 4) {
|
|
620
|
+
if (imageData.data[i] > 0) {
|
|
621
|
+
hasContent = true;
|
|
622
|
+
break;
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
if (!hasContent)
|
|
626
|
+
return;
|
|
627
|
+
// Draw via emptyCanvas (same pattern as renderSliceToCanvas)
|
|
628
|
+
this.callbacks.setEmptyCanvasSize(axis);
|
|
629
|
+
this.ctx.protectedData.ctxes.emptyCtx.putImageData(imageData, 0, 0);
|
|
630
|
+
sphereCtx.imageSmoothingEnabled = true;
|
|
631
|
+
// Coronal axis ('y') needs vertical flip to match display coordinate system
|
|
632
|
+
if (axis === 'y') {
|
|
633
|
+
sphereCtx.save();
|
|
634
|
+
sphereCtx.scale(1, -1);
|
|
635
|
+
sphereCtx.translate(0, -sphereCanvas.height);
|
|
636
|
+
}
|
|
637
|
+
sphereCtx.drawImage(this.ctx.protectedData.canvases.emptyCanvas, 0, 0, sphereCanvas.width, sphereCanvas.height);
|
|
638
|
+
if (axis === 'y') {
|
|
639
|
+
sphereCtx.restore();
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
catch (_a) {
|
|
643
|
+
// Volume not ready or slice out of bounds
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
/**
|
|
648
|
+
* Standalone helper — draw a filled circle.
|
|
649
|
+
* Used internally and by drawSphere() for preview rendering.
|
|
650
|
+
*/
|
|
651
|
+
function drawSphereCore(ctx, x, y, radius, color) {
|
|
652
|
+
ctx.beginPath();
|
|
653
|
+
ctx.arc(x, y, radius, 0, 2 * Math.PI);
|
|
654
|
+
ctx.fillStyle = color;
|
|
655
|
+
ctx.fill();
|
|
656
|
+
ctx.closePath();
|
|
192
657
|
}
|
|
193
658
|
//# sourceMappingURL=SphereTool.js.map
|