@ohif/extension-cornerstone 3.14.0-beta.10 → 3.14.0-beta.101

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 (325) 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 +502 -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 +2951 -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/MeasurementItems.tsx +70 -0
  33. package/src/components/MeasurementTableNested.tsx +30 -0
  34. package/src/components/MeasurementsMenu.tsx +84 -0
  35. package/src/components/MeasurementsOrAdditionalFindings.tsx +82 -0
  36. package/src/components/ModalityLoadBadge/ModalityLoadBadge.tsx +171 -0
  37. package/src/components/ModalityLoadBadge/index.ts +1 -0
  38. package/src/components/NavigationComponent/NavigationComponent.tsx +138 -0
  39. package/src/components/NavigationComponent/index.ts +3 -0
  40. package/src/components/OHIFViewportActionCorners.tsx +94 -0
  41. package/src/components/OpacityMenu/OpacityMenu.tsx +54 -0
  42. package/src/components/OpacityMenu/OpacityMenuWrapper.tsx +85 -0
  43. package/src/components/OpacityMenu/index.ts +2 -0
  44. package/src/components/PanelAccordionTrigger.tsx +48 -0
  45. package/src/components/SegmentationToolConfig.tsx +71 -0
  46. package/src/components/SegmentationUtilityButton.tsx +61 -0
  47. package/src/components/SelectItemWithModality.tsx +29 -0
  48. package/src/components/SeriesMeasurements.tsx +90 -0
  49. package/src/components/SeriesSummaryFromDisplaySet.tsx +21 -0
  50. package/src/components/StudyMeasurements.tsx +88 -0
  51. package/src/components/StudyMeasurementsActions.tsx +75 -0
  52. package/src/components/StudySummaryFromMetadata.test.ts +47 -0
  53. package/src/components/StudySummaryFromMetadata.tsx +31 -0
  54. package/src/components/StudySummaryWithActions.tsx +14 -0
  55. package/src/components/ThresholdMenu/ThresholdMenu.tsx +104 -0
  56. package/src/components/ThresholdMenu/ThresholdMenuWrapper.tsx +85 -0
  57. package/src/components/ThresholdMenu/index.ts +2 -0
  58. package/src/components/TrackingStatus/TrackingStatus.tsx +32 -0
  59. package/src/components/TrackingStatus/index.ts +1 -0
  60. package/src/components/VOIManualControlMenu/VOIManualControlMenu.tsx +190 -0
  61. package/src/components/VOIManualControlMenu/VOIManualControlMenuWrapper.tsx +85 -0
  62. package/src/components/VOIManualControlMenu/index.ts +2 -0
  63. package/src/components/ViewportColorbar/ViewportColorbar.tsx +150 -0
  64. package/src/components/ViewportColorbar/ViewportColorbarsContainer.tsx +125 -0
  65. package/src/components/ViewportColorbar/index.ts +5 -0
  66. package/src/components/ViewportDataOverlaySettingMenu/ViewportDataOverlayMenu.tsx +538 -0
  67. package/src/components/ViewportDataOverlaySettingMenu/ViewportDataOverlayMenuWrapper.tsx +91 -0
  68. package/src/components/ViewportDataOverlaySettingMenu/utils.ts +118 -0
  69. package/src/components/ViewportOrientationMenu/ViewportOrientationMenu.tsx +249 -0
  70. package/src/components/ViewportOrientationMenu/ViewportOrientationMenuWrapper.tsx +29 -0
  71. package/src/components/ViewportWindowLevel/ViewportWindowLevel.tsx +261 -0
  72. package/src/components/ViewportWindowLevel/getViewportVolumeHistogram.ts +72 -0
  73. package/src/components/ViewportWindowLevel/histogramWorker.js +97 -0
  74. package/src/components/ViewportWindowLevel/index.js +1 -0
  75. package/src/components/ViewportWindowLevel/utils.ts +176 -0
  76. package/src/components/WindowLevelActionMenu/Colorbar.tsx +30 -0
  77. package/src/components/WindowLevelActionMenu/Colormap.tsx +121 -0
  78. package/src/components/WindowLevelActionMenu/VolumeLighting.tsx +82 -0
  79. package/src/components/WindowLevelActionMenu/VolumeRenderingOptions.tsx +38 -0
  80. package/src/components/WindowLevelActionMenu/VolumeRenderingPresets.tsx +36 -0
  81. package/src/components/WindowLevelActionMenu/VolumeRenderingPresetsContent.tsx +78 -0
  82. package/src/components/WindowLevelActionMenu/VolumeRenderingQuality.tsx +64 -0
  83. package/src/components/WindowLevelActionMenu/VolumeShade.tsx +47 -0
  84. package/src/components/WindowLevelActionMenu/VolumeShift.tsx +92 -0
  85. package/src/components/WindowLevelActionMenu/WindowLevel.tsx +157 -0
  86. package/src/components/WindowLevelActionMenu/WindowLevelActionMenu.tsx +102 -0
  87. package/src/components/WindowLevelActionMenu/WindowLevelActionMenuWrapper.tsx +131 -0
  88. package/src/components/WindowLevelActionMenu/defaultWindowLevelPresets.ts +23 -0
  89. package/src/components/WindowLevelActionMenu/index.ts +11 -0
  90. package/src/components/WindowLevelActionMenu/windowLevelPresetHotkeys.test.ts +19 -0
  91. package/src/components/index.ts +12 -0
  92. package/src/constants/index.ts +13 -0
  93. package/src/customizations/CustomDropdownMenuContent.tsx +106 -0
  94. package/src/customizations/CustomSegmentStatisticsHeader.tsx +140 -0
  95. package/src/customizations/captureViewportModalCustomization.tsx +175 -0
  96. package/src/customizations/colorbarCustomization.ts +93 -0
  97. package/src/customizations/gpuSettingsPresetCustomization.ts +8 -0
  98. package/src/customizations/layoutSelectorCustomization.ts +104 -0
  99. package/src/customizations/measurementsCustomization.ts +124 -0
  100. package/src/customizations/miscCustomization.ts +22 -0
  101. package/src/customizations/modalityColorMapCustomization.ts +23 -0
  102. package/src/customizations/segmentationHydrationCustomization.ts +16 -0
  103. package/src/customizations/segmentationPanelCustomization.tsx +119 -0
  104. package/src/customizations/segmentationToolbarCustomization.ts +964 -0
  105. package/src/customizations/toolGroupToolsCustomization.ts +204 -0
  106. package/src/customizations/toolbarButtonsCustomization.ts +805 -0
  107. package/src/customizations/viewportClickCommandsCustomization.ts +15 -0
  108. package/src/customizations/viewportDownloadWarningCustomization.tsx +6 -0
  109. package/src/customizations/viewportOverlayCustomization.tsx +46 -0
  110. package/src/customizations/viewportScrollbarCustomization.tsx +27 -0
  111. package/src/customizations/viewportToolsCustomization.ts +33 -0
  112. package/src/customizations/volumeRenderingCustomization.ts +14 -0
  113. package/src/customizations/windowLevelPresetsCustomization.ts +5 -0
  114. package/src/enums.ts +9 -0
  115. package/src/getCustomizationModule.tsx +54 -0
  116. package/src/getHangingProtocolModule.ts +47 -0
  117. package/src/getPanelModule.tsx +128 -0
  118. package/src/getSopClassHandlerModule.js +284 -0
  119. package/src/getToolbarModule.tsx +622 -0
  120. package/src/hooks/index.ts +8 -0
  121. package/src/hooks/useActiveViewportSegmentationRepresentations.ts +14 -0
  122. package/src/hooks/useMeasurementTracking.ts +132 -0
  123. package/src/hooks/useMeasurements.ts +104 -0
  124. package/src/hooks/useSegmentations.ts +147 -0
  125. package/src/hooks/useViewportDisplaySets.ts +284 -0
  126. package/src/hooks/useViewportHover.ts +77 -0
  127. package/src/hooks/useViewportRendering.tsx +868 -0
  128. package/src/hooks/useViewportSegmentations.ts +245 -0
  129. package/src/hps/fourUp.ts +117 -0
  130. package/src/hps/frameView.ts +1581 -0
  131. package/src/hps/main3D.ts +142 -0
  132. package/src/hps/mpr.ts +197 -0
  133. package/src/hps/mprAnd3DVolumeViewport.ts +124 -0
  134. package/src/hps/only3D.ts +70 -0
  135. package/src/hps/primary3D.ts +142 -0
  136. package/src/hps/primaryAxial.ts +114 -0
  137. package/src/id.js +5 -0
  138. package/src/index.tsx +350 -0
  139. package/src/init.tsx +445 -0
  140. package/src/initCineService.ts +75 -0
  141. package/src/initContextMenu.ts +94 -0
  142. package/src/initCornerstoneTools.js +188 -0
  143. package/src/initDoubleClick.ts +82 -0
  144. package/src/initMeasurementService.ts +576 -0
  145. package/src/initStudyPrefetcherService.ts +33 -0
  146. package/src/initWADOImageLoader.js +56 -0
  147. package/src/panels/PanelMeasurement.tsx +84 -0
  148. package/src/panels/PanelSegmentation.tsx +338 -0
  149. package/src/services/ColorbarService/ColorbarService.ts +242 -0
  150. package/src/services/ColorbarService/index.ts +2 -0
  151. package/src/services/CornerstoneCacheService/CornerstoneCacheService.ts +326 -0
  152. package/src/services/CornerstoneCacheService/index.js +3 -0
  153. package/src/services/SegmentationService/RTSTRUCT/mapROIContoursToRTStructData.ts +36 -0
  154. package/src/services/SegmentationService/SegmentationService.test.ts +3698 -0
  155. package/src/services/SegmentationService/SegmentationService.ts +2376 -0
  156. package/src/services/SegmentationService/backends/ISegmentationBackend.ts +102 -0
  157. package/src/services/SegmentationService/backends/ISegmentationServiceInternals.ts +44 -0
  158. package/src/services/SegmentationService/backends/LegacySegmentationBackend.ts +139 -0
  159. package/src/services/SegmentationService/backends/NextSegmentationBackend.ts +159 -0
  160. package/src/services/SegmentationService/backends/index.ts +4 -0
  161. package/src/services/SegmentationService/index.ts +3 -0
  162. package/src/services/SyncGroupService/SyncGroupService.ts +264 -0
  163. package/src/services/SyncGroupService/createHydrateSegmentationSynchronizer.ts +118 -0
  164. package/src/services/SyncGroupService/index.js +3 -0
  165. package/src/services/ToolGroupService/ToolGroupService.test.ts +83 -0
  166. package/src/services/ToolGroupService/ToolGroupService.ts +541 -0
  167. package/src/services/ToolGroupService/index.js +3 -0
  168. package/src/services/ViewedDataService/ViewedDataService.ts +58 -0
  169. package/src/services/ViewedDataService/index.ts +3 -0
  170. package/src/services/ViewportService/CornerstoneViewportService.ts +1814 -0
  171. package/src/services/ViewportService/IViewportService.ts +64 -0
  172. package/src/services/ViewportService/Viewport.ts +372 -0
  173. package/src/services/ViewportService/adapter/IViewportAdapter.contract.test.ts +467 -0
  174. package/src/services/ViewportService/adapter/IViewportAdapter.ts +179 -0
  175. package/src/services/ViewportService/adapter/LegacyViewportAdapter.ts +240 -0
  176. package/src/services/ViewportService/adapter/NextViewportAdapter.ts +241 -0
  177. package/src/services/ViewportService/adapter/getViewportAdapter.ts +62 -0
  178. package/src/services/ViewportService/adapter/index.ts +16 -0
  179. package/src/services/ViewportService/backends/IViewportBackend.ts +195 -0
  180. package/src/services/ViewportService/backends/IViewportOperations.ts +98 -0
  181. package/src/services/ViewportService/backends/IViewportServiceInternals.ts +47 -0
  182. package/src/services/ViewportService/backends/LegacyViewportBackend.ts +264 -0
  183. package/src/services/ViewportService/backends/LegacyViewportOperations.ts +272 -0
  184. package/src/services/ViewportService/backends/NextViewportBackend.ts +671 -0
  185. package/src/services/ViewportService/backends/NextViewportOperations.ts +169 -0
  186. package/src/services/ViewportService/backends/README.md +62 -0
  187. package/src/services/ViewportService/backends/dataIdRegistry.ts +121 -0
  188. package/src/services/ViewportService/backends/viewportOperations.ts +71 -0
  189. package/src/services/ViewportService/constants.ts +3 -0
  190. package/src/state.ts +34 -0
  191. package/src/stores/index.ts +5 -0
  192. package/src/stores/presentationUtils.ts +42 -0
  193. package/src/stores/useLutPresentationStore.ts +166 -0
  194. package/src/stores/usePositionPresentationStore.ts +172 -0
  195. package/src/stores/useSegmentationPresentationStore.test.ts +146 -0
  196. package/src/stores/useSegmentationPresentationStore.ts +417 -0
  197. package/src/stores/useSelectedSegmentationsForViewportStore.ts +85 -0
  198. package/src/stores/useSynchronizersStore.ts +84 -0
  199. package/src/synchronizers/frameViewSynchronizer.ts +52 -0
  200. package/src/tools/CalibrationLineTool.ts +97 -0
  201. package/src/tools/ImageOverlayViewerTool.tsx +279 -0
  202. package/src/tools/OverlayPlaneModuleProvider.ts +40 -0
  203. package/src/tools/WindowLevelTool.test.ts +55 -0
  204. package/src/tools/WindowLevelTool.ts +22 -0
  205. package/src/types/AppTypes.ts +70 -0
  206. package/src/types/Colorbar.ts +114 -0
  207. package/src/types/Colormap.ts +16 -0
  208. package/src/types/CornerstoneCacheService.ts +40 -0
  209. package/src/types/CornerstoneServices.ts +18 -0
  210. package/src/types/Presentation.ts +83 -0
  211. package/src/types/SelectedSegmentationByTypeMap.ts +3 -0
  212. package/src/types/ViewportPresets.ts +53 -0
  213. package/src/types/VolumeLighting.ts +7 -0
  214. package/src/types/VolumeRenderingConfig.ts +8 -0
  215. package/src/types/WindowLevel.ts +5 -0
  216. package/src/types/index.ts +10 -0
  217. package/src/utils/ActiveViewportBehavior.tsx +80 -0
  218. package/src/utils/CornerstoneViewportDownloadForm.tsx +319 -0
  219. package/src/utils/DicomFileUploader.ts +204 -0
  220. package/src/utils/JumpPresets.ts +14 -0
  221. package/src/utils/autoHydrateViewportTypes.ts +69 -0
  222. package/src/utils/colormaps.js +1597 -0
  223. package/src/utils/createSegmentationForViewport.ts +83 -0
  224. package/src/utils/dicomLoaderService.js +225 -0
  225. package/src/utils/ecgMetadata.test.ts +137 -0
  226. package/src/utils/ecgMetadata.ts +109 -0
  227. package/src/utils/findNearbyToolData.test.ts +125 -0
  228. package/src/utils/findNearbyToolData.ts +21 -0
  229. package/src/utils/generateSegmentationCSVReport.test.ts +324 -0
  230. package/src/utils/generateSegmentationCSVReport.ts +131 -0
  231. package/src/utils/getActiveViewportEnabledElement.test.ts +70 -0
  232. package/src/utils/getActiveViewportEnabledElement.ts +8 -0
  233. package/src/utils/getCenterExtent.test.ts +313 -0
  234. package/src/utils/getCenterExtent.ts +46 -0
  235. package/src/utils/getCornerstoneBlendMode.test.ts +59 -0
  236. package/src/utils/getCornerstoneBlendMode.ts +25 -0
  237. package/src/utils/getCornerstoneOrientation.test.ts +78 -0
  238. package/src/utils/getCornerstoneOrientation.ts +31 -0
  239. package/src/utils/getCornerstoneViewportType.test.ts +169 -0
  240. package/src/utils/getCornerstoneViewportType.ts +88 -0
  241. package/src/utils/getInterleavedFrames.test.ts +85 -0
  242. package/src/utils/getInterleavedFrames.ts +73 -0
  243. package/src/utils/getLegacyViewportType.ts +64 -0
  244. package/src/utils/getNthFrames.test.ts +145 -0
  245. package/src/utils/getNthFrames.ts +31 -0
  246. package/src/utils/getViewportEnabledElement.test.ts +83 -0
  247. package/src/utils/getViewportEnabledElement.ts +8 -0
  248. package/src/utils/getViewportOrientationFromImageOrientationPatient.test.ts +50 -0
  249. package/src/utils/getViewportOrientationFromImageOrientationPatient.ts +56 -0
  250. package/src/utils/hydrationUtils.test.ts +572 -0
  251. package/src/utils/hydrationUtils.ts +197 -0
  252. package/src/utils/imageSliceSync/calculateViewportRegistrations.ts +28 -0
  253. package/src/utils/imageSliceSync/toggleImageSliceSync.ts +101 -0
  254. package/src/utils/index.ts +29 -0
  255. package/src/utils/initGpuSettingsPreset.ts +51 -0
  256. package/src/utils/initViewTiming.test.ts +342 -0
  257. package/src/utils/initViewTiming.ts +52 -0
  258. package/src/utils/initWebWorkerProgressHandler.test.ts +381 -0
  259. package/src/utils/initWebWorkerProgressHandler.ts +110 -0
  260. package/src/utils/interleave.test.ts +304 -0
  261. package/src/utils/interleave.ts +32 -0
  262. package/src/utils/interleaveCenterLoader.test.ts +547 -0
  263. package/src/utils/interleaveCenterLoader.ts +143 -0
  264. package/src/utils/interleaveTopToBottom.test.ts +487 -0
  265. package/src/utils/interleaveTopToBottom.ts +132 -0
  266. package/src/utils/isAnyDisplaySetCommon.ts +18 -0
  267. package/src/utils/isDisplaySetOverlayable.ts +96 -0
  268. package/src/utils/isMeasurementWithinViewport.test.ts +340 -0
  269. package/src/utils/isMeasurementWithinViewport.ts +33 -0
  270. package/src/utils/isReferenceViewable.test.ts +581 -0
  271. package/src/utils/isReferenceViewable.ts +95 -0
  272. package/src/utils/loadDisplaySetData.ts +49 -0
  273. package/src/utils/measurementServiceMappings/Angle.ts +200 -0
  274. package/src/utils/measurementServiceMappings/ArrowAnnotate.ts +176 -0
  275. package/src/utils/measurementServiceMappings/Bidirectional.ts +193 -0
  276. package/src/utils/measurementServiceMappings/CircleROI.ts +227 -0
  277. package/src/utils/measurementServiceMappings/CobbAngle.ts +206 -0
  278. package/src/utils/measurementServiceMappings/EllipticalROI.ts +221 -0
  279. package/src/utils/measurementServiceMappings/Length.ts +206 -0
  280. package/src/utils/measurementServiceMappings/LivewireContour.ts +175 -0
  281. package/src/utils/measurementServiceMappings/PlanarFreehandROI.ts +228 -0
  282. package/src/utils/measurementServiceMappings/Probe.ts +192 -0
  283. package/src/utils/measurementServiceMappings/RectangleROI.ts +225 -0
  284. package/src/utils/measurementServiceMappings/SegmentBidirectional.ts +184 -0
  285. package/src/utils/measurementServiceMappings/SplineROI.ts +227 -0
  286. package/src/utils/measurementServiceMappings/UltrasoundDirectional.ts +214 -0
  287. package/src/utils/measurementServiceMappings/UltrasoundPleuraBLine.ts +179 -0
  288. package/src/utils/measurementServiceMappings/constants/supportedTools.js +21 -0
  289. package/src/utils/measurementServiceMappings/index.ts +3 -0
  290. package/src/utils/measurementServiceMappings/measurementServiceMappingsFactory.ts +324 -0
  291. package/src/utils/measurementServiceMappings/utils/getDisplayUnit.js +3 -0
  292. package/src/utils/measurementServiceMappings/utils/getHandlesFromPoints.js +14 -0
  293. package/src/utils/measurementServiceMappings/utils/getIsLocked.ts +5 -0
  294. package/src/utils/measurementServiceMappings/utils/getIsVisible.ts +6 -0
  295. package/src/utils/measurementServiceMappings/utils/getSOPInstanceAttributes.js +66 -0
  296. package/src/utils/measurementServiceMappings/utils/getValueDisplayString.js +12 -0
  297. package/src/utils/measurementServiceMappings/utils/index.ts +17 -0
  298. package/src/utils/measurementServiceMappings/utils/selection.ts +33 -0
  299. package/src/utils/mpr/getProtocolViewportStructureFromGridViewports.ts +74 -0
  300. package/src/utils/nextViewportPolicies.ts +41 -0
  301. package/src/utils/nextViewports.ts +157 -0
  302. package/src/utils/nthLoader.test.ts +317 -0
  303. package/src/utils/nthLoader.ts +78 -0
  304. package/src/utils/presentations/getViewportPresentations.test.ts +280 -0
  305. package/src/utils/presentations/getViewportPresentations.ts +151 -0
  306. package/src/utils/promptHydrationDialog.test.ts +490 -0
  307. package/src/utils/promptHydrationDialog.ts +197 -0
  308. package/src/utils/removeViewportSegmentationRepresentations.test.ts +129 -0
  309. package/src/utils/removeViewportSegmentationRepresentations.ts +17 -0
  310. package/src/utils/segmentUtils.test.ts +515 -0
  311. package/src/utils/segmentUtils.ts +46 -0
  312. package/src/utils/segmentationExportUtils.test.ts +100 -0
  313. package/src/utils/segmentationExportUtils.ts +171 -0
  314. package/src/utils/segmentationHandlers.test.ts +614 -0
  315. package/src/utils/segmentationHandlers.ts +164 -0
  316. package/src/utils/setUpAnnotationEventHandlers.ts +26 -0
  317. package/src/utils/setUpSegmentationEventHandlers.test.ts +372 -0
  318. package/src/utils/setUpSegmentationEventHandlers.ts +122 -0
  319. package/src/utils/toggleVOISliceSync.test.ts +606 -0
  320. package/src/utils/toggleVOISliceSync.ts +103 -0
  321. package/src/utils/transitions.test.ts +351 -0
  322. package/src/utils/transitions.ts +300 -0
  323. package/src/utils/updateSegmentationStats.test.ts +942 -0
  324. package/src/utils/updateSegmentationStats.ts +192 -0
  325. package/src/utils/viewportDataShape.ts +85 -0
