Updated lesion dialog to use collections

This commit is contained in:
Erik Ziegler committed 2015-11-11 22:16:22 +01:00
1 parent 1d0ae73611
commit 9ce3e5ed86
11 files changed
+305 -305

No files matched your search

@@ -8,41 +8,70 @@ var cornerstoneTools = (function($, cornerstone, cornerstoneMath, cornerstoneToo
cornerstoneTools = {};
}
var configuration = {
getLesionLocationCallback: getLesionLocationCallback,
changeLesionLocationCallback: changeLesionLocationCallback,
};
// Define a callback to get your text annotation
// This could be used, e.g. to open a modal
function getLesionLocationCallback(measurementData, eventData, doneCallback) {
doneCallback(prompt('Enter your lesion location:'));
}
function changeLesionLocationCallback(measurementData, eventData, doneCallback) {
doneCallback(prompt('Change your lesion location:'));
}
var toolType = "lesion";
///////// BEGIN ACTIVE TOOL ///////
function createNewMeasurement(mouseEventData) {
function addNewMeasurement(mouseEventData) {
var element = mouseEventData.element;
timepointID = $(element).data('timepointID');
var lesionNumber = measurementManagerDAL.getNewLesionNumber(timepointID, true);
var lesionCounter = "";
function doneCallback(lesionNumber) {
measurementData.lesionName = "Target " + lesionNumber;
measurementData.lesionNumber = lesionNumber;
measurementData.active = false;
cornerstone.updateImage(element);
}
// ** This stuff should not be done here! We should do this inside addNewMeasurement!** //
var measurementData = createNewMeasurement(mouseEventData);
// Subscribe CornerstoneMouseup event, when mouse is up, call lesionDialog
$(element).on("CornerstoneToolsMouseUp", function(e) {
var eventData = {
mouseButtonMask: mouseEventData.which,
};
// associate this data with this imageId so we can render it and manipulate it
cornerstoneTools.addToolState(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.
$(element).off('CornerstoneToolsMouseMove', cornerstoneTools.lesion.mouseMoveCallback);
$(element).off('CornerstoneToolsMouseDown', cornerstoneTools.lesion.mouseDownCallback);
$(element).off('CornerstoneToolsMouseDownActivate', cornerstoneTools.lesion.mouseDownActivateCallback);
// Unsubscribe CornerstoneToolsMouseUp event
$(element).off("CornerstoneToolsMouseUp");
cornerstone.updateImage(element);
cornerstoneTools.moveNewHandle(mouseEventData, measurementData.handles.end, function() {
if (cornerstoneTools.anyHandlesOutsideImage(mouseEventData, measurementData.handles)) {
// delete the measurement
cornerstoneTools.removeToolState(element, toolType, measurementData);
} else {
// Set lesionMeasurementData Session
var config = cornerstoneTools.lesion.getConfiguration();
config.getLesionLocationCallback(measurementData, mouseEventData, doneCallback);
}
// Set lesionMeasurementData Session
activeLesionMeasurementData.timepointID = timepointID;
Session.set("lesionMeasurementData", activeLesionMeasurementData);
// Show LesionDialog
$(document).trigger("ShowLesionDialog", [e, activeLesionMeasurementData]);
$(element).on('CornerstoneToolsMouseMove', eventData, cornerstoneTools.lesion.mouseMoveCallback);
$(element).on('CornerstoneToolsMouseDown', eventData, cornerstoneTools.lesion.mouseDownCallback);
$(element).on('CornerstoneToolsMouseDownActivate', eventData, cornerstoneTools.lesion.mouseDownActivateCallback);
cornerstone.updateImage(element);
});
}
// Set Lesion Name
$(element).on("LesionNameSet", function(e, lesionName) {
lesionCounter = lesionName;
});
// Subscribe LesionMeasurementCreated
$(element).trigger("LesionMeasurementCreated");
// create the measurement data for this tool with the end handle activated
function createNewMeasurement(mouseEventData) {
// Create the measurement data for this tool with the end handle activated
var measurementData = {
visible: true,
active: true,
@@ -70,9 +99,8 @@ var cornerstoneTools = (function($, cornerstone, cornerstoneMath, cornerstoneToo
},
imageId: mouseEventData.image.imageId,
measurementText: 0,
lesionName: "Target " + lesionNumber,
lesionName: '',
isDeleted: false,
lesionNumber: lesionNumber,
isTarget: true,
uid: uuid.v4()
};
@@ -136,15 +164,15 @@ var cornerstoneTools = (function($, cornerstone, cornerstoneMath, cornerstoneToo
}
function updateLesionCollection(lesionData) {
if (!lesionData.active) {
return;
}
if (lesionData.active) {
if (lesionData.timepointID !== undefined && lesionData.timepointID !== "") {
// Update Measurements Collection
measurementManagerDAL.updateTimepointData(lesionData);
} else {
activeLesionMeasurementData = lesionData;
}
if (lesionData.timepointID && lesionData.timepointID !== "") {
// Update Measurements Collection
measurementManagerDAL.updateTimepointData(lesionData);
} else {
activeLesionMeasurementData = lesionData;
}
}
@@ -230,63 +258,62 @@ var cornerstoneTools = (function($, cornerstone, cornerstoneMath, cornerstoneToo
///////// END IMAGE RENDERING ///////
function updateLesion(e, eventData) {
var start = new Date();
var enabledElement = eventData.enabledElement;
var element = eventData.enabledElement.element;
var isTarget = eventData.lesionData.isTarget;
var lesionNumber = eventData.lesionData.lesionNumber;
var type = eventData.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) {
if (!toolData) {
return;
}
var data,
i;
//If type is delete, remove measurement
if (type === "delete") {
var deletedDataIndex = -1;
switch (type) {
case "delete":
//If type is delete, remove measurement
var deletedDataIndex = -1;
for (i = 0; i < toolData.data.length; i++) {
data = toolData.data[i];
for (i = 0; i < toolData.data.length; i++) {
data = toolData.data[i];
//When click a row of table measurements, measurement will be active and color will be green
if (data.lesionNumber === eventData.lesionNumber && eventData.type !== "active" && isTarget) {
data.visible = false;
deletedDataIndex = i;
//When click a row of table measurements, measurement will be active and color will be green
if (data.lesionNumber === lesionNumber && eventData.type !== "active" && isTarget) {
data.visible = false;
deletedDataIndex = i;
}
}
}
if (deletedDataIndex >= 0 && deletedDataIndex < toolData.data.length) {
toolData.data.splice(deletedDataIndex, 1);
}
} else if (type === "active") {
for (i = 0; i < toolData.data.length; i++) {
data = toolData.data[i];
//When click a row of table measurements, measurement will be active and color will be green
if (data.lesionNumber === eventData.lesionData.lesionNumber && eventData.type === "active" && isTarget) {
data.active = true;
} else {
if (deletedDataIndex >= 0 && deletedDataIndex < toolData.data.length) {
toolData.data.splice(deletedDataIndex, 1);
}
break;
case "active":
for (i = 0; i < toolData.data.length; i++) {
data = toolData.data[i];
//When click a row of table measurements, measurement will be active and color will be green
if (data.lesionNumber === lesionNumber && eventData.type === "active" && isTarget) {
data.active = true;
} else {
data.active = false;
}
}
break;
case "inactive":
for (i = 0; i < toolData.data.length; i++) {
data = toolData.data[i];
// Make inactive all lesions for the timepoint
data.active = false;
}
}
} else if (type === "inactive") {
for (i = 0; i < toolData.data.length; i++) {
data = toolData.data[i];
// Make inactive all lesions for the timepoint
data.active = false;
}
break;
}
var context = enabledElement.canvas.getContext('2d');
var end = new Date();
var diff = end - start;
//console.log(diff + ' ms');
cornerstone.updateImage(element);
}
@@ -298,19 +325,19 @@ var cornerstoneTools = (function($, cornerstone, cornerstoneMath, cornerstoneToo
if (eventData.type === "active") {
var stackToolDataSource = cornerstoneTools.getToolState(e.currentTarget, 'stack');
var stackData = stackToolDataSource.data[0];
var imageIdsArr = stackData.imageIds;
var indexOfImage = imageIdsArr.indexOf(eventData.lesionData.imageId);
if (indexOfImage > -1) {
cornerstone.loadAndCacheImage(stackData.imageIds[indexOfImage]).then(function(image) {
cornerstone.displayImage(eventData.enabledElement.element, image);
updateLesion(e, eventData);
});
var imageIds = stackData.imageIds;
var imageIdIndex = imageIds.indexOf(eventData.lesionData.imageId);
if (imageIdIndex < 0) {
return;
}
cornerstone.loadAndCacheImage(imageIds[imageIdIndex]).then(function(image) {
cornerstone.displayImage(eventData.enabledElement.element, image);
updateLesion(e, eventData);
});
} else if (eventData.type === "inactive") {
updateLesion(e, eventData);
}
}
//This function is called from cornerstone-viewport.html and updates lesion measurement and makes the lesion active
@@ -321,6 +348,7 @@ var cornerstoneTools = (function($, cornerstone, cornerstoneMath, cornerstoneToo
// module exports
cornerstoneTools.lesion = cornerstoneTools.mouseButtonTool({
createNewMeasurement: createNewMeasurement,
addNewMeasurement: addNewMeasurement,
onImageRendered: onImageRendered,
pointNearTool: pointNearTool,
toolType: toolType
@@ -328,10 +356,14 @@ var cornerstoneTools = (function($, cornerstone, cornerstoneMath, cornerstoneToo
cornerstoneTools.lesionTouch = cornerstoneTools.touchTool({
createNewMeasurement: createNewMeasurement,
//addNewMeasurement: addNewMeasurementTouch,
onImageRendered: onImageRendered,
pointNearTool: pointNearTool,
toolType: toolType
});
cornerstoneTools.lesion.setConfiguration(configuration);
return cornerstoneTools;
}($, cornerstone, cornerstoneMath, cornerstoneTools));
@@ -1,30 +1,9 @@
var measurementManagerDAL = (function() {
var trialPatientLocations = [];
PatientLocations = new Meteor.Collection(null);
// Returns trialPatientLocations array
function getPatientLocations() {
return trialPatientLocations;
}
function getLocationName(locationUID) {
for (var i = 0; i < trialPatientLocations.length; i++) {
var locationObject = trialPatientLocations[i];
if (locationObject.uid === locationUID) {
return locationObject.location.location;
}
}
return "";
}
// Adds new location to trialPatientLocations array
function addPatientLocation(location) {
var locationUID = uuid.v4();
var locationObject = {
uid: locationUID,
location: location
};
trialPatientLocations.push(locationObject);
return locationUID;
function getLocationName(id) {
var locationObject = PatientLocations.findOne(id);
return locationObject.location || "";
}
// Add timepoint data to Measurements collection
@@ -57,7 +36,7 @@ var measurementManagerDAL = (function() {
lesionUID: uuid.v4(),
number: Measurements.find().count() + 1,
lesionNumber: lesionData.lesionNumber,
isTarget: typeof lesionData.isTarget !== 'undefined'?lesionData.isTarget:true,
isTarget: lesionData.isTarget,
locationUID: lesionData.locationUID,
location: getLocationName(lesionData.locationUID),
timepoints: timepointsObject
@@ -67,9 +46,6 @@ 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,
@@ -100,10 +76,10 @@ var measurementManagerDAL = (function() {
}
// Check timepointData is found in Measurements collection
function timepointDataIsFound(lesionData) {
function hasTimepointData(lesionData) {
var timepointData = Measurements.findOne({
lesionNumber: lesionData.lesionNumber,
isTarget: typeof lesionData.isTarget!== 'undefined'?lesionData.isTarget:true
isTarget: lesionData.isTarget
});
if (timepointData) {
return true;
@@ -113,7 +89,7 @@ var measurementManagerDAL = (function() {
// Adds new timepoint item to tiemepoints array
function addLesionData(lesionData) {
if (timepointDataIsFound(lesionData)) {
if (hasTimepointData(lesionData)) {
// Update data
updateTimepointData(lesionData);
} else {
@@ -124,10 +100,6 @@ var measurementManagerDAL = (function() {
// Returns new lesion number according to timepointID
function getNewLesionNumber(timepointID, isTarget) {
if (typeof isTarget === 'undefined') {
isTarget = true;
}
// Get all current lesion measurements
var measurements = Measurements.find({isTarget: isTarget}).fetch();
@@ -153,14 +125,11 @@ var measurementManagerDAL = (function() {
}
// If lesion number is added for any timepoint, returns lesion locationUID
function isLesionNumberAdded(lesionData) {
if (!timepointDataIsFound(lesionData)) {
function lesionNumberExists(lesionData) {
if (!hasTimepointData(lesionData)) {
return;
}
if(typeof isTarget === undefined) {
isTarget = true;
}
var measurement = Measurements.find({
lesionNumber: lesionData.lesionNumber,
isTarget: lesionData.isTarget
@@ -169,13 +138,10 @@ var measurementManagerDAL = (function() {
return measurement.locationUID;
}
return {
addNewLocation: addPatientLocation,
getLocations: getPatientLocations,
addLesionData: addLesionData,
getNewLesionNumber: getNewLesionNumber,
isLesionNumberAdded: isLesionNumberAdded,
lesionNumberExists: lesionNumberExists,
updateTimepointData: updateTimepointData,
getLocationName: getLocationName
};
@@ -1,4 +1,3 @@
// Begin Source: src/imageTools/annotation.js
(function($, cornerstone, cornerstoneMath, cornerstoneTools) {
'use strict';
@@ -8,14 +7,13 @@
// 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:'));
doneChangingTextCallback(prompt('Add a non-target lesion name:'));
}
function changeTextCallback(data, doneChangingTextCallback) {
doneChangingTextCallback(prompt('Change your annotation:'));
}
var configuration = {
getTextCallback: getTextCallback,
changeTextCallback: changeTextCallback,
@@ -141,16 +139,6 @@
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;
@@ -185,7 +173,7 @@
context.fill();
}
function suscribeNonTargetToolModifiedEvent(element) {
function subcribeNonTargetToolModifiedEvent(element) {
var elementEvents = $._data(element, "events");
var index = Object.keys(elementEvents).indexOf("NonTargetToolSelected");
if (index < 0) {
@@ -197,7 +185,7 @@
///////// BEGIN IMAGE RENDERING ///////
function onImageRendered(e, eventData) {
suscribeNonTargetToolModifiedEvent(e.currentTarget);
subcribeNonTargetToolModifiedEvent(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);
@@ -229,8 +217,8 @@
// configurable shadow from CornerstoneTools
if (config && config.shadow) {
context.shadowColor = '#000000';
context.shadowOffsetX = +1;
context.shadowOffsetY = +1;
context.shadowOffsetX = 1;
context.shadowOffsetY = 1;
}
if (lesion.active) {
@@ -303,49 +291,6 @@
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;
@@ -497,24 +442,10 @@
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
})($, cornerstone, cornerstoneMath, cornerstoneTools);