Fixing cornerstone tools issues
This commit is contained in:
1 parent
dc767e5c83
commit
797b2f5588
12 files changed
+183
-192
No files matched your search
@@ -5,7 +5,7 @@ import { cornerstone, cornerstoneMath, cornerstoneTools } from 'meteor/ohif:corn
|
||||
const toolDefaultStates = Viewerbase.toolManager.getToolDefaultStates();
|
||||
const textBoxConfig = toolDefaultStates.textBoxConfig;
|
||||
|
||||
var configuration = {
|
||||
const configuration = {
|
||||
getMeasurementLocationCallback,
|
||||
changeMeasurementLocationCallback,
|
||||
drawHandles: false,
|
||||
@@ -15,27 +15,21 @@ var configuration = {
|
||||
};
|
||||
|
||||
// Used to cancel tool placement
|
||||
var keys = {
|
||||
ESC: 27
|
||||
};
|
||||
const keys = { ESC: 27 };
|
||||
|
||||
// Define a callback to get your text annotation
|
||||
// This could be used, e.g. to open a modal
|
||||
function getMeasurementLocationCallback(measurementData, eventData, doneCallback) {
|
||||
doneCallback(prompt('Enter your lesion location:'));
|
||||
doneCallback(window.prompt('Enter your lesion location:'));
|
||||
}
|
||||
|
||||
function changeMeasurementLocationCallback(measurementData, eventData, doneCallback) {
|
||||
doneCallback(prompt('Change your lesion location:'));
|
||||
doneCallback(window.prompt('Change your lesion location:'));
|
||||
}
|
||||
|
||||
|
||||
function createQualitativeTargetTool(toolType, responseText='') {
|
||||
var toolInterface = {
|
||||
toolType: toolType
|
||||
};
|
||||
|
||||
var response = responseText;
|
||||
const toolInterface = { toolType };
|
||||
const response = responseText;
|
||||
|
||||
/// --- Mouse Tool --- ///
|
||||
///////// BEGIN ACTIVE TOOL ///////
|
||||
@@ -51,8 +45,8 @@ function createQualitativeTargetTool(toolType, responseText='') {
|
||||
const measurementData = createNewMeasurement(mouseEventData);
|
||||
measurementData.viewport = cornerstone.getViewport(element);
|
||||
|
||||
const eventData = { mouseButtonMask: mouseEventData.which };
|
||||
const config = cornerstoneTools[toolType].getConfiguration();
|
||||
const tool = cornerstoneTools[toolType];
|
||||
const config = tool.getConfiguration();
|
||||
|
||||
// associate this data with this imageId so we can render it and manipulate it
|
||||
cornerstoneTools.addToolState(element, toolType, measurementData);
|
||||
@@ -60,10 +54,10 @@ function createQualitativeTargetTool(toolType, responseText='') {
|
||||
const disableDefaultHandlers = () => {
|
||||
// since we are dragging to another place to drop the end point, we can just activate
|
||||
// the end point and let the moveHandle move it for us.
|
||||
$element.off('CornerstoneToolsMouseMove', cornerstoneTools[toolType].mouseMoveCallback);
|
||||
$element.off('CornerstoneToolsMouseDown', cornerstoneTools[toolType].mouseDownCallback);
|
||||
$element.off('CornerstoneToolsMouseDownActivate', cornerstoneTools[toolType].mouseDownActivateCallback);
|
||||
$element.off('CornerstoneToolsMouseDoubleClick', doubleClickCallback);
|
||||
element.removeEventListener('cornerstonetoolsmousemove', tool.mouseMoveCallback);
|
||||
element.removeEventListener('cornerstonetoolsmousedown', tool.mouseDownCallback);
|
||||
element.removeEventListener('cornerstonetoolsmousedownactivate', tool.mouseDownActivateCallback);
|
||||
element.removeEventListener('cornerstonetoolsmousedoubleclick', doubleClickCallback);
|
||||
};
|
||||
|
||||
disableDefaultHandlers();
|
||||
@@ -116,10 +110,10 @@ function createQualitativeTargetTool(toolType, responseText='') {
|
||||
};
|
||||
|
||||
// Bind the event listener for image rendering
|
||||
$element.on('cornerstoneimagerendered', imageRenderedHandler);
|
||||
element.addEventListener('cornerstoneimagerendered', imageRenderedHandler);
|
||||
|
||||
// Bind the tool deactivation and enlargement handlers
|
||||
$element.on('CornerstoneToolsToolDeactivated', cancelAction);
|
||||
element.addEventListener('cornerstonetoolstooldeactivated', cancelAction);
|
||||
$element.one('ohif.viewer.viewport.toggleEnlargement', cancelAction);
|
||||
|
||||
cornerstone.updateImage(element);
|
||||
@@ -139,37 +133,37 @@ function createQualitativeTargetTool(toolType, responseText='') {
|
||||
$element.off('mousedown', mousedownHandler);
|
||||
|
||||
// Unbind the event listener for image rendering
|
||||
$element.off('cornerstoneimagerendered', imageRenderedHandler);
|
||||
element.removeEventListener('cornerstoneimagerendered', imageRenderedHandler);
|
||||
|
||||
// Unbind the tool deactivation and enlargement handlers
|
||||
$element.off('CornerstoneToolsToolDeactivated', cancelAction);
|
||||
element.removeEventListener('cornerstonetoolstooldeactivated', cancelAction);
|
||||
$element.off('ohif.viewer.viewport.toggleEnlargement', cancelAction);
|
||||
|
||||
// Disable the default handlers and re-enable again
|
||||
disableDefaultHandlers();
|
||||
$element.on('CornerstoneToolsMouseMove', eventData, cornerstoneTools[toolType].mouseMoveCallback);
|
||||
$element.on('CornerstoneToolsMouseDown', eventData, cornerstoneTools[toolType].mouseDownCallback);
|
||||
$element.on('CornerstoneToolsMouseDownActivate', eventData, cornerstoneTools[toolType].mouseDownActivateCallback);
|
||||
$element.on('CornerstoneToolsMouseDoubleClick', eventData, doubleClickCallback);
|
||||
element.addEventListener('cornerstonetoolsmousemove', tool.mouseMoveCallback);
|
||||
element.addEventListener('cornerstonetoolsmousedown', tool.mouseDownCallback);
|
||||
element.addEventListener('cornerstonetoolsmousedownactivate', tool.mouseDownActivateCallback);
|
||||
element.addEventListener('cornerstonetoolsmousedoubleclick', doubleClickCallback);
|
||||
|
||||
cornerstone.updateImage(element);
|
||||
});
|
||||
}
|
||||
|
||||
function createNewMeasurement(mouseEventData) {
|
||||
var imageId = mouseEventData.image.imageId;
|
||||
const imageId = mouseEventData.image.imageId;
|
||||
|
||||
// Get studyInstanceUid
|
||||
var study = cornerstone.metaData.get('study', imageId);
|
||||
var studyInstanceUid = study.studyInstanceUid;
|
||||
var patientId = study.patientId;
|
||||
const study = cornerstone.metaData.get('study', imageId);
|
||||
const studyInstanceUid = study.studyInstanceUid;
|
||||
const patientId = study.patientId;
|
||||
|
||||
// Get seriesInstanceUid
|
||||
var series = cornerstone.metaData.get('series', imageId);
|
||||
var seriesInstanceUid = series.seriesInstanceUid;
|
||||
const series = cornerstone.metaData.get('series', imageId);
|
||||
const seriesInstanceUid = series.seriesInstanceUid;
|
||||
|
||||
// create the measurement data for this tool with the end handle activated
|
||||
var measurementData = {
|
||||
const measurementData = {
|
||||
isCreating: true,
|
||||
visible: true,
|
||||
active: true,
|
||||
@@ -212,11 +206,11 @@ function createQualitativeTargetTool(toolType, responseText='') {
|
||||
///////// END ACTIVE TOOL ///////
|
||||
|
||||
function pointNearTool(element, data, coords) {
|
||||
var lineSegment = {
|
||||
const lineSegment = {
|
||||
start: cornerstone.pixelToCanvas(element, data.handles.start),
|
||||
end: cornerstone.pixelToCanvas(element, data.handles.end)
|
||||
};
|
||||
var distanceToPoint = cornerstoneMath.lineSegment.distanceToPoint(lineSegment, coords);
|
||||
const distanceToPoint = cornerstoneMath.lineSegment.distanceToPoint(lineSegment, coords);
|
||||
|
||||
if (cornerstoneTools.pointInsideBoundingBox(data.handles.textBox, coords)) {
|
||||
return true;
|
||||
@@ -227,9 +221,9 @@ function createQualitativeTargetTool(toolType, responseText='') {
|
||||
|
||||
function drawDottedArrow(context, start, end, color, lineWidth) {
|
||||
//variables to be used when creating the arrow
|
||||
var headLength = 10;
|
||||
const headLength = 10;
|
||||
|
||||
var angle = Math.atan2(end.y - start.y, end.x - start.x);
|
||||
const angle = Math.atan2(end.y - start.y, end.x - start.x);
|
||||
|
||||
//starting path of the arrow from the start square to the end square and drawing the stroke
|
||||
context.beginPath();
|
||||
@@ -263,24 +257,22 @@ function createQualitativeTargetTool(toolType, responseText='') {
|
||||
///////// BEGIN IMAGE RENDERING ///////
|
||||
function onImageRendered(e) {
|
||||
const eventData = e.detail;
|
||||
var element = eventData.element;
|
||||
const { element } = eventData;
|
||||
|
||||
// if we have no toolData for this element, return immediately as there is nothing to do
|
||||
var toolData = cornerstoneTools.getToolState(element, toolType);
|
||||
if (!toolData) {
|
||||
return;
|
||||
}
|
||||
const toolData = cornerstoneTools.getToolState(element, toolType);
|
||||
if (!toolData) return;
|
||||
|
||||
// we have tool data for this element - iterate over each one and draw it
|
||||
var context = eventData.canvasContext.canvas.getContext('2d');
|
||||
const context = eventData.canvasContext.canvas.getContext('2d');
|
||||
context.setTransform(1, 0, 0, 1, 0, 0);
|
||||
|
||||
var color;
|
||||
var lineWidth = cornerstoneTools.toolStyle.getToolWidth();
|
||||
var config = cornerstoneTools[toolType].getConfiguration();
|
||||
let color;
|
||||
const lineWidth = cornerstoneTools.toolStyle.getToolWidth();
|
||||
const config = cornerstoneTools[toolType].getConfiguration();
|
||||
|
||||
for (var i = 0; i < toolData.data.length; i++) {
|
||||
var data = toolData.data[i];
|
||||
for (let i = 0; i < toolData.data.length; i++) {
|
||||
const data = toolData.data[i];
|
||||
|
||||
context.save();
|
||||
|
||||
@@ -298,9 +290,9 @@ function createQualitativeTargetTool(toolType, responseText='') {
|
||||
}
|
||||
|
||||
// Draw the arrow
|
||||
var handleStartCanvas = cornerstone.pixelToCanvas(element, data.handles.start);
|
||||
var handleEndCanvas = cornerstone.pixelToCanvas(element, data.handles.end);
|
||||
var canvasTextLocation = cornerstone.pixelToCanvas(element, data.handles.textBox);
|
||||
const handleStartCanvas = cornerstone.pixelToCanvas(element, data.handles.start);
|
||||
const handleEndCanvas = cornerstone.pixelToCanvas(element, data.handles.end);
|
||||
const canvasTextLocation = cornerstone.pixelToCanvas(element, data.handles.textBox);
|
||||
|
||||
drawDottedArrow(context, handleEndCanvas, handleStartCanvas, color, lineWidth);
|
||||
|
||||
@@ -314,9 +306,9 @@ function createQualitativeTargetTool(toolType, responseText='') {
|
||||
|
||||
// Draw the text
|
||||
if (data.measurementNumber) {
|
||||
var textLines = [`Target ${data.measurementNumber}`, response];
|
||||
const textLines = [`Target ${data.measurementNumber}`, response];
|
||||
|
||||
var boundingBox = cornerstoneTools.drawTextBox(
|
||||
const boundingBox = cornerstoneTools.drawTextBox(
|
||||
context,
|
||||
textLines,
|
||||
canvasTextLocation.x,
|
||||
@@ -330,24 +322,24 @@ function createQualitativeTargetTool(toolType, responseText='') {
|
||||
OHIF.cornerstone.repositionTextBox(eventData, data, config.textBox);
|
||||
|
||||
// Draw linked line as dashed
|
||||
var link = {
|
||||
const link = {
|
||||
start: {},
|
||||
end: {}
|
||||
};
|
||||
|
||||
var midpointCanvas = {
|
||||
const midpointCanvas = {
|
||||
x: (handleStartCanvas.x + handleEndCanvas.x) / 2,
|
||||
y: (handleStartCanvas.y + handleEndCanvas.y) / 2,
|
||||
};
|
||||
|
||||
var points = [ handleStartCanvas, handleEndCanvas, midpointCanvas ];
|
||||
const points = [ handleStartCanvas, handleEndCanvas, midpointCanvas ];
|
||||
|
||||
link.end.x = canvasTextLocation.x;
|
||||
link.end.y = canvasTextLocation.y;
|
||||
|
||||
link.start = cornerstoneMath.point.findClosestPoint(points, link.end);
|
||||
|
||||
var boundingBoxPoints = [ {
|
||||
const boundingBoxPoints = [ {
|
||||
// Top middle point of bounding box
|
||||
x: boundingBox.left + boundingBox.width / 2,
|
||||
y: boundingBox.top
|
||||
@@ -385,19 +377,20 @@ function createQualitativeTargetTool(toolType, responseText='') {
|
||||
|
||||
///////// BEGIN ACTIVE TOOL ///////
|
||||
function addNewMeasurementTouch(touchEventData) {
|
||||
var element = touchEventData.element;
|
||||
const { element } = touchEventData;
|
||||
|
||||
function doneCallback() {
|
||||
measurementData.active = true;
|
||||
cornerstone.updateImage(element);
|
||||
}
|
||||
|
||||
var measurementData = createNewMeasurement(touchEventData);
|
||||
const measurementData = createNewMeasurement(touchEventData);
|
||||
cornerstoneTools.addToolState(element, toolType, measurementData);
|
||||
$(element).off('CornerstoneToolsTouchDrag', cornerstoneTools[toolType + "Touch"].touchMoveHandle);
|
||||
$(element).off('CornerstoneToolsDragStartActive', cornerstoneTools[toolType + "Touch"].touchDownActivateCallback);
|
||||
$(element).off('CornerstoneToolsTap', cornerstoneTools[toolType + "Touch"].tapCallback);
|
||||
var config = cornerstoneTools[toolType].getConfiguration();
|
||||
const touchTool = cornerstoneTools[toolType + 'Touch'];
|
||||
element.removeEventListener('cornerstonetoolstouchdrag', touchTool.touchMoveHandle);
|
||||
element.removeEventListener('cornerstonetoolsdragstartactive', touchTool.touchDownActivateCallback);
|
||||
element.removeEventListener('cornerstonetoolstap', touchTool.tapCallback);
|
||||
const config = cornerstoneTools[toolType].getConfiguration();
|
||||
|
||||
cornerstone.updateImage(element);
|
||||
|
||||
@@ -411,16 +404,16 @@ function createQualitativeTargetTool(toolType, responseText='') {
|
||||
|
||||
config.getMeasurementLocationCallback(measurementData, touchEventData, doneCallback);
|
||||
|
||||
$(element).on('CornerstoneToolsTouchDrag', cornerstoneTools[toolType + "Touch"].touchMoveHandle);
|
||||
$(element).on('CornerstoneToolsDragStartActive', cornerstoneTools[toolType + "Touch"].touchDownActivateCallback);
|
||||
$(element).on('CornerstoneToolsTap', cornerstoneTools[toolType + "Touch"].tapCallback);
|
||||
element.addEventListener('cornerstonetoolstouchdrag', touchTool.touchMoveHandle);
|
||||
element.addEventListener('cornerstonetoolsdragstartactive', touchTool.touchDownActivateCallback);
|
||||
element.addEventListener('cornerstonetoolstap', touchTool.tapCallback);
|
||||
});
|
||||
}
|
||||
|
||||
function doubleClickCallback(e) {
|
||||
const eventData = e.detail;
|
||||
var element = eventData.element;
|
||||
var data;
|
||||
const { element } = eventData;
|
||||
let data;
|
||||
|
||||
function doneCallback(data, deleteTool) {
|
||||
if (deleteTool === true) {
|
||||
@@ -437,17 +430,17 @@ function createQualitativeTargetTool(toolType, responseText='') {
|
||||
return false;
|
||||
}
|
||||
|
||||
var config = cornerstoneTools[toolType].getConfiguration();
|
||||
const config = cornerstoneTools[toolType].getConfiguration();
|
||||
|
||||
var coords = eventData.currentPoints.canvas;
|
||||
var toolData = cornerstoneTools.getToolState(element, toolType);
|
||||
const coords = eventData.currentPoints.canvas;
|
||||
const toolData = cornerstoneTools.getToolState(element, toolType);
|
||||
|
||||
// now check to see if there is a handle we can move
|
||||
if (!toolData) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (var i = 0; i < toolData.data.length; i++) {
|
||||
for (let i = 0; i < toolData.data.length; i++) {
|
||||
data = toolData.data[i];
|
||||
if (pointNearTool(element, data, coords)) {
|
||||
data.active = true;
|
||||
@@ -461,7 +454,6 @@ function createQualitativeTargetTool(toolType, responseText='') {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
toolInterface.mouse = cornerstoneTools.mouseButtonTool({
|
||||
addNewMeasurement: addNewMeasurement,
|
||||
createNewMeasurement: createNewMeasurement,
|
||||
@@ -483,12 +475,12 @@ function createQualitativeTargetTool(toolType, responseText='') {
|
||||
return toolInterface;
|
||||
}
|
||||
|
||||
var targetCRInterface = createQualitativeTargetTool('targetCR', 'CR');
|
||||
const targetCRInterface = createQualitativeTargetTool('targetCR', 'CR');
|
||||
cornerstoneTools.targetCR = targetCRInterface.mouse;
|
||||
cornerstoneTools.targetCR.setConfiguration(configuration);
|
||||
cornerstoneTools.targetCRTouch = targetCRInterface.touch;
|
||||
|
||||
var targetUNInterface = createQualitativeTargetTool('targetUN', 'UN');
|
||||
const targetUNInterface = createQualitativeTargetTool('targetUN', 'UN');
|
||||
cornerstoneTools.targetUN = targetUNInterface.mouse;
|
||||
cornerstoneTools.targetUN.setConfiguration(configuration);
|
||||
cornerstoneTools.targetUNTouch = targetUNInterface.touch;
|
||||
|
||||
Reference in new issue
Block a user