Skip to content

Latest commit

 

History

History
1432 lines (824 loc) · 31.8 KB

api.md

File metadata and controls

1432 lines (824 loc) · 31.8 KB

Table of Contents

setContextToDisplayFontSize

Sets the canvas context transformation matrix so it is scaled to show text more cleanly even if the image is scaled up. See https://github.com/cornerstonejs/cornerstoneTools/wiki/DrawingText for more information

Parameters

  • enabledElement
  • context
  • fontSize

Returns {fontSize: number, lineHeight: number, fontScale: number}

triggerEvent

Trigger a CustomEvent

Parameters

  • el EventTarget The element or EventTarget to trigger the event upon
  • type String The event type name
  • detail (Object | null) =null The event data to be sent (optional, default null)

Returns Boolean The return value is false if at least one event listener called preventDefault(). Otherwise it returns true.

convertToVector3

Convert an Array to a cornerstoneMath.Vector3

Parameters

  • arrayOrVector3 (Array | cornerstoneMath.Vector3) Input array or Vector3

Returns cornerstoneMath.Vector3

makeUnselectable

A helper function to make an element (and its content) being non selectable.

Parameters

  • element {HTMLElement} The element to make unselectable
  • ignorePointerEvents {Boolean} true to make this element also ignore events (e.g. mouse click), false otherwise

Returns void

playClip

Starts playing a clip of different time series of the same image 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 have time series

Parameters

  • element
  • framesPerSecond

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
  • framesPerSecond

stopClip

Stops an already playing clip.

  • @param element

Parameters

  • element

stopClip

Stops an already playing clip.

  • @param element

Parameters

  • element

getPlayClipTimeouts

[private] Turns a Frame Time Vector (0018,1065) array into a normalized array of timeouts. Each element ... of the resulting array represents the amount of time each frame will remain on the screen.

Parameters

  • vector Array A Frame Time Vector (0018,1065) as specified in section C.7.6.5.1.2 of DICOM standard.
  • speed Number A speed factor which will be applied to each element of the resulting array.

Returns Array An array with timeouts for each animation frame.

stopClipWithData

[private] Performs the heavy lifting of stopping an ongoing animation.

Parameters

  • playClipData Object The data from playClip that needs to be stopped.

Returns any void

triggerStopEvent

[private] Trigger playClip tool stop event.

Parameters

  • element

Returns any void

createNewMeasurement

Initialises a new freehand data object

Returns Object measurementData - data object

pointNearTool

Returns true if the mouse cursor is near a handle

Parameters

  • eventData Object data object associated with an event.
  • toolIndex Number the ID of the tool

Returns Boolean

pointNearHandle

Returns a handle of a particular tool if it is close to the mouse cursor

Parameters

  • eventData Object data object associated with an event.
  • toolIndex Number the ID of the tool

Returns (Number | Object | Boolean)

pointNearHandleAllTools

Returns a handle if it is close to the mouse cursor (all tools)

Parameters

  • eventData Object data object associated with an event.

Returns Object

mouseDownActivateCallback

Event handler for MOUSE_DOWN_ACTIVATE event, if tool is active and the event is not caught by mouseDownCallback

Parameters

startDrawing

Begining of drawing loop when tool is active and a click event happens far from existing handles.

Parameters

  • eventData Object data object associated with an event.

addPointPencilMode

If in pencilMode, check the mouse position is farther than the minimum distance between points, then add a point.

Parameters

  • eventData Object Data object associated with an event.
  • dataHandles Object Data object associated with the tool.

addPoint

Adds a point on mouse click in polygon mode.

Parameters

  • eventData Object data object associated with an event.

endDrawing

Ends the active drawing loop and completes the polygon.

Parameters

  • eventData Object data object associated with an event.
  • handleNearby Object the handle nearest to the mouse cursor.

mouseDownActive

If in pencilMode, check the mouse position is farther than the minimum distance between points, then add a point.

