Skip to main content

StackViewport

An object representing a single stack viewport, which is a camera looking into an internal viewport, and an associated target output canvas.

StackViewports can be rendered using both GPU and a fallback CPU is the GPU is not available (or low performance). Read more about StackViewports in the documentation section of this website.

Hierarchy

Implements

Index

Constructors

constructor

  • Constructor for the StackViewport class


    Parameters

    • props: ViewportInput

      ViewportInput

    Returns StackViewport

Properties

_actors

_actors: Map<string, any>

a Map containing the actor uid and actors

readonlycanvas

canvas: HTMLCanvasElement

an internal canvas that is created on the provided HTML element

readonlydefaultOptions

defaultOptions: any

Default options for the viewport which includes orientation, viewPlaneNormal and backgroundColor

readonlyelement

element: HTMLDivElement

HTML element in DOM that is used for rendering the viewport

readonlyid

id: string

unique identifier for the viewport

publicisDisabled

isDisabled: boolean

if the viewport has been disabled

publicmodality

modality: string

options

options for the viewport which includes orientation axis and backgroundColor

readonlyrenderingEngineId

renderingEngineId: string

RenderingEngine id that the viewport belongs to

sHeight

sHeight: number

sHeight of viewport on the offscreen canvas

sWidth

sWidth: number

sWidth of viewport on the offscreen canvas

publicscaling

scaling: Scaling

Scaling parameters

readonlysuppressEvents

suppressEvents: boolean

A flag representing if viewport methods should fire events or not

sx

sx: number

sx of viewport on the offscreen canvas

sy

sy: number

sy of viewport on the offscreen canvas

readonlytype

Type of viewport

Accessors

staticuseCustomRenderingPipeline

  • get useCustomRenderingPipeline(): boolean
  • Returns boolean

Methods

_getCorners

  • _getCorners(bounds: number[]): number[][]
  • Parameters

    • bounds: number[]

    Returns number[][]

_getEdges

  • _getEdges(bounds: number[]): [number[], number[]][]
  • Returns a list of edges for the imageData bounds, which are the cube edges in the case of volumeViewport edges. p1: front, bottom, left p2: front, top, left p3: back, bottom, left p4: back, top, left p5: front, bottom, right p6: front, top, right p7: back, bottom, right p8: back, top, right


    Parameters

    • bounds: number[]

      Bounds of the renderer

    Returns [number[], number[]][]

    Edges of the containing bounds

_getFocalPointForResetCamera

  • _getFocalPointForResetCamera(centeredFocalPoint: Point3, previousCamera: ICamera, __namedParameters: Object): Point3
  • Parameters

    • centeredFocalPoint: Point3
    • previousCamera: ICamera
    • __namedParameters: Object

    Returns Point3

_isInBounds

  • _isInBounds(point: Point3, bounds: number[]): boolean
  • Determines whether or not the 3D point position is inside the boundaries of the 3D imageData.


    Parameters

    • point: Point3

      3D coordinate

    • bounds: number[]

      Bounds of the image

    Returns boolean

    boolean

_removeActor

  • _removeActor(actorUID: string): void
  • Remove the actor from the viewport


    Parameters

    • actorUID: string

      The unique identifier for the actor.

    Returns void

publicaddActor

  • If the renderer is CPU based, throw an error. Otherwise, add the actor to the viewport


    Parameters

    • actorEntry: ActorEntry

      The ActorEntry object that was created by the user.

    Returns void

publicaddActors

  • If the renderer is CPU based, throw an error. Otherwise, add a list of actors to the viewport


    Parameters

    • actors: ActorEntry[]

      An array of ActorEntry objects.

    Returns void

publiccalibrateSpacing

  • calibrateSpacing(imageId: string): void
  • Calibrates the image with new metadata that has been added for imageId. To calibrate a viewport, you should add your calibration data manually to calibratedPixelSpacingMetadataProvider and call viewport.calibrateSpacing for it get applied.


    Parameters

    • imageId: string

      imageId to be calibrated

    Returns void

publiccanvasToWorld

  • canvasToWorld Returns the world coordinates of the given canvasPos projected onto the plane defined by the Viewport‘s camera.


    Parameters

    • canvasPos: Point2

      The position in canvas coordinates.

    Returns Point3

    The corresponding world coordinates.

publiccustomRenderViewportToCanvas

  • customRenderViewportToCanvas(): { canvas: HTMLCanvasElement; element: HTMLDivElement; renderingEngineId: string; viewportId: string }
  • Custom rendering pipeline for the rendering for the CPU fallback


    Returns { canvas: HTMLCanvasElement; element: HTMLDivElement; renderingEngineId: string; viewportId: string }

    • canvas: HTMLCanvasElement
    • element: HTMLDivElement
    • renderingEngineId: string
    • viewportId: string

