Skip to content

Commit

Permalink
Fix disabling issue
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesAPetts committed Sep 24, 2020
1 parent 832a82c commit e35774b
Showing 1 changed file with 3 additions and 93 deletions.
96 changes: 3 additions & 93 deletions src/CornerstoneViewport/CornerstoneViewport.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ class CornerstoneViewport extends Component {
cornerstone.displayImage(this.element, image);

if (isStackPrefetchEnabled) {
_enableStackPrefetching(this.element);
cornerstoneTools.stackPrefetch.enable(this.element);
}

if (isPlaying) {
Expand Down Expand Up @@ -254,10 +254,7 @@ class CornerstoneViewport extends Component {

// Need to stop/start to pickup stack changes in prefetcher
if (shouldStopStartStackPrefetch) {
const clear = true;

_enableStackPrefetching(this.element, clear);
_enableStackPrefetching(this.element);
cornerstoneTools.stackPrefetch.enable(this.element);
}

// ~~ ACTIVE TOOL
Expand Down Expand Up @@ -319,7 +316,7 @@ class CornerstoneViewport extends Component {
this._setupLoadHandlers(clear);

if (this.props.isStackPrefetchEnabled) {
_enableStackPrefetching(this.element, clear);
cornerstoneTools.stackPrefetch.disable(this.element);
}

cornerstoneTools.clearToolState(this.element, 'stackPrefetch');
Expand Down Expand Up @@ -714,85 +711,6 @@ class CornerstoneViewport extends Component {
this.setViewportActive();

scrollToIndex(this.element, value);

this.resetPrefetching(value);
};

resetPrefetching = imageIdIndex => {
cornerstoneTools.stackPrefetch.setConfiguration({
maxImagesToPrefetch: Infinity,
preserveExistingPool: false,
maxSimultaneousRequests: 6,
});

const { imageIds } = this.props;

const minImageIdIndex = 0;
const maxImageIdIndex = imageIds.length - 1;

let lowerImageIdIndex = imageIdIndex;
let upperImageIdIndex = imageIdIndex;

// Build up an array of images to prefetch, starting with the current image.
let imageIdsToPrefetch = [imageIds[imageIdIndex]];

// 0: From current stack position down to minimum.
// 1: From current stack position up to maximum.

const prefetchQueuedFilled = [false, false];

// Check if on edges and some criteria is already fulfilled

if (imageIdIndex === minImageIdIndex) {
prefetchQueuedFilled[0] = true;
} else if (imageIdIndex === maxImageIdIndex) {
prefetchQueuedFilled[1] = true;
}

while (
prefetchQueuedFilled[0] === false ||
prefetchQueuedFilled[1] === false
) {
if (prefetchQueuedFilled[0] === false) {
// Add imageId bellow
lowerImageIdIndex--;
imageIdsToPrefetch.push(imageIds[lowerImageIdIndex]);

if (lowerImageIdIndex === minImageIdIndex) {
prefetchQueuedFilled[0] = true;
}
}

if (prefetchQueuedFilled[1] === false) {
// Add imageId above
upperImageIdIndex++;
imageIdsToPrefetch.push(imageIds[upperImageIdIndex]);

if (upperImageIdIndex === maxImageIdIndex) {
prefetchQueuedFilled[1] = true;
}
}
}

const requestPoolManager = cornerstoneTools.requestPoolManager;
const requestType = 'prefetch';
const preventCache = false;
const noop = () => {};

requestPoolManager.clearRequestStack('prefetch');

imageIdsToPrefetch.forEach(imageId => {
requestPoolManager.addRequest(
{},
imageId,
requestType,
preventCache,
noop,
noop
);
});

requestPoolManager.startGrabbing();
};

setViewportActive = () => {
Expand Down Expand Up @@ -886,14 +804,6 @@ function _trySetActiveTool(element, activeToolName) {
});
}

function _enableStackPrefetching(element, clear = false) {
if (clear) {
cornerstoneTools.stackPrefetch.disable(element);
} else {
cornerstoneTools.stackPrefetch.enable(element);
}
}

/**
* Iterate over the provided tools; Add each tool to the target element
*
Expand Down

0 comments on commit e35774b

Please sign in to comment.