@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,2970 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getEnabledElement,
|
|
3
|
+
utilities as csUtils,
|
|
4
|
+
Types as CoreTypes,
|
|
5
|
+
getRenderingEngines,
|
|
6
|
+
} from '@cornerstonejs/core';
|
|
7
|
+
import {
|
|
8
|
+
ToolGroupManager,
|
|
9
|
+
Enums,
|
|
10
|
+
utilities as cstUtils,
|
|
11
|
+
annotation,
|
|
12
|
+
Types as ToolTypes,
|
|
13
|
+
SplineContourSegmentationTool,
|
|
14
|
+
cancelActiveManipulations,
|
|
15
|
+
} from '@cornerstonejs/tools';
|
|
16
|
+
import {
|
|
17
|
+
SegmentInfo,
|
|
18
|
+
LogicalOperation,
|
|
19
|
+
OperatorOptions,
|
|
20
|
+
} from '@cornerstonejs/tools/utilities/contourSegmentation/logicalOperators';
|
|
21
|
+
import * as cornerstoneTools from '@cornerstonejs/tools';
|
|
22
|
+
import * as labelmapInterpolation from '@cornerstonejs/labelmap-interpolation';
|
|
23
|
+
import { ONNXSegmentationController } from '@cornerstonejs/ai';
|
|
24
|
+
|
|
25
|
+
import { Types as OhifTypes, utils } from '@ohif/core';
|
|
26
|
+
import {
|
|
27
|
+
callInputDialogAutoComplete,
|
|
28
|
+
createReportAsync,
|
|
29
|
+
colorPickerDialog,
|
|
30
|
+
callInputDialog,
|
|
31
|
+
} from '@ohif/extension-default';
|
|
32
|
+
import toggleImageSliceSync from './utils/imageSliceSync/toggleImageSliceSync';
|
|
33
|
+
// Sanctioned flag read: RTSTRUCT contour hydration pins the referenced image to
|
|
34
|
+
// stack mode on the native ("next") path, a decision made before a target viewport exists.
|
|
35
|
+
import { getHydrationViewportTypeForModality } from './utils/nextViewportPolicies';
|
|
36
|
+
import { getFirstAnnotationSelected } from './utils/measurementServiceMappings/utils/selection';
|
|
37
|
+
import { getViewportEnabledElement } from './utils/getViewportEnabledElement';
|
|
38
|
+
import getActiveViewportEnabledElement from './utils/getActiveViewportEnabledElement';
|
|
39
|
+
import toggleVOISliceSync from './utils/toggleVOISliceSync';
|
|
40
|
+
import { findWindowLevelPreset } from './utils/findWindowLevelPreset';
|
|
41
|
+
import {
|
|
42
|
+
isStackViewportType,
|
|
43
|
+
isOrthographicViewportType,
|
|
44
|
+
isVolume3DViewportType,
|
|
45
|
+
isVolumeViewportType,
|
|
46
|
+
} from './utils/getLegacyViewportType';
|
|
47
|
+
import { viewportOperations as ops } from './services/ViewportService/backends/viewportOperations';
|
|
48
|
+
import { getViewportAdapter } from './services/ViewportService/adapter';
|
|
49
|
+
import {
|
|
50
|
+
usePositionPresentationStore,
|
|
51
|
+
useSegmentationPresentationStore,
|
|
52
|
+
useSelectedSegmentationsForViewportStore,
|
|
53
|
+
} from './stores';
|
|
54
|
+
import { toolNames } from './initCornerstoneTools';
|
|
55
|
+
import CornerstoneViewportDownloadForm from './utils/CornerstoneViewportDownloadForm';
|
|
56
|
+
import { updateSegmentBidirectionalStats } from './utils/updateSegmentationStats';
|
|
57
|
+
import { generateSegmentationCSVReport } from './utils/generateSegmentationCSVReport';
|
|
58
|
+
import { getUpdatedViewportsForSegmentation } from './utils/hydrationUtils';
|
|
59
|
+
import { loadDisplaySetData } from './utils/loadDisplaySetData';
|
|
60
|
+
import { SegmentationRepresentations } from '@cornerstonejs/tools/enums';
|
|
61
|
+
import { EasingFunctionEnum } from './utils/transitions';
|
|
62
|
+
import { createSegmentationForViewport } from './utils/createSegmentationForViewport';
|
|
63
|
+
import { utilities as segmentationUtilities } from '@cornerstonejs/tools/segmentation';
|
|
64
|
+
import i18n from '@ohif/i18n';
|
|
65
|
+
|
|
66
|
+
const { add, intersect, subtract, copy } = cstUtils.contourSegmentation;
|
|
67
|
+
|
|
68
|
+
const { DefaultHistoryMemo } = csUtils.HistoryMemo;
|
|
69
|
+
const toggleSyncFunctions = {
|
|
70
|
+
imageSlice: toggleImageSliceSync,
|
|
71
|
+
voi: toggleVOISliceSync,
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const { segmentation: segmentationUtils } = cstUtils;
|
|
75
|
+
|
|
76
|
+
const getLabelmapTools = ({ toolGroupService }) => {
|
|
77
|
+
const labelmapTools = [];
|
|
78
|
+
const toolGroupIds = toolGroupService.getToolGroupIds();
|
|
79
|
+
toolGroupIds.forEach(toolGroupId => {
|
|
80
|
+
const toolGroup = cornerstoneTools.ToolGroupManager.getToolGroup(toolGroupId);
|
|
81
|
+
const tools = toolGroup.getToolInstances();
|
|
82
|
+
// tools is an object with toolName as the key and tool as the value
|
|
83
|
+
Object.keys(tools).forEach(toolName => {
|
|
84
|
+
const tool = tools[toolName];
|
|
85
|
+
if (tool instanceof cornerstoneTools.LabelmapBaseTool) {
|
|
86
|
+
labelmapTools.push(tool);
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
return labelmapTools;
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
const getPreviewTools = ({ toolGroupService }) => {
|
|
94
|
+
const labelmapTools = getLabelmapTools({ toolGroupService });
|
|
95
|
+
|
|
96
|
+
const previewTools = labelmapTools.filter(tool => tool.acceptPreview || tool.rejectPreview);
|
|
97
|
+
|
|
98
|
+
return previewTools;
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
const segmentAI = new ONNXSegmentationController({
|
|
102
|
+
autoSegmentMode: true,
|
|
103
|
+
models: {
|
|
104
|
+
sam_b: [
|
|
105
|
+
{
|
|
106
|
+
name: 'sam-b-encoder',
|
|
107
|
+
url: 'https://huggingface.co/schmuell/sam-b-fp16/resolve/b64d0347d4d2cafd9a4e43b38853d6b5daa319fb/sam_vit_b_01ec64.encoder-fp16.onnx',
|
|
108
|
+
size: 180,
|
|
109
|
+
key: 'encoder',
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
name: 'sam-b-decoder',
|
|
113
|
+
url: 'https://huggingface.co/schmuell/sam-b-fp16/resolve/b64d0347d4d2cafd9a4e43b38853d6b5daa319fb/sam_vit_b_01ec64.decoder.onnx',
|
|
114
|
+
size: 17,
|
|
115
|
+
key: 'decoder',
|
|
116
|
+
},
|
|
117
|
+
],
|
|
118
|
+
},
|
|
119
|
+
modelName: 'sam_b',
|
|
120
|
+
});
|
|
121
|
+
let segmentAIEnabled = false;
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Converts a CSS color (hex or rgb/rgba string) to the { r, g, b, a }
|
|
125
|
+
* object shape the color picker dialog expects.
|
|
126
|
+
*/
|
|
127
|
+
function _cssColorToRgba(cssColor = ''): { r: number; g: number; b: number; a: number } {
|
|
128
|
+
const rgbMatch = cssColor.match(
|
|
129
|
+
/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*([\d.]+)\s*)?\)/
|
|
130
|
+
);
|
|
131
|
+
if (rgbMatch) {
|
|
132
|
+
return {
|
|
133
|
+
r: Number(rgbMatch[1]),
|
|
134
|
+
g: Number(rgbMatch[2]),
|
|
135
|
+
b: Number(rgbMatch[3]),
|
|
136
|
+
a: rgbMatch[4] !== undefined ? Number(rgbMatch[4]) : 1,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
return { r: 255, g: 255, b: 0, ...csUtils.color.hexToRgb(cssColor), a: 1 };
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function commandsModule({
|
|
143
|
+
servicesManager,
|
|
144
|
+
commandsManager,
|
|
145
|
+
extensionManager,
|
|
146
|
+
}: OhifTypes.Extensions.ExtensionParams): OhifTypes.Extensions.CommandsModule {
|
|
147
|
+
const {
|
|
148
|
+
viewportGridService,
|
|
149
|
+
toolbarService,
|
|
150
|
+
toolGroupService,
|
|
151
|
+
cineService,
|
|
152
|
+
uiDialogService,
|
|
153
|
+
cornerstoneViewportService,
|
|
154
|
+
uiNotificationService,
|
|
155
|
+
measurementService,
|
|
156
|
+
customizationService,
|
|
157
|
+
colorbarService,
|
|
158
|
+
hangingProtocolService,
|
|
159
|
+
syncGroupService,
|
|
160
|
+
segmentationService,
|
|
161
|
+
displaySetService,
|
|
162
|
+
} = servicesManager.services as AppTypes.Services;
|
|
163
|
+
|
|
164
|
+
function _getActiveViewportEnabledElement() {
|
|
165
|
+
return getActiveViewportEnabledElement(viewportGridService);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
function _getViewportEnabledElement(viewportId: string) {
|
|
169
|
+
return getViewportEnabledElement(viewportId);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// Resolves the cornerstone viewport for a command: the given viewport id, else the
|
|
173
|
+
// active one. Returns undefined when nothing is enabled.
|
|
174
|
+
function _resolveViewport(viewportId?: string) {
|
|
175
|
+
const enabledElement = viewportId
|
|
176
|
+
? _getViewportEnabledElement(viewportId)
|
|
177
|
+
: _getActiveViewportEnabledElement();
|
|
178
|
+
return enabledElement?.viewport;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function _getActiveViewportToolGroupId() {
|
|
182
|
+
const viewport = _getActiveViewportEnabledElement();
|
|
183
|
+
const toolGroup = viewport && toolGroupService.getToolGroupForViewport(viewport.id);
|
|
184
|
+
return toolGroup?.id;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function _usesPrimaryActivation(bindings) {
|
|
188
|
+
if (!bindings?.length) {
|
|
189
|
+
return true;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
return bindings.some(
|
|
193
|
+
binding =>
|
|
194
|
+
binding.mouseButton === Enums.MouseBindings.Primary &&
|
|
195
|
+
binding.modifierKey == null &&
|
|
196
|
+
binding.numTouchPoints == null
|
|
197
|
+
);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
function _getActiveSegmentationInfo() {
|
|
201
|
+
const viewportId = viewportGridService.getActiveViewportId();
|
|
202
|
+
const activeSegmentation = segmentationService.getActiveSegmentation(viewportId);
|
|
203
|
+
const segmentationId = activeSegmentation?.segmentationId;
|
|
204
|
+
const activeSegmentIndex = segmentationService.getActiveSegment(viewportId).segmentIndex;
|
|
205
|
+
|
|
206
|
+
return {
|
|
207
|
+
segmentationId,
|
|
208
|
+
segmentIndex: activeSegmentIndex,
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
function _handleBrushSizeAction(action: 'increase' | 'decrease') {
|
|
213
|
+
const toolGroupIds = toolGroupService.getToolGroupIds();
|
|
214
|
+
if (!toolGroupIds?.length) {
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
for (const toolGroupId of toolGroupIds) {
|
|
219
|
+
const brushSize = segmentationUtils.getBrushSizeForToolGroup(toolGroupId);
|
|
220
|
+
|
|
221
|
+
const newBrushSize = action === 'increase' ? brushSize + 3 : brushSize - 3;
|
|
222
|
+
|
|
223
|
+
if (brushSize) {
|
|
224
|
+
segmentationUtils.setBrushSizeForToolGroup(toolGroupId, newBrushSize);
|
|
225
|
+
|
|
226
|
+
toolbarService.refreshToolbarState({ toolGroupId });
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Creates a command function that sets a style property for segmentation types.
|
|
233
|
+
* If type is provided, sets the property for that type only.
|
|
234
|
+
* If type is not provided, sets the property for both Labelmap and Contour types.
|
|
235
|
+
* @param propertyName - The name of the style property to set
|
|
236
|
+
* @returns A command function that takes { type, value }
|
|
237
|
+
*/
|
|
238
|
+
const createSetStyleCommand = (propertyName: string) => {
|
|
239
|
+
return ({ type, value }) => {
|
|
240
|
+
const { segmentationService } = servicesManager.services;
|
|
241
|
+
if (type) {
|
|
242
|
+
segmentationService.setStyle({ type }, { [propertyName]: value });
|
|
243
|
+
} else {
|
|
244
|
+
segmentationService.setStyle(
|
|
245
|
+
{ type: SegmentationRepresentations.Labelmap },
|
|
246
|
+
{ [propertyName]: value }
|
|
247
|
+
);
|
|
248
|
+
segmentationService.setStyle(
|
|
249
|
+
{ type: SegmentationRepresentations.Contour },
|
|
250
|
+
{ [propertyName]: value }
|
|
251
|
+
);
|
|
252
|
+
}
|
|
253
|
+
};
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
const actions = {
|
|
257
|
+
jumpToMeasurementViewport: ({ annotationUID, measurement }) => {
|
|
258
|
+
cornerstoneTools.annotation.selection.setAnnotationSelected(annotationUID, true);
|
|
259
|
+
const { metadata } = measurement;
|
|
260
|
+
|
|
261
|
+
const activeViewportId = viewportGridService.getActiveViewportId();
|
|
262
|
+
// Finds the best viewport to jump to for showing the annotation view reference
|
|
263
|
+
// This may be different from active if there is a viewport already showing the display set.
|
|
264
|
+
const viewportId = cornerstoneViewportService.findNavigationCompatibleViewportId(
|
|
265
|
+
activeViewportId,
|
|
266
|
+
metadata
|
|
267
|
+
);
|
|
268
|
+
if (viewportId) {
|
|
269
|
+
const viewport = cornerstoneViewportService.getCornerstoneViewport(viewportId);
|
|
270
|
+
viewport.setViewReference(metadata);
|
|
271
|
+
viewport.render();
|
|
272
|
+
|
|
273
|
+
// If the measurement is not visible inside the current viewport, move the
|
|
274
|
+
// camera to it. The operations backend handles the lane: legacy re-centers
|
|
275
|
+
// in-plane (getCamera/setCamera), native skips it (no in-plane pan yet, CS-14)
|
|
276
|
+
// since setViewReference above already navigated to the measurement's slice.
|
|
277
|
+
if (ops.centerOnMeasurement(viewport, measurement)) {
|
|
278
|
+
viewport.render();
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
const { displaySetInstanceUID: referencedDisplaySetInstanceUID } = measurement;
|
|
285
|
+
if (!referencedDisplaySetInstanceUID) {
|
|
286
|
+
console.warn('ViewportGrid::No display set found in', measurement);
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
// Finds the viewport to update to show the given displayset/orientation.
|
|
291
|
+
// This will choose a view already containing the measurement display set
|
|
292
|
+
// if possible, otherwise will fallback to the active.
|
|
293
|
+
const viewportToUpdate = cornerstoneViewportService.findUpdateableViewportConfiguration(
|
|
294
|
+
activeViewportId,
|
|
295
|
+
measurement
|
|
296
|
+
);
|
|
297
|
+
|
|
298
|
+
if (!viewportToUpdate) {
|
|
299
|
+
console.warn('Unable to find a viewport to show this in');
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
const updatedViewports = hangingProtocolService.getViewportsRequireUpdate(
|
|
303
|
+
viewportToUpdate.viewportId,
|
|
304
|
+
referencedDisplaySetInstanceUID
|
|
305
|
+
);
|
|
306
|
+
|
|
307
|
+
if (!updatedViewports?.[0]) {
|
|
308
|
+
console.warn(
|
|
309
|
+
'ViewportGrid::Unable to navigate to viewport containing',
|
|
310
|
+
referencedDisplaySetInstanceUID
|
|
311
|
+
);
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
updatedViewports[0].viewportOptions = viewportToUpdate.viewportOptions;
|
|
316
|
+
|
|
317
|
+
// Update stored position presentation
|
|
318
|
+
commandsManager.run('updateStoredPositionPresentation', {
|
|
319
|
+
viewportId: viewportToUpdate.viewportId,
|
|
320
|
+
displaySetInstanceUIDs: [referencedDisplaySetInstanceUID],
|
|
321
|
+
referencedImageId: measurement.referencedImageId,
|
|
322
|
+
options: {
|
|
323
|
+
...measurement.metadata,
|
|
324
|
+
},
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
commandsManager.run('setDisplaySetsForViewports', { viewportsToUpdate: updatedViewports });
|
|
328
|
+
},
|
|
329
|
+
|
|
330
|
+
/**
|
|
331
|
+
* Cancels any in-progress annotation manipulation (e.g. drawing a Spline,
|
|
332
|
+
* Livewire or PlanarFreehand contour) on the active viewport. Reached on
|
|
333
|
+
* Escape via the `cancelActiveOperation` command. `cancelActiveManipulations`
|
|
334
|
+
* invokes the `cancel` method of each active/passive tool that has an
|
|
335
|
+
* in-progress annotation, so it is a no-op when nothing is being drawn.
|
|
336
|
+
*/
|
|
337
|
+
cancelMeasurement: () => {
|
|
338
|
+
const element = _getActiveViewportEnabledElement()?.viewport?.element;
|
|
339
|
+
if (element) {
|
|
340
|
+
cancelActiveManipulations(element);
|
|
341
|
+
}
|
|
342
|
+
},
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* Loads a display set's data without reference to a viewport.
|
|
346
|
+
*
|
|
347
|
+
* The viewport-independent counterpart to displaying it: this makes the data
|
|
348
|
+
* available (for a segmentation, present in the segmentation state), while
|
|
349
|
+
* where it is shown remains a separate decision. Loading is memoized per
|
|
350
|
+
* display set, so calling this early or more than once is free.
|
|
351
|
+
*/
|
|
352
|
+
loadDisplaySetData: async ({ displaySet, displaySetInstanceUID }) => {
|
|
353
|
+
const displaySetToLoad =
|
|
354
|
+
displaySet ?? displaySetService.getDisplaySetByUID(displaySetInstanceUID);
|
|
355
|
+
|
|
356
|
+
if (!displaySetToLoad) {
|
|
357
|
+
return;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
await loadDisplaySetData(displaySetToLoad, servicesManager);
|
|
361
|
+
},
|
|
362
|
+
|
|
363
|
+
hydrateSecondaryDisplaySet: async ({ displaySet, viewportId }) => {
|
|
364
|
+
if (!displaySet) {
|
|
365
|
+
return;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
const viewport = cornerstoneViewportService.getCornerstoneViewport(viewportId);
|
|
369
|
+
|
|
370
|
+
if (displaySet.isOverlayDisplaySet) {
|
|
371
|
+
// update the previously stored segmentationPresentation with the new viewportId
|
|
372
|
+
// presentation so that when we put the referencedDisplaySet back in the viewport
|
|
373
|
+
// it will have the correct segmentation representation hydrated
|
|
374
|
+
|
|
375
|
+
// Recorded as a hint only: _setSegmentationPresentation corrects
|
|
376
|
+
// Labelmap <-> Surface against the viewport that actually renders it,
|
|
377
|
+
// so this does not have to be resolved against a viewport here.
|
|
378
|
+
const segmentationType =
|
|
379
|
+
// Todo: check if PMAP modality should be handled such as SEG
|
|
380
|
+
displaySet.Modality !== 'SEG'
|
|
381
|
+
? SegmentationRepresentations.Contour
|
|
382
|
+
: viewport && isVolume3DViewportType(viewport)
|
|
383
|
+
? SegmentationRepresentations.Surface
|
|
384
|
+
: SegmentationRepresentations.Labelmap;
|
|
385
|
+
|
|
386
|
+
commandsManager.runCommand('updateStoredSegmentationPresentation', {
|
|
387
|
+
displaySet,
|
|
388
|
+
type: segmentationType,
|
|
389
|
+
});
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
// isHydrated means "display this display set as part of a standard view".
|
|
393
|
+
// That is decided here and does not depend on a viewport existing yet.
|
|
394
|
+
displaySet.isHydrated = true;
|
|
395
|
+
|
|
396
|
+
const referencedDisplaySetInstanceUID = displaySet.referencedDisplaySetInstanceUID;
|
|
397
|
+
|
|
398
|
+
const storePositionPresentation = refDisplaySet => {
|
|
399
|
+
// update the previously stored positionPresentation with the new viewportId
|
|
400
|
+
// presentation so that when we put the referencedDisplaySet back in the viewport
|
|
401
|
+
// it will be in the correct position zoom and pan
|
|
402
|
+
commandsManager.runCommand('updateStoredPositionPresentation', {
|
|
403
|
+
viewportId,
|
|
404
|
+
displaySetInstanceUIDs: [refDisplaySet.displaySetInstanceUID],
|
|
405
|
+
});
|
|
406
|
+
};
|
|
407
|
+
|
|
408
|
+
if (displaySet.Modality === 'SEG' || displaySet.Modality === 'RTSTRUCT') {
|
|
409
|
+
const referencedDisplaySet = displaySetService.getDisplaySetByUID(
|
|
410
|
+
referencedDisplaySetInstanceUID
|
|
411
|
+
);
|
|
412
|
+
storePositionPresentation(referencedDisplaySet);
|
|
413
|
+
|
|
414
|
+
const results = commandsManager.runCommand('loadSegmentationDisplaySetsForViewport', {
|
|
415
|
+
viewportId,
|
|
416
|
+
displaySetInstanceUIDs: [referencedDisplaySet.displaySetInstanceUID],
|
|
417
|
+
derivedDisplaySetInstanceUID: displaySet.displaySetInstanceUID,
|
|
418
|
+
// RTSTRUCT-on-next pins the referenced image to stack mode on hydrate;
|
|
419
|
+
// see the policy's rationale in utils/nextViewportPolicies.
|
|
420
|
+
viewportType: getHydrationViewportTypeForModality(displaySet.Modality),
|
|
421
|
+
});
|
|
422
|
+
|
|
423
|
+
const disableEditing = customizationService.getCustomization(
|
|
424
|
+
'panelSegmentation.disableEditing'
|
|
425
|
+
);
|
|
426
|
+
if (disableEditing) {
|
|
427
|
+
// Locking is a property of the segmentation, not of a per-viewport
|
|
428
|
+
// representation. Reading the segments from the representations would
|
|
429
|
+
// silently skip locking whenever hydration ran before the viewport
|
|
430
|
+
// had one.
|
|
431
|
+
const segmentationId = displaySet.displaySetInstanceUID;
|
|
432
|
+
const segmentation = segmentationService.getSegmentation(segmentationId);
|
|
433
|
+
|
|
434
|
+
Object.keys(segmentation?.segments ?? {}).forEach(segmentIndex => {
|
|
435
|
+
segmentationService.setSegmentLocked(segmentationId, parseInt(segmentIndex), true);
|
|
436
|
+
});
|
|
437
|
+
}
|
|
438
|
+
return results;
|
|
439
|
+
} else if (displaySet.Modality === 'SR') {
|
|
440
|
+
const results = commandsManager.runCommand('hydrateStructuredReport', {
|
|
441
|
+
displaySetInstanceUID: displaySet.displaySetInstanceUID,
|
|
442
|
+
});
|
|
443
|
+
const { SeriesInstanceUIDs } = results;
|
|
444
|
+
const referencedDisplaySets = displaySetService.getDisplaySetsForSeries(
|
|
445
|
+
SeriesInstanceUIDs[0]
|
|
446
|
+
);
|
|
447
|
+
referencedDisplaySets.forEach(storePositionPresentation);
|
|
448
|
+
|
|
449
|
+
if (referencedDisplaySets.length) {
|
|
450
|
+
actions.setDisplaySetsForViewports({
|
|
451
|
+
viewportsToUpdate: [
|
|
452
|
+
{
|
|
453
|
+
viewportId: viewportGridService.getActiveViewportId(),
|
|
454
|
+
displaySetInstanceUIDs: [referencedDisplaySets[0].displaySetInstanceUID],
|
|
455
|
+
},
|
|
456
|
+
],
|
|
457
|
+
});
|
|
458
|
+
}
|
|
459
|
+
return results;
|
|
460
|
+
}
|
|
461
|
+
},
|
|
462
|
+
runSegmentBidirectional: async ({ segmentationId, segmentIndex } = {}) => {
|
|
463
|
+
// Get active segmentation if not specified
|
|
464
|
+
const targetSegmentation =
|
|
465
|
+
segmentationId && segmentIndex
|
|
466
|
+
? { segmentationId, segmentIndex }
|
|
467
|
+
: _getActiveSegmentationInfo();
|
|
468
|
+
|
|
469
|
+
const { segmentationId: targetId, segmentIndex: targetIndex } = targetSegmentation;
|
|
470
|
+
|
|
471
|
+
// Check if the segment has voxels before computing bidirectional measurement
|
|
472
|
+
const uniqueSegmentIndices = cstUtils.segmentation.getUniqueSegmentIndices(targetId);
|
|
473
|
+
const hasVoxels = uniqueSegmentIndices.includes(targetIndex);
|
|
474
|
+
|
|
475
|
+
if (!hasVoxels) {
|
|
476
|
+
uiNotificationService.show({
|
|
477
|
+
title: i18n.t('SegmentationPanel:Segment Bidirectional'),
|
|
478
|
+
message: i18n.t(
|
|
479
|
+
'SegmentationPanel:Draw a segment before using bidirectional measurement'
|
|
480
|
+
),
|
|
481
|
+
type: 'warning',
|
|
482
|
+
});
|
|
483
|
+
return;
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
// Get bidirectional measurement data
|
|
487
|
+
const bidirectionalData = await cstUtils.segmentation.getSegmentLargestBidirectional({
|
|
488
|
+
segmentationId: targetId,
|
|
489
|
+
segmentIndices: [targetIndex],
|
|
490
|
+
});
|
|
491
|
+
|
|
492
|
+
if (!bidirectionalData.length) {
|
|
493
|
+
return;
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
const activeViewportId = viewportGridService.getActiveViewportId();
|
|
497
|
+
|
|
498
|
+
// Process each bidirectional measurement
|
|
499
|
+
bidirectionalData.forEach(measurement => {
|
|
500
|
+
const { segmentIndex, majorAxis, minorAxis } = measurement;
|
|
501
|
+
|
|
502
|
+
// Create annotation
|
|
503
|
+
const annotation = cornerstoneTools.SegmentBidirectionalTool.hydrate(
|
|
504
|
+
activeViewportId,
|
|
505
|
+
[majorAxis, minorAxis],
|
|
506
|
+
{
|
|
507
|
+
segmentIndex,
|
|
508
|
+
segmentationId: targetId,
|
|
509
|
+
}
|
|
510
|
+
);
|
|
511
|
+
|
|
512
|
+
measurement.annotationUID = annotation.annotationUID;
|
|
513
|
+
|
|
514
|
+
// Update segmentation stats
|
|
515
|
+
const updatedSegmentation = updateSegmentBidirectionalStats({
|
|
516
|
+
segmentationId: targetId,
|
|
517
|
+
segmentIndex: targetIndex,
|
|
518
|
+
bidirectionalData: measurement,
|
|
519
|
+
segmentationService,
|
|
520
|
+
annotation,
|
|
521
|
+
});
|
|
522
|
+
|
|
523
|
+
// Save changes if needed
|
|
524
|
+
if (updatedSegmentation) {
|
|
525
|
+
segmentationService.addOrUpdateSegmentation({
|
|
526
|
+
segmentationId: targetId,
|
|
527
|
+
segments: updatedSegmentation.segments,
|
|
528
|
+
});
|
|
529
|
+
}
|
|
530
|
+
});
|
|
531
|
+
|
|
532
|
+
// get the active segmentIndex bidirectional annotation and jump to it
|
|
533
|
+
const activeBidirectional = bidirectionalData.find(
|
|
534
|
+
measurement => measurement.segmentIndex === targetIndex
|
|
535
|
+
);
|
|
536
|
+
commandsManager.run('jumpToMeasurement', {
|
|
537
|
+
uid: activeBidirectional?.annotationUID,
|
|
538
|
+
});
|
|
539
|
+
},
|
|
540
|
+
interpolateLabelmap: () => {
|
|
541
|
+
const { segmentationId, segmentIndex } = _getActiveSegmentationInfo();
|
|
542
|
+
labelmapInterpolation.interpolate({
|
|
543
|
+
segmentationId,
|
|
544
|
+
segmentIndex,
|
|
545
|
+
});
|
|
546
|
+
},
|
|
547
|
+
/**
|
|
548
|
+
* Generates the selector props for the context menu, specific to
|
|
549
|
+
* the cornerstone viewport, and then runs the context menu.
|
|
550
|
+
*/
|
|
551
|
+
showCornerstoneContextMenu: options => {
|
|
552
|
+
const element = _getActiveViewportEnabledElement()?.viewport?.element;
|
|
553
|
+
|
|
554
|
+
const optionsToUse = { ...options, element };
|
|
555
|
+
const { useSelectedAnnotation, nearbyToolData, event } = optionsToUse;
|
|
556
|
+
|
|
557
|
+
// This code is used to invoke the context menu via keyboard shortcuts
|
|
558
|
+
if (useSelectedAnnotation && !nearbyToolData) {
|
|
559
|
+
const firstAnnotationSelected = getFirstAnnotationSelected(element);
|
|
560
|
+
// filter by allowed selected tools from config property (if there is any)
|
|
561
|
+
const isToolAllowed =
|
|
562
|
+
!optionsToUse.allowedSelectedTools ||
|
|
563
|
+
optionsToUse.allowedSelectedTools.includes(firstAnnotationSelected?.metadata?.toolName);
|
|
564
|
+
if (isToolAllowed) {
|
|
565
|
+
optionsToUse.nearbyToolData = firstAnnotationSelected;
|
|
566
|
+
} else {
|
|
567
|
+
return;
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
optionsToUse.defaultPointsPosition = [];
|
|
572
|
+
// if (optionsToUse.nearbyToolData) {
|
|
573
|
+
// optionsToUse.defaultPointsPosition = commandsManager.runCommand(
|
|
574
|
+
// 'getToolDataActiveCanvasPoints',
|
|
575
|
+
// { toolData: optionsToUse.nearbyToolData }
|
|
576
|
+
// );
|
|
577
|
+
// }
|
|
578
|
+
|
|
579
|
+
// TODO - make the selectorProps richer by including the study metadata and display set.
|
|
580
|
+
optionsToUse.selectorProps = {
|
|
581
|
+
toolName: optionsToUse.nearbyToolData?.metadata?.toolName,
|
|
582
|
+
value: optionsToUse.nearbyToolData,
|
|
583
|
+
uid: optionsToUse.nearbyToolData?.annotationUID,
|
|
584
|
+
nearbyToolData: optionsToUse.nearbyToolData,
|
|
585
|
+
event,
|
|
586
|
+
...optionsToUse.selectorProps,
|
|
587
|
+
};
|
|
588
|
+
|
|
589
|
+
commandsManager.run(options, optionsToUse);
|
|
590
|
+
},
|
|
591
|
+
/**
|
|
592
|
+
* Records the desired presentation of a derived (SEG/RTSTRUCT) display set
|
|
593
|
+
* against the display set it references.
|
|
594
|
+
*
|
|
595
|
+
* @param props.hydrated - true to display it in the standard viewports for
|
|
596
|
+
* the referenced display set, false to stop displaying it there. Writing
|
|
597
|
+
* false matters: the store is the desired state a viewport converges on,
|
|
598
|
+
* so simply omitting an entry would let an earlier `true` keep restoring
|
|
599
|
+
* a segmentation that was removed.
|
|
600
|
+
*/
|
|
601
|
+
updateStoredSegmentationPresentation: ({ displaySet, type, hydrated = true }) => {
|
|
602
|
+
const {
|
|
603
|
+
addSegmentationPresentationItem,
|
|
604
|
+
setHydrationForSegmentation,
|
|
605
|
+
segmentationPresentationStore,
|
|
606
|
+
} = useSegmentationPresentationStore.getState();
|
|
607
|
+
|
|
608
|
+
const referencedDisplaySetInstanceUID = displaySet.referencedDisplaySetInstanceUID;
|
|
609
|
+
const segmentationId = displaySet.displaySetInstanceUID;
|
|
610
|
+
|
|
611
|
+
// The store is keyed by the referenced display set, so there is no key to
|
|
612
|
+
// create an entry under without one - segmentations created in the client
|
|
613
|
+
// (see the SEGMENTATION_ADDED handler) have no referenced display set,
|
|
614
|
+
// and writing them would land every one of them under a single
|
|
615
|
+
// `undefined` key.
|
|
616
|
+
//
|
|
617
|
+
// They are still recorded, though: storePresentation records a
|
|
618
|
+
// client-drawn segmentation as hydrated under the key of whatever
|
|
619
|
+
// viewport it was drawn in (see _getInitialHydrationForSync), and that
|
|
620
|
+
// record is what re-adds it on the next mount. Nothing else supersedes it
|
|
621
|
+
// - syncSegmentationPresentation only ever merges - so a removal has to
|
|
622
|
+
// update it in place wherever it was written, or a segmentation the user
|
|
623
|
+
// dismissed or deleted comes back.
|
|
624
|
+
if (!referencedDisplaySetInstanceUID) {
|
|
625
|
+
setHydrationForSegmentation(segmentationId, { hydrated, type });
|
|
626
|
+
return;
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
// A caller that only changes hydration (removing the layer) has no reason
|
|
630
|
+
// to know the representation type, so keep whatever hydration recorded.
|
|
631
|
+
const existingType = segmentationPresentationStore[referencedDisplaySetInstanceUID]?.find(
|
|
632
|
+
item => item.segmentationId === segmentationId
|
|
633
|
+
)?.type;
|
|
634
|
+
|
|
635
|
+
addSegmentationPresentationItem(referencedDisplaySetInstanceUID, {
|
|
636
|
+
segmentationId,
|
|
637
|
+
hydrated,
|
|
638
|
+
type: type ?? existingType,
|
|
639
|
+
});
|
|
640
|
+
},
|
|
641
|
+
|
|
642
|
+
/** Stores the changed position presentation */
|
|
643
|
+
updateStoredPositionPresentation: ({
|
|
644
|
+
viewportId,
|
|
645
|
+
displaySetInstanceUIDs,
|
|
646
|
+
referencedImageId,
|
|
647
|
+
options,
|
|
648
|
+
}) => {
|
|
649
|
+
const presentations = cornerstoneViewportService.getPresentations(viewportId);
|
|
650
|
+
const { positionPresentationStore, setPositionPresentation, getPositionPresentationId } =
|
|
651
|
+
usePositionPresentationStore.getState();
|
|
652
|
+
|
|
653
|
+
// Look inside positionPresentationStore and find the key that includes ALL the displaySetInstanceUIDs
|
|
654
|
+
// and the value has viewportId as activeViewportId.
|
|
655
|
+
let previousReferencedDisplaySetStoreKey;
|
|
656
|
+
|
|
657
|
+
if (
|
|
658
|
+
displaySetInstanceUIDs &&
|
|
659
|
+
Array.isArray(displaySetInstanceUIDs) &&
|
|
660
|
+
displaySetInstanceUIDs.length > 0
|
|
661
|
+
) {
|
|
662
|
+
previousReferencedDisplaySetStoreKey = Object.entries(positionPresentationStore).find(
|
|
663
|
+
([key, value]) => {
|
|
664
|
+
return (
|
|
665
|
+
displaySetInstanceUIDs.every(uid => key.includes(uid)) &&
|
|
666
|
+
value?.viewportId === viewportId
|
|
667
|
+
);
|
|
668
|
+
}
|
|
669
|
+
)?.[0];
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
// Create presentation data with referencedImageId and options if provided
|
|
673
|
+
const presentationData =
|
|
674
|
+
referencedImageId || options?.FrameOfReferenceUID
|
|
675
|
+
? {
|
|
676
|
+
...presentations.positionPresentation,
|
|
677
|
+
viewReference: {
|
|
678
|
+
referencedImageId,
|
|
679
|
+
...options,
|
|
680
|
+
},
|
|
681
|
+
}
|
|
682
|
+
: presentations.positionPresentation;
|
|
683
|
+
|
|
684
|
+
// With no live viewport there is no position to record - getPresentations
|
|
685
|
+
// returns an object whose positionPresentation is undefined. Writing that
|
|
686
|
+
// would clobber the referenced series' stored slice/pan/zoom with
|
|
687
|
+
// undefined, which matters now that hydration runs without a viewport.
|
|
688
|
+
if (!presentationData) {
|
|
689
|
+
return;
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
if (previousReferencedDisplaySetStoreKey) {
|
|
693
|
+
setPositionPresentation(previousReferencedDisplaySetStoreKey, presentationData);
|
|
694
|
+
return;
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
// if not found means we have not visited that referencedDisplaySetInstanceUID before
|
|
698
|
+
// so we need to grab the positionPresentationId directly from the store,
|
|
699
|
+
// Todo: this is really hacky, we should have a better way for this
|
|
700
|
+
const positionPresentationId = getPositionPresentationId({
|
|
701
|
+
displaySetInstanceUIDs,
|
|
702
|
+
viewportId,
|
|
703
|
+
});
|
|
704
|
+
|
|
705
|
+
setPositionPresentation(positionPresentationId, presentationData);
|
|
706
|
+
},
|
|
707
|
+
getNearbyToolData({ nearbyToolData, element, canvasCoordinates }) {
|
|
708
|
+
return nearbyToolData ?? cstUtils.getAnnotationNearPoint(element, canvasCoordinates);
|
|
709
|
+
},
|
|
710
|
+
getNearbyAnnotation({ element, canvasCoordinates }) {
|
|
711
|
+
const nearbyToolData = actions.getNearbyToolData({
|
|
712
|
+
nearbyToolData: null,
|
|
713
|
+
element,
|
|
714
|
+
canvasCoordinates,
|
|
715
|
+
});
|
|
716
|
+
|
|
717
|
+
const isAnnotation = toolName => {
|
|
718
|
+
const enabledElement = getEnabledElement(element);
|
|
719
|
+
|
|
720
|
+
if (!enabledElement) {
|
|
721
|
+
return;
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
const { renderingEngineId, viewportId } = enabledElement;
|
|
725
|
+
const toolGroup = ToolGroupManager.getToolGroupForViewport(viewportId, renderingEngineId);
|
|
726
|
+
|
|
727
|
+
const toolInstance = toolGroup.getToolInstance(toolName);
|
|
728
|
+
|
|
729
|
+
return toolInstance?.constructor?.isAnnotation ?? true;
|
|
730
|
+
};
|
|
731
|
+
|
|
732
|
+
return nearbyToolData?.metadata?.toolName && isAnnotation(nearbyToolData.metadata.toolName)
|
|
733
|
+
? nearbyToolData
|
|
734
|
+
: null;
|
|
735
|
+
},
|
|
736
|
+
/**
|
|
737
|
+
* Common logic for handling measurement label updates through dialog
|
|
738
|
+
* @param uid - measurement uid
|
|
739
|
+
* @returns Promise that resolves when the label is updated
|
|
740
|
+
*/
|
|
741
|
+
_handleMeasurementLabelDialog: async uid => {
|
|
742
|
+
const labelConfig = customizationService.getCustomization('measurementLabels');
|
|
743
|
+
const renderContent = customizationService.getCustomization('ui.labellingComponent');
|
|
744
|
+
const measurement = measurementService.getMeasurement(uid);
|
|
745
|
+
|
|
746
|
+
if (!measurement) {
|
|
747
|
+
console.debug('No measurement found for label editing');
|
|
748
|
+
return;
|
|
749
|
+
}
|
|
750
|
+
|
|
751
|
+
if (!labelConfig) {
|
|
752
|
+
const label = await callInputDialog({
|
|
753
|
+
uiDialogService,
|
|
754
|
+
title: i18n.t('Tools:Edit Measurement Label'),
|
|
755
|
+
placeholder: measurement.label || i18n.t('Tools:Enter new label'),
|
|
756
|
+
defaultValue: measurement.label,
|
|
757
|
+
});
|
|
758
|
+
|
|
759
|
+
if (label !== undefined && label !== null) {
|
|
760
|
+
measurementService.update(uid, { ...measurement, label }, true);
|
|
761
|
+
}
|
|
762
|
+
return;
|
|
763
|
+
}
|
|
764
|
+
|
|
765
|
+
const val = await callInputDialogAutoComplete({
|
|
766
|
+
measurement,
|
|
767
|
+
uiDialogService,
|
|
768
|
+
labelConfig,
|
|
769
|
+
renderContent,
|
|
770
|
+
});
|
|
771
|
+
|
|
772
|
+
if (val !== undefined && val !== null) {
|
|
773
|
+
measurementService.update(uid, { ...measurement, label: val }, true);
|
|
774
|
+
}
|
|
775
|
+
},
|
|
776
|
+
/**
|
|
777
|
+
* Show the measurement labelling input dialog and update the label
|
|
778
|
+
* on the measurement with a response if not cancelled.
|
|
779
|
+
*/
|
|
780
|
+
setMeasurementLabel: async ({ uid }) => {
|
|
781
|
+
await actions._handleMeasurementLabelDialog(uid);
|
|
782
|
+
},
|
|
783
|
+
renameMeasurement: async ({ uid }) => {
|
|
784
|
+
await actions._handleMeasurementLabelDialog(uid);
|
|
785
|
+
},
|
|
786
|
+
/**
|
|
787
|
+
*
|
|
788
|
+
* @param props - containing the updates to apply
|
|
789
|
+
* @param props.measurementKey - chooses the measurement key to apply the
|
|
790
|
+
* code to. This will typically be finding or site to apply a
|
|
791
|
+
* finding code or a findingSites code.
|
|
792
|
+
* @param props.code - A coding scheme value from DICOM, including:
|
|
793
|
+
* * CodeValue - the language independent code, for example '1234'
|
|
794
|
+
* * CodingSchemeDesignator - the issue of the code value
|
|
795
|
+
* * CodeMeaning - the text value shown to the user
|
|
796
|
+
* * ref - a string reference in the form `<designator>:<codeValue>`
|
|
797
|
+
* * type - defaulting to 'finding'. Will replace other codes of same type
|
|
798
|
+
* * style - a styling object to use
|
|
799
|
+
* * Other fields
|
|
800
|
+
* Note it is a valid option to remove the finding or site values by
|
|
801
|
+
* supplying null for the code.
|
|
802
|
+
* @param props.uid - the measurement UID to find it with
|
|
803
|
+
* @param props.label - the text value for the code. Has NOTHING to do with
|
|
804
|
+
* the measurement label, which can be set with textLabel
|
|
805
|
+
* @param props.textLabel is the measurement label to apply. Set to null to
|
|
806
|
+
* delete.
|
|
807
|
+
*
|
|
808
|
+
* If the measurementKey is `site`, then the code will also be added/replace
|
|
809
|
+
* the 0 element of findingSites. This behaviour is expected to be enhanced
|
|
810
|
+
* in the future with ability to set other site information.
|
|
811
|
+
*/
|
|
812
|
+
updateMeasurement: props => {
|
|
813
|
+
const { code, uid, textLabel, label } = props;
|
|
814
|
+
let { style } = props;
|
|
815
|
+
const measurement = measurementService.getMeasurement(uid);
|
|
816
|
+
if (!measurement) {
|
|
817
|
+
console.warn('No measurement found to update', uid);
|
|
818
|
+
return;
|
|
819
|
+
}
|
|
820
|
+
const updatedMeasurement = {
|
|
821
|
+
...measurement,
|
|
822
|
+
};
|
|
823
|
+
// Call it textLabel as the label value
|
|
824
|
+
// TODO - remove the label setting when direct rendering of findingSites is enabled
|
|
825
|
+
if (textLabel !== undefined) {
|
|
826
|
+
updatedMeasurement.label = textLabel;
|
|
827
|
+
}
|
|
828
|
+
if (code !== undefined) {
|
|
829
|
+
const measurementKey = code.type || 'finding';
|
|
830
|
+
|
|
831
|
+
if (code.ref && !code.CodeValue) {
|
|
832
|
+
const split = code.ref.indexOf(':');
|
|
833
|
+
code.CodeValue = code.ref.substring(split + 1);
|
|
834
|
+
code.CodeMeaning = code.text || label;
|
|
835
|
+
code.CodingSchemeDesignator = code.ref.substring(0, split);
|
|
836
|
+
}
|
|
837
|
+
updatedMeasurement[measurementKey] = code;
|
|
838
|
+
if (measurementKey !== 'finding') {
|
|
839
|
+
if (updatedMeasurement.findingSites) {
|
|
840
|
+
updatedMeasurement.findingSites = updatedMeasurement.findingSites.filter(
|
|
841
|
+
it => it.type !== measurementKey
|
|
842
|
+
);
|
|
843
|
+
updatedMeasurement.findingSites.push(code);
|
|
844
|
+
} else {
|
|
845
|
+
updatedMeasurement.findingSites = [code];
|
|
846
|
+
}
|
|
847
|
+
}
|
|
848
|
+
}
|
|
849
|
+
|
|
850
|
+
style ||= updatedMeasurement.finding?.style;
|
|
851
|
+
style ||= updatedMeasurement.findingSites?.find(site => site?.style)?.style;
|
|
852
|
+
|
|
853
|
+
if (style) {
|
|
854
|
+
// Reset the selected values to preserve appearance on selection
|
|
855
|
+
style.lineDashSelected ||= style.lineDash;
|
|
856
|
+
annotation.config.style.setAnnotationStyles(measurement.uid, style);
|
|
857
|
+
|
|
858
|
+
// this is a bit ugly, but given the underlying behavior, this is how it needs to work.
|
|
859
|
+
switch (measurement.toolName) {
|
|
860
|
+
case toolNames.PlanarFreehandROI: {
|
|
861
|
+
const targetAnnotation = annotation.state.getAnnotation(measurement.uid);
|
|
862
|
+
targetAnnotation.data.isOpenUShapeContour = !!style.isOpenUShapeContour;
|
|
863
|
+
break;
|
|
864
|
+
}
|
|
865
|
+
default:
|
|
866
|
+
break;
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
measurementService.update(updatedMeasurement.uid, updatedMeasurement, true);
|
|
870
|
+
},
|
|
871
|
+
|
|
872
|
+
/**
|
|
873
|
+
* Opens a color picker for the measurement and applies the chosen color
|
|
874
|
+
* to the annotation (and its text box) via per-annotation styles.
|
|
875
|
+
*/
|
|
876
|
+
changeMeasurementColor: ({ uid }) => {
|
|
877
|
+
const measurement = measurementService.getMeasurement(uid);
|
|
878
|
+
if (!measurement) {
|
|
879
|
+
console.warn('No measurement found to change color', uid);
|
|
880
|
+
return;
|
|
881
|
+
}
|
|
882
|
+
|
|
883
|
+
const currentColor = annotation.config.style.getStyleProperty('color', {
|
|
884
|
+
annotationUID: uid,
|
|
885
|
+
toolName: measurement.toolName,
|
|
886
|
+
});
|
|
887
|
+
|
|
888
|
+
uiDialogService.show({
|
|
889
|
+
content: colorPickerDialog,
|
|
890
|
+
title: i18n.t('Tools:Measurement Color'),
|
|
891
|
+
contentProps: {
|
|
892
|
+
value: _cssColorToRgba(currentColor),
|
|
893
|
+
onSave: newRgbaColor => {
|
|
894
|
+
const { r, g, b, a = 1 } = newRgbaColor;
|
|
895
|
+
const cssColor = `rgba(${r}, ${g}, ${b}, ${a})`;
|
|
896
|
+
// updateMeasurement replaces the annotation styles and sets the contour shape from them
|
|
897
|
+
actions.updateMeasurement({
|
|
898
|
+
uid,
|
|
899
|
+
style: {
|
|
900
|
+
...annotation.config.style.getAnnotationToolStyles(uid),
|
|
901
|
+
isOpenUShapeContour: annotation.state.getAnnotation(uid)?.data?.isOpenUShapeContour,
|
|
902
|
+
color: cssColor,
|
|
903
|
+
colorHighlighted: cssColor,
|
|
904
|
+
colorSelected: cssColor,
|
|
905
|
+
colorLocked: cssColor,
|
|
906
|
+
textBoxColor: cssColor,
|
|
907
|
+
textBoxColorHighlighted: cssColor,
|
|
908
|
+
textBoxColorSelected: cssColor,
|
|
909
|
+
textBoxColorLocked: cssColor,
|
|
910
|
+
},
|
|
911
|
+
});
|
|
912
|
+
},
|
|
913
|
+
},
|
|
914
|
+
});
|
|
915
|
+
},
|
|
916
|
+
|
|
917
|
+
/**
|
|
918
|
+
* Records the instance that the given measurements were just stored as, so
|
|
919
|
+
* that storing them again offers to extend that series rather than creating
|
|
920
|
+
* another one.
|
|
921
|
+
*
|
|
922
|
+
* The predecessor is kept on the annotation as well as on the measurement,
|
|
923
|
+
* because the measurement is re-derived from the annotation whenever the
|
|
924
|
+
* annotation is edited.
|
|
925
|
+
*
|
|
926
|
+
* @param props.measurements - the measurements that were stored
|
|
927
|
+
* @param props.predecessorImageId - imageId of the instance they were stored as
|
|
928
|
+
* @returns the number of measurements the predecessor was recorded on
|
|
929
|
+
*/
|
|
930
|
+
recordMeasurementsPredecessor: ({ measurements = [], predecessorImageId }) => {
|
|
931
|
+
if (!predecessorImageId) {
|
|
932
|
+
return 0;
|
|
933
|
+
}
|
|
934
|
+
|
|
935
|
+
let recorded = 0;
|
|
936
|
+
|
|
937
|
+
for (const { uid } of measurements) {
|
|
938
|
+
const measurement = measurementService.getMeasurement(uid);
|
|
939
|
+
|
|
940
|
+
if (!measurement) {
|
|
941
|
+
continue;
|
|
942
|
+
}
|
|
943
|
+
|
|
944
|
+
measurement.predecessorImageId = predecessorImageId;
|
|
945
|
+
|
|
946
|
+
const targetAnnotation = annotation.state.getAnnotation(uid);
|
|
947
|
+
if (targetAnnotation) {
|
|
948
|
+
targetAnnotation.predecessorImageId = predecessorImageId;
|
|
949
|
+
}
|
|
950
|
+
|
|
951
|
+
recorded++;
|
|
952
|
+
}
|
|
953
|
+
|
|
954
|
+
return recorded;
|
|
955
|
+
},
|
|
956
|
+
|
|
957
|
+
/**
|
|
958
|
+
* Jumps to the specified (by uid) measurement in the active viewport.
|
|
959
|
+
* Also marks any provided display measurements isActive value
|
|
960
|
+
*/
|
|
961
|
+
jumpToMeasurement: ({ uid, displayMeasurements = [] }) => {
|
|
962
|
+
if (!uid) {
|
|
963
|
+
return;
|
|
964
|
+
}
|
|
965
|
+
measurementService.jumpToMeasurement(viewportGridService.getActiveViewportId(), uid);
|
|
966
|
+
for (const measurement of displayMeasurements) {
|
|
967
|
+
measurement.isActive = measurement.uid === uid;
|
|
968
|
+
}
|
|
969
|
+
},
|
|
970
|
+
|
|
971
|
+
removeMeasurement: ({ uid }) => {
|
|
972
|
+
if (Array.isArray(uid)) {
|
|
973
|
+
measurementService.removeMany(uid);
|
|
974
|
+
} else {
|
|
975
|
+
measurementService.remove(uid);
|
|
976
|
+
}
|
|
977
|
+
},
|
|
978
|
+
|
|
979
|
+
toggleLockMeasurement: ({ uid }) => {
|
|
980
|
+
measurementService.toggleLockMeasurement(uid);
|
|
981
|
+
},
|
|
982
|
+
|
|
983
|
+
toggleVisibilityMeasurement: ({ uid, items, visibility }) => {
|
|
984
|
+
if (visibility === undefined && items?.length) {
|
|
985
|
+
visibility = !items[0].isVisible;
|
|
986
|
+
}
|
|
987
|
+
if (Array.isArray(uid)) {
|
|
988
|
+
measurementService.toggleVisibilityMeasurementMany(uid, visibility);
|
|
989
|
+
} else {
|
|
990
|
+
measurementService.toggleVisibilityMeasurement(uid, visibility);
|
|
991
|
+
}
|
|
992
|
+
},
|
|
993
|
+
|
|
994
|
+
/**
|
|
995
|
+
* Download the CSV report for the measurements.
|
|
996
|
+
*/
|
|
997
|
+
downloadCSVMeasurementsReport: ({ measurementFilter }) => {
|
|
998
|
+
utils.downloadCSVReport(measurementService.getMeasurements(measurementFilter));
|
|
999
|
+
},
|
|
1000
|
+
|
|
1001
|
+
downloadCSVSegmentationReport: ({ segmentationId }) => {
|
|
1002
|
+
const segmentation = segmentationService.getSegmentation(segmentationId);
|
|
1003
|
+
|
|
1004
|
+
const { representationData } = segmentation;
|
|
1005
|
+
const { Labelmap } = representationData;
|
|
1006
|
+
const { referencedImageIds } = Labelmap;
|
|
1007
|
+
|
|
1008
|
+
const firstImageId = referencedImageIds[0];
|
|
1009
|
+
|
|
1010
|
+
// find displaySet for firstImageId
|
|
1011
|
+
const displaySet = displaySetService
|
|
1012
|
+
.getActiveDisplaySets()
|
|
1013
|
+
.find(ds => ds.imageIds?.some(i => i === firstImageId));
|
|
1014
|
+
|
|
1015
|
+
const {
|
|
1016
|
+
SeriesNumber,
|
|
1017
|
+
SeriesInstanceUID,
|
|
1018
|
+
StudyInstanceUID,
|
|
1019
|
+
SeriesDate,
|
|
1020
|
+
SeriesTime,
|
|
1021
|
+
SeriesDescription,
|
|
1022
|
+
} = displaySet;
|
|
1023
|
+
|
|
1024
|
+
const additionalInfo = {
|
|
1025
|
+
reference: {
|
|
1026
|
+
SeriesNumber,
|
|
1027
|
+
SeriesInstanceUID,
|
|
1028
|
+
StudyInstanceUID,
|
|
1029
|
+
SeriesDate,
|
|
1030
|
+
SeriesTime,
|
|
1031
|
+
SeriesDescription,
|
|
1032
|
+
},
|
|
1033
|
+
};
|
|
1034
|
+
|
|
1035
|
+
generateSegmentationCSVReport(segmentation, additionalInfo);
|
|
1036
|
+
},
|
|
1037
|
+
|
|
1038
|
+
// Retrieve value commands
|
|
1039
|
+
getActiveViewportEnabledElement: _getActiveViewportEnabledElement,
|
|
1040
|
+
|
|
1041
|
+
setViewportActive: ({ viewportId }) => {
|
|
1042
|
+
const viewportInfo = cornerstoneViewportService.getViewportInfo(viewportId);
|
|
1043
|
+
if (!viewportInfo) {
|
|
1044
|
+
console.warn('No viewport found for viewportId:', viewportId);
|
|
1045
|
+
return;
|
|
1046
|
+
}
|
|
1047
|
+
|
|
1048
|
+
viewportGridService.setActiveViewportId(viewportId);
|
|
1049
|
+
},
|
|
1050
|
+
arrowTextCallback: async ({ callback, data }) => {
|
|
1051
|
+
const labelConfig = customizationService.getCustomization('measurementLabels');
|
|
1052
|
+
const renderContent = customizationService.getCustomization('ui.labellingComponent');
|
|
1053
|
+
// ArrowAnnotateTool removes a just-drawn annotation when its text
|
|
1054
|
+
// callback returns a falsy label. Saving an empty label should keep
|
|
1055
|
+
// the arrow (same as Cancel), so skip the callback for new
|
|
1056
|
+
// annotations (no `data` means the annotation is new, not edited).
|
|
1057
|
+
const isNewAnnotation = !data;
|
|
1058
|
+
|
|
1059
|
+
if (!labelConfig) {
|
|
1060
|
+
const label = await callInputDialog({
|
|
1061
|
+
uiDialogService,
|
|
1062
|
+
title: i18n.t('Tools:Edit Arrow Text'),
|
|
1063
|
+
placeholder: data?.data?.label || i18n.t('Tools:Enter new text'),
|
|
1064
|
+
defaultValue: data?.data?.label || '',
|
|
1065
|
+
});
|
|
1066
|
+
|
|
1067
|
+
if (isNewAnnotation && !label) {
|
|
1068
|
+
return;
|
|
1069
|
+
}
|
|
1070
|
+
callback?.(label);
|
|
1071
|
+
return;
|
|
1072
|
+
}
|
|
1073
|
+
|
|
1074
|
+
const value = await callInputDialogAutoComplete({
|
|
1075
|
+
uiDialogService,
|
|
1076
|
+
labelConfig,
|
|
1077
|
+
renderContent,
|
|
1078
|
+
});
|
|
1079
|
+
if (isNewAnnotation && !value) {
|
|
1080
|
+
return;
|
|
1081
|
+
}
|
|
1082
|
+
callback?.(value);
|
|
1083
|
+
},
|
|
1084
|
+
|
|
1085
|
+
toggleCine: () => {
|
|
1086
|
+
const { viewports } = viewportGridService.getState();
|
|
1087
|
+
const { isCineEnabled } = cineService.getState();
|
|
1088
|
+
cineService.setIsCineEnabled(!isCineEnabled);
|
|
1089
|
+
viewports.forEach((_, index) => cineService.setCine({ id: index, isPlaying: false }));
|
|
1090
|
+
},
|
|
1091
|
+
|
|
1092
|
+
setViewportWindowLevel({
|
|
1093
|
+
viewportId,
|
|
1094
|
+
windowWidth,
|
|
1095
|
+
windowCenter,
|
|
1096
|
+
displaySetInstanceUID,
|
|
1097
|
+
}: {
|
|
1098
|
+
viewportId: string;
|
|
1099
|
+
windowWidth: number;
|
|
1100
|
+
windowCenter: number;
|
|
1101
|
+
displaySetInstanceUID?: string;
|
|
1102
|
+
}) {
|
|
1103
|
+
// convert to numbers
|
|
1104
|
+
const windowWidthNum = Number(windowWidth);
|
|
1105
|
+
const windowCenterNum = Number(windowCenter);
|
|
1106
|
+
|
|
1107
|
+
const renderingEngine = cornerstoneViewportService.getRenderingEngine();
|
|
1108
|
+
const viewport = renderingEngine.getViewport(viewportId);
|
|
1109
|
+
|
|
1110
|
+
// Stale/invalid viewport ids resolve to undefined; bail out before the VOI
|
|
1111
|
+
// apply + render below would throw.
|
|
1112
|
+
if (!viewport) {
|
|
1113
|
+
return;
|
|
1114
|
+
}
|
|
1115
|
+
|
|
1116
|
+
// Legacy volume viewports target a specific volume; the command owns that
|
|
1117
|
+
// resolution (it needs the service). The operations backend applies the VOI
|
|
1118
|
+
// (legacy setProperties vs native setDisplaySetPresentation on the active binding).
|
|
1119
|
+
const volumeId = isVolumeViewportType(viewport)
|
|
1120
|
+
? actions.getVolumeIdForDisplaySet({ viewportId, displaySetInstanceUID })
|
|
1121
|
+
: undefined;
|
|
1122
|
+
|
|
1123
|
+
ops.setWindowLevel(viewport, {
|
|
1124
|
+
windowWidth: windowWidthNum,
|
|
1125
|
+
windowCenter: windowCenterNum,
|
|
1126
|
+
volumeId,
|
|
1127
|
+
displaySetInstanceUID,
|
|
1128
|
+
});
|
|
1129
|
+
viewport.render();
|
|
1130
|
+
},
|
|
1131
|
+
toggleViewportColorbar: ({ viewportId, displaySetInstanceUIDs, options = {} }) => {
|
|
1132
|
+
const hasColorbar = colorbarService.hasColorbar(viewportId);
|
|
1133
|
+
if (hasColorbar) {
|
|
1134
|
+
colorbarService.removeColorbar(viewportId);
|
|
1135
|
+
return;
|
|
1136
|
+
}
|
|
1137
|
+
colorbarService.addColorbar(viewportId, displaySetInstanceUIDs, options);
|
|
1138
|
+
},
|
|
1139
|
+
setWindowLevel(props) {
|
|
1140
|
+
const { toolGroupId } = props;
|
|
1141
|
+
const { viewportId } = _getActiveViewportEnabledElement();
|
|
1142
|
+
const viewportToolGroupId = toolGroupService.getToolGroupForViewport(viewportId);
|
|
1143
|
+
|
|
1144
|
+
if (toolGroupId && toolGroupId !== viewportToolGroupId) {
|
|
1145
|
+
return;
|
|
1146
|
+
}
|
|
1147
|
+
|
|
1148
|
+
actions.setViewportWindowLevel({ ...props, viewportId });
|
|
1149
|
+
},
|
|
1150
|
+
setWindowLevelPreset: ({ presetName, presetIndex }) => {
|
|
1151
|
+
const windowLevelPresets = customizationService.getCustomization(
|
|
1152
|
+
'cornerstone.windowLevelPresets'
|
|
1153
|
+
);
|
|
1154
|
+
|
|
1155
|
+
const activeViewport = viewportGridService.getActiveViewportId();
|
|
1156
|
+
const viewport = cornerstoneViewportService.getCornerstoneViewport(activeViewport);
|
|
1157
|
+
const metadata = viewport.getImageData().metadata;
|
|
1158
|
+
|
|
1159
|
+
const modality = metadata.Modality;
|
|
1160
|
+
|
|
1161
|
+
if (!modality) {
|
|
1162
|
+
return;
|
|
1163
|
+
}
|
|
1164
|
+
|
|
1165
|
+
const windowLevelPresetForModality = windowLevelPresets[modality];
|
|
1166
|
+
|
|
1167
|
+
if (!windowLevelPresetForModality) {
|
|
1168
|
+
return;
|
|
1169
|
+
}
|
|
1170
|
+
|
|
1171
|
+
const windowLevelPreset = findWindowLevelPreset(
|
|
1172
|
+
windowLevelPresetForModality,
|
|
1173
|
+
presetName,
|
|
1174
|
+
presetIndex
|
|
1175
|
+
);
|
|
1176
|
+
|
|
1177
|
+
// A customization can have fewer presets than there are W/L hotkeys.
|
|
1178
|
+
if (!windowLevelPreset) {
|
|
1179
|
+
return;
|
|
1180
|
+
}
|
|
1181
|
+
|
|
1182
|
+
actions.setViewportWindowLevel({
|
|
1183
|
+
viewportId: activeViewport,
|
|
1184
|
+
windowWidth: windowLevelPreset.window,
|
|
1185
|
+
windowCenter: windowLevelPreset.level,
|
|
1186
|
+
});
|
|
1187
|
+
},
|
|
1188
|
+
getVolumeIdForDisplaySet: ({ viewportId, displaySetInstanceUID }) => {
|
|
1189
|
+
const viewport = cornerstoneViewportService.getCornerstoneViewport(viewportId);
|
|
1190
|
+
// `instanceof BaseVolumeViewport` is false for GenericViewport compat adapters,
|
|
1191
|
+
// so use the capability guard instead (cornerstone 5.x generic-viewport guide).
|
|
1192
|
+
// A stack-mode adapter passes the guard but getAllVolumeIds() returns [], so the
|
|
1193
|
+
// result is the same null as before on stacks.
|
|
1194
|
+
if (csUtils.viewportSupportsVolumeId(viewport)) {
|
|
1195
|
+
const volumeIds = (viewport as CoreTypes.IVolumeViewport).getAllVolumeIds();
|
|
1196
|
+
const volumeId = volumeIds.find(id => id.includes(displaySetInstanceUID));
|
|
1197
|
+
return volumeId;
|
|
1198
|
+
}
|
|
1199
|
+
return null;
|
|
1200
|
+
},
|
|
1201
|
+
setToolEnabled: ({ toolName, toggle, toolGroupId }) => {
|
|
1202
|
+
const { viewports } = viewportGridService.getState();
|
|
1203
|
+
|
|
1204
|
+
if (!viewports.size) {
|
|
1205
|
+
return;
|
|
1206
|
+
}
|
|
1207
|
+
|
|
1208
|
+
const toolGroup = toolGroupService.getToolGroup(toolGroupId ?? null);
|
|
1209
|
+
|
|
1210
|
+
if (!toolGroup || !toolGroup.hasTool(toolName)) {
|
|
1211
|
+
return;
|
|
1212
|
+
}
|
|
1213
|
+
|
|
1214
|
+
const toolIsEnabled = toolGroup.getToolOptions(toolName).mode === Enums.ToolModes.Enabled;
|
|
1215
|
+
|
|
1216
|
+
// Toggle the tool's state only if the toggle is true
|
|
1217
|
+
if (toggle) {
|
|
1218
|
+
toolIsEnabled ? toolGroup.setToolDisabled(toolName) : toolGroup.setToolEnabled(toolName);
|
|
1219
|
+
} else {
|
|
1220
|
+
toolGroup.setToolEnabled(toolName);
|
|
1221
|
+
}
|
|
1222
|
+
|
|
1223
|
+
const renderingEngine = cornerstoneViewportService.getRenderingEngine();
|
|
1224
|
+
renderingEngine.render();
|
|
1225
|
+
},
|
|
1226
|
+
toggleEnabledDisabledToolbar({ value, itemId, toolGroupId }) {
|
|
1227
|
+
const toolName = itemId || value;
|
|
1228
|
+
toolGroupId = toolGroupId ?? _getActiveViewportToolGroupId();
|
|
1229
|
+
|
|
1230
|
+
const toolGroup = toolGroupService.getToolGroup(toolGroupId);
|
|
1231
|
+
if (!toolGroup || !toolGroup.hasTool(toolName)) {
|
|
1232
|
+
return;
|
|
1233
|
+
}
|
|
1234
|
+
|
|
1235
|
+
const toolIsEnabled = toolGroup.getToolOptions(toolName).mode === Enums.ToolModes.Enabled;
|
|
1236
|
+
|
|
1237
|
+
toolIsEnabled ? toolGroup.setToolDisabled(toolName) : toolGroup.setToolEnabled(toolName);
|
|
1238
|
+
},
|
|
1239
|
+
toggleActiveDisabledToolbar({ value, itemId, toolGroupId, toolGroupIds }) {
|
|
1240
|
+
const toolName = itemId || value;
|
|
1241
|
+
const resolvedToolGroupIds = toolGroupIds?.length
|
|
1242
|
+
? toolGroupIds
|
|
1243
|
+
: [toolGroupId ?? _getActiveViewportToolGroupId()];
|
|
1244
|
+
|
|
1245
|
+
resolvedToolGroupIds.forEach(toolGroupId => {
|
|
1246
|
+
const toolGroup = toolGroupService.getToolGroup(toolGroupId);
|
|
1247
|
+
if (!toolGroup || !toolGroup.hasTool(toolName)) {
|
|
1248
|
+
return;
|
|
1249
|
+
}
|
|
1250
|
+
|
|
1251
|
+
const toolIsActive = [
|
|
1252
|
+
Enums.ToolModes.Active,
|
|
1253
|
+
Enums.ToolModes.Enabled,
|
|
1254
|
+
Enums.ToolModes.Passive,
|
|
1255
|
+
].includes(toolGroup.getToolOptions(toolName).mode);
|
|
1256
|
+
|
|
1257
|
+
if (toolIsActive) {
|
|
1258
|
+
toolGroup.setToolDisabled(toolName);
|
|
1259
|
+
|
|
1260
|
+
const bindings = toolGroupService.getToolBindings(toolGroupId, toolName);
|
|
1261
|
+
|
|
1262
|
+
if (_usesPrimaryActivation(bindings)) {
|
|
1263
|
+
// we should set the previously active tool to active after we set the
|
|
1264
|
+
// current tool disabled
|
|
1265
|
+
const prevToolName = toolGroup.getPrevActivePrimaryToolName();
|
|
1266
|
+
if (prevToolName !== toolName) {
|
|
1267
|
+
actions.setToolActive({ toolName: prevToolName, toolGroupId });
|
|
1268
|
+
}
|
|
1269
|
+
}
|
|
1270
|
+
|
|
1271
|
+
return;
|
|
1272
|
+
}
|
|
1273
|
+
|
|
1274
|
+
const bindings = toolGroupService.getToolBindings(toolGroupId, toolName);
|
|
1275
|
+
if (_usesPrimaryActivation(bindings)) {
|
|
1276
|
+
actions.setToolActive({ toolName, toolGroupId, bindings });
|
|
1277
|
+
} else {
|
|
1278
|
+
toolGroup.setToolActive(toolName, { bindings });
|
|
1279
|
+
}
|
|
1280
|
+
});
|
|
1281
|
+
},
|
|
1282
|
+
setToolActiveToolbar: ({ value, itemId, toolName, toolGroupIds = [], bindings }) => {
|
|
1283
|
+
// Sometimes it is passed as value (tools with options), sometimes as itemId (toolbar buttons)
|
|
1284
|
+
toolName = toolName || itemId || value;
|
|
1285
|
+
|
|
1286
|
+
toolGroupIds = toolGroupIds.length ? toolGroupIds : toolGroupService.getToolGroupIds();
|
|
1287
|
+
|
|
1288
|
+
toolGroupIds.forEach(toolGroupId => {
|
|
1289
|
+
actions.setToolActive({ toolName, toolGroupId, bindings });
|
|
1290
|
+
});
|
|
1291
|
+
},
|
|
1292
|
+
setToolActive: ({
|
|
1293
|
+
toolName,
|
|
1294
|
+
toolGroupId = null,
|
|
1295
|
+
bindings = [{ mouseButton: Enums.MouseBindings.Primary }],
|
|
1296
|
+
}) => {
|
|
1297
|
+
const { viewports } = viewportGridService.getState();
|
|
1298
|
+
|
|
1299
|
+
if (!viewports.size) {
|
|
1300
|
+
return;
|
|
1301
|
+
}
|
|
1302
|
+
|
|
1303
|
+
const toolGroup = toolGroupService.getToolGroup(toolGroupId);
|
|
1304
|
+
|
|
1305
|
+
if (!toolGroup) {
|
|
1306
|
+
return;
|
|
1307
|
+
}
|
|
1308
|
+
|
|
1309
|
+
if (!toolGroup?.hasTool(toolName)) {
|
|
1310
|
+
return;
|
|
1311
|
+
}
|
|
1312
|
+
|
|
1313
|
+
const activeToolName = toolGroup.getActivePrimaryMouseButtonTool();
|
|
1314
|
+
|
|
1315
|
+
if (activeToolName) {
|
|
1316
|
+
const activeToolOptions = toolGroup.getToolConfiguration(activeToolName);
|
|
1317
|
+
activeToolOptions?.disableOnPassive
|
|
1318
|
+
? toolGroup.setToolDisabled(activeToolName)
|
|
1319
|
+
: toolGroup.setToolPassive(activeToolName);
|
|
1320
|
+
}
|
|
1321
|
+
|
|
1322
|
+
// Set the new toolName to be active
|
|
1323
|
+
toolGroup.setToolActive(toolName, {
|
|
1324
|
+
bindings,
|
|
1325
|
+
});
|
|
1326
|
+
},
|
|
1327
|
+
// capture viewport
|
|
1328
|
+
showDownloadViewportModal: () => {
|
|
1329
|
+
const { activeViewportId } = viewportGridService.getState();
|
|
1330
|
+
|
|
1331
|
+
if (!cornerstoneViewportService.getCornerstoneViewport(activeViewportId)) {
|
|
1332
|
+
// Cannot download a non-cornerstone viewport (image).
|
|
1333
|
+
uiNotificationService.show({
|
|
1334
|
+
title: i18n.t('Tools:Download Image'),
|
|
1335
|
+
message: i18n.t('Tools:Image cannot be downloaded'),
|
|
1336
|
+
type: 'error',
|
|
1337
|
+
});
|
|
1338
|
+
return;
|
|
1339
|
+
}
|
|
1340
|
+
|
|
1341
|
+
const { uiModalService } = servicesManager.services;
|
|
1342
|
+
|
|
1343
|
+
if (uiModalService) {
|
|
1344
|
+
uiModalService.show({
|
|
1345
|
+
content: CornerstoneViewportDownloadForm,
|
|
1346
|
+
title: i18n.t('Tools:Download High Quality Image'),
|
|
1347
|
+
contentProps: {
|
|
1348
|
+
activeViewportId,
|
|
1349
|
+
cornerstoneViewportService,
|
|
1350
|
+
},
|
|
1351
|
+
containerClassName: 'max-w-4xl p-4',
|
|
1352
|
+
});
|
|
1353
|
+
}
|
|
1354
|
+
},
|
|
1355
|
+
/**
|
|
1356
|
+
* Rotates the viewport by `rotation` relative to its current rotation.
|
|
1357
|
+
*/
|
|
1358
|
+
rotateViewportBy: ({ rotation, viewportId }: { rotation: number; viewportId?: string }) => {
|
|
1359
|
+
actions._rotateViewport({ rotation, viewportId, rotationMode: 'apply' });
|
|
1360
|
+
},
|
|
1361
|
+
/**
|
|
1362
|
+
* Sets the viewport rotation to an absolute value `rotation`.
|
|
1363
|
+
*/
|
|
1364
|
+
setViewportRotation: ({ rotation, viewportId }: { rotation: number; viewportId?: string }) => {
|
|
1365
|
+
actions._rotateViewport({ rotation, viewportId, rotationMode: 'set' });
|
|
1366
|
+
},
|
|
1367
|
+
flipViewportHorizontal: ({
|
|
1368
|
+
viewportId,
|
|
1369
|
+
newValue = 'toggle',
|
|
1370
|
+
}: {
|
|
1371
|
+
viewportId?: string;
|
|
1372
|
+
newValue?: 'toggle' | boolean;
|
|
1373
|
+
}) => {
|
|
1374
|
+
const viewport = _resolveViewport(viewportId);
|
|
1375
|
+
if (!viewport) {
|
|
1376
|
+
return;
|
|
1377
|
+
}
|
|
1378
|
+
ops.flipHorizontal(viewport, newValue);
|
|
1379
|
+
viewport.render();
|
|
1380
|
+
},
|
|
1381
|
+
flipViewportVertical: ({
|
|
1382
|
+
viewportId,
|
|
1383
|
+
newValue = 'toggle',
|
|
1384
|
+
}: {
|
|
1385
|
+
viewportId?: string;
|
|
1386
|
+
newValue?: 'toggle' | boolean;
|
|
1387
|
+
}) => {
|
|
1388
|
+
const viewport = _resolveViewport(viewportId);
|
|
1389
|
+
if (!viewport) {
|
|
1390
|
+
return;
|
|
1391
|
+
}
|
|
1392
|
+
ops.flipVertical(viewport, newValue);
|
|
1393
|
+
viewport.render();
|
|
1394
|
+
},
|
|
1395
|
+
invertViewport: ({ element }) => {
|
|
1396
|
+
const viewport = element === undefined ? _resolveViewport() : element.viewport;
|
|
1397
|
+
if (!viewport) {
|
|
1398
|
+
return;
|
|
1399
|
+
}
|
|
1400
|
+
ops.invert(viewport);
|
|
1401
|
+
viewport.render();
|
|
1402
|
+
},
|
|
1403
|
+
resetViewport: () => {
|
|
1404
|
+
const viewport = _resolveViewport();
|
|
1405
|
+
if (!viewport) {
|
|
1406
|
+
return;
|
|
1407
|
+
}
|
|
1408
|
+
ops.reset(viewport);
|
|
1409
|
+
viewport.render();
|
|
1410
|
+
},
|
|
1411
|
+
scaleViewport: ({ direction }) => {
|
|
1412
|
+
const viewport = _resolveViewport();
|
|
1413
|
+
if (!viewport) {
|
|
1414
|
+
return;
|
|
1415
|
+
}
|
|
1416
|
+
ops.scaleBy(viewport, direction);
|
|
1417
|
+
viewport.render();
|
|
1418
|
+
},
|
|
1419
|
+
|
|
1420
|
+
/** Jumps the active viewport or the specified one to the given slice index */
|
|
1421
|
+
jumpToImage: ({ imageIndex, viewport: gridViewport }): void => {
|
|
1422
|
+
// Get current active viewport (return if none active)
|
|
1423
|
+
let viewport;
|
|
1424
|
+
if (!gridViewport) {
|
|
1425
|
+
const enabledElement = _getActiveViewportEnabledElement();
|
|
1426
|
+
if (!enabledElement) {
|
|
1427
|
+
return;
|
|
1428
|
+
}
|
|
1429
|
+
viewport = enabledElement.viewport;
|
|
1430
|
+
} else {
|
|
1431
|
+
viewport = cornerstoneViewportService.getCornerstoneViewport(gridViewport.id);
|
|
1432
|
+
}
|
|
1433
|
+
|
|
1434
|
+
// Get number of slices
|
|
1435
|
+
// -> Copied from cornerstone3D jumpToSlice\_getImageSliceData()
|
|
1436
|
+
let numberOfSlices = 0;
|
|
1437
|
+
|
|
1438
|
+
if (isStackViewportType(viewport)) {
|
|
1439
|
+
numberOfSlices = viewport.getImageIds().length;
|
|
1440
|
+
} else if (isOrthographicViewportType(viewport)) {
|
|
1441
|
+
numberOfSlices = csUtils.getImageSliceDataForVolumeViewport(viewport).numberOfSlices;
|
|
1442
|
+
} else {
|
|
1443
|
+
throw new Error('Unsupported viewport type');
|
|
1444
|
+
}
|
|
1445
|
+
|
|
1446
|
+
const jumpIndex = imageIndex < 0 ? numberOfSlices + imageIndex : imageIndex;
|
|
1447
|
+
if (jumpIndex >= numberOfSlices || jumpIndex < 0) {
|
|
1448
|
+
throw new Error(`Can't jump to ${imageIndex}`);
|
|
1449
|
+
}
|
|
1450
|
+
|
|
1451
|
+
// Set slice to last slice
|
|
1452
|
+
const options = { imageIndex: jumpIndex };
|
|
1453
|
+
csUtils.jumpToSlice(viewport.element, options);
|
|
1454
|
+
},
|
|
1455
|
+
scroll: (options: ToolTypes.ScrollOptions) => {
|
|
1456
|
+
const enabledElement = _getActiveViewportEnabledElement();
|
|
1457
|
+
// Allow either or direction for consistency in scroll implementation
|
|
1458
|
+
options.delta ??= options.direction || 1;
|
|
1459
|
+
options.direction ??= options.delta;
|
|
1460
|
+
|
|
1461
|
+
if (!enabledElement) {
|
|
1462
|
+
return;
|
|
1463
|
+
}
|
|
1464
|
+
|
|
1465
|
+
const { viewport } = enabledElement;
|
|
1466
|
+
|
|
1467
|
+
csUtils.scroll(viewport, options);
|
|
1468
|
+
},
|
|
1469
|
+
setViewportColormap: ({
|
|
1470
|
+
viewportId,
|
|
1471
|
+
displaySetInstanceUID,
|
|
1472
|
+
colormap,
|
|
1473
|
+
opacity = 1,
|
|
1474
|
+
immediate = false,
|
|
1475
|
+
}) => {
|
|
1476
|
+
const viewport = cornerstoneViewportService.getCornerstoneViewport(viewportId);
|
|
1477
|
+
|
|
1478
|
+
let hpOpacity;
|
|
1479
|
+
// Retrieve active protocol's viewport match details
|
|
1480
|
+
const { viewportMatchDetails } = hangingProtocolService.getActiveProtocol();
|
|
1481
|
+
// Get display set options for the specified viewport ID
|
|
1482
|
+
const displaySetsInfo = viewportMatchDetails.get(viewportId)?.displaySetsInfo;
|
|
1483
|
+
|
|
1484
|
+
if (displaySetsInfo) {
|
|
1485
|
+
// Find the display set that matches the given UID
|
|
1486
|
+
const matchingDisplaySet = displaySetsInfo.find(
|
|
1487
|
+
displaySet => displaySet.displaySetInstanceUID === displaySetInstanceUID
|
|
1488
|
+
);
|
|
1489
|
+
// If a matching display set is found, update the opacity with its value
|
|
1490
|
+
hpOpacity = matchingDisplaySet?.displaySetOptions?.options?.colormap?.opacity;
|
|
1491
|
+
}
|
|
1492
|
+
|
|
1493
|
+
// HP takes priority over the default opacity
|
|
1494
|
+
colormap = { ...colormap, opacity: hpOpacity || opacity };
|
|
1495
|
+
|
|
1496
|
+
// The legacy orthographic branch resolves the volumeId from the display set;
|
|
1497
|
+
// fall back to the viewport's first display set (needs viewportGridService, so
|
|
1498
|
+
// it is resolved here in the command rather than in the operations backend).
|
|
1499
|
+
if (isOrthographicViewportType(viewport) && !displaySetInstanceUID) {
|
|
1500
|
+
const { viewports } = viewportGridService.getState();
|
|
1501
|
+
displaySetInstanceUID = viewports.get(viewportId)?.displaySetInstanceUIDs[0];
|
|
1502
|
+
}
|
|
1503
|
+
|
|
1504
|
+
ops.setColormap(viewport, { colormap, displaySetInstanceUID });
|
|
1505
|
+
|
|
1506
|
+
if (immediate) {
|
|
1507
|
+
viewport.render();
|
|
1508
|
+
}
|
|
1509
|
+
},
|
|
1510
|
+
changeActiveViewport: ({ direction = 1 }) => {
|
|
1511
|
+
const { activeViewportId, viewports } = viewportGridService.getState();
|
|
1512
|
+
const viewportIds = Array.from(viewports.keys());
|
|
1513
|
+
const currentIndex = viewportIds.indexOf(activeViewportId);
|
|
1514
|
+
const nextViewportIndex =
|
|
1515
|
+
(currentIndex + direction + viewportIds.length) % viewportIds.length;
|
|
1516
|
+
viewportGridService.setActiveViewportId(viewportIds[nextViewportIndex] as string);
|
|
1517
|
+
},
|
|
1518
|
+
/**
|
|
1519
|
+
* If the syncId is given and a synchronizer with that ID already exists, it will
|
|
1520
|
+
* toggle it on/off for the provided viewports. If not, it will attempt to create
|
|
1521
|
+
* a new synchronizer using the given syncId and type for the specified viewports.
|
|
1522
|
+
* If no viewports are provided, you may notice some default behavior.
|
|
1523
|
+
* - 'voi' type, we will aim to synchronize all viewports with the same modality
|
|
1524
|
+
* -'imageSlice' type, we will aim to synchronize all viewports with the same orientation.
|
|
1525
|
+
*
|
|
1526
|
+
* @param options
|
|
1527
|
+
* @param options.viewports - The viewports to synchronize
|
|
1528
|
+
* @param options.syncId - The synchronization group ID
|
|
1529
|
+
* @param options.type - The type of synchronization to perform
|
|
1530
|
+
*/
|
|
1531
|
+
toggleSynchronizer: ({ type, viewports, syncId }) => {
|
|
1532
|
+
const synchronizer = syncGroupService.getSynchronizer(syncId);
|
|
1533
|
+
|
|
1534
|
+
if (synchronizer) {
|
|
1535
|
+
synchronizer.isDisabled() ? synchronizer.setEnabled(true) : synchronizer.setEnabled(false);
|
|
1536
|
+
return;
|
|
1537
|
+
}
|
|
1538
|
+
|
|
1539
|
+
const fn = toggleSyncFunctions[type];
|
|
1540
|
+
|
|
1541
|
+
if (fn) {
|
|
1542
|
+
fn({
|
|
1543
|
+
servicesManager,
|
|
1544
|
+
viewports,
|
|
1545
|
+
syncId,
|
|
1546
|
+
});
|
|
1547
|
+
}
|
|
1548
|
+
},
|
|
1549
|
+
setViewportForToolConfiguration: ({ viewportId, toolName }) => {
|
|
1550
|
+
if (!viewportId) {
|
|
1551
|
+
const { activeViewportId } = viewportGridService.getState();
|
|
1552
|
+
viewportId = activeViewportId ?? 'default';
|
|
1553
|
+
}
|
|
1554
|
+
|
|
1555
|
+
const toolGroup = toolGroupService.getToolGroupForViewport(viewportId);
|
|
1556
|
+
|
|
1557
|
+
if (!toolGroup?.hasTool(toolName)) {
|
|
1558
|
+
return;
|
|
1559
|
+
}
|
|
1560
|
+
|
|
1561
|
+
const prevConfig = toolGroup?.getToolConfiguration(toolName);
|
|
1562
|
+
toolGroup?.setToolConfiguration(
|
|
1563
|
+
toolName,
|
|
1564
|
+
{
|
|
1565
|
+
...prevConfig,
|
|
1566
|
+
sourceViewportId: viewportId,
|
|
1567
|
+
},
|
|
1568
|
+
true // overwrite
|
|
1569
|
+
);
|
|
1570
|
+
|
|
1571
|
+
const renderingEngine = cornerstoneViewportService.getRenderingEngine();
|
|
1572
|
+
renderingEngine.render();
|
|
1573
|
+
},
|
|
1574
|
+
storePresentation: ({ viewportId }) => {
|
|
1575
|
+
cornerstoneViewportService.storePresentation({ viewportId });
|
|
1576
|
+
},
|
|
1577
|
+
updateVolumeData: ({ volume }) => {
|
|
1578
|
+
// Marks the imageData and every texture set (full and reduced) of the computed volume dirty.
|
|
1579
|
+
volume.modified();
|
|
1580
|
+
},
|
|
1581
|
+
|
|
1582
|
+
attachProtocolViewportDataListener: ({ protocol, stageIndex }) => {
|
|
1583
|
+
const EVENT = cornerstoneViewportService.EVENTS.VIEWPORT_DATA_CHANGED;
|
|
1584
|
+
const command = protocol.callbacks.onViewportDataInitialized;
|
|
1585
|
+
const numPanes = protocol.stages?.[stageIndex]?.viewports.length ?? 1;
|
|
1586
|
+
let numPanesWithData = 0;
|
|
1587
|
+
const { unsubscribe } = cornerstoneViewportService.subscribe(EVENT, evt => {
|
|
1588
|
+
numPanesWithData++;
|
|
1589
|
+
|
|
1590
|
+
if (numPanesWithData === numPanes) {
|
|
1591
|
+
commandsManager.run(...command);
|
|
1592
|
+
|
|
1593
|
+
// Unsubscribe from the event
|
|
1594
|
+
unsubscribe(EVENT);
|
|
1595
|
+
}
|
|
1596
|
+
});
|
|
1597
|
+
},
|
|
1598
|
+
|
|
1599
|
+
setViewportPreset: ({ viewportId, preset }) => {
|
|
1600
|
+
const viewport = cornerstoneViewportService.getCornerstoneViewport(viewportId);
|
|
1601
|
+
if (!viewport) {
|
|
1602
|
+
return;
|
|
1603
|
+
}
|
|
1604
|
+
ops.setPreset(viewport, preset);
|
|
1605
|
+
viewport.render();
|
|
1606
|
+
},
|
|
1607
|
+
|
|
1608
|
+
/**
|
|
1609
|
+
* Sets the volume quality for a given viewport.
|
|
1610
|
+
* @param {string} viewportId - The ID of the viewport to set the volume quality.
|
|
1611
|
+
* @param {number} volumeQuality - The desired quality level of the volume rendering.
|
|
1612
|
+
*/
|
|
1613
|
+
|
|
1614
|
+
setVolumeRenderingQulaity: ({ viewportId, volumeQuality }) => {
|
|
1615
|
+
const viewport = cornerstoneViewportService.getCornerstoneViewport(viewportId);
|
|
1616
|
+
if (!viewport) {
|
|
1617
|
+
return;
|
|
1618
|
+
}
|
|
1619
|
+
ops.setVolumeRenderingQuality(viewport, volumeQuality);
|
|
1620
|
+
viewport.render();
|
|
1621
|
+
},
|
|
1622
|
+
|
|
1623
|
+
/**
|
|
1624
|
+
* Shifts opacity points for a given viewport id.
|
|
1625
|
+
* @param {string} viewportId - The ID of the viewport to set the mapping range.
|
|
1626
|
+
* @param {number} shift - The shift value to shift the points by.
|
|
1627
|
+
*/
|
|
1628
|
+
shiftVolumeOpacityPoints: ({ viewportId, shift }) => {
|
|
1629
|
+
const viewport = cornerstoneViewportService.getCornerstoneViewport(viewportId);
|
|
1630
|
+
if (!viewport) {
|
|
1631
|
+
return;
|
|
1632
|
+
}
|
|
1633
|
+
ops.shiftVolumeOpacityPoints(viewport, shift);
|
|
1634
|
+
viewport.render();
|
|
1635
|
+
},
|
|
1636
|
+
|
|
1637
|
+
/**
|
|
1638
|
+
* Sets the volume lighting settings for a given viewport.
|
|
1639
|
+
* @param {string} viewportId - The ID of the viewport to set the lighting settings.
|
|
1640
|
+
* @param {Object} options - The lighting settings to be set.
|
|
1641
|
+
* @param {boolean} options.shade - The shade setting for the lighting.
|
|
1642
|
+
* @param {number} options.ambient - The ambient setting for the lighting.
|
|
1643
|
+
* @param {number} options.diffuse - The diffuse setting for the lighting.
|
|
1644
|
+
* @param {number} options.specular - The specular setting for the lighting.
|
|
1645
|
+
**/
|
|
1646
|
+
|
|
1647
|
+
setVolumeLighting: ({ viewportId, options }) => {
|
|
1648
|
+
const viewport = cornerstoneViewportService.getCornerstoneViewport(viewportId);
|
|
1649
|
+
if (!viewport) {
|
|
1650
|
+
return;
|
|
1651
|
+
}
|
|
1652
|
+
ops.setVolumeLighting(viewport, options);
|
|
1653
|
+
viewport.render();
|
|
1654
|
+
},
|
|
1655
|
+
resetCrosshairs: ({ viewportId }) => {
|
|
1656
|
+
const crosshairInstances = [];
|
|
1657
|
+
|
|
1658
|
+
const getCrosshairInstances = toolGroupId => {
|
|
1659
|
+
const toolGroup = toolGroupService.getToolGroup(toolGroupId);
|
|
1660
|
+
// Only fetch the instance when Crosshairs is registered in this tool
|
|
1661
|
+
// group. getToolInstance logs a warning for an unregistered tool, and a
|
|
1662
|
+
// viewport's default tool group does not always include Crosshairs (e.g.
|
|
1663
|
+
// next viewports), which made Reset Viewport log a spurious warning.
|
|
1664
|
+
if (toolGroup?.hasTool('Crosshairs')) {
|
|
1665
|
+
crosshairInstances.push(toolGroup.getToolInstance('Crosshairs'));
|
|
1666
|
+
}
|
|
1667
|
+
};
|
|
1668
|
+
|
|
1669
|
+
if (!viewportId) {
|
|
1670
|
+
const toolGroupIds = toolGroupService.getToolGroupIds();
|
|
1671
|
+
toolGroupIds.forEach(getCrosshairInstances);
|
|
1672
|
+
} else {
|
|
1673
|
+
const toolGroup = toolGroupService.getToolGroupForViewport(viewportId);
|
|
1674
|
+
if (toolGroup) {
|
|
1675
|
+
getCrosshairInstances(toolGroup.id);
|
|
1676
|
+
}
|
|
1677
|
+
}
|
|
1678
|
+
|
|
1679
|
+
crosshairInstances.forEach(ins => {
|
|
1680
|
+
ins?.computeToolCenter();
|
|
1681
|
+
});
|
|
1682
|
+
},
|
|
1683
|
+
/**
|
|
1684
|
+
* Creates a labelmap for the active viewport
|
|
1685
|
+
*
|
|
1686
|
+
* The created labelmap will be registered as a display set and also added
|
|
1687
|
+
* as a segmentation representation to the viewport.
|
|
1688
|
+
*/
|
|
1689
|
+
createLabelmapForViewport: async ({ viewportId, options = {} }) => {
|
|
1690
|
+
return createSegmentationForViewport(servicesManager, {
|
|
1691
|
+
viewportId,
|
|
1692
|
+
options,
|
|
1693
|
+
segmentationType: SegmentationRepresentations.Labelmap,
|
|
1694
|
+
});
|
|
1695
|
+
},
|
|
1696
|
+
/**
|
|
1697
|
+
* Creates a contour for the active viewport
|
|
1698
|
+
*
|
|
1699
|
+
* The created contour will be registered as a display set and also added
|
|
1700
|
+
* as a segmentation representation to the viewport.
|
|
1701
|
+
*/
|
|
1702
|
+
createContourForViewport: async ({ viewportId, options = {} }) => {
|
|
1703
|
+
return createSegmentationForViewport(servicesManager, {
|
|
1704
|
+
viewportId,
|
|
1705
|
+
options,
|
|
1706
|
+
segmentationType: SegmentationRepresentations.Contour,
|
|
1707
|
+
});
|
|
1708
|
+
},
|
|
1709
|
+
|
|
1710
|
+
/**
|
|
1711
|
+
* Sets the active segmentation for a viewport
|
|
1712
|
+
* @param props.segmentationId - The ID of the segmentation to set as active
|
|
1713
|
+
*/
|
|
1714
|
+
setActiveSegmentation: ({ segmentationId }) => {
|
|
1715
|
+
const { viewportGridService, segmentationService } = servicesManager.services;
|
|
1716
|
+
segmentationService.setActiveSegmentation(
|
|
1717
|
+
viewportGridService.getActiveViewportId(),
|
|
1718
|
+
segmentationId
|
|
1719
|
+
);
|
|
1720
|
+
},
|
|
1721
|
+
|
|
1722
|
+
/**
|
|
1723
|
+
* Adds a new segment to a segmentation
|
|
1724
|
+
* @param props.segmentationId - The ID of the segmentation to add the segment to
|
|
1725
|
+
*/
|
|
1726
|
+
addSegmentCommand: ({ segmentationId, config }) => {
|
|
1727
|
+
const { segmentationService } = servicesManager.services;
|
|
1728
|
+
segmentationService.addSegment(segmentationId, config);
|
|
1729
|
+
},
|
|
1730
|
+
|
|
1731
|
+
/**
|
|
1732
|
+
* Sets the active segment and jumps to its center
|
|
1733
|
+
* @param props.segmentationId - The ID of the segmentation
|
|
1734
|
+
* @param props.segmentIndex - The index of the segment to activate
|
|
1735
|
+
*/
|
|
1736
|
+
setActiveSegmentAndCenterCommand: ({ segmentationId, segmentIndex }) => {
|
|
1737
|
+
const { segmentationService, viewportGridService } = servicesManager.services;
|
|
1738
|
+
// set both active segmentation and active segment
|
|
1739
|
+
segmentationService.setActiveSegmentation(
|
|
1740
|
+
viewportGridService.getActiveViewportId(),
|
|
1741
|
+
segmentationId
|
|
1742
|
+
);
|
|
1743
|
+
segmentationService.setActiveSegment(segmentationId, segmentIndex);
|
|
1744
|
+
|
|
1745
|
+
const { highlightAlpha, highlightSegment, animationLength, animationFunctionType } =
|
|
1746
|
+
(customizationService.getCustomization(
|
|
1747
|
+
'panelSegmentation.jumpToSegmentHighlightAnimationConfig'
|
|
1748
|
+
) as Object as {
|
|
1749
|
+
highlightAlpha?: number;
|
|
1750
|
+
highlightSegment?: boolean;
|
|
1751
|
+
animationLength?: number;
|
|
1752
|
+
animationFunctionType?: EasingFunctionEnum;
|
|
1753
|
+
}) ?? {};
|
|
1754
|
+
|
|
1755
|
+
const validAnimationFunctionType = Object.values(EasingFunctionEnum).includes(
|
|
1756
|
+
animationFunctionType
|
|
1757
|
+
)
|
|
1758
|
+
? animationFunctionType
|
|
1759
|
+
: undefined;
|
|
1760
|
+
|
|
1761
|
+
segmentationService.jumpToSegmentNext(
|
|
1762
|
+
segmentationId,
|
|
1763
|
+
segmentIndex,
|
|
1764
|
+
undefined,
|
|
1765
|
+
highlightAlpha,
|
|
1766
|
+
highlightSegment,
|
|
1767
|
+
animationLength,
|
|
1768
|
+
undefined,
|
|
1769
|
+
validAnimationFunctionType
|
|
1770
|
+
);
|
|
1771
|
+
},
|
|
1772
|
+
|
|
1773
|
+
/**
|
|
1774
|
+
* Toggles the visibility of a segment
|
|
1775
|
+
* @param props.segmentationId - The ID of the segmentation
|
|
1776
|
+
* @param props.segmentIndex - The index of the segment
|
|
1777
|
+
* @param props.type - The type of visibility to toggle
|
|
1778
|
+
*/
|
|
1779
|
+
toggleSegmentVisibilityCommand: ({ segmentationId, segmentIndex, type }) => {
|
|
1780
|
+
const { segmentationService, viewportGridService } = servicesManager.services;
|
|
1781
|
+
segmentationService.toggleSegmentVisibility(
|
|
1782
|
+
viewportGridService.getActiveViewportId(),
|
|
1783
|
+
segmentationId,
|
|
1784
|
+
segmentIndex,
|
|
1785
|
+
type
|
|
1786
|
+
);
|
|
1787
|
+
},
|
|
1788
|
+
|
|
1789
|
+
/**
|
|
1790
|
+
* Toggles the lock state of a segment
|
|
1791
|
+
* @param props.segmentationId - The ID of the segmentation
|
|
1792
|
+
* @param props.segmentIndex - The index of the segment
|
|
1793
|
+
*/
|
|
1794
|
+
toggleSegmentLockCommand: ({ segmentationId, segmentIndex }) => {
|
|
1795
|
+
const { segmentationService } = servicesManager.services;
|
|
1796
|
+
segmentationService.toggleSegmentLocked(segmentationId, segmentIndex);
|
|
1797
|
+
},
|
|
1798
|
+
|
|
1799
|
+
/**
|
|
1800
|
+
* Toggles the visibility of a segmentation representation
|
|
1801
|
+
* @param props.segmentationId - The ID of the segmentation
|
|
1802
|
+
* @param props.type - The type of representation
|
|
1803
|
+
*/
|
|
1804
|
+
toggleSegmentationVisibilityCommand: ({ segmentationId, type }) => {
|
|
1805
|
+
const { segmentationService, viewportGridService } = servicesManager.services;
|
|
1806
|
+
segmentationService.toggleSegmentationRepresentationVisibility(
|
|
1807
|
+
viewportGridService.getActiveViewportId(),
|
|
1808
|
+
{ segmentationId, type }
|
|
1809
|
+
);
|
|
1810
|
+
},
|
|
1811
|
+
|
|
1812
|
+
/**
|
|
1813
|
+
* Downloads a segmentation
|
|
1814
|
+
* @param props.segmentationId - The ID of the segmentation to download
|
|
1815
|
+
*/
|
|
1816
|
+
downloadSegmentationCommand: ({ segmentationId }) => {
|
|
1817
|
+
const { segmentationService } = servicesManager.services;
|
|
1818
|
+
segmentationService.downloadSegmentation(segmentationId);
|
|
1819
|
+
},
|
|
1820
|
+
|
|
1821
|
+
/**
|
|
1822
|
+
* Stores a segmentation and shows it in the viewport
|
|
1823
|
+
* @param props.segmentationId - The ID of the segmentation to store
|
|
1824
|
+
*/
|
|
1825
|
+
storeSegmentationCommand: async args => {
|
|
1826
|
+
const { segmentationId } = args;
|
|
1827
|
+
const { segmentationService, viewportGridService } = servicesManager.services;
|
|
1828
|
+
|
|
1829
|
+
const displaySetInstanceUIDs = await createReportAsync({
|
|
1830
|
+
servicesManager,
|
|
1831
|
+
getReport: () => commandsManager.runCommand('storeSegmentation', args),
|
|
1832
|
+
reportType: 'Segmentation',
|
|
1833
|
+
});
|
|
1834
|
+
|
|
1835
|
+
if (displaySetInstanceUIDs) {
|
|
1836
|
+
segmentationService.remove(segmentationId);
|
|
1837
|
+
viewportGridService.setDisplaySetsForViewport({
|
|
1838
|
+
viewportId: viewportGridService.getActiveViewportId(),
|
|
1839
|
+
displaySetInstanceUIDs,
|
|
1840
|
+
});
|
|
1841
|
+
}
|
|
1842
|
+
},
|
|
1843
|
+
|
|
1844
|
+
/**
|
|
1845
|
+
* Downloads a segmentation as RTSS
|
|
1846
|
+
* @param props.segmentationId - The ID of the segmentation
|
|
1847
|
+
*/
|
|
1848
|
+
downloadRTSSCommand: ({ segmentationId }) => {
|
|
1849
|
+
const { segmentationService } = servicesManager.services;
|
|
1850
|
+
segmentationService.downloadRTSS(segmentationId);
|
|
1851
|
+
},
|
|
1852
|
+
|
|
1853
|
+
/**
|
|
1854
|
+
* Sets the style for a segmentation
|
|
1855
|
+
* @param props.segmentationId - The ID of the segmentation
|
|
1856
|
+
* @param props.type - The type of style
|
|
1857
|
+
* @param props.key - The style key to set
|
|
1858
|
+
* @param props.value - The style value
|
|
1859
|
+
*/
|
|
1860
|
+
setSegmentationStyleCommand: ({ type, key, value }) => {
|
|
1861
|
+
const { segmentationService } = servicesManager.services;
|
|
1862
|
+
segmentationService.setStyle({ type }, { [key]: value });
|
|
1863
|
+
},
|
|
1864
|
+
|
|
1865
|
+
/**
|
|
1866
|
+
* Deletes a segment from a segmentation
|
|
1867
|
+
* @param props.segmentationId - The ID of the segmentation
|
|
1868
|
+
* @param props.segmentIndex - The index of the segment to delete
|
|
1869
|
+
*/
|
|
1870
|
+
deleteSegmentCommand: ({ segmentationId, segmentIndex }) => {
|
|
1871
|
+
const { segmentationService } = servicesManager.services;
|
|
1872
|
+
segmentationService.removeSegment(segmentationId, segmentIndex);
|
|
1873
|
+
},
|
|
1874
|
+
|
|
1875
|
+
/**
|
|
1876
|
+
* Deletes an entire segmentation
|
|
1877
|
+
* @param props.segmentationId - The ID of the segmentation to delete
|
|
1878
|
+
*/
|
|
1879
|
+
deleteSegmentationCommand: ({ segmentationId }) => {
|
|
1880
|
+
const { segmentationService } = servicesManager.services;
|
|
1881
|
+
segmentationService.remove(segmentationId);
|
|
1882
|
+
},
|
|
1883
|
+
|
|
1884
|
+
/**
|
|
1885
|
+
* Removes a segmentation from the viewport.
|
|
1886
|
+
*
|
|
1887
|
+
* This is the segmentation panel's Remove from Viewport, which lists the
|
|
1888
|
+
* segmentations of the study rather than the layers of one pane, so it is
|
|
1889
|
+
* the global statement: it un-hydrates the display set as well as clearing
|
|
1890
|
+
* it from the active viewport. The per-viewport equivalent is the viewport
|
|
1891
|
+
* data overlay menu's Remove, which runs `removeDisplaySetLayer` without
|
|
1892
|
+
* `unhydrate`.
|
|
1893
|
+
*
|
|
1894
|
+
* @param props.segmentationId - The ID of the segmentation to remove
|
|
1895
|
+
*/
|
|
1896
|
+
removeSegmentationFromViewportCommand: ({ segmentationId: displaySetInstanceUID }) => {
|
|
1897
|
+
const { viewportGridService } = servicesManager.services;
|
|
1898
|
+
const viewportId = viewportGridService.getActiveViewportId();
|
|
1899
|
+
|
|
1900
|
+
commandsManager.runCommand('removeDisplaySetLayer', {
|
|
1901
|
+
viewportId,
|
|
1902
|
+
displaySetInstanceUID,
|
|
1903
|
+
unhydrate: true,
|
|
1904
|
+
});
|
|
1905
|
+
},
|
|
1906
|
+
|
|
1907
|
+
/**
|
|
1908
|
+
* Toggles rendering of inactive segmentations
|
|
1909
|
+
*/
|
|
1910
|
+
toggleRenderInactiveSegmentationsCommand: () => {
|
|
1911
|
+
const { segmentationService, viewportGridService } = servicesManager.services;
|
|
1912
|
+
const viewportId = viewportGridService.getActiveViewportId();
|
|
1913
|
+
const renderInactive = segmentationService.getRenderInactiveSegmentations(viewportId);
|
|
1914
|
+
segmentationService.setRenderInactiveSegmentations(viewportId, !renderInactive);
|
|
1915
|
+
},
|
|
1916
|
+
|
|
1917
|
+
editSegmentLabel: async ({ segmentationId, segmentIndex }) => {
|
|
1918
|
+
const { segmentationService, uiDialogService } = servicesManager.services;
|
|
1919
|
+
const segmentation = segmentationService.getSegmentation(segmentationId);
|
|
1920
|
+
|
|
1921
|
+
if (!segmentation) {
|
|
1922
|
+
return;
|
|
1923
|
+
}
|
|
1924
|
+
|
|
1925
|
+
const segment = segmentation.segments[segmentIndex];
|
|
1926
|
+
|
|
1927
|
+
callInputDialog({
|
|
1928
|
+
uiDialogService,
|
|
1929
|
+
title: i18n.t('Tools:Edit Segment Label'),
|
|
1930
|
+
placeholder: i18n.t('Tools:Enter new label'),
|
|
1931
|
+
defaultValue: segment.label,
|
|
1932
|
+
}).then(label => {
|
|
1933
|
+
segmentationService.setSegmentLabel(segmentationId, segmentIndex, label);
|
|
1934
|
+
});
|
|
1935
|
+
},
|
|
1936
|
+
|
|
1937
|
+
editSegmentationLabel: ({ segmentationId }) => {
|
|
1938
|
+
const { segmentationService, uiDialogService } = servicesManager.services;
|
|
1939
|
+
const segmentation = segmentationService.getSegmentation(segmentationId);
|
|
1940
|
+
|
|
1941
|
+
if (!segmentation) {
|
|
1942
|
+
return;
|
|
1943
|
+
}
|
|
1944
|
+
|
|
1945
|
+
const { label } = segmentation;
|
|
1946
|
+
|
|
1947
|
+
callInputDialog({
|
|
1948
|
+
uiDialogService,
|
|
1949
|
+
title: i18n.t('Tools:Edit Segmentation Label'),
|
|
1950
|
+
placeholder: i18n.t('Tools:Enter new label'),
|
|
1951
|
+
defaultValue: label,
|
|
1952
|
+
}).then(label => {
|
|
1953
|
+
// The update clears `labelIsGenerated` - the user chose this label.
|
|
1954
|
+
segmentationService.addOrUpdateSegmentation({ segmentationId, label });
|
|
1955
|
+
});
|
|
1956
|
+
},
|
|
1957
|
+
|
|
1958
|
+
editSegmentColor: ({ segmentationId, segmentIndex }) => {
|
|
1959
|
+
const { segmentationService, uiDialogService, viewportGridService } =
|
|
1960
|
+
servicesManager.services;
|
|
1961
|
+
const viewportId = viewportGridService.getActiveViewportId();
|
|
1962
|
+
const color = segmentationService.getSegmentColor(viewportId, segmentationId, segmentIndex);
|
|
1963
|
+
|
|
1964
|
+
const rgbaColor = {
|
|
1965
|
+
r: color[0],
|
|
1966
|
+
g: color[1],
|
|
1967
|
+
b: color[2],
|
|
1968
|
+
a: color[3] / 255.0,
|
|
1969
|
+
};
|
|
1970
|
+
|
|
1971
|
+
uiDialogService.show({
|
|
1972
|
+
content: colorPickerDialog,
|
|
1973
|
+
title: i18n.t('Tools:Segment Color'),
|
|
1974
|
+
contentProps: {
|
|
1975
|
+
value: rgbaColor,
|
|
1976
|
+
onSave: newRgbaColor => {
|
|
1977
|
+
const color = [newRgbaColor.r, newRgbaColor.g, newRgbaColor.b, newRgbaColor.a * 255.0];
|
|
1978
|
+
segmentationService.setSegmentColor(viewportId, segmentationId, segmentIndex, color);
|
|
1979
|
+
},
|
|
1980
|
+
},
|
|
1981
|
+
});
|
|
1982
|
+
},
|
|
1983
|
+
|
|
1984
|
+
getRenderInactiveSegmentations: () => {
|
|
1985
|
+
const { segmentationService, viewportGridService } = servicesManager.services;
|
|
1986
|
+
return segmentationService.getRenderInactiveSegmentations(
|
|
1987
|
+
viewportGridService.getActiveViewportId()
|
|
1988
|
+
);
|
|
1989
|
+
},
|
|
1990
|
+
|
|
1991
|
+
deleteActiveAnnotation: () => {
|
|
1992
|
+
const activeAnnotationsUID = cornerstoneTools.annotation.selection.getAnnotationsSelected();
|
|
1993
|
+
activeAnnotationsUID.forEach(activeAnnotationUID => {
|
|
1994
|
+
measurementService.remove(activeAnnotationUID);
|
|
1995
|
+
});
|
|
1996
|
+
},
|
|
1997
|
+
setDisplaySetsForViewports: ({ viewportsToUpdate }) => {
|
|
1998
|
+
const { cineService, viewportGridService } = servicesManager.services;
|
|
1999
|
+
// Stopping the cine of modified viewports before changing the viewports to
|
|
2000
|
+
// avoid inconsistent state and lost references
|
|
2001
|
+
viewportsToUpdate.forEach(viewport => {
|
|
2002
|
+
const state = cineService.getState();
|
|
2003
|
+
const currentCineState = state.cines?.[viewport.viewportId];
|
|
2004
|
+
cineService.setCine({
|
|
2005
|
+
id: viewport.viewportId,
|
|
2006
|
+
frameRate: currentCineState?.frameRate ?? state.default?.frameRate ?? 24,
|
|
2007
|
+
isPlaying: false,
|
|
2008
|
+
});
|
|
2009
|
+
});
|
|
2010
|
+
|
|
2011
|
+
viewportGridService.setDisplaySetsForViewports(viewportsToUpdate);
|
|
2012
|
+
},
|
|
2013
|
+
undo: () => {
|
|
2014
|
+
DefaultHistoryMemo.undo();
|
|
2015
|
+
},
|
|
2016
|
+
redo: () => {
|
|
2017
|
+
DefaultHistoryMemo.redo();
|
|
2018
|
+
},
|
|
2019
|
+
toggleSegmentPreviewEdit: ({ toggle }) => {
|
|
2020
|
+
let labelmapTools = getLabelmapTools({ toolGroupService });
|
|
2021
|
+
labelmapTools = labelmapTools.filter(tool => !tool.toolName.includes('Eraser'));
|
|
2022
|
+
labelmapTools.forEach(tool => {
|
|
2023
|
+
tool.configuration = {
|
|
2024
|
+
...tool.configuration,
|
|
2025
|
+
preview: {
|
|
2026
|
+
...tool.configuration.preview,
|
|
2027
|
+
enabled: toggle,
|
|
2028
|
+
},
|
|
2029
|
+
};
|
|
2030
|
+
});
|
|
2031
|
+
},
|
|
2032
|
+
toggleSegmentSelect: ({ toggle }) => {
|
|
2033
|
+
const toolGroupIds = toolGroupService.getToolGroupIds();
|
|
2034
|
+
toolGroupIds.forEach(toolGroupId => {
|
|
2035
|
+
const toolGroup = cornerstoneTools.ToolGroupManager.getToolGroup(toolGroupId);
|
|
2036
|
+
if (toggle) {
|
|
2037
|
+
toolGroup.setToolActive(cornerstoneTools.SegmentSelectTool.toolName);
|
|
2038
|
+
} else {
|
|
2039
|
+
toolGroup.setToolDisabled(cornerstoneTools.SegmentSelectTool.toolName);
|
|
2040
|
+
}
|
|
2041
|
+
});
|
|
2042
|
+
},
|
|
2043
|
+
toggleSegmentLabel: ({ enabled }: { enabled?: boolean }) => {
|
|
2044
|
+
const toolName = cornerstoneTools.SegmentLabelTool.toolName;
|
|
2045
|
+
const toolGroupIds = toolGroupService.getToolGroupIds();
|
|
2046
|
+
|
|
2047
|
+
const isToolOn = toolGroupIds.some(toolGroupId => {
|
|
2048
|
+
const toolGroup = cornerstoneTools.ToolGroupManager.getToolGroup(toolGroupId);
|
|
2049
|
+
const mode = toolGroup.getToolInstance(toolName)?.mode;
|
|
2050
|
+
return mode === 'Active';
|
|
2051
|
+
});
|
|
2052
|
+
|
|
2053
|
+
const enableTool = enabled !== undefined ? enabled : !isToolOn;
|
|
2054
|
+
|
|
2055
|
+
toolGroupIds.forEach(toolGroupId => {
|
|
2056
|
+
const toolGroup = cornerstoneTools.ToolGroupManager.getToolGroup(toolGroupId);
|
|
2057
|
+
if (enableTool) {
|
|
2058
|
+
toolGroup.setToolActive(toolName);
|
|
2059
|
+
} else {
|
|
2060
|
+
toolGroup.setToolDisabled(toolName);
|
|
2061
|
+
}
|
|
2062
|
+
});
|
|
2063
|
+
},
|
|
2064
|
+
/**
|
|
2065
|
+
* Used to sync the apps initial state with the config file settings.
|
|
2066
|
+
*
|
|
2067
|
+
* Will mutate the tools object of the given tool group and add the segmentLabelTool to the proper place.
|
|
2068
|
+
*
|
|
2069
|
+
* Use it before initializing the toolGroup with the tools.
|
|
2070
|
+
*/
|
|
2071
|
+
initializeSegmentLabelTool: ({ tools }) => {
|
|
2072
|
+
const { customizationService } = servicesManager.services;
|
|
2073
|
+
const segmentLabelConfig = customizationService.getCustomization(
|
|
2074
|
+
'segmentation.segmentLabel'
|
|
2075
|
+
) as {
|
|
2076
|
+
enabledByDefault?: boolean;
|
|
2077
|
+
labelColor?: number[];
|
|
2078
|
+
hoverTimeout?: number;
|
|
2079
|
+
background?: string;
|
|
2080
|
+
};
|
|
2081
|
+
|
|
2082
|
+
if (segmentLabelConfig?.enabledByDefault) {
|
|
2083
|
+
const activeTools = tools?.active ?? [];
|
|
2084
|
+
activeTools.push({
|
|
2085
|
+
toolName: toolNames.SegmentLabel,
|
|
2086
|
+
configuration: {
|
|
2087
|
+
hoverTimeout: segmentLabelConfig?.hoverTimeout ?? 1,
|
|
2088
|
+
color: segmentLabelConfig?.labelColor,
|
|
2089
|
+
background: segmentLabelConfig?.background,
|
|
2090
|
+
},
|
|
2091
|
+
});
|
|
2092
|
+
|
|
2093
|
+
tools.active = activeTools;
|
|
2094
|
+
return tools;
|
|
2095
|
+
}
|
|
2096
|
+
|
|
2097
|
+
const disabledTools = tools?.disabled ?? [];
|
|
2098
|
+
disabledTools.push({
|
|
2099
|
+
toolName: toolNames.SegmentLabel,
|
|
2100
|
+
configuration: {
|
|
2101
|
+
hoverTimeout: segmentLabelConfig?.hoverTimeout ?? 1,
|
|
2102
|
+
color: segmentLabelConfig?.labelColor,
|
|
2103
|
+
},
|
|
2104
|
+
});
|
|
2105
|
+
tools.disabled = disabledTools;
|
|
2106
|
+
return tools;
|
|
2107
|
+
},
|
|
2108
|
+
toggleUseCenterSegmentIndex: ({ toggle }) => {
|
|
2109
|
+
let labelmapTools = getLabelmapTools({ toolGroupService });
|
|
2110
|
+
labelmapTools = labelmapTools.filter(tool => !tool.toolName.includes('Eraser'));
|
|
2111
|
+
labelmapTools.forEach(tool => {
|
|
2112
|
+
tool.configuration = {
|
|
2113
|
+
...tool.configuration,
|
|
2114
|
+
useCenterSegmentIndex: toggle,
|
|
2115
|
+
};
|
|
2116
|
+
});
|
|
2117
|
+
},
|
|
2118
|
+
_handlePreviewAction: action => {
|
|
2119
|
+
// May be undefined when no viewport is enabled (e.g. Escape pressed while
|
|
2120
|
+
// a modal such as Preferences is open).
|
|
2121
|
+
const enabledElement = _getActiveViewportEnabledElement();
|
|
2122
|
+
const previewTools = getPreviewTools({ toolGroupService });
|
|
2123
|
+
|
|
2124
|
+
previewTools.forEach(tool => {
|
|
2125
|
+
try {
|
|
2126
|
+
tool[`${action}Preview`]();
|
|
2127
|
+
} catch (error) {
|
|
2128
|
+
console.debug('Error accepting preview for tool', tool.toolName);
|
|
2129
|
+
}
|
|
2130
|
+
});
|
|
2131
|
+
|
|
2132
|
+
if (segmentAI.enabled) {
|
|
2133
|
+
segmentAI[`${action}Preview`](enabledElement?.viewport?.element);
|
|
2134
|
+
}
|
|
2135
|
+
},
|
|
2136
|
+
acceptPreview: () => {
|
|
2137
|
+
actions._handlePreviewAction('accept');
|
|
2138
|
+
},
|
|
2139
|
+
rejectPreview: () => {
|
|
2140
|
+
actions._handlePreviewAction('reject');
|
|
2141
|
+
},
|
|
2142
|
+
/**
|
|
2143
|
+
* Generic Escape handler. A single Escape press should discard whatever the
|
|
2144
|
+
* user has in progress, but that can be one of two unrelated things: a
|
|
2145
|
+
* provisional segmentation preview, or an annotation being drawn. Rather
|
|
2146
|
+
* than bind both `rejectPreview` and `cancelMeasurement` to `esc` (Mousetrap
|
|
2147
|
+
* keeps only one handler per key, so the second silently shadows the first),
|
|
2148
|
+
* this command orchestrates both single-purpose commands. Each is a no-op
|
|
2149
|
+
* when its state is not active, so running both is safe and order-independent.
|
|
2150
|
+
*/
|
|
2151
|
+
cancelActiveOperation: () => {
|
|
2152
|
+
try {
|
|
2153
|
+
actions.rejectPreview();
|
|
2154
|
+
} catch (error) {
|
|
2155
|
+
console.debug('Error rejecting active preview', error);
|
|
2156
|
+
} finally {
|
|
2157
|
+
actions.cancelMeasurement();
|
|
2158
|
+
}
|
|
2159
|
+
},
|
|
2160
|
+
clearMarkersForMarkerLabelmap: () => {
|
|
2161
|
+
const { viewport } = _getActiveViewportEnabledElement();
|
|
2162
|
+
const toolGroup = cornerstoneTools.ToolGroupManager.getToolGroupForViewport(viewport.id);
|
|
2163
|
+
const toolInstance = toolGroup.getToolInstance('MarkerLabelmap');
|
|
2164
|
+
|
|
2165
|
+
if (!toolInstance) {
|
|
2166
|
+
return;
|
|
2167
|
+
}
|
|
2168
|
+
|
|
2169
|
+
toolInstance.clearMarkers(viewport);
|
|
2170
|
+
},
|
|
2171
|
+
interpolateScrollForMarkerLabelmap: () => {
|
|
2172
|
+
const { viewport } = _getActiveViewportEnabledElement();
|
|
2173
|
+
const toolGroup = cornerstoneTools.ToolGroupManager.getToolGroupForViewport(viewport.id);
|
|
2174
|
+
const toolInstance = toolGroup.getToolInstance('MarkerLabelmap');
|
|
2175
|
+
|
|
2176
|
+
if (!toolInstance) {
|
|
2177
|
+
return;
|
|
2178
|
+
}
|
|
2179
|
+
|
|
2180
|
+
toolInstance.interpolateScroll(viewport, 1);
|
|
2181
|
+
},
|
|
2182
|
+
toggleLabelmapAssist: async () => {
|
|
2183
|
+
const { viewport } = _getActiveViewportEnabledElement();
|
|
2184
|
+
const newState = !segmentAI.enabled;
|
|
2185
|
+
segmentAI.enabled = newState;
|
|
2186
|
+
|
|
2187
|
+
if (!segmentAIEnabled) {
|
|
2188
|
+
await segmentAI.initModel();
|
|
2189
|
+
segmentAIEnabled = true;
|
|
2190
|
+
}
|
|
2191
|
+
|
|
2192
|
+
// set the brush tool to active
|
|
2193
|
+
const toolGroupIds = toolGroupService.getToolGroupIds();
|
|
2194
|
+
if (newState) {
|
|
2195
|
+
actions.setToolActiveToolbar({
|
|
2196
|
+
toolName: 'CircularBrushForAutoSegmentAI',
|
|
2197
|
+
toolGroupIds: toolGroupIds,
|
|
2198
|
+
});
|
|
2199
|
+
} else {
|
|
2200
|
+
toolGroupIds.forEach(toolGroupId => {
|
|
2201
|
+
const toolGroup = cornerstoneTools.ToolGroupManager.getToolGroup(toolGroupId);
|
|
2202
|
+
toolGroup.setToolPassive('CircularBrushForAutoSegmentAI');
|
|
2203
|
+
});
|
|
2204
|
+
}
|
|
2205
|
+
|
|
2206
|
+
if (segmentAI.enabled) {
|
|
2207
|
+
segmentAI.initViewport(viewport);
|
|
2208
|
+
}
|
|
2209
|
+
},
|
|
2210
|
+
setBrushSize: ({ value }) => {
|
|
2211
|
+
const brushSize = Number(value);
|
|
2212
|
+
|
|
2213
|
+
toolGroupService.getToolGroupIds()?.forEach(toolGroupId => {
|
|
2214
|
+
segmentationUtils.setBrushSizeForToolGroup(toolGroupId, brushSize);
|
|
2215
|
+
});
|
|
2216
|
+
},
|
|
2217
|
+
setThresholdRange: ({
|
|
2218
|
+
value,
|
|
2219
|
+
toolNames = [
|
|
2220
|
+
'ThresholdCircularBrush',
|
|
2221
|
+
'ThresholdSphereBrush',
|
|
2222
|
+
'ThresholdCircularBrushDynamic',
|
|
2223
|
+
'ThresholdSphereBrushDynamic',
|
|
2224
|
+
],
|
|
2225
|
+
}) => {
|
|
2226
|
+
const toolGroupIds = toolGroupService.getToolGroupIds();
|
|
2227
|
+
if (!toolGroupIds?.length) {
|
|
2228
|
+
return;
|
|
2229
|
+
}
|
|
2230
|
+
|
|
2231
|
+
for (const toolGroupId of toolGroupIds) {
|
|
2232
|
+
const toolGroup = toolGroupService.getToolGroup(toolGroupId);
|
|
2233
|
+
toolNames?.forEach(toolName => {
|
|
2234
|
+
toolGroup.setToolConfiguration(toolName, {
|
|
2235
|
+
threshold: {
|
|
2236
|
+
range: value,
|
|
2237
|
+
},
|
|
2238
|
+
});
|
|
2239
|
+
});
|
|
2240
|
+
}
|
|
2241
|
+
},
|
|
2242
|
+
increaseBrushSize: () => {
|
|
2243
|
+
_handleBrushSizeAction('increase');
|
|
2244
|
+
},
|
|
2245
|
+
decreaseBrushSize: () => {
|
|
2246
|
+
_handleBrushSizeAction('decrease');
|
|
2247
|
+
},
|
|
2248
|
+
addNewSegment: () => {
|
|
2249
|
+
const { segmentationService } = servicesManager.services;
|
|
2250
|
+
const { activeViewportId } = viewportGridService.getState();
|
|
2251
|
+
const activeSegmentation = segmentationService.getActiveSegmentation(activeViewportId);
|
|
2252
|
+
if (!activeSegmentation) {
|
|
2253
|
+
return;
|
|
2254
|
+
}
|
|
2255
|
+
segmentationService.addSegment(activeSegmentation.segmentationId);
|
|
2256
|
+
},
|
|
2257
|
+
loadSegmentationDisplaySetsForViewport: ({
|
|
2258
|
+
viewportId,
|
|
2259
|
+
displaySetInstanceUIDs,
|
|
2260
|
+
viewportType,
|
|
2261
|
+
// The SEG/RTSTRUCT being hydrated. Passing it lets the target selection
|
|
2262
|
+
// include panes that share its frame of reference rather than only those
|
|
2263
|
+
// hung with the exact referenced display set, and lets it work when there
|
|
2264
|
+
// is no viewport to match against at all.
|
|
2265
|
+
derivedDisplaySetInstanceUID,
|
|
2266
|
+
}) => {
|
|
2267
|
+
const updatedViewports = getUpdatedViewportsForSegmentation({
|
|
2268
|
+
viewportId,
|
|
2269
|
+
servicesManager,
|
|
2270
|
+
displaySetInstanceUIDs,
|
|
2271
|
+
derivedDisplaySetInstanceUID,
|
|
2272
|
+
});
|
|
2273
|
+
|
|
2274
|
+
if (!updatedViewports?.length) {
|
|
2275
|
+
return;
|
|
2276
|
+
}
|
|
2277
|
+
|
|
2278
|
+
updatedViewports.forEach(({ viewportId: csViewportId }) => {
|
|
2279
|
+
const csViewport = cornerstoneViewportService.getCornerstoneViewport(csViewportId);
|
|
2280
|
+
csViewport?.setNeedsRender?.();
|
|
2281
|
+
});
|
|
2282
|
+
|
|
2283
|
+
// A pinned viewportType (RTSTRUCT contour hydration on a native "next"
|
|
2284
|
+
// viewport requests 'stack') is a statement about the pane hydration was
|
|
2285
|
+
// invoked on, whose background is being set to the referenced image. The
|
|
2286
|
+
// other panes here were matched because they already show something the
|
|
2287
|
+
// segmentation can be drawn over - by frame of reference, and keeping the
|
|
2288
|
+
// display sets they already have - so their own render mode is the right
|
|
2289
|
+
// one and forcing 'stack' onto them would flip an MPR pane to a stack.
|
|
2290
|
+
// Note the merged entries carry no viewportOptions at all, so the grid
|
|
2291
|
+
// reducer would merge a bare `{ viewportType }` straight over the pane's
|
|
2292
|
+
// real options.
|
|
2293
|
+
const targetViewportId = viewportId || viewportGridService.getActiveViewportId();
|
|
2294
|
+
|
|
2295
|
+
actions.setDisplaySetsForViewports({
|
|
2296
|
+
viewportsToUpdate: updatedViewports.map(viewport => ({
|
|
2297
|
+
viewportId: viewport.viewportId,
|
|
2298
|
+
displaySetInstanceUIDs: viewport.displaySetInstanceUIDs,
|
|
2299
|
+
...(viewportType && viewport.viewportId === targetViewportId
|
|
2300
|
+
? { viewportOptions: { ...viewport.viewportOptions, viewportType } }
|
|
2301
|
+
: {}),
|
|
2302
|
+
})),
|
|
2303
|
+
});
|
|
2304
|
+
},
|
|
2305
|
+
setViewportOrientation: ({ viewportId, orientation }) => {
|
|
2306
|
+
const viewport = cornerstoneViewportService.getCornerstoneViewport(viewportId);
|
|
2307
|
+
|
|
2308
|
+
// Accept any viewport already rendering volume content (legacy ORTHOGRAPHIC
|
|
2309
|
+
// or a native viewport in volume mode) — both expose setOrientation().
|
|
2310
|
+
if (!viewport || !getViewportAdapter(viewport).canReorientInPlace()) {
|
|
2311
|
+
console.warn('Orientation can only be set on volume viewports');
|
|
2312
|
+
return;
|
|
2313
|
+
}
|
|
2314
|
+
|
|
2315
|
+
// Get display sets for this viewport to verify at least one is reconstructable
|
|
2316
|
+
const displaySetUIDs = viewportGridService.getDisplaySetsUIDsForViewport(viewportId);
|
|
2317
|
+
const displaySets = displaySetUIDs.map(uid => displaySetService.getDisplaySetByUID(uid));
|
|
2318
|
+
|
|
2319
|
+
if (!displaySets.some(ds => ds.isReconstructable)) {
|
|
2320
|
+
console.warn('Cannot change orientation: No reconstructable display sets in viewport');
|
|
2321
|
+
return;
|
|
2322
|
+
}
|
|
2323
|
+
|
|
2324
|
+
viewport.setOrientation(orientation);
|
|
2325
|
+
viewport.render();
|
|
2326
|
+
|
|
2327
|
+
// update the orientation in the viewport info
|
|
2328
|
+
const viewportInfo = cornerstoneViewportService.getViewportInfo(viewportId);
|
|
2329
|
+
viewportInfo.setOrientation(orientation);
|
|
2330
|
+
},
|
|
2331
|
+
/**
|
|
2332
|
+
* Toggles the horizontal flip state of the viewport.
|
|
2333
|
+
*/
|
|
2334
|
+
toggleViewportHorizontalFlip: ({ viewportId }: { viewportId?: string } = {}) => {
|
|
2335
|
+
actions.flipViewportHorizontal({ viewportId, newValue: 'toggle' });
|
|
2336
|
+
},
|
|
2337
|
+
|
|
2338
|
+
/**
|
|
2339
|
+
* Explicitly sets the horizontal flip state of the viewport.
|
|
2340
|
+
*/
|
|
2341
|
+
setViewportHorizontalFlip: ({
|
|
2342
|
+
flipped,
|
|
2343
|
+
viewportId,
|
|
2344
|
+
}: {
|
|
2345
|
+
flipped: boolean;
|
|
2346
|
+
viewportId?: string;
|
|
2347
|
+
}) => {
|
|
2348
|
+
actions.flipViewportHorizontal({ viewportId, newValue: flipped });
|
|
2349
|
+
},
|
|
2350
|
+
|
|
2351
|
+
/**
|
|
2352
|
+
* Toggles the vertical flip state of the viewport.
|
|
2353
|
+
*/
|
|
2354
|
+
toggleViewportVerticalFlip: ({ viewportId }: { viewportId?: string } = {}) => {
|
|
2355
|
+
actions.flipViewportVertical({ viewportId, newValue: 'toggle' });
|
|
2356
|
+
},
|
|
2357
|
+
|
|
2358
|
+
/**
|
|
2359
|
+
* Explicitly sets the vertical flip state of the viewport.
|
|
2360
|
+
*/
|
|
2361
|
+
setViewportVerticalFlip: ({
|
|
2362
|
+
flipped,
|
|
2363
|
+
viewportId,
|
|
2364
|
+
}: {
|
|
2365
|
+
flipped: boolean;
|
|
2366
|
+
viewportId?: string;
|
|
2367
|
+
}) => {
|
|
2368
|
+
actions.flipViewportVertical({ viewportId, newValue: flipped });
|
|
2369
|
+
},
|
|
2370
|
+
/**
|
|
2371
|
+
* Internal helper to rotate or set absolute rotation for a viewport.
|
|
2372
|
+
*/
|
|
2373
|
+
_rotateViewport: ({
|
|
2374
|
+
rotation,
|
|
2375
|
+
viewportId,
|
|
2376
|
+
rotationMode = 'apply',
|
|
2377
|
+
}: {
|
|
2378
|
+
rotation: number;
|
|
2379
|
+
viewportId?: string;
|
|
2380
|
+
rotationMode?: 'apply' | 'set';
|
|
2381
|
+
}) => {
|
|
2382
|
+
const viewport = _resolveViewport(viewportId);
|
|
2383
|
+
if (!viewport) {
|
|
2384
|
+
return;
|
|
2385
|
+
}
|
|
2386
|
+
ops.rotate(viewport, rotation, rotationMode);
|
|
2387
|
+
viewport.render();
|
|
2388
|
+
},
|
|
2389
|
+
startRecordingForAnnotationGroup: () => {
|
|
2390
|
+
cornerstoneTools.AnnotationTool.startGroupRecording();
|
|
2391
|
+
},
|
|
2392
|
+
endRecordingForAnnotationGroup: () => {
|
|
2393
|
+
cornerstoneTools.AnnotationTool.endGroupRecording();
|
|
2394
|
+
},
|
|
2395
|
+
triggerCreateAnnotationMemo: ({
|
|
2396
|
+
annotation,
|
|
2397
|
+
FrameOfReferenceUID,
|
|
2398
|
+
options,
|
|
2399
|
+
}: {
|
|
2400
|
+
annotation: ToolTypes.Annotation;
|
|
2401
|
+
FrameOfReferenceUID: string;
|
|
2402
|
+
options: { newAnnotation?: boolean; deleting?: boolean };
|
|
2403
|
+
}): void => {
|
|
2404
|
+
const { newAnnotation, deleting } = options;
|
|
2405
|
+
const renderingEngines = getRenderingEngines();
|
|
2406
|
+
const viewports = renderingEngines.flatMap(re => re.getViewports());
|
|
2407
|
+
const validViewport = viewports.find(
|
|
2408
|
+
vp => vp.getFrameOfReferenceUID() === FrameOfReferenceUID
|
|
2409
|
+
);
|
|
2410
|
+
|
|
2411
|
+
if (!validViewport) {
|
|
2412
|
+
return;
|
|
2413
|
+
}
|
|
2414
|
+
|
|
2415
|
+
cornerstoneTools.AnnotationTool.createAnnotationMemo(validViewport.element, annotation, {
|
|
2416
|
+
newAnnotation,
|
|
2417
|
+
deleting,
|
|
2418
|
+
});
|
|
2419
|
+
},
|
|
2420
|
+
activateSelectedSegmentationOfType: ({ segmentationRepresentationType }) => {
|
|
2421
|
+
const { segmentationService, viewportGridService } = servicesManager.services;
|
|
2422
|
+
const activeViewportId = viewportGridService.getActiveViewportId();
|
|
2423
|
+
const { selectedSegmentationsForViewport } =
|
|
2424
|
+
useSelectedSegmentationsForViewportStore.getState();
|
|
2425
|
+
const segmentationId = selectedSegmentationsForViewport[activeViewportId]?.get(
|
|
2426
|
+
segmentationRepresentationType
|
|
2427
|
+
);
|
|
2428
|
+
|
|
2429
|
+
if (!segmentationId) {
|
|
2430
|
+
return;
|
|
2431
|
+
}
|
|
2432
|
+
|
|
2433
|
+
segmentationService.setActiveSegmentation(activeViewportId, segmentationId);
|
|
2434
|
+
},
|
|
2435
|
+
setDynamicCursorSizeForSculptorTool: ({ value: isDynamicCursorSize }) => {
|
|
2436
|
+
const viewportId = viewportGridService.getActiveViewportId();
|
|
2437
|
+
const toolGroup = toolGroupService.getToolGroupForViewport(viewportId);
|
|
2438
|
+
const sculptorToolInstance = toolGroup.getToolInstance(toolNames.SculptorTool);
|
|
2439
|
+
const oldConfiguration = sculptorToolInstance.configuration;
|
|
2440
|
+
|
|
2441
|
+
sculptorToolInstance.configuration = {
|
|
2442
|
+
...oldConfiguration,
|
|
2443
|
+
updateCursorSize: isDynamicCursorSize ? 'dynamic' : '',
|
|
2444
|
+
};
|
|
2445
|
+
},
|
|
2446
|
+
setInterpolationToolConfiguration: ({ value: interpolateContours, toolNames }) => {
|
|
2447
|
+
const viewportId = viewportGridService.getActiveViewportId();
|
|
2448
|
+
const toolGroup = toolGroupService.getToolGroupForViewport(viewportId);
|
|
2449
|
+
|
|
2450
|
+
// Set the interpolation configuration for the active tool.
|
|
2451
|
+
const activeTool = toolGroupService.getActiveToolForViewport(viewportId);
|
|
2452
|
+
const interpolationConfig = {
|
|
2453
|
+
interpolation: {
|
|
2454
|
+
enabled: interpolateContours,
|
|
2455
|
+
},
|
|
2456
|
+
};
|
|
2457
|
+
toolGroup.setToolConfiguration(activeTool, interpolationConfig);
|
|
2458
|
+
|
|
2459
|
+
// Now set the interpolation configuration for the other tools specified.
|
|
2460
|
+
if (toolNames) {
|
|
2461
|
+
Object.values(toolGroup.getToolInstances()).forEach(toolInstance => {
|
|
2462
|
+
if (toolNames?.includes(toolInstance.toolName)) {
|
|
2463
|
+
toolGroup.setToolConfiguration(toolInstance.toolName, interpolationConfig);
|
|
2464
|
+
}
|
|
2465
|
+
});
|
|
2466
|
+
}
|
|
2467
|
+
},
|
|
2468
|
+
setSimplifiedSplineForSplineContourSegmentationTool: ({ value: simplifiedSpline }) => {
|
|
2469
|
+
const viewportId = viewportGridService.getActiveViewportId();
|
|
2470
|
+
const toolGroup = toolGroupService.getToolGroupForViewport(viewportId);
|
|
2471
|
+
Object.values(toolGroup.getToolInstances()).forEach(toolInstance => {
|
|
2472
|
+
if (toolInstance instanceof SplineContourSegmentationTool) {
|
|
2473
|
+
const oldConfiguration = toolInstance.configuration;
|
|
2474
|
+
toolInstance.configuration = {
|
|
2475
|
+
...oldConfiguration,
|
|
2476
|
+
simplifiedSpline,
|
|
2477
|
+
};
|
|
2478
|
+
}
|
|
2479
|
+
});
|
|
2480
|
+
},
|
|
2481
|
+
removeSmallContours: ({ areaThreshold: threshold }) => {
|
|
2482
|
+
const viewportId = viewportGridService.getActiveViewportId();
|
|
2483
|
+
const activeSegmentation = segmentationService.getActiveSegmentation(viewportId);
|
|
2484
|
+
const activeSegment = segmentationService.getActiveSegment(viewportId);
|
|
2485
|
+
|
|
2486
|
+
if (!activeSegmentation || !activeSegment) {
|
|
2487
|
+
return;
|
|
2488
|
+
}
|
|
2489
|
+
|
|
2490
|
+
const { removeContourIslands } = segmentationUtilities;
|
|
2491
|
+
removeContourIslands(activeSegmentation.segmentationId, activeSegment.segmentIndex, {
|
|
2492
|
+
threshold,
|
|
2493
|
+
});
|
|
2494
|
+
const renderingEngine = cornerstoneViewportService.getRenderingEngine();
|
|
2495
|
+
renderingEngine.render();
|
|
2496
|
+
},
|
|
2497
|
+
applyLogicalContourOperation: ({
|
|
2498
|
+
segmentAInfo,
|
|
2499
|
+
segmentBInfo,
|
|
2500
|
+
resultSegmentInfo,
|
|
2501
|
+
logicalOperation,
|
|
2502
|
+
}: {
|
|
2503
|
+
segmentAInfo: SegmentInfo;
|
|
2504
|
+
segmentBInfo: SegmentInfo;
|
|
2505
|
+
resultSegmentInfo: OperatorOptions;
|
|
2506
|
+
logicalOperation: LogicalOperation;
|
|
2507
|
+
}) => {
|
|
2508
|
+
switch (logicalOperation) {
|
|
2509
|
+
case LogicalOperation.Union:
|
|
2510
|
+
add(segmentAInfo, segmentBInfo, resultSegmentInfo);
|
|
2511
|
+
break;
|
|
2512
|
+
case LogicalOperation.Intersect:
|
|
2513
|
+
intersect(segmentAInfo, segmentBInfo, resultSegmentInfo);
|
|
2514
|
+
break;
|
|
2515
|
+
case LogicalOperation.Subtract:
|
|
2516
|
+
subtract(segmentAInfo, segmentBInfo, resultSegmentInfo);
|
|
2517
|
+
break;
|
|
2518
|
+
default:
|
|
2519
|
+
throw new Error('Unsupported logical operation');
|
|
2520
|
+
}
|
|
2521
|
+
},
|
|
2522
|
+
copyContourSegment: ({
|
|
2523
|
+
sourceSegmentInfo,
|
|
2524
|
+
targetSegmentInfo,
|
|
2525
|
+
}: {
|
|
2526
|
+
sourceSegmentInfo: SegmentInfo;
|
|
2527
|
+
targetSegmentInfo?: SegmentInfo;
|
|
2528
|
+
}) => {
|
|
2529
|
+
if (!targetSegmentInfo) {
|
|
2530
|
+
const sourceSegmentation = segmentationService.getSegmentation(
|
|
2531
|
+
sourceSegmentInfo.segmentationId
|
|
2532
|
+
);
|
|
2533
|
+
const sourceCachedStats =
|
|
2534
|
+
sourceSegmentation?.segments?.[sourceSegmentInfo.segmentIndex]?.cachedStats;
|
|
2535
|
+
|
|
2536
|
+
targetSegmentInfo = {
|
|
2537
|
+
segmentationId: sourceSegmentInfo.segmentationId,
|
|
2538
|
+
segmentIndex: segmentationService.getNextAvailableSegmentIndex(
|
|
2539
|
+
sourceSegmentInfo.segmentationId
|
|
2540
|
+
),
|
|
2541
|
+
};
|
|
2542
|
+
|
|
2543
|
+
// Copy source cachedStats so jump-to-segment navigation works on the duplicate segment.
|
|
2544
|
+
segmentationService.addSegment(targetSegmentInfo.segmentationId, {
|
|
2545
|
+
segmentIndex: targetSegmentInfo.segmentIndex,
|
|
2546
|
+
...(sourceCachedStats && {
|
|
2547
|
+
cachedStats: csUtils.deepClone(sourceCachedStats) as Record<string, unknown>,
|
|
2548
|
+
}),
|
|
2549
|
+
});
|
|
2550
|
+
}
|
|
2551
|
+
|
|
2552
|
+
copy(sourceSegmentInfo, targetSegmentInfo);
|
|
2553
|
+
},
|
|
2554
|
+
smoothContours: () => {
|
|
2555
|
+
const viewportId = viewportGridService.getActiveViewportId();
|
|
2556
|
+
const activeSegmentation = segmentationService.getActiveSegmentation(viewportId);
|
|
2557
|
+
const activeSegment = segmentationService.getActiveSegment(viewportId);
|
|
2558
|
+
|
|
2559
|
+
if (!activeSegmentation || !activeSegment) {
|
|
2560
|
+
return;
|
|
2561
|
+
}
|
|
2562
|
+
|
|
2563
|
+
const { smoothContours } = segmentationUtilities;
|
|
2564
|
+
smoothContours(activeSegmentation.segmentationId, activeSegment.segmentIndex);
|
|
2565
|
+
|
|
2566
|
+
const renderingEngine = cornerstoneViewportService.getRenderingEngine();
|
|
2567
|
+
renderingEngine.render();
|
|
2568
|
+
},
|
|
2569
|
+
removeContourHoles: () => {
|
|
2570
|
+
const viewportId = viewportGridService.getActiveViewportId();
|
|
2571
|
+
const activeSegmentation = segmentationService.getActiveSegmentation(viewportId);
|
|
2572
|
+
const activeSegment = segmentationService.getActiveSegment(viewportId);
|
|
2573
|
+
|
|
2574
|
+
if (!activeSegmentation || !activeSegment) {
|
|
2575
|
+
return;
|
|
2576
|
+
}
|
|
2577
|
+
|
|
2578
|
+
const { removeContourHoles } = segmentationUtilities;
|
|
2579
|
+
removeContourHoles(activeSegmentation.segmentationId, activeSegment.segmentIndex);
|
|
2580
|
+
|
|
2581
|
+
const renderingEngine = cornerstoneViewportService.getRenderingEngine();
|
|
2582
|
+
renderingEngine.render();
|
|
2583
|
+
},
|
|
2584
|
+
decimateContours: () => {
|
|
2585
|
+
const viewportId = viewportGridService.getActiveViewportId();
|
|
2586
|
+
const activeSegmentation = segmentationService.getActiveSegmentation(viewportId);
|
|
2587
|
+
const activeSegment = segmentationService.getActiveSegment(viewportId);
|
|
2588
|
+
|
|
2589
|
+
if (!activeSegmentation || !activeSegment) {
|
|
2590
|
+
return;
|
|
2591
|
+
}
|
|
2592
|
+
|
|
2593
|
+
const { decimateContours } = segmentationUtilities;
|
|
2594
|
+
decimateContours(activeSegmentation.segmentationId, activeSegment.segmentIndex);
|
|
2595
|
+
|
|
2596
|
+
const renderingEngine = cornerstoneViewportService.getRenderingEngine();
|
|
2597
|
+
renderingEngine.render();
|
|
2598
|
+
},
|
|
2599
|
+
convertContourHoles: () => {
|
|
2600
|
+
const viewportId = viewportGridService.getActiveViewportId();
|
|
2601
|
+
const activeSegmentation = segmentationService.getActiveSegmentation(viewportId);
|
|
2602
|
+
const activeSegment = segmentationService.getActiveSegment(viewportId);
|
|
2603
|
+
|
|
2604
|
+
if (!activeSegmentation || !activeSegment) {
|
|
2605
|
+
return;
|
|
2606
|
+
}
|
|
2607
|
+
|
|
2608
|
+
const targetSegmentInfo = {
|
|
2609
|
+
segmentationId: activeSegmentation.segmentationId,
|
|
2610
|
+
segmentIndex: segmentationService.getNextAvailableSegmentIndex(
|
|
2611
|
+
activeSegmentation.segmentationId
|
|
2612
|
+
),
|
|
2613
|
+
};
|
|
2614
|
+
|
|
2615
|
+
segmentationService.addSegment(targetSegmentInfo.segmentationId, {
|
|
2616
|
+
segmentIndex: targetSegmentInfo.segmentIndex,
|
|
2617
|
+
});
|
|
2618
|
+
|
|
2619
|
+
const { convertContourHoles } = segmentationUtilities;
|
|
2620
|
+
convertContourHoles(
|
|
2621
|
+
activeSegmentation.segmentationId,
|
|
2622
|
+
activeSegment.segmentIndex,
|
|
2623
|
+
targetSegmentInfo.segmentationId,
|
|
2624
|
+
targetSegmentInfo.segmentIndex
|
|
2625
|
+
);
|
|
2626
|
+
|
|
2627
|
+
const renderingEngine = cornerstoneViewportService.getRenderingEngine();
|
|
2628
|
+
renderingEngine.render();
|
|
2629
|
+
},
|
|
2630
|
+
};
|
|
2631
|
+
|
|
2632
|
+
const definitions = {
|
|
2633
|
+
// The command here is to show the viewer context menu, as being the
|
|
2634
|
+
// context menu
|
|
2635
|
+
showCornerstoneContextMenu: {
|
|
2636
|
+
commandFn: actions.showCornerstoneContextMenu,
|
|
2637
|
+
options: {
|
|
2638
|
+
menuCustomizationId: 'measurementsContextMenu',
|
|
2639
|
+
commands: [
|
|
2640
|
+
{
|
|
2641
|
+
commandName: 'showContextMenu',
|
|
2642
|
+
},
|
|
2643
|
+
],
|
|
2644
|
+
},
|
|
2645
|
+
},
|
|
2646
|
+
|
|
2647
|
+
getNearbyToolData: {
|
|
2648
|
+
commandFn: actions.getNearbyToolData,
|
|
2649
|
+
},
|
|
2650
|
+
getNearbyAnnotation: {
|
|
2651
|
+
commandFn: actions.getNearbyAnnotation,
|
|
2652
|
+
storeContexts: [],
|
|
2653
|
+
options: {},
|
|
2654
|
+
},
|
|
2655
|
+
toggleViewportColorbar: {
|
|
2656
|
+
commandFn: actions.toggleViewportColorbar,
|
|
2657
|
+
},
|
|
2658
|
+
setMeasurementLabel: {
|
|
2659
|
+
commandFn: actions.setMeasurementLabel,
|
|
2660
|
+
},
|
|
2661
|
+
renameMeasurement: {
|
|
2662
|
+
commandFn: actions.renameMeasurement,
|
|
2663
|
+
},
|
|
2664
|
+
updateMeasurement: {
|
|
2665
|
+
commandFn: actions.updateMeasurement,
|
|
2666
|
+
},
|
|
2667
|
+
changeMeasurementColor: {
|
|
2668
|
+
commandFn: actions.changeMeasurementColor,
|
|
2669
|
+
},
|
|
2670
|
+
jumpToMeasurement: actions.jumpToMeasurement,
|
|
2671
|
+
recordMeasurementsPredecessor: {
|
|
2672
|
+
commandFn: actions.recordMeasurementsPredecessor,
|
|
2673
|
+
},
|
|
2674
|
+
removeMeasurement: {
|
|
2675
|
+
commandFn: actions.removeMeasurement,
|
|
2676
|
+
},
|
|
2677
|
+
cancelMeasurement: {
|
|
2678
|
+
commandFn: actions.cancelMeasurement,
|
|
2679
|
+
},
|
|
2680
|
+
toggleLockMeasurement: {
|
|
2681
|
+
commandFn: actions.toggleLockMeasurement,
|
|
2682
|
+
},
|
|
2683
|
+
toggleVisibilityMeasurement: {
|
|
2684
|
+
commandFn: actions.toggleVisibilityMeasurement,
|
|
2685
|
+
},
|
|
2686
|
+
downloadCSVMeasurementsReport: {
|
|
2687
|
+
commandFn: actions.downloadCSVMeasurementsReport,
|
|
2688
|
+
},
|
|
2689
|
+
setViewportWindowLevel: {
|
|
2690
|
+
commandFn: actions.setViewportWindowLevel,
|
|
2691
|
+
},
|
|
2692
|
+
setWindowLevel: {
|
|
2693
|
+
commandFn: actions.setWindowLevel,
|
|
2694
|
+
},
|
|
2695
|
+
setWindowLevelPreset: {
|
|
2696
|
+
commandFn: actions.setWindowLevelPreset,
|
|
2697
|
+
},
|
|
2698
|
+
setToolActive: {
|
|
2699
|
+
commandFn: actions.setToolActive,
|
|
2700
|
+
},
|
|
2701
|
+
setToolActiveToolbar: {
|
|
2702
|
+
commandFn: actions.setToolActiveToolbar,
|
|
2703
|
+
},
|
|
2704
|
+
setToolEnabled: {
|
|
2705
|
+
commandFn: actions.setToolEnabled,
|
|
2706
|
+
},
|
|
2707
|
+
rotateViewportCW: {
|
|
2708
|
+
commandFn: actions.rotateViewportBy,
|
|
2709
|
+
options: { rotation: 90 },
|
|
2710
|
+
},
|
|
2711
|
+
rotateViewportCCW: {
|
|
2712
|
+
commandFn: actions.rotateViewportBy,
|
|
2713
|
+
options: { rotation: -90 },
|
|
2714
|
+
},
|
|
2715
|
+
rotateViewportCWSet: {
|
|
2716
|
+
commandFn: actions.setViewportRotation,
|
|
2717
|
+
options: { rotation: 90 },
|
|
2718
|
+
},
|
|
2719
|
+
incrementActiveViewport: {
|
|
2720
|
+
commandFn: actions.changeActiveViewport,
|
|
2721
|
+
},
|
|
2722
|
+
decrementActiveViewport: {
|
|
2723
|
+
commandFn: actions.changeActiveViewport,
|
|
2724
|
+
options: { direction: -1 },
|
|
2725
|
+
},
|
|
2726
|
+
flipViewportHorizontal: {
|
|
2727
|
+
commandFn: actions.toggleViewportHorizontalFlip,
|
|
2728
|
+
},
|
|
2729
|
+
flipViewportVertical: {
|
|
2730
|
+
commandFn: actions.toggleViewportVerticalFlip,
|
|
2731
|
+
},
|
|
2732
|
+
setViewportHorizontalFlip: {
|
|
2733
|
+
commandFn: actions.setViewportHorizontalFlip,
|
|
2734
|
+
options: { flipped: true },
|
|
2735
|
+
},
|
|
2736
|
+
setViewportVerticalFlip: {
|
|
2737
|
+
commandFn: actions.setViewportVerticalFlip,
|
|
2738
|
+
options: { flipped: true },
|
|
2739
|
+
},
|
|
2740
|
+
invertViewport: {
|
|
2741
|
+
commandFn: actions.invertViewport,
|
|
2742
|
+
},
|
|
2743
|
+
resetViewport: {
|
|
2744
|
+
commandFn: actions.resetViewport,
|
|
2745
|
+
},
|
|
2746
|
+
scaleUpViewport: {
|
|
2747
|
+
commandFn: actions.scaleViewport,
|
|
2748
|
+
options: { direction: 1 },
|
|
2749
|
+
},
|
|
2750
|
+
scaleDownViewport: {
|
|
2751
|
+
commandFn: actions.scaleViewport,
|
|
2752
|
+
options: { direction: -1 },
|
|
2753
|
+
},
|
|
2754
|
+
fitViewportToWindow: {
|
|
2755
|
+
commandFn: actions.scaleViewport,
|
|
2756
|
+
options: { direction: 0 },
|
|
2757
|
+
},
|
|
2758
|
+
nextImage: {
|
|
2759
|
+
commandFn: actions.scroll,
|
|
2760
|
+
options: { direction: 1 },
|
|
2761
|
+
},
|
|
2762
|
+
previousImage: {
|
|
2763
|
+
commandFn: actions.scroll,
|
|
2764
|
+
options: { direction: -1 },
|
|
2765
|
+
},
|
|
2766
|
+
firstImage: {
|
|
2767
|
+
commandFn: actions.jumpToImage,
|
|
2768
|
+
options: { imageIndex: 0 },
|
|
2769
|
+
},
|
|
2770
|
+
lastImage: {
|
|
2771
|
+
commandFn: actions.jumpToImage,
|
|
2772
|
+
options: { imageIndex: -1 },
|
|
2773
|
+
},
|
|
2774
|
+
jumpToImage: {
|
|
2775
|
+
commandFn: actions.jumpToImage,
|
|
2776
|
+
},
|
|
2777
|
+
showDownloadViewportModal: {
|
|
2778
|
+
commandFn: actions.showDownloadViewportModal,
|
|
2779
|
+
},
|
|
2780
|
+
toggleCine: {
|
|
2781
|
+
commandFn: actions.toggleCine,
|
|
2782
|
+
},
|
|
2783
|
+
arrowTextCallback: {
|
|
2784
|
+
commandFn: actions.arrowTextCallback,
|
|
2785
|
+
},
|
|
2786
|
+
setViewportActive: {
|
|
2787
|
+
commandFn: actions.setViewportActive,
|
|
2788
|
+
},
|
|
2789
|
+
setViewportColormap: {
|
|
2790
|
+
commandFn: actions.setViewportColormap,
|
|
2791
|
+
},
|
|
2792
|
+
setViewportForToolConfiguration: {
|
|
2793
|
+
commandFn: actions.setViewportForToolConfiguration,
|
|
2794
|
+
},
|
|
2795
|
+
storePresentation: {
|
|
2796
|
+
commandFn: actions.storePresentation,
|
|
2797
|
+
},
|
|
2798
|
+
attachProtocolViewportDataListener: {
|
|
2799
|
+
commandFn: actions.attachProtocolViewportDataListener,
|
|
2800
|
+
},
|
|
2801
|
+
setViewportPreset: {
|
|
2802
|
+
commandFn: actions.setViewportPreset,
|
|
2803
|
+
},
|
|
2804
|
+
setVolumeRenderingQulaity: {
|
|
2805
|
+
commandFn: actions.setVolumeRenderingQulaity,
|
|
2806
|
+
},
|
|
2807
|
+
shiftVolumeOpacityPoints: {
|
|
2808
|
+
commandFn: actions.shiftVolumeOpacityPoints,
|
|
2809
|
+
},
|
|
2810
|
+
setVolumeLighting: {
|
|
2811
|
+
commandFn: actions.setVolumeLighting,
|
|
2812
|
+
},
|
|
2813
|
+
resetCrosshairs: {
|
|
2814
|
+
commandFn: actions.resetCrosshairs,
|
|
2815
|
+
},
|
|
2816
|
+
toggleSynchronizer: {
|
|
2817
|
+
commandFn: actions.toggleSynchronizer,
|
|
2818
|
+
},
|
|
2819
|
+
updateVolumeData: {
|
|
2820
|
+
commandFn: actions.updateVolumeData,
|
|
2821
|
+
},
|
|
2822
|
+
toggleEnabledDisabledToolbar: {
|
|
2823
|
+
commandFn: actions.toggleEnabledDisabledToolbar,
|
|
2824
|
+
},
|
|
2825
|
+
toggleActiveDisabledToolbar: {
|
|
2826
|
+
commandFn: actions.toggleActiveDisabledToolbar,
|
|
2827
|
+
},
|
|
2828
|
+
updateStoredPositionPresentation: {
|
|
2829
|
+
commandFn: actions.updateStoredPositionPresentation,
|
|
2830
|
+
},
|
|
2831
|
+
updateStoredSegmentationPresentation: {
|
|
2832
|
+
commandFn: actions.updateStoredSegmentationPresentation,
|
|
2833
|
+
},
|
|
2834
|
+
createLabelmapForViewport: {
|
|
2835
|
+
commandFn: actions.createLabelmapForViewport,
|
|
2836
|
+
},
|
|
2837
|
+
createContourForViewport: {
|
|
2838
|
+
commandFn: actions.createContourForViewport,
|
|
2839
|
+
},
|
|
2840
|
+
setActiveSegmentation: {
|
|
2841
|
+
commandFn: actions.setActiveSegmentation,
|
|
2842
|
+
},
|
|
2843
|
+
addSegment: {
|
|
2844
|
+
commandFn: actions.addSegmentCommand,
|
|
2845
|
+
},
|
|
2846
|
+
setActiveSegmentAndCenter: {
|
|
2847
|
+
commandFn: actions.setActiveSegmentAndCenterCommand,
|
|
2848
|
+
},
|
|
2849
|
+
toggleSegmentVisibility: {
|
|
2850
|
+
commandFn: actions.toggleSegmentVisibilityCommand,
|
|
2851
|
+
},
|
|
2852
|
+
toggleSegmentLock: {
|
|
2853
|
+
commandFn: actions.toggleSegmentLockCommand,
|
|
2854
|
+
},
|
|
2855
|
+
toggleSegmentationVisibility: {
|
|
2856
|
+
commandFn: actions.toggleSegmentationVisibilityCommand,
|
|
2857
|
+
},
|
|
2858
|
+
downloadSegmentation: {
|
|
2859
|
+
commandFn: actions.downloadSegmentationCommand,
|
|
2860
|
+
},
|
|
2861
|
+
storeSegmentation: {
|
|
2862
|
+
commandFn: actions.storeSegmentationCommand,
|
|
2863
|
+
},
|
|
2864
|
+
downloadRTSS: {
|
|
2865
|
+
commandFn: actions.downloadRTSSCommand,
|
|
2866
|
+
},
|
|
2867
|
+
setSegmentationStyle: {
|
|
2868
|
+
commandFn: actions.setSegmentationStyleCommand,
|
|
2869
|
+
},
|
|
2870
|
+
deleteSegment: {
|
|
2871
|
+
commandFn: actions.deleteSegmentCommand,
|
|
2872
|
+
},
|
|
2873
|
+
deleteSegmentation: {
|
|
2874
|
+
commandFn: actions.deleteSegmentationCommand,
|
|
2875
|
+
},
|
|
2876
|
+
removeSegmentationFromViewport: {
|
|
2877
|
+
commandFn: actions.removeSegmentationFromViewportCommand,
|
|
2878
|
+
},
|
|
2879
|
+
toggleRenderInactiveSegmentations: {
|
|
2880
|
+
commandFn: actions.toggleRenderInactiveSegmentationsCommand,
|
|
2881
|
+
},
|
|
2882
|
+
setFillAlpha: {
|
|
2883
|
+
commandFn: createSetStyleCommand('fillAlpha'),
|
|
2884
|
+
},
|
|
2885
|
+
setOutlineWidth: {
|
|
2886
|
+
commandFn: createSetStyleCommand('outlineWidth'),
|
|
2887
|
+
},
|
|
2888
|
+
setRenderFill: {
|
|
2889
|
+
commandFn: createSetStyleCommand('renderFill'),
|
|
2890
|
+
},
|
|
2891
|
+
setRenderFillInactive: {
|
|
2892
|
+
commandFn: createSetStyleCommand('renderFillInactive'),
|
|
2893
|
+
},
|
|
2894
|
+
setRenderOutline: {
|
|
2895
|
+
commandFn: createSetStyleCommand('renderOutline'),
|
|
2896
|
+
},
|
|
2897
|
+
setRenderOutlineInactive: {
|
|
2898
|
+
commandFn: createSetStyleCommand('renderOutlineInactive'),
|
|
2899
|
+
},
|
|
2900
|
+
setFillAlphaInactive: {
|
|
2901
|
+
commandFn: createSetStyleCommand('fillAlphaInactive'),
|
|
2902
|
+
},
|
|
2903
|
+
editSegmentLabel: {
|
|
2904
|
+
commandFn: actions.editSegmentLabel,
|
|
2905
|
+
},
|
|
2906
|
+
editSegmentationLabel: {
|
|
2907
|
+
commandFn: actions.editSegmentationLabel,
|
|
2908
|
+
},
|
|
2909
|
+
editSegmentColor: {
|
|
2910
|
+
commandFn: actions.editSegmentColor,
|
|
2911
|
+
},
|
|
2912
|
+
getRenderInactiveSegmentations: {
|
|
2913
|
+
commandFn: actions.getRenderInactiveSegmentations,
|
|
2914
|
+
},
|
|
2915
|
+
deleteActiveAnnotation: {
|
|
2916
|
+
commandFn: actions.deleteActiveAnnotation,
|
|
2917
|
+
},
|
|
2918
|
+
setDisplaySetsForViewports: actions.setDisplaySetsForViewports,
|
|
2919
|
+
undo: actions.undo,
|
|
2920
|
+
redo: actions.redo,
|
|
2921
|
+
interpolateLabelmap: actions.interpolateLabelmap,
|
|
2922
|
+
runSegmentBidirectional: actions.runSegmentBidirectional,
|
|
2923
|
+
downloadCSVSegmentationReport: actions.downloadCSVSegmentationReport,
|
|
2924
|
+
toggleSegmentPreviewEdit: actions.toggleSegmentPreviewEdit,
|
|
2925
|
+
toggleSegmentSelect: actions.toggleSegmentSelect,
|
|
2926
|
+
acceptPreview: actions.acceptPreview,
|
|
2927
|
+
rejectPreview: actions.rejectPreview,
|
|
2928
|
+
cancelActiveOperation: actions.cancelActiveOperation,
|
|
2929
|
+
toggleUseCenterSegmentIndex: actions.toggleUseCenterSegmentIndex,
|
|
2930
|
+
toggleLabelmapAssist: actions.toggleLabelmapAssist,
|
|
2931
|
+
interpolateScrollForMarkerLabelmap: actions.interpolateScrollForMarkerLabelmap,
|
|
2932
|
+
clearMarkersForMarkerLabelmap: actions.clearMarkersForMarkerLabelmap,
|
|
2933
|
+
setBrushSize: actions.setBrushSize,
|
|
2934
|
+
setThresholdRange: actions.setThresholdRange,
|
|
2935
|
+
increaseBrushSize: actions.increaseBrushSize,
|
|
2936
|
+
decreaseBrushSize: actions.decreaseBrushSize,
|
|
2937
|
+
addNewSegment: actions.addNewSegment,
|
|
2938
|
+
loadSegmentationDisplaySetsForViewport: actions.loadSegmentationDisplaySetsForViewport,
|
|
2939
|
+
setViewportOrientation: actions.setViewportOrientation,
|
|
2940
|
+
hydrateSecondaryDisplaySet: actions.hydrateSecondaryDisplaySet,
|
|
2941
|
+
loadDisplaySetData: actions.loadDisplaySetData,
|
|
2942
|
+
getVolumeIdForDisplaySet: actions.getVolumeIdForDisplaySet,
|
|
2943
|
+
triggerCreateAnnotationMemo: actions.triggerCreateAnnotationMemo,
|
|
2944
|
+
startRecordingForAnnotationGroup: actions.startRecordingForAnnotationGroup,
|
|
2945
|
+
endRecordingForAnnotationGroup: actions.endRecordingForAnnotationGroup,
|
|
2946
|
+
toggleSegmentLabel: actions.toggleSegmentLabel,
|
|
2947
|
+
jumpToMeasurementViewport: actions.jumpToMeasurementViewport,
|
|
2948
|
+
initializeSegmentLabelTool: actions.initializeSegmentLabelTool,
|
|
2949
|
+
activateSelectedSegmentationOfType: actions.activateSelectedSegmentationOfType,
|
|
2950
|
+
setDynamicCursorSizeForSculptorTool: actions.setDynamicCursorSizeForSculptorTool,
|
|
2951
|
+
setSimplifiedSplineForSplineContourSegmentationTool:
|
|
2952
|
+
actions.setSimplifiedSplineForSplineContourSegmentationTool,
|
|
2953
|
+
removeSmallContours: actions.removeSmallContours,
|
|
2954
|
+
applyLogicalContourOperation: actions.applyLogicalContourOperation,
|
|
2955
|
+
copyContourSegment: actions.copyContourSegment,
|
|
2956
|
+
smoothContours: actions.smoothContours,
|
|
2957
|
+
removeContourHoles: actions.removeContourHoles,
|
|
2958
|
+
decimateContours: actions.decimateContours,
|
|
2959
|
+
convertContourHoles: actions.convertContourHoles,
|
|
2960
|
+
setInterpolationToolConfiguration: actions.setInterpolationToolConfiguration,
|
|
2961
|
+
};
|
|
2962
|
+
|
|
2963
|
+
return {
|
|
2964
|
+
actions,
|
|
2965
|
+
definitions,
|
|
2966
|
+
defaultContext: 'CORNERSTONE',
|
|
2967
|
+
};
|
|
2968
|
+
}
|
|
2969
|
+
|
|
2970
|
+
export default commandsModule;
|