Skip to content

Class: SliceModel

Defined in: src/display/SliceModel.ts:32

SliceModel represents the state of a single 2D slice within a 3D volume. It tracks:

  • currentCoord: The user’s current 3D coordinate in real-world mm (per NeuroSpace).
  • currentSliceIndex: Computed by projecting currentCoord onto the pinned dimension.
  • Methods to move to the next or previous slice.

IMPORTANT:

  • currentCoord must be a millimeter-space coordinate if NeuroSpace is configured for real-world mm. If you have voxel coords [i,j,k], do: const mmCoord = neuroSpace.gridToCoord(voxelCoord); sliceModel.setCurrentCoord(mmCoord); Otherwise currentSliceIndex will be incorrect.

Implements

Constructors

Constructor

ts
new SliceModel(
   totalSlices, 
   initialCoord, 
   neuroSpace, 
   viewAxes): SliceModel;

Defined in: src/display/SliceModel.ts:58

Constructs a new SliceModel.

Parameters

totalSlices

number

The number of slices along the movement axis.

initialCoord

number[]

The initial real-world mm 3D coordinate in the volume.

neuroSpace

NeuroSpace

The NeuroSpace describing dimension, spacing, transform, etc.

viewAxes

AxisSet3D

Which orientation axes we are using (e.g. AXIAL_LPI), from which we derive the pinned dimension.

Returns

SliceModel

Properties

currentCoord

ts
currentCoord: number[] = [];

Defined in: src/display/SliceModel.ts:37

The current 3D coordinate [X, Y, Z], stored in real-world mm space (consistent with the NeuroSpace transform).

Implementation of

ISliceModel.currentCoord


totalSlices

ts
totalSlices: number;

Defined in: src/display/SliceModel.ts:44

totalSlices is the maximum number of discrete slices along the pinned axis. For example, in a 256×256×128 volume, if the pinned axis is dimension #2, totalSlices might be 128.

Implementation of

ISliceModel.totalSlices

Accessors

currentSliceIndex

Get Signature

ts
get currentSliceIndex(): number;

Defined in: src/display/SliceModel.ts:82

currentSliceIndex is derived by mapping the real-world currentCoord into voxel/grid space, then extracting the pinned dimension’s coordinate and rounding it.

Returns

number

Current slice index

Implementation of

ISliceModel.currentSliceIndex

Methods

setCurrentCoord()

ts
setCurrentCoord(coord): void;

Defined in: src/display/SliceModel.ts:97

Sets the model’s 3D coordinate to a new mm coordinate, ensuring MobX reactivity by copying the array.

Parameters

coord

number[]

The new [X, Y, Z] in real-world mm.

Returns

void

Implementation of

ISliceModel.setCurrentCoord


setCurrentCoordIfChanged()

ts
setCurrentCoordIfChanged(coord): void;

Defined in: src/display/SliceModel.ts:123

Helper to set the coordinate only if it differs from the existing coordinate.

Parameters

coord

number[]

The new [X, Y, Z] in real-world mm.

Returns

void


setCurrentSliceIndex()

ts
setCurrentSliceIndex(index): void;

Defined in: src/display/SliceModel.ts:145

Sets the sliceIndex by updating the relevant dimension in voxel space, then converting back to mm (real-world) space for the model’s currentCoord.

Parameters

index

number

The new slice index (integer).

Returns

void

Implementation of

ISliceModel.setCurrentSliceIndex


previousSlice()

ts
previousSlice(): void;

Defined in: src/display/SliceModel.ts:173

Move to the previous slice, ensuring we don’t go below 0.

Returns

void

Implementation of

ISliceModel.previousSlice


nextSlice()

ts
nextSlice(): void;

Defined in: src/display/SliceModel.ts:182

Move to the next slice, ensuring we don’t exceed totalSlices - 1.

Returns

void

Implementation of

ISliceModel.nextSlice


getViewAxes()

ts
getViewAxes(): AxisSet3D;

Defined in: src/display/SliceModel.ts:190

Returns the AxisSet3D used by this model, e.g. AXIAL_LPI or CORONAL_LIP, etc.

Returns

AxisSet3D


onCoordChange()

ts
onCoordChange(callback): IReactionDisposer;

Defined in: src/display/SliceModel.ts:199

Subscribe to coordinate changes

Parameters

callback

(coord) => void

Function to call when coordinate changes

Returns

IReactionDisposer

Dispose function to unsubscribe

Implementation of

ISliceModel.onCoordChange


onSliceIndexChange()

ts
onSliceIndexChange(callback): IReactionDisposer;

Defined in: src/display/SliceModel.ts:211

Subscribe to slice index changes

Parameters

callback

(index) => void

Function to call when slice index changes

Returns

IReactionDisposer

Dispose function to unsubscribe

Implementation of

ISliceModel.onSliceIndexChange


dispose()

ts
dispose(): void;

Defined in: src/display/SliceModel.ts:221

Dispose of the model and clean up resources

Returns

void

Implementation of

ISliceModel.dispose

Released under the MIT License.