-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(DICOM Overlay): The overlay data wasn't being refreshed on change #3793
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
bb321cf
fix: The overlay data wasn't being refreshed on change
wayfarer3130 79be98a
Merge remote-tracking branch 'ohif/master' into feat/update-overlay-m…
wayfarer3130 8210da3
Split out the metadata provider for use elsewhere.
wayfarer3130 f129bd9
Fix the submodule update init to use latest from main
wayfarer3130 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
import { VolumeViewport, metaData } from '@cornerstonejs/core'; | ||
import { utilities } from '@cornerstonejs/core'; | ||
import { VolumeViewport, metaData, utilities } from '@cornerstonejs/core'; | ||
import { IStackViewport, IVolumeViewport, Point3 } from '@cornerstonejs/core/dist/esm/types'; | ||
import { AnnotationDisplayTool, drawing } from '@cornerstonejs/tools'; | ||
import { guid } from '@ohif/core/src/utils'; | ||
|
@@ -15,6 +14,9 @@ interface CachedStat { | |
}[]; | ||
} | ||
|
||
const _cachedOverlayMetadata: Map<string, any[]> = new Map(); | ||
let _cachedStats: { [key: string]: CachedStat } = {}; | ||
|
||
/** | ||
* Image Overlay Viewer tool is not a traditional tool that requires user interactin. | ||
* But it is used to display Pixel Overlays. And it will provide toggling capability. | ||
|
@@ -27,8 +29,26 @@ interface CachedStat { | |
*/ | ||
class ImageOverlayViewerTool extends AnnotationDisplayTool { | ||
static toolName = 'ImageOverlayViewer'; | ||
private _cachedOverlayMetadata: Map<string, any[]> = new Map(); | ||
private _cachedStats: { [key: string]: CachedStat } = {}; | ||
/** Adds the metadata for overlayPlaneModule */ | ||
public static add(imageId, metadata) { | ||
if (_cachedOverlayMetadata.get(imageId) === metadata) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make the cache a standard metaData provider. |
||
// This is a no-op here as the tool re-caches the data | ||
return; | ||
} | ||
_cachedOverlayMetadata.set(imageId, metadata); | ||
delete _cachedStats[imageId]; | ||
} | ||
|
||
/** Standard getter for metadata */ | ||
public static get(type: string, query: string | string[]) { | ||
if (Array.isArray(query)) { | ||
return; | ||
} | ||
if (type !== 'overlayPlaneModule') { | ||
return; | ||
} | ||
return _cachedOverlayMetadata.get(query); | ||
} | ||
|
||
wayfarer3130 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
constructor( | ||
toolProps = {}, | ||
|
@@ -43,8 +63,8 @@ class ImageOverlayViewerTool extends AnnotationDisplayTool { | |
} | ||
|
||
onSetToolDisabled = (): void => { | ||
this._cachedStats = {}; | ||
this._cachedOverlayMetadata = new Map(); | ||
_cachedStats = {}; | ||
_cachedOverlayMetadata.clear(); | ||
}; | ||
|
||
protected getReferencedImageId(viewport: IStackViewport | IVolumeViewport): string { | ||
|
@@ -64,9 +84,8 @@ class ImageOverlayViewerTool extends AnnotationDisplayTool { | |
return; | ||
} | ||
|
||
const overlays = | ||
this._cachedOverlayMetadata.get(imageId) ?? | ||
metaData.get('overlayPlaneModule', imageId)?.overlays; | ||
const overlayMetadata = metaData.get('overlayPlaneModule', imageId); | ||
const overlays = overlayMetadata?.overlays; | ||
|
||
// no overlays | ||
if (!overlays?.length) { | ||
|
@@ -79,7 +98,8 @@ class ImageOverlayViewerTool extends AnnotationDisplayTool { | |
overlay.y ||= 0; | ||
}); | ||
|
||
this._cachedOverlayMetadata.set(imageId, overlays); | ||
// Will clear cached stat data when the overlay data changes | ||
ImageOverlayViewerTool.add(imageId, overlayMetadata); | ||
|
||
this._getCachedStat(imageId, overlays, this.configuration.fillColor).then(cachedStat => { | ||
cachedStat.overlays.forEach(overlay => { | ||
|
@@ -155,8 +175,8 @@ class ImageOverlayViewerTool extends AnnotationDisplayTool { | |
overlayMetadata: any[], | ||
color: number[] | ||
): Promise<CachedStat> { | ||
if (this._cachedStats[imageId] && this._isSameColor(this._cachedStats[imageId].color, color)) { | ||
return this._cachedStats[imageId]; | ||
if (_cachedStats[imageId] && this._isSameColor(_cachedStats[imageId].color, color)) { | ||
return _cachedStats[imageId]; | ||
} | ||
|
||
const overlays = await Promise.all( | ||
|
@@ -178,7 +198,7 @@ class ImageOverlayViewerTool extends AnnotationDisplayTool { | |
|
||
const dataUrl = this._renderOverlayToDataUrl( | ||
{ width: overlay.columns, height: overlay.rows }, | ||
color, | ||
overlay.color || color, | ||
pixelData | ||
); | ||
|
||
|
@@ -191,12 +211,12 @@ class ImageOverlayViewerTool extends AnnotationDisplayTool { | |
}) | ||
); | ||
|
||
this._cachedStats[imageId] = { | ||
_cachedStats[imageId] = { | ||
color: color, | ||
overlays: overlays.filter(overlay => overlay), | ||
}; | ||
|
||
return this._cachedStats[imageId]; | ||
return _cachedStats[imageId]; | ||
} | ||
|
||
/** | ||
|
@@ -262,4 +282,7 @@ class ImageOverlayViewerTool extends AnnotationDisplayTool { | |
} | ||
} | ||
|
||
// Needs to be higher priority than default provider | ||
metaData.addProvider(ImageOverlayViewerTool.get, 10_000); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. register the provider for use. |
||
|
||
export default ImageOverlayViewerTool; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This just exposes the tool externally to be used. Otherwise it becomes difficult to add new metadata.