From c9fbd1f735eb21056fe6a77cd37a8be0544a823a Mon Sep 17 00:00:00 2001 From: Alireza Date: Mon, 11 Sep 2023 21:52:40 -0400 Subject: [PATCH 1/4] feat(brush size): enable specifying brush size for specific tool --- .../displayTools/Labelmap/labelmapDisplay.ts | 3 ++ .../displayTools/SegmentationDisplayTool.ts | 30 ++++++++----------- .../segmentation/brushSizeForToolGroup.ts | 12 +++++--- .../src/utilities/segmentation/utilities.ts | 6 +++- 4 files changed, 28 insertions(+), 23 deletions(-) diff --git a/packages/tools/src/tools/displayTools/Labelmap/labelmapDisplay.ts b/packages/tools/src/tools/displayTools/Labelmap/labelmapDisplay.ts index 8dd38b422d..42e071b693 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 chaged. 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..5192f76d23 100644 --- a/packages/tools/src/utilities/segmentation/brushSizeForToolGroup.ts +++ b/packages/tools/src/utilities/segmentation/brushSizeForToolGroup.ts @@ -6,7 +6,8 @@ import getBrushToolInstances from './utilities'; export function setBrushSizeForToolGroup( toolGroupId: string, - brushSize: number + brushSize: number, + toolName?: string ): void { const toolGroup = getToolGroup(toolGroupId); @@ -14,7 +15,7 @@ export function setBrushSizeForToolGroup( return; } - const brushBasedToolInstances = getBrushToolInstances(toolGroupId); + const brushBasedToolInstances = getBrushToolInstances(toolGroupId, toolName); brushBasedToolInstances.forEach((tool: BrushTool) => { tool.configuration.brushSize = brushSize; @@ -45,7 +46,10 @@ export function setBrushSizeForToolGroup( triggerAnnotationRenderForViewportIds(renderingEngine, viewportIds); } -export function getBrushSizeForToolGroup(toolGroupId: string): void { +export function getBrushSizeForToolGroup( + toolGroupId: string, + toolName?: string +): void { const toolGroup = getToolGroup(toolGroupId); if (toolGroup === undefined) { @@ -58,7 +62,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..47b3bfeafb 100644 --- a/packages/tools/src/utilities/segmentation/utilities.ts +++ b/packages/tools/src/utilities/segmentation/utilities.ts @@ -10,7 +10,7 @@ export type ThresholdInformation = { upper: number; }; -export default function getBrushToolInstances(toolGroupId) { +export default function getBrushToolInstances(toolGroupId, toolName) { const toolGroup = getToolGroup(toolGroupId); if (toolGroup === undefined) { @@ -23,6 +23,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 From a8d3ed4b782feb2909112c09811eeb5f208d736e Mon Sep 17 00:00:00 2001 From: Alireza Date: Tue, 12 Sep 2023 13:34:14 -0400 Subject: [PATCH 2/4] address review comments --- .../api/streaming-image-volume-loader.api.md | 3 +-- common/reviews/api/tools.api.md | 4 ++-- .../segmentation/brushSizeForToolGroup.ts | 14 ++++++++++++++ .../tools/src/utilities/segmentation/utilities.ts | 5 ++++- 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/common/reviews/api/streaming-image-volume-loader.api.md b/common/reviews/api/streaming-image-volume-loader.api.md index 454e7f8af1..3bb44fe637 100644 --- a/common/reviews/api/streaming-image-volume-loader.api.md +++ b/common/reviews/api/streaming-image-volume-loader.api.md @@ -4,7 +4,6 @@ ```ts -import { default as default_2 } from 'packages/core/dist/esm/enums/RequestType'; import type { GetGPUTier } from 'detect-gpu'; import type { mat4 } from 'gl-matrix'; import type { TierResult } from 'detect-gpu'; @@ -1562,7 +1561,7 @@ export class StreamingImageVolume extends BaseStreamingImageVolume { }; }; priority: number; - requestType: default_2; + requestType: RequestType_2; additionalDetails: { volumeId: string; }; diff --git a/common/reviews/api/tools.api.md b/common/reviews/api/tools.api.md index 3c04ed5c0e..a1045ca2c6 100644 --- a/common/reviews/api/tools.api.md +++ b/common/reviews/api/tools.api.md @@ -2075,7 +2075,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; @@ -4675,7 +4675,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/utilities/segmentation/brushSizeForToolGroup.ts b/packages/tools/src/utilities/segmentation/brushSizeForToolGroup.ts index 5192f76d23..c88d846086 100644 --- a/packages/tools/src/utilities/segmentation/brushSizeForToolGroup.ts +++ b/packages/tools/src/utilities/segmentation/brushSizeForToolGroup.ts @@ -4,6 +4,13 @@ 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, @@ -46,6 +53,13 @@ export function setBrushSizeForToolGroup( triggerAnnotationRenderForViewportIds(renderingEngine, viewportIds); } +/** + * 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 diff --git a/packages/tools/src/utilities/segmentation/utilities.ts b/packages/tools/src/utilities/segmentation/utilities.ts index 47b3bfeafb..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, toolName) { +export default function getBrushToolInstances( + toolGroupId: string, + toolName?: string +) { const toolGroup = getToolGroup(toolGroupId); if (toolGroup === undefined) { From d37dd90a5e4d84edca48544710dd644bb9c65bf4 Mon Sep 17 00:00:00 2001 From: Alireza Date: Tue, 12 Sep 2023 13:35:08 -0400 Subject: [PATCH 3/4] typo; --- .../tools/src/tools/displayTools/Labelmap/labelmapDisplay.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/tools/src/tools/displayTools/Labelmap/labelmapDisplay.ts b/packages/tools/src/tools/displayTools/Labelmap/labelmapDisplay.ts index 42e071b693..f86a6c842f 100644 --- a/packages/tools/src/tools/displayTools/Labelmap/labelmapDisplay.ts +++ b/packages/tools/src/tools/displayTools/Labelmap/labelmapDisplay.ts @@ -277,7 +277,7 @@ function _setLabelmapColorAndOpacity( ); // Todo: the below loop probably can be optimized so that we don't hit it - // unless a config has chaged. Right now we get into the following loop + // 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; From 3d1fbc2a7759a7cf1cdbe420e06ad38baf9bf3ac Mon Sep 17 00:00:00 2001 From: Alireza Date: Tue, 12 Sep 2023 13:46:31 -0400 Subject: [PATCH 4/4] update api --- common/reviews/api/streaming-image-volume-loader.api.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/common/reviews/api/streaming-image-volume-loader.api.md b/common/reviews/api/streaming-image-volume-loader.api.md index 3bb44fe637..454e7f8af1 100644 --- a/common/reviews/api/streaming-image-volume-loader.api.md +++ b/common/reviews/api/streaming-image-volume-loader.api.md @@ -4,6 +4,7 @@ ```ts +import { default as default_2 } from 'packages/core/dist/esm/enums/RequestType'; import type { GetGPUTier } from 'detect-gpu'; import type { mat4 } from 'gl-matrix'; import type { TierResult } from 'detect-gpu'; @@ -1561,7 +1562,7 @@ export class StreamingImageVolume extends BaseStreamingImageVolume { }; }; priority: number; - requestType: RequestType_2; + requestType: default_2; additionalDetails: { volumeId: string; };