Skip to content

LabelLayer ​

A layer that renders a 2D slice of a single-channel label image.

Label layer displays segmentation data where each pixel holds an integer label. Labels are colored by cycling through the color map's cycle with exact-value overrides in its lookupTable. Chunks stream through the same policy machinery as ImageLayer and the source must be single channel.

Clicking the layer picks the label under the pointer. With outlineSelected the picked label is outlined, and onPickValue receives the world position and label value for custom handling such as highlighting through setColorMap.

ts
const labels = new LabelLayer({
  source: labelSource,
  sliceCoords: { z: 12, c: [0] },
  opacity: 0.55,
  blendMode: "normal",
  onPickValue: ({ value }) => console.log(`label ${value}`),
});

viewport.addLayer(labels);

Extends Layer and inherits all public properties and methods.

Constructor ​

Creates a label layer for the given source and slice.

ts
new LabelLayer(props): LabelLayer;
ParameterDescription
props: LabelLayerPropsInitialization properties.

Types ​

LabelLayerProps ​

Initialization properties for constructing a label layer.

PropertyDescription
source: ChunkSourceThe single-channel label source to stream from.
sliceCoords: SliceCoordinatesThe slice to display in world units.
policy?: ImageSourcePolicyStreaming policy. Defaults to the exploration policy.
orientation?: SliceOrientationSlice plane orientation. Defaults to "XY".
colorMap?: LabelColorMapPropsColors for label values. Defaults to a built-in cycle.
onPickValue?: (info) => voidCalled with the picked label when the layer is clicked.
outlineSelected?: booleanOutlines the picked label. Defaults to false.
opacity?: numberLayer opacity in [0, 1]. Defaults to 1.
blendMode?: BlendModeHow the layer blends. Defaults to "none".
occludes?: booleanHides content behind. Inferred from blendMode.

LabelColorMapProps ​

Color assignments for label values.

Values present in lookupTable use its color. Any other value takes a color from cycle by index. Value 0 renders transparent unless the lookup table assigns it a color.

PropertyDescription
lookupTable?: ReadonlyMap<number, ColorLike>Exact colors for specific label values.
cycle?: ReadonlyArray<ColorLike>Colors cycled by value. Defaults to 6 built-ins.

LabelColorMap ​

A validated color map with every entry resolved to a Color. Returned by LabelLayer.colorMap.

PropertyDescription
lookupTable: ReadonlyMap<number, Color>Exact colors for specific label values.
cycle: ReadonlyArray<Color>Colors cycled by value.

Properties ​

type overrides ​

Identifies the layer type as LabelLayer.

ts
readonly type: "LabelLayer" = "LabelLayer";

Accessors ​

orientation SliceOrientation ​

The slice plane the layer displays.

ts
get orientation(): SliceOrientation;

colorMap LabelColorMap ​

The validated color map currently in effect.

ts
get colorMap(): LabelColorMap;

sliceCoords SliceCoordinates ​

The slice coordinates the layer displays. This is the object passed at construction and may be mutated to move through the data.

ts
get sliceCoords(): SliceCoordinates;

source ChunkSource ​

The chunked label source the layer streams from.

ts
get source(): ChunkSource;

imageSourcePolicy Readonly<ImageSourcePolicy> ​

The streaming policy in effect. Assign a new policy to reschedule loading at runtime, for example when switching between exploration and playback.

ts
get imageSourcePolicy(): Readonly<ImageSourcePolicy>;
ts
set imageSourcePolicy(newPolicy): void;
ParameterDescription
newPolicy: ImageSourcePolicyThe policy to apply.

lastPresentationTimeCoord number | undefined ​

The t coordinate of the most recently presented slice.

ts
get lastPresentationTimeCoord(): number | undefined;

Methods ​

update() void overrides ​

Streams chunks for the current view and refreshes the visible slice. Called automatically once per frame.

ts
update(viewport?): void;
ParameterDescription
viewport?: ViewportThe viewport being rendered.

setOrientation() void ​

Changes the slice orientation at runtime. Visible renderables are rebuilt for the new plane and chunks already resident in the shared cache are reused.

ts
setOrientation(orientation): void;
ParameterDescription
orientation: SliceOrientationThe new slice plane.

onEvent() void overrides ​

Handles click picking and selection outlining. Called automatically for each pointer event on the owning viewport.

ts
onEvent(event): void;
ParameterDescription
event: EventContextThe event with clip and world coordinates attached.

setColorMap() void ​

Replaces the color map and recolors all visible chunks.

ts
setColorMap(colorMap): void;
ParameterDescription
colorMap: LabelColorMapPropsColors for label values. Omitted fields fall back to defaults.

setSelectedValue() void ​

Sets the label value drawn as selected or null to clear the selection.

ts
setSelectedValue(value): void;
ParameterDescription
value: number | nullThe label value to select.

getValueAtWorld() Promise<number | null> ​

Reads the label value at a world position from the resident chunks. Prefers the current level of detail and falls back to other resident levels.

ts
getValueAtWorld(world): Promise<number | null>;
ParameterDescription
world: vec3The world-space position to sample.

Released under the MIT License