Skip to content

Class: CoordinateTransformer

Defined in: src/display/CoordinateTransformer.ts:39

CoordinateTransformer wraps a SliceTransform and adds convenience methods for screen-based picking. Typically, you pass in a parent PIXI.Container that might be scaled, flipped, or panned, and the code uses toLocal() to find local slice coordinates, which are then converted to or from volume coordinates.

Coordinate System Chain: Screen (pixels) → Container Local (pixels) → Slice (mm) → Volume (voxels) → World (mm)

World Space Convention: NIFTI LPI (Left-Posterior-Inferior)

  • X-axis: Left (-) to Right (+)
  • Y-axis: Posterior (-) to Anterior (+)
  • Z-axis: Inferior (-) to Superior (+)

Implements

Constructors

Constructor

ts
new CoordinateTransformer(
   neuroSpace, 
   viewAxes, 
   initialSliceIndex?): CoordinateTransformer;

Defined in: src/display/CoordinateTransformer.ts:51

Constructs a CoordinateTransformer.

Parameters

neuroSpace

NeuroSpace

The NeuroSpace describing the 3D volume.

viewAxes

AxisSet3D

The AxisSet3D specifying how to orient the slice (e.g., AXIAL_LPI or SAGITTAL_AIL, etc.).

initialSliceIndex?

number = 0

The slice index along the pinned axis. Defaults to 0.

Returns

CoordinateTransformer

Methods

setSliceIndex()

ts
setSliceIndex(sliceIndex): void;

Defined in: src/display/CoordinateTransformer.ts:60

Updates the pinned slice index (k dimension) in the transform.

Parameters

sliceIndex

number

The new slice index to display or pick against.

Returns

void

Implementation of

ICoordinateTransformer.setSliceIndex


screenToImageCoord()

ts
screenToImageCoord(
   screenX, 
   screenY, 
   mainContainer): object;

Defined in: src/display/CoordinateTransformer.ts:78

Converts a screen position (e.g., mouse pointer in stage coordinates) to local slice coordinates. This uses PIXI's toLocal(), letting any translation or scaling in the container be accounted for automatically.

Typically, the container might be scaled negatively in Y to flip the slice upright, so local Y might be reversed from raw image data.

Parameters

screenX

number

The screen X coordinate (in global / stage space).

screenY

number

The screen Y coordinate (in global / stage space).

mainContainer

Container

The container in which the slice is rendered.

Returns

object

An object { x, y } in local slice coordinates.

x
ts
x: number;
y
ts
y: number;

Implementation of

ICoordinateTransformer.screenToImageCoord


screenToScaledImageCoord()

ts
screenToScaledImageCoord(
   screenX, 
   screenY, 
   mainContainer): object;

Defined in: src/display/CoordinateTransformer.ts:102

Converts a screen position to scaled image coordinates in millimeters. This first converts screen coordinates to local image coordinates (in pixels), then scales them by the pixel spacing to get coordinates in physical units (mm).

NOTE: Local image coordinates returned by PIXI are in pixels. Most of the math in SliceTransform expects slice coordinates in mm. Use this helper whenever you need mm-space from a screen position.

Parameters

screenX

number

The screen X coordinate (in global / stage space).

screenY

number

The screen Y coordinate (in global / stage space).

mainContainer

Container

The container in which the slice is rendered.

Returns

object

An object { x, y } in millimeters, scaled by pixel spacing.

x
ts
x: number;
y
ts
y: number;

screenToVolumeCoord()

ts
screenToVolumeCoord(
   screenX, 
   screenY, 
   mainContainer): number[] | null;

Defined in: src/display/CoordinateTransformer.ts:132

An all-in-one helper to go from screen coordinates directly to 3D volume coordinates. This calls toLocal() (screen -> pixels), then converts pixels to mm using slice pixel spacing, and finally uses SliceTransform to map to voxel coordinates.

Parameters

screenX

number

The screen X coordinate (mouse in stage space).

screenY

number

The screen Y coordinate.

mainContainer

Container

The parent container to interpret local coords.

Returns

number[] | null

