Preventing re-rendering if viewport is on the same series

This commit is contained in:
Bruno Alves de Faria 2017-11-08 15:40:38 -02:00
parent 0eea7f9373
commit 7d2577b06f
3 changed files with 39 additions and 15 deletions

View File

@ -14,7 +14,6 @@ OHIF.measurements.findAndRenderDisplaySet = (displaySets, viewportIndex, studyIn
const displaySetData = {
studyInstanceUid: studyInstanceUid,
seriesInstanceUid: seriesInstanceUid,
sopInstanceUid: sopInstanceUid,
displaySetInstanceUid: stack.displaySetInstanceUid,
currentImageIdIndex: specificImageIndex
};

View File

@ -14,7 +14,25 @@ function renderIntoViewport(measurementData, enabledElement, viewportIndex) {
$(element).one('CornerstoneImageRendered', () => resolve());
};
// Check if the study / series we need is already the one in the viewport
// Find the study by studyInstanceUid and render the display set
const findAndRender = () => {
// @TypeSafeStudies
const study = OHIF.viewer.Studies.findBy({ studyInstanceUid });
// TODO: Support frames? e.g. for measurements on multi-frame instances
findAndRenderDisplaySet(
study.displaySets,
viewportIndex,
studyInstanceUid,
seriesInstanceUid,
sopInstanceUid,
renderedCallback
);
};
// Check if the study / series we need is already the one in the viewport.
// Otherwise, re-render the viewport with the required study/series, then add a rendered
// callback to activate the measurements
if (enabledElement && enabledElement.image) {
const imageId = enabledElement.image.imageId;
const series = cornerstone.metaData.get('series', imageId);
@ -24,18 +42,14 @@ function renderIntoViewport(measurementData, enabledElement, viewportIndex) {
const isSameSeries = series.seriesInstanceUid === measurementData.seriesInstanceUid;
if (isSameStudy && isSameSeries) {
// If it is, activate the measurements in this viewport and stop here
OHIF.viewerbase.viewportUtils.resetViewport('all');
renderedCallback(element);
} else {
findAndRender();
}
} else {
findAndRender();
}
// Otherwise, re-render the viewport with the required study/series, then add an rendered
// callback to activate the measurements
// @TypeSafeStudies
const study = OHIF.viewer.Studies.findBy({ studyInstanceUid });
// TODO: Support frames? e.g. for measurements on multi-frame instances
findAndRenderDisplaySet(study.displaySets, viewportIndex, studyInstanceUid, seriesInstanceUid, sopInstanceUid, renderedCallback);
});
}

View File

@ -37,7 +37,7 @@ const getActiveViewportElement = () => {
/**
* Get a cornerstone enabledElement for the Active Viewport Element
* @return {Object} Cornerstone's enabledElement object for the active
* viewport element or undefined if the element
* viewport element or undefined if the element
* is not enabled
*/
const getEnabledElementForActiveElement = () => {
@ -133,8 +133,7 @@ const flipH = () => {
updateOrientationMarkers(element, viewport);
};
const resetViewport = () => {
const element = getActiveViewportElement();
const resetViewportWithElement = element => {
const enabledElement = cornerstone.getEnabledElement(element);
if (enabledElement.fitToWindow === false) {
const imageId = enabledElement.image.imageId;
@ -149,6 +148,18 @@ const resetViewport = () => {
}
};
const resetViewport = (viewportIndex=null) => {
if (viewportIndex === null) {
resetViewportWithElement(getActiveViewportElement());
} else if (viewportIndex === 'all') {
$('.imageViewerViewport').each((index, element) => {
resetViewportWithElement(element);
});
} else {
resetViewportWithElement($('.imageViewerViewport').get(viewportIndex));
}
};
const clearTools = () => {
const element = getActiveViewportElement();
const toolStateManager = cornerstoneTools.globalImageIdSpecificToolStateManager;
@ -250,7 +261,7 @@ const isPlaying = () => {
// Get the clip state
const clipState = toolState.data[0];
if(clipState) {
// Return true if the clip is playing
return !_.isUndefined(clipState.intervalId);