AWV-1: Making the display set navigation buttons move the display sets on all viewports

This commit is contained in:
Bruno Alves de Faria 2016-09-02 16:10:54 -03:00
parent 8145e08f66
commit 0469747b5a
2 changed files with 104 additions and 12 deletions

View File

@ -4,6 +4,9 @@ OHIF.viewer = {};
// Move display sets forward or backward in the given viewport index
OHIF.viewer.moveSingleViewportDisplaySets = (viewportIndex, isNext) => {
// Get the setting that allow display set navigation looping over series
const allowLooping = OHIF.uiSettings.displaySetNavigationLoopOverSeries;
// Get the selected viewport data
const viewportData = window.layoutManager.viewportData[viewportIndex];
@ -25,8 +28,8 @@ OHIF.viewer.moveSingleViewportDisplaySets = (viewportIndex, isNext) => {
if (isNext) {
newIndex++;
if (newIndex >= displaySets.length) {
// Stop here if looping is now allowing
if (!OHIF.uiSettings.displaySetNavigationLoopOverSeries) {
// Stop here if looping is not allowed
if (!allowLooping) {
return;
}
@ -35,8 +38,8 @@ OHIF.viewer.moveSingleViewportDisplaySets = (viewportIndex, isNext) => {
} else {
newIndex--;
if (newIndex < 0) {
// Stop here if looping is now allowing
if (!OHIF.uiSettings.displaySetNavigationLoopOverSeries) {
// Stop here if looping is not allowed
if (!allowLooping) {
return;
}
@ -53,7 +56,93 @@ OHIF.viewer.moveSingleViewportDisplaySets = (viewportIndex, isNext) => {
// Move multiple display sets forward or backward in all viewports
OHIF.viewer.moveMultipleViewportDisplaySets = isNext => {
// TODO: implement
// Get the setting that allow display set navigation looping over series
const allowLooping = OHIF.uiSettings.displaySetNavigationLoopOverSeries;
// Get the viewport data list
const viewportDataList = window.layoutManager.viewportData;
// Create a map to control the display set movement
const moveMap = new Map();
// Iterate over each viewport and register its details on the movement map
viewportDataList.forEach((viewportData, viewportIndex) => {
// Get the current study
const currentStudy = _.findWhere(window.layoutManager.studies, {
studyInstanceUid: viewportData.studyInstanceUid
}) || window.layoutManager.studies[0];
// Get the display sets
const displaySets = currentStudy.displaySets;
// Get the current display set
const displaySet = _.findWhere(displaySets, {
displaySetInstanceUid: viewportData.displaySetInstanceUid
});
// Get the current instance index
let displaySetIndex = _.indexOf(displaySets, displaySet);
displaySetIndex = displaySetIndex < 0 ? 9999 : displaySetIndex;
// Try to get a map entry for current study or create it if not present
let studyViewports = moveMap.get(currentStudy);
if (!studyViewports) {
studyViewports = [];
moveMap.set(currentStudy, studyViewports);
}
// Register the viewport index and the display set index on the map
studyViewports.push({
viewportIndex,
displaySetIndex
});
});
// Iterate over the studies map and move its display sets
moveMap.forEach((studyViewports, study) => {
// Sort the viewports on the study by the display set index
studyViewports.sort((a, b) => a.displaySetIndex > b.displaySetIndex);
// Get the study display sets
const displaySets = study.displaySets;
// Calculate the base index
const firstIndex = studyViewports[0].displaySetIndex;
const amount = studyViewports.length;
const rest = firstIndex % amount;
let baseIndex = rest ? firstIndex - rest : firstIndex;
const direction = isNext ? 1 : -1;
baseIndex += amount * direction;
// Check if the base index will be outside the array bounds
if (baseIndex >= displaySets.length) {
// Stop here if looping is not allowed
if (!allowLooping) {
return;
}
baseIndex = 0;
} else if (baseIndex < 0) {
// Stop here if looping is not allowed
if (!allowLooping) {
return;
}
baseIndex = (displaySets.length - 1) - ((displaySets.length - 1) % amount);
}
// Iterate over the current study viewports
studyViewports.forEach(({ viewportIndex }, index) => {
// Get the new displaySet index to be rendered in viewport
const newIndex = baseIndex + index;
// Get the display set data for the new index
const displaySetData = displaySets[newIndex] || {};
// Rerender the viewport using the new display set data
window.layoutManager.rerenderViewportWithNewDisplaySet(viewportIndex, displaySetData);
});
});
};
// Move display sets forward or backward

View File

@ -29,15 +29,18 @@ LayoutManager = class LayoutManager {
var viewportIndex = 0;
var self = this;
var oldViewportData = self.viewportData;
var running = true;
self.viewportData = [];
this.studies.forEach(function(study) {
study.displaySets.forEach(function(displaySet) {
if (!displaySet.images.length) {
if (!displaySet.images.length || !running) {
return;
}
var currentViewportData;
var existingViewportData = self.viewportData[viewportIndex];
if (self.viewportData[viewportIndex]) {
var existingViewportData = oldViewportData[viewportIndex];
if (oldViewportData[viewportIndex]) {
currentViewportData = {
viewportIndex: existingViewportData.viewportIndex,
studyInstanceUid: existingViewportData.studyInstanceUid,
@ -48,8 +51,6 @@ LayoutManager = class LayoutManager {
imageId: existingViewportData.imageId,
currentImageIdIndex: existingViewportData.currentImageIdIndex // TODO Remove this once currentImageIdIndex is removed from imageViewerViewports
};
self.viewportData[viewportIndex] = currentViewportData;
} else {
// This tests to make sure there is actually image data in this instance
// TODO: Change this when we add PDF and MPEG support
@ -69,18 +70,20 @@ LayoutManager = class LayoutManager {
currentImageIdIndex: 0 // TODO Remove this once currentImageIdIndex is removed from imageViewerViewports
};
}
self.viewportData.push(currentViewportData);
}
self.viewportData.push(currentViewportData);
viewportIndex++;
if (viewportIndex === numViewports) {
running = false;
return false;
}
});
if (viewportIndex === numViewports) {
running = false;
return false;
}
});