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.
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.
new LabelLayer(props): LabelLayer;| Parameter | Description |
|---|---|
props: LabelLayerProps | Initialization properties. |
Types
LabelLayerProps
Initialization properties for constructing a label layer.
| Property | Description |
|---|---|
source: ChunkSource | The single-channel label source to stream from. |
sliceCoords: SliceCoordinates | The slice to display in world units. |
policy?: ImageSourcePolicy | Streaming policy. Defaults to the exploration policy. |
orientation?: SliceOrientation | Slice plane orientation. Defaults to "XY". |
colorMap?: LabelColorMapProps | Colors for label values. Defaults to a built-in cycle. |
onPickValue?: (info) => void | Called with the picked label when the layer is clicked. |
outlineSelected?: boolean | Outlines the picked label. Defaults to false. |
opacity?: number | Layer opacity in [0, 1]. Defaults to 1. |
blendMode?: BlendMode | How the layer blends. Defaults to "none". |
occludes?: boolean | Hides 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.
| Property | Description |
|---|---|
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.
| Property | Description |
|---|---|
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.
readonly type: "LabelLayer" = "LabelLayer";Accessors
orientation SliceOrientation
The slice plane the layer displays.
get orientation(): SliceOrientation;colorMap LabelColorMap
The validated color map currently in effect.
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.
get sliceCoords(): SliceCoordinates;source ChunkSource
The chunked label source the layer streams from.
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.
get imageSourcePolicy(): Readonly<ImageSourcePolicy>;set imageSourcePolicy(newPolicy): void;| Parameter | Description |
|---|---|
newPolicy: ImageSourcePolicy | The policy to apply. |
lastPresentationTimeCoord number | undefined
The t coordinate of the most recently presented slice.
get lastPresentationTimeCoord(): number | undefined;Methods
update() void overrides
Streams chunks for the current view and refreshes the visible slice. Called automatically once per frame.
update(viewport?): void;| Parameter | Description |
|---|---|
viewport?: Viewport | The 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.
setOrientation(orientation): void;| Parameter | Description |
|---|---|
orientation: SliceOrientation | The new slice plane. |
onEvent() void overrides
Handles click picking and selection outlining. Called automatically for each pointer event on the owning viewport.
onEvent(event): void;| Parameter | Description |
|---|---|
event: EventContext | The event with clip and world coordinates attached. |
setColorMap() void
Replaces the color map and recolors all visible chunks.
setColorMap(colorMap): void;| Parameter | Description |
|---|---|
colorMap: LabelColorMapProps | Colors for label values. Omitted fields fall back to defaults. |
setSelectedValue() void
Sets the label value drawn as selected or null to clear the selection.
setSelectedValue(value): void;| Parameter | Description |
|---|---|
value: number | null | The 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.
getValueAtWorld(world): Promise<number | null>;| Parameter | Description |
|---|---|
world: vec3 | The world-space position to sample. |