Skip to content

copper3d / Modules / Utils/segmentation/tools/SphereTool / SphereTool

Class: SphereTool

Utils/segmentation/tools/SphereTool.SphereTool

Hierarchy

  • BaseTool

    SphereTool

Table of contents

Constructors

Properties

Methods

Constructors

constructor

new SphereTool(ctx, callbacks)

Parameters

NameType
ctxToolContext
callbacksSphereHostDeps

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

NameTypeDescription
canvasXnumberX position in canvas mm-space
canvasYnumberY position in canvas mm-space
sliceIndexnumberSlice index along the viewing axis
axis"z" | "y" | "x"Viewing axis where the sphere was placed

Returns

Object

3D voxel coordinates

NameType
xnumber
ynumber
znumber

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
NameType
eWheelEvent
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

NameTypeDescription
radiusnumberSphere 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

NameType
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

NameType
mouseXnumber
mouseYnumber
radiusnumber

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

NameTypeDescription
ctxCanvasRenderingContext2DCanvas 2D context
xnumberCenter X coordinate
ynumberCenter Y coordinate
radiusnumberCircle radius in pixels
colorstringFill 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

NameTypeDescription
decaynumberDistance 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

NameTypeDescription
typeSphereTypeSphere type ('tumour', 'skin', 'ribcage', 'nipple')

Returns

number

Channel number (1-8) mapped to this sphere type

Example

ts
sphereTool.getChannelForSphereType('tumour');  // → 1
sphereTool.getChannelForSphereType('skin');    // → 4
sphereTool.getChannelForSphereType('tumour');  // → 1
sphereTool.getChannelForSphereType('skin');    // → 4

Defined 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

NameTypeDescription
typeSphereTypeSphere 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

NameTypeDescription
typeSphereTypeSphere type

Returns

string

Layer ID (e.g. 'layer1')

Defined in

src/Utils/segmentation/tools/SphereTool.ts:131


getSpherePosition

Private getSpherePosition(position, axis): Object

Parameters

NameType
positionICommXYZ
axis"z" | "y" | "x"

Returns

Object

NameType
xnumber
ynumber
znumber

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:

  1. Record sphere origin for current axis
  2. Convert origin to all three axes via setUpSphereOrigins
  3. Store origin for the active sphere type
  4. Enable crosshair at click position
  5. Draw calculator sphere preview

Event binding (wheel, pointerup) stays in DrawToolCore as orchestration.

Parameters

NameType
eMouseEvent

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:

  1. Write all placed calculator spheres to sphereMaskVolume
  2. Refresh sphere canvas overlay from volume
  3. 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

NameType
callbacksSphereHostDeps

Returns

void

Defined in

src/Utils/segmentation/tools/SphereTool.ts:103


setContext

setContext(ctx): void

Parameters

NameType
ctxToolContext

Returns

void

Inherited from

BaseTool.setContext

Defined in

src/Utils/segmentation/tools/BaseTool.ts:43


setSphereCanvasSize

setSphereCanvasSize(axis?): void

Parameters

NameType
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

NameType
_indexnumber
_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

NameTypeDefault valueDescription
labelnumberSPHERE_LABELS.defaultLabel 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

NameTypeDescription
typeSphereTypeSphere type ('tumour', 'skin', 'nipple', 'ribcage')

Returns

void

Defined in

src/Utils/segmentation/tools/SphereTool.ts:616