Parameters

  • e
  • toolData
  • currentTool
  • eventData Object data object associated with an event.
  • dataHandles Object data object associated with the tool.

mouseDownCallback

Event handler for MOUSE_DOWN event.

Parameters

mouseDownCallback

Draw the magnifying glass on mouseDown, and begin tracking mouse movements

Parameters

  • e

mouseDownCallback

Records the start point and attaches the drag event handler

Parameters

  • e

mouseMoveCallback

Event handler for MOUSE_MOVE event.

Parameters

mouseMoveActive

Event handler called by mouseMoveCallback when the tool is currently active.

Parameters

  • eventData Object data object associated with an event.
  • toolData Object data object associated with the freehand tool.

checkInvalidHandleLocation

Returns true if the proposed location of a new handle is invalid.

Parameters

  • data Object data object associated with the tool.

Returns Boolean

checkHandlesPencilMode

Returns true if the proposed location of a new handle is invalid (in pencilMode).

Parameters

  • data Object data object associated with the tool.

Returns Boolean

checkHandlesPolygonMode

Returns true if the proposed location of a new handle is invalid (in polygon mode).

Parameters

  • data Object data object associated with the tool.

Returns Boolean

invalidHandlePencilMode

Returns true if the mouse position is far enough from previous points (in pencilMode).

Parameters

  • data Object data object associated with the tool.
  • mousePoint Object the position of the mouse cursor.

Returns Boolean

mouseDragCallback

Event handler for MOUSE_DRAG event.

Parameters

mouseUpCallback

Event handler for MOUSE_UP event.

Parameters

mouseUpCallback

Remove the magnifying glass when the mouse event ends

Parameters

  • e

mouseDownPassive

Event handler called by mouseDownCallback when the tool is currently deactive.

Parameters

modifyObject

Event handler called by mouseDownPassive which modifies a tool's data.

Parameters

  • e Object The event.
  • nearby Object Object containing information about a nearby handle.

modifyTextBox

Event handler called by mouseDownPassive which modifies a tool's textBox.

Parameters

  • element Object The element associated with the event.
  • nearby Object Object containing information about a nearby handle.

modifyHandle

Event handler called by mouseDownPassive which modifies a tool's handle.

Parameters

  • element Object The element associated with the event.
  • nearby Object Object containing information about a nearby handle.
  • toolData Object The data associated with the tool.

mouseHover

Activates a particular tool when the mouseCursor is near one if it's handles or it's textBox.

Parameters

  • eventData Object The data assoicated with the event.
  • toolData Object The data associated with the tool.

keyDownCallback

Event handler for KEY_DOWN event.

Parameters

keyUpCallback

Event handler for KEY_UP event.

Parameters

getMouseLocation

Gets the current mouse location and stores it in the configuration object.

Parameters

  • eventData Object The data assoicated with the event.

numberWithCommas

Adds commas as thousand seperators to a Number to increase readability.

Parameters

  • number (Number | String) A Number or String literal representing a number.

Returns String A string literal representaton of the number with commas seperating the thousands.

onImageRendered

Event handler for IMAGE_RENDERED event.

Parameters

enable

Attaches event listeners to the element such that is is visible.

Parameters

  • element Object The viewport element to attach event listeners to.

disable

Disables the reference line tool for the given element.

Parameters

  • element Object The viewport element to attach event listeners to.

activate

Attaches event listeners to the element such that is is visible, modifiable, and new data can be created.

Parameters

  • element Object The viewport element to attach event listeners to.
  • mouseButtonMask

deactivate

Attaches event listeners to the element such that is is visible and modifiable.

Parameters

  • element Object The viewport element to attach event listeners to.
  • mouseButtonMask

removeEventListeners

Removes event listeners from the element.

Parameters

  • element Object The viewport element to remove event listeners from.

getConfiguration

Get the configuation object for the freehand tool.