publicgetActor

  • If the renderer is CPU based, throw an error. Otherwise, it returns the actor entry for the given actor UID.


    Parameters

    • actorUID: string

      The unique ID of the actor you want to get.

    Returns ActorEntry

    An ActorEntry object.

publicgetActorByIndex

  • Get an actor by its index


    Parameters

    • index: number

      array index.

    Returns ActorEntry

    actorUID

publicgetActorUIDByIndex

  • getActorUIDByIndex(index: number): string
  • Get an actor UID by its index


    Parameters

    • index: number

      array index.

    Returns string

    actorUID

publicgetActors

  • If the renderer is CPU based, throw an error. Otherwise, return the actors in the viewport


    Returns ActorEntry[]

    An array of ActorEntry objects.

publicgetCamera

  • If the user has selected CPU rendering, return the CPU camera, otherwise return the default camera


    Returns ICamera

    The camera object.

publicgetCanvas

  • getCanvas(): HTMLCanvasElement
  • Gets the target output canvas for the Viewport.


    Returns HTMLCanvasElement

    an HTMLCanvasElement.

publicgetCurrentImageId

  • getCurrentImageId(): string
  • Returns the currently rendered imageId


    Returns string

    string for imageId

publicgetCurrentImageIdIndex

  • getCurrentImageIdIndex(): number
  • Returns the index of the imageId being renderer


    Returns number

    currently shown imageId index

publicgetDefaultActor

  • If the renderer is CPU based, throw an error. Otherwise, return the default actor which is the first actor in the renderer.


    Returns ActorEntry

    An actor entry.

publicgetFrameOfReferenceUID

  • getFrameOfReferenceUID(): string
  • Returns the frame of reference UID, if the image doesn’t have imagePlaneModule metadata, it returns undefined, otherwise, frameOfReferenceUID is returned.


    Returns string

    frameOfReferenceUID : string representing frame of reference id

publicgetImageData

  • Returns the image and its properties that is being shown inside the stack viewport. It returns, the image dimensions, image direction, image scalar data, vtkImageData object, metadata, and scaling (e.g., PET suvbw)


    Returns IImageData | CPUIImageData

    IImageData: dimensions, direction, scalarData, vtkImageData, metadata, scaling

publicgetImageIds

  • getImageIds(): string[]
  • Returns the list of image Ids for the current viewport


    Returns string[]

    list of strings for image Ids

publicgetPan

  • Helper function to return the current canvas pan value.


    Returns Point2

    a Point2 containing the current pan values on the canvas, computed from the current camera, where the initial pan value is [0,0].

publicgetProperties

  • Retrieve the viewport properties


    Returns StackViewportProperties

    viewport properties including voi, invert, interpolation type, rotation, flip

publicgetRenderer

  • getRenderer(): any
  • If the renderer is CPU based, throw an error. Otherwise, returns the vtkRenderer responsible for rendering the Viewport.


    Returns any

    The vtkRenderer for the Viewport.

publicgetRenderingEngine

  • Returns the rendering engine driving the Viewport.


    Returns default

    The RenderingEngine instance.

publicgetTargetImageIdIndex

  • getTargetImageIdIndex(): number
  • Returns the imageIdIndex that is targeted to be loaded, in case of debounced loading (with scroll), the targetImageIdIndex is the latest imageId index that is requested to be loaded but debounced.


    Returns number

publicgetZoom

  • getZoom(): number
  • Returns a current zoom level relative to the initial parallel scale originally applied to the image. That is, on initial display, the zoom level is 1. Computed as a function of the camera.


    Returns number

publichasImageId

  • hasImageId(imageId: string): boolean
  • Returns true if the viewport contains the given imageId


    Parameters

    • imageId: string

      imageId

    Returns boolean

    boolean if imageId is in viewport

publichasImageURI

  • hasImageURI(imageURI: string): boolean
  • Returns true if the viewport contains the given imageURI (no data loader scheme)


    Parameters

    • imageURI: string

      imageURI

    Returns boolean

    boolean if imageURI is in viewport

publicremoveActors

  • removeActors(actorUIDs: string[]): void
  • Remove the actors with the given UIDs from the viewport


    Parameters

    • actorUIDs: string[]

      An array of actor UIDs to remove.

    Returns void

publicremoveAllActors

  • removeAllActors(): void
  • It throws an error if the renderer is CPU based. Otherwise, it removes the actors from the viewport.


    Returns void

publicrender

  • render(): void
  • Renders the Viewport using the RenderingEngine.


    Returns void

publicreset

  • reset(immediate?: boolean): void
  • Resets the options the Viewport‘s defaultOptions


    Parameters

    • immediate: boolean = false

      If true, renders the viewport after the options are reset.

    Returns void

