From eae957729848d44971050ca40d684dae8f919170 Mon Sep 17 00:00:00 2001 From: Alireza Date: Thu, 6 Mar 2025 11:36:27 -0500 Subject: [PATCH] fix(segmentation): Add segmentation ID requirement for threshold operations (#1879) --- packages/tools/examples/rectangleROIThreshold/index.ts | 1 - .../segmentation/rectangleROIThresholdVolumeByRange.ts | 3 ++- .../segmentation/thresholdSegmentationByRange.ts | 10 ++++++++-- .../utilities/segmentation/thresholdVolumeByRange.ts | 10 ++++++++-- 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/packages/tools/examples/rectangleROIThreshold/index.ts b/packages/tools/examples/rectangleROIThreshold/index.ts index 585db9e162..1cc057fdb2 100644 --- a/packages/tools/examples/rectangleROIThreshold/index.ts +++ b/packages/tools/examples/rectangleROIThreshold/index.ts @@ -149,7 +149,6 @@ addButtonToToolbar({ const ctVolume = cache.getVolume(ctVolumeId); const ptVolume = cache.getVolume(ptVolumeId); const segmentationVolume = cache.getVolume(segmentationId); - csToolsUtils.segmentation.rectangleROIThresholdVolumeByRange( selectedAnnotationUIDs, segmentationVolume, diff --git a/packages/tools/src/utilities/segmentation/rectangleROIThresholdVolumeByRange.ts b/packages/tools/src/utilities/segmentation/rectangleROIThresholdVolumeByRange.ts index 761ea090bc..e61fd37d3c 100644 --- a/packages/tools/src/utilities/segmentation/rectangleROIThresholdVolumeByRange.ts +++ b/packages/tools/src/utilities/segmentation/rectangleROIThresholdVolumeByRange.ts @@ -8,6 +8,7 @@ import getBoundsIJKFromRectangleAnnotations from '../rectangleROITool/getBoundsI import type { ThresholdInformation } from './utilities'; export type ThresholdOptions = { + segmentationId: string; numSlicesToProject?: number; // number of slices to project before and after current slice overwrite: boolean; overlapType?: number; // type of the voxel overlap @@ -67,7 +68,7 @@ function rectangleROIThresholdVolumeByRange( const outputSegmentationVolume = thresholdVolumeByRange( segmentationVolume, thresholdVolumeInformation, - { ...options, boundsIJK } + { ...options, boundsIJK, segmentationId: options.segmentationId } ); outputSegmentationVolume.modified(); diff --git a/packages/tools/src/utilities/segmentation/thresholdSegmentationByRange.ts b/packages/tools/src/utilities/segmentation/thresholdSegmentationByRange.ts index 10097054d7..cb0da9891a 100644 --- a/packages/tools/src/utilities/segmentation/thresholdSegmentationByRange.ts +++ b/packages/tools/src/utilities/segmentation/thresholdSegmentationByRange.ts @@ -18,8 +18,14 @@ function thresholdSegmentationByRange( segmentationVolume: Types.IImageVolume, segmentationIndex: number, thresholdVolumeInformation: ThresholdInformation[], - overlapType: number + overlapType: number, + segmentationId: string ): Types.IImageVolume { + if (!segmentationId) { + throw new Error( + 'Segmentation ID is required to be passed inside thresholdSegmentationByRange' + ); + } // prepare a list of volume information objects for callback functions const { baseVolumeIdx, volumeInfoList } = processVolumes( segmentationVolume, @@ -66,7 +72,7 @@ function thresholdSegmentationByRange( } }); - triggerSegmentationDataModified(segmentationVolume.volumeId); + triggerSegmentationDataModified(segmentationId); return segmentationVolume; } diff --git a/packages/tools/src/utilities/segmentation/thresholdVolumeByRange.ts b/packages/tools/src/utilities/segmentation/thresholdVolumeByRange.ts index 1d1f1da1dd..6901ba0e9d 100644 --- a/packages/tools/src/utilities/segmentation/thresholdVolumeByRange.ts +++ b/packages/tools/src/utilities/segmentation/thresholdVolumeByRange.ts @@ -6,6 +6,7 @@ import { getVoxelOverlap, processVolumes } from './utilities'; export type ThresholdRangeOptions = { overwrite: boolean; + segmentationId: string; boundsIJK: BoundsIJK; overlapType?: number; segmentIndex?: number; @@ -37,7 +38,12 @@ function thresholdVolumeByRange( ): Types.IImageVolume { const { imageData: segmentationImageData } = segmentationVolume; - const { overwrite, boundsIJK } = options; + const { overwrite, boundsIJK, segmentationId } = options; + if (!segmentationId) { + throw new Error( + 'Segmentation ID is required to be passed inside thresholdVolumeByRange as options' + ); + } const overlapType = options?.overlapType || 0; const segVoxelManager = segmentationVolume.voxelManager as Types.IVoxelManager; @@ -153,7 +159,7 @@ function thresholdVolumeByRange( boundsIJK, }); - triggerSegmentationDataModified(segmentationVolume.volumeId); + triggerSegmentationDataModified(options.segmentationId); return segmentationVolume; }