Skip to content

Class: VolLayer

Defined in: src/display/VolLayer.ts:34

VolLayer is a wrapper around a NeuroVol (3D neuroimaging volume) that manages slice extraction, caching, and color/opacity settings for visualization.

Supports any volume type implementing NeuroVol interface:

  • DenseNeuroVol: Dense typed array storage
  • SparseNeuroVol: Sparse voxel storage (memory efficient for masks/ROIs)
  • LogicalNeuroVol: Boolean mask volumes
  • ClusteredNeuroVol: Labeled/parcellated volumes

Constructors

Constructor

ts
new VolLayer(
   id, 
   volume, 
   colorMap, 
   range?, 
   threshold?, 
   opacity?, 
   cacheSize?): VolLayer;

Defined in: src/display/VolLayer.ts:101

Constructs a new VolLayer.

Parameters

id

string

A unique identifier for the layer.

volume

NeuroVol

The 3D neuroimaging volume data. Can be any NeuroVol implementation (DenseNeuroVol, SparseNeuroVol, LogicalNeuroVol, ClusteredNeuroVol).

colorMap

ColorMap

Instance of a ColorMap used for intensity -> RGBA transformation.

range?

Range | null

[Optional] The initial intensity range [min, max]. If not provided, it is inferred from the volume data.

threshold?

Threshold = ...

[Optional] The threshold range [low, high]. Defaults to [0, 0].

opacity?

number = 1.0

[Optional] The global opacity of this layer (0 to 1). Defaults to 1.0.

cacheSize?

number

Returns

VolLayer

Properties

id

ts
id: string;

Defined in: src/display/VolLayer.ts:38

A unique identifier for the layer.


volume

ts
volume: NeuroVol;

Defined in: src/display/VolLayer.ts:43

The underlying volume data. Can be any NeuroVol implementation.


colorMap

ts
colorMap: ColorMap;

Defined in: src/display/VolLayer.ts:49

Color mapping configuration for this volume layer. Used to transform intensity values to RGBA values.


opacity

ts
opacity: number;

Defined in: src/display/VolLayer.ts:54

Global opacity for this layer (0 to 1).


visible

ts
visible: boolean;

Defined in: src/display/VolLayer.ts:59

Whether this layer is visible.


range

ts
range: Range;

Defined in: src/display/VolLayer.ts:66

The intensity range [min, max] used for visualization. Values outside this range may be clipped or mapped differently, depending on the color map.


threshold

ts
threshold: Threshold;

Defined in: src/display/VolLayer.ts:73

The intensity threshold [low, high] used for masking. Intensity values outside this threshold range may be set to transparent, depending on the color map.


version

ts
version: number = 0;

Defined in: src/display/VolLayer.ts:79

Version number that increments whenever colormap settings change. Used by ImageLayer to invalidate texture cache.

Accessors

space

Get Signature

ts
get space(): NeuroSpace;

Defined in: src/display/VolLayer.ts:135

Returns the NeuroSpace of the underlying volume, describing dimensions, spacing, and orientation.

Returns

NeuroSpace

Methods

getSlice()

ts
getSlice(sliceIndex, outAxes): ImageSlice;

Defined in: src/display/VolLayer.ts:147

Retrieves a 2D slice from the volume given a slice index (in voxel coordinates) and an orientation (outAxes). The result is cached to avoid recomputation.

Parameters

sliceIndex

number

The integer slice index in the volume (voxel coordinate).

outAxes

AxisSet3D

The desired orientation axes for the output slice.

Returns

ImageSlice

An ImageSlice containing the 2D image data plus spatial metadata.


getTransformationToReference()

ts
getTransformationToReference(referenceSpace): Matrix;

Defined in: src/display/VolLayer.ts:178

Retrieves a transformation matrix from this layer's space to a reference space.

Parameters

referenceSpace

NeuroSpace

The reference NeuroSpace to transform into.

Returns

Matrix

A 4x4 transformation Matrix.


getSliceAt()

ts
getSliceAt(
   coord, 
   outAxes, 
   interpolation?): ImageSlice;

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

