DWVv0.37.0

ViewLayer

Source: viewLayer.js:26

View layer.

Not an EventTarget in order to forward native DOM events while preserving preventDefault() for tools (see '#fireDomEvent').


Constructor

new ViewLayer( containerDiv: HTMLElement, canvasSizeChecker?: CanvasSizeChecker, ): ViewLayer

Parameters

  • containerDiv (HTMLElement) — The layer div, its id will be used as this layer id.
  • canvasSizeChecker (CanvasSizeChecker, optional) — Optional canvas size checker, to share with other layers; defaults to a new one.

Instance Methods

getDataId(): string

Get the associated data id.

Returns

  • string — The data id.

getScale(): Scalar2D

Get the layer scale.

Returns

getAbsoluteZoomOffset(): Scalar2D

Get the layer zoom offset without the fit scale.

Returns

setImageSmoothing(flag: boolean)

Set the imageSmoothing flag value.

Parameters

  • flag (boolean) — True to enable smoothing.

setView(view: object, dataId: string)

Set the associated view.

Parameters

  • view (object) — The view.
  • dataId (string) — The associated data id.

getViewController(): ViewController

Get the view controller.

Returns

getImageData(): object

Get the canvas image data.

Returns

  • object — The image data.

onimageset(event: CustomEvent)

Handle an image set event.

Parameters

  • event (CustomEvent) — The event.

bindImage()

Bind this layer to the view image.

unbindImage()

Unbind this layer to the view image.

onimagecontentchange(event: CustomEvent)

Handle an image content change event.

Parameters

  • event (CustomEvent) — The event.

onimagegeometrychange(event: CustomEvent)

Handle an image change event.

Parameters

  • event (CustomEvent) — The event.

onimageresampled(event: CustomEvent)

Handle an image resampled event.

Parameters

  • event (CustomEvent) — The event.

getId(): string

Get the id of the layer.

Returns

  • string — The string id.

removeFromDOM()

Remove the HTML element from the DOM.

getBaseSize(): Scalar2D

Get the layer base size (without scale).

Returns

getImageWorldSize(): Scalar2D

Get the image world (mm) 2D size.

Returns

getOpacity(): number

Get the layer opacity.

Returns

  • number — The opacity ([0:1] range).

setOpacity(alpha: number)

Set the layer opacity.

Parameters

  • alpha (number) — The opacity ([0:1] range).

highlightSegment( segmentNumber: number, duration?: number, ): boolean

Temporarily highlight a segment: its opacity progressively dims and comes back to normal in one pulse. Only one segment is highlighted at a time: a new call resets the previous highlight.

Parameters

  • segmentNumber (number) — The segment number.
  • duration (number, optional) — The highlight duration in milliseconds, defaults to 750.

Returns

  • boolean — False if the layer is not a segmentation one.

getFillOpacity(): number

Get the fill opacity relative to the global opacity.

Returns

  • number — The fill opacity (between 0 and 1).

setFillOpacity(opacity: number)

Set the fill opacity relative to the global opacity. This only has an effect on segmentation views, or any other alpha function that makes use of it.

Parameters

  • opacity (number) — The fill opacity (between 0 and 1).

getContourThickness(): number

Get the thickness of the contour in pixels.

Returns

  • number — The contour thickness (integer >= 1).

setContourThickness(thickness: number)

Set the thickness of the contour in pixels. This only has an effect on segmentation views, or any other alpha function that makes use of it.

Parameters

  • thickness (number) — The contour thickness (integer >= 1).

addFlipOffsetX()

Add a flip offset along the layer X axis.

addFlipOffsetY()

Add a flip offset along the layer Y axis.

flipScaleX()

Flip the scale along the layer X axis.

flipScaleY()

Flip the scale along the layer Y axis.

flipScaleZ()

Flip the scale along the layer Z axis.

setScale(newScale: Scalar3D, center?: Point3D)

Set the layer scale.

Parameters

  • newScale (Scalar3D) — The scale as {x,y,z}.
  • center (Point3D, optional) — The scale center.

initScale(newScale: Scalar3D, absoluteZoomOffset: Scalar2D)

