utilities
Index
References
Namespaces
Functions
References
triggerEvent
Namespaces
boundingBox
extend2DBoundingBoxInViewAxis
Parameters
boundsIJK: [Point2, Point2, Point2]
[[iMin, iMax], [jMin, jMax], [kMin, kMax]]
numSlicesToProject: number
Returns [Types.Point2, Types.Point2, Types.Point2]
extended bounds
getBoundingBoxAroundShape
With a given vertices (points) coordinates in IJK, it calculates the minimum and maximum coordinate in each axis, and returns them. If dimensions are provided it also clip the min, max to the provided width, height and depth
Parameters
points: Point3[]
shape corner points coordinates (IJK)
optionaldimensions: Point3
dimensions of the image
Returns [Types.Point2, Types.Point2, Types.Point2]
[[xMin,xMax],[yMin,yMax], [zMin,zMax]]
cine
Events
CINE Tool Events
CLIP_STARTED
CLIP_STOPPED
addToolState
Parameters
element: HTMLDivElement
data: ToolData
Returns void
getToolState
Parameters
element: HTMLDivElement
Returns CINETypes.ToolData | undefined
playClip
Starts playing a clip or adjusts the frame rate of an already playing clip. framesPerSecond is optional and defaults to 30 if not specified. A negative framesPerSecond will play the clip in reverse. The element must be a stack of images
Parameters
element: HTMLDivElement
HTML Element
playClipOptions: PlayClipOptions
Returns void
stopClip
Stops an already playing clip.
Parameters
element: HTMLDivElement
HTML Element
Returns void
drawing
getTextBoxCoordsCanvas
Determine the coordinates that will place the textbox to the right of the annotation.
Parameters
annotationCanvasPoints: Point2[]
The canvas points of the annotation’s handles.
Returns Types.Point2
- The coordinates for default placement of the textbox.
math
ellipse
getCanvasEllipseCorners
It takes the canvas coordinates of the ellipse corners and returns the top left and bottom right corners of it
Parameters
ellipseCanvasPoints: canvasCoordinates
The coordinates of the ellipse in the canvas.
Returns Types.Point2[]
An array of two points.
pointInEllipse
Given an ellipse and a point, return true if the point is inside the ellipse
Parameters
ellipse: Ellipse
The ellipse object to check against.
pointLPS: Point3
The point in LPS space to test.
Returns boolean
A boolean value.
lineSegment
distanceToPoint
distanceToPointSquared
intersectLine
Calculates the intersection point between two lines in the 2D plane
Parameters
line1Start: Point2
x,y coordinates of the start of the first line
line1End: Point2
x,y coordinates of the end of the first line
line2Start: Point2
x,y coordinates of the start of the second line
line2End: Point2
x,y coordinates of the end of the second line
Returns number[]
[x,y] - point x,y of the point
point
distanceToPoint
polyline
addCanvasPointsToArray
calculateAreaOfPoints
Calculates the area of an array of
Point2
points using the shoelace algorithm.The units of the area are in the same units as the points are in. E.g. if the points are in canvas, then the result is in canvas pixels ^2; If they are in mm, then the result is in mm^2; etc.
Parameters
points: Point2[]
Returns number
getClosestIntersectionWithPolyline
Checks whether the line (
p1
,q1
) intersects any of the other lines in thepoints
, and returns the closest value.Parameters
Returns { distance: number; segment: Types.Point2 } | undefined
getFirstIntersectionWithPolyline
Checks whether the line (
p1
,q1
) intersects any of the other lines in thepoints
, and returns the first value.Parameters
Returns Types.Point2 | undefined
getSubPixelSpacingAndXYDirections
Gets the desired spacing for points in the polyline for the
PlanarFreehandROITool
in the x and y canvas directions, as well as returning these canvas directions in world space.Parameters
viewport: default | default
The Cornerstone3D
StackViewport
orVolumeViewport
.subPixelResolution: number
The number to divide the image pixel spacing by to get the sub pixel spacing. E.g.
10
will return spacings 10x smaller than the native image spacing.
Returns { spacing: Point2; xDir: Point3; yDir: Point3 }
The spacings of the X and Y directions, and the 3D directions of the x and y directions.
pointCanProjectOnLine
pointsAreWithinCloseContourProximity
rectangle
distanceToPoint
Calculates distance of the point to the rectangle. It calculates the minimum distance between the point and each line segment of the rectangle.
Parameters
rect: number[]
coordinates of the rectangle [left, top, width, height]
point: Point2
[x,y] coordinates of a point
Returns number
vec2
findClosestPoint
Find the closest point to the target point
Parameters
sourcePoints: Point2[]
The potential source points.
targetPoint: Point2
The target point, used to find the closest source.
Returns Types.Point2
The closest point in the array of point sources
liangBarksyClip
Parameters
a: any
b: any
box: any
[xmin, ymin, xmax, ymax]
optionalda: any
optionaldb: any
Returns 0 | 1
orientation
publicgetOrientationStringLPS
Returns the orientation of the vector in the patient coordinate system.
Parameters
vector: Point3
Input array
Returns string
The orientation in the patient coordinate system.
publicinvertOrientationStringLPS
Inverts an orientation string.
Parameters
orientationString: string
The orientation.
Returns string
The inverted orientationString.
planar
filterAnnotationsForDisplay
Given the viewport and the annotations, it filters the annotations array and only return those annotation that should be displayed on the viewport
Parameters
viewport: IViewport
annotations: Annotations
Annotations
Returns Annotations
A filtered version of the annotations.
filterAnnotationsWithinSlice
given some
Annotations
, and the slice defined by the camera’s normal direction and the spacing in the normal, filter theAnnotations
which is within the slice.Parameters
annotations: Annotations
Annotations
camera: ICamera
The camera
spacingInNormalDirection: number
The spacing in the normal direction
Returns Annotations
The filtered
Annotations
.
getPointInLineOfSightWithCriteria
Returns a point based on some criteria (e.g., minimum or maximum intensity) in the line of sight (on the line between the passed worldPosition and camera position). It iterated over the points with a step size on the line.
Parameters
viewport: default
Volume viewport
worldPos: Point3
World coordinates of the clicked location
targetVolumeId: string
target Volume ID in the viewport
criteriaFunction: (intensity: number, point: Point3) => Point3
A function that returns the point if it passes a certain written logic, for instance, it can be a maxValue function that keeps the records of all intensity values, and only return the point if its intensity is greater than the maximum intensity of the points passed before.
stepSize: number = 0.25
Returns Types.Point3
the World pos of the point that passes the criteriaFunction
getWorldWidthAndHeightFromCorners
Given two world positions and an orthogonal view to an
imageVolume
defined by aviewPlaneNormal
and aviewUp
, get the width and height in world coordinates of the rectangle defined by the two points. The implementation works both with orthogonal non-orthogonal rectangles.Parameters
viewPlaneNormal: Point3
The normal of the view.
viewUp: Point3
The up direction of the view.
topLeftWorld: Point3
The first world position.
bottomRightWorld: Point3
The second world position.
Returns { worldHeight: number; worldWidth: number }
The
worldWidth
andworldHeight
.worldHeight: number
worldWidth: number
planarFreehandROITool
interpolateAnnotation
Interpolates a given annotation from a given enabledElement. It mutates annotation param. The param knotsRatioPercentage defines the percentage of points to be considered as knots on the interpolation process. Interpolation will be skipped in case: annotation is not present in enabledElement (or there is no toolGroup associated with it), related tool is being modified.
Parameters
enabledElement: IEnabledElement
annotation: PlanarFreehandROIAnnotation
knotsRatioPercentage: number
Returns boolean
rectangleROITool
getBoundsIJKFromRectangleAnnotations
Parameters
annotations: any
referenceVolume: any
options: Options = ...
Returns any
segmentation
createLabelmapVolumeForViewport
Create a new 3D segmentation volume from the default imageData presented in the first actor of the viewport. It looks at the metadata of the imageData to determine the volume dimensions and spacing if particular options are not provided.
Parameters
input: { options?: { dimensions?: Point3; direction?: Float32Array; metadata?: any; origin?: Point3; scalarData?: Float32Array | Uint8Array; spacing?: Point3; targetBuffer?: { type: Float32Array | Uint8Array }; volumeId?: string }; renderingEngineId: string; segmentationId?: string; viewportId: string }
Returns Promise<string>
A promise that resolves to the Id of the new labelmap volume.
createMergedLabelmapForIndex
Given a list of labelmaps (with the possibility of overlapping regions), and a segmentIndex it creates a new labelmap with the same dimensions as the input labelmaps, but merges them into a single labelmap for the segmentIndex. It wipes out all other segment Indices. This is useful for calculating statistics regarding a specific segment when there are overlapping regions between labelmap (e.g. TMTV)
Parameters
labelmaps: IImageVolume[]
Array of labelmaps
segmentIndex: number = 1
The segment index to merge
volumeId: string = 'mergedLabelmap'
Returns Types.IImageVolume
Merged labelmap
floodFill
floodFill.js - Taken from MIT OSS lib - https://github.com/tuzz/n-dimensional-flood-fill Refactored to ES6.
Parameters
getter: FloodFillGetter
The getter to the elements of your data structure, e.g. getter(x,y) for a 2D interprettation of your structure.
seed: Point3 | Point2
The seed for your fill. The dimensionality is infered by the number of dimensions of the seed.
options: FloodFillOptions = {}
Returns FloodFillResult
getBrushSizeForToolGroup
Parameters
toolGroupId: string
Returns void
getBrushThresholdForToolGroup
Parameters
toolGroupId: string
Returns any
getDefaultRepresentationConfig
It returns a configuration object for the given representation type.
Parameters
segmentation: Segmentation
Returns LabelmapConfig
A representation configuration object.
isValidRepresentationConfig
Given a representation type and a configuration, return true if the configuration is valid for that representation type
Parameters
representationType: string
The type of segmentation representation
config: RepresentationConfig
RepresentationConfig
Returns boolean
A boolean value.
rectangleROIThresholdVolumeByRange
It uses the provided rectangleROI annotations (either RectangleROIThreshold, or RectangleROIStartEndThreshold) to compute an ROI that is the intersection of all the annotations. Then it uses the rectangleROIThreshold utility to threshold the volume.
Parameters
annotationUIDs: string[]
rectangleROI annotationsUIDs to use for ROI
segmentationVolume: IImageVolume
the segmentation volume
thresholdVolumeInformation: ThresholdInformation[]
object array containing the volume data and range threshold values
options: ThresholdOptions
options for thresholding
Returns Types.IImageVolume
setBrushSizeForToolGroup
Parameters
toolGroupId: string
brushSize: number
Returns void
setBrushThresholdForToolGroup
Parameters
toolGroupId: string
threshold: Point2
Returns void
thresholdVolumeByRange
It thresholds a segmentation volume based on a set of threshold values with respect to a list of volumes and respective threshold ranges.
Parameters
segmentationVolume: IImageVolume
the segmentation volume to be modified
thresholdVolumeInformation: ThresholdInformation[]
array of objects containing volume data and a range (lower and upper values) to threshold
options: ThresholdRangeOptions
the options for thresholding As there is a chance the volumes might have different dimensions and spacing, could be the case of no 1 to 1 mapping. So we need to work with the idea of voxel overlaps (1 to many mappings). We consider all intersections valid, to avoid thecomplexity to calculate a minimum voxel intersection percentage. This function, given a voxel center and spacing, calculates the overlap of the voxel with another volume and range check the voxels in the overlap. Three situations can occur: all voxels pass the range check, some voxels pass or none voxels pass. The overlapType parameter indicates if the user requires all voxels pass (overlapType = 1) or any voxel pass (overlapType = 0)
Returns Types.IImageVolume
segmented volume
triggerSegmentationRender
It triggers a render for all the segmentations of the tool group with the given Id.
Parameters
toolGroupId: string
The Id of the tool group to render.
Returns void
stackPrefetch
disable
Parameters
element: any
Returns void
enable
Parameters
element: any
Returns void
getConfiguration
Returns { maxImagesToPrefetch: number; preserveExistingPool: boolean }
maxImagesToPrefetch: number
preserveExistingPool: boolean
setConfiguration
Parameters
config: any
Returns void
touch
copyPoints
Parameters
points: ITouchPoints
Returns ITouchPoints
copyPointsList
Copies a set of points.
Parameters
points: ITouchPoints[]
The
IPoints
instance to copy.
Returns ITouchPoints[]
A copy of the points.
getDeltaDistance
getDeltaDistanceBetweenIPoints
getDeltaPoints
getDeltaRotation
Parameters
currentPoints: ITouchPoints[]
lastPoints: ITouchPoints[]
Returns void
getMeanPoints
getMeanTouchPoints
Parameters
points: ITouchPoints[]
Returns ITouchPoints
viewport
jumpToSlice
isViewportPreScaled
jumpToWorld
viewportFilters
filterViewportsWithFrameOfReferenceUID
Given an array of viewports, returns a list of viewports that are viewing a world space with the given
FrameOfReferenceUID
.Parameters
viewports: (default | default)[]
An array of viewports.
FrameOfReferenceUID: string
The UID defining a particular world space/Frame Of Reference.
Returns (Types.IStackViewport | Types.IVolumeViewport)[]
A filtered array of viewports.
filterViewportsWithParallelNormals
It filters the viewports that are looking in the same view as the camera It basically checks if the viewPlaneNormal is parallel to the camera viewPlaneNormal
Parameters
viewports: any
Array of viewports to filter
camera: any
Camera to compare against
EPS: number = 0.999
Returns any
- Array of viewports with the same view
filterViewportsWithToolEnabled
Given an array of viewports, returns a list of viewports that have the the specified tool enabled.
Parameters
viewports: (default | default)[]
An array of viewports.
toolName: string
The name of the tool to filter on.
Returns (Types.IStackViewport | Types.IVolumeViewport)[]
A filtered array of viewports.
getViewportIdsWithToolToRender
Given a cornerstone3D enabled
element
, and atoolName
, find all viewportIds looking at the same Frame Of Reference that have the tool with the giventoolName
active, passive or enabled.Parameters
element: HTMLDivElement
The target cornerstone3D enabled element.
toolName: string
The string toolName.
requireParallelNormals: boolean = true
If true, only return viewports that have parallel normals.
Returns string[]
An array of viewportIds.
Functions
calibrateImageSpacing
It adds the provided spacing to the Cornerstone internal calibratedPixelSpacing metadata provider, then it invalidates all the tools that have the imageId as their reference imageIds. Finally, it triggers a re-render for invalidated annotations.
Parameters
imageId: string
ImageId for the calibrated image
renderingEngine: default
Cornerstone RenderingEngine instance
rowPixelSpacing: number
Spacing in row direction
columnPixelSpacing: number
Spacing in column direction
Returns void
publicclip
Clips a value to an upper and lower bound.
Parameters
val: number
The value to clip.
low: number
The lower bound.
high: number
The upper bound.
Returns number
The clipped value.
debounce
Creates a debounced function that delays invoking
func
until afterwait
milliseconds have elapsed since the last time the debounced function was invoked, or until the next browser frame is drawn. The debounced function comes with acancel
method to cancel delayedfunc
invocations and aflush
method to immediately invoke them. Provideoptions
to indicate whetherfunc
should be invoked on the leading and/or trailing edge of thewait
timeout. Thefunc
is invoked with the last arguments provided to the debounced function. Subsequent calls to the debounced function return the result of the lastfunc
invocation.Note: If
leading
andtrailing
options aretrue
,func
is invoked on the trailing edge of the timeout only if the debounced function is invoked more than once during thewait
timeout.If
wait
is0
andleading
isfalse
,func
invocation is deferred until the next tick, similar tosetTimeout
with a timeout of0
.If
wait
is omitted in an environment withrequestAnimationFrame
,func
invocation will be deferred until the next frame is drawn (typically about 16ms).See David Corbacho’s article for details over the differences between
debounce
andthrottle
.Parameters
func: Function
The function to debounce.
optionalwait: number
The number of milliseconds to delay; if omitted,
requestAnimationFrame
is used (if available).optionaloptions: { leading: boolean; maxWait: number; trailing: boolean }
The options object.
Returns Function
Returns the new debounced function.
deepMerge
Merge two objects, recursively merging any objects that are arrays
Parameters
optionaltarget: {} = {}
The target object.
optionalsource: {} = {}
The source object to merge into the target object.
optionaloptionsArgument: any = undefined
The options object.
Returns any
The merged object.
getAnnotationNearPoint
Get the annotation that is close to the provided canvas point, it will return the first annotation that is found.
Parameters
element: HTMLDivElement
The element to search for an annotation on.
canvasPoint: Point2
The canvasPoint on the page where the user clicked.
proximity: number = 5
The distance from the canvasPoint to the annotation.
Returns Annotation | null
The annotation for the element
getAnnotationNearPointOnEnabledElement
“Find the annotation near the point on the enabled element.” it will return the first annotation that is found.
Parameters
enabledElement: IEnabledElement
The element that is currently active.
point: Point2
The point to search near.
proximity: number
The distance from the point that the annotation must be within.
Returns Annotation | null
A Annotation object.
isObject
Checks if
value
is the language type ofObject
. (e.g. arrays, functions, objects, regexes,new Number(0)
, andnew String('')
)Parameters
value: any
The value to check.
Returns boolean
Returns
true
ifvalue
is an object, elsefalse
.
jumpToSlice
It uses the imageIndex in the Options to scroll to the slice that is intended. It works for both Stack and Volume viewports. In VolumeViewports, the imageIndex should be given with respect to the index in the 3D image in the view direction (i.e. the index of the slice in Axial, Sagittal, Coronal, or Oblique).
Parameters
element: HTMLDivElement
the HTML Div element scrolling inside
options: JumpToSliceOptions = ...
the options used for jumping to a slice
Returns Promise<void>
Promise that resolves to ImageIdIndex
pointInShapeCallback
For each point in the image (If boundsIJK is not provided, otherwise, for each point in the provided bounding box), It runs the provided callback IF the point passes the provided criteria to be inside the shape (which is defined by the provided pointInShapeFn)
Parameters
imageData: vtkImageData | CPUImageData
The image data object.
pointInShapeFn: ShapeFnCriteria
A function that takes a point in LPS space and returns true if the point is in the shape and false if it is not.
callback: PointInShapeCallback
A function that will be called for every point in the shape.
optionalboundsIJK: BoundsIJK
The bounds of the volume in IJK coordinates.
Returns void
pointInSurroundingSphereCallback
Given an imageData, and the great circle top and bottom points of a sphere, this function will run the callback for each point of the imageData that is within the sphere defined by the great circle points. If the viewport is provided, region of interest will be an accurate approximation of the sphere (using viewport camera), and the resulting performance will be better.
Parameters
imageData: vtkImageData
The volume imageData
circlePoints: [Point3, Point3]
bottom and top points of the great circle in world coordinates
callback: PointInShapeCallback
A callback function that will be called for each point in the shape.
optionalviewport: default
Returns void
scroll
It scrolls one slice in the Stack or Volume Viewport, it uses the options provided to determine the slice to scroll to. For Stack Viewport, it scrolls in the 1 or -1 direction, for Volume Viewport, it uses the camera and focal point to determine the slice to scroll to based on the spacings.
Parameters
viewport: default | default
The viewport in which to scroll
options: ScrollOptions
Options to use for scrolling, including direction, invert, and volumeId
Returns void
throttle
Creates a throttled function that only invokes
func
at most once per everywait
milliseconds (or once per browser frame). The throttled function comes with acancel
method to cancel delayedfunc
invocations and aflush
method to immediately invoke them. Provideoptions
to indicate whetherfunc
should be invoked on the leading and/or trailing edge of thewait
timeout. Thefunc
is invoked with the last arguments provided to the throttled function. Subsequent calls to the throttled function return the result of the lastfunc
invocation.Note: If
leading
andtrailing
options aretrue
,func
is invoked on the trailing edge of the timeout only if the throttled function is invoked more than once during thewait
timeout.If
wait
is0
andleading
isfalse
,func
invocation is deferred until the next tick, similar tosetTimeout
with a timeout of0
.If
wait
is omitted in an environment withrequestAnimationFrame
,func
invocation will be deferred until the next frame is drawn (typically about 16ms).See David Corbacho’s article for details over the differences between
throttle
anddebounce
.Parameters
func: Function
The function to throttle.
optionalwait: number
The number of milliseconds to throttle invocations to; if omitted,
requestAnimationFrame
is used (if available).optionaloptions: { leading: boolean; trailing: boolean }
The options object.
Returns Function
Returns the new throttled function.
triggerAnnotationRender
It triggers the rendering of the annotations for the given HTML element using the
AnnotationRenderingEngine
Parameters
element: HTMLDivElement
The element to render the annotation on.
Returns void
triggerAnnotationRenderForViewportIds
Parameters
renderingEngine: default
viewportIdsToRender: string[]
Returns void
Uses the current bounds of the 2D rectangle and extends it in the view axis by numSlices It compares min and max of each IJK to find the view axis (for axial, zMin === zMax) and then calculates the extended range. It will assume the slice is relative to the current slice and will add the given slices to the current max of the boundingBox.