diff --git a/src/eventListeners/onImageRenderedBrushEventHandler.js b/src/eventListeners/onImageRenderedBrushEventHandler.js index 2146edf8c..068f5b5a4 100644 --- a/src/eventListeners/onImageRenderedBrushEventHandler.js +++ b/src/eventListeners/onImageRenderedBrushEventHandler.js @@ -139,16 +139,29 @@ function renderSegmentation(evt, segIndex, segData) { ); } - if (toolData.data[segIndex].invalidated) { - createNewBitmapAndQueueRenderOfSegmentation(evt, toolData, segIndex); - } -} - -function createNewBitmapAndQueueRenderOfSegmentation(evt, toolData, segIndex) { const eventData = evt.detail; const element = eventData.element; const enabledElement = external.cornerstone.getEnabledElement(element); + if ( + toolData.data[segIndex].invalidated || + state.invalidatedEnabledElements.includes(enabledElement.uuid) + ) { + createNewBitmapAndQueueRenderOfSegmentation( + eventData, + enabledElement.uuid, + toolData, + segIndex + ); + } +} + +function createNewBitmapAndQueueRenderOfSegmentation( + { image: eventImage, element }, + enabledElementUID, + toolData, + segIndex +) { const pixelData = toolData.data[segIndex].pixelData; const imageSpecificSegmentationAlpha = toolData.data[segIndex].alpha; @@ -160,10 +173,7 @@ function createNewBitmapAndQueueRenderOfSegmentation(evt, toolData, segIndex) { const colormap = external.cornerstone.colors.getColormap(colormapId); const colorLutTable = [[0, 0, 0, 0], colormap.getColor(segIndex)]; - const imageData = new ImageData( - eventData.image.width, - eventData.image.height - ); + const imageData = new ImageData(eventImage.width, eventImage.height); const image = { stats: {}, minPixelValue: 0, @@ -185,13 +195,16 @@ function createNewBitmapAndQueueRenderOfSegmentation(evt, toolData, segIndex) { window.createImageBitmap(imageData).then(newImageBitmap => { setters.imageBitmapCacheForElement( - enabledElement.uuid, + enabledElementUID, segIndex, newImageBitmap ); toolData.data[segIndex].invalidated = false; + state.invalidatedEnabledElements = state.invalidatedEnabledElements.filter( + iee => iee !== enabledElementUID + ); - external.cornerstone.updateImage(eventData.element); + external.cornerstone.updateImage(element); }); } diff --git a/src/store/modules/brushModule.js b/src/store/modules/brushModule.js index 90742d244..56e6e8a8b 100644 --- a/src/store/modules/brushModule.js +++ b/src/store/modules/brushModule.js @@ -12,6 +12,8 @@ const state = { visibleSegmentations: {}, imageBitmapCache: {}, segmentationMetadata: {}, + // + invalidatedEnabledElements: [], }; const setters = { @@ -25,6 +27,15 @@ const setters = { state.radius = Math.min(Math.max(radius, state.minRadius), state.maxRadius); }, + forceUpdateImageForElement(element) { + const enabledElement = external.cornerstone.getEnabledElement(element); + const enabledElementUID = enabledElement.uuid; + + if (!state.invalidatedEnabledElements.includes(enabledElementUID)) { + state.invalidatedEnabledElements.push(enabledElementUID); + } + }, + /** * TODO: Should this be a init config property? * Sets the brush color map to something other than the default