Skip to main content

Viewport

An object representing a single viewport, which is a camera looking into a viewport, and an associated target output HTMLDivElement. Viewport is a base class that can be extended to create a specific viewport type. Both VolumeViewport and StackViewport are subclasses of Viewport. Common logic for all viewports is contained in Viewport class which is camera properties/methods, vtk.js actors, and other common logic.

Hierarchy

Implements

Index

Constructors

constructor

  • new Viewport(props: ViewportInput): Viewport
  • Parameters

    • props: ViewportInput

    Returns Viewport

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

canvasToWorld

canvasToWorld: (canvasPos: Point2) => Point3

Type declaration

customRenderViewportToCanvas

customRenderViewportToCanvas: () => unknown

Type declaration

    • (): unknown
    • Returns unknown

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

getFrameOfReferenceUID

getFrameOfReferenceUID: () => string

Type declaration

    • (): string
    • Returns string

getNumberOfSlices

getNumberOfSlices: () => number

Type declaration

    • (): number
    • Returns number

getProperties

getProperties: () => void

Type declaration

    • (): void
    • Returns void

getRotation

getRotation: () => number

Type declaration

    • (): number
    • Returns number

readonlyid

id: string

unique identifier for the viewport

publicisDisabled

isDisabled: boolean

if the viewport has been disabled

options

options for the viewport which includes orientation axis, backgroundColor and displayArea

readonlyrenderingEngineId

renderingEngineId: string

RenderingEngine id that the viewport belongs to

resize

resize: () => void

Type declaration

    • (): void
    • Returns void

sHeight

sHeight: number

sHeight of viewport on the offscreen canvas

sWidth

sWidth: number

sWidth of viewport on the offscreen canvas

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

updateRenderingPipeline

updateRenderingPipeline: () => void

Type declaration

    • (): void
    • Returns void

publicviewportStatus

viewportStatus: ViewportStatus = ViewportStatus.NO_DATA

Record the rendering status, mostly for testing purposes, but can also be useful for knowing things like whether the viewport is initialized

worldToCanvas

worldToCanvas: (worldPos: Point3) => Point2

Type declaration

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

  • Add an actor to the viewport including its id, its actor and slabThickness if defined


    Parameters

    Returns void

publicaddActors

  • addActors(actors: ActorEntry[], resetCameraPanAndZoom?: boolean): void
  • Add a list of actors (actor entries) to the viewport


    Parameters

    • actors: ActorEntry[]

      An array of ActorEntry objects.

    • resetCameraPanAndZoom: boolean = false

      force reset pan and zoom of the camera, default value is false.

    Returns void

publicgetActor

  • Get an actor by its UID


    Parameters

    • actorUID: string

      The unique ID of the actor.

    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

publicgetActorUIDs

  • getActorUIDs(): string[]
  • Returns an array of unique identifiers for all the actors in the viewport.


    Returns string[]

    An array of strings

publicgetActors

  • Get all the actors in the viewport


    Returns ActorEntry[]

    An array of ActorEntry objects.

publicgetCamera

  • Get the camera’s current state


    Returns ICamera

    The camera object.

publicgetCanvas

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


    Returns HTMLCanvasElement

    an HTMLCanvasElement.

publicgetClippingPlanesForActor

  • getClippingPlanesForActor(actorEntry?: ActorEntry): vtkPlane[]
  • Method to get the clipping planes of a given actor


    Parameters

    • optionalactorEntry: ActorEntry

      The actor entry (a specific type you’ll define dependent on your code)

    Returns vtkPlane[]

    vtkPlanes - An array of vtkPlane objects associated with the given actor

publicgetCurrentImageIdIndex

  • getCurrentImageIdIndex(): number
  • Gets the current slice in the current camera orientation


    Returns number

publicgetDefaultActor

  • Get the default actor


    Returns ActorEntry

    An actor entry.

publicgetDisplayArea

  • returns the displayArea


    Returns DisplayArea

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].

publicgetReferenceId

  • Gets a referenced image url of some sort - could be a real image id, or could be a URL with parameters


    Parameters

    Returns string

publicgetRenderer

  • getRenderer(): any
  • 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.

publicgetViewReference

  • Gets a view target, allowing comparison between view positions as well as restoring views later.


    Parameters

    Returns ViewReference

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

publicisReferenceViewable

  • Find out if this viewport does or could show this view reference.


    Parameters

    Returns boolean

    true if the viewport could show this view reference

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
  • Remove all actors from the renderer


    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, resetToCenter?: boolean, storeAsInitialCamera?: boolean): boolean
  • Resets the camera based on the rendering volume(s) bounds. If resetPan and resetZoom are true it places the focal point at the center of the volume (or slice); otherwise, only the camera zoom and camera Pan or Zoom is reset for the current view.


    Parameters

    • resetPan: boolean = true

      If true, the camera focal point is reset to the center of the volume (slice)

    • resetZoom: boolean = true

      If true, the camera zoom is reset to the default zoom

    • resetToCenter: boolean = true
    • storeAsInitialCamera: boolean = true

      If true, reset camera is stored as the initial camera (to allow differences to be detected for pan/zoom values)

    Returns boolean

    boolean

publicsetActors

  • It removes all actors from the viewport and then adds the actors from the array.


    Parameters

    • actors: ActorEntry[]

      An array of ActorEntry objects.

    Returns void

publicsetCamera

  • setCamera(cameraInterface: ICamera, storeAsInitialCamera?: boolean): void
  • Set the camera parameters


    Parameters

    • cameraInterface: ICamera

      ICamera

    • storeAsInitialCamera: boolean = false

      to set the provided camera as the initial one, used to compute differences for things like pan and zoom.

    Returns void

publicsetDisplayArea

  • setDisplayArea(displayArea: DisplayArea, suppressEvents?: boolean): void
  • Sets the camera to an initial bounds. If resetPan and resetZoom are true it places the focal point at the center of the volume (or slice); otherwise, only the camera zoom and camera Pan or Zoom is reset for the current view.


    Parameters

    • displayArea: DisplayArea

      The display area of interest.

    • suppressEvents: boolean = false

      If true, don’t fire displayArea event.

    Returns void

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

publicsetRendered

  • setRendered(): void
  • Indicate that the image has been rendered. This will set the viewportStatus to RENDERED if there is image data available to actually be rendered - otherwise, the rendering simply showed the background image.


    Returns void

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

publicupdateCameraClippingPlanesAndRange

  • updateCameraClippingPlanesAndRange(): void
  • Updates the camera’s clipping planes and range.


    Returns void