2019-10-09 16:23:14 +02:00
|
|
|
import OHIF from '@ohif/core';
|
|
|
|
|
import cornerstone from 'cornerstone-core';
|
|
|
|
|
import csTools from 'cornerstone-tools';
|
|
|
|
|
import initCornerstoneTools from './initCornerstoneTools.js';
|
2019-11-08 13:55:56 +01:00
|
|
|
import queryString from 'query-string';
|
|
|
|
|
|
2019-11-13 21:02:14 +01:00
|
|
|
function fallbackMetaDataProvider(type, imageId) {
|
2019-11-08 13:55:56 +01:00
|
|
|
if (!imageId.includes('wado?requestType=WADO')) {
|
2019-11-13 21:02:14 +01:00
|
|
|
return;
|
2019-11-08 13:55:56 +01:00
|
|
|
}
|
|
|
|
|
|
2019-11-13 21:02:14 +01:00
|
|
|
// If you call for an WADO-URI imageId and get no
|
2019-11-08 13:55:56 +01:00
|
|
|
// metadata, try reformatting to WADO-RS imageId
|
|
|
|
|
const qs = queryString.parse(imageId);
|
2019-11-13 21:02:14 +01:00
|
|
|
const wadoRoot = window.store.getState().servers.servers[0].wadoRoot;
|
|
|
|
|
const wadoRsImageId = `wadors:${wadoRoot}/studies/${qs.studyUID}/series/${
|
|
|
|
|
qs.seriesUID
|
|
|
|
|
}/instances/${qs.objectUID}/frames/${qs.frame || 1}`;
|
2019-11-08 13:55:56 +01:00
|
|
|
|
|
|
|
|
return cornerstone.metaData.get(type, wadoRsImageId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Add this fallback provider with a low priority so it is handled last
|
|
|
|
|
cornerstone.metaData.addProvider(fallbackMetaDataProvider, -1);
|
|
|
|
|
|
2019-10-09 16:23:14 +02:00
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @param {object} configuration
|
|
|
|
|
* @param {Object|Array} configuration.csToolsConfig
|
|
|
|
|
*/
|
2019-11-13 21:02:14 +01:00
|
|
|
export default function init({ serviceManager, configuration = {} }) {
|
2019-10-09 16:23:14 +02:00
|
|
|
const { csToolsConfig } = configuration;
|
|
|
|
|
const { StackManager } = OHIF.utils;
|
|
|
|
|
const metadataProvider = new OHIF.cornerstone.MetadataProvider();
|
|
|
|
|
|
|
|
|
|
// ~~ Set our MetadataProvider
|
|
|
|
|
cornerstone.metaData.addProvider(
|
|
|
|
|
metadataProvider.provider.bind(metadataProvider)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
StackManager.setMetadataProvider(metadataProvider);
|
|
|
|
|
|
|
|
|
|
// ~~
|
|
|
|
|
const defaultCsToolsConfig = csToolsConfig || {
|
|
|
|
|
globalToolSyncEnabled: true,
|
|
|
|
|
showSVGCursors: true,
|
|
|
|
|
autoResizeViewports: false,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
initCornerstoneTools(defaultCsToolsConfig);
|
|
|
|
|
|
|
|
|
|
// ~~ Toooools 🙌
|
|
|
|
|
const {
|
|
|
|
|
PanTool,
|
|
|
|
|
ZoomTool,
|
|
|
|
|
WwwcTool,
|
|
|
|
|
MagnifyTool,
|
|
|
|
|
StackScrollTool,
|
|
|
|
|
StackScrollMouseWheelTool,
|
|
|
|
|
// Touch
|
|
|
|
|
PanMultiTouchTool,
|
|
|
|
|
ZoomTouchPinchTool,
|
|
|
|
|
// Annotations
|
|
|
|
|
EraserTool,
|
|
|
|
|
ArrowAnnotateTool,
|
|
|
|
|
BidirectionalTool,
|
|
|
|
|
LengthTool,
|
|
|
|
|
AngleTool,
|
|
|
|
|
FreehandRoiTool,
|
|
|
|
|
EllipticalRoiTool,
|
|
|
|
|
DragProbeTool,
|
|
|
|
|
RectangleRoiTool,
|
|
|
|
|
// Segmentation
|
|
|
|
|
BrushTool,
|
|
|
|
|
} = csTools;
|
|
|
|
|
const tools = [
|
|
|
|
|
PanTool,
|
|
|
|
|
ZoomTool,
|
|
|
|
|
WwwcTool,
|
|
|
|
|
MagnifyTool,
|
|
|
|
|
StackScrollTool,
|
|
|
|
|
StackScrollMouseWheelTool,
|
|
|
|
|
// Touch
|
|
|
|
|
PanMultiTouchTool,
|
|
|
|
|
ZoomTouchPinchTool,
|
|
|
|
|
// Annotations
|
|
|
|
|
EraserTool,
|
|
|
|
|
ArrowAnnotateTool,
|
|
|
|
|
BidirectionalTool,
|
|
|
|
|
LengthTool,
|
|
|
|
|
AngleTool,
|
|
|
|
|
FreehandRoiTool,
|
|
|
|
|
EllipticalRoiTool,
|
|
|
|
|
DragProbeTool,
|
|
|
|
|
RectangleRoiTool,
|
|
|
|
|
// Segmentation
|
|
|
|
|
BrushTool,
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
tools.forEach(tool => csTools.addTool(tool));
|
2019-11-13 21:02:14 +01:00
|
|
|
|
2019-10-09 16:23:14 +02:00
|
|
|
csTools.setToolActive('Pan', { mouseButtonMask: 4 });
|
|
|
|
|
csTools.setToolActive('Zoom', { mouseButtonMask: 2 });
|
|
|
|
|
csTools.setToolActive('Wwwc', { mouseButtonMask: 1 });
|
|
|
|
|
csTools.setToolActive('StackScrollMouseWheel', {}); // TODO: Empty options should not be required
|
|
|
|
|
csTools.setToolActive('PanMultiTouch', { pointers: 2 }); // TODO: Better error if no options
|
|
|
|
|
csTools.setToolActive('ZoomTouchPinch', {});
|
|
|
|
|
}
|