From f3beb8e7115429bdb0e37f4c61491d0b28a2f6b6 Mon Sep 17 00:00:00 2001 From: Joe Boccanfuso <109477394+jbocce@users.noreply.github.com> Date: Thu, 18 Dec 2025 09:33:54 -0500 Subject: [PATCH] fix(segmentation): When setting the segmentation style and the representation type is not provided, apply the style to all representation types. (#5662) --- extensions/cornerstone/src/commandsModule.ts | 122 +++++-------------- 1 file changed, 32 insertions(+), 90 deletions(-) diff --git a/extensions/cornerstone/src/commandsModule.ts b/extensions/cornerstone/src/commandsModule.ts index 53d987ceb..75964b503 100644 --- a/extensions/cornerstone/src/commandsModule.ts +++ b/extensions/cornerstone/src/commandsModule.ts @@ -179,6 +179,31 @@ function commandsModule({ } } + /** + * Creates a command function that sets a style property for segmentation types. + * If type is provided, sets the property for that type only. + * If type is not provided, sets the property for both Labelmap and Contour types. + * @param propertyName - The name of the style property to set + * @returns A command function that takes { type, value } + */ + const createSetStyleCommand = (propertyName: string) => { + return ({ type, value }) => { + const { segmentationService } = servicesManager.services; + if (type) { + segmentationService.setStyle({ type }, { [propertyName]: value }); + } else { + segmentationService.setStyle( + { type: SegmentationRepresentations.Labelmap }, + { [propertyName]: value } + ); + segmentationService.setStyle( + { type: SegmentationRepresentations.Contour }, + { [propertyName]: value } + ); + } + }; + }; + const actions = { jumpToMeasurementViewport: ({ annotationUID, measurement }) => { cornerstoneTools.annotation.selection.setAnnotationSelected(annotationUID, true); @@ -1728,89 +1753,6 @@ function commandsModule({ segmentationService.setRenderInactiveSegmentations(viewportId, !renderInactive); }, - /** - * Sets the fill alpha value for a segmentation type - * @param props.type - The type of segmentation - * @param props.value - The alpha value to set - */ - setFillAlphaCommand: ({ type, value }) => { - const { segmentationService } = servicesManager.services; - segmentationService.setStyle({ type }, { fillAlpha: value }); - }, - - /** - * Sets the outline width for a segmentation type - * @param props.type - The type of segmentation - * @param props.value - The width value to set - */ - setOutlineWidthCommand: ({ type, value }) => { - const { segmentationService } = servicesManager.services; - segmentationService.setStyle({ type }, { outlineWidth: value }); - }, - - /** - * Sets whether to render fill for a segmentation type - * @param props.type - The type of segmentation - * @param props.value - Whether to render fill - */ - setRenderFillCommand: ({ type, value }) => { - const { segmentationService } = servicesManager.services; - segmentationService.setStyle({ type }, { renderFill: value }); - }, - - /** - * Sets whether to render fill for inactive segmentations of a segmentation type - * @param props.type - The type of segmentation - * @param props.value - Whether to render fill for inactive segmentations - */ - setRenderFillInactiveCommand: ({ type, value }) => { - const { segmentationService } = servicesManager.services; - segmentationService.setStyle({ type }, { renderFillInactive: value }); - }, - - /** - * Sets whether to render outline for a segmentation type - * @param props.type - The type of segmentation - * @param props.value - Whether to render outline - */ - setRenderOutlineCommand: ({ type, value }) => { - const { segmentationService } = servicesManager.services; - segmentationService.setStyle({ type }, { renderOutline: value }); - }, - - /** - * Sets whether to render outline for inactive segmentations of a segmentation type - * @param props.type - The type of segmentation - * @param props.value - Whether to render outline for inactive segmentations - */ - setRenderOutlineInactiveCommand: ({ type, value }) => { - const { segmentationService } = servicesManager.services; - segmentationService.setStyle({ type }, { renderOutlineInactive: value }); - }, - - /** - * Sets the fill alpha for inactive segmentations. - * If no type is provided, the fill alpha for all types will be set. - * @param props.type - The type of segmentation - * @param props.value - The alpha value to set - */ - setFillAlphaInactiveCommand: ({ type, value }) => { - const { segmentationService } = servicesManager.services; - - if (type) { - segmentationService.setStyle({ type }, { fillAlphaInactive: value }); - } else { - segmentationService.setStyle( - { type: SegmentationRepresentations.Labelmap }, - { fillAlphaInactive: value } - ); - segmentationService.setStyle( - { type: SegmentationRepresentations.Contour }, - { fillAlphaInactive: value } - ); - } - }, - editSegmentLabel: async ({ segmentationId, segmentIndex }) => { const { segmentationService, uiDialogService } = servicesManager.services; const segmentation = segmentationService.getSegmentation(segmentationId); @@ -2731,25 +2673,25 @@ function commandsModule({ commandFn: actions.toggleRenderInactiveSegmentationsCommand, }, setFillAlpha: { - commandFn: actions.setFillAlphaCommand, + commandFn: createSetStyleCommand('fillAlpha'), }, setOutlineWidth: { - commandFn: actions.setOutlineWidthCommand, + commandFn: createSetStyleCommand('outlineWidth'), }, setRenderFill: { - commandFn: actions.setRenderFillCommand, + commandFn: createSetStyleCommand('renderFill'), }, setRenderFillInactive: { - commandFn: actions.setRenderFillInactiveCommand, + commandFn: createSetStyleCommand('renderFillInactive'), }, setRenderOutline: { - commandFn: actions.setRenderOutlineCommand, + commandFn: createSetStyleCommand('renderOutline'), }, setRenderOutlineInactive: { - commandFn: actions.setRenderOutlineInactiveCommand, + commandFn: createSetStyleCommand('renderOutlineInactive'), }, setFillAlphaInactive: { - commandFn: actions.setFillAlphaInactiveCommand, + commandFn: createSetStyleCommand('fillAlphaInactive'), }, editSegmentLabel: { commandFn: actions.editSegmentLabel,