2016-07-12 20:37:53 +02:00
|
|
|
|
import { OHIF } from 'meteor/ohif:core';
|
|
|
|
|
|
|
2016-06-29 22:39:40 +02:00
|
|
|
|
var activeTool = 'wwwc';
|
|
|
|
|
|
var defaultTool = 'wwwc';
|
2015-10-13 14:14:50 +02:00
|
|
|
|
|
|
|
|
|
|
var tools = {};
|
|
|
|
|
|
|
2015-12-10 11:32:53 +01:00
|
|
|
|
var toolDefaultStates = {
|
|
|
|
|
|
activate: [],
|
2016-08-05 12:16:47 +02:00
|
|
|
|
deactivate: ['length', 'angle', 'annotate', 'ellipticalRoi', 'rectangleRoi'],
|
2015-12-10 11:32:53 +01:00
|
|
|
|
enable: [],
|
2016-03-10 17:21:52 +01:00
|
|
|
|
disable: [],
|
|
|
|
|
|
disabledToolButtons: []
|
2015-12-10 11:32:53 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
2015-10-13 14:14:50 +02:00
|
|
|
|
var initialized = false;
|
|
|
|
|
|
|
|
|
|
|
|
function configureTools() {
|
2016-11-09 22:02:25 +01:00
|
|
|
|
|
|
|
|
|
|
// Get Cornerstone Tools
|
2016-11-11 17:26:13 +01:00
|
|
|
|
const { panMultiTouch, textStyle, toolStyle, toolColors, length,
|
2016-11-14 19:51:02 +01:00
|
|
|
|
bidirectional, arrowAnnotate, zoom, ellipticalRoi, nonTarget } = cornerstoneTools;
|
2016-11-09 22:02:25 +01:00
|
|
|
|
|
2015-10-13 14:14:50 +02:00
|
|
|
|
// Set the configuration for the multitouch pan tool
|
2016-11-09 22:02:25 +01:00
|
|
|
|
const multiTouchPanConfig = {
|
2015-10-13 14:14:50 +02:00
|
|
|
|
testPointers: function(eventData) {
|
|
|
|
|
|
return (eventData.numPointers >= 3);
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
2016-11-09 22:02:25 +01:00
|
|
|
|
panMultiTouch.setConfiguration(multiTouchPanConfig);
|
2016-02-16 15:03:34 +01:00
|
|
|
|
|
2016-11-09 22:02:25 +01:00
|
|
|
|
// Set text box background color
|
|
|
|
|
|
textStyle.setBackgroundColor('transparent');
|
2016-02-16 15:03:34 +01:00
|
|
|
|
|
2016-11-16 12:17:07 +01:00
|
|
|
|
// Set the tool font and font size
|
|
|
|
|
|
// context.font = "[style] [variant] [weight] [size]/[line height] [font family]";
|
|
|
|
|
|
const fontFamily = 'Roboto, OpenSans, HelveticaNeue-Light, Helvetica Neue Light, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif';
|
|
|
|
|
|
textStyle.setFont('15px ' + fontFamily);
|
|
|
|
|
|
|
2016-02-16 15:03:34 +01:00
|
|
|
|
// Set the tool width
|
2016-11-09 22:02:25 +01:00
|
|
|
|
toolStyle.setToolWidth(2);
|
2016-02-16 15:03:34 +01:00
|
|
|
|
|
|
|
|
|
|
// Set color for inactive tools
|
2016-11-16 12:17:07 +01:00
|
|
|
|
toolColors.setToolColor('rgb(255, 255, 0)');
|
2016-02-16 15:03:34 +01:00
|
|
|
|
|
|
|
|
|
|
// Set color for active tools
|
2016-11-16 12:17:07 +01:00
|
|
|
|
toolColors.setActiveColor('rgb(0, 255, 0)');
|
2016-11-09 22:02:25 +01:00
|
|
|
|
|
|
|
|
|
|
// Set shadow configuration for length and bidirectional text boxes
|
|
|
|
|
|
const shadowConfig = {
|
2016-11-16 17:21:30 +01:00
|
|
|
|
shadow: false,
|
2016-11-16 12:17:07 +01:00
|
|
|
|
shadowColor: '#000000',
|
2016-11-16 17:21:30 +01:00
|
|
|
|
shadowOffsetX: 0,
|
|
|
|
|
|
shadowOffsetY: 0
|
2016-11-09 22:02:25 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Get some tools config to not override them
|
2016-11-16 12:17:07 +01:00
|
|
|
|
const lengthConfig = length.getConfiguration();
|
2016-11-09 22:02:25 +01:00
|
|
|
|
const bidirectionalConfig = bidirectional.getConfiguration();
|
2016-11-11 17:26:13 +01:00
|
|
|
|
const ellipticalRoiConfig = ellipticalRoi.getConfiguration();
|
2016-11-14 19:51:02 +01:00
|
|
|
|
const nonTargetConfig = nonTarget.getConfiguration();
|
2016-11-09 22:02:25 +01:00
|
|
|
|
|
2016-11-15 20:22:59 +01:00
|
|
|
|
// Add shadow to length tool
|
2016-11-09 22:02:25 +01:00
|
|
|
|
length.setConfiguration({
|
|
|
|
|
|
...lengthConfig,
|
2016-11-17 16:41:13 +01:00
|
|
|
|
...shadowConfig,
|
|
|
|
|
|
drawHandlesOnHover: true
|
2016-11-09 22:02:25 +01:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// Add shadow to length tool
|
|
|
|
|
|
bidirectional.setConfiguration({
|
|
|
|
|
|
...bidirectionalConfig,
|
|
|
|
|
|
...shadowConfig
|
|
|
|
|
|
});
|
2016-08-05 12:16:47 +02:00
|
|
|
|
|
2016-11-11 17:26:13 +01:00
|
|
|
|
// Add shadow to length tool
|
|
|
|
|
|
ellipticalRoi.setConfiguration({
|
|
|
|
|
|
...ellipticalRoiConfig,
|
|
|
|
|
|
...shadowConfig
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2016-11-14 19:51:02 +01:00
|
|
|
|
// Add shadow to non target tool
|
|
|
|
|
|
nonTarget.setConfiguration({
|
|
|
|
|
|
...nonTargetConfig,
|
|
|
|
|
|
...shadowConfig
|
2016-11-16 12:17:07 +01:00
|
|
|
|
});
|
2016-11-14 19:51:02 +01:00
|
|
|
|
|
2016-08-05 12:16:47 +02:00
|
|
|
|
// Set the configuration values for the text annotation (Arrow) tool
|
2016-08-14 13:03:10 +02:00
|
|
|
|
const annotateConfig = {
|
2016-08-05 12:16:47 +02:00
|
|
|
|
getTextCallback: getAnnotationTextCallback,
|
|
|
|
|
|
changeTextCallback: changeAnnotationTextCallback,
|
|
|
|
|
|
drawHandles: false,
|
|
|
|
|
|
arrowFirst: true
|
|
|
|
|
|
};
|
2016-11-09 22:02:25 +01:00
|
|
|
|
arrowAnnotate.setConfiguration(annotateConfig);
|
2016-08-14 13:03:10 +02:00
|
|
|
|
|
|
|
|
|
|
const zoomConfig = {
|
|
|
|
|
|
minScale: 0.05,
|
|
|
|
|
|
maxScale: 10
|
|
|
|
|
|
};
|
2016-11-09 22:02:25 +01:00
|
|
|
|
zoom.setConfiguration(zoomConfig);
|
2015-10-13 14:14:50 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
toolManager = {
|
|
|
|
|
|
init: function() {
|
|
|
|
|
|
toolManager.addTool('wwwc', {
|
|
|
|
|
|
mouse: cornerstoneTools.wwwc,
|
|
|
|
|
|
touch: cornerstoneTools.wwwcTouchDrag
|
|
|
|
|
|
});
|
|
|
|
|
|
toolManager.addTool('zoom', {
|
|
|
|
|
|
mouse: cornerstoneTools.zoom,
|
|
|
|
|
|
touch: cornerstoneTools.zoomTouchDrag
|
|
|
|
|
|
});
|
|
|
|
|
|
toolManager.addTool('wwwcRegion', {
|
|
|
|
|
|
mouse: cornerstoneTools.wwwcRegion,
|
|
|
|
|
|
touch: cornerstoneTools.wwwcRegionTouch
|
|
|
|
|
|
});
|
|
|
|
|
|
toolManager.addTool('dragProbe', {
|
|
|
|
|
|
mouse: cornerstoneTools.dragProbe,
|
|
|
|
|
|
touch: cornerstoneTools.dragProbeTouch
|
|
|
|
|
|
});
|
|
|
|
|
|
toolManager.addTool('pan', {
|
|
|
|
|
|
mouse: cornerstoneTools.pan,
|
|
|
|
|
|
touch: cornerstoneTools.panTouchDrag
|
|
|
|
|
|
});
|
|
|
|
|
|
toolManager.addTool('stackScroll', {
|
|
|
|
|
|
mouse: cornerstoneTools.stackScroll,
|
|
|
|
|
|
touch: cornerstoneTools.stackScrollTouchDrag
|
|
|
|
|
|
});
|
|
|
|
|
|
toolManager.addTool('length', {
|
|
|
|
|
|
mouse: cornerstoneTools.length,
|
|
|
|
|
|
touch: cornerstoneTools.lengthTouch
|
|
|
|
|
|
});
|
|
|
|
|
|
toolManager.addTool('angle', {
|
|
|
|
|
|
mouse: cornerstoneTools.simpleAngle,
|
|
|
|
|
|
touch: cornerstoneTools.simpleAngleTouch
|
|
|
|
|
|
});
|
|
|
|
|
|
toolManager.addTool('magnify', {
|
|
|
|
|
|
mouse: cornerstoneTools.magnify,
|
|
|
|
|
|
touch: cornerstoneTools.magnifyTouchDrag
|
|
|
|
|
|
});
|
|
|
|
|
|
toolManager.addTool('ellipticalRoi', {
|
|
|
|
|
|
mouse: cornerstoneTools.ellipticalRoi,
|
|
|
|
|
|
touch: cornerstoneTools.ellipticalRoiTouch
|
|
|
|
|
|
});
|
|
|
|
|
|
toolManager.addTool('rectangleRoi', {
|
|
|
|
|
|
mouse: cornerstoneTools.rectangleRoi,
|
|
|
|
|
|
touch: cornerstoneTools.rectangleRoiTouch
|
|
|
|
|
|
});
|
|
|
|
|
|
toolManager.addTool('annotate', {
|
|
|
|
|
|
mouse: cornerstoneTools.arrowAnnotate,
|
|
|
|
|
|
touch: cornerstoneTools.arrowAnnotateTouch
|
|
|
|
|
|
});
|
2015-12-15 16:20:57 +01:00
|
|
|
|
|
2016-11-11 17:26:13 +01:00
|
|
|
|
toolManager.addTool('rotate', {
|
|
|
|
|
|
mouse: cornerstoneTools.rotate,
|
|
|
|
|
|
touch: cornerstoneTools.rotateTouchDrag
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2015-12-15 16:20:57 +01:00
|
|
|
|
if (OHIF.viewer.defaultTool) {
|
|
|
|
|
|
activeTool = OHIF.viewer.defaultTool;
|
|
|
|
|
|
}
|
2015-10-13 14:14:50 +02:00
|
|
|
|
|
|
|
|
|
|
configureTools();
|
|
|
|
|
|
initialized = true;
|
|
|
|
|
|
},
|
|
|
|
|
|
addTool: function(name, base) {
|
|
|
|
|
|
tools[name] = base;
|
|
|
|
|
|
},
|
2015-12-19 04:24:00 +01:00
|
|
|
|
getTools: function() {
|
|
|
|
|
|
return tools;
|
|
|
|
|
|
},
|
2015-12-10 11:32:53 +01:00
|
|
|
|
setToolDefaultStates: function(states) {
|
|
|
|
|
|
toolDefaultStates = states;
|
|
|
|
|
|
},
|
|
|
|
|
|
getToolDefaultStates: function() {
|
|
|
|
|
|
return toolDefaultStates;
|
2015-11-22 12:20:19 +01:00
|
|
|
|
},
|
2015-11-22 17:17:42 +01:00
|
|
|
|
setActiveToolForElement: function(tool, element) {
|
|
|
|
|
|
var canvases = $(element).find('canvas');
|
|
|
|
|
|
if (element.classList.contains('empty') || !canvases.length) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// First, deactivate the current active tool
|
|
|
|
|
|
tools[activeTool].mouse.deactivate(element, 1);
|
2016-11-12 01:22:57 +01:00
|
|
|
|
|
2015-11-22 17:17:42 +01:00
|
|
|
|
if (tools[activeTool].touch) {
|
|
|
|
|
|
tools[activeTool].touch.deactivate(element);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-12-10 11:32:53 +01:00
|
|
|
|
// Enable tools based on their default states
|
|
|
|
|
|
Object.keys(toolDefaultStates).forEach(function(action) {
|
|
|
|
|
|
var relevantTools = toolDefaultStates[action];
|
2016-03-10 17:21:52 +01:00
|
|
|
|
if (!relevantTools || !relevantTools.length || action === 'disabledToolButtons') {
|
2015-12-10 11:32:53 +01:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
relevantTools.forEach(function(toolType) {
|
2016-11-12 01:22:57 +01:00
|
|
|
|
// the currently active tool has already been deactivated and can be skipped
|
|
|
|
|
|
if (action === 'deactivate' && toolType === activeTool) {
|
|
|
|
|
|
return;
|
2015-12-10 11:32:53 +01:00
|
|
|
|
}
|
2016-11-12 01:22:57 +01:00
|
|
|
|
tools[toolType].mouse[action](
|
|
|
|
|
|
element,
|
|
|
|
|
|
(action === 'activate' || action === 'deactivate' ? 1 : void 0)
|
|
|
|
|
|
);
|
2015-12-10 11:32:53 +01:00
|
|
|
|
tools[toolType].touch[action](element);
|
|
|
|
|
|
});
|
2015-11-22 17:17:42 +01:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// Get the stack toolData
|
|
|
|
|
|
var toolData = cornerstoneTools.getToolState(element, 'stack');
|
|
|
|
|
|
if (!toolData || !toolData.data || !toolData.data.length) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Get the imageIds for this element
|
|
|
|
|
|
var imageIds = toolData.data[0].imageIds;
|
|
|
|
|
|
|
|
|
|
|
|
// Deactivate all the middle mouse, right click, and scroll wheel tools
|
|
|
|
|
|
cornerstoneTools.pan.deactivate(element);
|
|
|
|
|
|
cornerstoneTools.zoom.deactivate(element);
|
|
|
|
|
|
cornerstoneTools.zoomWheel.deactivate(element);
|
|
|
|
|
|
cornerstoneTools.stackScrollWheel.deactivate(element);
|
|
|
|
|
|
|
|
|
|
|
|
// Reactivate the relevant scrollwheel tool for this element
|
|
|
|
|
|
if (imageIds.length > 1) {
|
|
|
|
|
|
// scroll is the default tool for middle mouse wheel for stacks
|
|
|
|
|
|
cornerstoneTools.stackScrollWheel.activate(element);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
// zoom is the default tool for middle mouse wheel for single images (non stacks)
|
|
|
|
|
|
cornerstoneTools.zoomWheel.activate(element);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// This block ensures that the middle mouse and scroll tools keep working
|
|
|
|
|
|
if (tool === 'pan') {
|
|
|
|
|
|
cornerstoneTools.pan.activate(element, 3); // 3 means left mouse button and middle mouse button
|
|
|
|
|
|
cornerstoneTools.zoom.activate(element, 4); // zoom is the default tool for right mouse button
|
|
|
|
|
|
} else if (tool === 'zoom') {
|
|
|
|
|
|
cornerstoneTools.pan.activate(element, 2); // pan is the default tool for middle mouse button
|
|
|
|
|
|
cornerstoneTools.zoom.activate(element, 5); // 5 means left mouse button and right mouse button
|
|
|
|
|
|
} else {
|
|
|
|
|
|
// Reactivate the middle mouse and right click tools
|
|
|
|
|
|
cornerstoneTools.pan.activate(element, 2); // pan is the default tool for middle mouse button
|
|
|
|
|
|
cornerstoneTools.zoom.activate(element, 4); // zoom is the default tool for right mouse button
|
|
|
|
|
|
|
|
|
|
|
|
// Activate the chosen tool
|
|
|
|
|
|
tools[tool].mouse.activate(element, 1);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (tools[tool].touch) {
|
|
|
|
|
|
tools[tool].touch.activate(element);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
cornerstoneTools.zoomTouchPinch.activate(element);
|
|
|
|
|
|
cornerstoneTools.panMultiTouch.activate(element);
|
|
|
|
|
|
},
|
|
|
|
|
|
setActiveTool: function(tool, elements) {
|
2015-10-13 14:14:50 +02:00
|
|
|
|
if (!initialized) {
|
|
|
|
|
|
toolManager.init();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-12-11 17:55:19 +01:00
|
|
|
|
if (!tool) {
|
|
|
|
|
|
tool = defaultTool;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-12-09 15:48:24 +01:00
|
|
|
|
if (!elements || !elements.length) {
|
|
|
|
|
|
elements = $('.imageViewerViewport');
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-11-22 17:17:42 +01:00
|
|
|
|
// Otherwise, set the active tool for all viewport elements
|
|
|
|
|
|
$(elements).each(function(index, element) {
|
|
|
|
|
|
toolManager.setActiveToolForElement(tool, element);
|
2015-10-13 14:14:50 +02:00
|
|
|
|
});
|
|
|
|
|
|
activeTool = tool;
|
2016-06-29 22:39:40 +02:00
|
|
|
|
|
|
|
|
|
|
// Store the active tool in the session in order to enable reactivity
|
|
|
|
|
|
Session.set('ToolManagerActiveTool', tool);
|
2015-10-13 14:14:50 +02:00
|
|
|
|
},
|
|
|
|
|
|
getActiveTool: function() {
|
|
|
|
|
|
if (!activeTool) {
|
2015-12-09 15:48:24 +01:00
|
|
|
|
activeTool = defaultTool;
|
2015-10-13 14:14:50 +02:00
|
|
|
|
}
|
2016-06-29 22:39:40 +02:00
|
|
|
|
|
2015-10-13 14:14:50 +02:00
|
|
|
|
return activeTool;
|
|
|
|
|
|
},
|
|
|
|
|
|
setDefaultTool: function(tool) {
|
2015-12-09 15:48:24 +01:00
|
|
|
|
defaultTool = tool;
|
2015-10-13 14:14:50 +02:00
|
|
|
|
},
|
|
|
|
|
|
getDefaultTool: function() {
|
2015-12-09 15:48:24 +01:00
|
|
|
|
return defaultTool;
|
2015-10-13 14:14:50 +02:00
|
|
|
|
}
|
2016-03-10 17:21:52 +01:00
|
|
|
|
|
2015-10-13 14:14:50 +02:00
|
|
|
|
};
|