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,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