@ohif/extension-cornerstone 3.14.0-beta.11 → 3.14.0-beta.111

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