Switch toolState usage since ES6 modules are read-only

This commit is contained in:
Erik Ziegler 2017-06-13 09:59:01 +02:00
parent ddef3c4710
commit 27296a8bca
12 changed files with 308 additions and 309 deletions

View File

@ -16,8 +16,6 @@ import * as cornerstoneMath from 'cornerstone-math';
import * as cornerstoneWADOImageLoader from 'cornerstone-wado-image-loader'; import * as cornerstoneWADOImageLoader from 'cornerstone-wado-image-loader';
import * as dicomParser from 'dicom-parser'; import * as dicomParser from 'dicom-parser';
debugger;
export { export {
cornerstone, cornerstone,
cornerstoneTools, cornerstoneTools,

View File

@ -1,99 +1,93 @@
import { Viewerbase } from 'meteor/ohif:viewerbase'; 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'; function removeMeasurementTimepoint(data, index, toolType, element) {
var imageId = data.imageId;
// Delete a lesion if Ctrl+D or DELETE is pressed while a lesion is selected if (!imageId) {
var keys = { var enabledElement = cornerstone.getEnabledElement(element);
D: 68, imageId = enabledElement.image.imageId;
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);
} }
// TODO = Check if we have the same function already in Cornerstone Tools cornerstoneTools.removeToolState(element, toolType, data);
function getNearbyToolData(element, coords, toolTypes) { cornerstone.updateImage(element);
var allTools = Viewerbase.toolManager.getTools(); }
var pointNearTool = false;
var touchDevice = Viewerbase.helpers.isTouchDevice();
var nearbyTool = {},
nearbyToolIndex,
nearbyToolType;
toolTypes.forEach(function(toolType) { // TODO = Check if we have the same function already in Cornerstone Tools
var toolData = cornerstoneTools.getToolState(element, toolType); function getNearbyToolData(element, coords, toolTypes) {
if (!toolData) { var allTools = Viewerbase.toolManager.getTools();
return; 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++) { if (toolInterface.pointNearTool(element, data, coords)) {
var data = toolData.data[i]; pointNearTool = true;
nearbyTool.tool = data;
var toolInterface; nearbyTool.index = i;
if (touchDevice) { nearbyTool.toolType = toolType;
toolInterface = allTools[toolType].touch; break;
} else {
toolInterface = allTools[toolType].mouse;
}
if (toolInterface.pointNearTool(element, data, coords)) {
pointNearTool = true;
nearbyTool.tool = data;
nearbyTool.index = i;
nearbyTool.toolType = toolType;
break;
}
} }
}
if (pointNearTool === true) { if (pointNearTool === true) {
return false; 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) { // module/private exports
var keyCode = eventData.which; cornerstoneTools.deleteLesionKeyboardTool = cornerstoneTools.keyboardTool(keyDownCallback);
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);

View File

@ -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 = { const startPoint = {
x: config.verticalLine.start.x, x: config.verticalLine.start.x,
y: config.verticalLine.start.y y: config.verticalLine.start.y + i * config.verticalMinorTick
};
const endPoint = {
x: config.verticalLine.end.x,
y: config.verticalLine.end.y
}; };
context.beginPath(); const endPoint = {
context.strokeStyle = config.color; x: 0,
context.lineWidth = config.lineWidth; 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); 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 = { const startPoint = {
x: config.horizontalLine.start.x, x: config.horizontalLine.start.x + i * config.horizontalMinorTick,
y: config.horizontalLine.start.y y: config.horizontalLine.start.y
}; };
const endPoint = { const endPoint = {
x: config.horizontalLine.end.x, x: config.horizontalLine.start.x + i * config.horizontalMinorTick,
y: config.horizontalLine.end.y 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); 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){ const viewport = cornerstone.getViewport(eventData.enabledElement.element);
context.shadowColor = config.shadowColor; if (!viewport) {
context.shadowBlur = config.shadowBlur; return;
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 const canvasSize = {
function computeScaleBounds(eventData, canvasSize, imageSize, horizontalReduction, verticalReduction) { width: eventData.enabledElement.canvas.width,
height: eventData.enabledElement.canvas.height
};
const imageSize = {
width: eventData.enabledElement.image.width ,
height: eventData.enabledElement.image.height
};
let canvasBounds = { // Distance between intervals is 10mm
left: 0, const verticalIntervalScale = (10.0 / eventData.enabledElement.image.rowPixelSpacing) * eventData.viewport.scale;
top: 0, const horizontalIntervalScale = (10.0 / eventData.enabledElement.image.rowPixelSpacing) * eventData.viewport.scale;
width: canvasSize.width,
height: canvasSize.height
};
const hReduction = horizontalReduction * Math.min(1000, canvasSize.width); // 0.1 and 0.05 gives margin to horizontal and vertical lines
const vReduction = verticalReduction * Math.min(1000, canvasSize.height); const hscaleBounds = computeScaleBounds(eventData, canvasSize, imageSize, 0.25, 0.05);
canvasBounds = { const vscaleBounds = computeScaleBounds(eventData, canvasSize, imageSize, 0.05, 0.15);
left: canvasBounds.left + hReduction,
top: canvasBounds.top + vReduction,
width: canvasBounds.width - 2 * hReduction,
height: canvasBounds.height - 2 * vReduction
};
return { if (!canvasSize.width || !canvasSize.height || !imageSize.width || !imageSize.height || !hscaleBounds || !vscaleBounds) {
topLeft: { return;
x: canvasBounds.left, }
y: canvasBounds.top
const config = {
hscaleBounds,
vscaleBounds,
verticalMinorTick: verticalIntervalScale,
horizontalMinorTick: horizontalIntervalScale,
minorTickLength: 12.5,
majorTickLength: 25,
verticalLine: {
start: {
x: vscaleBounds.bottomRight.x,
y: vscaleBounds.topLeft.y
}, },
bottomRight: { end: {
x: canvasBounds.left + canvasBounds.width, x: vscaleBounds.bottomRight.x,
y: canvasBounds.top + canvasBounds.height y: vscaleBounds.bottomRight.y
} }
}; },
} horizontalLine: {
start: {
function onImageRendered(e, eventData) { x: hscaleBounds.topLeft.x,
y: hscaleBounds.bottomRight.y
// 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: { end: {
start: { x: hscaleBounds.bottomRight.x,
x: hscaleBounds.topLeft.x, y: hscaleBounds.bottomRight.y
y: hscaleBounds.bottomRight.y }
}, },
end: { color: 'white', // TODO: fix this later
x: hscaleBounds.bottomRight.x, lineWidth: cornerstoneTools.toolStyle.getToolWidth(),
y: hscaleBounds.bottomRight.y shadowColor: 'black',
} shadowBlur: 4
}, };
color: 'white', // TODO: fix this later
lineWidth: cornerstoneTools.toolStyle.getToolWidth(),
shadowColor: 'black',
shadowBlur: 4
};
const context = eventData.enabledElement.canvas.getContext('2d'); const context = eventData.enabledElement.canvas.getContext('2d');
context.setTransform(1, 0, 0, 1, 0, 0); context.setTransform(1, 0, 0, 1, 0, 0);
context.save(); context.save();
drawScalebars(context, config); drawScalebars(context, config);
context.restore(); context.restore();
} }
///////// END IMAGE RENDERING /////// ///////// END IMAGE RENDERING ///////
function disable(element) { function disable(element) {
// TODO: displayTool does not have cornerstone.updateImage(element) method to hide tool // TODO: displayTool does not have cornerstone.updateImage(element) method to hide tool
$(element).off('CornerstoneImageRendered', onImageRendered); $(element).off('CornerstoneImageRendered', onImageRendered);
cornerstone.updateImage(element); cornerstone.updateImage(element);
} }
// module exports // module exports
cornerstoneTools.scaleOverlayTool = cornerstoneTools.displayTool(onImageRendered); cornerstoneTools.scaleOverlayTool = cornerstoneTools.displayTool(onImageRendered);
cornerstoneTools.scaleOverlayTool.disable = disable; cornerstoneTools.scaleOverlayTool.disable = disable;
})($, cornerstone, cornerstoneTools);

