From 7e10830d5802e22bda4df6a3f8008e9a414b4cd4 Mon Sep 17 00:00:00 2001 From: Ghadeer Albattarni <165973963+GhadeerAlbattarni@users.noreply.github.com> Date: Wed, 4 Mar 2026 15:22:10 -0500 Subject: [PATCH] fix(segmentation): segment bidirectional tool error and show toast notification when no segment is drawn (#5861) --- extensions/cornerstone/src/commandsModule.ts | 19 +++++++++++++++++++ .../src/locales/en-US/SegmentationPanel.json | 7 ++++--- .../locales/test-LNG/SegmentationPanel.json | 4 +++- tests/pages/RightPanelPageObject.ts | 10 ++++++++++ 4 files changed, 36 insertions(+), 4 deletions(-) diff --git a/extensions/cornerstone/src/commandsModule.ts b/extensions/cornerstone/src/commandsModule.ts index 5aae47b81..0b74648be 100644 --- a/extensions/cornerstone/src/commandsModule.ts +++ b/extensions/cornerstone/src/commandsModule.ts @@ -398,12 +398,31 @@ function commandsModule({ const { segmentationId: targetId, segmentIndex: targetIndex } = targetSegmentation; + // Check if the segment has voxels before computing bidirectional measurement + const uniqueSegmentIndices = cstUtils.segmentation.getUniqueSegmentIndices(targetId); + const hasVoxels = uniqueSegmentIndices.includes(targetIndex); + + if (!hasVoxels) { + uiNotificationService.show({ + title: i18n.t('SegmentationPanel:Segment Bidirectional'), + message: i18n.t( + 'SegmentationPanel:Draw a segment before using bidirectional measurement' + ), + type: 'warning', + }); + return; + } + // Get bidirectional measurement data const bidirectionalData = await cstUtils.segmentation.getSegmentLargestBidirectional({ segmentationId: targetId, segmentIndices: [targetIndex], }); + if (!bidirectionalData.length) { + return; + } + const activeViewportId = viewportGridService.getActiveViewportId(); // Process each bidirectional measurement diff --git a/platform/i18n/src/locales/en-US/SegmentationPanel.json b/platform/i18n/src/locales/en-US/SegmentationPanel.json index 52f0928e6..7d5f567f4 100644 --- a/platform/i18n/src/locales/en-US/SegmentationPanel.json +++ b/platform/i18n/src/locales/en-US/SegmentationPanel.json @@ -42,8 +42,7 @@ "Export": "Export", "CSV Report": "CSV Report", "DICOM SEG": "DICOM SEG", - "DICOM RTSS": "DICOM RTSS" - , + "DICOM RTSS": "DICOM RTSS", "Fill contour holes": "Fill contour holes", "Fill Holes": "Fill Holes", "Remove Small Contours": "Remove Small Contours", @@ -63,5 +62,7 @@ "New segment name": "New segment name", "No segmentations available": "No segmentations available", "Not available on the current viewport": "Not available on the current viewport", - "Add segment to enable this tool": "Add segment to enable this tool" + "Add segment to enable this tool": "Add segment to enable this tool", + "Segment Bidirectional": "Segment Bidirectional", + "Draw a segment before using bidirectional measurement": "Draw a segment before using bidirectional measurement" } diff --git a/platform/i18n/src/locales/test-LNG/SegmentationPanel.json b/platform/i18n/src/locales/test-LNG/SegmentationPanel.json index f4aa60c1d..38103f6f7 100644 --- a/platform/i18n/src/locales/test-LNG/SegmentationPanel.json +++ b/platform/i18n/src/locales/test-LNG/SegmentationPanel.json @@ -62,5 +62,7 @@ "New segment name": "Test New segment name", "No segmentations available": "Test No segmentations available", "Not available on the current viewport": "Test Not available on the current viewport", - "Add segment to enable this tool": "Test Add segment to enable this tool" + "Add segment to enable this tool": "Test Add segment to enable this tool", + "Segment Bidirectional": "Test Segment Bidirectional", + "Draw a segment before using bidirectional measurement": "Test Draw a segment before using bidirectional measurement" } diff --git a/tests/pages/RightPanelPageObject.ts b/tests/pages/RightPanelPageObject.ts index 6b0715716..9b863db65 100644 --- a/tests/pages/RightPanelPageObject.ts +++ b/tests/pages/RightPanelPageObject.ts @@ -246,6 +246,16 @@ export class RightPanelPageObject { }, }; }, + + get segmentBidirectional() { + const button = page.getByTestId('SegmentBidirectional'); + return { + button, + click: async () => { + await button.click(); + }, + }; + }, }; }