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:
1 parent
ea0963d75f
commit
8f2604509d
26 files changed
+970
-384
No files matched your search
@@ -1,42 +1,23 @@
|
||||
import { Component } from "react";
|
||||
import PropTypes from "prop-types";
|
||||
import OHIF from "@ohif/core";
|
||||
import { useEffect } from 'react';
|
||||
import OHIF from '@ohif/core';
|
||||
|
||||
class StudyLoadingMonitor extends Component {
|
||||
static propTypes = {
|
||||
studies: PropTypes.array.isRequired,
|
||||
setStudyLoadingProgress: PropTypes.func.isRequired,
|
||||
clearStudyLoadingProgress: PropTypes.func.isRequired
|
||||
};
|
||||
const { StudyLoadingListener } = OHIF.classes;
|
||||
|
||||
componentDidMount() {
|
||||
// TODO: This is pretty ugly. The thing is that the StudyLoadingListener
|
||||
// needs to update the Redux store, but shouldn't know that it exists.
|
||||
// I am therefore passing in some functions to update the store instead,
|
||||
// but this should definitely be cleaned up somehow.
|
||||
const options = {
|
||||
_setProgressData: (progressId, progressData) => {
|
||||
this.props.setStudyLoadingProgress(progressId, progressData);
|
||||
},
|
||||
_clearProgressById: progressId => {
|
||||
this.props.clearStudyLoadingProgress(progressId);
|
||||
}
|
||||
const StudyLoadingMonitor = ({ studies }) => {
|
||||
useEffect(() => {
|
||||
const studyLoadingListener = StudyLoadingListener.getInstance();
|
||||
|
||||
if (studies && studies.length > 0) {
|
||||
studyLoadingListener.clear();
|
||||
studyLoadingListener.addStudies(studies);
|
||||
}
|
||||
|
||||
return () => {
|
||||
studyLoadingListener.clear();
|
||||
};
|
||||
}, [studies]);
|
||||
|
||||
const { StudyLoadingListener } = OHIF.classes;
|
||||
this.studyLoadingListener = StudyLoadingListener.getInstance(options);
|
||||
this.studyLoadingListener.clear();
|
||||
this.studyLoadingListener.addStudies(this.props.studies);
|
||||
}
|
||||
|
||||
render() {
|
||||
return null;
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
// Destroy stack loading listeners when we close the viewer
|
||||
this.studyLoadingListener.clear();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
export default StudyLoadingMonitor;
|
||||
@@ -0,0 +1,15 @@
|
||||
.StudyPrefetcher {
|
||||
height: 5px;
|
||||
width: 100%;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
background-color: var(--default-color);
|
||||
}
|
||||
|
||||
.StudyPrefetcher .item {
|
||||
height: 5px;
|
||||
}
|
||||
|
||||
.StudyPrefetcher .item.cached {
|
||||
background-color: black;
|
||||
}
|
||||
@@ -1,29 +1,93 @@
|
||||
import { Component } from "react";
|
||||
import PropTypes from "prop-types";
|
||||
import OHIF from "@ohif/core";
|
||||
import React, { useEffect } from 'react';
|
||||
import { classes, utils } from '@ohif/core';
|
||||
import PropTypes from 'prop-types';
|
||||
import cs from 'cornerstone-core';
|
||||
|
||||
const { StudyPrefetcher } = OHIF.classes;
|
||||
import './StudyPrefetcher.css';
|
||||
|
||||
class StudyPrefetcherComponent extends Component {
|
||||
static propTypes = {
|
||||
studies: PropTypes.array
|
||||
};
|
||||
const StudyPrefetcher = ({ studies, options }) => {
|
||||
useEffect(() => {
|
||||
const studyPrefetcher = classes.StudyPrefetcher.getInstance(
|
||||
studies,
|
||||
options
|
||||
);
|
||||
const studiesMetadata = studies.map(s =>
|
||||
utils.studyMetadataManager.get(s.StudyInstanceUID)
|
||||
);
|
||||
studyPrefetcher.setStudies(studiesMetadata);
|
||||
|
||||
componentDidMount() {
|
||||
const { studies } = this.props;
|
||||
const onNewImage = ({ detail }) => {
|
||||
/**
|
||||
* When images are cached the viewport will load instantly and
|
||||
* the display sets will not be available at this point in time.
|
||||
*
|
||||
* This code add display sets and updates the study prefetcher metadata.
|
||||
*/
|
||||
const studiesMetadata = studies.map(s => {
|
||||
const studyMetadata = utils.studyMetadataManager.get(
|
||||
s.StudyInstanceUID
|
||||
);
|
||||
const displaySets = studyMetadata.getDisplaySets();
|
||||
if (!displaySets || displaySets.length < 1) {
|
||||
s.displaySets.forEach(ds => studyMetadata.addDisplaySet(ds));
|
||||
}
|
||||
return studyMetadata;
|
||||
});
|
||||
studyPrefetcher.setStudies(studiesMetadata);
|
||||
|
||||
this.studyPrefetcher = StudyPrefetcher.getInstance();
|
||||
this.studyPrefetcher.setStudies(studies);
|
||||
}
|
||||
const study = studyPrefetcher.getStudy(detail.image);
|
||||
const series = studyPrefetcher.getSeries(study, detail.image);
|
||||
const instance = studyPrefetcher.getInstance(series, detail.image);
|
||||
|
||||
render() {
|
||||
return null;
|
||||
}
|
||||
if (study.displaySets && study.displaySets.length > 0) {
|
||||
const {
|
||||
displaySetInstanceUID,
|
||||
} = studyPrefetcher.getDisplaySetBySOPInstanceUID(
|
||||
study.displaySets,
|
||||
instance
|
||||
);
|
||||
studyPrefetcher.prefetch(detail.element, displaySetInstanceUID);
|
||||
}
|
||||
};
|
||||
|
||||
componentWillUnmount() {
|
||||
// Stop prefetching when we close the viewer
|
||||
this.studyPrefetcher.destroy();
|
||||
}
|
||||
}
|
||||
const onElementEnabled = ({ detail }) => {
|
||||
detail.element.addEventListener(cs.EVENTS.NEW_IMAGE, onNewImage);
|
||||
};
|
||||
|
||||
export default StudyPrefetcherComponent;
|
||||
cs.events.addEventListener(cs.EVENTS.ELEMENT_ENABLED, onElementEnabled);
|
||||
|
||||
return () => {
|
||||
cs.events.removeEventListener(
|
||||
cs.EVENTS.ELEMENT_ENABLED,
|
||||
onElementEnabled
|
||||
);
|
||||
studyPrefetcher.destroy();
|
||||
};
|
||||
}, [options, studies]);
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
StudyPrefetcher.propTypes = {
|
||||
studies: PropTypes.array.isRequired,
|
||||
options: PropTypes.shape({
|
||||
enabled: PropTypes.bool,
|
||||
order: PropTypes.string,
|
||||
displaySetCount: PropTypes.number,
|
||||
preventCache: PropTypes.bool,
|
||||
prefetchDisplaySetsTimeout: PropTypes.number,
|
||||
includeActiveDisplaySet: PropTypes.bool,
|
||||
}),
|
||||
};
|
||||
|
||||
StudyPrefetcher.defaultProps = {
|
||||
options: {
|
||||
order: 'closest',
|
||||
displaySetCount: 1,
|
||||
preventCache: false,
|
||||
prefetchDisplaySetsTimeout: 300,
|
||||
includeActiveDisplaySet: false,
|
||||
},
|
||||
};
|
||||
|
||||
export default StudyPrefetcher;
|
||||
Reference in new issue
Block a user