Skip to content

Commit

Permalink
Refactor interleaveCenterLoader and interleaveTopToBottom functions f…
Browse files Browse the repository at this point in the history
…or improved performance and readability
  • Loading branch information
sedghi committed Apr 15, 2024
1 parent 810e763 commit 28e7248
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 23 deletions.
27 changes: 17 additions & 10 deletions extensions/cornerstone/src/utils/interleaveCenterLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,25 @@ export default function interleaveCenterLoader({
* listen to it and as the other viewports are created we can set the volumes for them
* since volumes are already started loading.
*/
if (matchDetails.size !== viewportIdVolumeInputArrayMap.size) {
return;
}
const uniqueViewportVolumeDisplaySetUIDs = new Set();
viewportIdVolumeInputArrayMap.forEach((volumeInputArray, viewportId) => {
volumeInputArray.forEach(volumeInput => {
const { volumeId } = volumeInput;
uniqueViewportVolumeDisplaySetUIDs.add(volumeId);
});
});

// Check if all the matched volumes are loaded
for (const [_, details] of displaySetsMatchDetails.entries()) {
const { SeriesInstanceUID } = details;
const uniqueMatchedDisplaySetUIDs = new Set();

// HangingProtocol has matched, but don't have all the volumes created yet, so return
if (!Array.from(volumeIdMapsToLoad.values()).includes(SeriesInstanceUID)) {
return;
}
matchDetails.forEach(matchDetail => {
const { displaySetsInfo } = matchDetail;
displaySetsInfo.forEach(({ displaySetInstanceUID }) => {
uniqueMatchedDisplaySetUIDs.add(displaySetInstanceUID);
});
});

if (uniqueViewportVolumeDisplaySetUIDs.size !== uniqueMatchedDisplaySetUIDs.size) {
return;
}

const volumeIds = Array.from(volumeIdMapsToLoad.keys()).slice();
Expand Down
30 changes: 17 additions & 13 deletions extensions/cornerstone/src/utils/interleaveTopToBottom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,21 +75,25 @@ export default function interleaveTopToBottom({
* listen to it and as the other viewports are created we can set the volumes for them
* since volumes are already started loading.
*/
if (filteredMatchDetails.length !== viewportIdVolumeInputArrayMap.size) {
return;
}
const uniqueViewportVolumeDisplaySetUIDs = new Set();
viewportIdVolumeInputArrayMap.forEach((volumeInputArray, viewportId) => {
volumeInputArray.forEach(volumeInput => {
const { volumeId } = volumeInput;
uniqueViewportVolumeDisplaySetUIDs.add(volumeId);
});
});

// Check if all the matched volumes are loaded
for (const [_, details] of displaySetsMatchDetails.entries()) {
const { SeriesInstanceUID, displaySetInstanceUID } = details;
const uniqueMatchedDisplaySetUIDs = new Set();

// HangingProtocol has matched, but don't have all the volumes created yet, so return
if (
displaySetsToLoad.has(displaySetInstanceUID) &&
!Array.from(volumeIdMapsToLoad.values()).includes(SeriesInstanceUID)
) {
return;
}
matchDetails.forEach(matchDetail => {
const { displaySetsInfo } = matchDetail;
displaySetsInfo.forEach(({ displaySetInstanceUID }) => {
uniqueMatchedDisplaySetUIDs.add(displaySetInstanceUID);
});
});

if (uniqueViewportVolumeDisplaySetUIDs.size !== uniqueMatchedDisplaySetUIDs.size) {
return;
}

const volumeIds = Array.from(volumeIdMapsToLoad.keys()).slice();
Expand Down

0 comments on commit 28e7248

Please sign in to comment.