@ohif/extension-cornerstone 3.14.0-beta.97 → 3.14.0-beta.99
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 +18 -8
- package/src/Viewport/OHIFCornerstoneViewport.css +46 -0
- package/src/Viewport/OHIFCornerstoneViewport.tsx +502 -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 +2951 -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/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 +94 -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 +12 -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 +8 -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/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 +445 -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 +3698 -0
- package/src/services/SegmentationService/SegmentationService.ts +2376 -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 +671 -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.ts +83 -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/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 +96 -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/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,576 @@
|
|
|
1
|
+
import { eventTarget, Types, utilities as csUtils } from '@cornerstonejs/core';
|
|
2
|
+
import { Enums, annotation, cancelActiveManipulations } from '@cornerstonejs/tools';
|
|
3
|
+
import { DicomMetadataStore } from '@ohif/core';
|
|
4
|
+
|
|
5
|
+
import * as CSExtensionEnums from './enums';
|
|
6
|
+
import { toolNames } from './initCornerstoneTools';
|
|
7
|
+
import { onCompletedCalibrationLine } from './tools/CalibrationLineTool';
|
|
8
|
+
import measurementServiceMappingsFactory from './utils/measurementServiceMappings/measurementServiceMappingsFactory';
|
|
9
|
+
import getSOPInstanceAttributes from './utils/measurementServiceMappings/utils/getSOPInstanceAttributes';
|
|
10
|
+
import {
|
|
11
|
+
setAnnotationLabel,
|
|
12
|
+
triggerAnnotationRenderForViewportIds,
|
|
13
|
+
} from '@cornerstonejs/tools/utilities';
|
|
14
|
+
import getActiveViewportEnabledElement from './utils/getActiveViewportEnabledElement';
|
|
15
|
+
|
|
16
|
+
const { CORNERSTONE_3D_TOOLS_SOURCE_NAME, CORNERSTONE_3D_TOOLS_SOURCE_VERSION } = CSExtensionEnums;
|
|
17
|
+
const { removeAnnotation } = annotation.state;
|
|
18
|
+
const csToolsEvents = Enums.Events;
|
|
19
|
+
|
|
20
|
+
const { DefaultHistoryMemo } = csUtils.HistoryMemo;
|
|
21
|
+
|
|
22
|
+
const initMeasurementService = (
|
|
23
|
+
measurementService,
|
|
24
|
+
displaySetService,
|
|
25
|
+
cornerstoneViewportService,
|
|
26
|
+
customizationService
|
|
27
|
+
) => {
|
|
28
|
+
/* Initialization */
|
|
29
|
+
const {
|
|
30
|
+
Length,
|
|
31
|
+
Bidirectional,
|
|
32
|
+
EllipticalROI,
|
|
33
|
+
CircleROI,
|
|
34
|
+
ArrowAnnotate,
|
|
35
|
+
Angle,
|
|
36
|
+
CobbAngle,
|
|
37
|
+
RectangleROI,
|
|
38
|
+
PlanarFreehandROI,
|
|
39
|
+
SplineROI,
|
|
40
|
+
LivewireContour,
|
|
41
|
+
Probe,
|
|
42
|
+
UltrasoundDirectional,
|
|
43
|
+
UltrasoundPleuraBLine,
|
|
44
|
+
SegmentBidirectional,
|
|
45
|
+
} = measurementServiceMappingsFactory(
|
|
46
|
+
measurementService,
|
|
47
|
+
displaySetService,
|
|
48
|
+
cornerstoneViewportService,
|
|
49
|
+
customizationService
|
|
50
|
+
);
|
|
51
|
+
const csTools3DVer1MeasurementSource = measurementService.createSource(
|
|
52
|
+
CORNERSTONE_3D_TOOLS_SOURCE_NAME,
|
|
53
|
+
CORNERSTONE_3D_TOOLS_SOURCE_VERSION
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
/* Mappings */
|
|
57
|
+
measurementService.addMapping(
|
|
58
|
+
csTools3DVer1MeasurementSource,
|
|
59
|
+
'Length',
|
|
60
|
+
Length.matchingCriteria,
|
|
61
|
+
Length.toAnnotation,
|
|
62
|
+
Length.toMeasurement
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
measurementService.addMapping(
|
|
66
|
+
csTools3DVer1MeasurementSource,
|
|
67
|
+
'Crosshairs',
|
|
68
|
+
Length.matchingCriteria,
|
|
69
|
+
() => {
|
|
70
|
+
return null;
|
|
71
|
+
},
|
|
72
|
+
() => {
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
measurementService.addMapping(
|
|
78
|
+
csTools3DVer1MeasurementSource,
|
|
79
|
+
'Bidirectional',
|
|
80
|
+
Bidirectional.matchingCriteria,
|
|
81
|
+
Bidirectional.toAnnotation,
|
|
82
|
+
Bidirectional.toMeasurement
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
measurementService.addMapping(
|
|
86
|
+
csTools3DVer1MeasurementSource,
|
|
87
|
+
'EllipticalROI',
|
|
88
|
+
EllipticalROI.matchingCriteria,
|
|
89
|
+
EllipticalROI.toAnnotation,
|
|
90
|
+
EllipticalROI.toMeasurement
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
measurementService.addMapping(
|
|
94
|
+
csTools3DVer1MeasurementSource,
|
|
95
|
+
'CircleROI',
|
|
96
|
+
CircleROI.matchingCriteria,
|
|
97
|
+
CircleROI.toAnnotation,
|
|
98
|
+
CircleROI.toMeasurement
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
measurementService.addMapping(
|
|
102
|
+
csTools3DVer1MeasurementSource,
|
|
103
|
+
'ArrowAnnotate',
|
|
104
|
+
ArrowAnnotate.matchingCriteria,
|
|
105
|
+
ArrowAnnotate.toAnnotation,
|
|
106
|
+
ArrowAnnotate.toMeasurement
|
|
107
|
+
);
|
|
108
|
+
|
|
109
|
+
measurementService.addMapping(
|
|
110
|
+
csTools3DVer1MeasurementSource,
|
|
111
|
+
'CobbAngle',
|
|
112
|
+
CobbAngle.matchingCriteria,
|
|
113
|
+
CobbAngle.toAnnotation,
|
|
114
|
+
CobbAngle.toMeasurement
|
|
115
|
+
);
|
|
116
|
+
|
|
117
|
+
measurementService.addMapping(
|
|
118
|
+
csTools3DVer1MeasurementSource,
|
|
119
|
+
'Angle',
|
|
120
|
+
Angle.matchingCriteria,
|
|
121
|
+
Angle.toAnnotation,
|
|
122
|
+
Angle.toMeasurement
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
measurementService.addMapping(
|
|
126
|
+
csTools3DVer1MeasurementSource,
|
|
127
|
+
'RectangleROI',
|
|
128
|
+
RectangleROI.matchingCriteria,
|
|
129
|
+
RectangleROI.toAnnotation,
|
|
130
|
+
RectangleROI.toMeasurement
|
|
131
|
+
);
|
|
132
|
+
|
|
133
|
+
measurementService.addMapping(
|
|
134
|
+
csTools3DVer1MeasurementSource,
|
|
135
|
+
'PlanarFreehandROI',
|
|
136
|
+
PlanarFreehandROI.matchingCriteria,
|
|
137
|
+
PlanarFreehandROI.toAnnotation,
|
|
138
|
+
PlanarFreehandROI.toMeasurement
|
|
139
|
+
);
|
|
140
|
+
|
|
141
|
+
measurementService.addMapping(
|
|
142
|
+
csTools3DVer1MeasurementSource,
|
|
143
|
+
'SplineROI',
|
|
144
|
+
SplineROI.matchingCriteria,
|
|
145
|
+
SplineROI.toAnnotation,
|
|
146
|
+
SplineROI.toMeasurement
|
|
147
|
+
);
|
|
148
|
+
|
|
149
|
+
// On the UI side, the Calibration Line tool will work almost the same as the
|
|
150
|
+
// Length tool
|
|
151
|
+
measurementService.addMapping(
|
|
152
|
+
csTools3DVer1MeasurementSource,
|
|
153
|
+
'CalibrationLine',
|
|
154
|
+
Length.matchingCriteria,
|
|
155
|
+
Length.toAnnotation,
|
|
156
|
+
Length.toMeasurement
|
|
157
|
+
);
|
|
158
|
+
|
|
159
|
+
measurementService.addMapping(
|
|
160
|
+
csTools3DVer1MeasurementSource,
|
|
161
|
+
'LivewireContour',
|
|
162
|
+
LivewireContour.matchingCriteria,
|
|
163
|
+
LivewireContour.toAnnotation,
|
|
164
|
+
LivewireContour.toMeasurement
|
|
165
|
+
);
|
|
166
|
+
|
|
167
|
+
measurementService.addMapping(
|
|
168
|
+
csTools3DVer1MeasurementSource,
|
|
169
|
+
'Probe',
|
|
170
|
+
Probe.matchingCriteria,
|
|
171
|
+
Probe.toAnnotation,
|
|
172
|
+
Probe.toMeasurement
|
|
173
|
+
);
|
|
174
|
+
|
|
175
|
+
/** SR subtypes use same schema as base tools (Probe/RectangleROI) */
|
|
176
|
+
measurementService.addMapping(
|
|
177
|
+
csTools3DVer1MeasurementSource,
|
|
178
|
+
'SRPoint',
|
|
179
|
+
Probe.matchingCriteria,
|
|
180
|
+
Probe.toAnnotation,
|
|
181
|
+
Probe.toMeasurement
|
|
182
|
+
);
|
|
183
|
+
|
|
184
|
+
measurementService.addMapping(
|
|
185
|
+
csTools3DVer1MeasurementSource,
|
|
186
|
+
'SRRectangleROI',
|
|
187
|
+
RectangleROI.matchingCriteria,
|
|
188
|
+
RectangleROI.toAnnotation,
|
|
189
|
+
RectangleROI.toMeasurement
|
|
190
|
+
);
|
|
191
|
+
|
|
192
|
+
measurementService.addMapping(
|
|
193
|
+
csTools3DVer1MeasurementSource,
|
|
194
|
+
'UltrasoundDirectionalTool',
|
|
195
|
+
UltrasoundDirectional.matchingCriteria,
|
|
196
|
+
UltrasoundDirectional.toAnnotation,
|
|
197
|
+
UltrasoundDirectional.toMeasurement
|
|
198
|
+
);
|
|
199
|
+
|
|
200
|
+
measurementService.addMapping(
|
|
201
|
+
csTools3DVer1MeasurementSource,
|
|
202
|
+
'UltrasoundPleuraBLineTool',
|
|
203
|
+
UltrasoundPleuraBLine.matchingCriteria,
|
|
204
|
+
UltrasoundPleuraBLine.toAnnotation,
|
|
205
|
+
UltrasoundPleuraBLine.toMeasurement
|
|
206
|
+
);
|
|
207
|
+
|
|
208
|
+
measurementService.addMapping(
|
|
209
|
+
csTools3DVer1MeasurementSource,
|
|
210
|
+
'SegmentBidirectional',
|
|
211
|
+
SegmentBidirectional.matchingCriteria,
|
|
212
|
+
SegmentBidirectional.toAnnotation,
|
|
213
|
+
SegmentBidirectional.toMeasurement
|
|
214
|
+
);
|
|
215
|
+
|
|
216
|
+
return csTools3DVer1MeasurementSource;
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
const connectToolsToMeasurementService = ({
|
|
220
|
+
commandsManager,
|
|
221
|
+
servicesManager,
|
|
222
|
+
extensionManager,
|
|
223
|
+
}: {
|
|
224
|
+
commandsManager: AppTypes.CommandsManager;
|
|
225
|
+
servicesManager: AppTypes.ServicesManager;
|
|
226
|
+
extensionManager: AppTypes.ExtensionManager;
|
|
227
|
+
}) => {
|
|
228
|
+
const {
|
|
229
|
+
measurementService,
|
|
230
|
+
displaySetService,
|
|
231
|
+
cornerstoneViewportService,
|
|
232
|
+
customizationService,
|
|
233
|
+
} = servicesManager.services;
|
|
234
|
+
const csTools3DVer1MeasurementSource = initMeasurementService(
|
|
235
|
+
measurementService,
|
|
236
|
+
displaySetService,
|
|
237
|
+
cornerstoneViewportService,
|
|
238
|
+
customizationService
|
|
239
|
+
);
|
|
240
|
+
connectMeasurementServiceToTools({ servicesManager, commandsManager, extensionManager });
|
|
241
|
+
const { annotationToMeasurement, remove } = csTools3DVer1MeasurementSource;
|
|
242
|
+
|
|
243
|
+
//
|
|
244
|
+
function addMeasurement(csToolsEvent) {
|
|
245
|
+
try {
|
|
246
|
+
const annotationAddedEventDetail = csToolsEvent.detail;
|
|
247
|
+
const {
|
|
248
|
+
annotation: { metadata, annotationUID },
|
|
249
|
+
} = annotationAddedEventDetail;
|
|
250
|
+
const { toolName } = metadata;
|
|
251
|
+
|
|
252
|
+
if (csToolsEvent.type === completedEvt && toolName === toolNames.CalibrationLine) {
|
|
253
|
+
// show modal to input the measurement (mm)
|
|
254
|
+
onCompletedCalibrationLine(servicesManager, csToolsEvent)
|
|
255
|
+
.then(
|
|
256
|
+
() => {
|
|
257
|
+
console.log('Calibration applied.');
|
|
258
|
+
},
|
|
259
|
+
() => true
|
|
260
|
+
)
|
|
261
|
+
.finally(() => {
|
|
262
|
+
// we don't need the calibration line lingering around, remove the
|
|
263
|
+
// annotation from the display
|
|
264
|
+
removeAnnotation(annotationUID);
|
|
265
|
+
removeMeasurement(csToolsEvent);
|
|
266
|
+
// this will ensure redrawing of annotations
|
|
267
|
+
cornerstoneViewportService.resize();
|
|
268
|
+
});
|
|
269
|
+
} else {
|
|
270
|
+
// To force the measurementUID be the same as the annotationUID
|
|
271
|
+
// Todo: this should be changed when a measurement can include multiple annotations
|
|
272
|
+
// in the future
|
|
273
|
+
annotationAddedEventDetail.uid = annotationUID;
|
|
274
|
+
annotationToMeasurement(toolName, annotationAddedEventDetail);
|
|
275
|
+
}
|
|
276
|
+
} catch (error) {
|
|
277
|
+
console.warn('Failed to add measurement:', error);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
function updateMeasurement(csToolsEvent) {
|
|
282
|
+
try {
|
|
283
|
+
const annotationModifiedEventDetail = csToolsEvent.detail;
|
|
284
|
+
|
|
285
|
+
const {
|
|
286
|
+
annotation: { metadata, annotationUID },
|
|
287
|
+
} = annotationModifiedEventDetail;
|
|
288
|
+
|
|
289
|
+
// If the measurement hasn't been added, don't modify it
|
|
290
|
+
const measurement = measurementService.getMeasurement(annotationUID);
|
|
291
|
+
|
|
292
|
+
if (!measurement) {
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
295
|
+
const { toolName } = metadata;
|
|
296
|
+
|
|
297
|
+
annotationModifiedEventDetail.uid = annotationUID;
|
|
298
|
+
// Passing true to indicate this is an update and NOT a annotation (start) completion.
|
|
299
|
+
annotationToMeasurement(toolName, annotationModifiedEventDetail, true);
|
|
300
|
+
} catch (error) {
|
|
301
|
+
console.warn('Failed to update measurement:', error);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
function selectMeasurement(csToolsEvent) {
|
|
306
|
+
try {
|
|
307
|
+
const annotationSelectionEventDetail = csToolsEvent.detail;
|
|
308
|
+
|
|
309
|
+
const { added: addedSelectedAnnotationUIDs, removed: removedSelectedAnnotationUIDs } =
|
|
310
|
+
annotationSelectionEventDetail;
|
|
311
|
+
|
|
312
|
+
if (removedSelectedAnnotationUIDs) {
|
|
313
|
+
removedSelectedAnnotationUIDs.forEach(annotationUID =>
|
|
314
|
+
measurementService.setMeasurementSelected(annotationUID, false)
|
|
315
|
+
);
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
if (addedSelectedAnnotationUIDs) {
|
|
319
|
+
addedSelectedAnnotationUIDs.forEach(annotationUID =>
|
|
320
|
+
measurementService.setMeasurementSelected(annotationUID, true)
|
|
321
|
+
);
|
|
322
|
+
}
|
|
323
|
+
} catch (error) {
|
|
324
|
+
console.warn('Failed to select/unselect measurements:', error);
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* When csTools fires a removed event, remove the same measurement
|
|
330
|
+
* from the measurement service
|
|
331
|
+
*
|
|
332
|
+
* @param {*} csToolsEvent
|
|
333
|
+
*/
|
|
334
|
+
function removeMeasurement(csToolsEvent) {
|
|
335
|
+
try {
|
|
336
|
+
const annotationRemovedEventDetail = csToolsEvent.detail;
|
|
337
|
+
const {
|
|
338
|
+
annotation: { annotationUID },
|
|
339
|
+
} = annotationRemovedEventDetail;
|
|
340
|
+
const measurement = measurementService.getMeasurement(annotationUID);
|
|
341
|
+
if (measurement) {
|
|
342
|
+
remove(annotationUID, annotationRemovedEventDetail);
|
|
343
|
+
}
|
|
344
|
+
} catch (error) {
|
|
345
|
+
console.warn('Failed to remove measurement:', error);
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
// on display sets added, check if there are any measurements in measurement service that need to be
|
|
350
|
+
// put into cornerstone tools
|
|
351
|
+
const addedEvt = csToolsEvents.ANNOTATION_ADDED;
|
|
352
|
+
const completedEvt = csToolsEvents.ANNOTATION_COMPLETED;
|
|
353
|
+
const updatedEvt = csToolsEvents.ANNOTATION_MODIFIED;
|
|
354
|
+
const removedEvt = csToolsEvents.ANNOTATION_REMOVED;
|
|
355
|
+
const selectionEvt = csToolsEvents.ANNOTATION_SELECTION_CHANGE;
|
|
356
|
+
|
|
357
|
+
eventTarget.addEventListener(addedEvt, addMeasurement);
|
|
358
|
+
eventTarget.addEventListener(completedEvt, addMeasurement);
|
|
359
|
+
eventTarget.addEventListener(updatedEvt, updateMeasurement);
|
|
360
|
+
eventTarget.addEventListener(removedEvt, removeMeasurement);
|
|
361
|
+
eventTarget.addEventListener(selectionEvt, selectMeasurement);
|
|
362
|
+
|
|
363
|
+
return csTools3DVer1MeasurementSource;
|
|
364
|
+
};
|
|
365
|
+
|
|
366
|
+
const connectMeasurementServiceToTools = ({
|
|
367
|
+
servicesManager,
|
|
368
|
+
commandsManager,
|
|
369
|
+
extensionManager,
|
|
370
|
+
}) => {
|
|
371
|
+
const { measurementService, cornerstoneViewportService, viewportGridService } =
|
|
372
|
+
servicesManager.services;
|
|
373
|
+
const { MEASUREMENT_REMOVED, MEASUREMENTS_CLEARED, MEASUREMENT_UPDATED, RAW_MEASUREMENT_ADDED } =
|
|
374
|
+
measurementService.EVENTS;
|
|
375
|
+
|
|
376
|
+
measurementService.subscribe(MEASUREMENTS_CLEARED, ({ measurements, trackingContext }) => {
|
|
377
|
+
if (!Object.keys(measurements).length) {
|
|
378
|
+
return;
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
commandsManager.run('startRecordingForAnnotationGroup');
|
|
382
|
+
for (const measurement of Object.values(measurements)) {
|
|
383
|
+
const { uid, source } = measurement;
|
|
384
|
+
if (source.name !== CORNERSTONE_3D_TOOLS_SOURCE_NAME) {
|
|
385
|
+
continue;
|
|
386
|
+
}
|
|
387
|
+
const removedAnnotation = annotation.state.getAnnotation(uid);
|
|
388
|
+
removeAnnotation(uid);
|
|
389
|
+
commandsManager.run('triggerCreateAnnotationMemo', {
|
|
390
|
+
annotation: removedAnnotation,
|
|
391
|
+
FrameOfReferenceUID: removedAnnotation.metadata.FrameOfReferenceUID,
|
|
392
|
+
options: { deleting: true },
|
|
393
|
+
});
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
// If tracking context was provided, push a memo that keeps XState in sync with
|
|
397
|
+
// Cornerstone's annotation history across unlimited undo/redo cycles:
|
|
398
|
+
// undo → re-populate trackedStudy/trackedSeries so the panel reflects the
|
|
399
|
+
// restored annotations.
|
|
400
|
+
// redo → wipe trackedStudy/trackedSeries because the annotations have been
|
|
401
|
+
// re-deleted by their own Cornerstone memos; no measurements are
|
|
402
|
+
// deleted here (they are already gone), so CLEAR_TRACKING_CONTEXT is
|
|
403
|
+
// used instead of UNTRACK_ALL to avoid a double-delete.
|
|
404
|
+
if (trackingContext) {
|
|
405
|
+
DefaultHistoryMemo.push({
|
|
406
|
+
id: csUtils.uuidv4(),
|
|
407
|
+
operationType: 'trackingState',
|
|
408
|
+
restoreMemo(undo?: boolean) {
|
|
409
|
+
if (undo === true) {
|
|
410
|
+
commandsManager.run('restoreTrackedSeries', trackingContext);
|
|
411
|
+
} else if (undo === false) {
|
|
412
|
+
commandsManager.run('clearTrackedSeries');
|
|
413
|
+
}
|
|
414
|
+
},
|
|
415
|
+
});
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
commandsManager.run('endRecordingForAnnotationGroup');
|
|
419
|
+
|
|
420
|
+
// trigger a render
|
|
421
|
+
cornerstoneViewportService.getRenderingEngine().render();
|
|
422
|
+
});
|
|
423
|
+
|
|
424
|
+
measurementService.subscribe(
|
|
425
|
+
MEASUREMENT_UPDATED,
|
|
426
|
+
({ source, measurement, notYetUpdatedAtSource }) => {
|
|
427
|
+
if (!source) {
|
|
428
|
+
return;
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
if (source.name !== CORNERSTONE_3D_TOOLS_SOURCE_NAME) {
|
|
432
|
+
return;
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
if (notYetUpdatedAtSource === false) {
|
|
436
|
+
// This event was fired by cornerstone telling the measurement service to sync.
|
|
437
|
+
// Already in sync.
|
|
438
|
+
return;
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
const { uid, label, isLocked, isVisible } = measurement;
|
|
442
|
+
const sourceAnnotation = annotation.state.getAnnotation(uid);
|
|
443
|
+
const { data, metadata } = sourceAnnotation;
|
|
444
|
+
|
|
445
|
+
if (!data) {
|
|
446
|
+
return;
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
if (data.label !== label) {
|
|
450
|
+
const element = getActiveViewportEnabledElement(viewportGridService)?.viewport.element;
|
|
451
|
+
setAnnotationLabel(sourceAnnotation, element, label);
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
// update the isLocked state
|
|
455
|
+
annotation.locking.setAnnotationLocked(uid, isLocked);
|
|
456
|
+
|
|
457
|
+
// update the isVisible state
|
|
458
|
+
annotation.visibility.setAnnotationVisibility(uid, isVisible);
|
|
459
|
+
|
|
460
|
+
// annotation.config.style.setAnnotationStyles(uid, {
|
|
461
|
+
// color: `rgb(${color[0]}, ${color[1]}, ${color[2]})`,
|
|
462
|
+
// });
|
|
463
|
+
|
|
464
|
+
// I don't like this but will fix later
|
|
465
|
+
const renderingEngine =
|
|
466
|
+
cornerstoneViewportService.getRenderingEngine() as Types.IRenderingEngine;
|
|
467
|
+
// Note: We could do a better job by triggering the render on the
|
|
468
|
+
// viewport itself, but the removeAnnotation does not include that info...
|
|
469
|
+
const viewportIds = renderingEngine.getViewports().map(viewport => viewport.id);
|
|
470
|
+
triggerAnnotationRenderForViewportIds(viewportIds);
|
|
471
|
+
}
|
|
472
|
+
);
|
|
473
|
+
|
|
474
|
+
measurementService.subscribe(
|
|
475
|
+
RAW_MEASUREMENT_ADDED,
|
|
476
|
+
({ source, measurement, data, dataSource }) => {
|
|
477
|
+
if (source.name !== CORNERSTONE_3D_TOOLS_SOURCE_NAME) {
|
|
478
|
+
return;
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
const { referenceSeriesUID, referenceStudyUID, SOPInstanceUID, metadata } = measurement;
|
|
482
|
+
|
|
483
|
+
const instance = DicomMetadataStore.getInstance(
|
|
484
|
+
referenceStudyUID,
|
|
485
|
+
referenceSeriesUID,
|
|
486
|
+
SOPInstanceUID
|
|
487
|
+
);
|
|
488
|
+
|
|
489
|
+
let imageId;
|
|
490
|
+
let frameNumber = 1;
|
|
491
|
+
|
|
492
|
+
if (measurement?.metadata?.referencedImageId) {
|
|
493
|
+
imageId = measurement.metadata.referencedImageId;
|
|
494
|
+
frameNumber = getSOPInstanceAttributes(measurement.metadata.referencedImageId).frameNumber;
|
|
495
|
+
} else if (instance) {
|
|
496
|
+
imageId = dataSource.getImageIdsForInstance({ instance });
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
/**
|
|
500
|
+
* This annotation is used by the cornerstone viewport.
|
|
501
|
+
* This is not the read-only annotation rendered by the SR viewport.
|
|
502
|
+
*/
|
|
503
|
+
const annotationManager = annotation.state.getAnnotationManager();
|
|
504
|
+
const newAnnotation = {
|
|
505
|
+
annotationUID: measurement.uid,
|
|
506
|
+
// Not used in CS3D but stored in the CS3D state so that saving
|
|
507
|
+
// can apply the predecessor consistently.
|
|
508
|
+
predecessorImageId: measurement?.predecessorImageId,
|
|
509
|
+
highlighted: false,
|
|
510
|
+
isLocked: false,
|
|
511
|
+
// This is used to force a re-render of the annotation to
|
|
512
|
+
// re-calculate cached stats since sometimes in SR we
|
|
513
|
+
// get empty cached stats
|
|
514
|
+
invalidated: true,
|
|
515
|
+
metadata: {
|
|
516
|
+
...metadata,
|
|
517
|
+
toolName: measurement.toolName,
|
|
518
|
+
FrameOfReferenceUID: measurement.FrameOfReferenceUID,
|
|
519
|
+
referencedImageId: imageId,
|
|
520
|
+
},
|
|
521
|
+
data: {
|
|
522
|
+
/**
|
|
523
|
+
* Don't remove this destructuring of data here.
|
|
524
|
+
* This is used to pass annotation specific data forward e.g. contour
|
|
525
|
+
*/
|
|
526
|
+
...(data.annotation.data || {}),
|
|
527
|
+
text: data.annotation.data.text,
|
|
528
|
+
handles: { ...data.annotation.data.handles },
|
|
529
|
+
cachedStats: { ...data.annotation.data.cachedStats },
|
|
530
|
+
label: data.annotation.data.label,
|
|
531
|
+
frameNumber,
|
|
532
|
+
},
|
|
533
|
+
};
|
|
534
|
+
annotationManager.addAnnotation(newAnnotation);
|
|
535
|
+
commandsManager.run('triggerCreateAnnotationMemo', {
|
|
536
|
+
annotation: newAnnotation,
|
|
537
|
+
FrameOfReferenceUID: newAnnotation.metadata.FrameOfReferenceUID,
|
|
538
|
+
options: { newAnnotation: true },
|
|
539
|
+
});
|
|
540
|
+
}
|
|
541
|
+
);
|
|
542
|
+
|
|
543
|
+
measurementService.subscribe(
|
|
544
|
+
MEASUREMENT_REMOVED,
|
|
545
|
+
({ source, measurement: removedMeasurementId }) => {
|
|
546
|
+
if (source?.name && source.name !== CORNERSTONE_3D_TOOLS_SOURCE_NAME) {
|
|
547
|
+
return;
|
|
548
|
+
}
|
|
549
|
+
// Cancel any active tool manipulation (e.g., Spline/Livewire) to avoid leaving the tool
|
|
550
|
+
// in a drawing state after deleting a not completed measurement, which can block viewport interactivity.
|
|
551
|
+
commandsManager.run('cancelMeasurement');
|
|
552
|
+
|
|
553
|
+
const removedAnnotation = annotation.state.getAnnotation(removedMeasurementId);
|
|
554
|
+
removeAnnotation(removedMeasurementId);
|
|
555
|
+
// Ensure `removedAnnotation` is available before triggering the memo,
|
|
556
|
+
// as it can be undefined during an undo operation
|
|
557
|
+
if (removedAnnotation) {
|
|
558
|
+
commandsManager.run('triggerCreateAnnotationMemo', {
|
|
559
|
+
annotation: removedAnnotation,
|
|
560
|
+
FrameOfReferenceUID: removedAnnotation.metadata.FrameOfReferenceUID,
|
|
561
|
+
options: { deleting: true },
|
|
562
|
+
});
|
|
563
|
+
}
|
|
564
|
+
const renderingEngine = cornerstoneViewportService.getRenderingEngine();
|
|
565
|
+
// Note: We could do a better job by triggering the render on the
|
|
566
|
+
// viewport itself, but the removeAnnotation does not include that info...
|
|
567
|
+
renderingEngine.render();
|
|
568
|
+
}
|
|
569
|
+
);
|
|
570
|
+
};
|
|
571
|
+
|
|
572
|
+
export {
|
|
573
|
+
initMeasurementService,
|
|
574
|
+
connectToolsToMeasurementService,
|
|
575
|
+
connectMeasurementServiceToTools,
|
|
576
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { cache, imageLoadPoolManager, imageLoader, Enums, eventTarget, EVENTS as csEvents } from '@cornerstonejs/core';
|
|
2
|
+
|
|
3
|
+
function initStudyPrefetcherService(servicesManager: AppTypes.ServicesManager) {
|
|
4
|
+
const { studyPrefetcherService } = servicesManager.services;
|
|
5
|
+
|
|
6
|
+
studyPrefetcherService.requestType = Enums.RequestType.Prefetch;
|
|
7
|
+
studyPrefetcherService.imageLoadPoolManager = imageLoadPoolManager;
|
|
8
|
+
studyPrefetcherService.imageLoader = imageLoader;
|
|
9
|
+
|
|
10
|
+
studyPrefetcherService.cache = {
|
|
11
|
+
isImageCached(imageId: string): boolean {
|
|
12
|
+
return !!cache.getImageLoadObject(imageId);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
studyPrefetcherService.imageLoadEventsManager = {
|
|
17
|
+
addEventListeners(onImageLoaded, onImageLoadFailed) {
|
|
18
|
+
eventTarget.addEventListener(csEvents.IMAGE_LOADED, onImageLoaded);
|
|
19
|
+
eventTarget.addEventListener(csEvents.IMAGE_LOAD_FAILED, onImageLoadFailed);
|
|
20
|
+
|
|
21
|
+
return [
|
|
22
|
+
{
|
|
23
|
+
unsubscribe: () => eventTarget.removeEventListener(csEvents.IMAGE_LOADED, onImageLoaded)
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
unsubscribe: () => eventTarget.removeEventListener(csEvents.IMAGE_LOAD_FAILED, onImageLoadFailed)
|
|
27
|
+
},
|
|
28
|
+
]
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export default initStudyPrefetcherService;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { volumeLoader } from '@cornerstonejs/core';
|
|
2
|
+
import {
|
|
3
|
+
cornerstoneStreamingImageVolumeLoader,
|
|
4
|
+
cornerstoneStreamingDynamicImageVolumeLoader,
|
|
5
|
+
} from '@cornerstonejs/core/loaders';
|
|
6
|
+
import dicomImageLoader from '@cornerstonejs/dicom-image-loader';
|
|
7
|
+
import { errorHandler, utils } from '@ohif/core';
|
|
8
|
+
|
|
9
|
+
const { registerVolumeLoader } = volumeLoader;
|
|
10
|
+
|
|
11
|
+
export default function initWADOImageLoader(
|
|
12
|
+
userAuthenticationService,
|
|
13
|
+
appConfig,
|
|
14
|
+
extensionManager
|
|
15
|
+
) {
|
|
16
|
+
registerVolumeLoader('cornerstoneStreamingImageVolume', cornerstoneStreamingImageVolumeLoader);
|
|
17
|
+
|
|
18
|
+
registerVolumeLoader(
|
|
19
|
+
'cornerstoneStreamingDynamicImageVolume',
|
|
20
|
+
cornerstoneStreamingDynamicImageVolumeLoader
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
dicomImageLoader.init({
|
|
24
|
+
maxWebWorkers: Math.min(
|
|
25
|
+
Math.max(navigator.hardwareConcurrency - 1, 1),
|
|
26
|
+
appConfig.maxNumberOfWebWorkers
|
|
27
|
+
),
|
|
28
|
+
beforeSend: function (xhr) {
|
|
29
|
+
//TODO should be removed in the future and request emitted by DicomWebDataSource
|
|
30
|
+
const sourceConfig = extensionManager.getActiveDataSource()?.[0].getConfig() ?? {};
|
|
31
|
+
const headers = userAuthenticationService.getAuthorizationHeader();
|
|
32
|
+
const acceptHeader = utils.generateAcceptHeader(
|
|
33
|
+
sourceConfig.acceptHeader,
|
|
34
|
+
sourceConfig.requestTransferSyntaxUID,
|
|
35
|
+
sourceConfig.omitQuotationForMultipartRequest
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
const xhrRequestHeaders = {
|
|
39
|
+
Accept: acceptHeader,
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
if (headers) {
|
|
43
|
+
Object.assign(xhrRequestHeaders, headers);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return xhrRequestHeaders;
|
|
47
|
+
},
|
|
48
|
+
errorInterceptor: error => {
|
|
49
|
+
errorHandler.getHTTPErrorHandler(error);
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function destroy() {
|
|
55
|
+
console.debug('Destroying WADO Image Loader');
|
|
56
|
+
}
|