feat: OHIF-1000: Study prefetcher (#2466)

* Enable study prefetcher and expose configs

* Fix progress for all images

* Enable study loading listener

* Add new default for displaying progress bar for series

* Use events instead of redux to improve performance

* Add documentation, resolve issues with different datasets

* CR Updates

* CR Updates

* CR Updates & Resolve issue when activating both stack and study prefetch

* Add upward and update display set logic

* Add new behavior to prefetching orders

* Rollback display set check and activate cache check

* Remove prefetch check

* Check if displayset has images

* Debounce check cache events

* Remove usued debounce flags

* Ignore prefetching same image

* Use new image instead of image rendered

* Continue prefetch after cache check

* Update prefetch logic after checking cache

* Remove log

* Update displayset count default to 3

* Update netlify config

Co-authored-by: Alireza <ar.sedghi@gmail.com>
This commit is contained in:
Igor OctavianoandAlireza authored and GitHub committed 2021-09-09 09:58:24 +02:00
1 parent ea0963d75f
commit 8f2604509d
26 files changed
+970 -384

No files matched your search

@@ -1,44 +1,11 @@
import OHIF from '@ohif/core';
import { connect } from 'react-redux';
import { StudyBrowser } from '@ohif/ui';
import cloneDeep from 'lodash.clonedeep';
import findDisplaySetByUID from './findDisplaySetByUID';
import { servicesManager } from './../App.js';
const { studyMetadataManager } = OHIF.utils;
import { StudyBrowser } from '../../../ui/src/components/studyBrowser/StudyBrowser';
const { setActiveViewportSpecificData } = OHIF.redux.actions;
// TODO
// - Determine in which display set is active from Redux (activeViewportIndex and layout viewportData)
// - Pass in errors and stack loading progress from Redux
const mapStateToProps = (state, ownProps) => {
// If we know that the stack loading progress details have changed,
// we can try to update the component state so that the thumbnail
// progress bar is updated
const stackLoadingProgressMap = state.loading.progress;
const studiesWithLoadingData = cloneDeep(ownProps.studies);
studiesWithLoadingData.forEach(study => {
study.thumbnails.forEach(data => {
const { displaySetInstanceUID } = data;
const stackId = `StackProgress:${displaySetInstanceUID}`;
const stackProgressData = stackLoadingProgressMap[stackId];
let stackPercentComplete = 0;
if (stackProgressData) {
stackPercentComplete = stackProgressData.percentComplete;
}
data.stackPercentComplete = stackPercentComplete;
});
});
return {
studies: studiesWithLoadingData,
};
};
const mapDispatchToProps = (dispatch, ownProps) => {
return {
onThumbnailClick: displaySetInstanceUID => {
@@ -50,7 +17,10 @@ const mapDispatchToProps = (dispatch, ownProps) => {
if (displaySet.isDerived) {
const { Modality } = displaySet;
if (Modality === 'SEG' && servicesManager) {
const {LoggerService, UINotificationService} = servicesManager.services;
const {
LoggerService,
UINotificationService,
} = servicesManager.services;
const onDisplaySetLoadFailureHandler = error => {
LoggerService.error({ error, message: error.message });
UINotificationService.show({
@@ -61,20 +31,25 @@ const mapDispatchToProps = (dispatch, ownProps) => {
});
};
const {referencedDisplaySet, activatedLabelmapPromise} = displaySet.getSourceDisplaySet(
const {
referencedDisplaySet,
activatedLabelmapPromise,
} = displaySet.getSourceDisplaySet(
ownProps.studyMetadata,
true,
onDisplaySetLoadFailureHandler
);
displaySet = referencedDisplaySet;
activatedLabelmapPromise.then((activatedLabelmapIndex) => {
const selectionFired = new CustomEvent("extensiondicomsegmentationsegselected", {
"detail": {"activatedLabelmapIndex":activatedLabelmapIndex}
});
activatedLabelmapPromise.then(activatedLabelmapIndex => {
const selectionFired = new CustomEvent(
'extensiondicomsegmentationsegselected',
{
detail: { activatedLabelmapIndex: activatedLabelmapIndex },
}
);
document.dispatchEvent(selectionFired);
});
} else {
displaySet = displaySet.getSourceDisplaySet(ownProps.studyMetadata);
}
@@ -96,7 +71,7 @@ const mapDispatchToProps = (dispatch, ownProps) => {
};
const ConnectedStudyBrowser = connect(
mapStateToProps,
null,
mapDispatchToProps
)(StudyBrowser);
@@ -1,26 +0,0 @@
import { connect } from "react-redux";
import StudyLoadingMonitor from "../components/StudyLoadingMonitor.js";
import OHIF from "@ohif/core";
const {
setStudyLoadingProgress,
clearStudyLoadingProgress
} = OHIF.redux.actions;
const mapDispatchToProps = dispatch => {
return {
setStudyLoadingProgress: (progressId, progressData) => {
dispatch(setStudyLoadingProgress(progressId, progressData));
},
clearStudyLoadingProgress: progressId => {
dispatch(clearStudyLoadingProgress(progressId));
}
};
};
const ConnectedStudyLoadingMonitor = connect(
null,
mapDispatchToProps
)(StudyLoadingMonitor);
export default ConnectedStudyLoadingMonitor;
+163 -80
View File
@@ -1,11 +1,10 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import { useLogger } from '@ohif/ui';
import OHIF, { MODULE_TYPES, DICOMSR } from '@ohif/core';
import { withDialog } from '@ohif/ui';
import moment from 'moment';
import ConnectedHeader from './ConnectedHeader.js';
import ToolbarRow from './ToolbarRow.js';
import ConnectedStudyBrowser from './ConnectedStudyBrowser.js';
@@ -14,7 +13,6 @@ import SidePanel from './../components/SidePanel.js';
import ErrorBoundaryDialog from './../components/ErrorBoundaryDialog';
import { extensionManager } from './../App.js';
import { ReconstructionIssues } from './../../../core/src/enums.js';
import dcmjs from 'dcmjs';
// Contexts
import WhiteLabelingContext from '../context/WhiteLabelingContext.js';
@@ -22,8 +20,8 @@ import UserManagerContext from '../context/UserManagerContext';
import AppContext from '../context/AppContext';
import './Viewer.css';
import { finished } from 'stream';
import { cornerstoneWADOImageLoader } from 'cornerstone-wado-image-loader';
import StudyPrefetcher from '../components/StudyPrefetcher.js';
import StudyLoadingMonitor from '../components/StudyLoadingMonitor';
class Viewer extends Component {
static propTypes = {
@@ -197,11 +195,17 @@ class Viewer extends Component {
]);
}
const activeViewport = this.props.viewports[this.props.activeViewportIndex];
const activeDisplaySetInstanceUID =
activeViewport ? activeViewport.displaySetInstanceUID : undefined;
const activeViewport = this.props.viewports[
this.props.activeViewportIndex
];
const activeDisplaySetInstanceUID = activeViewport
? activeViewport.displaySetInstanceUID
: undefined;
this.setState({
thumbnails: _mapStudiesToThumbnails(studies, activeDisplaySetInstanceUID),
thumbnails: _mapStudiesToThumbnails(
studies,
activeDisplaySetInstanceUID
),
});
}
}
@@ -211,24 +215,31 @@ class Viewer extends Component {
studies,
isStudyLoaded,
activeViewportIndex,
viewports
viewports,
} = this.props;
const activeViewport = viewports[activeViewportIndex];
const activeDisplaySetInstanceUID =
activeViewport ? activeViewport.displaySetInstanceUID : undefined;
const activeDisplaySetInstanceUID = activeViewport
? activeViewport.displaySetInstanceUID
: undefined;
const prevActiveViewport = prevProps.viewports[prevProps.activeViewportIndex];
const prevActiveDisplaySetInstanceUID =
prevActiveViewport ? prevActiveViewport.displaySetInstanceUID : undefined;
const prevActiveViewport =
prevProps.viewports[prevProps.activeViewportIndex];
const prevActiveDisplaySetInstanceUID = prevActiveViewport
? prevActiveViewport.displaySetInstanceUID
: undefined;
if (studies !== prevProps.studies ||
if (
studies !== prevProps.studies ||
activeViewportIndex !== prevProps.activeViewportIndex ||
activeDisplaySetInstanceUID !== prevActiveDisplaySetInstanceUID
) {
) {
this.setState({
thumbnails: _mapStudiesToThumbnails(studies, activeDisplaySetInstanceUID),
thumbnails: _mapStudiesToThumbnails(
studies,
activeDisplaySetInstanceUID
),
activeDisplaySetInstanceUID,
});
}
if (isStudyLoaded && isStudyLoaded !== prevProps.isStudyLoaded) {
@@ -288,14 +299,12 @@ class Viewer extends Component {
</UserManagerContext.Consumer>
)}
</WhiteLabelingContext.Consumer>
{/* TOOLBAR */}
<ErrorBoundaryDialog context="ToolbarRow">
<ToolbarRow
activeViewport={
this.props.viewports[this.props.activeViewportIndex]
}
isDerivedDisplaySetsLoaded={this.props.isDerivedDisplaySetsLoaded}
isLeftSidePanelOpen={this.state.isLeftSidePanelOpen}
isRightSidePanelOpen={this.state.isRightSidePanelOpen}
selectedLeftSidePanel={
@@ -332,10 +341,9 @@ class Viewer extends Component {
studies={this.props.studies}
/>
</ErrorBoundaryDialog>
{/*<ConnectedStudyLoadingMonitor studies={this.props.studies} />*/}
{/*<StudyPrefetcher studies={this.props.studies} />*/}
<AppContext.Consumer>
{appContext => <StudyLoadingMonitor studies={this.props.studies} />}
</AppContext.Consumer>
{/* VIEWPORTS + SIDEPANELS */}
<div className="FlexboxLayout">
{/* LEFT */}
@@ -348,10 +356,24 @@ class Viewer extends Component {
activeIndex={this.props.activeViewportIndex}
/>
) : (
<ConnectedStudyBrowser
studies={this.state.thumbnails}
studyMetadata={this.props.studies}
/>
<AppContext.Consumer>
{appContext => {
const { appConfig } = appContext;
const { studyPrefetcher } = appConfig;
const { thumbnails } = this.state;
return (
<ConnectedStudyBrowser
studies={thumbnails}
studyMetadata={this.props.studies}
showThumbnailProgressBar={
studyPrefetcher &&
studyPrefetcher.enabled &&
studyPrefetcher.displayProgress
}
/>
);
}}
</AppContext.Consumer>
)}
</SidePanel>
</ErrorBoundaryDialog>
@@ -359,6 +381,22 @@ class Viewer extends Component {
{/* MAIN */}
<div className={classNames('main-content')}>
<ErrorBoundaryDialog context="ViewerMain">
<AppContext.Consumer>
{appContext => {
const { appConfig } = appContext;
const { studyPrefetcher } = appConfig;
const { studies } = this.props;
return (
studyPrefetcher &&
studyPrefetcher.enabled && (
<StudyPrefetcher
studies={studies}
options={studyPrefetcher}
/>
)
);
}}
</AppContext.Consumer>
<ConnectedViewerMain
studies={this.props.studies}
isStudyLoaded={this.props.isStudyLoaded}
@@ -410,7 +448,10 @@ export default withDialog(Viewer);
* @param {*object} displaySet
* @returns {[string]} an array of strings containing the warnings
*/
const _checkForSeriesInconsistencesWarnings = async function (displaySet, studies) {
const _checkForSeriesInconsistencesWarnings = async function(
displaySet,
studies
) {
if (displaySet.inconsistencyWarnings) {
// warnings already checked and cached in displaySet
return displaySet.inconsistencyWarnings;
@@ -418,23 +459,34 @@ const _checkForSeriesInconsistencesWarnings = async function (displaySet, studie
const inconsistencyWarnings = [];
if (displaySet.Modality !== 'SEG') {
if (displaySet.reconstructionIssues && displaySet.reconstructionIssues.length !== 0) {
if (
displaySet.reconstructionIssues &&
displaySet.reconstructionIssues.length !== 0
) {
displaySet.reconstructionIssues.forEach(warning => {
switch (warning) {
case ReconstructionIssues.DATASET_4D:
inconsistencyWarnings.push('The dataset is 4D.');
break;
case ReconstructionIssues.VARYING_IMAGESDIMENSIONS:
inconsistencyWarnings.push('The dataset frames have different dimensions (rows, columns).');
inconsistencyWarnings.push(
'The dataset frames have different dimensions (rows, columns).'
);
break;
case ReconstructionIssues.VARYING_IMAGESCOMPONENTS:
inconsistencyWarnings.push('The dataset frames have different components (Sample per pixel).');
inconsistencyWarnings.push(
'The dataset frames have different components (Sample per pixel).'
);
break;
case ReconstructionIssues.VARYING_IMAGESORIENTATION:
inconsistencyWarnings.push('The dataset frames have different orientation.');
inconsistencyWarnings.push(
'The dataset frames have different orientation.'
);
break;
case ReconstructionIssues.IRREGULAR_SPACING:
inconsistencyWarnings.push('The dataset frames have different pixel spacing.');
inconsistencyWarnings.push(
'The dataset frames have different pixel spacing.'
);
break;
case ReconstructionIssues.MULTIFFRAMES:
inconsistencyWarnings.push('The dataset is a multiframes.');
@@ -443,13 +495,22 @@ const _checkForSeriesInconsistencesWarnings = async function (displaySet, studie
break;
}
});
inconsistencyWarnings.push('The datasets is not a reconstructable 3D volume. MPR mode is not available.');
inconsistencyWarnings.push(
'The datasets is not a reconstructable 3D volume. MPR mode is not available.'
);
}
if (displaySet.missingFrames &&
if (
displaySet.missingFrames &&
(!displaySet.reconstructionIssues ||
(displaySet.reconstructionIssues && !displaySet.reconstructionIssues.find(warn => warn === ReconstructionIssues.DATASET_4D)))) {
inconsistencyWarnings.push('The datasets is missing frames: ' + displaySet.missingFrames + '.');
(displaySet.reconstructionIssues &&
!displaySet.reconstructionIssues.find(
warn => warn === ReconstructionIssues.DATASET_4D
)))
) {
inconsistencyWarnings.push(
'The datasets is missing frames: ' + displaySet.missingFrames + '.'
);
}
} else {
const segMetadata = displaySet.metadata;
@@ -458,24 +519,31 @@ const _checkForSeriesInconsistencesWarnings = async function (displaySet, studie
return inconsistencyWarnings;
}
const { referencedDisplaySet } = displaySet.getSourceDisplaySet(studies, false);
const { referencedDisplaySet } = displaySet.getSourceDisplaySet(
studies,
false
);
if (!referencedDisplaySet) {
displaySet.inconsistencyWarnings = inconsistencyWarnings;
return inconsistencyWarnings;
}
const imageIds = referencedDisplaySet.images.map(image => image.getImageId());
const imageIds = referencedDisplaySet.images.map(image =>
image.getImageId()
);
if (!imageIds || imageIds.length === 0) {
displaySet.inconsistencyWarnings = inconsistencyWarnings;
return inconsistencyWarnings;
}
for (
let i = 0, groupsLen = segMetadata.PerFrameFunctionalGroupsSequence.length;
let i = 0,
groupsLen = segMetadata.PerFrameFunctionalGroupsSequence.length;
i < groupsLen;
++i
) {
const PerFrameFunctionalGroups = segMetadata.PerFrameFunctionalGroupsSequence[i];
const PerFrameFunctionalGroups =
segMetadata.PerFrameFunctionalGroupsSequence[i];
if (!PerFrameFunctionalGroups) {
continue;
}
@@ -485,29 +553,27 @@ const _checkForSeriesInconsistencesWarnings = async function (displaySet, studie
SourceImageSequence = segMetadata.SourceImageSequence[i];
} else if (PerFrameFunctionalGroups.DerivationImageSequence) {
SourceImageSequence =
PerFrameFunctionalGroups.DerivationImageSequence
.SourceImageSequence;
PerFrameFunctionalGroups.DerivationImageSequence.SourceImageSequence;
}
if (!SourceImageSequence) {
if (inconsistencyWarnings.length === 0) {
const warningMessage = 'The segmentation ' +
const warningMessage =
'The segmentation ' +
'has frames out of plane respect to the source images.';
inconsistencyWarnings.push(warningMessage);
inconsistencyWarnings.push(warningMessage);
}
continue;
}
const {
ReferencedSOPInstanceUID,
} = SourceImageSequence;
const { ReferencedSOPInstanceUID } = SourceImageSequence;
const imageId = imageIds.find(imageId => {
const sopCommonModule = cornerstone.metaData.get(
"sopCommonModule",
imageId
'sopCommonModule',
imageId
);
if (!sopCommonModule) {
return;
return;
}
return sopCommonModule.sopInstanceUID === ReferencedSOPInstanceUID;
@@ -517,33 +583,32 @@ const _checkForSeriesInconsistencesWarnings = async function (displaySet, studie
continue;
}
const sourceImageMetadata = cornerstone.metaData.get(
"instance",
imageId
);
const sourceImageMetadata = cornerstone.metaData.get('instance', imageId);
if (
segMetadata.Rows !== sourceImageMetadata.Rows ||
segMetadata.Columns !== sourceImageMetadata.Columns
) {
const warningMessage = 'The segmentation ' +
const warningMessage =
'The segmentation ' +
'has frames with different geometry ' +
'dimensions (Rows and Columns) respect to the source images.';
inconsistencyWarnings.push(warningMessage);
inconsistencyWarnings.push(warningMessage);
break;
}
}
if (inconsistencyWarnings.length !== 0) {
const warningMessage = 'The segmentation format is not supported yet. ' +
const warningMessage =
'The segmentation format is not supported yet. ' +
'The segmentation data (segments) could not be loaded.';
inconsistencyWarnings.push(warningMessage);
inconsistencyWarnings.push(warningMessage);
}
}
// cache the warnings
displaySet.inconsistencyWarnings = inconsistencyWarnings;
return inconsistencyWarnings;
}
};
/**
* Checks if display set is active, i.e. if the series is currently shown
@@ -562,30 +627,42 @@ const _checkForSeriesInconsistencesWarnings = async function (displaySet, studie
* @param {string} activeDisplaySetInstanceUID
* @returns {boolean} is active.
*/
const _isDisplaySetActive = function(displaySet, studies, activeDisplaySetInstanceUID) {
const _isDisplaySetActive = function(
displaySet,
studies,
activeDisplaySetInstanceUID
) {
let active = false;
const {
displaySetInstanceUID,
} = displaySet;
const { displaySetInstanceUID } = displaySet;
// TO DO: in the future, we could possibly support new modalities
// we should have a list of all modalities here, instead of having hard coded checks
if (displaySet.Modality !== 'SEG' &&
if (
displaySet.Modality !== 'SEG' &&
displaySet.Modality !== 'RTSTRUCT' &&
displaySet.Modality !== 'RTDOSE') {
displaySet.Modality !== 'RTDOSE'
) {
active = activeDisplaySetInstanceUID === displaySetInstanceUID;
} else if (displaySet.getSourceDisplaySet){
} else if (displaySet.getSourceDisplaySet) {
if (displaySet.Modality === 'SEG') {
const { referencedDisplaySet } = displaySet.getSourceDisplaySet(studies, false);
active = referencedDisplaySet ?
activeDisplaySetInstanceUID === referencedDisplaySet.displaySetInstanceUID :
false;
const { referencedDisplaySet } = displaySet.getSourceDisplaySet(
studies,
false
);
active = referencedDisplaySet
? activeDisplaySetInstanceUID ===
referencedDisplaySet.displaySetInstanceUID
: false;
} else {
const referencedDisplaySet = displaySet.getSourceDisplaySet(studies, false);
active = referencedDisplaySet ?
activeDisplaySetInstanceUID === referencedDisplaySet.displaySetInstanceUID :
false;
const referencedDisplaySet = displaySet.getSourceDisplaySet(
studies,
false
);
active = referencedDisplaySet
? activeDisplaySetInstanceUID ===
referencedDisplaySet.displaySetInstanceUID
: false;
}
}
@@ -629,11 +706,17 @@ const _mapStudiesToThumbnails = function(studies, activeDisplaySetInstanceUID) {
altImageText = displaySet.Modality ? displaySet.Modality : 'UN';
}
const hasWarnings = _checkForSeriesInconsistencesWarnings(displaySet, studies);
const active = _isDisplaySetActive(displaySet, studies, activeDisplaySetInstanceUID)
const hasWarnings = _checkForSeriesInconsistencesWarnings(
displaySet,
studies
);
return {
active,
active: _isDisplaySetActive(
displaySet,
studies,
activeDisplaySetInstanceUID
),
imageId,
altImageText,
displaySetInstanceUID,