Switch toolState usage since ES6 modules are read-only
This commit is contained in:
1 parent
ddef3c4710
commit
27296a8bca
12 files changed
+308
-309
No files matched your search
@@ -1,99 +1,93 @@
|
||||
import { Viewerbase } from 'meteor/ohif:viewerbase';
|
||||
|
||||
(function(cornerstoneTools) {
|
||||
// Delete a lesion if Ctrl+D or DELETE is pressed while a lesion is selected
|
||||
var keys = {
|
||||
D: 68,
|
||||
DELETE: 46
|
||||
};
|
||||
|
||||
'use strict';
|
||||
|
||||
// Delete a lesion if Ctrl+D or DELETE is pressed while a lesion is selected
|
||||
var keys = {
|
||||
D: 68,
|
||||
DELETE: 46
|
||||
};
|
||||
|
||||
function removeMeasurementTimepoint(data, index, toolType, element) {
|
||||
var imageId = data.imageId;
|
||||
if (!imageId) {
|
||||
var enabledElement = cornerstone.getEnabledElement(element);
|
||||
imageId = enabledElement.image.imageId;
|
||||
}
|
||||
|
||||
cornerstoneTools.removeToolState(element, toolType, data);
|
||||
cornerstone.updateImage(element);
|
||||
function removeMeasurementTimepoint(data, index, toolType, element) {
|
||||
var imageId = data.imageId;
|
||||
if (!imageId) {
|
||||
var enabledElement = cornerstone.getEnabledElement(element);
|
||||
imageId = enabledElement.image.imageId;
|
||||
}
|
||||
|
||||
// TODO = Check if we have the same function already in Cornerstone Tools
|
||||
function getNearbyToolData(element, coords, toolTypes) {
|
||||
var allTools = Viewerbase.toolManager.getTools();
|
||||
var pointNearTool = false;
|
||||
var touchDevice = Viewerbase.helpers.isTouchDevice();
|
||||
var nearbyTool = {},
|
||||
nearbyToolIndex,
|
||||
nearbyToolType;
|
||||
cornerstoneTools.removeToolState(element, toolType, data);
|
||||
cornerstone.updateImage(element);
|
||||
}
|
||||
|
||||
toolTypes.forEach(function(toolType) {
|
||||
var toolData = cornerstoneTools.getToolState(element, toolType);
|
||||
if (!toolData) {
|
||||
return;
|
||||
// TODO = Check if we have the same function already in Cornerstone Tools
|
||||
function getNearbyToolData(element, coords, toolTypes) {
|
||||
var allTools = Viewerbase.toolManager.getTools();
|
||||
var pointNearTool = false;
|
||||
var touchDevice = Viewerbase.helpers.isTouchDevice();
|
||||
var nearbyTool = {},
|
||||
nearbyToolIndex,
|
||||
nearbyToolType;
|
||||
|
||||
toolTypes.forEach(function(toolType) {
|
||||
var toolData = cornerstoneTools.getToolState(element, toolType);
|
||||
if (!toolData) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (var i = 0; i < toolData.data.length; i++) {
|
||||
var data = toolData.data[i];
|
||||
|
||||
var toolInterface;
|
||||
if (touchDevice) {
|
||||
toolInterface = allTools[toolType].touch;
|
||||
} else {
|
||||
toolInterface = allTools[toolType].mouse;
|
||||
}
|
||||
|
||||
for (var i = 0; i < toolData.data.length; i++) {
|
||||
var data = toolData.data[i];
|
||||
|
||||
var toolInterface;
|
||||
if (touchDevice) {
|
||||
toolInterface = allTools[toolType].touch;
|
||||
} else {
|
||||
toolInterface = allTools[toolType].mouse;
|
||||
}
|
||||
|
||||
if (toolInterface.pointNearTool(element, data, coords)) {
|
||||
pointNearTool = true;
|
||||
nearbyTool.tool = data;
|
||||
nearbyTool.index = i;
|
||||
nearbyTool.toolType = toolType;
|
||||
break;
|
||||
}
|
||||
if (toolInterface.pointNearTool(element, data, coords)) {
|
||||
pointNearTool = true;
|
||||
nearbyTool.tool = data;
|
||||
nearbyTool.index = i;
|
||||
nearbyTool.toolType = toolType;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (pointNearTool === true) {
|
||||
return false;
|
||||
}
|
||||
if (pointNearTool === true) {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
return pointNearTool ? nearbyTool : undefined;
|
||||
}
|
||||
|
||||
function keyDownCallback(e, eventData) {
|
||||
var keyCode = eventData.which;
|
||||
|
||||
if (keyCode === keys.DELETE ||
|
||||
(keyCode === keys.D && eventData.event.ctrlKey === true)) {
|
||||
|
||||
var toolTypes = [ 'bidirectional', 'nonTarget', 'length', 'targetCR', 'targetUN', 'targetEX'];
|
||||
var nearbyToolData = getNearbyToolData(eventData.element, eventData.currentPoints.canvas, toolTypes);
|
||||
|
||||
if (!nearbyToolData) {
|
||||
return;
|
||||
}
|
||||
|
||||
const dialogSettings = {
|
||||
title: 'Delete measurements',
|
||||
message: 'Are you sure you want to delete this measurement?'
|
||||
};
|
||||
|
||||
// TODO= Refactor this so the confirmation dialog is an
|
||||
// optional settable callback in the tool's configuration
|
||||
OHIF.ui.showDialog('dialogConfirm', dialogSettings).then(() => {
|
||||
removeMeasurementTimepoint(nearbyToolData.tool,
|
||||
nearbyToolData.index,
|
||||
nearbyToolData.toolType,
|
||||
eventData.element
|
||||
);
|
||||
});
|
||||
|
||||
return pointNearTool ? nearbyTool : undefined;
|
||||
}
|
||||
}
|
||||
|
||||
function keyDownCallback(e, eventData) {
|
||||
var keyCode = eventData.which;
|
||||
|
||||
if (keyCode === keys.DELETE ||
|
||||
(keyCode === keys.D && eventData.event.ctrlKey === true)) {
|
||||
|
||||
var toolTypes = [ 'bidirectional', 'nonTarget', 'length', 'targetCR', 'targetUN', 'targetEX'];
|
||||
var nearbyToolData = getNearbyToolData(eventData.element, eventData.currentPoints.canvas, toolTypes);
|
||||
|
||||
if (!nearbyToolData) {
|
||||
return;
|
||||
}
|
||||
|
||||
const dialogSettings = {
|
||||
title: 'Delete measurements',
|
||||
message: 'Are you sure you want to delete this measurement?'
|
||||
};
|
||||
|
||||
// TODO= Refactor this so the confirmation dialog is an
|
||||
// optional settable callback in the tool's configuration
|
||||
OHIF.ui.showDialog('dialogConfirm', dialogSettings).then(() => {
|
||||
removeMeasurementTimepoint(nearbyToolData.tool,
|
||||
nearbyToolData.index,
|
||||
nearbyToolData.toolType,
|
||||
eventData.element
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// module/private exports
|
||||
cornerstoneTools.deleteLesionKeyboardTool = cornerstoneTools.keyboardTool(keyDownCallback);
|
||||
|
||||
})(cornerstoneTools);
|
||||
// module/private exports
|
||||
cornerstoneTools.deleteLesionKeyboardTool = cornerstoneTools.keyboardTool(keyDownCallback);
|
||||
@@ -1,229 +1,222 @@
|
||||
function drawLine(context, startPoint, endPoint, config) {
|
||||
context.moveTo(startPoint.x, startPoint.y);
|
||||
context.lineTo(endPoint.x, endPoint.y);
|
||||
}
|
||||
|
||||
(function($, cornerstone, cornerstoneTools) {
|
||||
function drawVerticalScalebarIntervals (context, config) {
|
||||
let i = 0;
|
||||
|
||||
'use strict';
|
||||
while (config.verticalLine.start.y + i * config.verticalMinorTick <= config.vscaleBounds.bottomRight.y) {
|
||||
|
||||
function drawLine(context, startPoint, endPoint, config) {
|
||||
context.moveTo(startPoint.x, startPoint.y);
|
||||
context.lineTo(endPoint.x, endPoint.y);
|
||||
}
|
||||
|
||||
function drawVerticalScalebarIntervals (context, config) {
|
||||
let i = 0;
|
||||
|
||||
while (config.verticalLine.start.y + i * config.verticalMinorTick <= config.vscaleBounds.bottomRight.y) {
|
||||
|
||||
const startPoint = {
|
||||
x: config.verticalLine.start.x,
|
||||
y: config.verticalLine.start.y + i * config.verticalMinorTick
|
||||
};
|
||||
|
||||
const endPoint = {
|
||||
x: 0,
|
||||
y: config.verticalLine.start.y + i * config.verticalMinorTick
|
||||
};
|
||||
if (i % 5 === 0) {
|
||||
|
||||
endPoint.x = config.verticalLine.start.x - config.majorTickLength;
|
||||
} else {
|
||||
|
||||
endPoint.x = config.verticalLine.start.x - config.minorTickLength;
|
||||
}
|
||||
|
||||
drawLine(context, startPoint, endPoint, config);
|
||||
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
function drawHorizontalScalebarIntervals (context, config) {
|
||||
let i = 0;
|
||||
|
||||
while (config.horizontalLine.start.x + i * config.horizontalMinorTick <= config.hscaleBounds.bottomRight.x) {
|
||||
|
||||
const startPoint = {
|
||||
x: config.horizontalLine.start.x + i * config.horizontalMinorTick,
|
||||
y: config.horizontalLine.start.y
|
||||
};
|
||||
|
||||
const endPoint = {
|
||||
x: config.horizontalLine.start.x + i * config.horizontalMinorTick,
|
||||
y: 0
|
||||
};
|
||||
|
||||
if (i % 5 === 0) {
|
||||
endPoint.y = config.horizontalLine.start.y - config.majorTickLength;
|
||||
} else {
|
||||
endPoint.y = config.horizontalLine.start.y - config.minorTickLength;
|
||||
}
|
||||
|
||||
drawLine(context, startPoint, endPoint, config);
|
||||
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
function drawVerticalScalebar(context, config) {
|
||||
const startPoint = {
|
||||
x: config.verticalLine.start.x,
|
||||
y: config.verticalLine.start.y
|
||||
};
|
||||
const endPoint = {
|
||||
x: config.verticalLine.end.x,
|
||||
y: config.verticalLine.end.y
|
||||
y: config.verticalLine.start.y + i * config.verticalMinorTick
|
||||
};
|
||||
|
||||
context.beginPath();
|
||||
context.strokeStyle = config.color;
|
||||
context.lineWidth = config.lineWidth;
|
||||
const endPoint = {
|
||||
x: 0,
|
||||
y: config.verticalLine.start.y + i * config.verticalMinorTick
|
||||
};
|
||||
if (i % 5 === 0) {
|
||||
|
||||
endPoint.x = config.verticalLine.start.x - config.majorTickLength;
|
||||
} else {
|
||||
|
||||
endPoint.x = config.verticalLine.start.x - config.minorTickLength;
|
||||
}
|
||||
|
||||
drawLine(context, startPoint, endPoint, config);
|
||||
drawVerticalScalebarIntervals(context, config);
|
||||
|
||||
context.stroke();
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
function drawHorizontalScalebarIntervals (context, config) {
|
||||
let i = 0;
|
||||
|
||||
while (config.horizontalLine.start.x + i * config.horizontalMinorTick <= config.hscaleBounds.bottomRight.x) {
|
||||
|
||||
function drawHorizontalScalebar(context, config) {
|
||||
const startPoint = {
|
||||
x: config.horizontalLine.start.x,
|
||||
x: config.horizontalLine.start.x + i * config.horizontalMinorTick,
|
||||
y: config.horizontalLine.start.y
|
||||
};
|
||||
|
||||
const endPoint = {
|
||||
x: config.horizontalLine.end.x,
|
||||
y: config.horizontalLine.end.y
|
||||
x: config.horizontalLine.start.x + i * config.horizontalMinorTick,
|
||||
y: 0
|
||||
};
|
||||
|
||||
if (i % 5 === 0) {
|
||||
endPoint.y = config.horizontalLine.start.y - config.majorTickLength;
|
||||
} else {
|
||||
endPoint.y = config.horizontalLine.start.y - config.minorTickLength;
|
||||
}
|
||||
|
||||
drawLine(context, startPoint, endPoint, config);
|
||||
drawHorizontalScalebarIntervals(context, config);
|
||||
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
function drawVerticalScalebar(context, config) {
|
||||
const startPoint = {
|
||||
x: config.verticalLine.start.x,
|
||||
y: config.verticalLine.start.y
|
||||
};
|
||||
const endPoint = {
|
||||
x: config.verticalLine.end.x,
|
||||
y: config.verticalLine.end.y
|
||||
};
|
||||
|
||||
context.beginPath();
|
||||
context.strokeStyle = config.color;
|
||||
context.lineWidth = config.lineWidth;
|
||||
|
||||
drawLine(context, startPoint, endPoint, config);
|
||||
drawVerticalScalebarIntervals(context, config);
|
||||
|
||||
context.stroke();
|
||||
}
|
||||
|
||||
function drawHorizontalScalebar(context, config) {
|
||||
const startPoint = {
|
||||
x: config.horizontalLine.start.x,
|
||||
y: config.horizontalLine.start.y
|
||||
};
|
||||
const endPoint = {
|
||||
x: config.horizontalLine.end.x,
|
||||
y: config.horizontalLine.end.y
|
||||
};
|
||||
|
||||
drawLine(context, startPoint, endPoint, config);
|
||||
drawHorizontalScalebarIntervals(context, config);
|
||||
}
|
||||
|
||||
function drawScalebars(context, config){
|
||||
context.shadowColor = config.shadowColor;
|
||||
context.shadowBlur = config.shadowBlur;
|
||||
context.strokeStyle = config.color;
|
||||
context.lineWidth = config.lineWidth;
|
||||
|
||||
context.beginPath();
|
||||
drawVerticalScalebar(context, config);
|
||||
drawHorizontalScalebar(context, config);
|
||||
context.stroke();
|
||||
}
|
||||
|
||||
// Computes the max bound for scales on the image
|
||||
function computeScaleBounds(eventData, canvasSize, imageSize, horizontalReduction, verticalReduction) {
|
||||
|
||||
let canvasBounds = {
|
||||
left: 0,
|
||||
top: 0,
|
||||
width: canvasSize.width,
|
||||
height: canvasSize.height
|
||||
};
|
||||
|
||||
const hReduction = horizontalReduction * Math.min(1000, canvasSize.width);
|
||||
const vReduction = verticalReduction * Math.min(1000, canvasSize.height);
|
||||
canvasBounds = {
|
||||
left: canvasBounds.left + hReduction,
|
||||
top: canvasBounds.top + vReduction,
|
||||
width: canvasBounds.width - 2 * hReduction,
|
||||
height: canvasBounds.height - 2 * vReduction
|
||||
};
|
||||
|
||||
return {
|
||||
topLeft: {
|
||||
x: canvasBounds.left,
|
||||
y: canvasBounds.top
|
||||
},
|
||||
bottomRight: {
|
||||
x: canvasBounds.left + canvasBounds.width,
|
||||
y: canvasBounds.top + canvasBounds.height
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function onImageRendered(e, eventData) {
|
||||
|
||||
// Check whether pixel spacing is defined
|
||||
if (!eventData.image.rowPixelSpacing || !eventData.image.columnPixelSpacing) {
|
||||
return;
|
||||
}
|
||||
|
||||
function drawScalebars(context, config){
|
||||
context.shadowColor = config.shadowColor;
|
||||
context.shadowBlur = config.shadowBlur;
|
||||
context.strokeStyle = config.color;
|
||||
context.lineWidth = config.lineWidth;
|
||||
|
||||
context.beginPath();
|
||||
drawVerticalScalebar(context, config);
|
||||
drawHorizontalScalebar(context, config);
|
||||
context.stroke();
|
||||
const viewport = cornerstone.getViewport(eventData.enabledElement.element);
|
||||
if (!viewport) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Computes the max bound for scales on the image
|
||||
function computeScaleBounds(eventData, canvasSize, imageSize, horizontalReduction, verticalReduction) {
|
||||
const canvasSize = {
|
||||
width: eventData.enabledElement.canvas.width,
|
||||
height: eventData.enabledElement.canvas.height
|
||||
};
|
||||
const imageSize = {
|
||||
width: eventData.enabledElement.image.width ,
|
||||
height: eventData.enabledElement.image.height
|
||||
};
|
||||
|
||||
let canvasBounds = {
|
||||
left: 0,
|
||||
top: 0,
|
||||
width: canvasSize.width,
|
||||
height: canvasSize.height
|
||||
};
|
||||
// Distance between intervals is 10mm
|
||||
const verticalIntervalScale = (10.0 / eventData.enabledElement.image.rowPixelSpacing) * eventData.viewport.scale;
|
||||
const horizontalIntervalScale = (10.0 / eventData.enabledElement.image.rowPixelSpacing) * eventData.viewport.scale;
|
||||
|
||||
const hReduction = horizontalReduction * Math.min(1000, canvasSize.width);
|
||||
const vReduction = verticalReduction * Math.min(1000, canvasSize.height);
|
||||
canvasBounds = {
|
||||
left: canvasBounds.left + hReduction,
|
||||
top: canvasBounds.top + vReduction,
|
||||
width: canvasBounds.width - 2 * hReduction,
|
||||
height: canvasBounds.height - 2 * vReduction
|
||||
};
|
||||
// 0.1 and 0.05 gives margin to horizontal and vertical lines
|
||||
const hscaleBounds = computeScaleBounds(eventData, canvasSize, imageSize, 0.25, 0.05);
|
||||
const vscaleBounds = computeScaleBounds(eventData, canvasSize, imageSize, 0.05, 0.15);
|
||||
|
||||
return {
|
||||
topLeft: {
|
||||
x: canvasBounds.left,
|
||||
y: canvasBounds.top
|
||||
if (!canvasSize.width || !canvasSize.height || !imageSize.width || !imageSize.height || !hscaleBounds || !vscaleBounds) {
|
||||
return;
|
||||
}
|
||||
|
||||
const config = {
|
||||
hscaleBounds,
|
||||
vscaleBounds,
|
||||
verticalMinorTick: verticalIntervalScale,
|
||||
horizontalMinorTick: horizontalIntervalScale,
|
||||
minorTickLength: 12.5,
|
||||
majorTickLength: 25,
|
||||
verticalLine: {
|
||||
start: {
|
||||
x: vscaleBounds.bottomRight.x,
|
||||
y: vscaleBounds.topLeft.y
|
||||
},
|
||||
bottomRight: {
|
||||
x: canvasBounds.left + canvasBounds.width,
|
||||
y: canvasBounds.top + canvasBounds.height
|
||||
end: {
|
||||
x: vscaleBounds.bottomRight.x,
|
||||
y: vscaleBounds.bottomRight.y
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function onImageRendered(e, eventData) {
|
||||
|
||||
// Check whether pixel spacing is defined
|
||||
if (!eventData.image.rowPixelSpacing || !eventData.image.columnPixelSpacing) {
|
||||
return;
|
||||
}
|
||||
|
||||
const viewport = cornerstone.getViewport(eventData.enabledElement.element);
|
||||
if (!viewport) {
|
||||
return;
|
||||
}
|
||||
|
||||
const canvasSize = {
|
||||
width: eventData.enabledElement.canvas.width,
|
||||
height: eventData.enabledElement.canvas.height
|
||||
};
|
||||
const imageSize = {
|
||||
width: eventData.enabledElement.image.width ,
|
||||
height: eventData.enabledElement.image.height
|
||||
};
|
||||
|
||||
// Distance between intervals is 10mm
|
||||
const verticalIntervalScale = (10.0 / eventData.enabledElement.image.rowPixelSpacing) * eventData.viewport.scale;
|
||||
const horizontalIntervalScale = (10.0 / eventData.enabledElement.image.rowPixelSpacing) * eventData.viewport.scale;
|
||||
|
||||
// 0.1 and 0.05 gives margin to horizontal and vertical lines
|
||||
const hscaleBounds = computeScaleBounds(eventData, canvasSize, imageSize, 0.25, 0.05);
|
||||
const vscaleBounds = computeScaleBounds(eventData, canvasSize, imageSize, 0.05, 0.15);
|
||||
|
||||
if (!canvasSize.width || !canvasSize.height || !imageSize.width || !imageSize.height || !hscaleBounds || !vscaleBounds) {
|
||||
return;
|
||||
}
|
||||
|
||||
const config = {
|
||||
hscaleBounds: hscaleBounds,
|
||||
vscaleBounds: vscaleBounds,
|
||||
verticalMinorTick: verticalIntervalScale,
|
||||
horizontalMinorTick: horizontalIntervalScale,
|
||||
minorTickLength: 12.5,
|
||||
majorTickLength: 25,
|
||||
verticalLine: {
|
||||
start: {
|
||||
x: vscaleBounds.bottomRight.x,
|
||||
y: vscaleBounds.topLeft.y
|
||||
},
|
||||
end: {
|
||||
x: vscaleBounds.bottomRight.x,
|
||||
y: vscaleBounds.bottomRight.y
|
||||
}
|
||||
},
|
||||
horizontalLine: {
|
||||
start: {
|
||||
x: hscaleBounds.topLeft.x,
|
||||
y: hscaleBounds.bottomRight.y
|
||||
},
|
||||
horizontalLine: {
|
||||
start: {
|
||||
x: hscaleBounds.topLeft.x,
|
||||
y: hscaleBounds.bottomRight.y
|
||||
},
|
||||
end: {
|
||||
x: hscaleBounds.bottomRight.x,
|
||||
y: hscaleBounds.bottomRight.y
|
||||
}
|
||||
},
|
||||
color: 'white', // TODO: fix this later
|
||||
lineWidth: cornerstoneTools.toolStyle.getToolWidth(),
|
||||
shadowColor: 'black',
|
||||
shadowBlur: 4
|
||||
};
|
||||
end: {
|
||||
x: hscaleBounds.bottomRight.x,
|
||||
y: hscaleBounds.bottomRight.y
|
||||
}
|
||||
},
|
||||
color: 'white', // TODO: fix this later
|
||||
lineWidth: cornerstoneTools.toolStyle.getToolWidth(),
|
||||
shadowColor: 'black',
|
||||
shadowBlur: 4
|
||||
};
|
||||
|
||||
const context = eventData.enabledElement.canvas.getContext('2d');
|
||||
context.setTransform(1, 0, 0, 1, 0, 0);
|
||||
context.save();
|
||||
const context = eventData.enabledElement.canvas.getContext('2d');
|
||||
context.setTransform(1, 0, 0, 1, 0, 0);
|
||||
context.save();
|
||||
|
||||
drawScalebars(context, config);
|
||||
context.restore();
|
||||
}
|
||||
drawScalebars(context, config);
|
||||
context.restore();
|
||||
}
|
||||
|
||||
///////// END IMAGE RENDERING ///////
|
||||
///////// END IMAGE RENDERING ///////
|
||||
|
||||
function disable(element) {
|
||||
// TODO: displayTool does not have cornerstone.updateImage(element) method to hide tool
|
||||
$(element).off('CornerstoneImageRendered', onImageRendered);
|
||||
cornerstone.updateImage(element);
|
||||
}
|
||||
function disable(element) {
|
||||
// TODO: displayTool does not have cornerstone.updateImage(element) method to hide tool
|
||||
$(element).off('CornerstoneImageRendered', onImageRendered);
|
||||
cornerstone.updateImage(element);
|
||||
}
|
||||
|
||||
// module exports
|
||||
cornerstoneTools.scaleOverlayTool = cornerstoneTools.displayTool(onImageRendered);
|
||||
cornerstoneTools.scaleOverlayTool.disable = disable;
|
||||
|
||||
})($, cornerstone, cornerstoneTools);
|
||||
// module exports
|
||||
cornerstoneTools.scaleOverlayTool = cornerstoneTools.displayTool(onImageRendered);
|
||||
cornerstoneTools.scaleOverlayTool.disable = disable;
|
||||
Reference in new issue
Block a user