utilities
Index
References
Namespaces
Variables
Functions
- actorIsA
- applyPreset
- calculateViewportsSpatialRegistration
- createFloat32SharedArray
- createInt16SharedArray
- createLinearRGBTransferFunction
- createSigmoidRGBTransferFunction
- createUint16SharedArray
- createUint8SharedArray
- deepMerge
- getClosestImageId
- getClosestStackImageIndexForPoint
- getImageLegacy
- getImageSliceDataForVolumeViewport
- getMinMax
- getRuntimeId
- getScalarDataType
- getScalingParameters
- getSliceRange
- getSpacingInNormalDirection
- getTargetVolumeAndSpacingInNormalDir
- getViewportImageCornersInWorld
- getViewportsWithImageURI
- getViewportsWithVolumeId
- getVoiFromSigmoidRGBTransferFunction
- getVolumeActorCorners
- getVolumeSliceRangeInfo
- getVolumeViewportScrollInfo
- getVolumeViewportsContainingSameVolumes
- hasNaNValues
- imageIdToURI
- imageToWorldCoords
- indexWithinDimensions
- invertRgbTransferFunction
- isEqual
- isImageActor
- isOpposite
- isPTPrescaledWithSUV
- loadImageToCanvas
- renderToCanvasCPU
- renderToCanvasGPU
- scaleRgbTransferFunction
- snapFocalPointToSlice
- transformWorldToIndex
- uuidv4
- worldToImageCoords
References
triggerEvent
Namespaces
colormap
getColormap
Parameters
name: any
name of the colormap
Returns any
colormap object
getColormapNames
Get all registered colormap names
Returns any[]
array of colormap names
registerColormap
Register a colormap
Parameters
colormap: ColormapRegistration
colormap object
Returns void
planar
linePlaneIntersection
planeDistanceToPoint
planeEquation
threePlaneIntersection
windowLevel
toLowHighRange
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
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
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: CalibratedPixelValue) => void
Adds metadata for an imageId.
Parameters
imageId: string
the imageId for the metadata to store
payload: CalibratedPixelValue
the payload composed of new calibrated pixel spacings
Returns void
get: (type: string, imageId: string) => CalibratedPixelValue
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 CalibratedPixelValue
the calibrated pixel spacings for the imageId if it exists, otherwise undefined
constspatialRegistrationMetadataProvider
Simple metadataProvider object to store metadata for spatial registration module.
Type declaration
add: (query: string[], payload: mat4) => void
Parameters
query: string[]
payload: mat4
Returns void
get: (type: string, query: string[]) => mat4
Parameters
type: string
query: string[]
Returns mat4
Functions
actorIsA
Parameters
actorEntry: ActorEntry
actorType: actorTypes
Returns boolean
applyPreset
Applies a preset to a volume actor.
Parameters
actor: vtkVolume
The volume actor to apply the preset to.
preset: ViewportPreset
The preset to apply.
Returns void
calculateViewportsSpatialRegistration
It calculates the registration matrix between two viewports (currently only translation is supported) If the viewports are in the same frame of reference, it will return early, but otherwise it will use the current image’s metadata to calculate the translation between the two viewports and adds it to the spatialRegistrationModule metadata provider
Parameters
Returns void
publiccreateFloat32SharedArray
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
publiccreateInt16SharedArray
A helper function that creates a new Int16 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 Int16Array
a Int8Array with an underlying SharedArrayBuffer
createLinearRGBTransferFunction
Parameters
voiRange: VOIRange
Returns vtkColorTransferFunction
createSigmoidRGBTransferFunction
A utility that can be used to generate an Sigmoid RgbTransferFunction. Sigmoid transfer functions are used in the dicom specification: https://dicom.nema.org/medical/dicom/2018b/output/chtml/part03/sect_C.11.2.html
Parameters
voiRange: VOIRange
approximationNodes: number = 1024
Returns vtkColorTransferFunction
publiccreateUint16SharedArray
A helper function that creates a new Uint16 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 Uint16Array
a Uint8Array with an underlying SharedArrayBuffer
publiccreateUint8SharedArray
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
deepMerge
Merge two objects, recursively merging any objects that are arrays
Parameters
target: {} = {}
The target object.
source: {} = {}
The source object to merge into the target object.
optionsArgument: any = undefined
The options object.
Returns any
The merged object.
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
Returns string
The imageId for the tool.
getClosestStackImageIndexForPoint
Given a point in 3D space and a viewport it returns the index of the closest imageId, it assumes that stack images are sorted according to their sliceLocation
Parameters
point: Point3
[A, B, C] coordinates of the point in 3D space
viewport: default
The StackViewport to search for the closest imageId
Returns number | null
The imageId index of the closest imageId or null if no imageId is found
getImageLegacy
Gets the IImage rendered by the given element. This is provided as a convenience for the legacy cornerstone getImage function. However it is encouraged for IStackViewport.getImage to be used instead.
Parameters
element: HTMLDivElement
the element rendering/containing the image
Returns Types.IImage | undefined
the image
getImageSliceDataForVolumeViewport
It calculates the number of slices and the current slice index for a given Volume viewport
Parameters
viewport: default
volume viewport
Returns ImageSliceData
An object with two properties: numberOfSlices and imageIndex.
getMinMax
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
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;
getScalarDataType
If the scalar data is a Uint8Array, return ‘Uint8Array’. If the scalar data is a Float32Array, return ‘Float32Array’. If the scalar data is a Int16Array, return ‘Int16Array’. If the scalar data is a Uint16Array, return ‘Uint16Array’. If the scalar data is none of the above, throw an error.
Parameters
scalingParameters: ScalingParameters
{
optionalscalarData: any
The data to be converted.
Returns string
The data type of the scalar data.
getScalingParameters
It returns the scaling parameters for the image with the given imageId. This can be used to get passed (as an option) to the imageLoader in order to apply scaling to the image inside the imageLoader.
Parameters
imageId: string
The imageId of the image
Returns ScalingParameters
ScalingParameters
getSliceRange
Given a
vtkVolumeActor
, and a normal direction, calculate the range of slices in the focal normal direction that encapsulate the volume. Also project thefocalPoint
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
andcurrent
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 theimageVolume
‘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
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 { actorUID: string; imageVolume: IImageVolume; spacingInNormalDirection: number }
An object containing the imageVolume and spacingInNormalDirection.
actorUID: string
imageVolume: IImageVolume
spacingInNormalDirection: number
getViewportImageCornersInWorld
Given a viewport, return the corners of the image in the viewport in world coordinates. Note that this is different than the corners of the canvas in world coordinates since an image can be zoomed out and the canvas can be larger than the image; hence, the corners of the canvas in world coordinates will be outside the image.
Parameters
Returns Point3[]
The corners of the image in the viewport in world coordinates.
getViewportsWithImageURI
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
Similar to getVolumeViewportsContainingSameVolumes, but uses the volumeId to filter viewports that contain the same volume.
Parameters
volumeId: string
optionalrenderingEngineId: string
Returns IVolumeViewport[]
VolumeViewport viewports array
getVoiFromSigmoidRGBTransferFunction
Parameters
cfun: vtkColorTransferFunction
Returns [number, number]
getVolumeActorCorners
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.
getVolumeSliceRangeInfo
Calculates the slice range for the given volume based on its orientation
Parameters
viewport: default
Volume viewport
volumeId: string
Id of one of the volumes loaded on the given viewport
Returns { camera: ICamera; sliceRange: ActorSliceRange; spacingInNormalDirection: number }
slice range information
camera: ICamera
sliceRange: ActorSliceRange
spacingInNormalDirection: number
getVolumeViewportScrollInfo
Calculates the number os steps the volume can scroll based on its orientation
Parameters
viewport: default
Volume viewport
volumeId: string
Id of one of the volumes loaded on the given viewport
Returns { currentStepIndex: number; numScrollSteps: number; sliceRangeInfo: { camera: ICamera; sliceRange: ActorSliceRange; spacingInNormalDirection: number } }
number of steps the volume can scroll and its current position
currentStepIndex: number
numScrollSteps: number
sliceRangeInfo: { camera: ICamera; sliceRange: ActorSliceRange; spacingInNormalDirection: number }
camera: ICamera
sliceRange: ActorSliceRange
spacingInNormalDirection: number
getVolumeViewportsContainingSameVolumes
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
hasNaNValues
A function that checks if there is a value in the array that is NaN. or if the input is a number it just checks if it is NaN.
Parameters
input: number | number[]
The input to check if it is NaN.
Returns boolean
- True if the input is NaN, false otherwise.
imageIdToURI
Removes the data loader scheme from the imageId
Parameters
imageId: string
Image ID
Returns string
imageId without the data loader scheme
imageToWorldCoords
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
invertRgbTransferFunction
A utility that can be used to invert (in place) an RgbTransferFunction.
Parameters
rgbTransferFunction: any
Returns void
isEqual
Returns whether two values are equal or not, based on epsilon comparison. For array comparison, it does NOT strictly compare them but only compare its values. It can compare array of numbers and also typed array. Otherwise it will just return false.
Type parameters
- ValueType
Parameters
v1: ValueType
The first value to compare
v2: ValueType
The second value to compare
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
Checks if a vtk Actor is an image actor (vtkVolume or vtkImageSlice) otherwise returns false.
Parameters
actorEntry: ActorEntry
Returns boolean
A boolean value.
isOpposite
isPTPrescaledWithSUV
Parameters
image: IImage
Returns number
loadImageToCanvas
Loads and renders an imageId to a Canvas. It will use the GPU rendering pipeline for image by default but you can force the CPU rendering pipeline by setting the useCPURendering parameter to true.
Parameters
options: LoadImageOptions
Returns Promise<string>
- A promise that resolves when the image has been rendered with the imageId
renderToCanvasCPU
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
optionalrenderingEngineId: string
Returns Promise<string>
renderToCanvasGPU
Renders an cornerstone image to a Canvas. This method will handle creation of a temporary enabledElement, setting the imageId, and rendering the image via a StackViewport, copying the canvas drawing to the given canvas Element, and disabling the created temporary element. SuppressEvents argument is used to prevent events from firing during the render process (e.g. during a series of renders to a thumbnail image).
Parameters
canvas: HTMLCanvasElement
Canvas element to render to
image: IImage
The image to render
modality: any = undefined
[Default = undefined] The modality of the image
renderingEngineId: string = '_thumbnails'
Returns Promise<string>
- A promise that resolves when the image has been rendered with the imageId
scaleRgbTransferFunction
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 thefocalPoint
and cameraposition
so that it moves forward/backwardsdeltaFrames
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
andnewPosition
of the camera.
transformWorldToIndex
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
Generates a unique id that has limited chance of collision
Returns string
a v4 compliant GUID
worldToImageCoords
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.
Get a colormap by name