From faea09e7ef2667aad5cef1efc2a6516677ca2915 Mon Sep 17 00:00:00 2001 From: Devu-trenser <91659097+Devu-trenser@users.noreply.github.com> Date: Wed, 15 Oct 2025 19:05:26 +0530 Subject: [PATCH] fix: Segmentation not displayed and unable to draw segments in volume viewport after converting Labelmap to Surface (#5488) * fix: unable to draw segment after 3d layout * comment update --------- --- .../createHydrateSegmentationSynchronizer.ts | 12 +++++------- .../ViewportService/CornerstoneViewportService.ts | 15 +++++---------- 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/extensions/cornerstone/src/services/SyncGroupService/createHydrateSegmentationSynchronizer.ts b/extensions/cornerstone/src/services/SyncGroupService/createHydrateSegmentationSynchronizer.ts index f72c7f89f..f20bbd6b8 100644 --- a/extensions/cornerstone/src/services/SyncGroupService/createHydrateSegmentationSynchronizer.ts +++ b/extensions/cornerstone/src/services/SyncGroupService/createHydrateSegmentationSynchronizer.ts @@ -65,13 +65,11 @@ const segmentationRepresentationModifiedCallback = async ( return; } - // whatever type the source viewport has, we need to add that to the target viewport - const sourceViewportRepresentation = segmentationService.getSegmentationRepresentations( - sourceViewport.viewportId, - { segmentationId } - ); - - const type = sourceViewportRepresentation[0].type; + // Ensure the segmentation representation aligns with the target viewport type. + const type: Enums.SegmentationRepresentations = + viewport.type === CoreEnums.ViewportType.VOLUME_3D + ? Enums.SegmentationRepresentations.Surface + : Enums.SegmentationRepresentations.Labelmap; await segmentationService.addSegmentationRepresentation(targetViewportId, { segmentationId, diff --git a/extensions/cornerstone/src/services/ViewportService/CornerstoneViewportService.ts b/extensions/cornerstone/src/services/ViewportService/CornerstoneViewportService.ts index 765ab204d..319817ee9 100644 --- a/extensions/cornerstone/src/services/ViewportService/CornerstoneViewportService.ts +++ b/extensions/cornerstone/src/services/ViewportService/CornerstoneViewportService.ts @@ -1336,17 +1336,12 @@ class CornerstoneViewportService extends PubSubService implements IViewportServi const { segmentationId, type, hydrated } = presentationItem; const { Labelmap, Surface } = csToolsEnums.SegmentationRepresentations; - const representationType = (() => { - if (type === Surface) { - if (viewport.type === csEnums.ViewportType.VOLUME_3D) { - return Surface; - } else { - return Labelmap; - } - } + const isVolume3D = viewport.type === csEnums.ViewportType.VOLUME_3D; - return type; - })(); + // Determine the appropriate segmentation representation for the viewport. + // If the current type is Surface but the viewport is not 3D, fallback to Labelmap. + // Otherwise, use the existing type. + const representationType = type === Surface && !isVolume3D ? Labelmap : type; if (hydrated) { segmentationService.addSegmentationRepresentation(viewport.id, {