Returns Object configuration - The freehand tool's configuration object.

setConfiguration

Set the configuation object for the freehand tool.

Parameters

  • config Object The configuration object to set the freehand tool's configuration.

Moves a part of the freehand tool whilst it is dragged by the mouse.

Parameters

  • currentHandle Object The handle being dragged.
  • data Object The data associated with the freehand tool being modified.

dragObject

Parameters

  • currentHandle
  • data

Meta

  • author: JamesAPetts

dragTextBox

Moves a freehand tool's textBox whilst it is dragged by the mouse.

Parameters

  • currentHandle Object The handle being dragged.

dragHandle

Moves a handle of the freehand tool whilst it is dragged by the mouse.

Parameters

  • currentHandle Object The handle being dragged.
  • data Object The data associated with the freehand tool being modified.

Places part of the freehand tool when the mouse button is released.

Parameters

  • e Object The event.
  • toolData Object The data associated with the freehand tool.

dropObject

Parameters

  • e
  • toolData

Meta

  • author: JamesAPetts

dropTextbox

Places a freehand tool's textBox.

Parameters

  • eventData Object Data object associated with the event.
  • toolData Object The data associated with the freehand tool.

dropHandle

Places a handle of the freehand tool if the new location is valid. If the new location is invalid the handle snaps back to its previous position.

Parameters

  • eventData Object Data object associated with the event.
  • toolData Object The data associated with the freehand tool.

toolName

Type: string

Meta

  • author: JamesAPetts

toolName

Type: string

Meta

  • author: JamesAPetts

insertOrDelete

Inserts or deletes a point from a freehand tool.

Parameters

  • e Object The event.
  • nearby Object Object containing information about a nearby handle.

deletePoint

Deletes a point from a freehand tool.

Parameters

  • eventData Object The data object associated with the event.
  • deleteInfo Object Object containing information about which point to delete.

insertPoint

Inserts a new point into a freehand tool.

Parameters

  • eventData Object The data object associated with the event.
  • insertInfo Object Object containing information about where to insert the point.

getInsertionIndex

Gets the handle index of a tool in which to insert the new point.

Parameters

  • insertInfo Object Object containing information about where to insert the point.

ClickedLineData

Type: Object

Properties

  • toolIndex Number ID of the tool that the line corresponds to.
  • handleIndexArray Object An array of the handle indicies that correspond to the line segment.

constructor

Constructs a linefinder with the eventdata

Parameters

  • eventData Object Data object associated with the event.

findLine

Looks for lines near the mouse cursor.

Returns ClickedLineData

_nearestHandleToPointAllTools

Finds the nearest handle to the mouse cursor for all tools.

Returns Object closestHandle - The handle closest to the point.

_nearestHandleToPoint

Finds the nearest handle to the mouse cursor for a specific tool.

Parameters

  • toolIndex Number The index of the particular freehand tool.

Returns Object An object containing information about the closest handle.

_getCloseLinesInTool

Finds all the lines close to the mouse point for a particular tool.

Parameters

  • toolIndex Number The index of the particular freehand tool.

Returns Object An array of lines close to the mouse point.

_findCorrectLine

Finds the line the user clicked on from an array of close lines.

Parameters

  • toolIndex Number The index of the particular freehand tool.
  • closeLines Object An array of lines close to the mouse point.

Returns (ClickedLineData | null) An instance of ClickedLineData containing information about the line, or null if no line is correct.

_pointProjectsToLineSegment

Returns true if the mouse point projects onto the line segment.

Parameters

  • toolIndex Number The index of the particular freehand tool.
  • handleIndexArray Object An array of indicies corresponding to the line segment.

Returns Boolean True if the mouse point projects onto the line segment

_getLineOriginToMouseAsVector

Constructs a vector from the direction and magnitude of the line from the the line origin to the mouse cursor.

Parameters

  • p Object An array of two points respresenting the line segment.

