Switch toolState usage since ES6 modules are read-only
This commit is contained in:
parent
ddef3c4710
commit
27296a8bca
@ -16,8 +16,6 @@ import * as cornerstoneMath from 'cornerstone-math';
|
||||
import * as cornerstoneWADOImageLoader from 'cornerstone-wado-image-loader';
|
||||
import * as dicomParser from 'dicom-parser';
|
||||
|
||||
debugger;
|
||||
|
||||
export {
|
||||
cornerstone,
|
||||
cornerstoneTools,
|
||||
|
||||
@ -1,16 +1,12 @@
|
||||
import { Viewerbase } from 'meteor/ohif:viewerbase';
|
||||
|
||||
(function(cornerstoneTools) {
|
||||
|
||||
'use strict';
|
||||
|
||||
// Delete a lesion if Ctrl+D or DELETE is pressed while a lesion is selected
|
||||
var keys = {
|
||||
// Delete a lesion if Ctrl+D or DELETE is pressed while a lesion is selected
|
||||
var keys = {
|
||||
D: 68,
|
||||
DELETE: 46
|
||||
};
|
||||
};
|
||||
|
||||
function removeMeasurementTimepoint(data, index, toolType, element) {
|
||||
function removeMeasurementTimepoint(data, index, toolType, element) {
|
||||
var imageId = data.imageId;
|
||||
if (!imageId) {
|
||||
var enabledElement = cornerstone.getEnabledElement(element);
|
||||
@ -19,10 +15,10 @@ import { Viewerbase } from 'meteor/ohif:viewerbase';
|
||||
|
||||
cornerstoneTools.removeToolState(element, toolType, data);
|
||||
cornerstone.updateImage(element);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO = Check if we have the same function already in Cornerstone Tools
|
||||
function getNearbyToolData(element, coords, toolTypes) {
|
||||
// TODO = Check if we have the same function already in Cornerstone Tools
|
||||
function getNearbyToolData(element, coords, toolTypes) {
|
||||
var allTools = Viewerbase.toolManager.getTools();
|
||||
var pointNearTool = false;
|
||||
var touchDevice = Viewerbase.helpers.isTouchDevice();
|
||||
@ -61,9 +57,9 @@ import { Viewerbase } from 'meteor/ohif:viewerbase';
|
||||
});
|
||||
|
||||
return pointNearTool ? nearbyTool : undefined;
|
||||
}
|
||||
}
|
||||
|
||||
function keyDownCallback(e, eventData) {
|
||||
function keyDownCallback(e, eventData) {
|
||||
var keyCode = eventData.which;
|
||||
|
||||
if (keyCode === keys.DELETE ||
|
||||
@ -91,9 +87,7 @@ import { Viewerbase } from 'meteor/ohif:viewerbase';
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// module/private exports
|
||||
cornerstoneTools.deleteLesionKeyboardTool = cornerstoneTools.keyboardTool(keyDownCallback);
|
||||
|
||||
})(cornerstoneTools);
|
||||
// module/private exports
|
||||
cornerstoneTools.deleteLesionKeyboardTool = cornerstoneTools.keyboardTool(keyDownCallback);
|
||||
|
||||
@ -1,14 +1,9 @@
|
||||
|
||||
(function($, cornerstone, cornerstoneTools) {
|
||||
|
||||
'use strict';
|
||||
|
||||
function drawLine(context, startPoint, endPoint, config) {
|
||||
function drawLine(context, startPoint, endPoint, config) {
|
||||
context.moveTo(startPoint.x, startPoint.y);
|
||||
context.lineTo(endPoint.x, endPoint.y);
|
||||
}
|
||||
}
|
||||
|
||||
function drawVerticalScalebarIntervals (context, config) {
|
||||
function drawVerticalScalebarIntervals (context, config) {
|
||||
let i = 0;
|
||||
|
||||
while (config.verticalLine.start.y + i * config.verticalMinorTick <= config.vscaleBounds.bottomRight.y) {
|
||||
@ -34,9 +29,9 @@
|
||||
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function drawHorizontalScalebarIntervals (context, config) {
|
||||
function drawHorizontalScalebarIntervals (context, config) {
|
||||
let i = 0;
|
||||
|
||||
while (config.horizontalLine.start.x + i * config.horizontalMinorTick <= config.hscaleBounds.bottomRight.x) {
|
||||
@ -61,9 +56,9 @@
|
||||
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function drawVerticalScalebar(context, config) {
|
||||
function drawVerticalScalebar(context, config) {
|
||||
const startPoint = {
|
||||
x: config.verticalLine.start.x,
|
||||
y: config.verticalLine.start.y
|
||||
@ -81,9 +76,9 @@
|
||||
drawVerticalScalebarIntervals(context, config);
|
||||
|
||||
context.stroke();
|
||||
}
|
||||
}
|
||||
|
||||
function drawHorizontalScalebar(context, config) {
|
||||
function drawHorizontalScalebar(context, config) {
|
||||
const startPoint = {
|
||||
x: config.horizontalLine.start.x,
|
||||
y: config.horizontalLine.start.y
|
||||
@ -95,9 +90,9 @@
|
||||
|
||||
drawLine(context, startPoint, endPoint, config);
|
||||
drawHorizontalScalebarIntervals(context, config);
|
||||
}
|
||||
}
|
||||
|
||||
function drawScalebars(context, config){
|
||||
function drawScalebars(context, config){
|
||||
context.shadowColor = config.shadowColor;
|
||||
context.shadowBlur = config.shadowBlur;
|
||||
context.strokeStyle = config.color;
|
||||
@ -107,10 +102,10 @@
|
||||
drawVerticalScalebar(context, config);
|
||||
drawHorizontalScalebar(context, config);
|
||||
context.stroke();
|
||||
}
|
||||
}
|
||||
|
||||
// Computes the max bound for scales on the image
|
||||
function computeScaleBounds(eventData, canvasSize, imageSize, horizontalReduction, verticalReduction) {
|
||||
// Computes the max bound for scales on the image
|
||||
function computeScaleBounds(eventData, canvasSize, imageSize, horizontalReduction, verticalReduction) {
|
||||
|
||||
let canvasBounds = {
|
||||
left: 0,
|
||||
@ -138,9 +133,9 @@
|
||||
y: canvasBounds.top + canvasBounds.height
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
function onImageRendered(e, eventData) {
|
||||
function onImageRendered(e, eventData) {
|
||||
|
||||
// Check whether pixel spacing is defined
|
||||
if (!eventData.image.rowPixelSpacing || !eventData.image.columnPixelSpacing) {
|
||||
@ -174,8 +169,8 @@
|
||||
}
|
||||
|
||||
const config = {
|
||||
hscaleBounds: hscaleBounds,
|
||||
vscaleBounds: vscaleBounds,
|
||||
hscaleBounds,
|
||||
vscaleBounds,
|
||||
verticalMinorTick: verticalIntervalScale,
|
||||
horizontalMinorTick: horizontalIntervalScale,
|
||||
minorTickLength: 12.5,
|
||||
@ -212,18 +207,16 @@
|
||||
|
||||
drawScalebars(context, config);
|
||||
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
|
||||
$(element).off('CornerstoneImageRendered', onImageRendered);
|
||||
cornerstone.updateImage(element);
|
||||
}
|
||||
}
|
||||
|
||||
// module exports
|
||||
cornerstoneTools.scaleOverlayTool = cornerstoneTools.displayTool(onImageRendered);
|
||||
cornerstoneTools.scaleOverlayTool.disable = disable;
|
||||
|
||||
})($, cornerstone, cornerstoneTools);
|
||||
// module exports
|
||||
cornerstoneTools.scaleOverlayTool = cornerstoneTools.displayTool(onImageRendered);
|
||||
cornerstoneTools.scaleOverlayTool.disable = disable;
|
||||
|
||||
@ -2,7 +2,7 @@ import { OHIF } from 'meteor/ohif:core';
|
||||
|
||||
const removeToolDataWithMeasurementId = (imageId, toolType, measurementId) => {
|
||||
OHIF.log.info('removeToolDataWithMeasurementId');
|
||||
const toolState = cornerstoneTools.globalImageIdSpecificToolStateManager.toolState;
|
||||
const toolState = cornerstoneTools.globalImageIdSpecificToolStateManager.saveToolState();
|
||||
|
||||
// Find any related toolData
|
||||
if (!toolState[imageId] || !toolState[imageId][toolType]) {
|
||||
@ -32,6 +32,8 @@ const removeToolDataWithMeasurementId = (imageId, toolType, measurementId) => {
|
||||
toRemove.forEach(function(index) {
|
||||
toolData.splice(index, 1);
|
||||
});
|
||||
|
||||
cornerstoneTools.globalImageIdSpecificToolStateManager.restoreToolState(toolState);
|
||||
};
|
||||
|
||||
OHIF.lesiontracker.clearMeasurementTimepointData = (measurementId, timepointId) => {
|
||||
|
||||
@ -315,7 +315,8 @@ class MeasurementApi {
|
||||
const measurementNumber = filter.measurementNumber || entries[0].measurementNumber;
|
||||
|
||||
// Synchronize the new data with cornerstone tools
|
||||
const toolState = cornerstoneTools.globalImageIdSpecificToolStateManager.toolState;
|
||||
const toolState = cornerstoneTools.globalImageIdSpecificToolStateManager.saveToolState();
|
||||
|
||||
_.each(entries, entry => {
|
||||
if (toolState[entry.imageId]) {
|
||||
const toolData = toolState[entry.imageId][entry.toolType];
|
||||
@ -331,6 +332,8 @@ class MeasurementApi {
|
||||
}
|
||||
});
|
||||
|
||||
cornerstoneTools.globalImageIdSpecificToolStateManager.restoreToolState(toolState);
|
||||
|
||||
// Synchronize the updated measurements with Cornerstone Tools
|
||||
// toolData to make sure the displayed measurements show 'Target X' correctly
|
||||
const syncFilter = _.clone(filter);
|
||||
|
||||
@ -107,7 +107,6 @@ class MeasurementHandlers {
|
||||
Collection._c2._simpleSchema.clean(measurement);
|
||||
|
||||
// Insert the new measurement into the collection
|
||||
console.log(measurement);
|
||||
Collection.update(measurementId, {
|
||||
$set: measurement
|
||||
});
|
||||
|
||||
@ -10,7 +10,8 @@ import { OHIF } from 'meteor/ohif:core';
|
||||
function activateTool(measurementData) {
|
||||
const toolType = measurementData.toolType;
|
||||
const imageId = measurementData.imageId;
|
||||
const toolState = cornerstoneTools.globalImageIdSpecificToolStateManager.toolState;
|
||||
const toolState = cornerstoneTools.globalImageIdSpecificToolStateManager.saveToolState();
|
||||
|
||||
const toolData = toolState[imageId][toolType];
|
||||
if (!toolData || !toolData.data || !toolData.data.length) {
|
||||
return;
|
||||
@ -19,7 +20,11 @@ function activateTool(measurementData) {
|
||||
// When a measurement is selected, it will be activated in Cornerstone's
|
||||
// tool data
|
||||
const tool = toolData.data.find(data => data._id === measurementData._id);
|
||||
if (tool) {
|
||||
tool.active = true;
|
||||
}
|
||||
|
||||
cornerstoneTools.globalImageIdSpecificToolStateManager.restoreToolState(toolState);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -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
|
||||
* This is used to remove the active color on entire sets of tools
|
||||
*/
|
||||
OHIF.measurements.deactivateAllToolData = () => {
|
||||
const toolState = cornerstoneTools.globalImageIdSpecificToolStateManager.toolState;
|
||||
const toolState = cornerstoneTools.globalImageIdSpecificToolStateManager.saveToolState()
|
||||
|
||||
Object.keys(toolState).forEach(imageId => {
|
||||
const toolData = toolState[imageId];
|
||||
|
||||
Object.keys(toolData).forEach(toolType => {
|
||||
const specificToolData = toolData[toolType];
|
||||
const specificToolData = toolData[toolType]
|
||||
if (!specificToolData || !specificToolData.data || !specificToolData.data.length) {
|
||||
return;
|
||||
return
|
||||
}
|
||||
|
||||
specificToolData.data.forEach(data => {
|
||||
data.active = false;
|
||||
data.active = false
|
||||
});
|
||||
});
|
||||
})
|
||||
};
|
||||
});
|
||||
|
||||
cornerstoneTools.globalImageIdSpecificToolStateManager.restoreToolState(toolState)
|
||||
}
|
||||
|
||||
@ -82,8 +82,6 @@ OHIF.measurements.jumpToRowItem = (rowItem, timepoints) => {
|
||||
// Deactivate stack synchronizer because it will be re-activated later
|
||||
OHIF.viewer.stackImagePositionOffsetSynchronizer.deactivate();
|
||||
|
||||
console.log('jumpToRowItem');
|
||||
|
||||
// Retrieve the timepoints that are currently being displayed in the
|
||||
// Measurement Table
|
||||
const numTimepoints = Math.max(timepoints.length, 1);
|
||||
@ -124,7 +122,7 @@ OHIF.measurements.jumpToRowItem = (rowItem, timepoints) => {
|
||||
try {
|
||||
enabledElement = cornerstone.getEnabledElement(element)
|
||||
} catch(error) {
|
||||
OHIF.log.warn(error);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (enabledElement && enabledElement.image) {
|
||||
|
||||
@ -4,7 +4,7 @@ import { OHIF } from 'meteor/ohif:core';
|
||||
OHIF.measurements.syncMeasurementAndToolData = measurement => {
|
||||
OHIF.log.info('syncMeasurementAndToolData');
|
||||
|
||||
const toolState = cornerstoneTools.globalImageIdSpecificToolStateManager.toolState;
|
||||
const toolState = cornerstoneTools.globalImageIdSpecificToolStateManager.saveToolState();
|
||||
const imageId = measurement.imageId;
|
||||
const toolType = measurement.toolType;
|
||||
|
||||
@ -55,4 +55,6 @@ OHIF.measurements.syncMeasurementAndToolData = measurement => {
|
||||
|
||||
// Add the MeasurementData into the toolData for this imageId
|
||||
toolState[imageId][toolType].data.push(measurement);
|
||||
|
||||
cornerstoneTools.globalImageIdSpecificToolStateManager.restoreToolState(toolState);
|
||||
};
|
||||
|
||||
@ -71,4 +71,7 @@ Template.viewerMain.onDestroyed(() => {
|
||||
|
||||
// Stop prefetching when we close the viewer
|
||||
instance.studyPrefetcher.destroy();
|
||||
|
||||
// Clear references to all stacks in the StackManager
|
||||
OHIF.viewerbase.stackManager.clearStacks();
|
||||
});
|
||||
|
||||
@ -10,7 +10,7 @@ import { OHIF } from 'meteor/ohif:core';
|
||||
*/
|
||||
export const prepareViewerData = ({ studyInstanceUids, timepointId, timepointsFilter={} }) => {
|
||||
// Clear the cornerstone tool data to sync the measurements with the measurements API
|
||||
cornerstoneTools.globalImageIdSpecificToolStateManager = cornerstoneTools.newImageIdSpecificToolStateManager();
|
||||
cornerstoneTools.globalImageIdSpecificToolStateManager.restoreToolState({});
|
||||
|
||||
// Retrieve the studies metadata
|
||||
const promise = new Promise((resolve, reject) => {
|
||||
@ -109,7 +109,7 @@ const getDataFromTimepoint = timepoint => {
|
||||
|
||||
return {
|
||||
studyInstanceUids: relatedStudies,
|
||||
timepointIds: timepointIds
|
||||
timepointIds
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user