@@ -0,0 +1,2951 @@
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
+
1053
+ if (!labelConfig) {
1054
+ const label = await callInputDialog({
1055
+ uiDialogService,
1056
+ title: i18n.t('Tools:Edit Arrow Text'),
1057
+ placeholder: data?.data?.label || i18n.t('Tools:Enter new text'),
1058
+ defaultValue: data?.data?.label || '',
1059
+ });
1060
+
1061
+ callback?.(label);
1062
+ return;
1063
+ }
1064
+
1065
+ const value = await callInputDialogAutoComplete({
1066
+ uiDialogService,
1067
+ labelConfig,
1068
+ renderContent,
1069
+ });
1070
+ callback?.(value);
1071
+ },
1072
+
1073
+ toggleCine: () => {
1074
+ const { viewports } = viewportGridService.getState();
1075
+ const { isCineEnabled } = cineService.getState();
1076
+ cineService.setIsCineEnabled(!isCineEnabled);
1077
+ viewports.forEach((_, index) => cineService.setCine({ id: index, isPlaying: false }));
1078
+ },
1079
+
1080
+ setViewportWindowLevel({
1081
+ viewportId,
1082
+ windowWidth,
1083
+ windowCenter,
1084
+ displaySetInstanceUID,
1085
+ }: {
1086
+ viewportId: string;
1087
+ windowWidth: number;
1088
+ windowCenter: number;
1089
+ displaySetInstanceUID?: string;
1090
+ }) {
1091
+ // convert to numbers
1092
+ const windowWidthNum = Number(windowWidth);
1093
+ const windowCenterNum = Number(windowCenter);
1094
+
1095
+ const renderingEngine = cornerstoneViewportService.getRenderingEngine();
1096
+ const viewport = renderingEngine.getViewport(viewportId);
1097
+
1098
+ // Stale/invalid viewport ids resolve to undefined; bail out before the VOI
1099
+ // apply + render below would throw.
1100
+ if (!viewport) {
1101
+ return;
1102
+ }
1103
+
1104
+ // Legacy volume viewports target a specific volume; the command owns that
1105
+ // resolution (it needs the service). The operations backend applies the VOI
1106
+ // (legacy setProperties vs native setDisplaySetPresentation on the active binding).
1107
+ const volumeId = isVolumeViewportType(viewport)
1108
+ ? actions.getVolumeIdForDisplaySet({ viewportId, displaySetInstanceUID })
1109
+ : undefined;
1110
+
1111
+ ops.setWindowLevel(viewport, {
1112
+ windowWidth: windowWidthNum,
1113
+ windowCenter: windowCenterNum,
1114
+ volumeId,
1115
+ displaySetInstanceUID,
1116
+ });
1117
+ viewport.render();
1118
+ },
1119
+ toggleViewportColorbar: ({ viewportId, displaySetInstanceUIDs, options = {} }) => {
1120
+ const hasColorbar = colorbarService.hasColorbar(viewportId);
1121
+ if (hasColorbar) {
1122
+ colorbarService.removeColorbar(viewportId);
1123
+ return;
1124
+ }
1125
+ colorbarService.addColorbar(viewportId, displaySetInstanceUIDs, options);
1126
+ },
1127
+ setWindowLevel(props) {
1128
+ const { toolGroupId } = props;
1129
+ const { viewportId } = _getActiveViewportEnabledElement();
1130
+ const viewportToolGroupId = toolGroupService.getToolGroupForViewport(viewportId);
1131
+
1132
+ if (toolGroupId && toolGroupId !== viewportToolGroupId) {
1133
+ return;
1134
+ }
1135
+
1136
+ actions.setViewportWindowLevel({ ...props, viewportId });
1137
+ },
1138
+ setWindowLevelPreset: ({ presetName, presetIndex }) => {
1139
+ const windowLevelPresets = customizationService.getCustomization(
1140
+ 'cornerstone.windowLevelPresets'
1141
+ );
1142
+
1143
+ const activeViewport = viewportGridService.getActiveViewportId();
1144
+ const viewport = cornerstoneViewportService.getCornerstoneViewport(activeViewport);
1145
+ const metadata = viewport.getImageData().metadata;
1146
+
1147
+ const modality = metadata.Modality;
1148
+
1149
+ if (!modality) {
1150
+ return;
1151
+ }
1152
+
1153
+ const windowLevelPresetForModality = windowLevelPresets[modality];
1154
+
1155
+ if (!windowLevelPresetForModality) {
1156
+ return;
1157
+ }
1158
+
1159
+ const windowLevelPreset =
1160
+ windowLevelPresetForModality[presetName] ??
1161
+ Object.values(windowLevelPresetForModality)[presetIndex];
1162
+
1163
+ actions.setViewportWindowLevel({
1164
+ viewportId: activeViewport,
1165
+ windowWidth: windowLevelPreset.window,
1166
+ windowCenter: windowLevelPreset.level,
1167
+ });
1168
+ },
1169
+ getVolumeIdForDisplaySet: ({ viewportId, displaySetInstanceUID }) => {
1170
+ const viewport = cornerstoneViewportService.getCornerstoneViewport(viewportId);
1171
+ // `instanceof BaseVolumeViewport` is false for GenericViewport compat adapters,
1172
+ // so use the capability guard instead (cornerstone 5.x generic-viewport guide).
1173
+ // A stack-mode adapter passes the guard but getAllVolumeIds() returns [], so the
1174
+ // result is the same null as before on stacks.
1175
+ if (csUtils.viewportSupportsVolumeId(viewport)) {
1176
+ const volumeIds = (viewport as CoreTypes.IVolumeViewport).getAllVolumeIds();
1177
+ const volumeId = volumeIds.find(id => id.includes(displaySetInstanceUID));
1178
+ return volumeId;
1179
+ }
1180
+ return null;
1181
+ },
1182
+ setToolEnabled: ({ toolName, toggle, toolGroupId }) => {
1183
+ const { viewports } = viewportGridService.getState();
1184
+
1185
+ if (!viewports.size) {
1186
+ return;
1187
+ }
1188
+
1189
+ const toolGroup = toolGroupService.getToolGroup(toolGroupId ?? null);
1190
+
1191
+ if (!toolGroup || !toolGroup.hasTool(toolName)) {
1192
+ return;
1193
+ }
1194
+
1195
+ const toolIsEnabled = toolGroup.getToolOptions(toolName).mode === Enums.ToolModes.Enabled;
1196
+
1197
+ // Toggle the tool's state only if the toggle is true
1198
+ if (toggle) {
1199
+ toolIsEnabled ? toolGroup.setToolDisabled(toolName) : toolGroup.setToolEnabled(toolName);
1200
+ } else {
1201
+ toolGroup.setToolEnabled(toolName);
1202
+ }
1203
+
1204
+ const renderingEngine = cornerstoneViewportService.getRenderingEngine();
1205
+ renderingEngine.render();
1206
+ },
1207
+ toggleEnabledDisabledToolbar({ value, itemId, toolGroupId }) {
1208
+ const toolName = itemId || value;
1209
+ toolGroupId = toolGroupId ?? _getActiveViewportToolGroupId();
1210
+
1211
+ const toolGroup = toolGroupService.getToolGroup(toolGroupId);
1212
+ if (!toolGroup || !toolGroup.hasTool(toolName)) {
1213
+ return;
1214
+ }
1215
+
1216
+ const toolIsEnabled = toolGroup.getToolOptions(toolName).mode === Enums.ToolModes.Enabled;
1217
+
1218
+ toolIsEnabled ? toolGroup.setToolDisabled(toolName) : toolGroup.setToolEnabled(toolName);
1219
+ },
1220
+ toggleActiveDisabledToolbar({ value, itemId, toolGroupId, toolGroupIds }) {
1221
+ const toolName = itemId || value;
1222
+ const resolvedToolGroupIds = toolGroupIds?.length
1223
+ ? toolGroupIds
1224
+ : [toolGroupId ?? _getActiveViewportToolGroupId()];
1225
+
1226
+ resolvedToolGroupIds.forEach(toolGroupId => {
1227
+ const toolGroup = toolGroupService.getToolGroup(toolGroupId);
1228
+ if (!toolGroup || !toolGroup.hasTool(toolName)) {
1229
+ return;
1230
+ }
1231
+
1232
+ const toolIsActive = [
1233
+ Enums.ToolModes.Active,
1234
+ Enums.ToolModes.Enabled,
1235
+ Enums.ToolModes.Passive,
1236
+ ].includes(toolGroup.getToolOptions(toolName).mode);
1237
+
1238
+ if (toolIsActive) {
1239
+ toolGroup.setToolDisabled(toolName);
1240
+
1241
+ const bindings = toolGroupService.getToolBindings(toolGroupId, toolName);
1242
+
1243
+ if (_usesPrimaryActivation(bindings)) {
1244
+ // we should set the previously active tool to active after we set the
1245
+ // current tool disabled
1246
+ const prevToolName = toolGroup.getPrevActivePrimaryToolName();
1247
+ if (prevToolName !== toolName) {
1248
+ actions.setToolActive({ toolName: prevToolName, toolGroupId });
1249
+ }
1250
+ }
1251
+
1252
+ return;
1253
+ }
1254
+
1255
+ const bindings = toolGroupService.getToolBindings(toolGroupId, toolName);
1256
+ if (_usesPrimaryActivation(bindings)) {
1257
+ actions.setToolActive({ toolName, toolGroupId, bindings });
1258
+ } else {
1259
+ toolGroup.setToolActive(toolName, { bindings });
1260
+ }
1261
+ });
1262
+ },
1263
+ setToolActiveToolbar: ({ value, itemId, toolName, toolGroupIds = [], bindings }) => {
1264
+ // Sometimes it is passed as value (tools with options), sometimes as itemId (toolbar buttons)
1265
+ toolName = toolName || itemId || value;
1266
+
1267
+ toolGroupIds = toolGroupIds.length ? toolGroupIds : toolGroupService.getToolGroupIds();
1268
+
1269
+ toolGroupIds.forEach(toolGroupId => {
1270
+ actions.setToolActive({ toolName, toolGroupId, bindings });
1271
+ });
1272
+ },
1273
+ setToolActive: ({
1274
+ toolName,
1275
+ toolGroupId = null,
1276
+ bindings = [{ mouseButton: Enums.MouseBindings.Primary }],
1277
+ }) => {
1278
+ const { viewports } = viewportGridService.getState();
1279
+
1280
+ if (!viewports.size) {
1281
+ return;
1282
+ }
1283
+
1284
+ const toolGroup = toolGroupService.getToolGroup(toolGroupId);
1285
+
1286
+ if (!toolGroup) {
1287
+ return;
1288
+ }
1289
+
1290
+ if (!toolGroup?.hasTool(toolName)) {
1291
+ return;
1292
+ }
1293
+
1294
+ const activeToolName = toolGroup.getActivePrimaryMouseButtonTool();
1295
+
1296
+ if (activeToolName) {
1297
+ const activeToolOptions = toolGroup.getToolConfiguration(activeToolName);
1298
+ activeToolOptions?.disableOnPassive
1299
+ ? toolGroup.setToolDisabled(activeToolName)
1300
+ : toolGroup.setToolPassive(activeToolName);
1301
+ }
1302
+
1303
+ // Set the new toolName to be active
1304
+ toolGroup.setToolActive(toolName, {
1305
+ bindings,
1306
+ });
1307
+ },
1308
+ // capture viewport
1309
+ showDownloadViewportModal: () => {
1310
+ const { activeViewportId } = viewportGridService.getState();
1311
+
1312
+ if (!cornerstoneViewportService.getCornerstoneViewport(activeViewportId)) {
1313
+ // Cannot download a non-cornerstone viewport (image).
1314
+ uiNotificationService.show({
1315
+ title: i18n.t('Tools:Download Image'),
1316
+ message: i18n.t('Tools:Image cannot be downloaded'),
1317
+ type: 'error',
1318
+ });
1319
+ return;
1320
+ }
1321
+
1322
+ const { uiModalService } = servicesManager.services;
1323
+
1324
+ if (uiModalService) {
1325
+ uiModalService.show({
1326
+ content: CornerstoneViewportDownloadForm,
1327
+ title: i18n.t('Tools:Download High Quality Image'),
1328
+ contentProps: {
1329
+ activeViewportId,
1330
+ cornerstoneViewportService,
1331
+ },
1332
+ containerClassName: 'max-w-4xl p-4',
1333
+ });
1334
+ }
1335
+ },
1336
+ /**
1337
+ * Rotates the viewport by `rotation` relative to its current rotation.
1338
+ */
1339
+ rotateViewportBy: ({ rotation, viewportId }: { rotation: number; viewportId?: string }) => {
1340
+ actions._rotateViewport({ rotation, viewportId, rotationMode: 'apply' });
1341
+ },
1342
+ /**
1343
+ * Sets the viewport rotation to an absolute value `rotation`.
1344
+ */
1345
+ setViewportRotation: ({ rotation, viewportId }: { rotation: number; viewportId?: string }) => {
1346
+ actions._rotateViewport({ rotation, viewportId, rotationMode: 'set' });
1347
+ },
1348
+ flipViewportHorizontal: ({
1349
+ viewportId,
1350
+ newValue = 'toggle',
1351
+ }: {
1352
+ viewportId?: string;
1353
+ newValue?: 'toggle' | boolean;
1354
+ }) => {
1355
+ const viewport = _resolveViewport(viewportId);
1356
+ if (!viewport) {
1357
+ return;
1358
+ }
1359
+ ops.flipHorizontal(viewport, newValue);
1360
+ viewport.render();
1361
+ },
1362
+ flipViewportVertical: ({
1363
+ viewportId,
1364
+ newValue = 'toggle',
1365
+ }: {
1366
+ viewportId?: string;
1367
+ newValue?: 'toggle' | boolean;
1368
+ }) => {
1369
+ const viewport = _resolveViewport(viewportId);
1370
+ if (!viewport) {
1371
+ return;
1372
+ }
1373
+ ops.flipVertical(viewport, newValue);
1374
+ viewport.render();
1375
+ },
1376
+ invertViewport: ({ element }) => {
1377
+ const viewport = element === undefined ? _resolveViewport() : element.viewport;
1378
+ if (!viewport) {
1379
+ return;
1380
+ }
1381
+ ops.invert(viewport);
1382
+ viewport.render();
1383
+ },
1384
+ resetViewport: () => {
1385
+ const viewport = _resolveViewport();
1386
+ if (!viewport) {
1387
+ return;
1388
+ }
1389
+ ops.reset(viewport);
1390
+ viewport.render();
1391
+ },
1392
+ scaleViewport: ({ direction }) => {
1393
+ const viewport = _resolveViewport();
1394
+ if (!viewport) {
1395
+ return;
1396
+ }
1397
+ ops.scaleBy(viewport, direction);
1398
+ viewport.render();
1399
+ },
1400
+
1401
+ /** Jumps the active viewport or the specified one to the given slice index */
1402
+ jumpToImage: ({ imageIndex, viewport: gridViewport }): void => {
1403
+ // Get current active viewport (return if none active)
1404
+ let viewport;
1405
+ if (!gridViewport) {
1406
+ const enabledElement = _getActiveViewportEnabledElement();
1407
+ if (!enabledElement) {
1408
+ return;
1409
+ }
1410
+ viewport = enabledElement.viewport;
1411
+ } else {
1412
+ viewport = cornerstoneViewportService.getCornerstoneViewport(gridViewport.id);
1413
+ }
1414
+
1415
+ // Get number of slices
1416
+ // -> Copied from cornerstone3D jumpToSlice\_getImageSliceData()
1417
+ let numberOfSlices = 0;
1418
+
1419
+ if (isStackViewportType(viewport)) {
1420
+ numberOfSlices = viewport.getImageIds().length;
1421
+ } else if (isOrthographicViewportType(viewport)) {
1422
+ numberOfSlices = csUtils.getImageSliceDataForVolumeViewport(viewport).numberOfSlices;
1423
+ } else {
1424
+ throw new Error('Unsupported viewport type');
1425
+ }
1426
+
1427
+ const jumpIndex = imageIndex < 0 ? numberOfSlices + imageIndex : imageIndex;
1428
+ if (jumpIndex >= numberOfSlices || jumpIndex < 0) {
1429
+ throw new Error(`Can't jump to ${imageIndex}`);
1430
+ }
1431
+
1432
+ // Set slice to last slice
1433
+ const options = { imageIndex: jumpIndex };
1434
+ csUtils.jumpToSlice(viewport.element, options);
1435
+ },
1436
+ scroll: (options: ToolTypes.ScrollOptions) => {
1437
+ const enabledElement = _getActiveViewportEnabledElement();
1438
+ // Allow either or direction for consistency in scroll implementation
1439
+ options.delta ??= options.direction || 1;
1440
+ options.direction ??= options.delta;
1441
+
1442
+ if (!enabledElement) {
1443
+ return;
1444
+ }
1445
+
1446
+ const { viewport } = enabledElement;
1447
+
1448
+ csUtils.scroll(viewport, options);
1449
+ },
1450
+ setViewportColormap: ({
1451
+ viewportId,
1452
+ displaySetInstanceUID,
1453
+ colormap,
1454
+ opacity = 1,
1455
+ immediate = false,
1456
+ }) => {
1457
+ const viewport = cornerstoneViewportService.getCornerstoneViewport(viewportId);
1458
+
1459
+ let hpOpacity;
1460
+ // Retrieve active protocol's viewport match details
1461
+ const { viewportMatchDetails } = hangingProtocolService.getActiveProtocol();
1462
+ // Get display set options for the specified viewport ID
1463
+ const displaySetsInfo = viewportMatchDetails.get(viewportId)?.displaySetsInfo;
1464
+
1465
+ if (displaySetsInfo) {
1466
+ // Find the display set that matches the given UID
1467
+ const matchingDisplaySet = displaySetsInfo.find(
1468
+ displaySet => displaySet.displaySetInstanceUID === displaySetInstanceUID
1469
+ );
1470
+ // If a matching display set is found, update the opacity with its value
1471
+ hpOpacity = matchingDisplaySet?.displaySetOptions?.options?.colormap?.opacity;
1472
+ }
1473
+
1474
+ // HP takes priority over the default opacity
1475
+ colormap = { ...colormap, opacity: hpOpacity || opacity };
1476
+
1477
+ // The legacy orthographic branch resolves the volumeId from the display set;
1478
+ // fall back to the viewport's first display set (needs viewportGridService, so
1479
+ // it is resolved here in the command rather than in the operations backend).
1480
+ if (isOrthographicViewportType(viewport) && !displaySetInstanceUID) {
1481
+ const { viewports } = viewportGridService.getState();
1482
+ displaySetInstanceUID = viewports.get(viewportId)?.displaySetInstanceUIDs[0];
1483
+ }
1484
+
1485
+ ops.setColormap(viewport, { colormap, displaySetInstanceUID });
1486
+
1487
+ if (immediate) {
1488
+ viewport.render();
1489
+ }
1490
+ },
1491
+ changeActiveViewport: ({ direction = 1 }) => {
1492
+ const { activeViewportId, viewports } = viewportGridService.getState();
1493
+ const viewportIds = Array.from(viewports.keys());
1494
+ const currentIndex = viewportIds.indexOf(activeViewportId);
1495
+ const nextViewportIndex =
1496
+ (currentIndex + direction + viewportIds.length) % viewportIds.length;
1497
+ viewportGridService.setActiveViewportId(viewportIds[nextViewportIndex] as string);
1498
+ },
1499
+ /**
1500
+ * If the syncId is given and a synchronizer with that ID already exists, it will
1501
+ * toggle it on/off for the provided viewports. If not, it will attempt to create
1502
+ * a new synchronizer using the given syncId and type for the specified viewports.
1503
+ * If no viewports are provided, you may notice some default behavior.
1504
+ * - 'voi' type, we will aim to synchronize all viewports with the same modality
1505
+ * -'imageSlice' type, we will aim to synchronize all viewports with the same orientation.
1506
+ *
1507
+ * @param options
1508
+ * @param options.viewports - The viewports to synchronize
1509
+ * @param options.syncId - The synchronization group ID
1510
+ * @param options.type - The type of synchronization to perform
1511
+ */
1512
+ toggleSynchronizer: ({ type, viewports, syncId }) => {
1513
+ const synchronizer = syncGroupService.getSynchronizer(syncId);
1514
+
1515
+ if (synchronizer) {
1516
+ synchronizer.isDisabled() ? synchronizer.setEnabled(true) : synchronizer.setEnabled(false);
1517
+ return;
1518
+ }
1519
+
1520
+ const fn = toggleSyncFunctions[type];
1521
+
1522
+ if (fn) {
1523
+ fn({
1524
+ servicesManager,
1525
+ viewports,
1526
+ syncId,
1527
+ });
1528
+ }
1529
+ },
1530
+ setViewportForToolConfiguration: ({ viewportId, toolName }) => {
1531
+ if (!viewportId) {
1532
+ const { activeViewportId } = viewportGridService.getState();
1533
+ viewportId = activeViewportId ?? 'default';
1534
+ }
1535
+
1536
+ const toolGroup = toolGroupService.getToolGroupForViewport(viewportId);
1537
+
1538
+ if (!toolGroup?.hasTool(toolName)) {
1539
+ return;
1540
+ }
1541
+
1542
+ const prevConfig = toolGroup?.getToolConfiguration(toolName);
1543
+ toolGroup?.setToolConfiguration(
1544
+ toolName,
1545
+ {
1546
+ ...prevConfig,
1547
+ sourceViewportId: viewportId,
1548
+ },
1549
+ true // overwrite
1550
+ );
1551
+
1552
+ const renderingEngine = cornerstoneViewportService.getRenderingEngine();
1553
+ renderingEngine.render();
1554
+ },
1555
+ storePresentation: ({ viewportId }) => {
1556
+ cornerstoneViewportService.storePresentation({ viewportId });
1557
+ },
1558
+ updateVolumeData: ({ volume }) => {
1559
+ // Marks the imageData and every texture set (full and reduced) of the computed volume dirty.
1560
+ volume.modified();
1561
+ },
1562
+
1563
+ attachProtocolViewportDataListener: ({ protocol, stageIndex }) => {
1564
+ const EVENT = cornerstoneViewportService.EVENTS.VIEWPORT_DATA_CHANGED;
1565
+ const command = protocol.callbacks.onViewportDataInitialized;
1566
+ const numPanes = protocol.stages?.[stageIndex]?.viewports.length ?? 1;
1567
+ let numPanesWithData = 0;
1568
+ const { unsubscribe } = cornerstoneViewportService.subscribe(EVENT, evt => {
1569
+ numPanesWithData++;
1570
+
1571
+ if (numPanesWithData === numPanes) {
1572
+ commandsManager.run(...command);
1573
+
1574
+ // Unsubscribe from the event
1575
+ unsubscribe(EVENT);
1576
+ }
1577
+ });
1578
+ },
1579
+
1580
+ setViewportPreset: ({ viewportId, preset }) => {
1581
+ const viewport = cornerstoneViewportService.getCornerstoneViewport(viewportId);
1582
+ if (!viewport) {
1583
+ return;
1584
+ }
1585
+ ops.setPreset(viewport, preset);
1586
+ viewport.render();
1587
+ },
1588
+
1589
+ /**
1590
+ * Sets the volume quality for a given viewport.
1591
+ * @param {string} viewportId - The ID of the viewport to set the volume quality.
1592
+ * @param {number} volumeQuality - The desired quality level of the volume rendering.
1593
+ */
1594
+
1595
+ setVolumeRenderingQulaity: ({ viewportId, volumeQuality }) => {
1596
+ const viewport = cornerstoneViewportService.getCornerstoneViewport(viewportId);
1597
+ if (!viewport) {
1598
+ return;
1599
+ }
1600
+ ops.setVolumeRenderingQuality(viewport, volumeQuality);
1601
+ viewport.render();
1602
+ },
1603
+
1604
+ /**
1605
+ * Shifts opacity points for a given viewport id.
1606
+ * @param {string} viewportId - The ID of the viewport to set the mapping range.
1607
+ * @param {number} shift - The shift value to shift the points by.
1608
+ */
1609
+ shiftVolumeOpacityPoints: ({ viewportId, shift }) => {
1610
+ const viewport = cornerstoneViewportService.getCornerstoneViewport(viewportId);
1611
+ if (!viewport) {
1612
+ return;
1613
+ }
1614
+ ops.shiftVolumeOpacityPoints(viewport, shift);
1615
+ viewport.render();
1616
+ },
1617
+
1618
+ /**
1619
+ * Sets the volume lighting settings for a given viewport.
1620
+ * @param {string} viewportId - The ID of the viewport to set the lighting settings.
1621
+ * @param {Object} options - The lighting settings to be set.
1622
+ * @param {boolean} options.shade - The shade setting for the lighting.
1623
+ * @param {number} options.ambient - The ambient setting for the lighting.
1624
+ * @param {number} options.diffuse - The diffuse setting for the lighting.
1625
+ * @param {number} options.specular - The specular setting for the lighting.
1626
+ **/
1627
+
1628
+ setVolumeLighting: ({ viewportId, options }) => {
1629
+ const viewport = cornerstoneViewportService.getCornerstoneViewport(viewportId);
1630
+ if (!viewport) {
1631
+ return;
1632
+ }
1633
+ ops.setVolumeLighting(viewport, options);
1634
+ viewport.render();
1635
+ },
1636
+ resetCrosshairs: ({ viewportId }) => {
1637
+ const crosshairInstances = [];
1638
+
1639
+ const getCrosshairInstances = toolGroupId => {
1640
+ const toolGroup = toolGroupService.getToolGroup(toolGroupId);
1641
+ // Only fetch the instance when Crosshairs is registered in this tool
1642
+ // group. getToolInstance logs a warning for an unregistered tool, and a
1643
+ // viewport's default tool group does not always include Crosshairs (e.g.
1644
+ // next viewports), which made Reset Viewport log a spurious warning.
1645
+ if (toolGroup?.hasTool('Crosshairs')) {
1646
+ crosshairInstances.push(toolGroup.getToolInstance('Crosshairs'));
1647
+ }
1648
+ };
1649
+
1650
+ if (!viewportId) {
1651
+ const toolGroupIds = toolGroupService.getToolGroupIds();
1652
+ toolGroupIds.forEach(getCrosshairInstances);
1653
+ } else {
1654
+ const toolGroup = toolGroupService.getToolGroupForViewport(viewportId);
1655
+ if (toolGroup) {
1656
+ getCrosshairInstances(toolGroup.id);
1657
+ }
1658
+ }
1659
+
1660
+ crosshairInstances.forEach(ins => {
1661
+ ins?.computeToolCenter();
1662
+ });
1663
+ },
1664
+ /**
1665
+ * Creates a labelmap for the active viewport
1666
+ *
1667
+ * The created labelmap will be registered as a display set and also added
1668
+ * as a segmentation representation to the viewport.
1669
+ */
1670
+ createLabelmapForViewport: async ({ viewportId, options = {} }) => {
1671
+ return createSegmentationForViewport(servicesManager, {
1672
+ viewportId,
1673
+ options,
1674
+ segmentationType: SegmentationRepresentations.Labelmap,
1675
+ });
1676
+ },
1677
+ /**
1678
+ * Creates a contour for the active viewport
1679
+ *
1680
+ * The created contour will be registered as a display set and also added
1681
+ * as a segmentation representation to the viewport.
1682
+ */
1683
+ createContourForViewport: async ({ viewportId, options = {} }) => {
1684
+ return createSegmentationForViewport(servicesManager, {
1685
+ viewportId,
1686
+ options,
1687
+ segmentationType: SegmentationRepresentations.Contour,
1688
+ });
1689
+ },
1690
+
1691
+ /**
1692
+ * Sets the active segmentation for a viewport
1693
+ * @param props.segmentationId - The ID of the segmentation to set as active
1694
+ */
1695
+ setActiveSegmentation: ({ segmentationId }) => {
1696
+ const { viewportGridService, segmentationService } = servicesManager.services;
1697
+ segmentationService.setActiveSegmentation(
1698
+ viewportGridService.getActiveViewportId(),
1699
+ segmentationId
1700
+ );
1701
+ },
1702
+
1703
+ /**
1704
+ * Adds a new segment to a segmentation
1705
+ * @param props.segmentationId - The ID of the segmentation to add the segment to
1706
+ */
1707
+ addSegmentCommand: ({ segmentationId, config }) => {
1708
+ const { segmentationService } = servicesManager.services;
1709
+ segmentationService.addSegment(segmentationId, config);
1710
+ },
1711
+
1712
+ /**
1713
+ * Sets the active segment and jumps to its center
1714
+ * @param props.segmentationId - The ID of the segmentation
1715
+ * @param props.segmentIndex - The index of the segment to activate
1716
+ */
1717
+ setActiveSegmentAndCenterCommand: ({ segmentationId, segmentIndex }) => {
1718
+ const { segmentationService, viewportGridService } = servicesManager.services;
1719
+ // set both active segmentation and active segment
1720
+ segmentationService.setActiveSegmentation(
1721
+ viewportGridService.getActiveViewportId(),
1722
+ segmentationId
1723
+ );
1724
+ segmentationService.setActiveSegment(segmentationId, segmentIndex);
1725
+
1726
+ const { highlightAlpha, highlightSegment, animationLength, animationFunctionType } =
1727
+ (customizationService.getCustomization(
1728
+ 'panelSegmentation.jumpToSegmentHighlightAnimationConfig'
1729
+ ) as Object as {
1730
+ highlightAlpha?: number;
1731
+ highlightSegment?: boolean;
1732
+ animationLength?: number;
1733
+ animationFunctionType?: EasingFunctionEnum;
1734
+ }) ?? {};
1735
+
1736
+ const validAnimationFunctionType = Object.values(EasingFunctionEnum).includes(
1737
+ animationFunctionType
1738
+ )
1739
+ ? animationFunctionType
1740
+ : undefined;
1741
+
1742
+ segmentationService.jumpToSegmentNext(
1743
+ segmentationId,
1744
+ segmentIndex,
1745
+ undefined,
1746
+ highlightAlpha,
1747
+ highlightSegment,
1748
+ animationLength,
1749
+ undefined,
1750
+ validAnimationFunctionType
1751
+ );
1752
+ },
1753
+
1754
+ /**
1755
+ * Toggles the visibility of a segment
1756
+ * @param props.segmentationId - The ID of the segmentation
1757
+ * @param props.segmentIndex - The index of the segment
1758
+ * @param props.type - The type of visibility to toggle
1759
+ */
1760
+ toggleSegmentVisibilityCommand: ({ segmentationId, segmentIndex, type }) => {
1761
+ const { segmentationService, viewportGridService } = servicesManager.services;
1762
+ segmentationService.toggleSegmentVisibility(
1763
+ viewportGridService.getActiveViewportId(),
1764
+ segmentationId,
1765
+ segmentIndex,
1766
+ type
1767
+ );
1768
+ },
1769
+
1770
+ /**
1771
+ * Toggles the lock state of a segment
1772
+ * @param props.segmentationId - The ID of the segmentation
1773
+ * @param props.segmentIndex - The index of the segment
1774
+ */
1775
+ toggleSegmentLockCommand: ({ segmentationId, segmentIndex }) => {
1776
+ const { segmentationService } = servicesManager.services;
1777
+ segmentationService.toggleSegmentLocked(segmentationId, segmentIndex);
1778
+ },
1779
+
1780
+ /**
1781
+ * Toggles the visibility of a segmentation representation
1782
+ * @param props.segmentationId - The ID of the segmentation
1783
+ * @param props.type - The type of representation
1784
+ */
1785
+ toggleSegmentationVisibilityCommand: ({ segmentationId, type }) => {
1786
+ const { segmentationService, viewportGridService } = servicesManager.services;
1787
+ segmentationService.toggleSegmentationRepresentationVisibility(
1788
+ viewportGridService.getActiveViewportId(),
1789
+ { segmentationId, type }
1790
+ );
1791
+ },
1792
+
1793
+ /**
1794
+ * Downloads a segmentation
1795
+ * @param props.segmentationId - The ID of the segmentation to download
1796
+ */
1797
+ downloadSegmentationCommand: ({ segmentationId }) => {
1798
+ const { segmentationService } = servicesManager.services;
1799
+ segmentationService.downloadSegmentation(segmentationId);
1800
+ },
1801
+
1802
+ /**
1803
+ * Stores a segmentation and shows it in the viewport
1804
+ * @param props.segmentationId - The ID of the segmentation to store
1805
+ */
1806
+ storeSegmentationCommand: async args => {
1807
+ const { segmentationId } = args;
1808
+ const { segmentationService, viewportGridService } = servicesManager.services;
1809
+
1810
+ const displaySetInstanceUIDs = await createReportAsync({
1811
+ servicesManager,
1812
+ getReport: () => commandsManager.runCommand('storeSegmentation', args),
1813
+ reportType: 'Segmentation',
1814
+ });
1815
+
1816
+ if (displaySetInstanceUIDs) {
1817
+ segmentationService.remove(segmentationId);
1818
+ viewportGridService.setDisplaySetsForViewport({
1819
+ viewportId: viewportGridService.getActiveViewportId(),
1820
+ displaySetInstanceUIDs,
1821
+ });
1822
+ }
1823
+ },
1824
+
1825
+ /**
1826
+ * Downloads a segmentation as RTSS
1827
+ * @param props.segmentationId - The ID of the segmentation
1828
+ */
1829
+ downloadRTSSCommand: ({ segmentationId }) => {
1830
+ const { segmentationService } = servicesManager.services;
1831
+ segmentationService.downloadRTSS(segmentationId);
1832
+ },
1833
+
1834
+ /**
1835
+ * Sets the style for a segmentation
1836
+ * @param props.segmentationId - The ID of the segmentation
1837
+ * @param props.type - The type of style
1838
+ * @param props.key - The style key to set
1839
+ * @param props.value - The style value
1840
+ */
1841
+ setSegmentationStyleCommand: ({ type, key, value }) => {
1842
+ const { segmentationService } = servicesManager.services;
1843
+ segmentationService.setStyle({ type }, { [key]: value });
1844
+ },
1845
+
1846
+ /**
1847
+ * Deletes a segment from a segmentation
1848
+ * @param props.segmentationId - The ID of the segmentation
1849
+ * @param props.segmentIndex - The index of the segment to delete
1850
+ */
1851
+ deleteSegmentCommand: ({ segmentationId, segmentIndex }) => {
1852
+ const { segmentationService } = servicesManager.services;
1853
+ segmentationService.removeSegment(segmentationId, segmentIndex);
1854
+ },
1855
+
1856
+ /**
1857
+ * Deletes an entire segmentation
1858
+ * @param props.segmentationId - The ID of the segmentation to delete
1859
+ */
1860
+ deleteSegmentationCommand: ({ segmentationId }) => {
1861
+ const { segmentationService } = servicesManager.services;
1862
+ segmentationService.remove(segmentationId);
1863
+ },
1864
+
1865
+ /**
1866
+ * Removes a segmentation from the viewport.
1867
+ *
1868
+ * This is the segmentation panel's Remove from Viewport, which lists the
1869
+ * segmentations of the study rather than the layers of one pane, so it is
1870
+ * the global statement: it un-hydrates the display set as well as clearing
1871
+ * it from the active viewport. The per-viewport equivalent is the viewport
1872
+ * data overlay menu's Remove, which runs `removeDisplaySetLayer` without
1873
+ * `unhydrate`.
1874
+ *
1875
+ * @param props.segmentationId - The ID of the segmentation to remove
1876
+ */
1877
+ removeSegmentationFromViewportCommand: ({ segmentationId: displaySetInstanceUID }) => {
1878
+ const { viewportGridService } = servicesManager.services;
1879
+ const viewportId = viewportGridService.getActiveViewportId();
1880
+
1881
+ commandsManager.runCommand('removeDisplaySetLayer', {
1882
+ viewportId,
1883
+ displaySetInstanceUID,
1884
+ unhydrate: true,
1885
+ });
1886
+ },
1887
+
1888
+ /**
1889
+ * Toggles rendering of inactive segmentations
1890
+ */
1891
+ toggleRenderInactiveSegmentationsCommand: () => {
1892
+ const { segmentationService, viewportGridService } = servicesManager.services;
1893
+ const viewportId = viewportGridService.getActiveViewportId();
1894
+ const renderInactive = segmentationService.getRenderInactiveSegmentations(viewportId);
1895
+ segmentationService.setRenderInactiveSegmentations(viewportId, !renderInactive);
1896
+ },
1897
+
1898
+ editSegmentLabel: async ({ segmentationId, segmentIndex }) => {
1899
+ const { segmentationService, uiDialogService } = servicesManager.services;
1900
+ const segmentation = segmentationService.getSegmentation(segmentationId);
1901
+
1902
+ if (!segmentation) {
1903
+ return;
1904
+ }
1905
+
1906
+ const segment = segmentation.segments[segmentIndex];
1907
+
1908
+ callInputDialog({
1909
+ uiDialogService,
1910
+ title: i18n.t('Tools:Edit Segment Label'),
1911
+ placeholder: i18n.t('Tools:Enter new label'),
1912
+ defaultValue: segment.label,
1913
+ }).then(label => {
1914
+ segmentationService.setSegmentLabel(segmentationId, segmentIndex, label);
1915
+ });
1916
+ },
1917
+
1918
+ editSegmentationLabel: ({ segmentationId }) => {
1919
+ const { segmentationService, uiDialogService } = servicesManager.services;
1920
+ const segmentation = segmentationService.getSegmentation(segmentationId);
1921
+
1922
+ if (!segmentation) {
1923
+ return;
1924
+ }
1925
+
1926
+ const { label } = segmentation;
1927
+
1928
+ callInputDialog({
1929
+ uiDialogService,
1930
+ title: i18n.t('Tools:Edit Segmentation Label'),
1931
+ placeholder: i18n.t('Tools:Enter new label'),
1932
+ defaultValue: label,
1933
+ }).then(label => {
1934
+ // The update clears `labelIsGenerated` - the user chose this label.
1935
+ segmentationService.addOrUpdateSegmentation({ segmentationId, label });
1936
+ });
1937
+ },
1938
+
1939
+ editSegmentColor: ({ segmentationId, segmentIndex }) => {
1940
+ const { segmentationService, uiDialogService, viewportGridService } =
1941
+ servicesManager.services;
1942
+ const viewportId = viewportGridService.getActiveViewportId();
1943
+ const color = segmentationService.getSegmentColor(viewportId, segmentationId, segmentIndex);
1944
+
1945
+ const rgbaColor = {
1946
+ r: color[0],
1947
+ g: color[1],
1948
+ b: color[2],
1949
+ a: color[3] / 255.0,
1950
+ };
1951
+
1952
+ uiDialogService.show({
1953
+ content: colorPickerDialog,
1954
+ title: i18n.t('Tools:Segment Color'),
1955
+ contentProps: {
1956
+ value: rgbaColor,
1957
+ onSave: newRgbaColor => {
1958
+ const color = [newRgbaColor.r, newRgbaColor.g, newRgbaColor.b, newRgbaColor.a * 255.0];
1959
+ segmentationService.setSegmentColor(viewportId, segmentationId, segmentIndex, color);
1960
+ },
1961
+ },
1962
+ });
1963
+ },
1964
+
1965
+ getRenderInactiveSegmentations: () => {
1966
+ const { segmentationService, viewportGridService } = servicesManager.services;
1967
+ return segmentationService.getRenderInactiveSegmentations(
1968
+ viewportGridService.getActiveViewportId()
1969
+ );
1970
+ },
1971
+
1972
+ deleteActiveAnnotation: () => {
1973
+ const activeAnnotationsUID = cornerstoneTools.annotation.selection.getAnnotationsSelected();
1974
+ activeAnnotationsUID.forEach(activeAnnotationUID => {
1975
+ measurementService.remove(activeAnnotationUID);
1976
+ });
1977
+ },
1978
+ setDisplaySetsForViewports: ({ viewportsToUpdate }) => {
1979
+ const { cineService, viewportGridService } = servicesManager.services;
1980
+ // Stopping the cine of modified viewports before changing the viewports to
1981
+ // avoid inconsistent state and lost references
1982
+ viewportsToUpdate.forEach(viewport => {
1983
+ const state = cineService.getState();
1984
+ const currentCineState = state.cines?.[viewport.viewportId];
1985
+ cineService.setCine({
1986
+ id: viewport.viewportId,
1987
+ frameRate: currentCineState?.frameRate ?? state.default?.frameRate ?? 24,
1988
+ isPlaying: false,
1989
+ });
1990
+ });
1991
+
1992
+ viewportGridService.setDisplaySetsForViewports(viewportsToUpdate);
1993
+ },
1994
+ undo: () => {
1995
+ DefaultHistoryMemo.undo();
1996
+ },
1997
+ redo: () => {
1998
+ DefaultHistoryMemo.redo();
1999
+ },
2000
+ toggleSegmentPreviewEdit: ({ toggle }) => {
2001
+ let labelmapTools = getLabelmapTools({ toolGroupService });
2002
+ labelmapTools = labelmapTools.filter(tool => !tool.toolName.includes('Eraser'));
2003
+ labelmapTools.forEach(tool => {
2004
+ tool.configuration = {
2005
+ ...tool.configuration,
2006
+ preview: {
2007
+ ...tool.configuration.preview,
2008
+ enabled: toggle,
2009
+ },
2010
+ };
2011
+ });
2012
+ },
2013
+ toggleSegmentSelect: ({ toggle }) => {
2014
+ const toolGroupIds = toolGroupService.getToolGroupIds();
2015
+ toolGroupIds.forEach(toolGroupId => {
2016
+ const toolGroup = cornerstoneTools.ToolGroupManager.getToolGroup(toolGroupId);
2017
+ if (toggle) {
2018
+ toolGroup.setToolActive(cornerstoneTools.SegmentSelectTool.toolName);
2019
+ } else {
2020
+ toolGroup.setToolDisabled(cornerstoneTools.SegmentSelectTool.toolName);
2021
+ }
2022
+ });
2023
+ },
2024
+ toggleSegmentLabel: ({ enabled }: { enabled?: boolean }) => {
2025
+ const toolName = cornerstoneTools.SegmentLabelTool.toolName;
2026
+ const toolGroupIds = toolGroupService.getToolGroupIds();
2027
+
2028
+ const isToolOn = toolGroupIds.some(toolGroupId => {
2029
+ const toolGroup = cornerstoneTools.ToolGroupManager.getToolGroup(toolGroupId);
2030
+ const mode = toolGroup.getToolInstance(toolName)?.mode;
2031
+ return mode === 'Active';
2032
+ });
2033
+
2034
+ const enableTool = enabled !== undefined ? enabled : !isToolOn;
2035
+
2036
+ toolGroupIds.forEach(toolGroupId => {
2037
+ const toolGroup = cornerstoneTools.ToolGroupManager.getToolGroup(toolGroupId);
2038
+ if (enableTool) {
2039
+ toolGroup.setToolActive(toolName);
2040
+ } else {
2041
+ toolGroup.setToolDisabled(toolName);
2042
+ }
2043
+ });
2044
+ },
2045
+ /**
2046
+ * Used to sync the apps initial state with the config file settings.
2047
+ *
2048
+ * Will mutate the tools object of the given tool group and add the segmentLabelTool to the proper place.
2049
+ *
2050
+ * Use it before initializing the toolGroup with the tools.
2051
+ */
2052
+ initializeSegmentLabelTool: ({ tools }) => {
2053
+ const { customizationService } = servicesManager.services;
2054
+ const segmentLabelConfig = customizationService.getCustomization(
2055
+ 'segmentation.segmentLabel'
2056
+ ) as {
2057
+ enabledByDefault?: boolean;
2058
+ labelColor?: number[];
2059
+ hoverTimeout?: number;
2060
+ background?: string;
2061
+ };
2062
+
2063
+ if (segmentLabelConfig?.enabledByDefault) {
2064
+ const activeTools = tools?.active ?? [];
2065
+ activeTools.push({
2066
+ toolName: toolNames.SegmentLabel,
2067
+ configuration: {
2068
+ hoverTimeout: segmentLabelConfig?.hoverTimeout ?? 1,
2069
+ color: segmentLabelConfig?.labelColor,
2070
+ background: segmentLabelConfig?.background,
2071
+ },
2072
+ });
2073
+
2074
+ tools.active = activeTools;
2075
+ return tools;
2076
+ }
2077
+
2078
+ const disabledTools = tools?.disabled ?? [];
2079
+ disabledTools.push({
2080
+ toolName: toolNames.SegmentLabel,
2081
+ configuration: {
2082
+ hoverTimeout: segmentLabelConfig?.hoverTimeout ?? 1,
2083
+ color: segmentLabelConfig?.labelColor,
2084
+ },
2085
+ });
2086
+ tools.disabled = disabledTools;
2087
+ return tools;
2088
+ },
2089
+ toggleUseCenterSegmentIndex: ({ toggle }) => {
2090
+ let labelmapTools = getLabelmapTools({ toolGroupService });
2091
+ labelmapTools = labelmapTools.filter(tool => !tool.toolName.includes('Eraser'));
2092
+ labelmapTools.forEach(tool => {
2093
+ tool.configuration = {
2094
+ ...tool.configuration,
2095
+ useCenterSegmentIndex: toggle,
2096
+ };
2097
+ });
2098
+ },
2099
+ _handlePreviewAction: action => {
2100
+ // May be undefined when no viewport is enabled (e.g. Escape pressed while
2101
+ // a modal such as Preferences is open).
2102
+ const enabledElement = _getActiveViewportEnabledElement();
2103
+ const previewTools = getPreviewTools({ toolGroupService });
2104
+
2105
+ previewTools.forEach(tool => {
2106
+ try {
2107
+ tool[`${action}Preview`]();
2108
+ } catch (error) {
2109
+ console.debug('Error accepting preview for tool', tool.toolName);
2110
+ }
2111
+ });
2112
+
2113
+ if (segmentAI.enabled) {
2114
+ segmentAI[`${action}Preview`](enabledElement?.viewport?.element);
2115
+ }
2116
+ },
2117
+ acceptPreview: () => {
2118
+ actions._handlePreviewAction('accept');
2119
+ },
2120
+ rejectPreview: () => {
2121
+ actions._handlePreviewAction('reject');
2122
+ },
2123
+ /**
2124
+ * Generic Escape handler. A single Escape press should discard whatever the
2125
+ * user has in progress, but that can be one of two unrelated things: a
2126
+ * provisional segmentation preview, or an annotation being drawn. Rather
2127
+ * than bind both `rejectPreview` and `cancelMeasurement` to `esc` (Mousetrap
2128
+ * keeps only one handler per key, so the second silently shadows the first),
2129
+ * this command orchestrates both single-purpose commands. Each is a no-op
2130
+ * when its state is not active, so running both is safe and order-independent.
2131
+ */
2132
+ cancelActiveOperation: () => {
2133
+ try {
2134
+ actions.rejectPreview();
2135
+ } catch (error) {
2136
+ console.debug('Error rejecting active preview', error);
2137
+ } finally {
2138
+ actions.cancelMeasurement();
2139
+ }
2140
+ },
2141
+ clearMarkersForMarkerLabelmap: () => {
2142
+ const { viewport } = _getActiveViewportEnabledElement();
2143
+ const toolGroup = cornerstoneTools.ToolGroupManager.getToolGroupForViewport(viewport.id);
2144
+ const toolInstance = toolGroup.getToolInstance('MarkerLabelmap');
2145
+
2146
+ if (!toolInstance) {
2147
+ return;
2148
+ }
2149
+
2150
+ toolInstance.clearMarkers(viewport);
2151
+ },
2152
+ interpolateScrollForMarkerLabelmap: () => {
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.interpolateScroll(viewport, 1);
2162
+ },
2163
+ toggleLabelmapAssist: async () => {
2164
+ const { viewport } = _getActiveViewportEnabledElement();
2165
+ const newState = !segmentAI.enabled;
2166
+ segmentAI.enabled = newState;
2167
+
2168
+ if (!segmentAIEnabled) {
2169
+ await segmentAI.initModel();
2170
+ segmentAIEnabled = true;
2171
+ }
2172
+
2173
+ // set the brush tool to active
2174
+ const toolGroupIds = toolGroupService.getToolGroupIds();
2175
+ if (newState) {
2176
+ actions.setToolActiveToolbar({
2177
+ toolName: 'CircularBrushForAutoSegmentAI',
2178
+ toolGroupIds: toolGroupIds,
2179
+ });
2180
+ } else {
2181
+ toolGroupIds.forEach(toolGroupId => {
2182
+ const toolGroup = cornerstoneTools.ToolGroupManager.getToolGroup(toolGroupId);
2183
+ toolGroup.setToolPassive('CircularBrushForAutoSegmentAI');
2184
+ });
2185
+ }
2186
+
2187
+ if (segmentAI.enabled) {
2188
+ segmentAI.initViewport(viewport);
2189
+ }
2190
+ },
2191
+ setBrushSize: ({ value }) => {
2192
+ const brushSize = Number(value);
2193
+
2194
+ toolGroupService.getToolGroupIds()?.forEach(toolGroupId => {
2195
+ segmentationUtils.setBrushSizeForToolGroup(toolGroupId, brushSize);
2196
+ });
2197
+ },
2198
+ setThresholdRange: ({
2199
+ value,
2200
+ toolNames = [
2201
+ 'ThresholdCircularBrush',
2202
+ 'ThresholdSphereBrush',
2203
+ 'ThresholdCircularBrushDynamic',
2204
+ 'ThresholdSphereBrushDynamic',
2205
+ ],
2206
+ }) => {
2207
+ const toolGroupIds = toolGroupService.getToolGroupIds();
2208
+ if (!toolGroupIds?.length) {
2209
+ return;
2210
+ }
2211
+
2212
+ for (const toolGroupId of toolGroupIds) {
2213
+ const toolGroup = toolGroupService.getToolGroup(toolGroupId);
2214
+ toolNames?.forEach(toolName => {
2215
+ toolGroup.setToolConfiguration(toolName, {
2216
+ threshold: {
2217
+ range: value,
2218
+ },
2219
+ });
2220
+ });
2221
+ }
2222
+ },
2223
+ increaseBrushSize: () => {
2224
+ _handleBrushSizeAction('increase');
2225
+ },
2226
+ decreaseBrushSize: () => {
2227
+ _handleBrushSizeAction('decrease');
2228
+ },
2229
+ addNewSegment: () => {
2230
+ const { segmentationService } = servicesManager.services;
2231
+ const { activeViewportId } = viewportGridService.getState();
2232
+ const activeSegmentation = segmentationService.getActiveSegmentation(activeViewportId);
2233
+ if (!activeSegmentation) {
2234
+ return;
2235
+ }
2236
+ segmentationService.addSegment(activeSegmentation.segmentationId);
2237
+ },
2238
+ loadSegmentationDisplaySetsForViewport: ({
2239
+ viewportId,
2240
+ displaySetInstanceUIDs,
2241
+ viewportType,
2242
+ // The SEG/RTSTRUCT being hydrated. Passing it lets the target selection
2243
+ // include panes that share its frame of reference rather than only those
2244
+ // hung with the exact referenced display set, and lets it work when there
2245
+ // is no viewport to match against at all.
2246
+ derivedDisplaySetInstanceUID,
2247
+ }) => {
2248
+ const updatedViewports = getUpdatedViewportsForSegmentation({
2249
+ viewportId,
2250
+ servicesManager,
2251
+ displaySetInstanceUIDs,
2252
+ derivedDisplaySetInstanceUID,
2253
+ });
2254
+
2255
+ if (!updatedViewports?.length) {
2256
+ return;
2257
+ }
2258
+
2259
+ updatedViewports.forEach(({ viewportId: csViewportId }) => {
2260
+ const csViewport = cornerstoneViewportService.getCornerstoneViewport(csViewportId);
2261
+ csViewport?.setNeedsRender?.();
2262
+ });
2263
+
2264
+ // A pinned viewportType (RTSTRUCT contour hydration on a native "next"
2265
+ // viewport requests 'stack') is a statement about the pane hydration was
2266
+ // invoked on, whose background is being set to the referenced image. The
2267
+ // other panes here were matched because they already show something the
2268
+ // segmentation can be drawn over - by frame of reference, and keeping the
2269
+ // display sets they already have - so their own render mode is the right
2270
+ // one and forcing 'stack' onto them would flip an MPR pane to a stack.
2271
+ // Note the merged entries carry no viewportOptions at all, so the grid
2272
+ // reducer would merge a bare `{ viewportType }` straight over the pane's
2273
+ // real options.
2274
+ const targetViewportId = viewportId || viewportGridService.getActiveViewportId();
2275
+
2276
+ actions.setDisplaySetsForViewports({
2277
+ viewportsToUpdate: updatedViewports.map(viewport => ({
2278
+ viewportId: viewport.viewportId,
2279
+ displaySetInstanceUIDs: viewport.displaySetInstanceUIDs,
2280
+ ...(viewportType && viewport.viewportId === targetViewportId
2281
+ ? { viewportOptions: { ...viewport.viewportOptions, viewportType } }
2282
+ : {}),
2283
+ })),
2284
+ });
2285
+ },
2286
+ setViewportOrientation: ({ viewportId, orientation }) => {
2287
+ const viewport = cornerstoneViewportService.getCornerstoneViewport(viewportId);
2288
+
2289
+ // Accept any viewport already rendering volume content (legacy ORTHOGRAPHIC
2290
+ // or a native viewport in volume mode) — both expose setOrientation().
2291
+ if (!viewport || !getViewportAdapter(viewport).canReorientInPlace()) {
2292
+ console.warn('Orientation can only be set on volume viewports');
2293
+ return;
2294
+ }
2295
+
2296
+ // Get display sets for this viewport to verify at least one is reconstructable
2297
+ const displaySetUIDs = viewportGridService.getDisplaySetsUIDsForViewport(viewportId);
2298
+ const displaySets = displaySetUIDs.map(uid => displaySetService.getDisplaySetByUID(uid));
2299
+
2300
+ if (!displaySets.some(ds => ds.isReconstructable)) {
2301
+ console.warn('Cannot change orientation: No reconstructable display sets in viewport');
2302
+ return;
2303
+ }
2304
+
2305
+ viewport.setOrientation(orientation);
2306
+ viewport.render();
2307
+
2308
+ // update the orientation in the viewport info
2309
+ const viewportInfo = cornerstoneViewportService.getViewportInfo(viewportId);
2310
+ viewportInfo.setOrientation(orientation);
2311
+ },
2312
+ /**
2313
+ * Toggles the horizontal flip state of the viewport.
2314
+ */
2315
+ toggleViewportHorizontalFlip: ({ viewportId }: { viewportId?: string } = {}) => {
2316
+ actions.flipViewportHorizontal({ viewportId, newValue: 'toggle' });
2317
+ },
2318
+
2319
+ /**
2320
+ * Explicitly sets the horizontal flip state of the viewport.
2321
+ */
2322
+ setViewportHorizontalFlip: ({
2323
+ flipped,
2324
+ viewportId,
2325
+ }: {
2326
+ flipped: boolean;
2327
+ viewportId?: string;
2328
+ }) => {
2329
+ actions.flipViewportHorizontal({ viewportId, newValue: flipped });
2330
+ },
2331
+
2332
+ /**
2333
+ * Toggles the vertical flip state of the viewport.
2334
+ */
2335
+ toggleViewportVerticalFlip: ({ viewportId }: { viewportId?: string } = {}) => {
2336
+ actions.flipViewportVertical({ viewportId, newValue: 'toggle' });
2337
+ },
2338
+
2339
+ /**
2340
+ * Explicitly sets the vertical flip state of the viewport.
2341
+ */
2342
+ setViewportVerticalFlip: ({
2343
+ flipped,
2344
+ viewportId,
2345
+ }: {
2346
+ flipped: boolean;
2347
+ viewportId?: string;
2348
+ }) => {
2349
+ actions.flipViewportVertical({ viewportId, newValue: flipped });
2350
+ },
2351
+ /**
2352
+ * Internal helper to rotate or set absolute rotation for a viewport.
2353
+ */
2354
+ _rotateViewport: ({
2355
+ rotation,
2356
+ viewportId,
2357
+ rotationMode = 'apply',
2358
+ }: {
2359
+ rotation: number;
2360
+ viewportId?: string;
2361
+ rotationMode?: 'apply' | 'set';
2362
+ }) => {
2363
+ const viewport = _resolveViewport(viewportId);
2364
+ if (!viewport) {
2365
+ return;
2366
+ }
2367
+ ops.rotate(viewport, rotation, rotationMode);
2368
+ viewport.render();
2369
+ },
2370
+ startRecordingForAnnotationGroup: () => {
2371
+ cornerstoneTools.AnnotationTool.startGroupRecording();
2372
+ },
2373
+ endRecordingForAnnotationGroup: () => {
2374
+ cornerstoneTools.AnnotationTool.endGroupRecording();
2375
+ },
2376
+ triggerCreateAnnotationMemo: ({
2377
+ annotation,
2378
+ FrameOfReferenceUID,
2379
+ options,
2380
+ }: {
2381
+ annotation: ToolTypes.Annotation;
2382
+ FrameOfReferenceUID: string;
2383
+ options: { newAnnotation?: boolean; deleting?: boolean };
2384
+ }): void => {
2385
+ const { newAnnotation, deleting } = options;
2386
+ const renderingEngines = getRenderingEngines();
2387
+ const viewports = renderingEngines.flatMap(re => re.getViewports());
2388
+ const validViewport = viewports.find(
2389
+ vp => vp.getFrameOfReferenceUID() === FrameOfReferenceUID
2390
+ );
2391
+
2392
+ if (!validViewport) {
2393
+ return;
2394
+ }
2395
+
2396
+ cornerstoneTools.AnnotationTool.createAnnotationMemo(validViewport.element, annotation, {
2397
+ newAnnotation,
2398
+ deleting,
2399
+ });
2400
+ },
2401
+ activateSelectedSegmentationOfType: ({ segmentationRepresentationType }) => {
2402
+ const { segmentationService, viewportGridService } = servicesManager.services;
2403
+ const activeViewportId = viewportGridService.getActiveViewportId();
2404
+ const { selectedSegmentationsForViewport } =
2405
+ useSelectedSegmentationsForViewportStore.getState();
2406
+ const segmentationId = selectedSegmentationsForViewport[activeViewportId]?.get(
2407
+ segmentationRepresentationType
2408
+ );
2409
+
2410
+ if (!segmentationId) {
2411
+ return;
2412
+ }
2413
+
2414
+ segmentationService.setActiveSegmentation(activeViewportId, segmentationId);
2415
+ },
2416
+ setDynamicCursorSizeForSculptorTool: ({ value: isDynamicCursorSize }) => {
2417
+ const viewportId = viewportGridService.getActiveViewportId();
2418
+ const toolGroup = toolGroupService.getToolGroupForViewport(viewportId);
2419
+ const sculptorToolInstance = toolGroup.getToolInstance(toolNames.SculptorTool);
2420
+ const oldConfiguration = sculptorToolInstance.configuration;
2421
+
2422
+ sculptorToolInstance.configuration = {
2423
+ ...oldConfiguration,
2424
+ updateCursorSize: isDynamicCursorSize ? 'dynamic' : '',
2425
+ };
2426
+ },
2427
+ setInterpolationToolConfiguration: ({ value: interpolateContours, toolNames }) => {
2428
+ const viewportId = viewportGridService.getActiveViewportId();
2429
+ const toolGroup = toolGroupService.getToolGroupForViewport(viewportId);
2430
+
2431
+ // Set the interpolation configuration for the active tool.
2432
+ const activeTool = toolGroupService.getActiveToolForViewport(viewportId);
2433
+ const interpolationConfig = {
2434
+ interpolation: {
2435
+ enabled: interpolateContours,
2436
+ },
2437
+ };
2438
+ toolGroup.setToolConfiguration(activeTool, interpolationConfig);
2439
+
2440
+ // Now set the interpolation configuration for the other tools specified.
2441
+ if (toolNames) {
2442
+ Object.values(toolGroup.getToolInstances()).forEach(toolInstance => {
2443
+ if (toolNames?.includes(toolInstance.toolName)) {
2444
+ toolGroup.setToolConfiguration(toolInstance.toolName, interpolationConfig);
2445
+ }
2446
+ });
2447
+ }
2448
+ },
2449
+ setSimplifiedSplineForSplineContourSegmentationTool: ({ value: simplifiedSpline }) => {
2450
+ const viewportId = viewportGridService.getActiveViewportId();
2451
+ const toolGroup = toolGroupService.getToolGroupForViewport(viewportId);
2452
+ Object.values(toolGroup.getToolInstances()).forEach(toolInstance => {
2453
+ if (toolInstance instanceof SplineContourSegmentationTool) {
2454
+ const oldConfiguration = toolInstance.configuration;
2455
+ toolInstance.configuration = {
2456
+ ...oldConfiguration,
2457
+ simplifiedSpline,
2458
+ };
2459
+ }
2460
+ });
2461
+ },
2462
+ removeSmallContours: ({ areaThreshold: threshold }) => {
2463
+ const viewportId = viewportGridService.getActiveViewportId();
2464
+ const activeSegmentation = segmentationService.getActiveSegmentation(viewportId);
2465
+ const activeSegment = segmentationService.getActiveSegment(viewportId);
2466
+
2467
+ if (!activeSegmentation || !activeSegment) {
2468
+ return;
2469
+ }
2470
+
2471
+ const { removeContourIslands } = segmentationUtilities;
2472
+ removeContourIslands(activeSegmentation.segmentationId, activeSegment.segmentIndex, {
2473
+ threshold,
2474
+ });
2475
+ const renderingEngine = cornerstoneViewportService.getRenderingEngine();
2476
+ renderingEngine.render();
2477
+ },
2478
+ applyLogicalContourOperation: ({
2479
+ segmentAInfo,
2480
+ segmentBInfo,
2481
+ resultSegmentInfo,
2482
+ logicalOperation,
2483
+ }: {
2484
+ segmentAInfo: SegmentInfo;
2485
+ segmentBInfo: SegmentInfo;
2486
+ resultSegmentInfo: OperatorOptions;
2487
+ logicalOperation: LogicalOperation;
2488
+ }) => {
2489
+ switch (logicalOperation) {
2490
+ case LogicalOperation.Union:
2491
+ add(segmentAInfo, segmentBInfo, resultSegmentInfo);
2492
+ break;
2493
+ case LogicalOperation.Intersect:
2494
+ intersect(segmentAInfo, segmentBInfo, resultSegmentInfo);
2495
+ break;
2496
+ case LogicalOperation.Subtract:
2497
+ subtract(segmentAInfo, segmentBInfo, resultSegmentInfo);
2498
+ break;
2499
+ default:
2500
+ throw new Error('Unsupported logical operation');
2501
+ }
2502
+ },
2503
+ copyContourSegment: ({
2504
+ sourceSegmentInfo,
2505
+ targetSegmentInfo,
2506
+ }: {
2507
+ sourceSegmentInfo: SegmentInfo;
2508
+ targetSegmentInfo?: SegmentInfo;
2509
+ }) => {
2510
+ if (!targetSegmentInfo) {
2511
+ const sourceSegmentation = segmentationService.getSegmentation(
2512
+ sourceSegmentInfo.segmentationId
2513
+ );
2514
+ const sourceCachedStats =
2515
+ sourceSegmentation?.segments?.[sourceSegmentInfo.segmentIndex]?.cachedStats;
2516
+
2517
+ targetSegmentInfo = {
2518
+ segmentationId: sourceSegmentInfo.segmentationId,
2519
+ segmentIndex: segmentationService.getNextAvailableSegmentIndex(
2520
+ sourceSegmentInfo.segmentationId
2521
+ ),
2522
+ };
2523
+
2524
+ // Copy source cachedStats so jump-to-segment navigation works on the duplicate segment.
2525
+ segmentationService.addSegment(targetSegmentInfo.segmentationId, {
2526
+ segmentIndex: targetSegmentInfo.segmentIndex,
2527
+ ...(sourceCachedStats && {
2528
+ cachedStats: csUtils.deepClone(sourceCachedStats) as Record<string, unknown>,
2529
+ }),
2530
+ });
2531
+ }
2532
+
2533
+ copy(sourceSegmentInfo, targetSegmentInfo);
2534
+ },
2535
+ smoothContours: () => {
2536
+ const viewportId = viewportGridService.getActiveViewportId();
2537
+ const activeSegmentation = segmentationService.getActiveSegmentation(viewportId);
2538
+ const activeSegment = segmentationService.getActiveSegment(viewportId);
2539
+
2540
+ if (!activeSegmentation || !activeSegment) {
2541
+ return;
2542
+ }
2543
+
2544
+ const { smoothContours } = segmentationUtilities;
2545
+ smoothContours(activeSegmentation.segmentationId, activeSegment.segmentIndex);
2546
+
2547
+ const renderingEngine = cornerstoneViewportService.getRenderingEngine();
2548
+ renderingEngine.render();
2549
+ },
2550
+ removeContourHoles: () => {
2551
+ const viewportId = viewportGridService.getActiveViewportId();
2552
+ const activeSegmentation = segmentationService.getActiveSegmentation(viewportId);
2553
+ const activeSegment = segmentationService.getActiveSegment(viewportId);
2554
+
2555
+ if (!activeSegmentation || !activeSegment) {
2556
+ return;
2557
+ }
2558
+
2559
+ const { removeContourHoles } = segmentationUtilities;
2560
+ removeContourHoles(activeSegmentation.segmentationId, activeSegment.segmentIndex);
2561
+
2562
+ const renderingEngine = cornerstoneViewportService.getRenderingEngine();
2563
+ renderingEngine.render();
2564
+ },
2565
+ decimateContours: () => {
2566
+ const viewportId = viewportGridService.getActiveViewportId();
2567
+ const activeSegmentation = segmentationService.getActiveSegmentation(viewportId);
2568
+ const activeSegment = segmentationService.getActiveSegment(viewportId);
2569
+
2570
+ if (!activeSegmentation || !activeSegment) {
2571
+ return;
2572
+ }
2573
+
2574
+ const { decimateContours } = segmentationUtilities;
2575
+ decimateContours(activeSegmentation.segmentationId, activeSegment.segmentIndex);
2576
+
2577
+ const renderingEngine = cornerstoneViewportService.getRenderingEngine();
2578
+ renderingEngine.render();
2579
+ },
2580
+ convertContourHoles: () => {
2581
+ const viewportId = viewportGridService.getActiveViewportId();
2582
+ const activeSegmentation = segmentationService.getActiveSegmentation(viewportId);
2583
+ const activeSegment = segmentationService.getActiveSegment(viewportId);
2584
+
2585
+ if (!activeSegmentation || !activeSegment) {
2586
+ return;
2587
+ }
2588
+
2589
+ const targetSegmentInfo = {
2590
+ segmentationId: activeSegmentation.segmentationId,
2591
+ segmentIndex: segmentationService.getNextAvailableSegmentIndex(
2592
+ activeSegmentation.segmentationId
2593
+ ),
2594
+ };
2595
+
2596
+ segmentationService.addSegment(targetSegmentInfo.segmentationId, {
2597
+ segmentIndex: targetSegmentInfo.segmentIndex,
2598
+ });
2599
+
2600
+ const { convertContourHoles } = segmentationUtilities;
2601
+ convertContourHoles(
2602
+ activeSegmentation.segmentationId,
2603
+ activeSegment.segmentIndex,
2604
+ targetSegmentInfo.segmentationId,
2605
+ targetSegmentInfo.segmentIndex
2606
+ );
2607
+
2608
+ const renderingEngine = cornerstoneViewportService.getRenderingEngine();
2609
+ renderingEngine.render();
2610
+ },
2611
+ };
2612
+
2613
+ const definitions = {
2614
+ // The command here is to show the viewer context menu, as being the
2615
+ // context menu
2616
+ showCornerstoneContextMenu: {
2617
+ commandFn: actions.showCornerstoneContextMenu,
2618
+ options: {
2619
+ menuCustomizationId: 'measurementsContextMenu',
2620
+ commands: [
2621
+ {
2622
+ commandName: 'showContextMenu',
2623
+ },
2624
+ ],
2625
+ },
2626
+ },
2627
+
2628
+ getNearbyToolData: {
2629
+ commandFn: actions.getNearbyToolData,
2630
+ },
2631
+ getNearbyAnnotation: {
2632
+ commandFn: actions.getNearbyAnnotation,
2633
+ storeContexts: [],
2634
+ options: {},
2635
+ },
2636
+ toggleViewportColorbar: {
2637
+ commandFn: actions.toggleViewportColorbar,
2638
+ },
2639
+ setMeasurementLabel: {
2640
+ commandFn: actions.setMeasurementLabel,
2641
+ },
2642
+ renameMeasurement: {
2643
+ commandFn: actions.renameMeasurement,
2644
+ },
2645
+ updateMeasurement: {
2646
+ commandFn: actions.updateMeasurement,
2647
+ },
2648
+ changeMeasurementColor: {
2649
+ commandFn: actions.changeMeasurementColor,
2650
+ },
2651
+ jumpToMeasurement: actions.jumpToMeasurement,
2652
+ recordMeasurementsPredecessor: {
2653
+ commandFn: actions.recordMeasurementsPredecessor,
2654
+ },
2655
+ removeMeasurement: {
2656
+ commandFn: actions.removeMeasurement,
2657
+ },
2658
+ cancelMeasurement: {
2659
+ commandFn: actions.cancelMeasurement,
2660
+ },
2661
+ toggleLockMeasurement: {
2662
+ commandFn: actions.toggleLockMeasurement,
2663
+ },
2664
+ toggleVisibilityMeasurement: {
2665
+ commandFn: actions.toggleVisibilityMeasurement,
2666
+ },
2667
+ downloadCSVMeasurementsReport: {
2668
+ commandFn: actions.downloadCSVMeasurementsReport,
2669
+ },
2670
+ setViewportWindowLevel: {
2671
+ commandFn: actions.setViewportWindowLevel,
2672
+ },
2673
+ setWindowLevel: {
2674
+ commandFn: actions.setWindowLevel,
2675
+ },
2676
+ setWindowLevelPreset: {
2677
+ commandFn: actions.setWindowLevelPreset,
2678
+ },
2679
+ setToolActive: {
2680
+ commandFn: actions.setToolActive,
2681
+ },
2682
+ setToolActiveToolbar: {
2683
+ commandFn: actions.setToolActiveToolbar,
2684
+ },
2685
+ setToolEnabled: {
2686
+ commandFn: actions.setToolEnabled,
2687
+ },
2688
+ rotateViewportCW: {
2689
+ commandFn: actions.rotateViewportBy,
2690
+ options: { rotation: 90 },
2691
+ },
2692
+ rotateViewportCCW: {
2693
+ commandFn: actions.rotateViewportBy,
2694
+ options: { rotation: -90 },
2695
+ },
2696
+ rotateViewportCWSet: {
2697
+ commandFn: actions.setViewportRotation,
2698
+ options: { rotation: 90 },
2699
+ },
2700
+ incrementActiveViewport: {
2701
+ commandFn: actions.changeActiveViewport,
2702
+ },
2703
+ decrementActiveViewport: {
2704
+ commandFn: actions.changeActiveViewport,
2705
+ options: { direction: -1 },
2706
+ },
2707
+ flipViewportHorizontal: {
2708
+ commandFn: actions.toggleViewportHorizontalFlip,
2709
+ },
2710
+ flipViewportVertical: {
2711
+ commandFn: actions.toggleViewportVerticalFlip,
2712
+ },
2713
+ setViewportHorizontalFlip: {
2714
+ commandFn: actions.setViewportHorizontalFlip,
2715
+ options: { flipped: true },
2716
+ },
2717
+ setViewportVerticalFlip: {
2718
+ commandFn: actions.setViewportVerticalFlip,
2719
+ options: { flipped: true },
2720
+ },
2721
+ invertViewport: {
2722
+ commandFn: actions.invertViewport,
2723
+ },
2724
+ resetViewport: {
2725
+ commandFn: actions.resetViewport,
2726
+ },
2727
+ scaleUpViewport: {
2728
+ commandFn: actions.scaleViewport,
2729
+ options: { direction: 1 },
2730
+ },
2731
+ scaleDownViewport: {
2732
+ commandFn: actions.scaleViewport,
2733
+ options: { direction: -1 },
2734
+ },
2735
+ fitViewportToWindow: {
2736
+ commandFn: actions.scaleViewport,
2737
+ options: { direction: 0 },
2738
+ },
2739
+ nextImage: {
2740
+ commandFn: actions.scroll,
2741
+ options: { direction: 1 },
2742
+ },
2743
+ previousImage: {
2744
+ commandFn: actions.scroll,
2745
+ options: { direction: -1 },
2746
+ },
2747
+ firstImage: {
2748
+ commandFn: actions.jumpToImage,
2749
+ options: { imageIndex: 0 },
2750
+ },
2751
+ lastImage: {
2752
+ commandFn: actions.jumpToImage,
2753
+ options: { imageIndex: -1 },
2754
+ },
2755
+ jumpToImage: {
2756
+ commandFn: actions.jumpToImage,
2757
+ },
2758
+ showDownloadViewportModal: {
2759
+ commandFn: actions.showDownloadViewportModal,
2760
+ },
2761
+ toggleCine: {
2762
+ commandFn: actions.toggleCine,
2763
+ },
2764
+ arrowTextCallback: {
2765
+ commandFn: actions.arrowTextCallback,
2766
+ },
2767
+ setViewportActive: {
2768
+ commandFn: actions.setViewportActive,
2769
+ },
2770
+ setViewportColormap: {
2771
+ commandFn: actions.setViewportColormap,
2772
+ },
2773
+ setViewportForToolConfiguration: {
2774
+ commandFn: actions.setViewportForToolConfiguration,
2775
+ },
2776
+ storePresentation: {
2777
+ commandFn: actions.storePresentation,
2778
+ },
2779
+ attachProtocolViewportDataListener: {
2780
+ commandFn: actions.attachProtocolViewportDataListener,
2781
+ },
2782
+ setViewportPreset: {
2783
+ commandFn: actions.setViewportPreset,
2784
+ },
2785
+ setVolumeRenderingQulaity: {
2786
+ commandFn: actions.setVolumeRenderingQulaity,
2787
+ },
2788
+ shiftVolumeOpacityPoints: {
2789
+ commandFn: actions.shiftVolumeOpacityPoints,
2790
+ },
2791
+ setVolumeLighting: {
2792
+ commandFn: actions.setVolumeLighting,
2793
+ },
2794
+ resetCrosshairs: {
2795
+ commandFn: actions.resetCrosshairs,
2796
+ },
2797
+ toggleSynchronizer: {
2798
+ commandFn: actions.toggleSynchronizer,
2799
+ },
2800
+ updateVolumeData: {
2801
+ commandFn: actions.updateVolumeData,
2802
+ },
2803
+ toggleEnabledDisabledToolbar: {
2804
+ commandFn: actions.toggleEnabledDisabledToolbar,
2805
+ },
2806
+ toggleActiveDisabledToolbar: {
2807
+ commandFn: actions.toggleActiveDisabledToolbar,
2808
+ },
2809
+ updateStoredPositionPresentation: {
2810
+ commandFn: actions.updateStoredPositionPresentation,
2811
+ },
2812
+ updateStoredSegmentationPresentation: {
2813
+ commandFn: actions.updateStoredSegmentationPresentation,
2814
+ },
2815
+ createLabelmapForViewport: {
2816
+ commandFn: actions.createLabelmapForViewport,
2817
+ },
2818
+ createContourForViewport: {
2819
+ commandFn: actions.createContourForViewport,
2820
+ },
2821
+ setActiveSegmentation: {
2822
+ commandFn: actions.setActiveSegmentation,
2823
+ },
2824
+ addSegment: {
2825
+ commandFn: actions.addSegmentCommand,
2826
+ },
2827
+ setActiveSegmentAndCenter: {
2828
+ commandFn: actions.setActiveSegmentAndCenterCommand,
2829
+ },
2830
+ toggleSegmentVisibility: {
2831
+ commandFn: actions.toggleSegmentVisibilityCommand,
2832
+ },
2833
+ toggleSegmentLock: {
2834
+ commandFn: actions.toggleSegmentLockCommand,
2835
+ },
2836
+ toggleSegmentationVisibility: {
2837
+ commandFn: actions.toggleSegmentationVisibilityCommand,
2838
+ },
2839
+ downloadSegmentation: {
2840
+ commandFn: actions.downloadSegmentationCommand,
2841
+ },
2842
+ storeSegmentation: {
2843
+ commandFn: actions.storeSegmentationCommand,
2844
+ },
2845
+ downloadRTSS: {
2846
+ commandFn: actions.downloadRTSSCommand,
2847
+ },
2848
+ setSegmentationStyle: {
2849
+ commandFn: actions.setSegmentationStyleCommand,
2850
+ },
2851
+ deleteSegment: {
2852
+ commandFn: actions.deleteSegmentCommand,
2853
+ },
2854
+ deleteSegmentation: {
2855
+ commandFn: actions.deleteSegmentationCommand,
2856
+ },
2857
+ removeSegmentationFromViewport: {
2858
+ commandFn: actions.removeSegmentationFromViewportCommand,
2859
+ },
2860
+ toggleRenderInactiveSegmentations: {
2861
+ commandFn: actions.toggleRenderInactiveSegmentationsCommand,
2862
+ },
2863
+ setFillAlpha: {
2864
+ commandFn: createSetStyleCommand('fillAlpha'),
2865
+ },
2866
+ setOutlineWidth: {
2867
+ commandFn: createSetStyleCommand('outlineWidth'),
2868
+ },
2869
+ setRenderFill: {
2870
+ commandFn: createSetStyleCommand('renderFill'),
2871
+ },
2872
+ setRenderFillInactive: {
2873
+ commandFn: createSetStyleCommand('renderFillInactive'),
2874
+ },
2875
+ setRenderOutline: {
2876
+ commandFn: createSetStyleCommand('renderOutline'),
2877
+ },
2878
+ setRenderOutlineInactive: {
2879
+ commandFn: createSetStyleCommand('renderOutlineInactive'),
2880
+ },
2881
+ setFillAlphaInactive: {
2882
+ commandFn: createSetStyleCommand('fillAlphaInactive'),
2883
+ },
2884
+ editSegmentLabel: {
2885
+ commandFn: actions.editSegmentLabel,
2886
+ },
2887
+ editSegmentationLabel: {
2888
+ commandFn: actions.editSegmentationLabel,
2889
+ },
2890
+ editSegmentColor: {
2891
+ commandFn: actions.editSegmentColor,
2892
+ },
2893
+ getRenderInactiveSegmentations: {
2894
+ commandFn: actions.getRenderInactiveSegmentations,
2895
+ },
2896
+ deleteActiveAnnotation: {
2897
+ commandFn: actions.deleteActiveAnnotation,
2898
+ },
2899
+ setDisplaySetsForViewports: actions.setDisplaySetsForViewports,
2900
+ undo: actions.undo,
2901
+ redo: actions.redo,
2902
+ interpolateLabelmap: actions.interpolateLabelmap,
2903
+ runSegmentBidirectional: actions.runSegmentBidirectional,
2904
+ downloadCSVSegmentationReport: actions.downloadCSVSegmentationReport,
2905
+ toggleSegmentPreviewEdit: actions.toggleSegmentPreviewEdit,
2906
+ toggleSegmentSelect: actions.toggleSegmentSelect,
2907
+ acceptPreview: actions.acceptPreview,
2908
+ rejectPreview: actions.rejectPreview,
2909
+ cancelActiveOperation: actions.cancelActiveOperation,
2910
+ toggleUseCenterSegmentIndex: actions.toggleUseCenterSegmentIndex,
2911
+ toggleLabelmapAssist: actions.toggleLabelmapAssist,
2912
+ interpolateScrollForMarkerLabelmap: actions.interpolateScrollForMarkerLabelmap,
2913
+ clearMarkersForMarkerLabelmap: actions.clearMarkersForMarkerLabelmap,
2914
+ setBrushSize: actions.setBrushSize,
2915
+ setThresholdRange: actions.setThresholdRange,
2916
+ increaseBrushSize: actions.increaseBrushSize,
2917
+ decreaseBrushSize: actions.decreaseBrushSize,
2918
+ addNewSegment: actions.addNewSegment,
2919
+ loadSegmentationDisplaySetsForViewport: actions.loadSegmentationDisplaySetsForViewport,
2920
+ setViewportOrientation: actions.setViewportOrientation,
2921
+ hydrateSecondaryDisplaySet: actions.hydrateSecondaryDisplaySet,
2922
+ loadDisplaySetData: actions.loadDisplaySetData,
2923
+ getVolumeIdForDisplaySet: actions.getVolumeIdForDisplaySet,
2924
+ triggerCreateAnnotationMemo: actions.triggerCreateAnnotationMemo,
2925
+ startRecordingForAnnotationGroup: actions.startRecordingForAnnotationGroup,
2926
+ endRecordingForAnnotationGroup: actions.endRecordingForAnnotationGroup,
2927
+ toggleSegmentLabel: actions.toggleSegmentLabel,
2928
+ jumpToMeasurementViewport: actions.jumpToMeasurementViewport,
2929
+ initializeSegmentLabelTool: actions.initializeSegmentLabelTool,
2930
+ activateSelectedSegmentationOfType: actions.activateSelectedSegmentationOfType,
2931
+ setDynamicCursorSizeForSculptorTool: actions.setDynamicCursorSizeForSculptorTool,
2932
+ setSimplifiedSplineForSplineContourSegmentationTool:
2933
+ actions.setSimplifiedSplineForSplineContourSegmentationTool,
2934
+ removeSmallContours: actions.removeSmallContours,
2935
+ applyLogicalContourOperation: actions.applyLogicalContourOperation,
2936
+ copyContourSegment: actions.copyContourSegment,
2937
+ smoothContours: actions.smoothContours,
2938
+ removeContourHoles: actions.removeContourHoles,
2939
+ decimateContours: actions.decimateContours,
2940
+ convertContourHoles: actions.convertContourHoles,
2941
+ setInterpolationToolConfiguration: actions.setInterpolationToolConfiguration,
2942
+ };
2943
+
2944
+ return {
2945
+ actions,
2946
+ definitions,
2947
+ defaultContext: 'CORNERSTONE',
2948
+ };
2949
+ }
2950
+
2951
+ export default commandsModule;