@ohif/extension-cornerstone 3.14.0-beta.12 → 3.14.0-beta.120
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/915.ohif-extension-cornerstone.umd.js +1 -1
- package/dist/ohif-extension-cornerstone.umd.js +1 -5
- package/package.json +33 -25
- package/src/Viewport/OHIFCornerstoneViewport.css +46 -0
- package/src/Viewport/OHIFCornerstoneViewport.tsx +498 -0
- package/src/Viewport/Overlays/CornerstoneOverlays.tsx +103 -0
- package/src/Viewport/Overlays/CustomizableViewportOverlay.css +25 -0
- package/src/Viewport/Overlays/CustomizableViewportOverlay.tsx +469 -0
- package/src/Viewport/Overlays/ViewportImageScrollbar.tsx +106 -0
- package/src/Viewport/Overlays/ViewportImageSliceLoadingIndicator.tsx +87 -0
- package/src/Viewport/Overlays/ViewportOrientationMarkers.css +41 -0
- package/src/Viewport/Overlays/ViewportOrientationMarkers.tsx +136 -0
- package/src/Viewport/Overlays/ViewportSliceProgressScrollbar/ViewportSliceProgressScrollbar.tsx +195 -0
- package/src/Viewport/Overlays/ViewportSliceProgressScrollbar/helpers.ts +46 -0
- package/src/Viewport/Overlays/ViewportSliceProgressScrollbar/hooks.ts +383 -0
- package/src/Viewport/Overlays/ViewportSliceProgressScrollbar/index.ts +1 -0
- package/src/Viewport/Overlays/ViewportSliceProgressScrollbar/types.ts +17 -0
- package/src/Viewport/Overlays/utils.ts +66 -0
- package/src/commandsModule.ts +2970 -0
- package/src/components/AccordionGroup/AccordionGroup.tsx +195 -0
- package/src/components/AccordionGroup/index.ts +4 -0
- package/src/components/ActiveViewportWindowLevel/ActiveViewportWindowLevel.tsx +23 -0
- package/src/components/ActiveViewportWindowLevel/index.js +1 -0
- package/src/components/AdvancedRenderingControls/AdvancedRenderingControls.tsx +149 -0
- package/src/components/AdvancedRenderingControls/index.ts +1 -0
- package/src/components/CinePlayer/CinePlayer.tsx +247 -0
- package/src/components/CinePlayer/index.ts +3 -0
- package/src/components/DicomUpload/DicomUpload.tsx +111 -0
- package/src/components/DicomUpload/DicomUploadProgress.tsx +396 -0
- package/src/components/DicomUpload/DicomUploadProgressItem.tsx +119 -0
- package/src/components/ExportSegmentationSubMenuItem.tsx +75 -0
- package/src/components/FidelityIndicator/FidelityIndicator.tsx +152 -0
- package/src/components/FidelityIndicator/index.ts +1 -0
- package/src/components/MeasurementItems.tsx +70 -0
- package/src/components/MeasurementTableNested.tsx +30 -0
- package/src/components/MeasurementsMenu.tsx +84 -0
- package/src/components/MeasurementsOrAdditionalFindings.tsx +82 -0
- package/src/components/ModalityLoadBadge/ModalityLoadBadge.tsx +171 -0
- package/src/components/ModalityLoadBadge/index.ts +1 -0
- package/src/components/NavigationComponent/NavigationComponent.tsx +138 -0
- package/src/components/NavigationComponent/index.ts +3 -0
- package/src/components/OHIFViewportActionCorners.tsx +109 -0
- package/src/components/OpacityMenu/OpacityMenu.tsx +54 -0
- package/src/components/OpacityMenu/OpacityMenuWrapper.tsx +85 -0
- package/src/components/OpacityMenu/index.ts +2 -0
- package/src/components/PanelAccordionTrigger.tsx +48 -0
- package/src/components/SegmentationToolConfig.tsx +71 -0
- package/src/components/SegmentationUtilityButton.tsx +61 -0
- package/src/components/SelectItemWithModality.tsx +29 -0
- package/src/components/SeriesMeasurements.tsx +90 -0
- package/src/components/SeriesSummaryFromDisplaySet.tsx +21 -0
- package/src/components/StudyMeasurements.tsx +88 -0
- package/src/components/StudyMeasurementsActions.tsx +75 -0
- package/src/components/StudySummaryFromMetadata.test.ts +47 -0
- package/src/components/StudySummaryFromMetadata.tsx +31 -0
- package/src/components/StudySummaryWithActions.tsx +14 -0
- package/src/components/ThresholdMenu/ThresholdMenu.tsx +104 -0
- package/src/components/ThresholdMenu/ThresholdMenuWrapper.tsx +85 -0
- package/src/components/ThresholdMenu/index.ts +2 -0
- package/src/components/TrackingStatus/TrackingStatus.tsx +32 -0
- package/src/components/TrackingStatus/index.ts +1 -0
- package/src/components/VOIManualControlMenu/VOIManualControlMenu.tsx +190 -0
- package/src/components/VOIManualControlMenu/VOIManualControlMenuWrapper.tsx +85 -0
- package/src/components/VOIManualControlMenu/index.ts +2 -0
- package/src/components/ViewportColorbar/ViewportColorbar.tsx +150 -0
- package/src/components/ViewportColorbar/ViewportColorbarsContainer.tsx +125 -0
- package/src/components/ViewportColorbar/index.ts +5 -0
- package/src/components/ViewportDataOverlaySettingMenu/ViewportDataOverlayMenu.tsx +538 -0
- package/src/components/ViewportDataOverlaySettingMenu/ViewportDataOverlayMenuWrapper.tsx +91 -0
- package/src/components/ViewportDataOverlaySettingMenu/utils.ts +118 -0
- package/src/components/ViewportOrientationMenu/ViewportOrientationMenu.tsx +249 -0
- package/src/components/ViewportOrientationMenu/ViewportOrientationMenuWrapper.tsx +29 -0
- package/src/components/ViewportWindowLevel/ViewportWindowLevel.tsx +261 -0
- package/src/components/ViewportWindowLevel/getViewportVolumeHistogram.ts +72 -0
- package/src/components/ViewportWindowLevel/histogramWorker.js +97 -0
- package/src/components/ViewportWindowLevel/index.js +1 -0
- package/src/components/ViewportWindowLevel/utils.ts +176 -0
- package/src/components/WindowLevelActionMenu/Colorbar.tsx +30 -0
- package/src/components/WindowLevelActionMenu/Colormap.tsx +121 -0
- package/src/components/WindowLevelActionMenu/VolumeLighting.tsx +82 -0
- package/src/components/WindowLevelActionMenu/VolumeRenderingOptions.tsx +38 -0
- package/src/components/WindowLevelActionMenu/VolumeRenderingPresets.tsx +36 -0
- package/src/components/WindowLevelActionMenu/VolumeRenderingPresetsContent.tsx +78 -0
- package/src/components/WindowLevelActionMenu/VolumeRenderingQuality.tsx +64 -0
- package/src/components/WindowLevelActionMenu/VolumeShade.tsx +47 -0
- package/src/components/WindowLevelActionMenu/VolumeShift.tsx +92 -0
- package/src/components/WindowLevelActionMenu/WindowLevel.tsx +157 -0
- package/src/components/WindowLevelActionMenu/WindowLevelActionMenu.tsx +102 -0
- package/src/components/WindowLevelActionMenu/WindowLevelActionMenuWrapper.tsx +131 -0
- package/src/components/WindowLevelActionMenu/defaultWindowLevelPresets.ts +23 -0
- package/src/components/WindowLevelActionMenu/index.ts +11 -0
- package/src/components/WindowLevelActionMenu/windowLevelPresetHotkeys.test.ts +19 -0
- package/src/components/index.ts +13 -0
- package/src/constants/index.ts +13 -0
- package/src/customizations/CustomDropdownMenuContent.tsx +106 -0
- package/src/customizations/CustomSegmentStatisticsHeader.tsx +140 -0
- package/src/customizations/captureViewportModalCustomization.tsx +175 -0
- package/src/customizations/colorbarCustomization.ts +93 -0
- package/src/customizations/gpuSettingsPresetCustomization.ts +8 -0
- package/src/customizations/layoutSelectorCustomization.ts +104 -0
- package/src/customizations/measurementsCustomization.ts +124 -0
- package/src/customizations/miscCustomization.ts +22 -0
- package/src/customizations/modalityColorMapCustomization.ts +23 -0
- package/src/customizations/segmentationHydrationCustomization.ts +16 -0
- package/src/customizations/segmentationPanelCustomization.tsx +119 -0
- package/src/customizations/segmentationToolbarCustomization.ts +964 -0
- package/src/customizations/toolGroupToolsCustomization.ts +204 -0
- package/src/customizations/toolbarButtonsCustomization.ts +805 -0
- package/src/customizations/viewportClickCommandsCustomization.ts +15 -0
- package/src/customizations/viewportDownloadWarningCustomization.tsx +6 -0
- package/src/customizations/viewportOverlayCustomization.tsx +46 -0
- package/src/customizations/viewportScrollbarCustomization.tsx +27 -0
- package/src/customizations/viewportToolsCustomization.ts +33 -0
- package/src/customizations/volumeRenderingCustomization.ts +14 -0
- package/src/customizations/windowLevelPresetsCustomization.ts +5 -0
- package/src/enums.ts +9 -0
- package/src/getCustomizationModule.tsx +54 -0
- package/src/getHangingProtocolModule.ts +47 -0
- package/src/getPanelModule.tsx +128 -0
- package/src/getSopClassHandlerModule.js +284 -0
- package/src/getToolbarModule.tsx +622 -0
- package/src/hooks/index.ts +9 -0
- package/src/hooks/useActiveViewportSegmentationRepresentations.ts +14 -0
- package/src/hooks/useMeasurementTracking.ts +132 -0
- package/src/hooks/useMeasurements.ts +104 -0
- package/src/hooks/useSegmentations.ts +147 -0
- package/src/hooks/useViewportDisplaySets.ts +284 -0
- package/src/hooks/useViewportFidelity.ts +243 -0
- package/src/hooks/useViewportHover.ts +77 -0
- package/src/hooks/useViewportRendering.tsx +868 -0
- package/src/hooks/useViewportSegmentations.ts +245 -0
- package/src/hps/fourUp.ts +117 -0
- package/src/hps/frameView.ts +1581 -0
- package/src/hps/main3D.ts +142 -0
- package/src/hps/mpr.ts +197 -0
- package/src/hps/mprAnd3DVolumeViewport.ts +124 -0
- package/src/hps/only3D.ts +70 -0
- package/src/hps/primary3D.ts +142 -0
- package/src/hps/primaryAxial.ts +114 -0
- package/src/id.js +5 -0
- package/src/index.tsx +350 -0
- package/src/init.tsx +450 -0
- package/src/initCineService.ts +75 -0
- package/src/initContextMenu.ts +94 -0
- package/src/initCornerstoneTools.js +188 -0
- package/src/initDoubleClick.ts +82 -0
- package/src/initMeasurementService.ts +576 -0
- package/src/initStudyPrefetcherService.ts +33 -0
- package/src/initWADOImageLoader.js +56 -0
- package/src/panels/PanelMeasurement.tsx +84 -0
- package/src/panels/PanelSegmentation.tsx +338 -0
- package/src/services/ColorbarService/ColorbarService.ts +242 -0
- package/src/services/ColorbarService/index.ts +2 -0
- package/src/services/CornerstoneCacheService/CornerstoneCacheService.ts +326 -0
- package/src/services/CornerstoneCacheService/index.js +3 -0
- package/src/services/SegmentationService/RTSTRUCT/mapROIContoursToRTStructData.ts +36 -0
- package/src/services/SegmentationService/SegmentationService.test.ts +3727 -0
- package/src/services/SegmentationService/SegmentationService.ts +2390 -0
- package/src/services/SegmentationService/backends/ISegmentationBackend.ts +102 -0
- package/src/services/SegmentationService/backends/ISegmentationServiceInternals.ts +44 -0
- package/src/services/SegmentationService/backends/LegacySegmentationBackend.ts +139 -0
- package/src/services/SegmentationService/backends/NextSegmentationBackend.ts +159 -0
- package/src/services/SegmentationService/backends/index.ts +4 -0
- package/src/services/SegmentationService/index.ts +3 -0
- package/src/services/SyncGroupService/SyncGroupService.ts +264 -0
- package/src/services/SyncGroupService/createHydrateSegmentationSynchronizer.ts +118 -0
- package/src/services/SyncGroupService/index.js +3 -0
- package/src/services/ToolGroupService/ToolGroupService.test.ts +83 -0
- package/src/services/ToolGroupService/ToolGroupService.ts +541 -0
- package/src/services/ToolGroupService/index.js +3 -0
- package/src/services/ViewedDataService/ViewedDataService.ts +58 -0
- package/src/services/ViewedDataService/index.ts +3 -0
- package/src/services/ViewportService/CornerstoneViewportService.ts +1814 -0
- package/src/services/ViewportService/IViewportService.ts +64 -0
- package/src/services/ViewportService/Viewport.ts +372 -0
- package/src/services/ViewportService/adapter/IViewportAdapter.contract.test.ts +467 -0
- package/src/services/ViewportService/adapter/IViewportAdapter.ts +179 -0
- package/src/services/ViewportService/adapter/LegacyViewportAdapter.ts +240 -0
- package/src/services/ViewportService/adapter/NextViewportAdapter.ts +241 -0
- package/src/services/ViewportService/adapter/getViewportAdapter.ts +62 -0
- package/src/services/ViewportService/adapter/index.ts +16 -0
- package/src/services/ViewportService/backends/IViewportBackend.ts +195 -0
- package/src/services/ViewportService/backends/IViewportOperations.ts +98 -0
- package/src/services/ViewportService/backends/IViewportServiceInternals.ts +47 -0
- package/src/services/ViewportService/backends/LegacyViewportBackend.ts +264 -0
- package/src/services/ViewportService/backends/LegacyViewportOperations.ts +272 -0
- package/src/services/ViewportService/backends/NextViewportBackend.ts +673 -0
- package/src/services/ViewportService/backends/NextViewportOperations.ts +169 -0
- package/src/services/ViewportService/backends/README.md +62 -0
- package/src/services/ViewportService/backends/dataIdRegistry.ts +121 -0
- package/src/services/ViewportService/backends/viewportOperations.ts +71 -0
- package/src/services/ViewportService/constants.ts +3 -0
- package/src/state.ts +34 -0
- package/src/stores/index.ts +5 -0
- package/src/stores/presentationUtils.ts +42 -0
- package/src/stores/useLutPresentationStore.ts +166 -0
- package/src/stores/usePositionPresentationStore.ts +172 -0
- package/src/stores/useSegmentationPresentationStore.test.ts +146 -0
- package/src/stores/useSegmentationPresentationStore.ts +417 -0
- package/src/stores/useSelectedSegmentationsForViewportStore.ts +85 -0
- package/src/stores/useSynchronizersStore.ts +84 -0
- package/src/synchronizers/frameViewSynchronizer.ts +52 -0
- package/src/tools/CalibrationLineTool.ts +97 -0
- package/src/tools/ImageOverlayViewerTool.tsx +279 -0
- package/src/tools/OverlayPlaneModuleProvider.ts +40 -0
- package/src/tools/WindowLevelTool.test.ts +55 -0
- package/src/tools/WindowLevelTool.ts +22 -0
- package/src/types/AppTypes.ts +70 -0
- package/src/types/Colorbar.ts +114 -0
- package/src/types/Colormap.ts +16 -0
- package/src/types/CornerstoneCacheService.ts +40 -0
- package/src/types/CornerstoneServices.ts +18 -0
- package/src/types/Presentation.ts +83 -0
- package/src/types/SelectedSegmentationByTypeMap.ts +3 -0
- package/src/types/ViewportPresets.ts +53 -0
- package/src/types/VolumeLighting.ts +7 -0
- package/src/types/VolumeRenderingConfig.ts +8 -0
- package/src/types/WindowLevel.ts +5 -0
- package/src/types/index.ts +10 -0
- package/src/utils/ActiveViewportBehavior.tsx +80 -0
- package/src/utils/CornerstoneViewportDownloadForm.tsx +319 -0
- package/src/utils/DicomFileUploader.ts +204 -0
- package/src/utils/JumpPresets.ts +14 -0
- package/src/utils/autoHydrateViewportTypes.ts +69 -0
- package/src/utils/colormaps.js +1597 -0
- package/src/utils/createSegmentationForViewport.test.ts +93 -0
- package/src/utils/createSegmentationForViewport.ts +123 -0
- package/src/utils/dicomLoaderService.js +225 -0
- package/src/utils/ecgMetadata.test.ts +137 -0
- package/src/utils/ecgMetadata.ts +109 -0
- package/src/utils/findNearbyToolData.test.ts +125 -0
- package/src/utils/findNearbyToolData.ts +21 -0
- package/src/utils/findWindowLevelPreset.test.ts +55 -0
- package/src/utils/findWindowLevelPreset.ts +46 -0
- package/src/utils/generateSegmentationCSVReport.test.ts +324 -0
- package/src/utils/generateSegmentationCSVReport.ts +131 -0
- package/src/utils/getActiveViewportEnabledElement.test.ts +70 -0
- package/src/utils/getActiveViewportEnabledElement.ts +8 -0
- package/src/utils/getCenterExtent.test.ts +313 -0
- package/src/utils/getCenterExtent.ts +46 -0
- package/src/utils/getCornerstoneBlendMode.test.ts +59 -0
- package/src/utils/getCornerstoneBlendMode.ts +25 -0
- package/src/utils/getCornerstoneOrientation.test.ts +78 -0
- package/src/utils/getCornerstoneOrientation.ts +31 -0
- package/src/utils/getCornerstoneViewportType.test.ts +169 -0
- package/src/utils/getCornerstoneViewportType.ts +88 -0
- package/src/utils/getInterleavedFrames.test.ts +85 -0
- package/src/utils/getInterleavedFrames.ts +73 -0
- package/src/utils/getLegacyViewportType.ts +64 -0
- package/src/utils/getNthFrames.test.ts +145 -0
- package/src/utils/getNthFrames.ts +31 -0
- package/src/utils/getViewportEnabledElement.test.ts +83 -0
- package/src/utils/getViewportEnabledElement.ts +8 -0
- package/src/utils/getViewportOrientationFromImageOrientationPatient.test.ts +50 -0
- package/src/utils/getViewportOrientationFromImageOrientationPatient.ts +56 -0
- package/src/utils/hydrationUtils.test.ts +572 -0
- package/src/utils/hydrationUtils.ts +197 -0
- package/src/utils/imageSliceSync/calculateViewportRegistrations.ts +28 -0
- package/src/utils/imageSliceSync/toggleImageSliceSync.ts +101 -0
- package/src/utils/index.ts +29 -0
- package/src/utils/initGpuSettingsPreset.ts +51 -0
- package/src/utils/initViewTiming.test.ts +342 -0
- package/src/utils/initViewTiming.ts +52 -0
- package/src/utils/initWebWorkerProgressHandler.test.ts +381 -0
- package/src/utils/initWebWorkerProgressHandler.ts +110 -0
- package/src/utils/interleave.test.ts +304 -0
- package/src/utils/interleave.ts +32 -0
- package/src/utils/interleaveCenterLoader.test.ts +547 -0
- package/src/utils/interleaveCenterLoader.ts +143 -0
- package/src/utils/interleaveTopToBottom.test.ts +487 -0
- package/src/utils/interleaveTopToBottom.ts +132 -0
- package/src/utils/isAnyDisplaySetCommon.ts +18 -0
- package/src/utils/isDisplaySetOverlayable.ts +106 -0
- package/src/utils/isMeasurementWithinViewport.test.ts +340 -0
- package/src/utils/isMeasurementWithinViewport.ts +33 -0
- package/src/utils/isReferenceViewable.test.ts +581 -0
- package/src/utils/isReferenceViewable.ts +95 -0
- package/src/utils/loadDisplaySetData.ts +49 -0
- package/src/utils/measurementServiceMappings/Angle.ts +200 -0
- package/src/utils/measurementServiceMappings/ArrowAnnotate.ts +176 -0
- package/src/utils/measurementServiceMappings/Bidirectional.ts +193 -0
- package/src/utils/measurementServiceMappings/CircleROI.ts +227 -0
- package/src/utils/measurementServiceMappings/CobbAngle.ts +206 -0
- package/src/utils/measurementServiceMappings/EllipticalROI.ts +221 -0
- package/src/utils/measurementServiceMappings/Length.ts +206 -0
- package/src/utils/measurementServiceMappings/LivewireContour.ts +175 -0
- package/src/utils/measurementServiceMappings/PlanarFreehandROI.ts +228 -0
- package/src/utils/measurementServiceMappings/Probe.ts +192 -0
- package/src/utils/measurementServiceMappings/RectangleROI.ts +225 -0
- package/src/utils/measurementServiceMappings/SegmentBidirectional.ts +184 -0
- package/src/utils/measurementServiceMappings/SplineROI.ts +227 -0
- package/src/utils/measurementServiceMappings/UltrasoundDirectional.ts +214 -0
- package/src/utils/measurementServiceMappings/UltrasoundPleuraBLine.ts +179 -0
- package/src/utils/measurementServiceMappings/constants/supportedTools.js +21 -0
- package/src/utils/measurementServiceMappings/index.ts +3 -0
- package/src/utils/measurementServiceMappings/measurementServiceMappingsFactory.ts +324 -0
- package/src/utils/measurementServiceMappings/utils/getDisplayUnit.js +3 -0
- package/src/utils/measurementServiceMappings/utils/getHandlesFromPoints.js +14 -0
- package/src/utils/measurementServiceMappings/utils/getIsLocked.ts +5 -0
- package/src/utils/measurementServiceMappings/utils/getIsVisible.ts +6 -0
- package/src/utils/measurementServiceMappings/utils/getSOPInstanceAttributes.js +66 -0
- package/src/utils/measurementServiceMappings/utils/getValueDisplayString.js +12 -0
- package/src/utils/measurementServiceMappings/utils/index.ts +17 -0
- package/src/utils/measurementServiceMappings/utils/selection.ts +33 -0
- package/src/utils/mpr/getProtocolViewportStructureFromGridViewports.ts +74 -0
- package/src/utils/nextViewportPolicies.ts +41 -0
- package/src/utils/nextViewports.ts +157 -0
- package/src/utils/nthLoader.test.ts +317 -0
- package/src/utils/nthLoader.ts +78 -0
- package/src/utils/presentations/getViewportPresentations.test.ts +280 -0
- package/src/utils/presentations/getViewportPresentations.ts +151 -0
- package/src/utils/promptHydrationDialog.test.ts +490 -0
- package/src/utils/promptHydrationDialog.ts +197 -0
- package/src/utils/promptTimePointScope.tsx +82 -0
- package/src/utils/removeViewportSegmentationRepresentations.test.ts +129 -0
- package/src/utils/removeViewportSegmentationRepresentations.ts +17 -0
- package/src/utils/segmentUtils.test.ts +515 -0
- package/src/utils/segmentUtils.ts +46 -0
- package/src/utils/segmentationExportUtils.test.ts +100 -0
- package/src/utils/segmentationExportUtils.ts +171 -0
- package/src/utils/segmentationHandlers.test.ts +614 -0
- package/src/utils/segmentationHandlers.ts +164 -0
- package/src/utils/setUpAnnotationEventHandlers.ts +26 -0
- package/src/utils/setUpSegmentationEventHandlers.test.ts +372 -0
- package/src/utils/setUpSegmentationEventHandlers.ts +122 -0
- package/src/utils/toggleVOISliceSync.test.ts +606 -0
- package/src/utils/toggleVOISliceSync.ts +103 -0
- package/src/utils/transitions.test.ts +351 -0
- package/src/utils/transitions.ts +300 -0
- package/src/utils/updateSegmentationStats.test.ts +942 -0
- package/src/utils/updateSegmentationStats.ts +192 -0
- package/src/utils/viewportDataShape.ts +85 -0
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import * as cornerstoneTools from '@cornerstonejs/tools';
|
|
2
|
+
import { updateSegmentationStats } from './updateSegmentationStats';
|
|
3
|
+
import { useSelectedSegmentationsForViewportStore } from '../stores';
|
|
4
|
+
import { SegmentationRepresentations } from '@cornerstonejs/tools/enums';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Sets up the handler for segmentation data modification events
|
|
8
|
+
*/
|
|
9
|
+
export function setupSegmentationDataModifiedHandler({
|
|
10
|
+
segmentationService,
|
|
11
|
+
customizationService,
|
|
12
|
+
commandsManager,
|
|
13
|
+
}) {
|
|
14
|
+
// A flag to indicate if the event is unsubscribed to. This is important because
|
|
15
|
+
// the debounced callback does an await and in that period of time the event may have
|
|
16
|
+
// been unsubscribed.
|
|
17
|
+
let isUnsubscribed = false;
|
|
18
|
+
const { unsubscribe: debouncedUnsubscribe } = segmentationService.subscribeDebounced(
|
|
19
|
+
segmentationService.EVENTS.SEGMENTATION_DATA_MODIFIED,
|
|
20
|
+
async ({ segmentationId }) => {
|
|
21
|
+
const disableUpdateSegmentationStats = customizationService.getCustomization(
|
|
22
|
+
'panelSegmentation.disableUpdateSegmentationStats'
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
const segmentation = segmentationService.getSegmentation(segmentationId);
|
|
26
|
+
|
|
27
|
+
if (!segmentation || disableUpdateSegmentationStats) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const readableText = customizationService.getCustomization('panelSegmentation.readableText');
|
|
32
|
+
|
|
33
|
+
// Check for segments with bidirectional measurements and update them
|
|
34
|
+
const segmentIndices = Object.keys(segmentation.segments)
|
|
35
|
+
.map(index => parseInt(index))
|
|
36
|
+
.filter(index => index > 0);
|
|
37
|
+
|
|
38
|
+
for (const segmentIndex of segmentIndices) {
|
|
39
|
+
const segment = segmentation.segments[segmentIndex];
|
|
40
|
+
if (segment?.cachedStats?.namedStats?.bidirectional) {
|
|
41
|
+
// Run the command to update the bidirectional measurement
|
|
42
|
+
commandsManager.runCommand('runSegmentBidirectional', {
|
|
43
|
+
segmentationId,
|
|
44
|
+
segmentIndex,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const updatedSegmentation = await updateSegmentationStats({
|
|
50
|
+
segmentation,
|
|
51
|
+
segmentationId,
|
|
52
|
+
readableText,
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
if (!isUnsubscribed && updatedSegmentation) {
|
|
56
|
+
const existingSegmentation = segmentationService.getSegmentation(segmentationId);
|
|
57
|
+
|
|
58
|
+
if (existingSegmentation) {
|
|
59
|
+
segmentationService.addOrUpdateSegmentation({
|
|
60
|
+
segmentationId,
|
|
61
|
+
segments: updatedSegmentation.segments,
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
1000
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
const unsubscribe = () => {
|
|
70
|
+
isUnsubscribed = true;
|
|
71
|
+
debouncedUnsubscribe();
|
|
72
|
+
};
|
|
73
|
+
return { unsubscribe };
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Sets up the handler for segmentation modification events
|
|
78
|
+
*/
|
|
79
|
+
export function setupSegmentationModifiedHandler({ segmentationService }) {
|
|
80
|
+
const { unsubscribe } = segmentationService.subscribe(
|
|
81
|
+
segmentationService.EVENTS.SEGMENTATION_MODIFIED,
|
|
82
|
+
async ({ segmentationId }) => {
|
|
83
|
+
const segmentation = segmentationService.getSegmentation(segmentationId);
|
|
84
|
+
|
|
85
|
+
if (!segmentation) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const annotationState = cornerstoneTools.annotation.state.getAllAnnotations();
|
|
90
|
+
const bidirectionalAnnotations = annotationState.filter(
|
|
91
|
+
annotation =>
|
|
92
|
+
annotation.metadata.toolName === cornerstoneTools.SegmentBidirectionalTool.toolName
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
const segmentIndices = Object.keys(segmentation.segments)
|
|
96
|
+
.map(index => parseInt(index))
|
|
97
|
+
.filter(index => index > 0);
|
|
98
|
+
|
|
99
|
+
// check if there is a bidirectional data that exists but the segment
|
|
100
|
+
// does not exists anymore we need to remove the bidirectional data
|
|
101
|
+
const bidirectionalAnnotationsToRemove = bidirectionalAnnotations.filter(
|
|
102
|
+
annotation =>
|
|
103
|
+
annotation.metadata.segmentationId === segmentationId &&
|
|
104
|
+
!segmentIndices.includes(annotation.metadata.segmentIndex)
|
|
105
|
+
);
|
|
106
|
+
|
|
107
|
+
const toRemoveUIDs = bidirectionalAnnotationsToRemove.map(
|
|
108
|
+
annotation => annotation.annotationUID
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
toRemoveUIDs.forEach(uid => {
|
|
112
|
+
cornerstoneTools.annotation.state.removeAnnotation(uid);
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
);
|
|
116
|
+
|
|
117
|
+
return { unsubscribe };
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Sets up auto tab switching for when the first segmentation is added into the viewer.
|
|
122
|
+
*/
|
|
123
|
+
export function setUpSelectedSegmentationsForViewportHandler({ segmentationService }) {
|
|
124
|
+
const selectedSegmentationsForViewportEvents = [
|
|
125
|
+
segmentationService.EVENTS.SEGMENTATION_MODIFIED,
|
|
126
|
+
segmentationService.EVENTS.SEGMENTATION_REPRESENTATION_MODIFIED,
|
|
127
|
+
];
|
|
128
|
+
|
|
129
|
+
const unsubscribeSelectedSegmentationsForViewportEvents = selectedSegmentationsForViewportEvents
|
|
130
|
+
.map(eventName =>
|
|
131
|
+
segmentationService.subscribe(eventName, event => {
|
|
132
|
+
const { viewportId } = event;
|
|
133
|
+
|
|
134
|
+
if (!viewportId) {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const { selectedSegmentationsForViewport, setSelectedSegmentationsForViewport } =
|
|
139
|
+
useSelectedSegmentationsForViewportStore.getState();
|
|
140
|
+
|
|
141
|
+
const representations = segmentationService.getSegmentationRepresentations(viewportId);
|
|
142
|
+
|
|
143
|
+
const activeRepresentation = representations.find(representation => representation.active);
|
|
144
|
+
|
|
145
|
+
const typeToSegmentationIdMap =
|
|
146
|
+
selectedSegmentationsForViewport[viewportId] ??
|
|
147
|
+
new Map<SegmentationRepresentations, string>();
|
|
148
|
+
|
|
149
|
+
if (activeRepresentation) {
|
|
150
|
+
typeToSegmentationIdMap.set(
|
|
151
|
+
activeRepresentation.type,
|
|
152
|
+
activeRepresentation.segmentationId
|
|
153
|
+
);
|
|
154
|
+
} else {
|
|
155
|
+
typeToSegmentationIdMap.clear();
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
setSelectedSegmentationsForViewport(viewportId, typeToSegmentationIdMap);
|
|
159
|
+
})
|
|
160
|
+
)
|
|
161
|
+
.map(subscription => subscription.unsubscribe);
|
|
162
|
+
|
|
163
|
+
return { unsubscribeSelectedSegmentationsForViewportEvents };
|
|
164
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import * as csTools from '@cornerstonejs/tools';
|
|
2
|
+
|
|
3
|
+
import { eventTarget } from '@cornerstonejs/core';
|
|
4
|
+
|
|
5
|
+
const { Enums: csToolsEnums } = csTools;
|
|
6
|
+
|
|
7
|
+
const _autoAcceptAnnotationInterpolationHandler = evt => {
|
|
8
|
+
const { element } = evt.detail;
|
|
9
|
+
csTools.utilities.contours.acceptAutogeneratedInterpolations(element, {});
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export const setUpAnnotationEventHandlers = (): [() => void] => {
|
|
13
|
+
eventTarget.addEventListener(
|
|
14
|
+
csToolsEnums.Events.ANNOTATION_INTERPOLATION_PROCESS_COMPLETED,
|
|
15
|
+
_autoAcceptAnnotationInterpolationHandler
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
const annotationInterpolationProcessCompletedUnsubscribe = () => {
|
|
19
|
+
eventTarget.removeEventListener(
|
|
20
|
+
csToolsEnums.Events.ANNOTATION_INTERPOLATION_PROCESS_COMPLETED,
|
|
21
|
+
_autoAcceptAnnotationInterpolationHandler
|
|
22
|
+
);
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
return [annotationInterpolationProcessCompletedUnsubscribe];
|
|
26
|
+
};
|
|
@@ -0,0 +1,372 @@
|
|
|
1
|
+
import { setUpSegmentationEventHandlers } from './setUpSegmentationEventHandlers';
|
|
2
|
+
import {
|
|
3
|
+
setupSegmentationDataModifiedHandler,
|
|
4
|
+
setupSegmentationModifiedHandler,
|
|
5
|
+
setUpSelectedSegmentationsForViewportHandler,
|
|
6
|
+
} from './segmentationHandlers';
|
|
7
|
+
|
|
8
|
+
jest.mock('./segmentationHandlers', () => ({
|
|
9
|
+
setupSegmentationDataModifiedHandler: jest.fn(),
|
|
10
|
+
setupSegmentationModifiedHandler: jest.fn(),
|
|
11
|
+
setUpSelectedSegmentationsForViewportHandler: jest.fn(),
|
|
12
|
+
}));
|
|
13
|
+
|
|
14
|
+
describe('setUpSegmentationEventHandlers', () => {
|
|
15
|
+
const mockSegmentationService = {
|
|
16
|
+
EVENTS: {
|
|
17
|
+
SEGMENTATION_ADDED: 'SEGMENTATION_ADDED',
|
|
18
|
+
SEGMENTATION_REMOVED: 'SEGMENTATION_REMOVED',
|
|
19
|
+
},
|
|
20
|
+
subscribe: jest.fn(),
|
|
21
|
+
getSegmentation: jest.fn(),
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const mockCustomizationService = {};
|
|
25
|
+
|
|
26
|
+
const mockDisplaySetService = {
|
|
27
|
+
getDisplaySetByUID: jest.fn(),
|
|
28
|
+
addDisplaySets: jest.fn(),
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const mockCommandsManager = {};
|
|
32
|
+
|
|
33
|
+
const mockServicesManager = {
|
|
34
|
+
services: {
|
|
35
|
+
segmentationService: mockSegmentationService,
|
|
36
|
+
customizationService: mockCustomizationService,
|
|
37
|
+
displaySetService: mockDisplaySetService,
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const mockUnsubscribeDataModified = jest.fn();
|
|
42
|
+
const mockUnsubscribeModified = jest.fn();
|
|
43
|
+
const mockUnsubscribeCreated = jest.fn();
|
|
44
|
+
const mockUnsubscribeRemoved = jest.fn();
|
|
45
|
+
const mockUnsubscribeSelectedSegmentationsForViewportEvents = [jest.fn(), jest.fn()];
|
|
46
|
+
|
|
47
|
+
const defaultParameters = {
|
|
48
|
+
servicesManager: mockServicesManager as unknown as AppTypes.ServicesManager,
|
|
49
|
+
commandsManager: mockCommandsManager,
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
beforeEach(() => {
|
|
53
|
+
jest.clearAllMocks();
|
|
54
|
+
(setupSegmentationDataModifiedHandler as jest.Mock).mockReturnValue({
|
|
55
|
+
unsubscribe: mockUnsubscribeDataModified,
|
|
56
|
+
});
|
|
57
|
+
(setupSegmentationModifiedHandler as jest.Mock).mockReturnValue({
|
|
58
|
+
unsubscribe: mockUnsubscribeModified,
|
|
59
|
+
});
|
|
60
|
+
(setUpSelectedSegmentationsForViewportHandler as jest.Mock).mockReturnValue({
|
|
61
|
+
unsubscribeSelectedSegmentationsForViewportEvents:
|
|
62
|
+
mockUnsubscribeSelectedSegmentationsForViewportEvents,
|
|
63
|
+
});
|
|
64
|
+
mockSegmentationService.subscribe.mockImplementation((eventName: string) => {
|
|
65
|
+
if (eventName === mockSegmentationService.EVENTS.SEGMENTATION_ADDED) {
|
|
66
|
+
return { unsubscribe: mockUnsubscribeCreated };
|
|
67
|
+
}
|
|
68
|
+
if (eventName === mockSegmentationService.EVENTS.SEGMENTATION_REMOVED) {
|
|
69
|
+
return { unsubscribe: mockUnsubscribeRemoved };
|
|
70
|
+
}
|
|
71
|
+
return { unsubscribe: jest.fn() };
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('should setup segmentation data modified handler', () => {
|
|
76
|
+
setUpSegmentationEventHandlers(defaultParameters);
|
|
77
|
+
|
|
78
|
+
expect(setupSegmentationDataModifiedHandler).toHaveBeenCalledWith({
|
|
79
|
+
segmentationService: mockSegmentationService,
|
|
80
|
+
customizationService: mockCustomizationService,
|
|
81
|
+
commandsManager: mockCommandsManager,
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it('should setup segmentation modified handler', () => {
|
|
86
|
+
setUpSegmentationEventHandlers(defaultParameters);
|
|
87
|
+
|
|
88
|
+
expect(setupSegmentationModifiedHandler).toHaveBeenCalledWith({
|
|
89
|
+
segmentationService: mockSegmentationService,
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it('should subscribe to SEGMENTATION_ADDED event', () => {
|
|
94
|
+
setUpSegmentationEventHandlers(defaultParameters);
|
|
95
|
+
|
|
96
|
+
expect(mockSegmentationService.subscribe).toHaveBeenCalledWith(
|
|
97
|
+
mockSegmentationService.EVENTS.SEGMENTATION_ADDED,
|
|
98
|
+
expect.any(Function)
|
|
99
|
+
);
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it('should return unsubscriptions object', () => {
|
|
103
|
+
const result = setUpSegmentationEventHandlers(defaultParameters);
|
|
104
|
+
|
|
105
|
+
expect(result).toEqual({
|
|
106
|
+
unsubscriptions: [
|
|
107
|
+
mockUnsubscribeDataModified,
|
|
108
|
+
mockUnsubscribeModified,
|
|
109
|
+
mockUnsubscribeCreated,
|
|
110
|
+
mockUnsubscribeRemoved,
|
|
111
|
+
...mockUnsubscribeSelectedSegmentationsForViewportEvents,
|
|
112
|
+
],
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it('should return early when displaySet already exists for segmentationId', () => {
|
|
117
|
+
const mockDisplaySet = {
|
|
118
|
+
displaySetInstanceUID: 'test-segmentation-id',
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
mockDisplaySetService.getDisplaySetByUID.mockReturnValue(mockDisplaySet);
|
|
122
|
+
|
|
123
|
+
setUpSegmentationEventHandlers(defaultParameters);
|
|
124
|
+
|
|
125
|
+
const callback = mockSegmentationService.subscribe.mock.calls[0][1];
|
|
126
|
+
const evt = { segmentationId: 'test-segmentation-id' };
|
|
127
|
+
|
|
128
|
+
callback(evt);
|
|
129
|
+
|
|
130
|
+
expect(mockDisplaySetService.getDisplaySetByUID).toHaveBeenCalledWith('test-segmentation-id');
|
|
131
|
+
expect(mockSegmentationService.getSegmentation).not.toHaveBeenCalled();
|
|
132
|
+
expect(mockDisplaySetService.addDisplaySets).not.toHaveBeenCalled();
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
it('should create and add display set when segmentation is added and no displaySet exists', () => {
|
|
136
|
+
const mockSegmentation = {
|
|
137
|
+
label: 'Test Segmentation Label',
|
|
138
|
+
cachedStats: {
|
|
139
|
+
info: 'Test Segmentation Label',
|
|
140
|
+
},
|
|
141
|
+
representationData: {
|
|
142
|
+
Labelmap: {
|
|
143
|
+
imageIds: ['image-1', 'image-2', 'image-3'],
|
|
144
|
+
},
|
|
145
|
+
},
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
mockDisplaySetService.getDisplaySetByUID.mockReturnValue(null);
|
|
149
|
+
mockSegmentationService.getSegmentation.mockReturnValue(mockSegmentation);
|
|
150
|
+
|
|
151
|
+
setUpSegmentationEventHandlers(defaultParameters);
|
|
152
|
+
|
|
153
|
+
const callback = mockSegmentationService.subscribe.mock.calls[0][1];
|
|
154
|
+
const evt = { segmentationId: 'test-segmentation-id' };
|
|
155
|
+
|
|
156
|
+
callback(evt);
|
|
157
|
+
|
|
158
|
+
expect(mockDisplaySetService.getDisplaySetByUID).toHaveBeenCalledWith('test-segmentation-id');
|
|
159
|
+
expect(mockSegmentationService.getSegmentation).toHaveBeenCalledWith('test-segmentation-id');
|
|
160
|
+
expect(mockDisplaySetService.addDisplaySets).toHaveBeenCalledWith({
|
|
161
|
+
displaySetInstanceUID: 'test-segmentation-id',
|
|
162
|
+
SOPClassUID: '1.2.840.10008.5.1.4.1.1.66.4',
|
|
163
|
+
SOPClassHandlerId: '@ohif/extension-cornerstone-dicom-seg.sopClassHandlerModule.dicom-seg',
|
|
164
|
+
SeriesDescription: mockSegmentation.label,
|
|
165
|
+
Modality: 'SEG',
|
|
166
|
+
numImageFrames: mockSegmentation.representationData.Labelmap.imageIds.length,
|
|
167
|
+
imageIds: mockSegmentation.representationData.Labelmap.imageIds,
|
|
168
|
+
isOverlayDisplaySet: true,
|
|
169
|
+
label: mockSegmentation.label,
|
|
170
|
+
madeInClient: true,
|
|
171
|
+
segmentationId: 'test-segmentation-id',
|
|
172
|
+
isDerived: true,
|
|
173
|
+
});
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
it('should handle displaySet undefined when segmentation is added', () => {
|
|
177
|
+
const mockSegmentation = {
|
|
178
|
+
label: 'Test Segmentation Label',
|
|
179
|
+
cachedStats: {
|
|
180
|
+
info: 'Test Segmentation Label',
|
|
181
|
+
},
|
|
182
|
+
representationData: {
|
|
183
|
+
Labelmap: {
|
|
184
|
+
imageIds: ['image-1', 'image-2'],
|
|
185
|
+
},
|
|
186
|
+
},
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
mockDisplaySetService.getDisplaySetByUID.mockReturnValue(undefined);
|
|
190
|
+
mockSegmentationService.getSegmentation.mockReturnValue(mockSegmentation);
|
|
191
|
+
|
|
192
|
+
setUpSegmentationEventHandlers(defaultParameters);
|
|
193
|
+
|
|
194
|
+
const callback = mockSegmentationService.subscribe.mock.calls[0][1];
|
|
195
|
+
const evt = { segmentationId: 'test-segmentation-id' };
|
|
196
|
+
|
|
197
|
+
callback(evt);
|
|
198
|
+
|
|
199
|
+
expect(mockSegmentationService.getSegmentation).toHaveBeenCalledWith('test-segmentation-id');
|
|
200
|
+
expect(mockDisplaySetService.addDisplaySets).toHaveBeenCalledWith({
|
|
201
|
+
displaySetInstanceUID: 'test-segmentation-id',
|
|
202
|
+
SOPClassUID: '1.2.840.10008.5.1.4.1.1.66.4',
|
|
203
|
+
SOPClassHandlerId: '@ohif/extension-cornerstone-dicom-seg.sopClassHandlerModule.dicom-seg',
|
|
204
|
+
SeriesDescription: mockSegmentation.label,
|
|
205
|
+
Modality: 'SEG',
|
|
206
|
+
numImageFrames: mockSegmentation.representationData.Labelmap.imageIds.length,
|
|
207
|
+
imageIds: mockSegmentation.representationData.Labelmap.imageIds,
|
|
208
|
+
isOverlayDisplaySet: true,
|
|
209
|
+
label: mockSegmentation.label,
|
|
210
|
+
madeInClient: true,
|
|
211
|
+
segmentationId: 'test-segmentation-id',
|
|
212
|
+
isDerived: true,
|
|
213
|
+
});
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
it('should handle empty imageIds array', () => {
|
|
217
|
+
const mockSegmentation = {
|
|
218
|
+
label: 'Empty Segmentation',
|
|
219
|
+
cachedStats: {
|
|
220
|
+
info: 'Empty Segmentation',
|
|
221
|
+
},
|
|
222
|
+
representationData: {
|
|
223
|
+
Labelmap: {
|
|
224
|
+
imageIds: [],
|
|
225
|
+
},
|
|
226
|
+
},
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
mockDisplaySetService.getDisplaySetByUID.mockReturnValue(null);
|
|
230
|
+
mockSegmentationService.getSegmentation.mockReturnValue(mockSegmentation);
|
|
231
|
+
|
|
232
|
+
setUpSegmentationEventHandlers(defaultParameters);
|
|
233
|
+
|
|
234
|
+
const callback = mockSegmentationService.subscribe.mock.calls[0][1];
|
|
235
|
+
const evt = { segmentationId: 'empty-segmentation-id' };
|
|
236
|
+
|
|
237
|
+
callback(evt);
|
|
238
|
+
|
|
239
|
+
expect(mockDisplaySetService.addDisplaySets).toHaveBeenCalledWith({
|
|
240
|
+
displaySetInstanceUID: 'empty-segmentation-id',
|
|
241
|
+
SOPClassUID: '1.2.840.10008.5.1.4.1.1.66.4',
|
|
242
|
+
SOPClassHandlerId: '@ohif/extension-cornerstone-dicom-seg.sopClassHandlerModule.dicom-seg',
|
|
243
|
+
SeriesDescription: mockSegmentation.label,
|
|
244
|
+
Modality: 'SEG',
|
|
245
|
+
numImageFrames: 0,
|
|
246
|
+
imageIds: [],
|
|
247
|
+
isOverlayDisplaySet: true,
|
|
248
|
+
label: mockSegmentation.label,
|
|
249
|
+
madeInClient: true,
|
|
250
|
+
segmentationId: 'empty-segmentation-id',
|
|
251
|
+
isDerived: true,
|
|
252
|
+
});
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
it('should handle different segmentation label values', () => {
|
|
256
|
+
const mockSegmentation = {
|
|
257
|
+
label: 'Custom Label Text',
|
|
258
|
+
cachedStats: {
|
|
259
|
+
info: 'Custom Label Text',
|
|
260
|
+
},
|
|
261
|
+
representationData: {
|
|
262
|
+
Labelmap: {
|
|
263
|
+
imageIds: ['custom-image-1'],
|
|
264
|
+
},
|
|
265
|
+
},
|
|
266
|
+
};
|
|
267
|
+
|
|
268
|
+
mockDisplaySetService.getDisplaySetByUID.mockReturnValue(null);
|
|
269
|
+
mockSegmentationService.getSegmentation.mockReturnValue(mockSegmentation);
|
|
270
|
+
|
|
271
|
+
setUpSegmentationEventHandlers(defaultParameters);
|
|
272
|
+
|
|
273
|
+
const callback = mockSegmentationService.subscribe.mock.calls[0][1];
|
|
274
|
+
const evt = { segmentationId: 'custom-segmentation-id' };
|
|
275
|
+
|
|
276
|
+
callback(evt);
|
|
277
|
+
|
|
278
|
+
expect(mockDisplaySetService.addDisplaySets).toHaveBeenCalledWith({
|
|
279
|
+
displaySetInstanceUID: 'custom-segmentation-id',
|
|
280
|
+
SOPClassUID: '1.2.840.10008.5.1.4.1.1.66.4',
|
|
281
|
+
SOPClassHandlerId: '@ohif/extension-cornerstone-dicom-seg.sopClassHandlerModule.dicom-seg',
|
|
282
|
+
SeriesDescription: 'Custom Label Text',
|
|
283
|
+
Modality: 'SEG',
|
|
284
|
+
numImageFrames: 1,
|
|
285
|
+
imageIds: ['custom-image-1'],
|
|
286
|
+
isOverlayDisplaySet: true,
|
|
287
|
+
label: 'Custom Label Text',
|
|
288
|
+
madeInClient: true,
|
|
289
|
+
segmentationId: 'custom-segmentation-id',
|
|
290
|
+
isDerived: true,
|
|
291
|
+
});
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
it('should handle multiple segmentation events', () => {
|
|
295
|
+
const mockSegmentation1 = {
|
|
296
|
+
label: 'Segmentation 1',
|
|
297
|
+
cachedStats: {
|
|
298
|
+
info: 'Segmentation 1',
|
|
299
|
+
},
|
|
300
|
+
representationData: {
|
|
301
|
+
Labelmap: {
|
|
302
|
+
imageIds: ['image-1'],
|
|
303
|
+
},
|
|
304
|
+
},
|
|
305
|
+
};
|
|
306
|
+
|
|
307
|
+
const mockSegmentation2 = {
|
|
308
|
+
label: 'Segmentation 2',
|
|
309
|
+
cachedStats: {
|
|
310
|
+
info: 'Segmentation 2',
|
|
311
|
+
},
|
|
312
|
+
representationData: {
|
|
313
|
+
Labelmap: {
|
|
314
|
+
imageIds: ['image-2', 'image-3'],
|
|
315
|
+
},
|
|
316
|
+
},
|
|
317
|
+
};
|
|
318
|
+
|
|
319
|
+
mockDisplaySetService.getDisplaySetByUID.mockReturnValue(null);
|
|
320
|
+
mockSegmentationService.getSegmentation
|
|
321
|
+
.mockReturnValueOnce(mockSegmentation1)
|
|
322
|
+
.mockReturnValueOnce(mockSegmentation2);
|
|
323
|
+
|
|
324
|
+
setUpSegmentationEventHandlers(defaultParameters);
|
|
325
|
+
|
|
326
|
+
const callback = mockSegmentationService.subscribe.mock.calls[0][1];
|
|
327
|
+
|
|
328
|
+
callback({ segmentationId: 'segmentation-1' });
|
|
329
|
+
callback({ segmentationId: 'segmentation-2' });
|
|
330
|
+
|
|
331
|
+
expect(mockDisplaySetService.addDisplaySets).toHaveBeenCalledTimes(2);
|
|
332
|
+
expect(mockDisplaySetService.addDisplaySets).toHaveBeenNthCalledWith(1, {
|
|
333
|
+
displaySetInstanceUID: 'segmentation-1',
|
|
334
|
+
SOPClassUID: '1.2.840.10008.5.1.4.1.1.66.4',
|
|
335
|
+
SOPClassHandlerId: '@ohif/extension-cornerstone-dicom-seg.sopClassHandlerModule.dicom-seg',
|
|
336
|
+
SeriesDescription: mockSegmentation1.label,
|
|
337
|
+
Modality: 'SEG',
|
|
338
|
+
numImageFrames: 1,
|
|
339
|
+
imageIds: mockSegmentation1.representationData.Labelmap.imageIds,
|
|
340
|
+
isOverlayDisplaySet: true,
|
|
341
|
+
label: mockSegmentation1.label,
|
|
342
|
+
madeInClient: true,
|
|
343
|
+
segmentationId: 'segmentation-1',
|
|
344
|
+
isDerived: true,
|
|
345
|
+
});
|
|
346
|
+
expect(mockDisplaySetService.addDisplaySets).toHaveBeenNthCalledWith(2, {
|
|
347
|
+
displaySetInstanceUID: 'segmentation-2',
|
|
348
|
+
SOPClassUID: '1.2.840.10008.5.1.4.1.1.66.4',
|
|
349
|
+
SOPClassHandlerId: '@ohif/extension-cornerstone-dicom-seg.sopClassHandlerModule.dicom-seg',
|
|
350
|
+
SeriesDescription: mockSegmentation2.label,
|
|
351
|
+
Modality: 'SEG',
|
|
352
|
+
numImageFrames: 2,
|
|
353
|
+
imageIds: mockSegmentation2.representationData.Labelmap.imageIds,
|
|
354
|
+
isOverlayDisplaySet: true,
|
|
355
|
+
label: mockSegmentation2.label,
|
|
356
|
+
madeInClient: true,
|
|
357
|
+
segmentationId: 'segmentation-2',
|
|
358
|
+
isDerived: true,
|
|
359
|
+
});
|
|
360
|
+
});
|
|
361
|
+
|
|
362
|
+
it('should call all unsubscribe functions in returned unsubscriptions array', () => {
|
|
363
|
+
const result = setUpSegmentationEventHandlers(defaultParameters);
|
|
364
|
+
|
|
365
|
+
result.unsubscriptions.forEach(unsubscribe => unsubscribe());
|
|
366
|
+
|
|
367
|
+
expect(mockUnsubscribeDataModified).toHaveBeenCalled();
|
|
368
|
+
expect(mockUnsubscribeModified).toHaveBeenCalled();
|
|
369
|
+
expect(mockUnsubscribeCreated).toHaveBeenCalled();
|
|
370
|
+
expect(mockUnsubscribeRemoved).toHaveBeenCalled();
|
|
371
|
+
});
|
|
372
|
+
});
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { Enums as csToolsEnums } from '@cornerstonejs/tools';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
setUpSelectedSegmentationsForViewportHandler,
|
|
5
|
+
setupSegmentationDataModifiedHandler,
|
|
6
|
+
setupSegmentationModifiedHandler,
|
|
7
|
+
} from './segmentationHandlers';
|
|
8
|
+
|
|
9
|
+
export const setUpSegmentationEventHandlers = ({ servicesManager, commandsManager }) => {
|
|
10
|
+
const { segmentationService, customizationService, displaySetService, viewportGridService } =
|
|
11
|
+
servicesManager.services;
|
|
12
|
+
|
|
13
|
+
const { unsubscribe: unsubscribeSegmentationDataModifiedHandler } =
|
|
14
|
+
setupSegmentationDataModifiedHandler({
|
|
15
|
+
segmentationService,
|
|
16
|
+
customizationService,
|
|
17
|
+
commandsManager,
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
const { unsubscribe: unsubscribeSegmentationModifiedHandler } = setupSegmentationModifiedHandler({
|
|
21
|
+
segmentationService,
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
const { unsubscribe: unsubscribeSegmentationCreated } = segmentationService.subscribe(
|
|
25
|
+
segmentationService.EVENTS.SEGMENTATION_ADDED,
|
|
26
|
+
evt => {
|
|
27
|
+
const { segmentationId } = evt;
|
|
28
|
+
const displaySet = displaySetService.getDisplaySetByUID(segmentationId);
|
|
29
|
+
if (displaySet) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const segmentation = segmentationService.getSegmentation(segmentationId);
|
|
34
|
+
const label = segmentation.label;
|
|
35
|
+
const imageIds =
|
|
36
|
+
segmentation.representationData?.Labelmap?.imageIds ??
|
|
37
|
+
segmentation.representationData?.Contour?.imageIds;
|
|
38
|
+
|
|
39
|
+
// Create a display set for the segmentation
|
|
40
|
+
const segmentationDisplaySet = {
|
|
41
|
+
displaySetInstanceUID: segmentationId,
|
|
42
|
+
SOPClassUID: '1.2.840.10008.5.1.4.1.1.66.4',
|
|
43
|
+
SOPClassHandlerId: '@ohif/extension-cornerstone-dicom-seg.sopClassHandlerModule.dicom-seg',
|
|
44
|
+
SeriesDescription: label,
|
|
45
|
+
Modality: segmentation.representationData[csToolsEnums.SegmentationRepresentations.Contour]
|
|
46
|
+
? 'RTSTRUCT'
|
|
47
|
+
: 'SEG',
|
|
48
|
+
numImageFrames: imageIds.length,
|
|
49
|
+
imageIds,
|
|
50
|
+
isOverlayDisplaySet: true,
|
|
51
|
+
label,
|
|
52
|
+
madeInClient: true,
|
|
53
|
+
segmentationId: segmentationId,
|
|
54
|
+
isDerived: true,
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
displaySetService.addDisplaySets(segmentationDisplaySet);
|
|
58
|
+
}
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
const { unsubscribe: unsubscribeSegmentationRemoved } = segmentationService.subscribe(
|
|
62
|
+
segmentationService.EVENTS.SEGMENTATION_REMOVED,
|
|
63
|
+
({ segmentationId }) => {
|
|
64
|
+
const displaySet = displaySetService.getDisplaySetByUID(segmentationId);
|
|
65
|
+
|
|
66
|
+
// Remove the display set layer from all viewports that have it
|
|
67
|
+
if (displaySet) {
|
|
68
|
+
// This is the global removal path (the segmentation is gone from state,
|
|
69
|
+
// e.g. deleted from the segmentation panel), so clear the global
|
|
70
|
+
// "show this wherever it logically belongs" state. It must happen
|
|
71
|
+
// outside the loop below: that loop only visits viewports carrying the
|
|
72
|
+
// segmentation as an explicit layer, and a hydrated segmentation is
|
|
73
|
+
// never listed in a viewport's displaySetInstanceUIDs - only the
|
|
74
|
+
// referenced volume is. Recording `hydrated: false` rather than just
|
|
75
|
+
// dropping the entry keeps the store a statement of desired state, so a
|
|
76
|
+
// viewport created later converges on "not shown" instead of replaying
|
|
77
|
+
// an earlier `hydrated: true`.
|
|
78
|
+
displaySet.isHydrated = false;
|
|
79
|
+
|
|
80
|
+
commandsManager.runCommand('updateStoredSegmentationPresentation', {
|
|
81
|
+
displaySet,
|
|
82
|
+
hydrated: false,
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
const state = viewportGridService.getState();
|
|
86
|
+
const viewports = state.viewports;
|
|
87
|
+
|
|
88
|
+
// Find all viewports that contain this segmentation's display set as a layer
|
|
89
|
+
for (const [viewportId, viewport] of viewports.entries()) {
|
|
90
|
+
const displaySetInstanceUIDs = viewport.displaySetInstanceUIDs || [];
|
|
91
|
+
if (displaySetInstanceUIDs.includes(segmentationId)) {
|
|
92
|
+
// Remove the display set layer from this viewport
|
|
93
|
+
commandsManager.runCommand('removeDisplaySetLayer', {
|
|
94
|
+
viewportId,
|
|
95
|
+
displaySetInstanceUID: segmentationId,
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Delete the display set from the service if it was made in client
|
|
101
|
+
if (displaySet.madeInClient) {
|
|
102
|
+
displaySetService.deleteDisplaySet(segmentationId);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
const { unsubscribeSelectedSegmentationsForViewportEvents } =
|
|
109
|
+
setUpSelectedSegmentationsForViewportHandler({
|
|
110
|
+
segmentationService,
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
const unsubscriptions = [
|
|
114
|
+
unsubscribeSegmentationDataModifiedHandler,
|
|
115
|
+
unsubscribeSegmentationModifiedHandler,
|
|
116
|
+
unsubscribeSegmentationCreated,
|
|
117
|
+
unsubscribeSegmentationRemoved,
|
|
118
|
+
...unsubscribeSelectedSegmentationsForViewportEvents,
|
|
119
|
+
];
|
|
120
|
+
|
|
121
|
+
return { unsubscriptions };
|
|
122
|
+
};
|