@ohif/extension-cornerstone 3.14.0-beta.12 → 3.14.0-beta.121
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 +3008 -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/Viewport3DCompassMenu.tsx +261 -0
- package/src/components/ViewportOrientationMenu/ViewportOrientationMenu.tsx +249 -0
- package/src/components/ViewportOrientationMenu/ViewportOrientationMenuWrapper.tsx +40 -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 +352 -0
- package/src/init.tsx +450 -0
- package/src/initCineService.ts +75 -0
- package/src/initContextMenu.ts +94 -0
- package/src/initCornerstoneTools.js +191 -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
- package/src/utils/volume3dView.test.ts +48 -0
- package/src/utils/volume3dView.ts +113 -0
|
@@ -0,0 +1,417 @@
|
|
|
1
|
+
import { create } from 'zustand';
|
|
2
|
+
import { devtools } from 'zustand/middleware';
|
|
3
|
+
import { SegmentationPresentation, SegmentationPresentationItem } from '../types/Presentation';
|
|
4
|
+
import { JOIN_STR } from './presentationUtils';
|
|
5
|
+
import { getViewportOrientationFromImageOrientationPatient } from '../utils/getViewportOrientationFromImageOrientationPatient';
|
|
6
|
+
|
|
7
|
+
const PRESENTATION_TYPE_ID = 'segmentationPresentationId';
|
|
8
|
+
const DEBUG_STORE = false;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The keys are the presentationId.
|
|
12
|
+
*/
|
|
13
|
+
type SegmentationPresentationStore = {
|
|
14
|
+
/**
|
|
15
|
+
* Type identifier for the store.
|
|
16
|
+
*/
|
|
17
|
+
type: string;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Stores segmentation presentations indexed by their presentation ID.
|
|
21
|
+
*/
|
|
22
|
+
segmentationPresentationStore: Record<string, SegmentationPresentation>;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Sets the segmentation presentation for a given segmentation ID.
|
|
26
|
+
*
|
|
27
|
+
* @param presentationId - The presentation ID.
|
|
28
|
+
* @param value - The `SegmentationPresentation` to associate with the ID.
|
|
29
|
+
*/
|
|
30
|
+
setSegmentationPresentation: (presentationId: string, value: SegmentationPresentation) => void;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Clears all segmentation presentations from the store.
|
|
34
|
+
*/
|
|
35
|
+
clearSegmentationPresentationStore: () => void;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Retrieves the presentation ID based on the provided parameters.
|
|
39
|
+
*
|
|
40
|
+
* @param id - The ID to check.
|
|
41
|
+
* @param options - Configuration options.
|
|
42
|
+
* @param options.viewport - The current viewport.
|
|
43
|
+
* @param options.viewports - All available viewports.
|
|
44
|
+
* @param options.isUpdatingSameViewport - Indicates if the same viewport is being updated.
|
|
45
|
+
* @param options.servicesManager - The services manager instance.
|
|
46
|
+
* @returns The segmentation presentation ID or undefined.
|
|
47
|
+
*/
|
|
48
|
+
getPresentationId: (
|
|
49
|
+
id: string,
|
|
50
|
+
options: {
|
|
51
|
+
viewport: AppTypes.ViewportGrid.Viewport;
|
|
52
|
+
viewports: AppTypes.ViewportGrid.Viewports;
|
|
53
|
+
isUpdatingSameViewport: boolean;
|
|
54
|
+
servicesManager: AppTypes.ServicesManager;
|
|
55
|
+
}
|
|
56
|
+
) => string | undefined;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Adds or replaces a segmentation presentation item.
|
|
60
|
+
*
|
|
61
|
+
* Items are identified by their `segmentationId`: an existing entry for the
|
|
62
|
+
* same segmentation is replaced rather than appended. Appending would let
|
|
63
|
+
* hydrate -> remove -> hydrate accumulate duplicate entries for one
|
|
64
|
+
* segmentation, and the viewport applies every entry, so the same
|
|
65
|
+
* representation would be added more than once.
|
|
66
|
+
*
|
|
67
|
+
* @param presentationId - The presentation ID.
|
|
68
|
+
* @param segmentationPresentationItem - The item to add or replace.
|
|
69
|
+
*/
|
|
70
|
+
addSegmentationPresentationItem: (
|
|
71
|
+
presentationId: string,
|
|
72
|
+
segmentationPresentationItem: SegmentationPresentationItem
|
|
73
|
+
) => void;
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Updates the recorded hydration of one segmentation in every presentation
|
|
77
|
+
* that already holds an entry for it, creating none.
|
|
78
|
+
*
|
|
79
|
+
* The store is keyed by the display set a segmentation is hydrated against,
|
|
80
|
+
* so a segmentation with no referenced display set - one drawn in the client -
|
|
81
|
+
* has no key of its own to be written under. It is still recorded, under the
|
|
82
|
+
* key of whatever viewport it was drawn in (see `_getInitialHydrationForSync`
|
|
83
|
+
* in CornerstoneViewportService), and nothing supersedes that record on its
|
|
84
|
+
* own - `syncSegmentationPresentation` only ever merges. So a removal
|
|
85
|
+
* converges the store by rewriting the entries that exist, rather than
|
|
86
|
+
* inventing a key that every such segmentation would collide under.
|
|
87
|
+
*
|
|
88
|
+
* @param segmentationId - The segmentation to restate.
|
|
89
|
+
* @param value.hydrated - The hydration to record for it.
|
|
90
|
+
* @param value.type - The representation type, if the caller knows it;
|
|
91
|
+
* otherwise each entry keeps the type it has.
|
|
92
|
+
*/
|
|
93
|
+
setHydrationForSegmentation: (
|
|
94
|
+
segmentationId: string,
|
|
95
|
+
value: { hydrated: boolean | null; type?: SegmentationPresentationItem['type'] }
|
|
96
|
+
) => void;
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Records the representations a viewport is currently rendering, without
|
|
100
|
+
* changing hydration.
|
|
101
|
+
*
|
|
102
|
+
* `hydrated` is display-set-global ("show this wherever it logically
|
|
103
|
+
* belongs") and is owned by the hydration paths, which write it through
|
|
104
|
+
* `addSegmentationPresentationItem`. A viewport's live representations are
|
|
105
|
+
* not: a segmentation added from the viewport data overlay menu is meant for
|
|
106
|
+
* that one pane, and the presentation id is shared by every pane over the
|
|
107
|
+
* same background. So for a segmentation the store already knows about this
|
|
108
|
+
* keeps the recorded `hydrated` and only refreshes `type`/`config`; the
|
|
109
|
+
* caller's `hydrated` applies only to a segmentation with no entry yet.
|
|
110
|
+
*
|
|
111
|
+
* Entries the viewport is not rendering are kept as they are - a pane that
|
|
112
|
+
* was gated out of automatic hydration, or one the user removed the overlay
|
|
113
|
+
* from, must not erase the record the other panes resolve against.
|
|
114
|
+
*
|
|
115
|
+
* @param presentationId - The presentation ID.
|
|
116
|
+
* @param items - One item per representation the viewport renders.
|
|
117
|
+
*/
|
|
118
|
+
syncSegmentationPresentation: (presentationId: string, items: SegmentationPresentation) => void;
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Gets the current segmentation presentation ID.
|
|
122
|
+
*
|
|
123
|
+
* @param params - Parameters for retrieving the segmentation presentation ID.
|
|
124
|
+
* @param params.viewport - The current viewport.
|
|
125
|
+
* @param params.servicesManager - The services manager instance.
|
|
126
|
+
* @returns The current segmentation presentation ID.
|
|
127
|
+
*/
|
|
128
|
+
getSegmentationPresentationId: ({
|
|
129
|
+
viewport,
|
|
130
|
+
servicesManager,
|
|
131
|
+
}: {
|
|
132
|
+
viewport: AppTypes.ViewportGrid.Viewport;
|
|
133
|
+
servicesManager: AppTypes.ServicesManager;
|
|
134
|
+
}) => string;
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Generates a segmentation presentation ID based on the viewport configuration.
|
|
139
|
+
*
|
|
140
|
+
* @param id - The ID to check.
|
|
141
|
+
* @param options - Configuration options.
|
|
142
|
+
* @param options.viewport - The current viewport.
|
|
143
|
+
* @param options.viewports - All available viewports.
|
|
144
|
+
* @param options.isUpdatingSameViewport - Indicates if the same viewport is being updated.
|
|
145
|
+
* @param options.servicesManager - The services manager instance.
|
|
146
|
+
* @returns The segmentation presentation ID or undefined.
|
|
147
|
+
*/
|
|
148
|
+
const getPresentationId = (
|
|
149
|
+
id: string,
|
|
150
|
+
{
|
|
151
|
+
viewport,
|
|
152
|
+
viewports,
|
|
153
|
+
isUpdatingSameViewport,
|
|
154
|
+
servicesManager,
|
|
155
|
+
}: {
|
|
156
|
+
viewport: AppTypes.ViewportGrid.Viewport;
|
|
157
|
+
viewports: AppTypes.ViewportGrid.Viewports;
|
|
158
|
+
isUpdatingSameViewport: boolean;
|
|
159
|
+
servicesManager: AppTypes.ServicesManager;
|
|
160
|
+
}
|
|
161
|
+
): string | undefined => {
|
|
162
|
+
if (id !== PRESENTATION_TYPE_ID) {
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
return _getSegmentationPresentationId({ viewport, servicesManager });
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Helper function to generate the segmentation presentation ID.
|
|
171
|
+
*
|
|
172
|
+
* @param params - Parameters for generating the segmentation presentation ID.
|
|
173
|
+
* @param params.viewport - The current viewport.
|
|
174
|
+
* @param params.servicesManager - The services manager instance.
|
|
175
|
+
* @returns The segmentation presentation ID or undefined.
|
|
176
|
+
*/
|
|
177
|
+
const _getSegmentationPresentationId = ({
|
|
178
|
+
viewport,
|
|
179
|
+
servicesManager,
|
|
180
|
+
}: {
|
|
181
|
+
viewport: AppTypes.ViewportGrid.Viewport;
|
|
182
|
+
servicesManager: AppTypes.ServicesManager;
|
|
183
|
+
}) => {
|
|
184
|
+
if (!viewport?.viewportOptions || !viewport.displaySetInstanceUIDs?.length) {
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
const { displaySetService } = servicesManager.services;
|
|
189
|
+
const { displaySetInstanceUIDs, viewportOptions } = viewport;
|
|
190
|
+
|
|
191
|
+
// Match keys used by updateStoredSegmentationPresentation (referenced volume only).
|
|
192
|
+
// Including overlay UIDs (e.g. SEG) produced ids like "MR&SEG" while the store
|
|
193
|
+
// entry is under "MR", so hydrated segmentations never applied and viewports could mis-render.
|
|
194
|
+
const nonOverlayUIDs = displaySetInstanceUIDs.filter(uid => {
|
|
195
|
+
const ds = displaySetService.getDisplaySetByUID(uid);
|
|
196
|
+
return ds && !ds.isOverlayDisplaySet;
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
if (!nonOverlayUIDs.length) {
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
let orientation = viewportOptions.orientation;
|
|
204
|
+
|
|
205
|
+
if (!orientation) {
|
|
206
|
+
// Calculate orientation from the viewport sample image
|
|
207
|
+
const displaySet = displaySetService.getDisplaySetByUID(nonOverlayUIDs[0]);
|
|
208
|
+
const sampleImage = displaySet?.images?.[0];
|
|
209
|
+
const imageOrientationPatient = sampleImage?.ImageOrientationPatient;
|
|
210
|
+
|
|
211
|
+
orientation = getViewportOrientationFromImageOrientationPatient(imageOrientationPatient);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
const segmentationPresentationArr = [];
|
|
215
|
+
|
|
216
|
+
// Keyed by the exact display set UIDs. Two display sets can share a frame of
|
|
217
|
+
// reference while being unrelated series, so the frame of reference is not
|
|
218
|
+
// usable as a key - which viewports a hydrated segmentation belongs in is a
|
|
219
|
+
// relation, resolved at read time by getViewportPresentations rather than
|
|
220
|
+
// encoded here.
|
|
221
|
+
segmentationPresentationArr.push(...nonOverlayUIDs);
|
|
222
|
+
|
|
223
|
+
// Uncomment if unique indexing is needed
|
|
224
|
+
// addUniqueIndex(
|
|
225
|
+
// segmentationPresentationArr,
|
|
226
|
+
// 'segmentationPresentationId',
|
|
227
|
+
// viewports,
|
|
228
|
+
// isUpdatingSameViewport
|
|
229
|
+
// );
|
|
230
|
+
|
|
231
|
+
return segmentationPresentationArr.join(JOIN_STR);
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Creates the Segmentation Presentation store.
|
|
236
|
+
*
|
|
237
|
+
* @param set - The zustand set function.
|
|
238
|
+
* @returns The Segmentation Presentation store state and actions.
|
|
239
|
+
*/
|
|
240
|
+
const createSegmentationPresentationStore = set => ({
|
|
241
|
+
type: PRESENTATION_TYPE_ID,
|
|
242
|
+
segmentationPresentationStore: {},
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Clears all segmentation presentations from the store.
|
|
246
|
+
*/
|
|
247
|
+
clearSegmentationPresentationStore: () =>
|
|
248
|
+
set({ segmentationPresentationStore: {} }, false, 'clearSegmentationPresentationStore'),
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Adds a new segmentation presentation item to the store, replacing any
|
|
252
|
+
* existing item for the same segmentation.
|
|
253
|
+
*
|
|
254
|
+
* segmentationPresentationItem: {
|
|
255
|
+
* segmentationId: string;
|
|
256
|
+
* type: SegmentationRepresentations;
|
|
257
|
+
* hydrated: boolean | null;
|
|
258
|
+
* config?: unknown;
|
|
259
|
+
* }
|
|
260
|
+
*/
|
|
261
|
+
addSegmentationPresentationItem: (
|
|
262
|
+
presentationId: string,
|
|
263
|
+
segmentationPresentationItem: SegmentationPresentationItem
|
|
264
|
+
) =>
|
|
265
|
+
set(
|
|
266
|
+
state => {
|
|
267
|
+
const existingItems = state.segmentationPresentationStore[presentationId] || [];
|
|
268
|
+
|
|
269
|
+
// Upsert by segmentationId: the store records the desired state of a
|
|
270
|
+
// segmentation for this presentation, so there is exactly one entry per
|
|
271
|
+
// segmentation and a later write (hydrate, or remove-from-viewport)
|
|
272
|
+
// supersedes an earlier one.
|
|
273
|
+
const otherItems = existingItems.filter(
|
|
274
|
+
item => item.segmentationId !== segmentationPresentationItem.segmentationId
|
|
275
|
+
);
|
|
276
|
+
|
|
277
|
+
return {
|
|
278
|
+
segmentationPresentationStore: {
|
|
279
|
+
...state.segmentationPresentationStore,
|
|
280
|
+
[presentationId]: [...otherItems, segmentationPresentationItem],
|
|
281
|
+
},
|
|
282
|
+
};
|
|
283
|
+
},
|
|
284
|
+
false,
|
|
285
|
+
'addSegmentationPresentationItem'
|
|
286
|
+
),
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* Restates the hydration of a segmentation wherever it is already recorded.
|
|
290
|
+
* See the type declaration for why this updates in place instead of writing
|
|
291
|
+
* an entry of its own.
|
|
292
|
+
*/
|
|
293
|
+
setHydrationForSegmentation: (
|
|
294
|
+
segmentationId: string,
|
|
295
|
+
{ hydrated, type }: { hydrated: boolean | null; type?: SegmentationPresentationItem['type'] }
|
|
296
|
+
) =>
|
|
297
|
+
set(
|
|
298
|
+
state => {
|
|
299
|
+
const updated: Record<string, SegmentationPresentation> = {};
|
|
300
|
+
const entries = Object.entries(state.segmentationPresentationStore) as [
|
|
301
|
+
string,
|
|
302
|
+
SegmentationPresentation,
|
|
303
|
+
][];
|
|
304
|
+
|
|
305
|
+
for (const [presentationId, items] of entries) {
|
|
306
|
+
if (!items?.some(item => item.segmentationId === segmentationId)) {
|
|
307
|
+
continue;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
updated[presentationId] = items.map(item =>
|
|
311
|
+
item.segmentationId === segmentationId
|
|
312
|
+
? { ...item, hydrated, type: type ?? item.type }
|
|
313
|
+
: item
|
|
314
|
+
);
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
// Nothing recorded for this segmentation is not something to state, and
|
|
318
|
+
// returning the state unchanged leaves subscribers alone.
|
|
319
|
+
if (!Object.keys(updated).length) {
|
|
320
|
+
return state;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
return {
|
|
324
|
+
segmentationPresentationStore: { ...state.segmentationPresentationStore, ...updated },
|
|
325
|
+
};
|
|
326
|
+
},
|
|
327
|
+
false,
|
|
328
|
+
'setHydrationForSegmentation'
|
|
329
|
+
),
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* Records the representations a viewport is currently rendering, keeping the
|
|
333
|
+
* hydration already recorded for each of them. See the type declaration for
|
|
334
|
+
* why hydration is not the viewport's to state.
|
|
335
|
+
*/
|
|
336
|
+
syncSegmentationPresentation: (presentationId: string, items: SegmentationPresentation) => {
|
|
337
|
+
// Nothing rendered is not a statement that nothing belongs here, and
|
|
338
|
+
// storePresentation runs on every viewport teardown, so skip the write
|
|
339
|
+
// rather than notifying subscribers of an unchanged store.
|
|
340
|
+
if (!items?.length) {
|
|
341
|
+
return;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
set(
|
|
345
|
+
state => {
|
|
346
|
+
const merged = [...(state.segmentationPresentationStore[presentationId] || [])];
|
|
347
|
+
|
|
348
|
+
for (const item of items) {
|
|
349
|
+
const index = merged.findIndex(
|
|
350
|
+
existing => existing.segmentationId === item.segmentationId
|
|
351
|
+
);
|
|
352
|
+
|
|
353
|
+
if (index === -1) {
|
|
354
|
+
merged.push(item);
|
|
355
|
+
continue;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
merged[index] = { ...item, hydrated: merged[index].hydrated };
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
return {
|
|
362
|
+
segmentationPresentationStore: {
|
|
363
|
+
...state.segmentationPresentationStore,
|
|
364
|
+
[presentationId]: merged,
|
|
365
|
+
},
|
|
366
|
+
};
|
|
367
|
+
},
|
|
368
|
+
false,
|
|
369
|
+
'syncSegmentationPresentation'
|
|
370
|
+
);
|
|
371
|
+
},
|
|
372
|
+
|
|
373
|
+
/**
|
|
374
|
+
* Sets the segmentation presentation for a given presentation ID. A segmentation
|
|
375
|
+
* presentation is an array of SegmentationPresentationItem.
|
|
376
|
+
*
|
|
377
|
+
* segmentationPresentationItem: {
|
|
378
|
+
* segmentationId: string;
|
|
379
|
+
* type: SegmentationRepresentations;
|
|
380
|
+
* hydrated: boolean | null;
|
|
381
|
+
* config?: unknown;
|
|
382
|
+
* }
|
|
383
|
+
*
|
|
384
|
+
* segmentationPresentation: SegmentationPresentationItem[]
|
|
385
|
+
*/
|
|
386
|
+
setSegmentationPresentation: (presentationId: string, values: SegmentationPresentation) =>
|
|
387
|
+
set(
|
|
388
|
+
state => ({
|
|
389
|
+
segmentationPresentationStore: {
|
|
390
|
+
...state.segmentationPresentationStore,
|
|
391
|
+
[presentationId]: values,
|
|
392
|
+
},
|
|
393
|
+
}),
|
|
394
|
+
false,
|
|
395
|
+
'setSegmentationPresentation'
|
|
396
|
+
),
|
|
397
|
+
|
|
398
|
+
/**
|
|
399
|
+
* Retrieves the presentation ID based on the provided parameters.
|
|
400
|
+
*/
|
|
401
|
+
getPresentationId,
|
|
402
|
+
|
|
403
|
+
/**
|
|
404
|
+
* Retrieves the current segmentation presentation ID.
|
|
405
|
+
*/
|
|
406
|
+
getSegmentationPresentationId: _getSegmentationPresentationId,
|
|
407
|
+
});
|
|
408
|
+
|
|
409
|
+
/**
|
|
410
|
+
* Zustand store for managing segmentation presentations.
|
|
411
|
+
* Applies devtools middleware when DEBUG_STORE is enabled.
|
|
412
|
+
*/
|
|
413
|
+
export const useSegmentationPresentationStore = create<SegmentationPresentationStore>()(
|
|
414
|
+
DEBUG_STORE
|
|
415
|
+
? devtools(createSegmentationPresentationStore, { name: 'Segmentation Presentation Store' })
|
|
416
|
+
: createSegmentationPresentationStore
|
|
417
|
+
);
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { create } from 'zustand';
|
|
2
|
+
import { devtools } from 'zustand/middleware';
|
|
3
|
+
import { SelectedSegmentationByTypeMap } from '../types/SelectedSegmentationByTypeMap';
|
|
4
|
+
|
|
5
|
+
const PRESENTATION_TYPE_ID = 'selectedSegmentationsForViewportId';
|
|
6
|
+
const DEBUG_STORE = false;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Represents the state and actions for managing selected segmentations for a viewport by representation type.
|
|
10
|
+
*/
|
|
11
|
+
type SelectedSegmentationsForViewportState = {
|
|
12
|
+
/**
|
|
13
|
+
* Stores a mapping from viewport id to a map of representation type to segmentation id.
|
|
14
|
+
*/
|
|
15
|
+
selectedSegmentationsForViewport: Record<string, SelectedSegmentationByTypeMap>;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Sets the selected segmentations for a given viewport id.
|
|
19
|
+
*
|
|
20
|
+
* @param key - The viewport id.
|
|
21
|
+
* @param value - The `SelectedSegmentationByTypeMap` to associate with the viewport id.
|
|
22
|
+
*/
|
|
23
|
+
setSelectedSegmentationsForViewport: (key: string, value: SelectedSegmentationByTypeMap) => void;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Clears all selected segmentations for all viewports.
|
|
27
|
+
*/
|
|
28
|
+
clearSelectedSegmentationsForViewportStore: () => void;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Type identifier for the store.
|
|
32
|
+
*/
|
|
33
|
+
type: string;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Creates the Selected Segmentations For Viewport store.
|
|
38
|
+
*
|
|
39
|
+
* @param set - The zustand set function.
|
|
40
|
+
* @returns The selected segmentations for viewport store state and actions.
|
|
41
|
+
*/
|
|
42
|
+
const createSelectedSegmentationsForViewportStore = (
|
|
43
|
+
set
|
|
44
|
+
): SelectedSegmentationsForViewportState => ({
|
|
45
|
+
selectedSegmentationsForViewport: {},
|
|
46
|
+
type: PRESENTATION_TYPE_ID,
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Sets the selected segmentations for a given viewport id.
|
|
50
|
+
*/
|
|
51
|
+
setSelectedSegmentationsForViewport: (key, value) =>
|
|
52
|
+
set(
|
|
53
|
+
state => ({
|
|
54
|
+
selectedSegmentationsForViewport: {
|
|
55
|
+
...state.selectedSegmentationsForViewport,
|
|
56
|
+
[key]: value,
|
|
57
|
+
},
|
|
58
|
+
}),
|
|
59
|
+
false,
|
|
60
|
+
'setSelectedSegmentationsForViewport'
|
|
61
|
+
),
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Clears all selected segmentations for all viewports.
|
|
65
|
+
*/
|
|
66
|
+
clearSelectedSegmentationsForViewportStore: () =>
|
|
67
|
+
set(
|
|
68
|
+
{ selectedSegmentationsForViewport: {} },
|
|
69
|
+
false,
|
|
70
|
+
'clearSelectedSegmentationsForViewportStore'
|
|
71
|
+
),
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Zustand store for managing selected segmentations for a viewport by representation type.
|
|
76
|
+
* Applies devtools middleware when DEBUG_STORE is enabled.
|
|
77
|
+
*/
|
|
78
|
+
export const useSelectedSegmentationsForViewportStore =
|
|
79
|
+
create<SelectedSegmentationsForViewportState>()(
|
|
80
|
+
DEBUG_STORE
|
|
81
|
+
? devtools(createSelectedSegmentationsForViewportStore, {
|
|
82
|
+
name: 'SelectedSegmentationsForViewportStore',
|
|
83
|
+
})
|
|
84
|
+
: createSelectedSegmentationsForViewportStore
|
|
85
|
+
);
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { create } from 'zustand';
|
|
2
|
+
import { devtools } from 'zustand/middleware';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Identifier for the synchronizers store type.
|
|
6
|
+
*/
|
|
7
|
+
const PRESENTATION_TYPE_ID = 'synchronizersStoreId';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Flag to enable or disable debug mode for the store.
|
|
11
|
+
* Set to `true` to enable zustand devtools.
|
|
12
|
+
*/
|
|
13
|
+
const DEBUG_STORE = false;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Information about a single synchronizer.
|
|
17
|
+
*/
|
|
18
|
+
type SynchronizerInfo = {
|
|
19
|
+
id: string;
|
|
20
|
+
type: string;
|
|
21
|
+
sourceViewports: Array<{ viewportId: string; renderingEngineId: string }>;
|
|
22
|
+
targetViewports: Array<{ viewportId: string; renderingEngineId: string }>;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* State shape for the Synchronizers store.
|
|
27
|
+
*/
|
|
28
|
+
type SynchronizersState = {
|
|
29
|
+
/**
|
|
30
|
+
* Stores synchronizer information indexed by a unique key.
|
|
31
|
+
*/
|
|
32
|
+
synchronizersStore: Record<string, SynchronizerInfo[]>;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Sets the synchronizers for a specific viewport.
|
|
36
|
+
*
|
|
37
|
+
* @param viewportId - The ID of the viewport.
|
|
38
|
+
* @param synchronizers - An array of SynchronizerInfo.
|
|
39
|
+
*/
|
|
40
|
+
setSynchronizers: (viewportId: string, synchronizers: SynchronizerInfo[]) => void;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Clears the entire synchronizers store.
|
|
44
|
+
*/
|
|
45
|
+
clearSynchronizersStore: () => void;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Creates the Synchronizers store.
|
|
50
|
+
*
|
|
51
|
+
* @param set - The zustand set function.
|
|
52
|
+
* @returns The synchronizers store state and actions.
|
|
53
|
+
*/
|
|
54
|
+
const createSynchronizersStore = (set): SynchronizersState => ({
|
|
55
|
+
synchronizersStore: {},
|
|
56
|
+
type: PRESENTATION_TYPE_ID,
|
|
57
|
+
|
|
58
|
+
setSynchronizers: (viewportId: string, synchronizers: SynchronizerInfo[]) => {
|
|
59
|
+
set(
|
|
60
|
+
state => ({
|
|
61
|
+
synchronizersStore: {
|
|
62
|
+
...state.synchronizersStore,
|
|
63
|
+
[viewportId]: synchronizers,
|
|
64
|
+
},
|
|
65
|
+
}),
|
|
66
|
+
false,
|
|
67
|
+
'setSynchronizers'
|
|
68
|
+
);
|
|
69
|
+
},
|
|
70
|
+
|
|
71
|
+
clearSynchronizersStore: () => {
|
|
72
|
+
set({ synchronizersStore: {} }, false, 'clearSynchronizersStore');
|
|
73
|
+
},
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Zustand store for managing synchronizers.
|
|
78
|
+
* Applies devtools middleware when DEBUG_STORE is enabled.
|
|
79
|
+
*/
|
|
80
|
+
export const useSynchronizersStore = create<SynchronizersState>()(
|
|
81
|
+
DEBUG_STORE
|
|
82
|
+
? devtools(createSynchronizersStore, { name: 'SynchronizersStore' })
|
|
83
|
+
: createSynchronizersStore
|
|
84
|
+
);
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { SynchronizerManager, Synchronizer } from '@cornerstonejs/tools';
|
|
2
|
+
import { EVENTS, getRenderingEngine, type Types, utilities } from '@cornerstonejs/core';
|
|
3
|
+
|
|
4
|
+
const frameViewSyncCallback = (
|
|
5
|
+
synchronizerInstance: Synchronizer,
|
|
6
|
+
sourceViewport: Types.IViewportId,
|
|
7
|
+
targetViewport: Types.IViewportId
|
|
8
|
+
) => {
|
|
9
|
+
const renderingEngine = getRenderingEngine(targetViewport.renderingEngineId);
|
|
10
|
+
if (!renderingEngine) {
|
|
11
|
+
throw new Error(`No RenderingEngine for Id: ${targetViewport.renderingEngineId}`);
|
|
12
|
+
}
|
|
13
|
+
const sViewport = renderingEngine.getViewport(sourceViewport.viewportId) as Types.IStackViewport;
|
|
14
|
+
|
|
15
|
+
const { viewportIndex: targetViewportIndex } = synchronizerInstance.getOptions(
|
|
16
|
+
targetViewport.viewportId
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
const { viewportIndex: sourceViewportIndex } = synchronizerInstance.getOptions(
|
|
20
|
+
sourceViewport.viewportId
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
if (targetViewportIndex === undefined || sourceViewportIndex === undefined) {
|
|
24
|
+
throw new Error('No viewportIndex provided');
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const tViewport = renderingEngine.getViewport(targetViewport.viewportId) as Types.IStackViewport;
|
|
28
|
+
|
|
29
|
+
const sourceSliceIndex = sViewport.getSliceIndex();
|
|
30
|
+
const sliceDifference = Number(targetViewportIndex) - Number(sourceViewportIndex);
|
|
31
|
+
const targetSliceIndex = sourceSliceIndex + sliceDifference;
|
|
32
|
+
|
|
33
|
+
if (targetSliceIndex === tViewport.getSliceIndex()) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
utilities.jumpToSlice(tViewport.element, {
|
|
38
|
+
imageIndex: targetSliceIndex,
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const createFrameViewSynchronizer = (synchronizerName: string): Synchronizer => {
|
|
43
|
+
const synchronizer = SynchronizerManager.createSynchronizer(
|
|
44
|
+
synchronizerName,
|
|
45
|
+
EVENTS.STACK_VIEWPORT_SCROLL,
|
|
46
|
+
frameViewSyncCallback,
|
|
47
|
+
{ auxiliaryEvents: [{ name: EVENTS.CAMERA_MODIFIED, source: 'element' }] }
|
|
48
|
+
);
|
|
49
|
+
return synchronizer;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export { createFrameViewSynchronizer };
|