All files / extensions/cornerstone/src/utils getInterleavedFrames.js

91.3% Statements 21/23
77.77% Branches 7/9
100% Functions 1/1
91.3% Lines 21/23

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61  6x 6x   6x   6x 6x     6x       6x             6x   6x       6x       114x   114x 114x         114x 6x       114x   108x 108x         108x 6x         6x    
export default function getInterleavedFrames(imageIds) {
  const minImageIdIndex = 0;
  const maxImageIdIndex = imageIds.length - 1;
 
  const middleImageIdIndex = Math.floor(imageIds.length / 2);
 
  let lowerImageIdIndex = middleImageIdIndex;
  let upperImageIdIndex = middleImageIdIndex;
 
  // Build up an array of images to prefetch, starting with the current image.
  const imageIdsToPrefetch = [
    { imageId: imageIds[middleImageIdIndex], imageIdIndex: middleImageIdIndex },
  ];
 
  const prefetchQueuedFilled = {
    currentPositionDownToMinimum: false,
    currentPositionUpToMaximum: false,
  };
 
  // Check if on edges and some criteria is already fulfilled
 
  Iif (middleImageIdIndex === minImageIdIndex) {
    prefetchQueuedFilled.currentPositionDownToMinimum = true;
  } else Iif (middleImageIdIndex === maxImageIdIndex) {
    prefetchQueuedFilled.currentPositionUpToMaximum = true;
  }
 
  while (
    !prefetchQueuedFilled.currentPositionDownToMinimum ||
    !prefetchQueuedFilled.currentPositionUpToMaximum
  ) {
    if (!prefetchQueuedFilled.currentPositionDownToMinimum) {
      // Add imageId below
      lowerImageIdIndex--;
      imageIdsToPrefetch.push({
        imageId: imageIds[lowerImageIdIndex],
        imageIdIndex: lowerImageIdIndex,
      });
 
      if (lowerImageIdIndex === minImageIdIndex) {
        prefetchQueuedFilled.currentPositionDownToMinimum = true;
      }
    }
 
    if (!prefetchQueuedFilled.currentPositionUpToMaximum) {
      // Add imageId above
      upperImageIdIndex++;
      imageIdsToPrefetch.push({
        imageId: imageIds[upperImageIdIndex],
        imageIdIndex: upperImageIdIndex,
      });
 
      if (upperImageIdIndex === maxImageIdIndex) {
        prefetchQueuedFilled.currentPositionUpToMaximum = true;
      }
    }
  }
 
  return imageIdsToPrefetch;
}