@@ -184,10 +184,11 @@ class CornerstoneViewport extends Component {
184184 const image = await cornerstone . loadAndCacheImage ( imageId ) ;
185185
186186 // Display
187+
187188 cornerstone . displayImage ( this . element , image ) ;
188189
189190 if ( isStackPrefetchEnabled ) {
190- _enableStackPrefetching ( this . element ) ;
191+ cornerstoneTools . stackPrefetch . enable ( this . element ) ;
191192 }
192193
193194 if ( isPlaying ) {
@@ -254,10 +255,7 @@ class CornerstoneViewport extends Component {
254255
255256 // Need to stop/start to pickup stack changes in prefetcher
256257 if ( shouldStopStartStackPrefetch ) {
257- const clear = true ;
258-
259- _enableStackPrefetching ( this . element , clear ) ;
260- _enableStackPrefetching ( this . element ) ;
258+ cornerstoneTools . stackPrefetch . enable ( this . element ) ;
261259 }
262260
263261 // ~~ ACTIVE TOOL
@@ -319,7 +317,7 @@ class CornerstoneViewport extends Component {
319317 this . _setupLoadHandlers ( clear ) ;
320318
321319 if ( this . props . isStackPrefetchEnabled ) {
322- _enableStackPrefetching ( this . element , clear ) ;
320+ cornerstoneTools . stackPrefetch . disable ( this . element ) ;
323321 }
324322
325323 cornerstoneTools . clearToolState ( this . element , 'stackPrefetch' ) ;
@@ -714,85 +712,6 @@ class CornerstoneViewport extends Component {
714712 this . setViewportActive ( ) ;
715713
716714 scrollToIndex ( this . element , value ) ;
717-
718- this . resetPrefetching ( value ) ;
719- } ;
720-
721- resetPrefetching = imageIdIndex => {
722- cornerstoneTools . stackPrefetch . setConfiguration ( {
723- maxImagesToPrefetch : Infinity ,
724- preserveExistingPool : false ,
725- maxSimultaneousRequests : 6 ,
726- } ) ;
727-
728- const { imageIds } = this . props ;
729-
730- const minImageIdIndex = 0 ;
731- const maxImageIdIndex = imageIds . length - 1 ;
732-
733- let lowerImageIdIndex = imageIdIndex ;
734- let upperImageIdIndex = imageIdIndex ;
735-
736- // Build up an array of images to prefetch, starting with the current image.
737- let imageIdsToPrefetch = [ imageIds [ imageIdIndex ] ] ;
738-
739- // 0: From current stack position down to minimum.
740- // 1: From current stack position up to maximum.
741-
742- const prefetchQueuedFilled = [ false , false ] ;
743-
744- // Check if on edges and some criteria is already fulfilled
745-
746- if ( imageIdIndex === minImageIdIndex ) {
747- prefetchQueuedFilled [ 0 ] = true ;
748- } else if ( imageIdIndex === maxImageIdIndex ) {
749- prefetchQueuedFilled [ 1 ] = true ;
750- }
751-
752- while (
753- prefetchQueuedFilled [ 0 ] === false ||
754- prefetchQueuedFilled [ 1 ] === false
755- ) {
756- if ( prefetchQueuedFilled [ 0 ] === false ) {
757- // Add imageId bellow
758- lowerImageIdIndex -- ;
759- imageIdsToPrefetch . push ( imageIds [ lowerImageIdIndex ] ) ;
760-
761- if ( lowerImageIdIndex === minImageIdIndex ) {
762- prefetchQueuedFilled [ 0 ] = true ;
763- }
764- }
765-
766- if ( prefetchQueuedFilled [ 1 ] === false ) {
767- // Add imageId above
768- upperImageIdIndex ++ ;
769- imageIdsToPrefetch . push ( imageIds [ upperImageIdIndex ] ) ;
770-
771- if ( upperImageIdIndex === maxImageIdIndex ) {
772- prefetchQueuedFilled [ 1 ] = true ;
773- }
774- }
775- }
776-
777- const requestPoolManager = cornerstoneTools . requestPoolManager ;
778- const requestType = 'prefetch' ;
779- const preventCache = false ;
780- const noop = ( ) => { } ;
781-
782- requestPoolManager . clearRequestStack ( 'prefetch' ) ;
783-
784- imageIdsToPrefetch . forEach ( imageId => {
785- requestPoolManager . addRequest (
786- { } ,
787- imageId ,
788- requestType ,
789- preventCache ,
790- noop ,
791- noop
792- ) ;
793- } ) ;
794-
795- requestPoolManager . startGrabbing ( ) ;
796715 } ;
797716
798717 setViewportActive = ( ) => {
@@ -886,14 +805,6 @@ function _trySetActiveTool(element, activeToolName) {
886805 } ) ;
887806}
888807
889- function _enableStackPrefetching ( element , clear = false ) {
890- if ( clear ) {
891- cornerstoneTools . stackPrefetch . disable ( element ) ;
892- } else {
893- cornerstoneTools . stackPrefetch . enable ( element ) ;
894- }
895- }
896-
897808/**
898809 * Iterate over the provided tools; Add each tool to the target element
899810 *
0 commit comments