nonTarget tool is added
This commit is contained in:
parent
02a5b2fc53
commit
db21685473
@ -3,4 +3,8 @@ Meteor.startup(function() {
|
||||
mouse: cornerstoneTools.lesion,
|
||||
touch: cornerstoneTools.lesionTouch
|
||||
});
|
||||
toolManager.addTool('nonTarget', {
|
||||
mouse: cornerstoneTools.nonTarget,
|
||||
touch: cornerstoneTools.nonTargetTouch
|
||||
});
|
||||
});
|
||||
@ -1,6 +1,8 @@
|
||||
<template name="viewer">
|
||||
<div id="viewer">
|
||||
{{ >lesionDialog }}
|
||||
{{ >nonTargetLesionDialog}}
|
||||
|
||||
{{ >hidingPanel }}
|
||||
<div id="viewportAndLesionTable">
|
||||
{{ >viewerMain }}
|
||||
|
||||
@ -53,6 +53,13 @@ Template.viewerMain.helpers({
|
||||
iconClasses: 'fa fa-arrows-alt'
|
||||
});
|
||||
|
||||
buttonData.push({
|
||||
id: 'nonTarget',
|
||||
title: 'Non-Target Tool',
|
||||
classes: 'imageViewerTool',
|
||||
iconClasses: 'fa fa-arrows-v'
|
||||
});
|
||||
|
||||
toolbarOptions.buttonData = buttonData;
|
||||
toolbarOptions.includePlayClipButton = false;
|
||||
toolbarOptions.includeLayoutButton = false;
|
||||
|
||||
@ -831,7 +831,7 @@ if (typeof cornerstoneTools === 'undefined') {
|
||||
|
||||
//TODO: ayselafsar
|
||||
//Check hover event for lesion tool text
|
||||
if (mouseToolInterface.toolType === "lesion") {
|
||||
if (mouseToolInterface.toolType === "lesion" || mouseToolInterface.toolType === "nonTarget") {
|
||||
if ( mouseToolInterface.pointNearToolForText(eventData.element, data, coords) && !data.active) {
|
||||
data.active = !data.active;
|
||||
}
|
||||
|
||||
@ -14,7 +14,7 @@ var cornerstoneTools = (function($, cornerstone, cornerstoneMath, cornerstoneToo
|
||||
function createNewMeasurement(mouseEventData) {
|
||||
var element = mouseEventData.element;
|
||||
timepointID = $(element).data('timepointID');
|
||||
var lesionNumber = measurementManagerDAL.getNewLesionNumber(timepointID);
|
||||
var lesionNumber = measurementManagerDAL.getNewLesionNumber(timepointID, true);
|
||||
var lesionCounter = "";
|
||||
|
||||
// Subscribe CornerstoneMouseup event, when mouse is up, call lesionDialog
|
||||
@ -78,6 +78,7 @@ var cornerstoneTools = (function($, cornerstone, cornerstoneMath, cornerstoneToo
|
||||
lesionName: "Target " + lesionNumber,
|
||||
isDeleted: false,
|
||||
lesionNumber: lesionNumber,
|
||||
isTarget: true,
|
||||
uid: uuid.v4()
|
||||
};
|
||||
return measurementData;
|
||||
@ -253,6 +254,7 @@ var cornerstoneTools = (function($, cornerstone, cornerstoneMath, cornerstoneToo
|
||||
var start = new Date();
|
||||
|
||||
var enabledElement = eventObject.enabledElement;
|
||||
var isTarget = eventObject.isTarget;
|
||||
var lesionNumber = eventObject.lesionData.lesionNumber;
|
||||
var type = eventObject.type;
|
||||
|
||||
|
||||
@ -41,7 +41,7 @@ var measurementManagerDAL = (function() {
|
||||
// Add real mesurement
|
||||
timepointObject = {
|
||||
longestDiameter: lesionData.measurementText,
|
||||
imageId: lesionData.imageId
|
||||
imageId: lesionData.imageId,
|
||||
};
|
||||
} else {
|
||||
// Add null measurement
|
||||
@ -54,8 +54,9 @@ var measurementManagerDAL = (function() {
|
||||
}
|
||||
|
||||
var lesionDataObject = {
|
||||
lesionUID: uuid.v4(),
|
||||
lesionNumber: lesionData.lesionNumber,
|
||||
isTarget: true,
|
||||
isTarget: typeof lesionData.isTarget !== 'undefined'?lesionData.isTarget:true,
|
||||
locationUID: lesionData.locationUID,
|
||||
location: getLocationName(lesionData.locationUID),
|
||||
timepoints: timepointsObject
|
||||
@ -65,9 +66,13 @@ var measurementManagerDAL = (function() {
|
||||
|
||||
// Update timepoint data in Measurements collection
|
||||
function updateTimepointData(lesionData) {
|
||||
if(typeof lesionData.isTarget === 'undefined') {
|
||||
lesionData.isTarget = true;
|
||||
}
|
||||
// Find the specific lesion to be updated
|
||||
var measurement = Measurements.find({
|
||||
lesionNumber: lesionData.lesionNumber
|
||||
lesionNumber: lesionData.lesionNumber,
|
||||
isTarget: lesionData.isTarget
|
||||
}).fetch()[0];
|
||||
|
||||
// If no such lesion exists, stop here
|
||||
@ -84,7 +89,8 @@ var measurementManagerDAL = (function() {
|
||||
timepoints[timepointID].imageId = lesionData.imageId;
|
||||
|
||||
Measurements.update({
|
||||
lesionNumber: lesionData.lesionNumber
|
||||
lesionNumber: lesionData.lesionNumber,
|
||||
isTarget: lesionData.isTarget
|
||||
}, {
|
||||
$set: {
|
||||
timepoints: timepoints
|
||||
@ -93,9 +99,10 @@ var measurementManagerDAL = (function() {
|
||||
}
|
||||
|
||||
// Check timepointData is found in Measurements collection
|
||||
function timepointDataIsFound(lesionNumber) {
|
||||
function timepointDataIsFound(lesionData) {
|
||||
var timepointData = Measurements.findOne({
|
||||
lesionNumber: lesionNumber
|
||||
lesionNumber: lesionData.lesionNumber,
|
||||
isTarget: typeof lesionData.isTarget!== 'undefined'?lesionData.isTarget:true
|
||||
});
|
||||
if (timepointData) {
|
||||
return true;
|
||||
@ -115,9 +122,13 @@ var measurementManagerDAL = (function() {
|
||||
}
|
||||
|
||||
// Returns new lesion number according to timepointID
|
||||
function getNewLesionNumber(timepointID) {
|
||||
function getNewLesionNumber(timepointID, isTarget) {
|
||||
|
||||
if (typeof isTarget === 'undefined') {
|
||||
isTarget = true;
|
||||
}
|
||||
// Get all current lesion measurements
|
||||
var measurements = Measurements.find().fetch();
|
||||
var measurements = Measurements.find({isTarget: isTarget}).fetch();
|
||||
|
||||
// If no measurements exist yet, start at 1
|
||||
if (!measurements.length) {
|
||||
@ -137,29 +148,34 @@ var measurementManagerDAL = (function() {
|
||||
lesionNumberCounter = lesionNumberCounter + 1;
|
||||
}
|
||||
}
|
||||
console.log(lesionNumberCounter + 1);
|
||||
return lesionNumberCounter + 1;
|
||||
}
|
||||
|
||||
// If lesion number is added for any timepoint, returns lesion locationUID
|
||||
function isLesionNumberAdded(lesionNumber) {
|
||||
if (!timepointDataIsFound(lesionNumber)) {
|
||||
function isLesionNumberAdded(lesionData) {
|
||||
if (!timepointDataIsFound(lesionData)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(typeof isTarget === undefined) {
|
||||
isTarget = true;
|
||||
}
|
||||
var measurement = Measurements.find({
|
||||
lesionNumber: lesionNumber
|
||||
lesionNumber: lesionData.lesionNumber,
|
||||
isTarget: lesionData.isTarget
|
||||
}).fetch()[0];
|
||||
|
||||
return measurement.locationUID;
|
||||
}
|
||||
|
||||
|
||||
return {
|
||||
addNewLocation: addPatientLocation,
|
||||
getLocations: getPatientLocations,
|
||||
addLesionData: addLesionData,
|
||||
getNewLesionNumber: getNewLesionNumber,
|
||||
isLesionNumberAdded: isLesionNumberAdded,
|
||||
updateTimepointData: updateTimepointData
|
||||
updateTimepointData: updateTimepointData,
|
||||
getLocationName: getLocationName
|
||||
};
|
||||
})();
|
||||
509
Packages/lesiontracker/compatibility/nonTargetTool.js
Normal file
509
Packages/lesiontracker/compatibility/nonTargetTool.js
Normal file
@ -0,0 +1,509 @@
|
||||
// Begin Source: src/imageTools/annotation.js
|
||||
(function($, cornerstone, cornerstoneMath, cornerstoneTools) {
|
||||
|
||||
'use strict';
|
||||
|
||||
var toolType = 'nonTarget';
|
||||
|
||||
// Define a callback to get your text annotation
|
||||
// This could be used, e.g. to open a modal
|
||||
function getTextCallback(doneChangingTextCallback) {
|
||||
doneChangingTextCallback(prompt('Enter your annotation:'));
|
||||
}
|
||||
|
||||
function changeTextCallback(data, doneChangingTextCallback) {
|
||||
doneChangingTextCallback(prompt('Change your annotation:'));
|
||||
}
|
||||
|
||||
|
||||
var configuration = {
|
||||
getTextCallback: getTextCallback,
|
||||
changeTextCallback: changeTextCallback,
|
||||
drawHandles: false,
|
||||
drawHandlesOnHover: true,
|
||||
arrowFirst: true
|
||||
};
|
||||
|
||||
/// --- Mouse Tool --- ///
|
||||
///////// BEGIN ACTIVE TOOL ///////
|
||||
function addNewMeasurement(mouseEventData) {
|
||||
|
||||
function doneChangingTextCallback(text) {
|
||||
if (text !== null) {
|
||||
measurementData.text = text;
|
||||
} else {
|
||||
cornerstoneTools.removeToolState(mouseEventData.element, toolType, measurementData);
|
||||
}
|
||||
|
||||
measurementData.active = false;
|
||||
cornerstone.updateImage(mouseEventData.element);
|
||||
}
|
||||
|
||||
var measurementData = createNewMeasurement(mouseEventData);
|
||||
|
||||
var eventData = {
|
||||
mouseButtonMask: mouseEventData.which
|
||||
};
|
||||
|
||||
// associate this data with this imageId so we can render it and manipulate it
|
||||
cornerstoneTools.addToolState(mouseEventData.element, toolType, measurementData);
|
||||
|
||||
// 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.
|
||||
$(mouseEventData.element).off('CornerstoneToolsMouseMove', cornerstoneTools.nonTarget.mouseMoveCallback);
|
||||
$(mouseEventData.element).off('CornerstoneToolsMouseDown', cornerstoneTools.nonTarget.mouseDownCallback);
|
||||
$(mouseEventData.element).off('CornerstoneToolsMouseDownActivate', cornerstoneTools.nonTarget.mouseDownActivateCallback);
|
||||
|
||||
cornerstone.updateImage(mouseEventData.element);
|
||||
cornerstoneTools.moveNewHandle(mouseEventData, measurementData.handles.end, function() {
|
||||
if (cornerstoneTools.anyHandlesOutsideImage(mouseEventData, measurementData.handles)) {
|
||||
// delete the measurement
|
||||
cornerstoneTools.removeToolState(mouseEventData.element, toolType, measurementData);
|
||||
}
|
||||
|
||||
var config = cornerstoneTools.nonTarget.getConfiguration();
|
||||
if (measurementData.text === undefined) {
|
||||
config.getTextCallback(doneChangingTextCallback);
|
||||
}
|
||||
|
||||
$(mouseEventData.element).on('CornerstoneToolsMouseMove', eventData, cornerstoneTools.nonTarget.mouseMoveCallback);
|
||||
|
||||
// CornerstoneToolsMouseDown Event
|
||||
$(mouseEventData.element).on('CornerstoneToolsMouseDown', eventData, cornerstoneTools.nonTarget.mouseDownCallback);
|
||||
$(mouseEventData.element).on('CornerstoneToolsMouseDownActivate', eventData, cornerstoneTools.nonTarget.mouseDownActivateCallback);
|
||||
|
||||
cornerstone.updateImage(mouseEventData.element);
|
||||
});
|
||||
}
|
||||
|
||||
function createNewMeasurement(mouseEventData) {
|
||||
// create the measurement data for this tool with the end handle activated
|
||||
// TODO: Get text from measurements collection
|
||||
// Subscribe CornerstoneMouseup event, when mouse is up, call lesionDialog
|
||||
$(mouseEventData.element).on("CornerstoneToolsMouseUp", function (e) {
|
||||
// Unsubscribe CornerstoneToolsMouseUp event
|
||||
$(mouseEventData.element).off("CornerstoneToolsMouseUp");
|
||||
$(mouseEventData.element).trigger("NonTargetToolAdded", [e, measurementData]);
|
||||
|
||||
});
|
||||
var timepointID = $(mouseEventData.element).data('timepointID');
|
||||
var lesionNumber = measurementManagerDAL.getNewLesionNumber(timepointID, false);
|
||||
|
||||
var measurementData = {
|
||||
visible: true,
|
||||
active: true,
|
||||
handles: {
|
||||
start: {
|
||||
x: mouseEventData.currentPoints.image.x,
|
||||
y: mouseEventData.currentPoints.image.y,
|
||||
highlight: true,
|
||||
active: false
|
||||
},
|
||||
end: {
|
||||
x: mouseEventData.currentPoints.image.x,
|
||||
y: mouseEventData.currentPoints.image.y,
|
||||
highlight: true,
|
||||
active: false
|
||||
}
|
||||
},
|
||||
linkedTextCoords: {
|
||||
start: {
|
||||
x: mouseEventData.currentPoints.image.x,
|
||||
y: mouseEventData.currentPoints.image.y,
|
||||
highlight: true,
|
||||
active: false
|
||||
},
|
||||
end: {
|
||||
x: mouseEventData.currentPoints.image.x,
|
||||
y: mouseEventData.currentPoints.image.y,
|
||||
highlight: true,
|
||||
active: true
|
||||
},
|
||||
init: false
|
||||
},
|
||||
imageId: mouseEventData.image.imageId,
|
||||
lesionNumber: lesionNumber,
|
||||
text: "Non-Target " + lesionNumber,
|
||||
isTarget: false
|
||||
};
|
||||
|
||||
return measurementData;
|
||||
}
|
||||
///////// END ACTIVE TOOL ///////
|
||||
|
||||
function pointNearTool(element, data, coords) {
|
||||
var lineSegment = {
|
||||
start: cornerstone.pixelToCanvas(element, data.handles.start),
|
||||
end: cornerstone.pixelToCanvas(element, data.handles.end)
|
||||
};
|
||||
|
||||
var distanceToPoint = cornerstoneMath.lineSegment.distanceToPoint(lineSegment, coords);
|
||||
return (distanceToPoint < 25);
|
||||
}
|
||||
|
||||
function pointNearToolForText(element, data, coords) {
|
||||
var lineSegment = {
|
||||
start: cornerstone.pixelToCanvas(element, data.linkedTextCoords.start),
|
||||
end: cornerstone.pixelToCanvas(element, data.linkedTextCoords.end)
|
||||
};
|
||||
|
||||
var distanceToPoint = cornerstoneMath.lineSegment.distanceToPoint(lineSegment, coords);
|
||||
return (distanceToPoint < 30);
|
||||
}
|
||||
|
||||
function drawArrow(context, start, end, color, lineWidth) {
|
||||
//variables to be used when creating the arrow
|
||||
var headLength = 10;
|
||||
|
||||
var 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();
|
||||
context.moveTo(start.x, start.y);
|
||||
context.lineTo(end.x, end.y);
|
||||
context.strokeStyle = color;
|
||||
context.lineWidth = lineWidth;
|
||||
context.stroke();
|
||||
|
||||
//starting a new path from the head of the arrow to one of the sides of the point
|
||||
context.beginPath();
|
||||
context.moveTo(end.x, end.y);
|
||||
context.lineTo(end.x - headLength * Math.cos(angle - Math.PI / 7), end.y - headLength * Math.sin(angle - Math.PI / 7));
|
||||
|
||||
//path from the side point of the arrow, to the other side point
|
||||
context.lineTo(end.x - headLength * Math.cos(angle + Math.PI / 7), end.y - headLength * Math.sin(angle + Math.PI / 7));
|
||||
|
||||
//path from the side point back to the tip of the arrow, and then again to the opposite side point
|
||||
context.lineTo(end.x, end.y);
|
||||
context.lineTo(end.x - headLength * Math.cos(angle - Math.PI / 7), end.y - headLength * Math.sin(angle - Math.PI / 7));
|
||||
|
||||
//draws the paths created above
|
||||
context.strokeStyle = color;
|
||||
context.lineWidth = lineWidth;
|
||||
context.stroke();
|
||||
context.fillStyle = color;
|
||||
context.fill();
|
||||
}
|
||||
|
||||
function suscribenonTargetToolModifiedEvent(element) {
|
||||
var elementEvents = $._data(element, "events");
|
||||
var index = Object.keys(elementEvents).indexOf("nonTargetToolModified");
|
||||
if (index < 0) {
|
||||
// Subscribe LesionToolModified and calls measurementModified function when lesion measurement is changed or updated.
|
||||
$(element).on("nonTargetToolModified", measurementModified);
|
||||
}
|
||||
|
||||
}
|
||||
///////// BEGIN IMAGE RENDERING ///////
|
||||
function onImageRendered(e, eventData) {
|
||||
|
||||
suscribenonTargetToolModifiedEvent(e.currentTarget);
|
||||
|
||||
// if we have no toolData for this element, return immediately as there is nothing to do
|
||||
var toolData = cornerstoneTools.getToolState(e.currentTarget, toolType);
|
||||
if (toolData === undefined) {
|
||||
return;
|
||||
}
|
||||
|
||||
// we have tool data for this element - iterate over each one and draw it
|
||||
var context = eventData.canvasContext.canvas.getContext('2d');
|
||||
context.setTransform(1, 0, 0, 1, 0, 0);
|
||||
|
||||
var color;
|
||||
var lineWidth = cornerstoneTools.toolStyle.getToolWidth();
|
||||
var font = cornerstoneTools.textStyle.getFont();
|
||||
var config = cornerstoneTools.nonTarget.getConfiguration();
|
||||
|
||||
for (var i = 0; i < toolData.data.length; i++) {
|
||||
context.save();
|
||||
|
||||
var data = toolData.data[i];
|
||||
|
||||
if (data.active) {
|
||||
color = cornerstoneTools.toolColors.getActiveColor();
|
||||
} else {
|
||||
color = cornerstoneTools.toolColors.getToolColor();
|
||||
}
|
||||
|
||||
// Draw the arrow
|
||||
var handleStartCanvas = cornerstone.pixelToCanvas(eventData.element, data.handles.start);
|
||||
var handleEndCanvas = cornerstone.pixelToCanvas(eventData.element, data.handles.end);
|
||||
|
||||
if (config.arrowFirst) {
|
||||
drawArrow(context, handleEndCanvas, handleStartCanvas, color, lineWidth);
|
||||
} else {
|
||||
drawArrow(context, handleStartCanvas, handleEndCanvas, color, lineWidth);
|
||||
}
|
||||
|
||||
if (config.drawHandles) {
|
||||
cornerstoneTools.drawHandles(context, eventData, data.handles, color);
|
||||
} else if (config.drawHandlesOnHover && data.handles.start.active) {
|
||||
cornerstoneTools.drawHandles(context, eventData, [ data.handles.start ], color);
|
||||
} else if (config.drawHandlesOnHover && data.handles.end.active) {
|
||||
cornerstoneTools.drawHandles(context, eventData, [ data.handles.end ], color);
|
||||
}
|
||||
|
||||
//Set coordinates of text
|
||||
var linkedTextStartCanvas = cornerstone.pixelToCanvas(eventData.element, data.linkedTextCoords.start);
|
||||
var linkedTextEndCanvas = cornerstone.pixelToCanvas(eventData.element, data.linkedTextCoords.end);
|
||||
if (!data.linkedTextCoords.init) {
|
||||
data.linkedTextCoords.start.x = data.handles.start.x + 50;
|
||||
data.linkedTextCoords.start.y = data.handles.start.y + 40;
|
||||
linkedTextStartCanvas = cornerstone.pixelToCanvas(eventData.element, data.linkedTextCoords.start);
|
||||
|
||||
//Set end point of linkedTextCoords
|
||||
data.linkedTextCoords.end.x = data.linkedTextCoords.start.x + 50;
|
||||
data.linkedTextCoords.end.y = data.linkedTextCoords.start.y + 30;
|
||||
linkedTextEndCanvas = cornerstone.pixelToCanvas(eventData.element, data.linkedTextCoords.end);
|
||||
|
||||
//initialized coordinates of text
|
||||
data.linkedTextCoords.init = true;
|
||||
}
|
||||
|
||||
//Draw linked line as dashed
|
||||
context.setLineDash([2, 3]);
|
||||
context.beginPath();
|
||||
context.strokeStyle = color;
|
||||
context.lineWidth = 1 / eventData.viewport.scale;
|
||||
var mid = {
|
||||
x: (handleStartCanvas.x + handleEndCanvas.x) / 2,
|
||||
y: (handleStartCanvas.y + handleEndCanvas.y) / 2
|
||||
};
|
||||
|
||||
context.moveTo(mid.x, mid.y);
|
||||
context.lineTo(linkedTextStartCanvas.x + 20, linkedTextStartCanvas.y);
|
||||
context.stroke();
|
||||
|
||||
|
||||
// Draw the text
|
||||
if (data.text && data.text !== '') {
|
||||
context.font = font;
|
||||
|
||||
var textCoords = {
|
||||
x: linkedTextStartCanvas.x,
|
||||
y: linkedTextStartCanvas.y
|
||||
};
|
||||
|
||||
cornerstoneTools.drawTextBox(context, data.text, textCoords.x, textCoords.y, color);
|
||||
}
|
||||
|
||||
|
||||
context.restore();
|
||||
}
|
||||
}
|
||||
// ---- Touch tool ----
|
||||
|
||||
///////// BEGIN ACTIVE TOOL ///////
|
||||
function addNewMeasurementTouch(touchEventData) {
|
||||
var element = touchEventData.element;
|
||||
|
||||
function doneChangingTextCallback(text) {
|
||||
if (text !== null) {
|
||||
measurementData.text = text;
|
||||
} else {
|
||||
cornerstoneTools.removeToolState(element, toolType, measurementData);
|
||||
}
|
||||
|
||||
measurementData.active = false;
|
||||
cornerstone.updateImage(element);
|
||||
}
|
||||
|
||||
var measurementData = createNewMeasurement(touchEventData);
|
||||
cornerstoneTools.addToolState(element, toolType, measurementData);
|
||||
$(element).off('CornerstoneToolsTouchDrag', cornerstoneTools.nonTargetTouch.touchMoveCallback);
|
||||
$(element).off('CornerstoneToolsDragStartActive', cornerstoneTools.nonTargetTouch.touchDownActivateCallback);
|
||||
$(element).off('CornerstoneToolsTap', cornerstoneTools.nonTargetTouch.tapCallback);
|
||||
cornerstone.updateImage(element);
|
||||
|
||||
cornerstoneTools.moveNewHandleTouch(touchEventData, measurementData.handles.end, function() {
|
||||
cornerstone.updateImage(element);
|
||||
|
||||
if (cornerstoneTools.anyHandlesOutsideImage(touchEventData, measurementData.handles)) {
|
||||
// delete the measurement
|
||||
cornerstoneTools.removeToolState(element, toolType, measurementData);
|
||||
}
|
||||
|
||||
var config = cornerstoneTools.nonTarget.getConfiguration();
|
||||
if (measurementData.text === undefined) {
|
||||
config.getTextCallback(doneChangingTextCallback);
|
||||
}
|
||||
|
||||
$(element).on('CornerstoneToolsTouchDrag', cornerstoneTools.nonTargetTouch.touchMoveCallback);
|
||||
$(element).on('CornerstoneToolsDragStartActive', cornerstoneTools.nonTargetTouch.touchDownActivateCallback);
|
||||
$(element).on('CornerstoneToolsTap', cornerstoneTools.nonTargetTouch.tapCallback);
|
||||
});
|
||||
}
|
||||
|
||||
function doubleClickCallback(e, eventData) {
|
||||
var element = eventData.element;
|
||||
var data;
|
||||
|
||||
function doneChangingTextCallback(data, updatedText, deleteTool) {
|
||||
if (deleteTool === true) {
|
||||
cornerstoneTools.removeToolState(element, toolType, data);
|
||||
} else {
|
||||
data.text = updatedText;
|
||||
}
|
||||
|
||||
data.active = false;
|
||||
cornerstone.updateImage(element);
|
||||
}
|
||||
|
||||
if (e.data && e.data.mouseButtonMask && !cornerstoneTools.isMouseButtonEnabled(eventData.which, e.data.mouseButtonMask)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var config = cornerstoneTools.nonTarget.getConfiguration();
|
||||
|
||||
var coords = eventData.currentPoints.canvas;
|
||||
var toolData = cornerstoneTools.getToolState(element, toolType);
|
||||
|
||||
// now check to see if there is a handle we can move
|
||||
if (!toolData) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (var i = 0; i < toolData.data.length; i++) {
|
||||
data = toolData.data[i];
|
||||
if (pointNearTool(element, data, coords)) {
|
||||
data.active = true;
|
||||
cornerstone.updateImage(element);
|
||||
// Allow relabelling via a callback
|
||||
config.changeTextCallback(data, doneChangingTextCallback);
|
||||
|
||||
e.stopImmediatePropagation();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return false; // false = causes jquery to preventDefault() and stopPropagation() this event
|
||||
}
|
||||
|
||||
function updateLesion(e, eventObject) {
|
||||
var start = new Date();
|
||||
|
||||
var enabledElement = eventObject.enabledElement;
|
||||
var isTarget = eventObject.lesionData.isTarget;
|
||||
var lesionNumber = eventObject.lesionData.lesionNumber;
|
||||
var type = eventObject.type;
|
||||
|
||||
// if we have no toolData for this element, return immediately as there is nothing to do
|
||||
var toolData = cornerstoneTools.getToolState(e.currentTarget, toolType);
|
||||
if (toolData === undefined) {
|
||||
return;
|
||||
}
|
||||
|
||||
//If type is delete, remove measurement
|
||||
if (type === "delete") {
|
||||
var deletedDataIndex = -1;
|
||||
|
||||
for (var i = 0; i < toolData.data.length; i++) {
|
||||
var data = toolData.data[i];
|
||||
|
||||
//When click a row of table measurements, measurement will be active and color will be green
|
||||
if (data.lesionNumber === eventObject.lesionNumber && eventObject.type !== "active") {
|
||||
data.visible = false;
|
||||
deletedDataIndex = i;
|
||||
}
|
||||
}
|
||||
|
||||
if (deletedDataIndex >= 0 && deletedDataIndex < toolData.data.length) {
|
||||
toolData.data.splice(deletedDataIndex, 1);
|
||||
}
|
||||
} else if (type === "active") {
|
||||
for (var i = 0; i < toolData.data.length; i++) {
|
||||
var data = toolData.data[i];
|
||||
//When click a row of table measurements, measurement will be active and color will be green
|
||||
if (data.lesionNumber === eventObject.lesionData.lesionNumber && eventObject.type === "active") {
|
||||
data.active = true;
|
||||
} else {
|
||||
data.active = false;
|
||||
}
|
||||
}
|
||||
} else if (type === "inactive") {
|
||||
for (var i = 0; i < toolData.data.length; i++) {
|
||||
var data = toolData.data[i];
|
||||
// Make inactive all lesions for the timepoint
|
||||
data.active = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
enabledElement.image.render(enabledElement, true);
|
||||
|
||||
var context = enabledElement.canvas.getContext('2d');
|
||||
|
||||
var end = new Date();
|
||||
var diff = end - start;
|
||||
//console.log(diff + ' ms');
|
||||
|
||||
var eventData = {
|
||||
viewport: enabledElement.viewport,
|
||||
element: enabledElement.element,
|
||||
image: enabledElement.image,
|
||||
enabledElement: enabledElement,
|
||||
canvasContext: context,
|
||||
measurementText: "",
|
||||
renderTimeInMs: diff,
|
||||
lesionNumber: lesionNumber,
|
||||
type: type //Holds image will be deleted or active
|
||||
};
|
||||
|
||||
enabledElement.invalid = false;
|
||||
|
||||
onImageRendered(e, eventData);
|
||||
}
|
||||
|
||||
function loadImage(e, eventObject) {
|
||||
// If type is active, load image and activate lesion
|
||||
// If type is inactive, update lesions of enabledElement as inactive
|
||||
|
||||
if (eventObject.type === "active") {
|
||||
var stackToolDataSource = cornerstoneTools.getToolState(e.currentTarget, 'stack');
|
||||
var stackData = stackToolDataSource.data[0];
|
||||
var imageIdsArr = stackData.imageIds;
|
||||
var indexOfImage = imageIdsArr.indexOf(eventObject.lesionData.imageId);
|
||||
if (indexOfImage > -1) {
|
||||
cornerstone.loadAndCacheImage(stackData.imageIds[indexOfImage]).then(function(image) {
|
||||
cornerstone.displayImage(eventObject.enabledElement.element, image);
|
||||
updateLesion(e, eventObject);
|
||||
});
|
||||
}
|
||||
} else if (eventObject.type === "inactive") {
|
||||
updateLesion(e, eventObject);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
//This function is called from cornerstone-viewport.html and updates lesion measurement and makes the lesion active
|
||||
function measurementModified(e, eventObject) {
|
||||
loadImage(e, eventObject);
|
||||
}
|
||||
|
||||
cornerstoneTools.nonTarget = cornerstoneTools.mouseButtonTool({
|
||||
addNewMeasurement: addNewMeasurement,
|
||||
createNewMeasurement: createNewMeasurement,
|
||||
onImageRendered: onImageRendered,
|
||||
pointNearTool: pointNearTool,
|
||||
pointNearToolForText: pointNearToolForText,
|
||||
toolType: toolType,
|
||||
mouseDoubleClickCallback: doubleClickCallback
|
||||
});
|
||||
|
||||
cornerstoneTools.nonTarget.setConfiguration(configuration);
|
||||
|
||||
cornerstoneTools.nonTargetTouch = cornerstoneTools.touchTool({
|
||||
addNewMeasurement: addNewMeasurementTouch,
|
||||
createNewMeasurement: createNewMeasurement,
|
||||
onImageRendered: onImageRendered,
|
||||
pointNearTool: pointNearTool,
|
||||
pointNearToolForText: pointNearToolForText,
|
||||
toolType: toolType,
|
||||
pressCallback: doubleClickCallback
|
||||
});
|
||||
|
||||
|
||||
})($, cornerstone, cornerstoneMath, cornerstoneTools);
|
||||
|
||||
// End Source; src/imageTools/annotation.js
|
||||
@ -4,7 +4,7 @@ Template.lesionDialog.onRendered(function () {
|
||||
// related to the chosen location.
|
||||
|
||||
$(document).on("ShowLesionDialog", function (e, eventData, lesionData) {
|
||||
var locationUID = measurementManagerDAL.isLesionNumberAdded(lesionData.lesionNumber);
|
||||
var locationUID = measurementManagerDAL.isLesionNumberAdded(lesionData);
|
||||
|
||||
if (locationUID) {
|
||||
lesionData.locationUID = locationUID;
|
||||
|
||||
@ -51,8 +51,6 @@ Template.lesionLocationDialog.onRendered(function() {
|
||||
Template.lesionLocationDialog.events({
|
||||
'click button#btnCloseLesionPopup': function(e) {
|
||||
$("#lesionDialog").modal("hide");
|
||||
// TODO: Remove lastAddedLesionData from canvas
|
||||
// TODO: Remove lastAddedLesionData from collection
|
||||
},
|
||||
|
||||
'change select#selectLesionLocation': function(e) {
|
||||
|
||||
@ -1,14 +1,51 @@
|
||||
Measurements = new Meteor.Collection(null);
|
||||
Timepoints = new Meteor.Collection(null);
|
||||
|
||||
// When nonTarget lesion is added to image, insert data to lesion table
|
||||
function nonTargetToolAdded(e, eventData, lesionData) {
|
||||
lesionData.timepointID = $(e.currentTarget).data('timepointID');
|
||||
|
||||
var locationUID = measurementManagerDAL.isLesionNumberAdded(lesionData);
|
||||
if (locationUID) {
|
||||
// location is selected and disable select location in dialog
|
||||
lesionData.locationUID = locationUID;
|
||||
var locationName = measurementManagerDAL.getLocationName(locationUID);
|
||||
var locationIndex;
|
||||
$("#selectNonTargetLesionLocation option").each(function()
|
||||
{
|
||||
if ($(this).text() === locationName) {
|
||||
locationIndex = $(this).index();
|
||||
return;
|
||||
}
|
||||
});
|
||||
$("#selectNonTargetLesionLocation option").eq(locationIndex).attr("selected", "selected");
|
||||
// $("#selectNonTargetLesionLocation").attr("disabled", "disabled");
|
||||
|
||||
}
|
||||
|
||||
// Save lesionData in Session to use after location and response are selected
|
||||
Session.set("nonTargetLesionData", lesionData);
|
||||
|
||||
var dialogPointsOnPage = eventData.currentPoints.page;
|
||||
$("#modal-dialog-container-nonTargetLesion").css({
|
||||
"top": dialogPointsOnPage.y,
|
||||
"left": dialogPointsOnPage.x
|
||||
});
|
||||
|
||||
$("#nonTargetLesionLocationDialog").modal("show");
|
||||
|
||||
}
|
||||
|
||||
// Activate selected lesions when lesion table row is clicked
|
||||
function updateLesions(e) {
|
||||
// lesionNumber of measurement = id of row
|
||||
var lesionNumber = parseInt($(e.currentTarget).attr("id"), 10);
|
||||
var isTarget = $(e.currentTarget).find('td').eq(2).html().trim() === 'N'?false:true;
|
||||
|
||||
// Find data for specific lesion
|
||||
var measurementData = Measurements.find({
|
||||
lesionNumber: lesionNumber
|
||||
lesionNumber: lesionNumber,
|
||||
isTarget: isTarget
|
||||
}).fetch()[0];
|
||||
|
||||
var timepoints = measurementData.timepoints;
|
||||
@ -24,6 +61,7 @@ function updateLesions(e) {
|
||||
var eventData = {
|
||||
enabledElement: cornerstone.getEnabledElement(element),
|
||||
lesionData: {
|
||||
isTarget: isTarget,
|
||||
lesionNumber: lesionNumber,
|
||||
imageId: timepointObject.imageId
|
||||
},
|
||||
@ -34,7 +72,11 @@ function updateLesions(e) {
|
||||
eventData.type = "inactive";
|
||||
}
|
||||
|
||||
if(!isTarget) {
|
||||
$(element).trigger("nonTargetToolModified", eventData);
|
||||
}
|
||||
$(element).trigger("LesionToolModified", eventData);
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
@ -59,9 +101,13 @@ Template.lesionTable.onRendered(function() {
|
||||
});
|
||||
|
||||
$(element).data('timepointID', timepointID);
|
||||
|
||||
// Listen NonTargetToolAdded Event
|
||||
$(element).on("NonTargetToolAdded", nonTargetToolAdded);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Template.lesionTable.helpers({
|
||||
'measurement': function() {
|
||||
return Measurements.find();
|
||||
|
||||
@ -0,0 +1,32 @@
|
||||
#nonTargetLesionLocationDialog {
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
#modal-dialog-container-nonTargetLesion {
|
||||
position: absolute;
|
||||
border: none;
|
||||
}
|
||||
|
||||
#btnCloseNonTargetLesionPopup {
|
||||
outline: 0;
|
||||
border: none;
|
||||
background-color: transparent;
|
||||
}
|
||||
|
||||
#selectNonTargetLesionLocation, #selectNonTargetLesionLocationResponse {
|
||||
width: 80%;
|
||||
}
|
||||
|
||||
.dialogContent, .lesionLocation, .locationResponse {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.elementContainer {
|
||||
width: 100%;
|
||||
margin: 0 auto;
|
||||
float: none;
|
||||
}
|
||||
|
||||
.locationOK {
|
||||
text-align: center;
|
||||
}
|
||||
@ -0,0 +1,40 @@
|
||||
<template name="nonTargetLesionDialog">
|
||||
<div class="modal fade" id="nonTargetLesionLocationDialog">
|
||||
<div id="modal-dialog-container-nonTargetLesion" class="modal-dialog modal-sm">
|
||||
<div class="modal-content" style="padding: 10px;">
|
||||
<div class="dialogHeader">
|
||||
<div style="float:left;"><h4>Select Lesion Location</h4></div>
|
||||
<div style="float:right;"><button class="btn" id="btnCloseNonTargetLesionPopup"><i class="fa fa-close"></i></button></div>
|
||||
</div>
|
||||
<div class="dialogContent">
|
||||
|
||||
<div class="lesionLocation">
|
||||
<div class="elementContainer">
|
||||
<label>Lesion Location</label>
|
||||
</div>
|
||||
<div class="elementContainer">
|
||||
<select id="selectNonTargetLesionLocation">
|
||||
<option value="-1"></option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="locationResponse">
|
||||
<div class="elementContainer">
|
||||
<label>Response</label>
|
||||
</div>
|
||||
<div class="elementContainer">
|
||||
<select id="selectNonTargetLesionLocationResponse">
|
||||
<option value="-1"></option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="locationOK">
|
||||
<button class="btn" id="nonTargetLesionOK">OK</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@ -0,0 +1,133 @@
|
||||
//fill selectLesionLocation element
|
||||
var lesionLocationsArray = [{
|
||||
location: "Brain Brainstem",
|
||||
hasDescription: false,
|
||||
description: ""
|
||||
}, {
|
||||
location: "Brain Cerebellum Left",
|
||||
hasDescription: false,
|
||||
description: ""
|
||||
}, {
|
||||
location: "Brain Cerebrum Left",
|
||||
hasDescription: false,
|
||||
description: ""
|
||||
}, {
|
||||
location: "Brain Cerebrum Right",
|
||||
hasDescription: false,
|
||||
description: ""
|
||||
}, {
|
||||
location: "Brain Multiple Sites",
|
||||
hasDescription: false,
|
||||
description: ""
|
||||
}];
|
||||
|
||||
var lesionLocationsResponseArray = [
|
||||
{
|
||||
text: "Complete response",
|
||||
code: "CR",
|
||||
description: ""
|
||||
},
|
||||
{
|
||||
text: "Progressive disease",
|
||||
code: "PD",
|
||||
description: ""
|
||||
},
|
||||
{
|
||||
text: "Stable disease",
|
||||
code: "SD",
|
||||
description: ""
|
||||
},
|
||||
{
|
||||
text: "Non-measurable",
|
||||
code: "NM",
|
||||
description: ""
|
||||
},
|
||||
{
|
||||
text: "Unknown",
|
||||
code: "UN",
|
||||
description: ""
|
||||
},
|
||||
{
|
||||
text: "Not Evaluable",
|
||||
code: "NE",
|
||||
description: ""
|
||||
},
|
||||
{
|
||||
text: "Non-CR/Non-PD",
|
||||
code: "NN",
|
||||
description: ""
|
||||
},
|
||||
{
|
||||
text: "Excluded",
|
||||
code: "EX",
|
||||
description: ""
|
||||
}
|
||||
];
|
||||
|
||||
Template.nonTargetLesionDialog.onRendered(function() {
|
||||
|
||||
function fillSelectLesionLocation() {
|
||||
var el = $("#selectNonTargetLesionLocation");
|
||||
el.find('option:not(:first)').remove();
|
||||
$.each(lesionLocationsArray, function(key, value) {
|
||||
el.append("<option value='" + key + "'>" + value.location + "</option>");
|
||||
});
|
||||
}
|
||||
|
||||
function fillResponses() {
|
||||
var el = $("#selectNonTargetLesionLocationResponse");
|
||||
el.find('option:not(:first)').remove();
|
||||
$.each(lesionLocationsResponseArray, function(key, value) {
|
||||
el.append("<option value='" + value.code + "'>" + value.code +" - "+value.text + "</option>");
|
||||
});
|
||||
}
|
||||
|
||||
// Fill dropdown
|
||||
fillSelectLesionLocation();
|
||||
|
||||
// Fill location responses
|
||||
fillResponses();
|
||||
|
||||
});
|
||||
|
||||
Template.nonTargetLesionDialog.events({
|
||||
'click button#btnCloseNonTargetLesionPopup': function(e) {
|
||||
$("#nonTargetLesionLocationDialog").modal("hide");
|
||||
},
|
||||
|
||||
'click button#nonTargetLesionOK': function() {
|
||||
// Set activeModule parameters in index.html
|
||||
$("#nonTargetLesionLocationDialog").modal("hide");
|
||||
|
||||
var lesionData = Session.get("nonTargetLesionData");
|
||||
// Get selected location data
|
||||
var selectedLocationIndex = $("#selectNonTargetLesionLocation").val();
|
||||
if (selectedLocationIndex < 0) {
|
||||
return;
|
||||
}
|
||||
// Get selected location data
|
||||
var locationObj = lesionLocationsArray[selectedLocationIndex];
|
||||
lesionData.location = $("#selectNonTargetLesionLocation :selected").text();
|
||||
lesionData.measurementText = $("#selectNonTargetLesionLocationResponse").val();
|
||||
|
||||
// Select first option
|
||||
$("#selectNonTargetLesionLocation").val($("#selectNonTargetLesionLocation option:first").val());
|
||||
$("#selectNonTargetLesionLocationResponse").val($("#selectNonTargetLesionLocationResponse option:first").val());
|
||||
|
||||
if (typeof lesionData.locationUID !== 'undefined') {
|
||||
measurementManagerDAL.updateTimepointData(lesionData);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Adds location data to trialPatientLocations array and returns locationUID
|
||||
var locationUID = measurementManagerDAL.addNewLocation(locationObj);
|
||||
// Linkk locationUID with activeLesionMeasurementData
|
||||
lesionData.locationUID = locationUID;
|
||||
|
||||
measurementManagerDAL.addLesionData(lesionData);
|
||||
|
||||
|
||||
|
||||
}
|
||||
});
|
||||
@ -15,6 +15,7 @@ Package.onUse(function (api) {
|
||||
api.use('cornerstone');
|
||||
|
||||
api.addFiles('compatibility/lesionTool.js', 'client', {bare: true});
|
||||
api.addFiles('compatibility/nonTargetTool.js', 'client', {bare: true});
|
||||
api.addFiles('compatibility/measurementManagerDAL.js', 'client', {bare: true});
|
||||
|
||||
api.addFiles('components/lesionDialog/lesionDialog.html', 'client');
|
||||
@ -36,9 +37,12 @@ Package.onUse(function (api) {
|
||||
api.addFiles('components/lesionTableTimepointHeader/lesionTableTimepointHeader.html', 'client');
|
||||
api.addFiles('components/lesionTableTimepointHeader/lesionTableTimepointHeader.js', 'client');
|
||||
|
||||
api.addFiles('components/nonTargetLesionDialog/nonTargetLesionDialog.html', 'client');
|
||||
api.addFiles('components/nonTargetLesionDialog/nonTargetLesionDialog.css', 'client');
|
||||
api.addFiles('components/nonTargetLesionDialog/nonTargetLesionDialog.js', 'client');
|
||||
|
||||
|
||||
// Library functions
|
||||
api.addFiles('lib/getActiveTimepointID.js', 'client');
|
||||
api.addFiles('lib/uuid.js', 'client');
|
||||
|
||||
api.export('Measurements', 'client');
|
||||
|
||||
@ -356,6 +356,7 @@ Template.imageViewerViewport.onRendered(function() {
|
||||
// When the imageViewerViewport template is rendered
|
||||
var element = this.find(".imageViewerViewport");
|
||||
|
||||
|
||||
// Display the loading indicator for this element
|
||||
$(element).siblings('.imageViewerLoadingIndicator').css('display', 'block');
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user