From e35774ba39287f7900c511a5d37111564b422b4a Mon Sep 17 00:00:00 2001 From: "James A. Petts" Date: Thu, 24 Sep 2020 16:57:40 +0100 Subject: [PATCH] Fix disabling issue --- .../CornerstoneViewport.js | 96 +------------------ 1 file changed, 3 insertions(+), 93 deletions(-) diff --git a/src/CornerstoneViewport/CornerstoneViewport.js b/src/CornerstoneViewport/CornerstoneViewport.js index 0027527..c2bd638 100644 --- a/src/CornerstoneViewport/CornerstoneViewport.js +++ b/src/CornerstoneViewport/CornerstoneViewport.js @@ -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) { @@ -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 @@ -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'); @@ -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 = () => { @@ -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 *