Prefetching multiple stacks stops prematurely

562 views
Skip to first unread message

Neil Panjwani

unread,
Dec 21, 2015, 4:17:03 PM12/21/15
to cornerstone platform
Hi,

I'm running into a problem with the stack prefetch tool. I'm trying to prefetch a stack of CT images and a stack of overlay images which represent radiation dose. Both stacks are jpegs and are of the same size; they are loaded with the cornerstoneWebImageLoader. 

I have no problems at all when loading the CT stack alone. When I try to prefetch both stacks as below I find that that the loading stops prematurely. When I inspect the image cache in the browser, only 5 CT slices are loaded and all of the dose slices are loaded. I'm not sure why the rest of the CT slices are not loading. I have very similar loading code from a previous app which was working well and didn't have this issue, so I wonder if some of the updates have broken the way that I'm approaching prefetching. I'm currently using the master branch of cornerstoneTools.

var synchronizer = new cornerstoneTools.Synchronizer("CornerstoneNewImage", cornerstoneTools.stackImageIndexSynchronizer);

cornerstone.loadImage(imageIds[0]).then(function(image) {
    // Display this image
    cornerstone.displayImage(element, image);

    // Set the stack as tool state
    cornerstoneTools.addStackStateManager(element, ['stack']);
    cornerstoneTools.addToolState(element, 'stack', stack);

    // Enable all tools we want to use with this element
    cornerstoneTools.mouseInput.enable(element);
    cornerstoneTools.mouseWheelInput.enable(element);
    cornerstoneTools.keyboardInput.enable(element);

    cornerstoneTools.stackScroll.activate(element, 1);
    cornerstoneTools.stackScrollWheel.activate(element);
    cornerstoneTools.stackScrollKeyboard.activate(element);

    // Stack prefetching
    cornerstoneTools.stackPrefetch.enable(element, 3);

    synchronizer.add(element);
});

// Add stacks and prefetch overlays
// overlays is an array of overlay objects
// each object contains the following keys:
// stack, element, and name 
for (var i = 0; i < overlays.length; i++) {
    var ov = overlays[i];

    cornerstone.loadImage(ov.stack.imageIds[0]).then(function(image) {
        cornerstoneTools.addStackStateManager(ov.element, ['stack']);
        cornerstoneTools.addToolState(ov.element, 'stack', ov.stack);
        cornerstoneTools.stackPrefetch.enable(ov.element, 3);
        synchronizer.add(ov.element);
    });
}

Neil Panjwani

unread,
Dec 21, 2015, 7:21:40 PM12/21/15
to cornerstone platform
I've also noticed that it works if I add a setTimeout of 5+ seconds to the code to load the overlays (enough time to finish fetching the CT). It's as if the stack prefetch gets confused when I tell it to prefetch additional stacks. Am I using it incorrectly?

Erik Ziegler

unread,
Dec 22, 2015, 1:23:43 PM12/22/15
to cornerstone platform
Hi Neil,

There could be a bug, but I'm not sure. 

First of all, stackPrefetch.enable only takes one argument now, the element itself (I don't remember if it used to take more).

When stackPrefetch is enabled on an element, it adds all the stack's imageIds to the requestPoolManager. That will request images in parallel, up to a maximum of 6 at a time (depending on your browser), to keep the maximum number of connections to the server open.

Are you enabling stackPrefetch on the same element (any element!) multiple times at any point?

When you enable stackPrefetch on an element it checks if there was previously stackPrefetch data related to this element, and if so, it clears all prefetch data from the requestPoolManager. This could be improved (e.g. we could clear only the requests related to this element). I'm not sure if this is the problem, though.

kev n

unread,
Oct 27, 2016, 6:19:49 AM10/27/16
to cornerstone platform
Hi Erik,

I have faced a similar problem as well. While fetching multiple stacks, the prefetcher just stops after a while.

However, in my case if I start scrolling a bit - the prefetching resumes and stops again. The first time it stopped at 33% of the total stack and the next time it stops at 66%.

I switched off the wifi to check if it would throw an error - which it did not. It threw an error when i started scrolling (which was expected).
It is neither a cache issue as I have been logging them to the console and it first stops when the cache is at 106 mb with 312 images cached.

Any help would be great.
Message has been deleted
Message has been deleted

Lamba Cini

unread,
Mar 21, 2017, 8:31:53 PM3/21/17
to cornerstone platform
i have a same problem, like this.


http://2.1m.yt/FFlsZuv.gif

27 Ekim 2016 Perşembe 13:19:49 UTC+3 tarihinde kev n yazdı:

Christophe Carpentier

unread,
Aug 17, 2018, 8:40:47 AM8/17/18
to cornerstone platform
I was struggling with the same issue: We use a multi-viewer layout and when switching from one viewer to the other, the first one stops loading.
We've found that the reason for this is that the prefetch query pool is emptied for each new prefetch, loading only the current one.

I'm submitting a PR to allow not to empty it, and to stack the new pool above the existing one: This way, the last selected will still have the priority, but as soon as it is over, the next one is processed.
Reply all
Reply to author
Forward
0 new messages