Tool Types
In order to make development of new Tools quick, easy and relatively boilerplate-free, all Tools extend a base class, which provides the functionality required to integrate seamlessly into the cornerstoneTools framework.
Base classes have two types of methods of interest to Tool developers:
@abstractmethods: These methods must be implemented by subclasses.@virtualmethods: These methods have default functionality, but may be overridden by subclasses to alter functionality.
Check the api docs for full documentation of the api.
Base Tool
The BaseTool is the top level parent of all Tools in Cornerstone Tools. It takes care of initializing the Tool's configuration, applying mixins, and providing @virtual functions for mouse/touch interaction for Active tools.
- Virtual Methods:
preMouseDownCallbackpostMouseDownCallbackpreTouchStartCallbackpostTouchStartCallback
Cursors (Optional)
Any tool may define cursors to replace the mouse cursor when active. This feature is optional. You must set the globalConfigurationModule option showSVGCursors to true to use them. This can be done upon initialization of cornerstoneTools:
cornerstoneTools.init({ showSVGCursors: true });
A tool may implement a single cursor by setting the svgCursor to an MouseCursor object, or by setting a set of cursors per strategy tag:
// ...
cursors: {
FILL_INSIDE: segCircleFillInsideCursor,
FILL_OUTSIDE: segCircleFillOutsideCursor,
ERASE_OUTSIDE: segCircleEraseOutsideCursor,
ERASE_INSIDE: segCircleEraseInsideCursor,
},
// or
svgCursor: segCircleFillInsideCursor,
// ...
If you are using the cursor-by-strategy method implemented by cursors, you do not need to set the default svgCursor, as BaseTool will do this for you.
Base Annotation Tool
The BaseAnnotationTool is an extension of BaseTool for Tools that create and manipulate annotation data.
- Abstract Methods:
createNewMeasurementpointNearTooldistanceFromPointrenderToolData
- Virtual Methods:
mouseMoveCallbackhandleSelectedCallbacktoolSelectedCallbackupdateCachedStats
Base Brush Tool
The BaseBrushTool is an extension of BaseTool for Tools which edit the segmentation module's Labelmap3D data by painting on the canvas. Used for creating and editing segmentations.
Unlike subclasses of BaseAnnotationTool, subclasses of BaseBrushTool don't manage the rendering of their own data. Rendering of the segmentation masks is centralized at src/eventListeners/onImageRenderedBrushEventHandler.js. If a Labelmap2D object exists on a displayed cornerstone image, and either of the segmentation module's renderFill or renderOutline configuration options are true.
- Abstract Methods:
renderBrush_paint
- Virtual Methods:
mouseDragCallbackpreMouseDownCallback_startPainting_endPainting
Segmentation Tools
"Segmentation Tools" are derivatives of BaseTool that interact with the labelmap layer in some way other than by manually brushing, for which you would choose to derive from BaseBrushTool.
Anatomy
Segmentation Tools are more of a modular design pattern rather than a tool type, and so are constructed via composition rather than inheritance.
SegmentationTools are comprised of a few components:
- A Segmentation Mixin - The role of a segmentation mixin is to provide a delineation mechanism, which generates an
operationDataobject which is passed to the active strategy alongside the cornerstone event. - One or more
strategiesto be called when the segmentation mixin callsthis.applyActiveStrategy(evt, operationData). - An (optional) set of
cursorsforstrategies.
Example
Below is an example of a Segementation Tool:
/**
* @public
* @class CircleScissorsTool
* @memberof Tools
* @classdesc Tool for manipulating labelmap data using a circle.
* @extends Tools.Base.BaseTool
*/
export default class CircleScissorsTool extends BaseTool {
/** @inheritdoc */
constructor(props = {}) {
const defaultProps = {
name: 'CircleScissors',
strategies: {
FILL_INSIDE: fillInsideCircle,
FILL_OUTSIDE: fillOutsideCircle,
ERASE_OUTSIDE: eraseOutsideCircle,
ERASE_INSIDE: eraseInsideCircle,
},
cursors: {
FILL_INSIDE: segCircleFillInsideCursor,
FILL_OUTSIDE: segCircleFillOutsideCursor,
ERASE_OUTSIDE: segCircleEraseOutsideCursor,
ERASE_INSIDE: segCircleEraseInsideCursor,
},
defaultStrategy: 'FILL_INSIDE',
supportedInteractionTypes: ['Mouse', 'Touch'],
svgCursor: segCircleFillInsideCursor,
mixins: ['circleSegmentationMixin'],
};
super(props, defaultProps);
}
}
Lets analyse the components unique to segmentation tools:
Segmentation Mixins
// ...
mixins: ['circleSegmentationMixin'];
// ...
The mixins prop can be used as with BaseTool, but at least one segmentation mixin must be used. The job the segmentation mixin is to take user input through some means, implement _applyStrategy, and call the strategy with appropriate input.
Mixin-aware Strategies
// ...
strategies: {
FILL_INSIDE: fillInsideCircle,
FILL_OUTSIDE: fillOutsideCircle,
ERASE_OUTSIDE: eraseOutsideCircle,
ERASE_INSIDE: eraseInsideCircle,
},
// ...
defaultStrategy: 'FILL_INSIDE',
// ...
The strategies prop defines a set of operations that can be executed at the end of delineation. The strategies implemented should expect operationData of the form provided by the segmentation mixin implemented by the Tool.