cornerstonejs / cornerstoneTools

A framework for tools built on top of Cornerstone.
https://tools.cornerstonejs.org/
MIT License
574 stars 456 forks source link

StackPrefetch fetches only first layer #1554

Open hpawe01 opened 10 months ago

hpawe01 commented 10 months ago

Prerequisites

Description

In a multi layer setup only the images of the first stack are prefetched. If you have multiple layers, e.g. 1. the actual image and 2. an overlay, and scroll through the stack, you will notice a delay for the overlay part.

In the code you also see that only the first stack is used for the prefetch operation: https://github.com/cornerstonejs/cornerstoneTools/blob/master/src/stackTools/stackPrefetch.js#L77

Steps to Reproduce the issue

// 1. add stack manager
cornerstoneTools.addStackStateManager(element, ['stack']);

// 2. add stacks
cornerstoneTools.addToolState(element, 'stack', stack1)
cornerstoneTools.addToolState(element, 'stack', stack2)

// 3. configure fusion renderer
const renderer = new cornerstoneTools.stackRenderers.FusionRenderer();
cornerstoneTools.addToolState(element, 'stackRenderer', renderer);
renderer.currentImageIdIndex = stack1.currentImageIdIndex
renderer.findImageFn = (imageIds, targetImageId) => {
  const targetImageIndex = stack1.imageIds.indexOf(targetImageId)
  return imageIds[targetImageIndex];
}
renderer.render(element);

// 4. prefetch stack
cornerstoneTools.stackPrefetch.setConfiguration({ 'maxSimultaneousRequests': 8, 'preserveExistingPool': true });
cornerstoneTools.stackPrefetch.enable(element);

Expected behavior: stackPrefetch.enable() should prefetch images for all stacks

Actual behavior: stackPrefetch.enable() prefetches images only for the first stack

CodeSandbox With Reproduction of Issue:

Sorry, I don't have that kind of dummy stack data public available.