Skip to main content

utilities

Index

References

triggerEvent

Re-exports triggerEvent

Namespaces

planar

planar:

linePlaneIntersection

  • It calculates the intersection of a line and a plane. Plane equation is Ax+By+Cz=D


    Parameters

    • p0: Point3

      [x,y,z] of the first point of the line

    • p1: Point3

      [x,y,z] of the second point of the line

    • plane: Plane

      [A, B, C, D] Plane parameter: Ax+By+Cz=D

    Returns Point3

    • [X,Y,Z] coordinates of the intersection

planeEquation

  • It returns the plane equation defined by a point and a normal vector.


    Parameters

    • normal: Point3

      normal vector

    • point: Point3 | vec3

      a point on the plane

    Returns Plane

    • [A, B,C, D] of plane equation AX + BY + C*Z = D

threePlaneIntersection

  • Computes the intersection of three planes in 3D space with equations: A1X + B1Y + C1Z = D1 A2X + B2Y + C2Z = D2 A3X + B3Y + C3*Z = D3


    Parameters

    Returns Point3

    • [x, y, z] the intersection in the world coordinate

windowLevel

windowLevel:

toLowHighRange

  • toLowHighRange(windowWidth: number, windowCenter: number): { lower: number; upper: number }
  • Given a window width and center, return the lower and upper bounds of the window


    Parameters

    • windowWidth: number

      the width of the window in HU

    • windowCenter: number

      The center of the window.

    Returns { lower: number; upper: number }

    a JavaScript object with two properties: lower and upper.

    • lower: number
    • upper: number

toWindowLevel

  • toWindowLevel(low: number, high: number): { windowCenter: number; windowWidth: number }
  • Given a low and high window level, return the window width and window center


    Parameters

    • low: number

      The low window level.

    • high: number

      The high window level.

    Returns { windowCenter: number; windowWidth: number }

    a JavaScript object with two properties: windowWidth and windowCenter.

    • windowCenter: number
    • windowWidth: number

Variables

constcalibratedPixelSpacingMetadataProvider

calibratedPixelSpacingMetadataProvider: { add: (imageId: string, payload: [number, number]) => void; get: (type: string, imageId: string) => [number, number] } = ...

Simple metadataProvider object to store metadata for calibrated spacings. This can be added via cornerstone.metaData.addProvider(…) in order to store and return calibrated pixel spacings when metaData type is “calibratedPixelSpacing”.


Type declaration

  • add: (imageId: string, payload: [number, number]) => void
      • (imageId: string, payload: [number, number]): void
      • Adds metadata for an imageId.


        Parameters

        • imageId: string

          the imageId for the metadata to store

        • payload: [number, number]

          the payload composed of new calibrated pixel spacings

        Returns void

  • get: (type: string, imageId: string) => [number, number]
      • (type: string, imageId: string): [number, number]
      • Returns the metadata for an imageId if it exists.


        Parameters

        • type: string

          the type of metadata to enquire about

        • imageId: string

          the imageId to enquire about

        Returns [number, number]

        the calibrated pixel spacings for the imageId if it exists, otherwise undefined

Functions

publiccreateFloat32SharedArray

  • createFloat32SharedArray(length: number): Float32Array
  • A helper function that creates a new Float32Array that utilized a shared array buffer. This allows the array to be updated simultaneously in workers or the main thread. Depending on the system (the CPU, the OS, the Browser) it can take a while until the change is propagated to all contexts.


    Parameters

    • length: number

      frame size * number of frames

    Returns Float32Array

    a Float32Array with an underlying SharedArrayBuffer

publiccreateUint8SharedArray

  • createUint8SharedArray(length: number): Uint8Array
  • A helper function that creates a new Float32Array that utilized a shared array buffer. This allows the array to be updated simultaneously in workers or the main thread. Depending on the system (the CPU, the OS, the Browser) it can take a while until the change is propagated to all contexts.


    Parameters

    • length: number

      frame size * number of frames

    Returns Uint8Array

    a Uint8Array with an underlying SharedArrayBuffer

getClosestImageId

  • Given an image, a point in space and the viewPlaneNormal it returns the closest imageId of the image volume that is within half voxel spacing of the point in space.


    Parameters

    • imageVolume: IImageVolume

      The image volume

    • worldPos: Point3

      The position in the world coordinate system (from mouse click)

    • viewPlaneNormal: Point3

      The normal vector of the viewport

    • viewUp: Point3

      The viewUp vector of the camera.

    Returns string

    The imageId for the tool.

getImageSliceDataForVolumeViewport

  • It calculates the number of slices and the current slice index for a given Volume viewport


    Parameters

    Returns ImageSliceData

    An object with two properties: numberOfSlices and imageIndex.

getMinMax

  • getMinMax(storedPixelData: number[]): { max: number; min: number }
  • Calculate the minimum and maximum values in an Array


    Parameters

    • storedPixelData: number[]

      The pixel data to calculate the min and max values for

    Returns { max: number; min: number }

    an object with two properties: min and max

    • max: number
    • min: number

