Removing ohif-cornerstone as a dependency for ohif-viewerbase (Final step)
This commit is contained in:
1 parent
b866e6e6c7
commit
c2c8a43c3a
18 files changed
+436
-370
No files matched your search
+21
-44
@@ -14,7 +14,6 @@ import { updateCrosshairsSynchronizer } from '../../../lib/updateCrosshairsSynch
|
||||
import { toolManager } from '../../../lib/toolManager';
|
||||
import { updateOrientationMarkers } from '../../../lib/updateOrientationMarkers';
|
||||
import { getInstanceClassDefaultViewport } from '../../../lib/instanceClassSpecificViewport';
|
||||
import { updateMetaData } from '../../../lib/metaDataProvider';
|
||||
import { OHIFError } from '../../../lib/classes/OHIFError';
|
||||
|
||||
const allCornerstoneEvents = 'CornerstoneToolsMouseDown CornerstoneToolsMouseDownActivate ' +
|
||||
@@ -110,7 +109,7 @@ const loadDisplaySetIntoViewport = (data, templateData) => {
|
||||
// The ViewportLoading object relates the viewport elements with whichever
|
||||
// image is currently being loaded into them. This is useful so that we can
|
||||
// place progress (download %) for each image inside the proper viewports.
|
||||
ViewportLoading[viewportIndex] = imageId;
|
||||
window.ViewportLoading[viewportIndex] = imageId;
|
||||
|
||||
// Enable Cornerstone for the viewport element
|
||||
const options = {
|
||||
@@ -159,6 +158,14 @@ const loadDisplaySetIntoViewport = (data, templateData) => {
|
||||
}
|
||||
}
|
||||
|
||||
// Additional tasks for metadata provider. If using your own
|
||||
// metadata provider, this may not be necessary.
|
||||
// updateMetadata is important, though, to update image metadata that
|
||||
// for any reason was missing some information such as rows, columns,
|
||||
// sliceThickness, etc (See MetadataProvider class from ohif-cornerstone package)
|
||||
const metadataProvider = OHIF.viewer.metadataProvider;
|
||||
const isUpdateMetadataDefined = metadataProvider && typeof metadataProvider.updateMetadata === 'function';
|
||||
|
||||
// loadAndCacheImage configurable callbacks
|
||||
const callbacks = imageViewerViewportData.callbacks;
|
||||
|
||||
@@ -188,8 +195,10 @@ const loadDisplaySetIntoViewport = (data, templateData) => {
|
||||
enabledElement.image = image;
|
||||
enabledElement.viewport = cornerstone.getDefaultViewport(enabledElement.canvas, image);
|
||||
|
||||
// Update the metaData for missing fields
|
||||
updateMetaData(image);
|
||||
if (isUpdateMetadataDefined) {
|
||||
// Update the metaData for missing fields
|
||||
metadataProvider.updateMetadata(image);
|
||||
}
|
||||
|
||||
// Check if there are default viewport settings for this sopClassUid
|
||||
if (!displaySet.images || !displaySet.images.length) {
|
||||
@@ -230,7 +239,7 @@ const loadDisplaySetIntoViewport = (data, templateData) => {
|
||||
|
||||
// Remove the data for this viewport from the ViewportLoading object
|
||||
// This will stop the loading percentage complete from being displayed.
|
||||
delete ViewportLoading[viewportIndex];
|
||||
delete window.ViewportLoading[viewportIndex];
|
||||
|
||||
// Call the handler function that represents the end of the image loading phase
|
||||
// (e.g. hide the progress text box)
|
||||
@@ -330,8 +339,10 @@ const loadDisplaySetIntoViewport = (data, templateData) => {
|
||||
// since this callback function is called multiple times (eg: when a tool is
|
||||
// enabled/disabled -> cornerstone[toolName].tool.enable)
|
||||
|
||||
// Update the metaData for missing fields
|
||||
updateMetaData(eventData.enabledElement.image);
|
||||
if(isUpdateMetadataDefined) {
|
||||
// Update the metaData for missing fields
|
||||
metadataProvider.updateMetadata(eventData.enabledElement.image);
|
||||
}
|
||||
|
||||
// Update the templateData with the new imageId
|
||||
// This allows the template helpers to update reactively
|
||||
@@ -507,43 +518,9 @@ const setDisplaySet = (data, displaySetInstanceUid, templateData) => {
|
||||
loadDisplaySetIntoViewport(data, templateData);
|
||||
};
|
||||
|
||||
/**
|
||||
* This function searches an object to return the keys that contain a specific value
|
||||
*
|
||||
* @param object {object} The object to be searched
|
||||
* @param value The value to be found
|
||||
*
|
||||
* @returns {array} The keys for which the object has the specified value
|
||||
*/
|
||||
const getKeysByValue = (object, value) => {
|
||||
// http://stackoverflow.com/questions/9907419/javascript-object-get-key-by-value
|
||||
return Object.keys(object).filter(key => object[key] === value);
|
||||
};
|
||||
|
||||
Meteor.startup(function() {
|
||||
// On Meteor startup, define the global objects used to store loading imageIds
|
||||
// by viewport / thumbnail element
|
||||
ViewportLoading = {};
|
||||
|
||||
// Whenever the CornerstoneImageLoadProgress is fired, identify which viewports
|
||||
// the "in-progress" image is to be displayed in. Then pass the percent complete
|
||||
// via the Meteor Session to the other templates to be displayed in the relevant viewports.
|
||||
$(cornerstone).on('CornerstoneImageLoadProgress', function(e, eventData) {
|
||||
viewportIndices = getKeysByValue(ViewportLoading, eventData.imageId);
|
||||
viewportIndices.forEach(function(viewportIndex) {
|
||||
Session.set('CornerstoneLoadProgress' + viewportIndex, eventData.percentComplete);
|
||||
});
|
||||
|
||||
const encodedId = OHIF.string.encodeId(eventData.imageId);
|
||||
Session.set('CornerstoneThumbnailLoadProgress' + encodedId, eventData.percentComplete);
|
||||
});
|
||||
|
||||
const config = {
|
||||
magnifySize: 300,
|
||||
magnificationLevel: 3
|
||||
};
|
||||
|
||||
cornerstoneTools.magnify.setConfiguration(config);
|
||||
Meteor.startup(() => {
|
||||
window.ViewportLoading = window.ViewportLoading || {};
|
||||
toolManager.configureLoadProcess();
|
||||
});
|
||||
|
||||
Template.imageViewerViewport.onRendered(function() {
|
||||
|
||||
+24
-19
@@ -3,36 +3,41 @@ import { Template } from 'meteor/templating';
|
||||
import { $ } from 'meteor/jquery';
|
||||
import { OHIF } from 'meteor/ohif:core';
|
||||
|
||||
Meteor.startup(function() {
|
||||
cornerstoneTools.loadHandlerManager.setStartLoadHandler(startLoadingHandler);
|
||||
cornerstoneTools.loadHandlerManager.setEndLoadHandler(doneLoadingHandler);
|
||||
cornerstoneTools.loadHandlerManager.setErrorLoadingHandler(errorLoadingHandler);
|
||||
Meteor.startup(() => {
|
||||
// This checking is necessary because cornerstoneTools may not have some tools available.
|
||||
// Example: when an app defines its own cornerstone's lib versions, so it
|
||||
// uses only ohif-viewerbase and not ohif-cornerstone and those libs are added later.
|
||||
if (cornerstoneTools.loadHandlerManager) {
|
||||
cornerstoneTools.loadHandlerManager.setStartLoadHandler(startLoadingHandler);
|
||||
cornerstoneTools.loadHandlerManager.setEndLoadHandler(doneLoadingHandler);
|
||||
cornerstoneTools.loadHandlerManager.setErrorLoadingHandler(errorLoadingHandler);
|
||||
}
|
||||
});
|
||||
|
||||
var loadHandlerTimeout;
|
||||
let loadHandlerTimeout;
|
||||
|
||||
const startLoadingHandler = function(element) {
|
||||
const startLoadingHandler = element => {
|
||||
clearTimeout(loadHandlerTimeout);
|
||||
loadHandlerTimeout = setTimeout(function() {
|
||||
loadHandlerTimeout = setTimeout(() => {
|
||||
console.log('startLoading');
|
||||
var elem = $(element);
|
||||
const elem = $(element);
|
||||
elem.siblings('.imageViewerErrorLoadingIndicator').css('display', 'none');
|
||||
elem.find('canvas').not('.magnifyTool').addClass('faded');
|
||||
elem.siblings('.imageViewerLoadingIndicator').css('display', 'block');
|
||||
}, OHIF.viewer.loadIndicatorDelay);
|
||||
};
|
||||
|
||||
const doneLoadingHandler = function(element) {
|
||||
const doneLoadingHandler = element => {
|
||||
clearTimeout(loadHandlerTimeout);
|
||||
var elem = $(element);
|
||||
const elem = $(element);
|
||||
elem.siblings('.imageViewerErrorLoadingIndicator').css('display', 'none');
|
||||
elem.find('canvas').not('.magnifyTool').removeClass('faded');
|
||||
elem.siblings('.imageViewerLoadingIndicator').css('display', 'none');
|
||||
};
|
||||
|
||||
const errorLoadingHandler = function(element, imageId, error, source) {
|
||||
const errorLoadingHandler = (element, imageId, error, source) => {
|
||||
clearTimeout(loadHandlerTimeout);
|
||||
var elem = $(element);
|
||||
const elem = $(element);
|
||||
|
||||
// Could probably chain all of these, but this is more readable
|
||||
elem.find('canvas').not('.magnifyTool').removeClass('faded');
|
||||
@@ -43,14 +48,14 @@ const errorLoadingHandler = function(element, imageId, error, source) {
|
||||
return;
|
||||
}
|
||||
|
||||
var errorLoadingIndicator = elem.siblings('.imageViewerErrorLoadingIndicator');
|
||||
const errorLoadingIndicator = elem.siblings('.imageViewerErrorLoadingIndicator');
|
||||
errorLoadingIndicator.css('display', 'block');
|
||||
|
||||
// This is just used to expand upon some error messages that are sent
|
||||
// when things fail. An example is a network error throwing the error
|
||||
// which is only described as "network".
|
||||
var errorDetails = {
|
||||
network: "A network error has occurred"
|
||||
const errorDetails = {
|
||||
network: 'A network error has occurred'
|
||||
// We need to expand this further when we see more obscure error messages
|
||||
};
|
||||
|
||||
@@ -58,17 +63,17 @@ const errorLoadingHandler = function(element, imageId, error, source) {
|
||||
error = errorDetails[error];
|
||||
}
|
||||
|
||||
errorLoadingIndicator.find('.description').text("An error has occurred while loading image: " + imageId);
|
||||
errorLoadingIndicator.find('.description').text(`An error has occurred while loading image: ${imageId}`);
|
||||
if (error) {
|
||||
errorLoadingIndicator.find('.details').text("Details: " + error);
|
||||
errorLoadingIndicator.find('.details').text(`Details: ${error}`);
|
||||
}
|
||||
};
|
||||
|
||||
Template.loadingIndicator.helpers({
|
||||
'percentComplete'() {
|
||||
var percentComplete = Session.get('CornerstoneLoadProgress' + this.viewportIndex);
|
||||
const percentComplete = Session.get('CornerstoneLoadProgress' + this.viewportIndex);
|
||||
if (percentComplete && percentComplete !== 100) {
|
||||
return percentComplete + '%';
|
||||
return `${percentComplete}%`;
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -10,9 +10,6 @@ import { ResizeViewportManager } from '../../../lib/classes/ResizeViewportManage
|
||||
import { LayoutManager } from '../../../lib/classes/LayoutManager';
|
||||
|
||||
Meteor.startup(() => {
|
||||
// Create the synchronizer used to update reference lines
|
||||
OHIF.viewer.updateImageSynchronizer = new cornerstoneTools.Synchronizer('CornerstoneNewImage', cornerstoneTools.updateImageSynchronizer);
|
||||
|
||||
window.ResizeViewportManager = window.ResizeViewportManager || new ResizeViewportManager();
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user