copper3d / Modules / Utils/segmentation/tools/SphereTool / SphereTool
Class: SphereTool
Utils/segmentation/tools/SphereTool.SphereTool
Hierarchy
BaseTool↳
SphereTool
Table of contents
Constructors
Properties
Methods
- canvasToVoxelCenter
- clearSphereCanvas
- configMouseSphereWheel
- drawCalculatorSphere
- drawCalculatorSphereOnEachViews
- drawSphere
- drawSphereCore
- drawSphereOnEachViews
- getChannelForSphereType
- getColorForSphereType
- getLayerForSphereType
- getSpherePosition
- onSphereClick
- onSpherePointerUp
- refreshSphereCanvas
- setCallbacks
- setContext
- setSphereCanvasSize
- storeSphereImages
- write3DSphereToVolume
- writeAllCalculatorSpheresToVolume
- writeCalculatorSphereToVolume
Constructors
constructor
• new SphereTool(ctx, callbacks)
Parameters
| Name | Type |
|---|---|
ctx | ToolContext |
callbacks | SphereHostDeps |
Overrides
BaseTool.constructor
Defined in
src/Utils/segmentation/tools/SphereTool.ts:98
Properties
callbacks
• Private callbacks: SphereHostDeps
Defined in
src/Utils/segmentation/tools/SphereTool.ts:96
ctx
• Protected ctx: ToolContext
Inherited from
BaseTool.ctx
Defined in
src/Utils/segmentation/tools/BaseTool.ts:37
Methods
canvasToVoxelCenter
▸ canvasToVoxelCenter(canvasX, canvasY, sliceIndex, axis): Object
Convert canvas (mm-space) coordinates to 3D voxel coordinates.
Parameters
| Name | Type | Description |
|---|---|---|
canvasX | number | X position in canvas mm-space |
canvasY | number | Y position in canvas mm-space |
sliceIndex | number | Slice index along the viewing axis |
axis | "z" | "y" | "x" | Viewing axis where the sphere was placed |
Returns
Object
3D voxel coordinates
| Name | Type |
|---|---|
x | number |
y | number |
z | number |
Defined in
src/Utils/segmentation/tools/SphereTool.ts:534
clearSphereCanvas
▸ clearSphereCanvas(): [HTMLCanvasElement, CanvasRenderingContext2D]
Returns
[HTMLCanvasElement, CanvasRenderingContext2D]
Defined in
src/Utils/segmentation/tools/SphereTool.ts:206
configMouseSphereWheel
▸ configMouseSphereWheel(): (e: WheelEvent) => void
Returns a wheel event handler that adjusts sphere radius while the user holds left-click in sphere mode.
Radius is clamped to [1, 50].
Returns
fn
▸ (e): void
Returns a wheel event handler that adjusts sphere radius while the user holds left-click in sphere mode.
Radius is clamped to [1, 50].
Parameters
| Name | Type |
|---|---|
e | WheelEvent |
Returns
void
Defined in
src/Utils/segmentation/tools/SphereTool.ts:242
drawCalculatorSphere
▸ drawCalculatorSphere(radius): void
Draw all placed calculator spheres on the current slice.
Called every frame to show existing sphere markers on the current view. Uses SPHERE_COLORS for consistent type-based coloring.
Parameters
| Name | Type | Description |
|---|---|---|
radius | number | Sphere radius to draw |
Returns
void
Defined in
src/Utils/segmentation/tools/SphereTool.ts:414
drawCalculatorSphereOnEachViews
▸ drawCalculatorSphereOnEachViews(axis): void
Draw all 4 calculator sphere types on each view axis.
Groups sphere positions by their slice index so that spheres on the same slice are drawn together before storing.
Uses SPHERE_COLORS for each sphere type instead of nrrd_states.*Color.
Parameters
| Name | Type |
|---|---|
axis | "z" | "y" | "x" |
Returns
void
Defined in
src/Utils/segmentation/tools/SphereTool.ts:344
drawSphere
▸ drawSphere(mouseX, mouseY, radius): void
Draw a sphere preview circle on the sphere canvas using the current gui_states.fillColor. Called during sphere mode pointer-down.
NOTE: Does NOT composite to master canvas — the start() render loop draws the sphere canvas directly to drawingCtx for proper layering.
Parameters
| Name | Type |
|---|---|
mouseX | number |
mouseY | number |
radius | number |
Returns
void
Defined in
src/Utils/segmentation/tools/SphereTool.ts:228
drawSphereCore
▸ drawSphereCore(ctx, x, y, radius, color): void
Draw a filled circle on the given context.
Parameters
| Name | Type | Description |
|---|---|---|
ctx | CanvasRenderingContext2D | Canvas 2D context |
x | number | Center X coordinate |
y | number | Center Y coordinate |
radius | number | Circle radius in pixels |
color | string | Fill color (CSS string) |
Returns
void
Defined in
src/Utils/segmentation/tools/SphereTool.ts:192
drawSphereOnEachViews
▸ drawSphereOnEachViews(decay, axis): void
Draw a sphere cross-section at a given decay distance from center, for a specific axis view.
Called for each decay value [0..sphereRadius] for all 3 axes, creating the 3D sphere effect.
The sphere circle radius at each slice = sphereRadius - decay (linear decay).
Parameters
| Name | Type | Description |
|---|---|---|
decay | number | Distance from sphere center slice |
axis | "z" | "y" | "x" | Axis to render on ('x', 'y', 'z') |
Returns
void
Defined in
src/Utils/segmentation/tools/SphereTool.ts:291
getChannelForSphereType
▸ getChannelForSphereType(type): number
Get the channel number for a sphere type.
Parameters
| Name | Type | Description |
|---|---|---|
type | SphereType | Sphere type ('tumour', 'skin', 'ribcage', 'nipple') |
Returns
number
Channel number (1-8) mapped to this sphere type
Example
sphereTool.getChannelForSphereType('tumour'); // → 1
sphereTool.getChannelForSphereType('skin'); // → 4sphereTool.getChannelForSphereType('tumour'); // → 1
sphereTool.getChannelForSphereType('skin'); // → 4Defined in
src/Utils/segmentation/tools/SphereTool.ts:121
getColorForSphereType
▸ getColorForSphereType(type): string
Get the preview color for a sphere type.
If a volume is available for the target layer, uses the volume's custom color map (respects per-layer color customization). Otherwise falls back to SPHERE_COLORS (derived from CHANNEL_HEX_COLORS).
Parameters
| Name | Type | Description |
|---|---|---|
type | SphereType | Sphere type |
Returns
string
CSS color string (hex)
Defined in
src/Utils/segmentation/tools/SphereTool.ts:145
getLayerForSphereType
▸ getLayerForSphereType(type): string
Get the default layer for a sphere type.
Parameters
| Name | Type | Description |
|---|---|---|
type | SphereType | Sphere type |
Returns
string
Layer ID (e.g. 'layer1')
Defined in
src/Utils/segmentation/tools/SphereTool.ts:131
getSpherePosition
▸ Private getSpherePosition(position, axis): Object
Parameters
| Name | Type |
|---|---|
position | ICommXYZ |
axis | "z" | "y" | "x" |
Returns
Object
| Name | Type |
|---|---|
x | number |
y | number |
z | number |
Defined in
src/Utils/segmentation/tools/SphereTool.ts:325
onSphereClick
▸ onSphereClick(e): void
Handle left-click in sphere mode — record origin, draw preview.
Performs all data operations for sphere placement:
- Record sphere origin for current axis
- Convert origin to all three axes via setUpSphereOrigins
- Store origin for the active sphere type
- Enable crosshair at click position
- Draw calculator sphere preview
Event binding (wheel, pointerup) stays in DrawToolCore as orchestration.
Parameters
| Name | Type |
|---|---|
e | MouseEvent |
Returns
void
Defined in
src/Utils/segmentation/tools/SphereTool.ts:449
onSpherePointerUp
▸ onSpherePointerUp(): void
Handle pointer-up in sphere mode — write to volume, fire callbacks.
Performs:
- Write all placed calculator spheres to sphereMaskVolume
- Refresh sphere canvas overlay from volume
- Fire onSphereChanged and onCalculatorPositionsChanged callbacks
Event cleanup (wheel, pointerup listener removal) stays in DrawToolCore.
Returns
void
Defined in
src/Utils/segmentation/tools/SphereTool.ts:504
refreshSphereCanvas
▸ refreshSphereCanvas(): void
Render the current slice of sphereMaskVolume to drawingSphereCanvas.
Called after any operation that changes the view (slice, axis, zoom) to keep the sphere overlay visible. Uses the same render pipeline as layer masks (emptyCanvas → sphere canvas at display scale).
Returns
void
Defined in
src/Utils/segmentation/tools/SphereTool.ts:688
setCallbacks
▸ setCallbacks(callbacks): void
Parameters
| Name | Type |
|---|---|
callbacks | SphereHostDeps |
Returns
void
Defined in
src/Utils/segmentation/tools/SphereTool.ts:103
setContext
▸ setContext(ctx): void
Parameters
| Name | Type |
|---|---|
ctx | ToolContext |
Returns
void
Inherited from
BaseTool.setContext
Defined in
src/Utils/segmentation/tools/BaseTool.ts:43
setSphereCanvasSize
▸ setSphereCanvasSize(axis?): void
Parameters
| Name | Type |
|---|---|
axis? | "z" | "y" | "x" |
Returns
void
Defined in
src/Utils/segmentation/tools/SphereTool.ts:163
storeSphereImages
▸ Private storeSphereImages(_index, _axis): void
Store sphere slice image into SphereMaskVolume.
Currently a no-op — sphere slice data is rendered as overlay only.
TODO: Future — write sphere circle data into nrrd_states.sphereMaskVolume at the specified slice index and axis. Use SPHERE_CHANNEL_MAP to determine the target channel when integrating with layer MaskVolume.
Parameters
| Name | Type |
|---|---|
_index | number |
_axis | "z" | "y" | "x" |
Returns
void
Defined in
src/Utils/segmentation/tools/SphereTool.ts:272
write3DSphereToVolume
▸ write3DSphereToVolume(label?): void
Write a 3D solid sphere to sphereMaskVolume.
Converts the sphere center from canvas mm-space to voxel coordinates, then iterates over a bounding box and sets voxels within the sphere. The sphere is an ellipsoid in voxel space to appear circular in physical (mm) space on all axis views.
Parameters
| Name | Type | Default value | Description |
|---|---|---|---|
label | number | SPHERE_LABELS.default | Label value to write (1-4, default 1) |
Returns
void
Defined in
src/Utils/segmentation/tools/SphereTool.ts:571
writeAllCalculatorSpheresToVolume
▸ writeAllCalculatorSpheresToVolume(): void
Write all placed calculator spheres to the volume. Clears the volume first, then writes each placed sphere type.
Returns
void
Defined in
src/Utils/segmentation/tools/SphereTool.ts:667
writeCalculatorSphereToVolume
▸ writeCalculatorSphereToVolume(type): void
Write a calculator sphere type to sphereMaskVolume. Uses the stored origin for the specified sphere type.
Parameters
| Name | Type | Description |
|---|---|---|
type | SphereType | Sphere type ('tumour', 'skin', 'nipple', 'ribcage') |
Returns
void