getRuntimeId

  • getRuntimeId(context?: unknown, separator?: string, max?: number): string
  • Generate a unique numeric ID string valid during a single runtime session;


    Parameters

    • optionalcontext: unknown

      An optional object to be used as context. Defaults to a global context;

    • optionalseparator: string

      The component separator. Defaults to “-“;

    • optionalmax: number

      The maximum component value. Defaults to 4294967295;

    Returns string

    The string representation of the the unique ID;

getSliceRange

  • Given a vtkVolumeActor, and a normal direction, calculate the range of slices in the focal normal direction that encapsulate the volume. Also project the focalPoint onto this range.


    Parameters

    • volumeActor: vtkVolume

      The vtkVolumeActor.

    • viewPlaneNormal: Point3

      The normal to the camera view.

    • focalPoint: Point3

      The focal point of the camera.

    Returns ActorSliceRange

    an object containing the min, max and current positions in the normal direction.

getSpacingInNormalDirection

  • Given an imageVolume and a normal direction (viewPlaneNormal), calculates the spacing between voxels in the normal direction. If (viewPlaneNormal) is parallel to one of the directions you will obtain the spacing in that direction. Otherwise each of the imageVolume‘s directions are projected onto the volume, so that you obtain a spacing of the order of “seeing a new set of voxels if the camera where to dolly”.


    Parameters

    • imageVolume: IImageVolume

      The image volume to calculate the spacing in the normal direction.

    • viewPlaneNormal: Point3

      The normal direction of the view plane.

    Returns number

getTargetVolumeAndSpacingInNormalDir

  • getTargetVolumeAndSpacingInNormalDir(viewport: default, camera: ICamera, targetVolumeId?: string): { imageVolume: IImageVolume; spacingInNormalDirection: number }
  • Given a volume viewport and camera, find the target volume. The imageVolume is retrieved from cache for the specified targetVolumeId or in case it is not provided, it chooses the volumeId on the viewport (there might be more than one in case of fusion) that has the finest resolution in the direction of view (normal).


    Parameters

    • viewport: default

      volume viewport

    • camera: ICamera

      current camera

    • optionaltargetVolumeId: string

      If a target volumeId is given that volume is forced to be used.

    Returns { imageVolume: IImageVolume; spacingInNormalDirection: number }

    An object containing the imageVolume and spacingInNormalDirection.

getViewportsWithImageURI

  • getViewportsWithImageURI(imageURI: string, renderingEngineId?: string): Viewport[]
  • Get the viewport that is rendering the image with the given imageURI (imageId without the loader schema), this can be a stackViewport or a volumeViewport.


    Parameters

    • imageURI: string

      The imageURI of the image that is requested

    • optionalrenderingEngineId: string

    Returns Viewport[]

    A Viewport

getViewportsWithVolumeId

  • getViewportsWithVolumeId(volumeId: string, renderingEngineId?: string): IVolumeViewport[]

getVolumeActorCorners

  • getVolumeActorCorners(volumeActor: any): Point3[]
  • Converts vtkVolumeActor bounds to corners in world space.


    Parameters

    • volumeActor: any

      The vtkVolumeActor.

    Returns Point3[]

    An array of the corners of the volumeActor in world space.

getVolumeViewportsContainingSameVolumes

  • getVolumeViewportsContainingSameVolumes(targetViewport: default, renderingEngineId?: string): IVolumeViewport[]
  • Returns the viewports containing the same volume actors (all actors) the same as the target viewport. If renderingEngineId is provided, it will only return viewports that are associated with the renderingEngineId; otherwise, it will return search in all rendering engines.

    This method is useful for finding viewports that are associated with the same volume (e.g., for tools that share state between viewports).


    Parameters

    • targetViewport: default
    • optionalrenderingEngineId: string

    Returns IVolumeViewport[]

    array of viewports that have the same volume actor as the target viewport

imageIdToURI

  • imageIdToURI(imageId: string): string
  • Removes the data loader scheme from the imageId


    Parameters

    • imageId: string

      Image ID

    Returns string

    imageId without the data loader scheme

imageToWorldCoords

  • imageToWorldCoords(imageId: string, imageCoords: Point2): Point3 | undefined
  • Given the imageId and a 2d coordinates on the image space with [0,0] being the top left corner of the top left pixel, and options which includes the imageId, it returns the 3d coordinates on the world space.


    Parameters

    • imageId: string

      The image id

    • imageCoords: Point2

      The 2d coordinates on the image

    Returns Point3 | undefined

    The 3d coordinates on the world.

indexWithinDimensions

  • indexWithinDimensions(index: Point3, dimensions: Point3): boolean
  • Returns true if the specified index is within the given dimensions.


    Parameters

    • index: Point3

      The index to check.

    • dimensions: Point3

      The dimensions to check against.

    Returns boolean

    True if the index is in-bounds.

