-
Notifications
You must be signed in to change notification settings - Fork 456
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(OverlayTool): Support for rendering DICOM Group 6xxx Overlay Pla…
…ne layers on top of the image (#860) - Thanks @kofifus, @jdnarvaez * feat(OverlayTool): Support for rendering overlay layers on top of the image data See DICOM: http://dicom.nema.org/dicom/2013/output/chtml/part03/sect_C.9.html re #780 * Add OverlayTool exports * Add overlay tool to examples * Make sure enabledElement is defined * Capitalize data-tool; better tool toggling * lowercase first letter 👍 * Use @cornerstonejs org scope * dry run; finding tag and publishing feature/hotfix branches as tagged releases * Change workflow priority * filtering is regex * Fix bash syntax error * invoke script w/ bash * Playing w/ bash syntax in circleCI's environment * Public scoped packages * Publish a tagged package * Make sure we're not stealing a version number that can be used for master * Better RegExp to set version * Tidying up comments and formatting * Try using an alternative package version * Update OverlayTool.js * Update OverlayTool.js * Fix prettier build error * Protect against `null` viewport pixelSpacing * Remove unnecessary changes * Fix unnecessary changes * Fixes for rendering overlays Co-authored-by: Kofifus <[email protected]> Co-authored-by: Erik Ziegler <[email protected]>
- Loading branch information
1 parent
32af3d9
commit 4eef070
Showing
4 changed files
with
128 additions
and
1 deletion.
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
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 |
---|---|---|
@@ -0,0 +1,110 @@ | ||
import external from '../externalModules.js'; | ||
import BaseTool from './base/BaseTool.js'; | ||
|
||
/** | ||
* | ||
* http://dicom.nema.org/dicom/2013/output/chtml/part03/sect_C.9.html | ||
* | ||
* @public | ||
* @class Overlay | ||
* @memberof Tools | ||
* | ||
* @classdesc Tool for displaying a scale overlay on the image. | ||
* @extends Tools.Base.BaseTool | ||
*/ | ||
export default class OverlayTool extends BaseTool { | ||
constructor(configuration = {}) { | ||
const defaultConfig = { | ||
name: 'Overlay', | ||
configuration: {}, | ||
mixins: ['enabledOrDisabledBinaryTool'], | ||
}; | ||
const initialConfiguration = Object.assign(defaultConfig, configuration); | ||
|
||
super(initialConfiguration); | ||
|
||
this.initialConfiguration = initialConfiguration; | ||
} | ||
|
||
enabledCallback(element) { | ||
this.forceImageUpdate(element); | ||
} | ||
|
||
disabledCallback(element) { | ||
this.forceImageUpdate(element); | ||
} | ||
|
||
forceImageUpdate(element) { | ||
const enabledElement = external.cornerstone.getEnabledElement(element); | ||
|
||
if (enabledElement.image) { | ||
external.cornerstone.updateImage(element); | ||
} | ||
} | ||
|
||
renderToolData(evt) { | ||
const eventData = evt.detail; | ||
const { enabledElement, image, viewport, canvasContext } = eventData; | ||
|
||
if (!eventData || !enabledElement || !image) { | ||
return; | ||
} | ||
|
||
const overlayPlaneMetadata = external.cornerstone.metaData.get( | ||
'overlayPlaneModule', | ||
image.imageId | ||
); | ||
|
||
if ( | ||
!overlayPlaneMetadata || | ||
!overlayPlaneMetadata.overlays || | ||
!overlayPlaneMetadata.overlays.length | ||
) { | ||
return; | ||
} | ||
|
||
const viewportPixelSpacing = { | ||
column: viewport.displayedArea.columnPixelSpacing || 1, | ||
row: viewport.displayedArea.rowPixelSpacing || 1, | ||
}; | ||
const imageWidth = | ||
Math.abs(viewport.displayedArea.brhc.x - viewport.displayedArea.tlhc.x) * | ||
viewportPixelSpacing.column; | ||
const imageHeight = | ||
Math.abs(viewport.displayedArea.brhc.y - viewport.displayedArea.tlhc.y) * | ||
viewportPixelSpacing.row; | ||
|
||
overlayPlaneMetadata.overlays.forEach(overlay => { | ||
if (overlay.visible === false) { | ||
return; | ||
} | ||
|
||
const layerCanvas = document.createElement('canvas'); | ||
|
||
layerCanvas.width = imageWidth; | ||
layerCanvas.height = imageHeight; | ||
|
||
const layerContext = layerCanvas.getContext('2d'); | ||
|
||
layerContext.fillStyle = overlay.fillStyle || 'white'; | ||
|
||
if (overlay.type === 'R') { | ||
layerContext.fillRect(0, 0, layerCanvas.width, layerCanvas.height); | ||
layerContext.globalCompositeOperation = 'xor'; | ||
} | ||
|
||
let i = 0; | ||
|
||
for (let y = 0; y < overlay.rows; y++) { | ||
for (let x = 0; x < overlay.columns; x++) { | ||
if (overlay.pixelData[i++] > 0) { | ||
layerContext.fillRect(x, y, 1, 1); | ||
} | ||
} | ||
} | ||
|
||
// Draw the overlay layer onto the canvas | ||
canvasContext.drawImage(layerCanvas, 0, 0); | ||
}); | ||
} | ||
} |
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