Returns Object An array containing the x and y components of the vector.

_distanceOfPointfromLine

Calculates the perpendicular distance of the mouse cursor from a line segment.

Parameters

Returns Number The perpendicular distance of the mouse cursor from the line segment.

getCanvasPointsFromHandles

Returns the canvas positions from the handle's pixel positions.

Parameters

Returns Object An array contsining the handle positions in canvas coordinates.

getLineAsVector

Converts a line segment to a vector.

Parameters

  • p Object An array of two points respresenting the line segment.

Returns Object An array containing the x and y components of the vector, as well as a magnitude property.

getNextHandleIndex

Gets the next handl index from a cyclical array of points.

Parameters

  • currentIndex Number The current index.
  • length Number The number of handles in the polygon.

Returns Number The index of the next handle.

freeHandArea

Parameters

  • dataHandles
  • scaling

Meta

  • author: JamesAPetts

Calculates the statistics of all the points within the freehand object.

Parameters

  • sp Object An array of the pixel data.
  • boundingBox Object Rectangular box enclosing the polygon.
  • dataHandles Object Data object associated with the tool.

Returns Object statisticsObj - Object containing the derived statistics.

calculateFreehandStatistics

Parameters

  • sp
  • boundingBox
  • dataHandles

Meta

  • author: JamesAPetts

getSum

Calculates the sum, squared sum and count of all pixels within the polygon.

Parameters

  • sp Object An array of the pixel data.
  • boundingBox Object Rectangular box enclosing the polygon.
  • dataHandles Object Data object associated with the tool.

Returns Object sum - Object containing the sum, squared sum and pixel count.

sumPointIfInFreehand

Adds the pixel to the workingSum if it is within the polygon.

Parameters

  • dataHandles Object Data object associated with the tool.
  • point Object The pixel coordinates.
  • workingSum Object The working sum, squared sum and pixel count.
  • pixelValue Object The pixel value.

pointInFreehand

Calculates if "point" is inside the polygon defined by dataHandles by counting the number of times a ray originating from "point" crosses the edges of the polygon. Odd === inside, Even === outside. The bool "inROI" flips every time the ray originating from location and pointing to the right crosses a linesegment.

Parameters

  • dataHandles
  • location

Meta

  • author: JamesAPetts

isEnclosedY

Returns true if the y-position yp is enclosed within y-positions y1 and y2.

Parameters

  • yp Number The y position of point p.
  • y1 Number The y position of point 1.
  • y2 Number The y position of point 2.

Returns Boolean True if the y-position yp is enclosed within y-positions y1 and y2.

isLineRightOfPoint

Returns true if the line segment is to the right of the point.

Parameters

  • point Object The point being queried.
  • lp1 Object The first point of the line segment.
  • lp2 Object The second point of the line segment.

Returns Boolean True if the line is to the right of the point.

lineSegmentAtPoint

Returns the y value of the line segment at the x value of the point.

Parameters

  • point Object The point being queried.
  • lp1 Object The first point of the line segment.
  • lp2 Object The second point of the line segment.

Returns Object An object containing the y value as well as the gradient of the line segment.

rayFromPointCrosssesLine

Returns true if a rightwards ray originating from the point crosses the line defined by handleI and handleJ.

Parameters

  • point Object The point being queried.
  • handleI Object The first handle of the line segment.
  • handleJ Object The second handle of the line segment.

Returns Boolean True if a rightwards ray originating from the point crosses the line defined by handleI and handleJ.

newHandle

Orientation algoritm to determine if two lines cross. Credit and details: geeksforgeeks.org/check-if-two-given-line-segments-intersect/

Parameters

  • candidateHandle
  • dataHandles

Meta

  • author: JamesAPetts

newHandle

Determines whether a new handle causes an intersection of the lines of the polygon.

Parameters

  • candidateHandle Object The new handle to check.
  • dataHandles Object data object associated with the tool.

