src/tools/toolOptions.jsjavascript
import {ArrowFactory} from './shapes/arrow.js';
import {CircleFactory} from './shapes/circle.js';
import {EllipseFactory} from './shapes/ellipse.js';
import {ProtractorFactory} from './shapes/protractor.js';
import {RectangleFactory} from './shapes/rectangle.js';
import {RoiFactory} from './shapes/roi.js';
import {RulerFactory} from './shapes/ruler.js';
import {BidimensionalFactory} from './shapes/bidimensional.js';
import {Threshold, Sobel, Sharpen} from './filter.js';
/**
* List of client provided tool options to be added to
* the default ones.
*
* @example
* import {App, AppOptions, ViewConfig, toolOptions, ROI, Point2D}
* from '//esm.sh/dwv';
* // custom factory
* class LoveFactory {
* getName() {return 'love';}
* static supports(mathShape) {return mathShape instanceof ROI;}
* getNPoints() {return 1;}
* setAnnotationMathShape(annotation, points) {
* const px = points[0].getX();
* const py = points[0].getY();
* annotation.mathShape = new ROI([
* new Point2D(px+15,py), new Point2D(px+10,py-10),
* new Point2D(px,py), new Point2D(px-10,py-10),
* new Point2D(px-15,py), new Point2D(px,py+20)
* ]);
* annotation.getFactory = function () {return new LoveFactory();}
* }
* createShapeGroup(annotation, style) {
* const roi = annotation.mathShape;
* // konva line
* const arr = [];
* for (let i = 0; i < roi.getLength(); ++i) {
* arr.push(roi.getPoint(i).getX());
* arr.push(roi.getPoint(i).getY());
* }
* const shape = new Konva.Line({
* name: 'shape', points: arr,
* stroke: 'red', strokeWidth: 2,
* closed: true
* });
* // konva group
* const group = new Konva.Group();
* group.name('love-group');
* group.visible(true);
* group.id(annotation.trackingUid);
* group.add(shape);
* return group;
* }
* }
* // pass it to dwv option list
* toolOptions['draw'] = {LoveFactory};
* // create the dwv app
* const app = new App();
* // initialise
* const viewConfig0 = new ViewConfig('layerGroup0');
* const viewConfigs = {'*': [viewConfig0]};
* const options = new AppOptions(viewConfigs);
* options.tools = {Draw: {options: ['Love']}};
* app.init(options);
* // activate tool
* app.addEventListener('load', function () {
* app.setTool('Draw');
* app.setToolFeatures({shapeName: 'Love'});
* });
* // load dicom data
* app.loadURLs([
* 'https://raw.githubusercontent.com/ivmartel/dwv/master/tests/data/bbmri-53323851.dcm'
* ]);
*
* @type {Record<string, Record<string, any>>}
*/
export const toolOptions = {};
/**
* Default tool options.
*
* @type {Record<string, Record<string, any>>}
*/
export const defaultToolOptions = {
draw: {
ArrowFactory,
CircleFactory,
EllipseFactory,
ProtractorFactory,
RectangleFactory,
RoiFactory,
RulerFactory,
BidimensionalFactory
},
filter: {
Threshold,
Sobel,
Sharpen
}
};