A 3-element array [i, j, k] in volume/voxel space, typically floating if partial-voxel.


sliceToVolumeCoord()

ts
sliceToVolumeCoord(imagePt): number[];

Defined in: src/display/CoordinateTransformer.ts:151

Converts 2D local image coordinates (pixels) to volume coordinates. This uses SliceTransform.imageToVolumeCoord, which applies pixel spacing to obtain mm before solving for voxel coordinates with pinned k.

Parameters

imagePt

The local image coordinate { x, y } in pixels.

x

number

y

number

Returns

number[]

A 3-element array [i, j, k] in the volume space.

Implementation of

ICoordinateTransformer.sliceToVolumeCoord


sliceToWorldCoord()

ts
sliceToWorldCoord(imagePt): number[];

Defined in: src/display/CoordinateTransformer.ts:162

Converts 2D local image coordinates (pixels) to original world coordinates (mm) in the un-pinned NeuroSpace.

Parameters

imagePt

The local image coordinate { x, y } in pixels.

x

number

y

number

Returns

number[]

A 3-element array [x, y, z] in world mm.

Implementation of

ICoordinateTransformer.sliceToWorldCoord


volumeToLocalSliceCoord()

ts
volumeToLocalSliceCoord(volCoord): object;

Defined in: src/display/CoordinateTransformer.ts:177

The inverse of sliceToVolumeCoord. Given [i, j, k] in volume space, returns the local slice coordinate [x, y].

Use this, for example, to place a crosshair or highlight a particular volume coordinate on the 2D slice.

Parameters

volCoord

number[]

A 3-element array [i, j, k] in volume space.

Returns

object

The local 2D coordinate { x, y }, which can be used to position PIXI display objects within the container.

x
ts
x: number;
y
ts
y: number;

screenToVolumeCoordSafe()

ts
screenToVolumeCoordSafe(
   screenX, 
   screenY, 
   mainContainer, 
   options?): number[] | null;

Defined in: src/display/CoordinateTransformer.ts:191

Safe version of screenToVolumeCoord that validates coordinates

Parameters

screenX

number

The screen X coordinate

screenY

number

The screen Y coordinate

mainContainer

Container

The parent container

options?

ValidationOptions = {}

Validation options

Returns

number[] | null

A 3-element array or null if invalid


sliceToVolumeCoordSafe()

ts
sliceToVolumeCoordSafe(imagePt, options?): number[] | null;

Defined in: src/display/CoordinateTransformer.ts:220

Safe version of sliceToVolumeCoord with validation

Parameters

imagePt
x

number

y

number

options?

ValidationOptions = {}

Validation options

Returns

number[] | null

A 3-element array or null if invalid


volumeToLocalSliceCoordSafe()

ts
volumeToLocalSliceCoordSafe(volCoord, options?): 
  | {
  x: number;
  y: number;
}
  | null;

Defined in: src/display/CoordinateTransformer.ts:240

Safe version of volumeToLocalSliceCoord with validation

Parameters

volCoord

number[]

The volume coordinate

options?

ValidationOptions = {}

Validation options

Returns

| { x: number; y: number; } | null

The local 2D coordinate or null if invalid


getSliceBounds()

ts
getSliceBounds(): object;

Defined in: src/display/CoordinateTransformer.ts:254

Get the bounds for valid slice coordinates

Returns

object

Bounds in millimeters

minX
ts
minX: number;
maxX
ts
maxX: number;
minY
ts
minY: number;
maxY
ts
maxY: number;

isSliceIndexValid()

ts
isSliceIndexValid(): boolean;

Defined in: src/display/CoordinateTransformer.ts:262

Check if current slice index is valid

Returns

boolean

true if valid


validateSliceIndex()

ts
validateSliceIndex(
   sliceIndex, 
   totalSlices, 
   options?): number | null;

Defined in: src/display/CoordinateTransformer.ts:273

Validate and optionally clamp the slice index

Parameters

sliceIndex

number

The slice index to validate

totalSlices

number

Total number of slices

options?

ValidationOptions = {}

Validation options

Returns

number | null

Validated slice index or null

Released under the MIT License.