diff --git a/common/reviews/api/tools.api.md b/common/reviews/api/tools.api.md index e623166efe..87e37acf7f 100644 --- a/common/reviews/api/tools.api.md +++ b/common/reviews/api/tools.api.md @@ -2076,7 +2076,7 @@ function getBoundingBoxAroundShape(points: Types_2.Point3[], dimensions?: Types_ function getBoundsIJKFromRectangleAnnotations(annotations: any, referenceVolume: any, options?: Options): any; // @public (undocumented) -function getBrushSizeForToolGroup(toolGroupId: string): void; +function getBrushSizeForToolGroup(toolGroupId: string, toolName?: string): void; // @public (undocumented) function getBrushThresholdForToolGroup(toolGroupId: string): any; @@ -4677,7 +4677,7 @@ function setAnnotationVisibility(annotationUID: string, visible?: boolean): void function setAttributesIfNecessary(attributes: any, svgNode: any): void; // @public (undocumented) -function setBrushSizeForToolGroup(toolGroupId: string, brushSize: number): void; +function setBrushSizeForToolGroup(toolGroupId: string, brushSize: number, toolName?: string): void; // @public (undocumented) function setBrushThresholdForToolGroup(toolGroupId: string, threshold: Types_2.Point2): void; diff --git a/packages/tools/src/tools/displayTools/Labelmap/labelmapDisplay.ts b/packages/tools/src/tools/displayTools/Labelmap/labelmapDisplay.ts index 8dd38b422d..f86a6c842f 100644 --- a/packages/tools/src/tools/displayTools/Labelmap/labelmapDisplay.ts +++ b/packages/tools/src/tools/displayTools/Labelmap/labelmapDisplay.ts @@ -276,6 +276,9 @@ function _setLabelmapColorAndOpacity( isActiveLabelmap ); + // Todo: the below loop probably can be optimized so that we don't hit it + // unless a config has changed. Right now we get into the following loop + // even for brush drawing which does not makes sense for (let i = 0; i < numColors; i++) { const segmentIndex = i; const segmentColor = colorLUT[segmentIndex]; diff --git a/packages/tools/src/tools/displayTools/SegmentationDisplayTool.ts b/packages/tools/src/tools/displayTools/SegmentationDisplayTool.ts index 8ce0686265..6f98e72552 100644 --- a/packages/tools/src/tools/displayTools/SegmentationDisplayTool.ts +++ b/packages/tools/src/tools/displayTools/SegmentationDisplayTool.ts @@ -143,26 +143,20 @@ class SegmentationDisplayTool extends BaseTool { const config = this._getMergedRepresentationsConfig(toolGroupId); const viewportsRenderList = []; + const display = + representation.type === Representations.Labelmap + ? labelmapDisplay + : contourDisplay; + for (const viewport of toolGroupViewports) { - if (representation.type == Representations.Labelmap) { - viewportsRenderList.push( - labelmapDisplay.render( - viewport as Types.IVolumeViewport, - representation, - config - ) - ); - } else if (representation.type == Representations.Contour) { - viewportsRenderList.push( - contourDisplay.render( - viewport as Types.IVolumeViewport, - representation, - config - ) - ); - } - } + const renderedViewport = display.render( + viewport as Types.IVolumeViewport, + representation, + config + ); + viewportsRenderList.push(renderedViewport); + } return viewportsRenderList; } ); diff --git a/packages/tools/src/utilities/segmentation/brushSizeForToolGroup.ts b/packages/tools/src/utilities/segmentation/brushSizeForToolGroup.ts index f544d553f0..c88d846086 100644 --- a/packages/tools/src/utilities/segmentation/brushSizeForToolGroup.ts +++ b/packages/tools/src/utilities/segmentation/brushSizeForToolGroup.ts @@ -4,9 +4,17 @@ import triggerAnnotationRenderForViewportIds from '../triggerAnnotationRenderFor import { getRenderingEngine } from '@cornerstonejs/core'; import getBrushToolInstances from './utilities'; +/** + * Sets the brush size for all brush-based tools in a given tool group. + * @param toolGroupId - The ID of the tool group to set the brush size for. + * @param brushSize - The new brush size to set. + * @param toolName - The name of the specific tool to set the brush size for (optional) + * If not provided, all brush-based tools in the tool group will be affected. + */ export function setBrushSizeForToolGroup( toolGroupId: string, - brushSize: number + brushSize: number, + toolName?: string ): void { const toolGroup = getToolGroup(toolGroupId); @@ -14,7 +22,7 @@ export function setBrushSizeForToolGroup( return; } - const brushBasedToolInstances = getBrushToolInstances(toolGroupId); + const brushBasedToolInstances = getBrushToolInstances(toolGroupId, toolName); brushBasedToolInstances.forEach((tool: BrushTool) => { tool.configuration.brushSize = brushSize; @@ -45,7 +53,17 @@ export function setBrushSizeForToolGroup( triggerAnnotationRenderForViewportIds(renderingEngine, viewportIds); } -export function getBrushSizeForToolGroup(toolGroupId: string): void { +/** + * Gets the brush size for the first brush-based tool instance in a given tool group. + * @param toolGroupId - The ID of the tool group to get the brush size for. + * @param toolName - The name of the specific tool to get the brush size for (Optional) + * If not provided, the first brush-based tool instance in the tool group will be used. + * @returns The brush size of the selected tool instance, or undefined if no brush-based tool instance is found. + */ +export function getBrushSizeForToolGroup( + toolGroupId: string, + toolName?: string +): void { const toolGroup = getToolGroup(toolGroupId); if (toolGroup === undefined) { @@ -58,7 +76,7 @@ export function getBrushSizeForToolGroup(toolGroupId: string): void { return; } - const brushBasedToolInstances = getBrushToolInstances(toolGroupId); + const brushBasedToolInstances = getBrushToolInstances(toolGroupId, toolName); // one is enough as they share the same brush size const brushToolInstance = brushBasedToolInstances[0]; diff --git a/packages/tools/src/utilities/segmentation/utilities.ts b/packages/tools/src/utilities/segmentation/utilities.ts index 0dc50fd820..840d9fc565 100644 --- a/packages/tools/src/utilities/segmentation/utilities.ts +++ b/packages/tools/src/utilities/segmentation/utilities.ts @@ -10,7 +10,10 @@ export type ThresholdInformation = { upper: number; }; -export default function getBrushToolInstances(toolGroupId) { +export default function getBrushToolInstances( + toolGroupId: string, + toolName?: string +) { const toolGroup = getToolGroup(toolGroupId); if (toolGroup === undefined) { @@ -23,6 +26,10 @@ export default function getBrushToolInstances(toolGroupId) { return; } + if (toolName && toolInstances[toolName]) { + return [toolInstances[toolName]]; + } + // For each tool that has BrushTool as base class, set the brush size. const brushBasedToolInstances = Object.values(toolInstances).filter( (toolInstance) => toolInstance instanceof BrushTool