Returns Boolean Whether the new line intersects with any other lines of the polygon.

end

Checks if the last line of a polygon will intersect the other lines of the polgyon.

Parameters

  • dataHandles Object data object associated with the tool.

Returns Boolean Whether the last line intersects with any other lines of the polygon.

modify

Checks whether the modification of a handle's position causes intersection of the lines of the polygon

Parameters

  • dataHandles Object data object associated with the tool.
  • modifiedHandleId Number The id of the handle being modified.

Returns Boolean Whether the modfication causes any intersections.

doesIntersectOtherLines

Checks whether the line (p1,q1) intersects any of the other lines in the polygon.

Parameters

  • dataHandles Object data object associated with the tool.
  • p1 Object Coordinates of the start of the line.
  • q1 Object Coordinates of the end of the line.
  • ignoredHandleIds Object Ids of handles to ignore (i.e. lines that share a vertex with the line being tested).

Returns Boolean Whether the line intersects any of the other lines in the polygon.

doesIntersect

Checks whether the line (p1,q1) intersects the line (p2,q2) via an orientation algorithm.

Parameters

  • p1 Object Coordinates of the start of the line 2.
  • q1 Object Coordinates of the end of the line 2.
  • p2
  • q2

Returns Boolean Whether lines (p1,q1) and (p2,q2) intersect.

orientation

Checks the orientation of 3 points.

Parameters

Returns Number 0: Colinear, 1: Clockwise, 2: Anticlockwise

onSegment

Checks if point q lines on the segment (p,r).

Parameters

Returns Boolean If q lies on line segment (p,r).

FreehandHandleData

Parameters

  • position
  • highlight (optional, default true)
  • active (optional, default true)

Meta

  • author: JamesAPetts

FreehandHandleData

Type: Object

Properties

  • x Number The x position.
  • y Number The y position.
  • highlight Boolean Whether the handle should be rendered as the highlighted color.
  • active Boolean Whether the handle is active.
  • lines Object An array of lines associated with the handle.

dragCallback

Drag callback is triggered by both the touch and mouse magnify tools

Parameters

  • e

dragCallback

Draws the rectangular region while the touch or mouse event drag occurs

Parameters

  • e

createMagnificationCanvas

Creates the magnifying glass canvas

Parameters

  • element

removeMagnificationCanvas

Find the magnifying glass canvas and remove it

Parameters

  • element

calculateMinMaxMean

Calculates the minimum, maximum, and mean value in the given pixel array

Parameters

  • storedPixelLuminanceData
  • globalMin
  • globalMax

applyWWWCRegion

Calculates the minimum and maximum value in the given pixel array

Parameters

  • eventData

recordStartPoint

Records the start point of the click or touch

Parameters

  • eventData

getToolOptions

Retrieve the options object associated with a particular toolName and element

Parameters

  • toolName string Tool name identifier of the target options object
  • element HTMLElement Element of the target options object

Returns Object Target options object (empty if not yet set)

setToolOptions

Set the options object associated with a particular toolName and element

Parameters

  • toolName string Tool name identifier of the target options object
  • element HTMLElement Element of the target options object
  • options Object Options object to store at target

Returns void

clearToolOptions

Clear the options object associated with a particular toolName and element

Parameters

  • toolName string Tool name identifier of the target options object
  • element HTMLElement Element of the target options object

Returns void

clearToolOptionsByToolName

Clear the options objects associated with a particular toolName

Parameters

  • toolName string Tool type identifier of the target options objects

Returns void

clearToolOptionsByToolType

Clear the options objects associated with a particular toolType Deprecation Notice: This method will be replaced by clearToolOptionsByToolName

Parameters

  • toolType string Tool type identifier of the target options objects

Returns void

clearToolOptionsByElement

Clear the options objects associated with a particular element

Parameters

  • element HTMLElement Element of the target options objects

Returns void