Retrieves a 2D slice by real-world (or continuous) coordinates, rather than integer indices. Uses the specified interpolation mode. Caches the result for faster subsequent retrieval.

Parameters

coord

number[]

The [x, y, z] coordinate in the volume's space.

outAxes

AxisSet3D

The orientation for the output slice.

interpolation?

"nearest" | "trilinear"

The interpolation method: 'nearest' or 'trilinear'. Defaults to 'trilinear'.

Returns

ImageSlice

An ImageSlice with the processed 2D image data plus spatial metadata.


replaceVolume()

ts
replaceVolume(newVolume, opts?): void;

Defined in: src/display/VolLayer.ts:226

Replace the underlying volume while keeping the same layer id and color settings. Faster than removing/re-adding a layer because it preserves viewer references.

Parameters

newVolume

NeuroVol

A NeuroVol with matching geometry (dim, axes, spacing, origin).

opts?

Optional display overrides (range/threshold/opacity/colormap).

range?

Range | null

threshold?

Threshold

opacity?

number

colormap?

ColorMap

Returns

void


getOrthoSliceAt()

ts
getOrthoSliceAt(coord, interpolation?): object;

Defined in: src/display/VolLayer.ts:298

Retrieves three orthogonal slices (axial, sagittal, coronal) at a specific coordinate.

Parameters

coord

number[]

The [x, y, z] coordinate in the volume's space.

interpolation?

"nearest" | "trilinear"

Interpolation method: 'nearest' or 'trilinear'. Defaults to 'trilinear'.

Returns

object

An object containing axial, sagittal, and coronal slices.

axial
ts
axial: ImageSlice;
sagittal
ts
sagittal: ImageSlice;
coronal
ts
coronal: ImageSlice;

containsCoord()

ts
containsCoord(coord): boolean;

Defined in: src/display/VolLayer.ts:372

Checks if the provided coordinate is within the boundaries of this volume's space.

Parameters

coord

number[]

A [x, y, z] coordinate in real-world or continuous space.

Returns

boolean

True if the coordinate lies within the volume bounds, false otherwise.


setColormap()

ts
setColormap(colormap): void;

Defined in: src/display/VolLayer.ts:382

Replaces the current ColorMap with a new one and invalidates the slice cache.

Parameters

colormap

ColorMap

The new ColorMap to use.

Returns

void


getCacheStats()

ts
getCacheStats(): object;

Defined in: src/display/VolLayer.ts:404

Gets cache statistics for monitoring performance

Returns

object

size
ts
size: number;
capacity
ts
capacity: number;
hits
ts
hits: number;
misses
ts
misses: number;
evictions
ts
evictions: number;
hitRatio
ts
hitRatio: number;

getRange()

ts
getRange(): Range;

Defined in: src/display/VolLayer.ts:418

Retrieves the current intensity range used by this layer.

Returns

Range


getVolumeRange()

ts
getVolumeRange(): [number, number];

Defined in: src/display/VolLayer.ts:426

Retrieves the full intensity range of the underlying volume, as calculated by the volume data itself.

Returns

[number, number]


getThreshold()

ts
getThreshold(): Threshold;

Defined in: src/display/VolLayer.ts:433

Retrieves the current threshold range used by this layer.

Returns

Threshold


setThreshold()

ts
setThreshold(threshold): void;

Defined in: src/display/VolLayer.ts:443

Sets a new intensity threshold [low, high] and invalidates the cache.

Parameters

threshold

Threshold

The new threshold to apply.

Returns

void


setOpacity()

ts
setOpacity(opacity): void;

Defined in: src/display/VolLayer.ts:455

Sets a new opacity (0-1) for this layer and invalidates the cache.

Parameters

opacity

number

The new opacity value.

Returns

void


setRange()

ts
setRange(range): void;

Defined in: src/display/VolLayer.ts:467

Sets a new intensity range [min, max] for visualization and invalidates the cache.

Parameters

range

Range

The new intensity range.

Returns

void


setVisible()

ts
setVisible(visible): void;

Defined in: src/display/VolLayer.ts:479

Sets the visibility of this layer.

Parameters

visible

boolean

Whether the layer should be visible.

Returns

void

Released under the MIT License.