Skip to content

Layer ​

Abstract base class for any layer that can be added to a viewport.

A layer owns a set of renderable objects and contributes them to the scene each frame. Subclasses such as ImageLayer, VolumeLayer, and LabelLayer implement update to build or refresh those objects for the current view. Custom layers register objects with addObject and report readiness through setState.

Layers carry shared presentation state in opacity, blendMode, and occludes, and expose a lifecycle LayerState that observers can subscribe to. A layer instance may be attached to only one viewport at a time.

ts
class Particles extends Layer {
  public readonly type = "Particles";

  constructor(points: PointProps[]) {
    super();
    this.addObject(new PointsRenderable(points));
    this.setState("ready");
  }

  public update() {}
}

viewport.addLayer(new Particles(points));

Extended by ​

Constructor ​

Creates a layer with the given presentation state.

ts
new Layer(props?): Layer;
ParameterDescription
props: LayerPropsInitialization properties. Defaults to {}.

Types ​

ChannelProps ​

Appearance settings for a single image channel.

PropertyDescription
visible?: booleanWhether the channel is drawn. Defaults to true.
color?: ColorLikeThe channel's tint color. Defaults to white.
contrastLimits?: [number, number]Intensity range shown. Defaults to the data range.
opacity?: numberChannel opacity in [0, 1]. Defaults to 1.

LayerState ​

The loading lifecycle state of a layer.

ts
type LayerState = "initialized" | "loading" | "ready";

BlendMode ​

How a layer's output blends with previously drawn content.

ts
type BlendMode = 
  | "none"
  | "normal"
  | "additive"
  | "subtractive"
  | "multiply"
  | "premultipliedOver";

StateChangeCallback ​

A callback invoked after a layer's state changes.

ts
type StateChangeCallback = (newState, prevState?) => void;

LayerProps ​

Initialization properties for constructing a layer.

PropertyDescription
opacity?: numberLayer opacity in [0, 1]. Defaults to 1.
blendMode?: BlendModeHow the layer blends. Defaults to "none".
occludes?: booleanHides content behind. Inferred from blendMode.

SliceCoordinates ​

World-space coordinates selecting the data to display.

PropertyDescription
x?: numberPosition on the x axis in world units.
y?: numberPosition on the y axis in world units.
z?: numberPosition on the z axis in world units.
c?: number[]Channel indices to load. Defaults to all channels.
t?: numberThe time point to display.

PointPickingResult ​

The result of picking a value from a layer with a click.

PropertyDescription
world: vec3The picked position in world units.
value: numberThe data value sampled at the position.

SliceOrientation ​

The plane a 2D slice lies on, named by its in-plane axes.

ts
type SliceOrientation = "XY" | "XZ" | "YZ";

Properties ​

type ​

A string identifying the concrete layer type.

ts
abstract readonly type: string;

blendMode ​

How the layer's output blends with previously drawn content. Also applies to blending between objects within the layer.

ts
blendMode: BlendMode;

occludes ​

Whether the layer writes depth and hides content drawn behind it.

Occluding layers render a depth pass and always draw before non-occluding layers regardless of their order in the viewport. When not set explicitly this value is inferred from blendMode at construction only. Reassigning blendMode later does not update it.

ts
occludes: boolean;

requiresSceneDepth_ ​

Set to true by subclasses whose shaders read scene depth.

ts
protected requiresSceneDepth_: boolean = false;

Accessors ​

requiresSceneDepth boolean ​

Whether the layer's shaders read scene depth. When true the renderer draws occluding layers to a depth texture the layer's shaders can sample. A layer cannot both occlude and read scene depth.

ts
get requiresSceneDepth(): boolean;

opacity number ​

The layer's opacity in [0, 1]. Values outside are clamped.

ts
get opacity(): number;
ts
set opacity(value): void;
ParameterDescription
value: numberThe new opacity in [0, 1].

coverageGroups ReadonlyMap<number | null, readonly RenderableObject[]> ​

The layer's renderable objects grouped by coverage group. Objects in a group draw each pixel at most once, letting chunks at multiple levels of detail overlap correctly.

ts
get coverageGroups(): ReadonlyMap<number | null, readonly RenderableObject[]>;

state LayerState ​

The layer's current lifecycle state.

ts
get state(): LayerState;

Methods ​

update() void ​

Builds or refreshes the layer's renderable objects for the current view. Called automatically once per frame for every layer in a viewport.

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

onEvent() void ​

Handles a pointer or wheel event from the owning viewport. Called automatically for each event before the camera controls. The default implementation does nothing.

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

onAttached() void ​

Lifecycle hook that is called automatically when a layer is is attached to a viewport. A layer can only be attached to one viewport at a time.

ts
onAttached(context): void;
ParameterDescription
context: IdetikContextThe shared runtime context.

onDetached() void ​

Lifecycle hook that is called automatically when a layer is detached from a viewport.

ts
onDetached(context): void;
ParameterDescription
context: IdetikContextThe shared runtime context.

addStateChangeCallback() void ​

Registers a callback invoked after every state change.

ts
addStateChangeCallback(callback): void;
ParameterDescription
callback: StateChangeCallbackReceives the new and previous states.

removeStateChangeCallback() void ​

Removes a previously registered state change callback.

ts
removeStateChangeCallback(callback): void;
ParameterDescription
callback: StateChangeCallbackThe callback to remove.

setState() void ​

Sets the lifecycle state and notifies state change callbacks.

ts
protected setState(newState): void;
ParameterDescription
newState: LayerStateThe state to enter.

addObject() void ​

Registers a renderable object for drawing. Objects in the same coverage group draw each pixel at most once.

ts
protected addObject(object, coverageGroup?): void;
ParameterDescription
object: RenderableObjectThe object to add.
coverageGroup: number | nullThe group key. Defaults to null.

clearObjects() void ​

Removes all registered renderable objects.

ts
protected clearObjects(): void;

getUniforms() Record<string, unknown> ​

Returns uniform name-value pairs applied to every object drawn by this layer. Override in subclasses that need custom shader uniforms.

ts
getUniforms(): Record<string, unknown>;

Released under the MIT License