Initialise the layer scale.

Parameters

  • newScale (Scalar3D) — The scale as {x,y,z}.
  • absoluteZoomOffset (Scalar2D) — The zoom offset as {x,y} without the fit scale (as provided by getAbsoluteZoomOffset).

setBaseOffset( scrollOffset: Vector3D, planeOffset: Vector3D, layerGroupOrigin?: Point3D, layerGroupOrigin0?: Point3D, ): boolean

Set the base layer offset. Updates the layer offset.

Parameters

  • scrollOffset (Vector3D) — The scroll offset vector.
  • planeOffset (Vector3D) — The plane offset vector.
  • layerGroupOrigin (Point3D, optional) — The layer group origin.
  • layerGroupOrigin0 (Point3D, optional) — The layer group first origin.

Returns

  • boolean — True if the offset was updated.

setOffset(newOffset: Scalar3D)

Set the layer offset.

Parameters

  • newOffset (Scalar3D) — The offset as {x,y,z}.

displayToPlaneIndex(point2D: Point2D): Index

Transform a display position to a 2D index.

Parameters

  • point2D (Point2D) — The input point.

Returns

  • Index — The equivalent 2D index.

displayToPlaneScale(point2D: Point2D): Point2D

Remove scale from a display position.

Parameters

  • point2D (Point2D) — The input point.

Returns

displayToPlanePos(point2D: Point2D): Point2D

Get a plane position from a display position.

Parameters

  • point2D (Point2D) — The input point.

Returns

planePosToDisplay(point2D: Point2D): Point2D

Get a display position from a plane position.

Parameters

  • point2D (Point2D) — The input point.

Returns

  • Point2D — The display position, can be individually undefined if out of bounds.

displayToMainPlanePos(point2D: Point2D): Point2D

Get a main plane position from a display position.

Parameters

  • point2D (Point2D) — The input point.

Returns

  • Point2D — The main plane position.

display(flag: boolean)

Display the layer.

Parameters

  • flag (boolean) — Whether to display the layer or not.

isVisible(): boolean

Check if the layer is visible.

Returns

  • boolean — True if the layer is visible.

draw()

Draw the content (imageData) of the layer. The imageData variable needs to be set.

Fires

  • App#event:renderstart
  • App#event:renderend

initialise(size: Scalar2D, spacing: Scalar2D, alpha: number)

Initialise the layer: set the canvas and context.

Parameters

  • size (Scalar2D) — The image size as {x,y}.
  • spacing (Scalar2D) — The image spacing as {x,y}.
  • alpha (number) — The initial data opacity.

fitToContainer( containerSize: Scalar2D, divToWorldSizeRatio: number, fitOffset: Scalar2D, )

Fit the layer to its parent container.

Parameters

  • containerSize (Scalar2D) — The fit size as {x,y}.
  • divToWorldSizeRatio (number) — The div to world size ratio.
  • fitOffset (Scalar2D) — The fit offset as {x,y}.

bindInteraction()

Enable and listen to container interaction events.

unbindInteraction()

Disable and stop listening to container interaction events.

addEventListener(type: string, callback: function)

Add an event listener to this class.

Parameters

  • type (string) — The event type.
  • callback (function) — The function associated with the provided event type, will be called with the fired event.

removeEventListener(type: string, callback: function)

Remove an event listener from this class.

Parameters

  • type (string) — The event type.
  • callback (function) — The function associated with the provided event type.

isValidPosition(): boolean

Check if the position is valid.

Returns

  • boolean — True if the position is valid.

setCurrentPosition(position: Point, _index?: Index): boolean

Set the current position.

Parameters

  • position (Point) — The new position.
  • _index (Index, optional) — The new index (not used).

Returns

  • boolean — True if the position was updated.

clear()

Clear the context.

Events

basesizechange: CustomEvent

Base size change event: the layer world size changed, the stage needs to be fitted to its container again.

Properties

  • detail (object) — The event detail.
    • detail.srclayerid (string) — The source layer id.
    • detail.dataid (string) — The data id.
    • detail.value (Array) — The new base size as [x, y].