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 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,
|
||||||
|
|||||||
@ -1,16 +1,12 @@
|
|||||||
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 = {
|
||||||
'use strict';
|
|
||||||
|
|
||||||
// Delete a lesion if Ctrl+D or DELETE is pressed while a lesion is selected
|
|
||||||
var keys = {
|
|
||||||
D: 68,
|
D: 68,
|
||||||
DELETE: 46
|
DELETE: 46
|
||||||
};
|
};
|
||||||
|
|
||||||
function removeMeasurementTimepoint(data, index, toolType, element) {
|
function removeMeasurementTimepoint(data, index, toolType, element) {
|
||||||
var imageId = data.imageId;
|
var imageId = data.imageId;
|
||||||
if (!imageId) {
|
if (!imageId) {
|
||||||
var enabledElement = cornerstone.getEnabledElement(element);
|
var enabledElement = cornerstone.getEnabledElement(element);
|
||||||
@ -19,10 +15,10 @@ import { Viewerbase } from 'meteor/ohif:viewerbase';
|
|||||||
|
|
||||||
cornerstoneTools.removeToolState(element, toolType, data);
|
cornerstoneTools.removeToolState(element, toolType, data);
|
||||||
cornerstone.updateImage(element);
|
cornerstone.updateImage(element);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO = Check if we have the same function already in Cornerstone Tools
|
// TODO = Check if we have the same function already in Cornerstone Tools
|
||||||
function getNearbyToolData(element, coords, toolTypes) {
|
function getNearbyToolData(element, coords, toolTypes) {
|
||||||
var allTools = Viewerbase.toolManager.getTools();
|
var allTools = Viewerbase.toolManager.getTools();
|
||||||
var pointNearTool = false;
|
var pointNearTool = false;
|
||||||
var touchDevice = Viewerbase.helpers.isTouchDevice();
|
var touchDevice = Viewerbase.helpers.isTouchDevice();
|
||||||
@ -61,9 +57,9 @@ import { Viewerbase } from 'meteor/ohif:viewerbase';
|
|||||||
});
|
});
|
||||||
|
|
||||||
return pointNearTool ? nearbyTool : undefined;
|
return pointNearTool ? nearbyTool : undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
function keyDownCallback(e, eventData) {
|
function keyDownCallback(e, eventData) {
|
||||||
var keyCode = eventData.which;
|
var keyCode = eventData.which;
|
||||||
|
|
||||||
if (keyCode === keys.DELETE ||
|
if (keyCode === keys.DELETE ||
|
||||||
@ -91,9 +87,7 @@ import { Viewerbase } from 'meteor/ohif:viewerbase';
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// module/private exports
|
// module/private exports
|
||||||
cornerstoneTools.deleteLesionKeyboardTool = cornerstoneTools.keyboardTool(keyDownCallback);
|
cornerstoneTools.deleteLesionKeyboardTool = cornerstoneTools.keyboardTool(keyDownCallback);
|
||||||
|
|
||||||
})(cornerstoneTools);
|
|
||||||
|
|||||||
@ -1,14 +1,9 @@
|
|||||||
|
function drawLine(context, startPoint, endPoint, config) {
|
||||||
(function($, cornerstone, cornerstoneTools) {
|
|
||||||
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
function drawLine(context, startPoint, endPoint, config) {
|
|
||||||
context.moveTo(startPoint.x, startPoint.y);
|
context.moveTo(startPoint.x, startPoint.y);
|
||||||
context.lineTo(endPoint.x, endPoint.y);
|
context.lineTo(endPoint.x, endPoint.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
function drawVerticalScalebarIntervals (context, config) {
|
function drawVerticalScalebarIntervals (context, config) {
|
||||||
let i = 0;
|
let i = 0;
|
||||||
|
|
||||||
while (config.verticalLine.start.y + i * config.verticalMinorTick <= config.vscaleBounds.bottomRight.y) {
|
while (config.verticalLine.start.y + i * config.verticalMinorTick <= config.vscaleBounds.bottomRight.y) {
|
||||||
@ -34,9 +29,9 @@
|
|||||||
|
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function drawHorizontalScalebarIntervals (context, config) {
|
function drawHorizontalScalebarIntervals (context, config) {
|
||||||
let i = 0;
|
let i = 0;
|
||||||
|
|
||||||
while (config.horizontalLine.start.x + i * config.horizontalMinorTick <= config.hscaleBounds.bottomRight.x) {
|
while (config.horizontalLine.start.x + i * config.horizontalMinorTick <= config.hscaleBounds.bottomRight.x) {
|
||||||
@ -61,9 +56,9 @@
|
|||||||
|
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function drawVerticalScalebar(context, config) {
|
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
|
||||||
@ -81,9 +76,9 @@
|
|||||||
drawVerticalScalebarIntervals(context, config);
|
drawVerticalScalebarIntervals(context, config);
|
||||||
|
|
||||||
context.stroke();
|
context.stroke();
|
||||||
}
|
}
|
||||||
|
|
||||||
function drawHorizontalScalebar(context, config) {
|
function drawHorizontalScalebar(context, config) {
|
||||||
const startPoint = {
|
const startPoint = {
|
||||||
x: config.horizontalLine.start.x,
|
x: config.horizontalLine.start.x,
|
||||||
y: config.horizontalLine.start.y
|
y: config.horizontalLine.start.y
|
||||||
@ -95,9 +90,9 @@
|
|||||||
|
|
||||||
drawLine(context, startPoint, endPoint, config);
|
drawLine(context, startPoint, endPoint, config);
|
||||||
drawHorizontalScalebarIntervals(context, config);
|
drawHorizontalScalebarIntervals(context, config);
|
||||||
}
|
}
|
||||||
|
|
||||||
function drawScalebars(context, config){
|
function drawScalebars(context, config){
|
||||||
context.shadowColor = config.shadowColor;
|
context.shadowColor = config.shadowColor;
|
||||||
context.shadowBlur = config.shadowBlur;
|
context.shadowBlur = config.shadowBlur;
|
||||||
context.strokeStyle = config.color;
|
context.strokeStyle = config.color;
|
||||||
@ -107,10 +102,10 @@
|
|||||||
drawVerticalScalebar(context, config);
|
drawVerticalScalebar(context, config);
|
||||||
drawHorizontalScalebar(context, config);
|
drawHorizontalScalebar(context, config);
|
||||||
context.stroke();
|
context.stroke();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Computes the max bound for scales on the image
|
// Computes the max bound for scales on the image
|
||||||
function computeScaleBounds(eventData, canvasSize, imageSize, horizontalReduction, verticalReduction) {
|
function computeScaleBounds(eventData, canvasSize, imageSize, horizontalReduction, verticalReduction) {
|
||||||
|
|
||||||
let canvasBounds = {
|
let canvasBounds = {
|
||||||
left: 0,
|
left: 0,
|
||||||
@ -138,9 +133,9 @@
|
|||||||
y: canvasBounds.top + canvasBounds.height
|
y: canvasBounds.top + canvasBounds.height
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function onImageRendered(e, eventData) {
|
function onImageRendered(e, eventData) {
|
||||||
|
|
||||||
// Check whether pixel spacing is defined
|
// Check whether pixel spacing is defined
|
||||||
if (!eventData.image.rowPixelSpacing || !eventData.image.columnPixelSpacing) {
|
if (!eventData.image.rowPixelSpacing || !eventData.image.columnPixelSpacing) {
|
||||||
@ -174,8 +169,8 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
const config = {
|
const config = {
|
||||||
hscaleBounds: hscaleBounds,
|
hscaleBounds,
|
||||||
vscaleBounds: vscaleBounds,
|
vscaleBounds,
|
||||||
verticalMinorTick: verticalIntervalScale,
|
verticalMinorTick: verticalIntervalScale,
|
||||||
horizontalMinorTick: horizontalIntervalScale,
|
horizontalMinorTick: horizontalIntervalScale,
|
||||||
minorTickLength: 12.5,
|
minorTickLength: 12.5,
|
||||||
@ -212,18 +207,16 @@
|
|||||||
|
|
||||||
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);
|
|
||||||
|
|||||||
@ -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) => {
|
||||||
|
|||||||
@ -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);
|
||||||
|
|||||||
@ -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
|
||||||
});
|
});
|
||||||
|
|||||||
@ -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);
|
||||||
|
if (tool) {
|
||||||
tool.active = true;
|
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
|
* 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)
|
||||||
|
}
|
||||||
|
|||||||
@ -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) {
|
||||||
|
|||||||
@ -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);
|
||||||
};
|
};
|
||||||
|
|||||||
@ -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();
|
||||||
});
|
});
|
||||||
|
|||||||
@ -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
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user