Skip to content

Commit

Permalink
Merge pull request #1029 from dannyrb/feature/per-segment-brush-opacity
Browse files Browse the repository at this point in the history
feat: force bitmap cache invalidation
  • Loading branch information
dannyrb authored Jul 25, 2019
2 parents dabef0b + 67cc7d0 commit 868f535
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 12 deletions.
37 changes: 25 additions & 12 deletions src/eventListeners/onImageRenderedBrushEventHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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,
Expand All @@ -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);
});
}

Expand Down
11 changes: 11 additions & 0 deletions src/store/modules/brushModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ const state = {
visibleSegmentations: {},
imageBitmapCache: {},
segmentationMetadata: {},
//
invalidatedEnabledElements: [],
};

const setters = {
Expand All @@ -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
Expand Down

0 comments on commit 868f535

Please sign in to comment.