invertRgbTransferFunction

  • invertRgbTransferFunction(rgbTransferFunction: any): void
  • A utility that can be used to invert (in place) an RgbTransferFunction.


    Parameters

    • rgbTransferFunction: any

    Returns void

isEqual

  • isEqual(v1: number[] | Float32Array, v2: number[] | Float32Array, tolerance?: number): boolean
  • returns equal if the two arrays are identical within the given tolerance.


    Parameters

    • v1: number[] | Float32Array

      The first array of values

    • v2: number[] | Float32Array

      The second array of values.

    • tolerance: number = 1e-5

      The acceptable tolerance, the default is 0.00001

    Returns boolean

    True if the two values are within the tolerance levels.

isImageActor

  • isImageActor(actor: vtkVolume | vtkActor | vtkImageSlice): boolean
  • Checks if a vtk Actor is an image actor (vtkVolume or vtkImageSlice) otherwise returns false.


    Parameters

    • actor: vtkVolume | vtkActor | vtkImageSlice

      actor

    Returns boolean

    A boolean value.

isOpposite

  • isOpposite(v1: Point3, v2: Point3, tolerance?: number): boolean
  • returns equal if the two vec3s are opposite within the given tolerance in each dimension.


    Parameters

    • v1: Point3

      The first 3 vector

    • v2: Point3

      The second 3 vector.

    • tolerance: number = 1e-5

      The acceptable tolerance.

    Returns boolean

    True if the two values are within the tolerance levels.

loadImageToCanvas

  • loadImageToCanvas(canvas: HTMLCanvasElement, imageId: string, requestType?: RequestType, priority?: number): Promise<string>
  • Loads and renders an imageId to a Canvas. It will use the CPU rendering pipeline for image.


    Parameters

    • canvas: HTMLCanvasElement

      Canvas element to render to

    • imageId: string

      The imageId to render

    • requestType: RequestType = RequestType.Thumbnail

      The type of request (default to interaction), can be ‘interaction’ or ‘prefetch’ or ‘thumbnail’ the order of loading for the pool manager is interaction, thumbnail, prefetch

    • priority: number = -5

      The priority of the request within the request type (lower is higher priority)

    Returns Promise<string>

    • A promise that resolves when the image has been rendered with the imageId

renderToCanvas

  • renderToCanvas(canvas: HTMLCanvasElement, image: IImage, modality?: string): void
  • Renders a cornerstone image object to a canvas. Note: this does not load the image but only takes care of the rendering pipeline


    Parameters

    • canvas: HTMLCanvasElement

      Canvas element to render to

    • image: IImage

      Cornerstone image object

    • optionalmodality: string

    Returns void

scaleRgbTransferFunction

  • scaleRgbTransferFunction(rgbTransferFunction: any, scalingFactor: number): void
  • A utility that can be used to scale (in place) an RgbTransferFunction. We often use this to scale the transfer function based on a PET calculation.


    Parameters

    • rgbTransferFunction: any
    • scalingFactor: number

    Returns void

snapFocalPointToSlice

  • Given a number of frames, deltaFrames, move the focalPoint and camera position so that it moves forward/backwards deltaFrames in the camera’s normal direction, and snaps to the nearest frame.


    Parameters

    • focalPoint: Point3

      The focal point to move.

    • position: Point3

      The camera position to move.

    • sliceRange: ActorSliceRange

      The scroll range used to find the current position in the stack, as well as prevent scrolling past the extent of the volume.

    • viewPlaneNormal: Point3

      The normal direction of the camera.

    • spacingInNormalDirection: number

      The spacing of frames the normal direction of the camera.

    • deltaFrames: number

      The number of frames to jump.

    Returns { newFocalPoint: Point3; newPosition: Point3 }

    The newFocalPoint and newPosition of the camera.

transformWorldToIndex

  • transformWorldToIndex(imageData: any, worldPos: Point3): any
  • Given an imageData object and a point in physical space, return the index of the voxel that contains the point. TODO: this should be pushed to vtk upstream.


    Parameters

    • imageData: any

      The image data object.

    • worldPos: Point3

    Returns any

    An array of integers.

uuidv4

  • uuidv4(): string
  • Generates a unique id that has limited chance of collision


    Returns string

    a v4 compliant GUID

worldToImageCoords

  • worldToImageCoords(imageId: string, worldCoords: Point3): Point2 | undefined
  • Given the imageId, and 3d coordinates on the world space, it returns the continuos image coordinates (IJ) on the image space. The image space is defined with [0,0] being on the top left corner of the top left pixel, the [1,1] being on the bottom right corner of the top left pixel.


    Parameters

    • imageId: string

      The image id

    • worldCoords: Point3

      The 3d coordinates on the world.

    Returns Point2 | undefined

    The 2d coordinates on the image.