Merging toolManager, enablePrefetchOnElement and imageViewerViewport...
This commit is contained in:
1 parent
068192e035
commit
00656ef943
4 files changed
+407
-187
No files matched your search
@@ -1,13 +1,33 @@
|
||||
import { Session } from 'meteor/session';
|
||||
import { $ } from 'meteor/jquery';
|
||||
import { OHIF } from 'meteor/ohif:core';
|
||||
import { getFrameOfReferenceUID } from './getFrameOfReferenceUID';
|
||||
import { updateCrosshairsSynchronizer } from './updateCrosshairsSynchronizer';
|
||||
import { crosshairsSynchronizers } from './crosshairsSynchronizers';
|
||||
|
||||
let activeTool = 'wwwc';
|
||||
let defaultTool = 'wwwc';
|
||||
|
||||
let tools = {};
|
||||
|
||||
let gestures = {
|
||||
zoomTouchPinch: {
|
||||
enabled: true
|
||||
},
|
||||
panMultiTouch: {
|
||||
enabled: true
|
||||
},
|
||||
stackScrollMultiTouch: {
|
||||
enabled: true
|
||||
},
|
||||
doubleTapZoom: {
|
||||
enabled: true
|
||||
}
|
||||
};
|
||||
|
||||
let toolDefaultStates = {
|
||||
activate: [],
|
||||
deactivate: ['length', 'angle', 'annotate', 'ellipticalRoi', 'rectangleRoi'],
|
||||
deactivate: ['length', 'angle', 'annotate', 'ellipticalRoi', 'rectangleRoi', 'textMarker'],
|
||||
enable: [],
|
||||
disable: [],
|
||||
disabledToolButtons: [],
|
||||
@@ -21,74 +41,10 @@ let toolDefaultStates = {
|
||||
|
||||
let initialized = false;
|
||||
|
||||
const configureTools = () => {
|
||||
|
||||
// Get Cornerstone Tools
|
||||
const { panMultiTouch, textStyle, toolStyle, toolColors,
|
||||
length, arrowAnnotate, zoom, ellipticalRoi } = cornerstoneTools;
|
||||
|
||||
// Set the configuration for the multitouch pan tool
|
||||
const multiTouchPanConfig = {
|
||||
testPointers: eventData => {
|
||||
return (eventData.numPointers >= 3);
|
||||
}
|
||||
};
|
||||
panMultiTouch.setConfiguration(multiTouchPanConfig);
|
||||
|
||||
// Set text box background color
|
||||
textStyle.setBackgroundColor('transparent');
|
||||
|
||||
// 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);
|
||||
|
||||
// Set the tool width
|
||||
toolStyle.setToolWidth(2);
|
||||
|
||||
// Set color for inactive tools
|
||||
toolColors.setToolColor('rgb(255, 255, 0)');
|
||||
|
||||
// Set color for active tools
|
||||
toolColors.setActiveColor('rgb(0, 255, 0)');
|
||||
|
||||
// Set shadow configuration
|
||||
const shadowConfig = toolManager.getToolDefaultStates().shadowConfig;
|
||||
|
||||
// Get some tools config to not override them
|
||||
const lengthConfig = length.getConfiguration();
|
||||
const ellipticalRoiConfig = ellipticalRoi.getConfiguration();
|
||||
|
||||
// Add shadow to length tool
|
||||
length.setConfiguration({
|
||||
...lengthConfig,
|
||||
...shadowConfig,
|
||||
drawHandlesOnHover: true
|
||||
});
|
||||
|
||||
// Add shadow to length tool
|
||||
ellipticalRoi.setConfiguration({
|
||||
...ellipticalRoiConfig,
|
||||
...shadowConfig
|
||||
});
|
||||
|
||||
// Set the configuration values for the text annotation (Arrow) tool
|
||||
const annotateConfig = {
|
||||
getTextCallback: getAnnotationTextCallback,
|
||||
changeTextCallback: changeAnnotationTextCallback,
|
||||
drawHandles: false,
|
||||
arrowFirst: true
|
||||
};
|
||||
arrowAnnotate.setConfiguration(annotateConfig);
|
||||
|
||||
const zoomConfig = {
|
||||
minScale: 0.05,
|
||||
maxScale: 10
|
||||
};
|
||||
zoom.setConfiguration(zoomConfig);
|
||||
}
|
||||
|
||||
toolManager = {
|
||||
/**
|
||||
* Exported "toolManager" Singleton
|
||||
*/
|
||||
export const toolManager = {
|
||||
init() {
|
||||
toolManager.addTool('wwwc', {
|
||||
mouse: cornerstoneTools.wwwc,
|
||||
@@ -144,13 +100,94 @@ toolManager = {
|
||||
touch: cornerstoneTools.rotateTouchDrag
|
||||
});
|
||||
|
||||
toolManager.addTool('spine', {
|
||||
mouse: cornerstoneTools.textMarker,
|
||||
touch: cornerstoneTools.textMarkerTouch
|
||||
});
|
||||
|
||||
toolManager.addTool('crosshairs', {
|
||||
mouse: cornerstoneTools.crosshairs,
|
||||
touch: cornerstoneTools.crosshairsTouch
|
||||
});
|
||||
|
||||
if (OHIF.viewer.defaultTool) {
|
||||
activeTool = OHIF.viewer.defaultTool;
|
||||
}
|
||||
|
||||
configureTools();
|
||||
this.configureTools();
|
||||
initialized = true;
|
||||
},
|
||||
configureTools() {
|
||||
// Get Cornerstone Tools
|
||||
const { panMultiTouch, textStyle, toolStyle, toolColors,
|
||||
length, arrowAnnotate, zoom, ellipticalRoi } = cornerstoneTools;
|
||||
|
||||
// Set the configuration for the multitouch pan tool
|
||||
const multiTouchPanConfig = {
|
||||
testPointers: eventData => {
|
||||
return (eventData.numPointers >= 3);
|
||||
}
|
||||
};
|
||||
panMultiTouch.setConfiguration(multiTouchPanConfig);
|
||||
|
||||
// Set text box background color
|
||||
textStyle.setBackgroundColor('transparent');
|
||||
|
||||
// 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);
|
||||
|
||||
// Set the tool width
|
||||
toolStyle.setToolWidth(2);
|
||||
|
||||
// Set color for inactive tools
|
||||
toolColors.setToolColor('rgb(255, 255, 0)');
|
||||
|
||||
// Set color for active tools
|
||||
toolColors.setActiveColor('rgb(0, 255, 0)');
|
||||
|
||||
// Set shadow configuration
|
||||
const shadowConfig = toolManager.getToolDefaultStates().shadowConfig;
|
||||
|
||||
// Get some tools config to not override them
|
||||
const lengthConfig = length.getConfiguration();
|
||||
const ellipticalRoiConfig = ellipticalRoi.getConfiguration();
|
||||
|
||||
// Add shadow to length tool
|
||||
length.setConfiguration({
|
||||
...lengthConfig,
|
||||
...shadowConfig,
|
||||
drawHandlesOnHover: true
|
||||
});
|
||||
|
||||
// Add shadow to length tool
|
||||
ellipticalRoi.setConfiguration({
|
||||
...ellipticalRoiConfig,
|
||||
...shadowConfig
|
||||
});
|
||||
|
||||
// Set the configuration values for the text annotation (Arrow) tool
|
||||
const annotateConfig = {
|
||||
getTextCallback: getAnnotationTextCallback,
|
||||
changeTextCallback: changeAnnotationTextCallback,
|
||||
drawHandles: false,
|
||||
arrowFirst: true
|
||||
};
|
||||
arrowAnnotate.setConfiguration(annotateConfig);
|
||||
|
||||
const zoomConfig = {
|
||||
minScale: 0.05,
|
||||
maxScale: 10
|
||||
};
|
||||
zoom.setConfiguration(zoomConfig);
|
||||
},
|
||||
setGestures(newGestures) {
|
||||
gestures = newGestures;
|
||||
},
|
||||
getGestures() {
|
||||
return gestures;
|
||||
},
|
||||
addTool(name, base) {
|
||||
tools[name] = base;
|
||||
},
|
||||
@@ -164,7 +201,7 @@ toolManager = {
|
||||
return toolDefaultStates;
|
||||
},
|
||||
setActiveToolForElement(tool, element) {
|
||||
var canvases = $(element).find('canvas');
|
||||
const canvases = $(element).find('canvas');
|
||||
if (element.classList.contains('empty') || !canvases.length) {
|
||||
return;
|
||||
}
|
||||
@@ -177,12 +214,12 @@ toolManager = {
|
||||
}
|
||||
|
||||
// Enable tools based on their default states
|
||||
Object.keys(toolDefaultStates).forEach(function(action) {
|
||||
var relevantTools = toolDefaultStates[action];
|
||||
Object.keys(toolDefaultStates).forEach( action => {
|
||||
const relevantTools = toolDefaultStates[action];
|
||||
if (!relevantTools || !relevantTools.length || action === 'disabledToolButtons') {
|
||||
return;
|
||||
}
|
||||
relevantTools.forEach(function(toolType) {
|
||||
relevantTools.forEach( toolType => {
|
||||
// the currently active tool has already been deactivated and can be skipped
|
||||
if (action === 'deactivate' && toolType === activeTool) {
|
||||
return;
|
||||
@@ -196,40 +233,75 @@ toolManager = {
|
||||
});
|
||||
|
||||
// Get the stack toolData
|
||||
var toolData = cornerstoneTools.getToolState(element, 'stack');
|
||||
const 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;
|
||||
const 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);
|
||||
cornerstoneTools.panMultiTouch.disable(element);
|
||||
cornerstoneTools.zoomTouchPinch.disable(element);
|
||||
cornerstoneTools.stackScrollMultiTouch.disable(element);
|
||||
cornerstoneTools.doubleTapZoom.disable(element);
|
||||
|
||||
// Reactivate the middle mouse and right click tools
|
||||
cornerstoneTools.zoom.activate(element, 4); // zoom is the default tool for right mouse button
|
||||
|
||||
// Reactivate the relevant scrollwheel tool for this element
|
||||
let multiTouchPanConfig;
|
||||
if (imageIds.length > 1) {
|
||||
// scroll is the default tool for middle mouse wheel for stacks
|
||||
cornerstoneTools.stackScrollWheel.activate(element);
|
||||
|
||||
if (gestures['stackScrollMultiTouch'].enabled === true) {
|
||||
cornerstoneTools.stackScrollMultiTouch.activate(element); // Three finger scroll
|
||||
}
|
||||
|
||||
multiTouchPanConfig = {
|
||||
testPointers(eventData) {
|
||||
return (eventData.numPointers === 2);
|
||||
}
|
||||
};
|
||||
|
||||
cornerstoneTools.panMultiTouch.setConfiguration(multiTouchPanConfig);
|
||||
} else {
|
||||
// zoom is the default tool for middle mouse wheel for single images (non stacks)
|
||||
cornerstoneTools.zoomWheel.activate(element);
|
||||
|
||||
multiTouchPanConfig = {
|
||||
testPointers(eventData) {
|
||||
return (eventData.numPointers >= 2);
|
||||
}
|
||||
};
|
||||
cornerstoneTools.panMultiTouch.setConfiguration(multiTouchPanConfig);
|
||||
}
|
||||
|
||||
// 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 === 'crosshairs') {
|
||||
cornerstoneTools.pan.activate(element, 2); // pan is the default tool for middle mouse button
|
||||
const currentFrameOfReferenceUID = getFrameOfReferenceUID(element);
|
||||
if (currentFrameOfReferenceUID) {
|
||||
updateCrosshairsSynchronizer(currentFrameOfReferenceUID);
|
||||
const synchronizer = crosshairsSynchronizers.synchronizers[currentFrameOfReferenceUID];
|
||||
|
||||
// Activate the chosen tool
|
||||
tools[tool].mouse.activate(element, 1, synchronizer);
|
||||
}
|
||||
} 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);
|
||||
@@ -239,14 +311,45 @@ toolManager = {
|
||||
tools[tool].touch.activate(element);
|
||||
}
|
||||
|
||||
cornerstoneTools.zoomTouchPinch.activate(element);
|
||||
cornerstoneTools.panMultiTouch.activate(element);
|
||||
if (gestures['zoomTouchPinch'].enabled === true) {
|
||||
cornerstoneTools.zoomTouchPinch.activate(element); // Two finger pinch
|
||||
}
|
||||
|
||||
if (gestures['panMultiTouch'].enabled === true) {
|
||||
cornerstoneTools.panMultiTouch.activate(element); // Two or >= Two finger pan
|
||||
}
|
||||
|
||||
if (gestures['doubleTapZoom'].enabled === true) {
|
||||
cornerstoneTools.doubleTapZoom.activate(element);
|
||||
}
|
||||
},
|
||||
setActiveTool(tool, elements) {
|
||||
if (!initialized) {
|
||||
toolManager.init();
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: Add textMarkerDialogs template to OHIF's
|
||||
*/
|
||||
const dialog = document.getElementById('textMarkerOptionsDialog');
|
||||
if(dialog) {
|
||||
if (tool === 'spine' && activeTool !== 'spine' && dialog.getAttribute('open') !== 'open') {
|
||||
dialog.show();
|
||||
} else if(activeTool !== 'spine' && dialog.getAttribute("open") === "open") {
|
||||
dialog.close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: Use Session variables to activate a button and use Helpers like in toolbarSectionButton.js from OHIF’s.
|
||||
*/
|
||||
// Set the div to active for the tool
|
||||
$('.imageViewerButton').removeClass('active');
|
||||
const toolButton = document.getElementById(tool);
|
||||
if (toolButton) {
|
||||
toolButton.classList.add('active');
|
||||
}
|
||||
|
||||
if (!tool) {
|
||||
tool = defaultTool;
|
||||
}
|
||||
@@ -277,6 +380,11 @@ toolManager = {
|
||||
getDefaultTool() {
|
||||
return defaultTool;
|
||||
},
|
||||
setConfigureTools(configureTools) {
|
||||
if(typeof configureTools === 'function') {
|
||||
this.configureTools = configureTools;
|
||||
}
|
||||
},
|
||||
activateCommandButton(button) {
|
||||
const activeCommandButtons = Session.get('ToolManagerActiveCommandButtons') || [];
|
||||
|
||||
@@ -294,5 +402,4 @@ toolManager = {
|
||||
Session.set('ToolManagerActiveCommandButtons', activeCommandButtons);
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
Reference in new issue
Block a user