publicresetCamera

  • resetCamera(resetPan?: boolean, resetZoom?: boolean): boolean
  • Centers Pan and resets the zoom for stack viewport.


    Parameters

    • resetPan: boolean = true
    • resetZoom: boolean = true

    Returns boolean

publicresetProperties

  • resetProperties(): void
  • Reset the viewport properties to the default values


    Returns void

publicresize

  • resize(): void
  • Resizes the viewport - only used in CPU fallback for StackViewport. The GPU resizing happens inside the RenderingEngine.


    Returns void

publicscroll

  • scroll(delta: number, debounce?: boolean, loop?: boolean): void
  • It scrolls the stack of imageIds by the delta amount provided. If the debounce flag is set, it will only scroll the stack if the delta is greater than the debounceThreshold which is 40 milliseconds by default.


    Parameters

    • delta: number

      number of indices to scroll, it can be positive or negative

    • debounce: boolean = true

      whether to debounce the scroll event

    • loop: boolean = false

      whether to loop the stack

    Returns void

publicsetActors

  • If the renderer is CPU-based, throw an error; otherwise, set the actors in the viewport.


    Parameters

    • actors: ActorEntry[]

      An array of ActorEntry objects.

    Returns void

publicsetCamera

  • setCamera(cameraInterface: ICamera, storeAsInitialCamera?: boolean): void
  • Set the camera based on the provided camera object.


    Parameters

    • cameraInterface: ICamera

      The camera interface that will be used to render the scene.

    • storeAsInitialCamera: boolean = false

    Returns void

publicsetColormap

  • Sets the colormap for the current viewport.


    Parameters

    Returns void

publicsetImageIdIndex

  • setImageIdIndex(imageIdIndex: number): Promise<string>
  • Loads the image based on the provided imageIdIndex. It is an Async function which returns a promise that resolves to the imageId.


    Parameters

    • imageIdIndex: number

      number represents imageId index in the list of provided imageIds in setStack

    Returns Promise<string>

publicsetOptions

  • Sets new options and (TODO) applies them.


    Parameters

    • options: ViewportInputOptions

      The viewport options to set.

    • immediate: boolean = false

      If true, renders the viewport after the options are set.

    Returns void

publicsetOrientationOfClippingPlanes

  • setOrientationOfClippingPlanes(vtkPlanes: vtkPlane[], slabThickness: number, viewPlaneNormal: Point3, focalPoint: Point3): void
  • Parameters

    • vtkPlanes: vtkPlane[]
    • slabThickness: number
    • viewPlaneNormal: Point3
    • focalPoint: Point3

    Returns void

publicsetPan

  • setPan(pan: Point2, storeAsInitialCamera?: boolean): void
  • Sets the canvas pan value relative to the initial view position of 0,0 Modifies the camera to perform the pan.


    Parameters

    • pan: Point2
    • storeAsInitialCamera: boolean = false

    Returns void

publicsetProperties

  • Sets the properties for the viewport on the default actor. Properties include setting the VOI, inverting the colors and setting the interpolation type, rotation


    Parameters

    Returns void

publicsetStack

  • setStack(imageIds: string[], currentImageIdIndex?: number): Promise<string>
  • Sets the imageIds to be visualized inside the stack viewport. It accepts list of imageIds, the index of the first imageId to be viewed. It is a asynchronous function that returns a promise resolving to imageId being displayed in the stack viewport.


    Parameters

    • imageIds: string[]

      list of strings, that represents list of image Ids

    • currentImageIdIndex: number = 0

      number representing the index of the initial image to be displayed

    Returns Promise<string>

publicsetZoom

  • setZoom(value: number, storeAsInitialCamera?: boolean): void
  • Zooms the image using parallel scale by updating the camera value.


    Parameters

    • value: number

      The relative parallel scale to apply. It is relative to the initial offsets value.

    • storeAsInitialCamera: boolean = false

      can be set to true to reset the camera after applying this zoom as the initial camera. A subsequent getZoom call will return “1”, but the zoom will have been applied.

    Returns void

publictriggerCameraModifiedEventIfNecessary

  • triggerCameraModifiedEventIfNecessary(previousCamera: ICamera, updatedCamera: ICamera): void
  • Trigger camera modified event


    Parameters

    Returns void

publicunsetColormap

  • unsetColormap(): void
  • It sets the colormap to the default colormap.


    Returns void

publicworldToCanvas

  • Returns the canvas coordinates of the given worldPos projected onto the Viewport‘s canvas.


    Parameters

    • worldPos: Point3

      The position in world coordinates.

    Returns Point2

    The corresponding canvas coordinates.