View File

@ -2,7 +2,7 @@ import { OHIF } from 'meteor/ohif:core';
const removeToolDataWithMeasurementId = (imageId, toolType, measurementId) => { const removeToolDataWithMeasurementId = (imageId, toolType, measurementId) => {
OHIF.log.info('removeToolDataWithMeasurementId'); OHIF.log.info('removeToolDataWithMeasurementId');
const toolState = cornerstoneTools.globalImageIdSpecificToolStateManager.toolState; const toolState = cornerstoneTools.globalImageIdSpecificToolStateManager.saveToolState();
// Find any related toolData // Find any related toolData
if (!toolState[imageId] || !toolState[imageId][toolType]) { if (!toolState[imageId] || !toolState[imageId][toolType]) {
@ -32,6 +32,8 @@ const removeToolDataWithMeasurementId = (imageId, toolType, measurementId) => {
toRemove.forEach(function(index) { toRemove.forEach(function(index) {
toolData.splice(index, 1); toolData.splice(index, 1);
}); });
cornerstoneTools.globalImageIdSpecificToolStateManager.restoreToolState(toolState);
}; };
OHIF.lesiontracker.clearMeasurementTimepointData = (measurementId, timepointId) => { OHIF.lesiontracker.clearMeasurementTimepointData = (measurementId, timepointId) => {

View File

@ -315,7 +315,8 @@ class MeasurementApi {
const measurementNumber = filter.measurementNumber || entries[0].measurementNumber; const measurementNumber = filter.measurementNumber || entries[0].measurementNumber;
// Synchronize the new data with cornerstone tools // Synchronize the new data with cornerstone tools
const toolState = cornerstoneTools.globalImageIdSpecificToolStateManager.toolState; const toolState = cornerstoneTools.globalImageIdSpecificToolStateManager.saveToolState();
_.each(entries, entry => { _.each(entries, entry => {
if (toolState[entry.imageId]) { if (toolState[entry.imageId]) {
const toolData = toolState[entry.imageId][entry.toolType]; const toolData = toolState[entry.imageId][entry.toolType];
@ -331,6 +332,8 @@ class MeasurementApi {
} }
}); });
cornerstoneTools.globalImageIdSpecificToolStateManager.restoreToolState(toolState);
// Synchronize the updated measurements with Cornerstone Tools // Synchronize the updated measurements with Cornerstone Tools
// toolData to make sure the displayed measurements show 'Target X' correctly // toolData to make sure the displayed measurements show 'Target X' correctly
const syncFilter = _.clone(filter); const syncFilter = _.clone(filter);

View File

@ -107,7 +107,6 @@ class MeasurementHandlers {
Collection._c2._simpleSchema.clean(measurement); Collection._c2._simpleSchema.clean(measurement);
// Insert the new measurement into the collection // Insert the new measurement into the collection
console.log(measurement);
Collection.update(measurementId, { Collection.update(measurementId, {
$set: measurement $set: measurement
}); });

View File

@ -10,7 +10,8 @@ import { OHIF } from 'meteor/ohif:core';
function activateTool(measurementData) { function activateTool(measurementData) {
const toolType = measurementData.toolType; const toolType = measurementData.toolType;
const imageId = measurementData.imageId; const imageId = measurementData.imageId;
const toolState = cornerstoneTools.globalImageIdSpecificToolStateManager.toolState; const toolState = cornerstoneTools.globalImageIdSpecificToolStateManager.saveToolState();
const toolData = toolState[imageId][toolType]; const toolData = toolState[imageId][toolType];
if (!toolData || !toolData.data || !toolData.data.length) { if (!toolData || !toolData.data || !toolData.data.length) {
return; return;
@ -19,7 +20,11 @@ function activateTool(measurementData) {
// When a measurement is selected, it will be activated in Cornerstone's // When a measurement is selected, it will be activated in Cornerstone's
// tool data // tool data
const tool = toolData.data.find(data => data._id === measurementData._id); const tool = toolData.data.find(data => data._id === measurementData._id);
tool.active = true; if (tool) {
tool.active = true;
}
cornerstoneTools.globalImageIdSpecificToolStateManager.restoreToolState(toolState);
}; };

View File

@ -1,24 +1,26 @@
import { OHIF } from 'meteor/ohif:core'; import { OHIF } from 'meteor/ohif:core'
/** /**
* Sets all tool data entries value for 'active' to false * Sets all tool data entries value for 'active' to false
* This is used to remove the active color on entire sets of tools * This is used to remove the active color on entire sets of tools
*/ */
OHIF.measurements.deactivateAllToolData = () => { OHIF.measurements.deactivateAllToolData = () => {
const toolState = cornerstoneTools.globalImageIdSpecificToolStateManager.toolState; const toolState = cornerstoneTools.globalImageIdSpecificToolStateManager.saveToolState()
Object.keys(toolState).forEach(imageId => { Object.keys(toolState).forEach(imageId => {
const toolData = toolState[imageId]; const toolData = toolState[imageId];
Object.keys(toolData).forEach(toolType => { Object.keys(toolData).forEach(toolType => {
const specificToolData = toolData[toolType]; const specificToolData = toolData[toolType]
if (!specificToolData || !specificToolData.data || !specificToolData.data.length) { if (!specificToolData || !specificToolData.data || !specificToolData.data.length) {
return; return
} }
specificToolData.data.forEach(data => { specificToolData.data.forEach(data => {
data.active = false; data.active = false
}); });
}); });
}) });
};
cornerstoneTools.globalImageIdSpecificToolStateManager.restoreToolState(toolState)
}

View File

@ -82,8 +82,6 @@ OHIF.measurements.jumpToRowItem = (rowItem, timepoints) => {
// Deactivate stack synchronizer because it will be re-activated later // Deactivate stack synchronizer because it will be re-activated later
OHIF.viewer.stackImagePositionOffsetSynchronizer.deactivate(); OHIF.viewer.stackImagePositionOffsetSynchronizer.deactivate();
console.log('jumpToRowItem');
// Retrieve the timepoints that are currently being displayed in the // Retrieve the timepoints that are currently being displayed in the
// Measurement Table // Measurement Table
const numTimepoints = Math.max(timepoints.length, 1); const numTimepoints = Math.max(timepoints.length, 1);
@ -124,7 +122,7 @@ OHIF.measurements.jumpToRowItem = (rowItem, timepoints) => {
try { try {
enabledElement = cornerstone.getEnabledElement(element) enabledElement = cornerstone.getEnabledElement(element)
} catch(error) { } catch(error) {
OHIF.log.warn(error); continue;
} }
if (enabledElement && enabledElement.image) { if (enabledElement && enabledElement.image) {

View File

@ -4,7 +4,7 @@ import { OHIF } from 'meteor/ohif:core';
OHIF.measurements.syncMeasurementAndToolData = measurement => { OHIF.measurements.syncMeasurementAndToolData = measurement => {
OHIF.log.info('syncMeasurementAndToolData'); OHIF.log.info('syncMeasurementAndToolData');
const toolState = cornerstoneTools.globalImageIdSpecificToolStateManager.toolState; const toolState = cornerstoneTools.globalImageIdSpecificToolStateManager.saveToolState();
const imageId = measurement.imageId; const imageId = measurement.imageId;
const toolType = measurement.toolType; const toolType = measurement.toolType;
@ -55,4 +55,6 @@ OHIF.measurements.syncMeasurementAndToolData = measurement => {
// Add the MeasurementData into the toolData for this imageId // Add the MeasurementData into the toolData for this imageId
toolState[imageId][toolType].data.push(measurement); toolState[imageId][toolType].data.push(measurement);
cornerstoneTools.globalImageIdSpecificToolStateManager.restoreToolState(toolState);
}; };

View File

@ -71,4 +71,7 @@ Template.viewerMain.onDestroyed(() => {
// Stop prefetching when we close the viewer // Stop prefetching when we close the viewer
instance.studyPrefetcher.destroy(); instance.studyPrefetcher.destroy();
// Clear references to all stacks in the StackManager
OHIF.viewerbase.stackManager.clearStacks();
}); });

View File

@ -10,7 +10,7 @@ import { OHIF } from 'meteor/ohif:core';
*/ */
export const prepareViewerData = ({ studyInstanceUids, timepointId, timepointsFilter={} }) => { export const prepareViewerData = ({ studyInstanceUids, timepointId, timepointsFilter={} }) => {
// Clear the cornerstone tool data to sync the measurements with the measurements API // Clear the cornerstone tool data to sync the measurements with the measurements API
cornerstoneTools.globalImageIdSpecificToolStateManager = cornerstoneTools.newImageIdSpecificToolStateManager(); cornerstoneTools.globalImageIdSpecificToolStateManager.restoreToolState({});
// Retrieve the studies metadata // Retrieve the studies metadata
const promise = new Promise((resolve, reject) => { const promise = new Promise((resolve, reject) => {
@ -109,7 +109,7 @@ const getDataFromTimepoint = timepoint => {
return { return {
studyInstanceUids: relatedStudies, studyInstanceUids: relatedStudies,
timepointIds: timepointIds timepointIds
}; };
}; };