@ohif/extension-cornerstone 3.14.0-beta.12 → 3.14.0-beta.121

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (335) hide show
  1. package/dist/915.ohif-extension-cornerstone.umd.js +1 -1
  2. package/dist/ohif-extension-cornerstone.umd.js +1 -5
  3. package/package.json +33 -25
  4. package/src/Viewport/OHIFCornerstoneViewport.css +46 -0
  5. package/src/Viewport/OHIFCornerstoneViewport.tsx +498 -0
  6. package/src/Viewport/Overlays/CornerstoneOverlays.tsx +103 -0
  7. package/src/Viewport/Overlays/CustomizableViewportOverlay.css +25 -0
  8. package/src/Viewport/Overlays/CustomizableViewportOverlay.tsx +469 -0
  9. package/src/Viewport/Overlays/ViewportImageScrollbar.tsx +106 -0
  10. package/src/Viewport/Overlays/ViewportImageSliceLoadingIndicator.tsx +87 -0
  11. package/src/Viewport/Overlays/ViewportOrientationMarkers.css +41 -0
  12. package/src/Viewport/Overlays/ViewportOrientationMarkers.tsx +136 -0
  13. package/src/Viewport/Overlays/ViewportSliceProgressScrollbar/ViewportSliceProgressScrollbar.tsx +195 -0
  14. package/src/Viewport/Overlays/ViewportSliceProgressScrollbar/helpers.ts +46 -0
  15. package/src/Viewport/Overlays/ViewportSliceProgressScrollbar/hooks.ts +383 -0
  16. package/src/Viewport/Overlays/ViewportSliceProgressScrollbar/index.ts +1 -0
  17. package/src/Viewport/Overlays/ViewportSliceProgressScrollbar/types.ts +17 -0
  18. package/src/Viewport/Overlays/utils.ts +66 -0
  19. package/src/commandsModule.ts +3008 -0
  20. package/src/components/AccordionGroup/AccordionGroup.tsx +195 -0
  21. package/src/components/AccordionGroup/index.ts +4 -0
  22. package/src/components/ActiveViewportWindowLevel/ActiveViewportWindowLevel.tsx +23 -0
  23. package/src/components/ActiveViewportWindowLevel/index.js +1 -0
  24. package/src/components/AdvancedRenderingControls/AdvancedRenderingControls.tsx +149 -0
  25. package/src/components/AdvancedRenderingControls/index.ts +1 -0
  26. package/src/components/CinePlayer/CinePlayer.tsx +247 -0
  27. package/src/components/CinePlayer/index.ts +3 -0
  28. package/src/components/DicomUpload/DicomUpload.tsx +111 -0
  29. package/src/components/DicomUpload/DicomUploadProgress.tsx +396 -0
  30. package/src/components/DicomUpload/DicomUploadProgressItem.tsx +119 -0
  31. package/src/components/ExportSegmentationSubMenuItem.tsx +75 -0
  32. package/src/components/FidelityIndicator/FidelityIndicator.tsx +152 -0
  33. package/src/components/FidelityIndicator/index.ts +1 -0
  34. package/src/components/MeasurementItems.tsx +70 -0
  35. package/src/components/MeasurementTableNested.tsx +30 -0
  36. package/src/components/MeasurementsMenu.tsx +84 -0
  37. package/src/components/MeasurementsOrAdditionalFindings.tsx +82 -0
  38. package/src/components/ModalityLoadBadge/ModalityLoadBadge.tsx +171 -0
  39. package/src/components/ModalityLoadBadge/index.ts +1 -0
  40. package/src/components/NavigationComponent/NavigationComponent.tsx +138 -0
  41. package/src/components/NavigationComponent/index.ts +3 -0
  42. package/src/components/OHIFViewportActionCorners.tsx +109 -0
  43. package/src/components/OpacityMenu/OpacityMenu.tsx +54 -0
  44. package/src/components/OpacityMenu/OpacityMenuWrapper.tsx +85 -0
  45. package/src/components/OpacityMenu/index.ts +2 -0
  46. package/src/components/PanelAccordionTrigger.tsx +48 -0
  47. package/src/components/SegmentationToolConfig.tsx +71 -0
  48. package/src/components/SegmentationUtilityButton.tsx +61 -0
  49. package/src/components/SelectItemWithModality.tsx +29 -0
  50. package/src/components/SeriesMeasurements.tsx +90 -0
  51. package/src/components/SeriesSummaryFromDisplaySet.tsx +21 -0
  52. package/src/components/StudyMeasurements.tsx +88 -0
  53. package/src/components/StudyMeasurementsActions.tsx +75 -0
  54. package/src/components/StudySummaryFromMetadata.test.ts +47 -0
  55. package/src/components/StudySummaryFromMetadata.tsx +31 -0
  56. package/src/components/StudySummaryWithActions.tsx +14 -0
  57. package/src/components/ThresholdMenu/ThresholdMenu.tsx +104 -0
  58. package/src/components/ThresholdMenu/ThresholdMenuWrapper.tsx +85 -0
  59. package/src/components/ThresholdMenu/index.ts +2 -0
  60. package/src/components/TrackingStatus/TrackingStatus.tsx +32 -0
  61. package/src/components/TrackingStatus/index.ts +1 -0
  62. package/src/components/VOIManualControlMenu/VOIManualControlMenu.tsx +190 -0
  63. package/src/components/VOIManualControlMenu/VOIManualControlMenuWrapper.tsx +85 -0
  64. package/src/components/VOIManualControlMenu/index.ts +2 -0
  65. package/src/components/ViewportColorbar/ViewportColorbar.tsx +150 -0
  66. package/src/components/ViewportColorbar/ViewportColorbarsContainer.tsx +125 -0
  67. package/src/components/ViewportColorbar/index.ts +5 -0
  68. package/src/components/ViewportDataOverlaySettingMenu/ViewportDataOverlayMenu.tsx +538 -0
  69. package/src/components/ViewportDataOverlaySettingMenu/ViewportDataOverlayMenuWrapper.tsx +91 -0
  70. package/src/components/ViewportDataOverlaySettingMenu/utils.ts +118 -0
  71. package/src/components/ViewportOrientationMenu/Viewport3DCompassMenu.tsx +261 -0
  72. package/src/components/ViewportOrientationMenu/ViewportOrientationMenu.tsx +249 -0
  73. package/src/components/ViewportOrientationMenu/ViewportOrientationMenuWrapper.tsx +40 -0
  74. package/src/components/ViewportWindowLevel/ViewportWindowLevel.tsx +261 -0
  75. package/src/components/ViewportWindowLevel/getViewportVolumeHistogram.ts +72 -0
  76. package/src/components/ViewportWindowLevel/histogramWorker.js +97 -0
  77. package/src/components/ViewportWindowLevel/index.js +1 -0
  78. package/src/components/ViewportWindowLevel/utils.ts +176 -0
  79. package/src/components/WindowLevelActionMenu/Colorbar.tsx +30 -0
  80. package/src/components/WindowLevelActionMenu/Colormap.tsx +121 -0
  81. package/src/components/WindowLevelActionMenu/VolumeLighting.tsx +82 -0
  82. package/src/components/WindowLevelActionMenu/VolumeRenderingOptions.tsx +38 -0
  83. package/src/components/WindowLevelActionMenu/VolumeRenderingPresets.tsx +36 -0
  84. package/src/components/WindowLevelActionMenu/VolumeRenderingPresetsContent.tsx +78 -0
  85. package/src/components/WindowLevelActionMenu/VolumeRenderingQuality.tsx +64 -0
  86. package/src/components/WindowLevelActionMenu/VolumeShade.tsx +47 -0
  87. package/src/components/WindowLevelActionMenu/VolumeShift.tsx +92 -0
  88. package/src/components/WindowLevelActionMenu/WindowLevel.tsx +157 -0
  89. package/src/components/WindowLevelActionMenu/WindowLevelActionMenu.tsx +102 -0
  90. package/src/components/WindowLevelActionMenu/WindowLevelActionMenuWrapper.tsx +131 -0
  91. package/src/components/WindowLevelActionMenu/defaultWindowLevelPresets.ts +23 -0
  92. package/src/components/WindowLevelActionMenu/index.ts +11 -0
  93. package/src/components/WindowLevelActionMenu/windowLevelPresetHotkeys.test.ts +19 -0
  94. package/src/components/index.ts +13 -0
  95. package/src/constants/index.ts +13 -0
  96. package/src/customizations/CustomDropdownMenuContent.tsx +106 -0
  97. package/src/customizations/CustomSegmentStatisticsHeader.tsx +140 -0
  98. package/src/customizations/captureViewportModalCustomization.tsx +175 -0
  99. package/src/customizations/colorbarCustomization.ts +93 -0
  100. package/src/customizations/gpuSettingsPresetCustomization.ts +8 -0
  101. package/src/customizations/layoutSelectorCustomization.ts +104 -0
  102. package/src/customizations/measurementsCustomization.ts +124 -0
  103. package/src/customizations/miscCustomization.ts +22 -0
  104. package/src/customizations/modalityColorMapCustomization.ts +23 -0
  105. package/src/customizations/segmentationHydrationCustomization.ts +16 -0
  106. package/src/customizations/segmentationPanelCustomization.tsx +119 -0
  107. package/src/customizations/segmentationToolbarCustomization.ts +964 -0
  108. package/src/customizations/toolGroupToolsCustomization.ts +204 -0
  109. package/src/customizations/toolbarButtonsCustomization.ts +805 -0
  110. package/src/customizations/viewportClickCommandsCustomization.ts +15 -0
  111. package/src/customizations/viewportDownloadWarningCustomization.tsx +6 -0
  112. package/src/customizations/viewportOverlayCustomization.tsx +46 -0
  113. package/src/customizations/viewportScrollbarCustomization.tsx +27 -0
  114. package/src/customizations/viewportToolsCustomization.ts +33 -0
  115. package/src/customizations/volumeRenderingCustomization.ts +14 -0
  116. package/src/customizations/windowLevelPresetsCustomization.ts +5 -0
  117. package/src/enums.ts +9 -0
  118. package/src/getCustomizationModule.tsx +54 -0
  119. package/src/getHangingProtocolModule.ts +47 -0
  120. package/src/getPanelModule.tsx +128 -0
  121. package/src/getSopClassHandlerModule.js +284 -0
  122. package/src/getToolbarModule.tsx +622 -0
  123. package/src/hooks/index.ts +9 -0
  124. package/src/hooks/useActiveViewportSegmentationRepresentations.ts +14 -0
  125. package/src/hooks/useMeasurementTracking.ts +132 -0
  126. package/src/hooks/useMeasurements.ts +104 -0
  127. package/src/hooks/useSegmentations.ts +147 -0
  128. package/src/hooks/useViewportDisplaySets.ts +284 -0
  129. package/src/hooks/useViewportFidelity.ts +243 -0
  130. package/src/hooks/useViewportHover.ts +77 -0
  131. package/src/hooks/useViewportRendering.tsx +868 -0
  132. package/src/hooks/useViewportSegmentations.ts +245 -0
  133. package/src/hps/fourUp.ts +117 -0
  134. package/src/hps/frameView.ts +1581 -0
  135. package/src/hps/main3D.ts +142 -0
  136. package/src/hps/mpr.ts +197 -0
  137. package/src/hps/mprAnd3DVolumeViewport.ts +124 -0
  138. package/src/hps/only3D.ts +70 -0
  139. package/src/hps/primary3D.ts +142 -0
  140. package/src/hps/primaryAxial.ts +114 -0
  141. package/src/id.js +5 -0
  142. package/src/index.tsx +352 -0
  143. package/src/init.tsx +450 -0
  144. package/src/initCineService.ts +75 -0
  145. package/src/initContextMenu.ts +94 -0
  146. package/src/initCornerstoneTools.js +191 -0
  147. package/src/initDoubleClick.ts +82 -0
  148. package/src/initMeasurementService.ts +576 -0
  149. package/src/initStudyPrefetcherService.ts +33 -0
  150. package/src/initWADOImageLoader.js +56 -0
  151. package/src/panels/PanelMeasurement.tsx +84 -0
  152. package/src/panels/PanelSegmentation.tsx +338 -0
  153. package/src/services/ColorbarService/ColorbarService.ts +242 -0
  154. package/src/services/ColorbarService/index.ts +2 -0
  155. package/src/services/CornerstoneCacheService/CornerstoneCacheService.ts +326 -0
  156. package/src/services/CornerstoneCacheService/index.js +3 -0
  157. package/src/services/SegmentationService/RTSTRUCT/mapROIContoursToRTStructData.ts +36 -0
  158. package/src/services/SegmentationService/SegmentationService.test.ts +3727 -0
  159. package/src/services/SegmentationService/SegmentationService.ts +2390 -0
  160. package/src/services/SegmentationService/backends/ISegmentationBackend.ts +102 -0
  161. package/src/services/SegmentationService/backends/ISegmentationServiceInternals.ts +44 -0
  162. package/src/services/SegmentationService/backends/LegacySegmentationBackend.ts +139 -0
  163. package/src/services/SegmentationService/backends/NextSegmentationBackend.ts +159 -0
  164. package/src/services/SegmentationService/backends/index.ts +4 -0
  165. package/src/services/SegmentationService/index.ts +3 -0
  166. package/src/services/SyncGroupService/SyncGroupService.ts +264 -0
  167. package/src/services/SyncGroupService/createHydrateSegmentationSynchronizer.ts +118 -0
  168. package/src/services/SyncGroupService/index.js +3 -0
  169. package/src/services/ToolGroupService/ToolGroupService.test.ts +83 -0
  170. package/src/services/ToolGroupService/ToolGroupService.ts +541 -0
  171. package/src/services/ToolGroupService/index.js +3 -0
  172. package/src/services/ViewedDataService/ViewedDataService.ts +58 -0
  173. package/src/services/ViewedDataService/index.ts +3 -0
  174. package/src/services/ViewportService/CornerstoneViewportService.ts +1814 -0
  175. package/src/services/ViewportService/IViewportService.ts +64 -0
  176. package/src/services/ViewportService/Viewport.ts +372 -0
  177. package/src/services/ViewportService/adapter/IViewportAdapter.contract.test.ts +467 -0
  178. package/src/services/ViewportService/adapter/IViewportAdapter.ts +179 -0
  179. package/src/services/ViewportService/adapter/LegacyViewportAdapter.ts +240 -0
  180. package/src/services/ViewportService/adapter/NextViewportAdapter.ts +241 -0
  181. package/src/services/ViewportService/adapter/getViewportAdapter.ts +62 -0
  182. package/src/services/ViewportService/adapter/index.ts +16 -0
  183. package/src/services/ViewportService/backends/IViewportBackend.ts +195 -0
  184. package/src/services/ViewportService/backends/IViewportOperations.ts +98 -0
  185. package/src/services/ViewportService/backends/IViewportServiceInternals.ts +47 -0
  186. package/src/services/ViewportService/backends/LegacyViewportBackend.ts +264 -0
  187. package/src/services/ViewportService/backends/LegacyViewportOperations.ts +272 -0
  188. package/src/services/ViewportService/backends/NextViewportBackend.ts +673 -0
  189. package/src/services/ViewportService/backends/NextViewportOperations.ts +169 -0
  190. package/src/services/ViewportService/backends/README.md +62 -0
  191. package/src/services/ViewportService/backends/dataIdRegistry.ts +121 -0
  192. package/src/services/ViewportService/backends/viewportOperations.ts +71 -0
  193. package/src/services/ViewportService/constants.ts +3 -0
  194. package/src/state.ts +34 -0
  195. package/src/stores/index.ts +5 -0
  196. package/src/stores/presentationUtils.ts +42 -0
  197. package/src/stores/useLutPresentationStore.ts +166 -0
  198. package/src/stores/usePositionPresentationStore.ts +172 -0
  199. package/src/stores/useSegmentationPresentationStore.test.ts +146 -0
  200. package/src/stores/useSegmentationPresentationStore.ts +417 -0
  201. package/src/stores/useSelectedSegmentationsForViewportStore.ts +85 -0
  202. package/src/stores/useSynchronizersStore.ts +84 -0
  203. package/src/synchronizers/frameViewSynchronizer.ts +52 -0
  204. package/src/tools/CalibrationLineTool.ts +97 -0
  205. package/src/tools/ImageOverlayViewerTool.tsx +279 -0
  206. package/src/tools/OverlayPlaneModuleProvider.ts +40 -0
  207. package/src/tools/WindowLevelTool.test.ts +55 -0
  208. package/src/tools/WindowLevelTool.ts +22 -0
  209. package/src/types/AppTypes.ts +70 -0
  210. package/src/types/Colorbar.ts +114 -0
  211. package/src/types/Colormap.ts +16 -0
  212. package/src/types/CornerstoneCacheService.ts +40 -0
  213. package/src/types/CornerstoneServices.ts +18 -0
  214. package/src/types/Presentation.ts +83 -0
  215. package/src/types/SelectedSegmentationByTypeMap.ts +3 -0
  216. package/src/types/ViewportPresets.ts +53 -0
  217. package/src/types/VolumeLighting.ts +7 -0
  218. package/src/types/VolumeRenderingConfig.ts +8 -0
  219. package/src/types/WindowLevel.ts +5 -0
  220. package/src/types/index.ts +10 -0
  221. package/src/utils/ActiveViewportBehavior.tsx +80 -0
  222. package/src/utils/CornerstoneViewportDownloadForm.tsx +319 -0
  223. package/src/utils/DicomFileUploader.ts +204 -0
  224. package/src/utils/JumpPresets.ts +14 -0
  225. package/src/utils/autoHydrateViewportTypes.ts +69 -0
  226. package/src/utils/colormaps.js +1597 -0
  227. package/src/utils/createSegmentationForViewport.test.ts +93 -0
  228. package/src/utils/createSegmentationForViewport.ts +123 -0
  229. package/src/utils/dicomLoaderService.js +225 -0
  230. package/src/utils/ecgMetadata.test.ts +137 -0
  231. package/src/utils/ecgMetadata.ts +109 -0
  232. package/src/utils/findNearbyToolData.test.ts +125 -0
  233. package/src/utils/findNearbyToolData.ts +21 -0
  234. package/src/utils/findWindowLevelPreset.test.ts +55 -0
  235. package/src/utils/findWindowLevelPreset.ts +46 -0
  236. package/src/utils/generateSegmentationCSVReport.test.ts +324 -0
  237. package/src/utils/generateSegmentationCSVReport.ts +131 -0
  238. package/src/utils/getActiveViewportEnabledElement.test.ts +70 -0
  239. package/src/utils/getActiveViewportEnabledElement.ts +8 -0
  240. package/src/utils/getCenterExtent.test.ts +313 -0
  241. package/src/utils/getCenterExtent.ts +46 -0
  242. package/src/utils/getCornerstoneBlendMode.test.ts +59 -0
  243. package/src/utils/getCornerstoneBlendMode.ts +25 -0
  244. package/src/utils/getCornerstoneOrientation.test.ts +78 -0
  245. package/src/utils/getCornerstoneOrientation.ts +31 -0
  246. package/src/utils/getCornerstoneViewportType.test.ts +169 -0
  247. package/src/utils/getCornerstoneViewportType.ts +88 -0
  248. package/src/utils/getInterleavedFrames.test.ts +85 -0
  249. package/src/utils/getInterleavedFrames.ts +73 -0
  250. package/src/utils/getLegacyViewportType.ts +64 -0
  251. package/src/utils/getNthFrames.test.ts +145 -0
  252. package/src/utils/getNthFrames.ts +31 -0
  253. package/src/utils/getViewportEnabledElement.test.ts +83 -0
  254. package/src/utils/getViewportEnabledElement.ts +8 -0
  255. package/src/utils/getViewportOrientationFromImageOrientationPatient.test.ts +50 -0
  256. package/src/utils/getViewportOrientationFromImageOrientationPatient.ts +56 -0
  257. package/src/utils/hydrationUtils.test.ts +572 -0
  258. package/src/utils/hydrationUtils.ts +197 -0
  259. package/src/utils/imageSliceSync/calculateViewportRegistrations.ts +28 -0
  260. package/src/utils/imageSliceSync/toggleImageSliceSync.ts +101 -0
  261. package/src/utils/index.ts +29 -0
  262. package/src/utils/initGpuSettingsPreset.ts +51 -0
  263. package/src/utils/initViewTiming.test.ts +342 -0
  264. package/src/utils/initViewTiming.ts +52 -0
  265. package/src/utils/initWebWorkerProgressHandler.test.ts +381 -0
  266. package/src/utils/initWebWorkerProgressHandler.ts +110 -0
  267. package/src/utils/interleave.test.ts +304 -0
  268. package/src/utils/interleave.ts +32 -0
  269. package/src/utils/interleaveCenterLoader.test.ts +547 -0
  270. package/src/utils/interleaveCenterLoader.ts +143 -0
  271. package/src/utils/interleaveTopToBottom.test.ts +487 -0
  272. package/src/utils/interleaveTopToBottom.ts +132 -0
  273. package/src/utils/isAnyDisplaySetCommon.ts +18 -0
  274. package/src/utils/isDisplaySetOverlayable.ts +106 -0
  275. package/src/utils/isMeasurementWithinViewport.test.ts +340 -0
  276. package/src/utils/isMeasurementWithinViewport.ts +33 -0
  277. package/src/utils/isReferenceViewable.test.ts +581 -0
  278. package/src/utils/isReferenceViewable.ts +95 -0
  279. package/src/utils/loadDisplaySetData.ts +49 -0
  280. package/src/utils/measurementServiceMappings/Angle.ts +200 -0
  281. package/src/utils/measurementServiceMappings/ArrowAnnotate.ts +176 -0
  282. package/src/utils/measurementServiceMappings/Bidirectional.ts +193 -0
  283. package/src/utils/measurementServiceMappings/CircleROI.ts +227 -0
  284. package/src/utils/measurementServiceMappings/CobbAngle.ts +206 -0
  285. package/src/utils/measurementServiceMappings/EllipticalROI.ts +221 -0
  286. package/src/utils/measurementServiceMappings/Length.ts +206 -0
  287. package/src/utils/measurementServiceMappings/LivewireContour.ts +175 -0
  288. package/src/utils/measurementServiceMappings/PlanarFreehandROI.ts +228 -0
  289. package/src/utils/measurementServiceMappings/Probe.ts +192 -0
  290. package/src/utils/measurementServiceMappings/RectangleROI.ts +225 -0
  291. package/src/utils/measurementServiceMappings/SegmentBidirectional.ts +184 -0
  292. package/src/utils/measurementServiceMappings/SplineROI.ts +227 -0
  293. package/src/utils/measurementServiceMappings/UltrasoundDirectional.ts +214 -0
  294. package/src/utils/measurementServiceMappings/UltrasoundPleuraBLine.ts +179 -0
  295. package/src/utils/measurementServiceMappings/constants/supportedTools.js +21 -0
  296. package/src/utils/measurementServiceMappings/index.ts +3 -0
  297. package/src/utils/measurementServiceMappings/measurementServiceMappingsFactory.ts +324 -0
  298. package/src/utils/measurementServiceMappings/utils/getDisplayUnit.js +3 -0
  299. package/src/utils/measurementServiceMappings/utils/getHandlesFromPoints.js +14 -0
  300. package/src/utils/measurementServiceMappings/utils/getIsLocked.ts +5 -0
  301. package/src/utils/measurementServiceMappings/utils/getIsVisible.ts +6 -0
  302. package/src/utils/measurementServiceMappings/utils/getSOPInstanceAttributes.js +66 -0
  303. package/src/utils/measurementServiceMappings/utils/getValueDisplayString.js +12 -0
  304. package/src/utils/measurementServiceMappings/utils/index.ts +17 -0
  305. package/src/utils/measurementServiceMappings/utils/selection.ts +33 -0
  306. package/src/utils/mpr/getProtocolViewportStructureFromGridViewports.ts +74 -0
  307. package/src/utils/nextViewportPolicies.ts +41 -0
  308. package/src/utils/nextViewports.ts +157 -0
  309. package/src/utils/nthLoader.test.ts +317 -0
  310. package/src/utils/nthLoader.ts +78 -0
  311. package/src/utils/presentations/getViewportPresentations.test.ts +280 -0
  312. package/src/utils/presentations/getViewportPresentations.ts +151 -0
  313. package/src/utils/promptHydrationDialog.test.ts +490 -0
  314. package/src/utils/promptHydrationDialog.ts +197 -0
  315. package/src/utils/promptTimePointScope.tsx +82 -0
  316. package/src/utils/removeViewportSegmentationRepresentations.test.ts +129 -0
  317. package/src/utils/removeViewportSegmentationRepresentations.ts +17 -0
  318. package/src/utils/segmentUtils.test.ts +515 -0
  319. package/src/utils/segmentUtils.ts +46 -0
  320. package/src/utils/segmentationExportUtils.test.ts +100 -0
  321. package/src/utils/segmentationExportUtils.ts +171 -0
  322. package/src/utils/segmentationHandlers.test.ts +614 -0
  323. package/src/utils/segmentationHandlers.ts +164 -0
  324. package/src/utils/setUpAnnotationEventHandlers.ts +26 -0
  325. package/src/utils/setUpSegmentationEventHandlers.test.ts +372 -0
  326. package/src/utils/setUpSegmentationEventHandlers.ts +122 -0
  327. package/src/utils/toggleVOISliceSync.test.ts +606 -0
  328. package/src/utils/toggleVOISliceSync.ts +103 -0
  329. package/src/utils/transitions.test.ts +351 -0
  330. package/src/utils/transitions.ts +300 -0
  331. package/src/utils/updateSegmentationStats.test.ts +942 -0
  332. package/src/utils/updateSegmentationStats.ts +192 -0
  333. package/src/utils/viewportDataShape.ts +85 -0
  334. package/src/utils/volume3dView.test.ts +48 -0
  335. package/src/utils/volume3dView.ts +113 -0
@@ -0,0 +1,102 @@
1
+ import type { Types as csTypes } from '@cornerstonejs/core';
2
+ import type { Enums as csToolsEnums, Types as cstTypes } from '@cornerstonejs/tools';
3
+
4
+ /** A derived labelmap image produced by the SEG adapter (one per referenced image,
5
+ * per overlap group). `voxelManager.getScalarData()` yields the slice's label values. */
6
+ export interface SegLabelmapImage {
7
+ imageId: string;
8
+ voxelManager?: { getScalarData: () => ArrayLike<number> };
9
+ }
10
+
11
+ /** Inputs for assembling the cornerstone SegmentationPublicInput from a loaded SEG
12
+ * display set. `segDisplaySet.labelMapImages` is the adapter's array-of-groups (one
13
+ * conflict-free group per overlap layer); `overlappingSegments` flags whether the
14
+ * SEG actually has overlap. `derivedImageIds` is the flattened image-id list. */
15
+ export interface AssembleSegmentationForSEGParams {
16
+ segmentationId: string;
17
+ segDisplaySet: {
18
+ labelMapImages?: SegLabelmapImage[][];
19
+ overlappingSegments?: boolean;
20
+ [key: string]: unknown;
21
+ };
22
+ derivedImageIds: string[];
23
+ referencedImageIds: string[];
24
+ label: string;
25
+ fallbackLabel: string;
26
+ segments: { [segmentIndex: string]: cstTypes.Segment };
27
+ }
28
+
29
+ /**
30
+ * Result of classifying a labelmap add: the representation type to actually use
31
+ * (LABELMAP, or SURFACE for a 3D viewport) and whether the viewport was promoted
32
+ * stack -> volume (ORTHOGRAPHIC). When `isConverted` is true the caller defers the
33
+ * representation add until the grid re-mounts the recreated viewport.
34
+ */
35
+ export interface LabelmapAddClassification {
36
+ representationTypeToUse: csToolsEnums.SegmentationRepresentations;
37
+ isConverted: boolean;
38
+ }
39
+
40
+ /**
41
+ * Segmentation backend twin (mirrors the viewport backend family at
42
+ * `ViewportService/backends/`). One implementation per lane:
43
+ * - LegacySegmentationBackend: today's behavior (may promote a stack viewport to
44
+ * an ORTHOGRAPHIC volume viewport via the host's convertStackToVolumeViewport).
45
+ * - NextSegmentationBackend: the native GenericViewport ("next") path — renders
46
+ * the labelmap IN PLACE on the raw PlanarViewport and never promotes.
47
+ *
48
+ * DISPATCH (deliberately diverges from IViewportBackend): unlike the viewport
49
+ * lifecycle backend, which is selected ONCE by the appConfig flag, the segmentation
50
+ * twin is routed PER VIEWPORT via `isNextViewport(viewport)` (the same
51
+ * runtime predicate used by `viewportOperations`). A flag-on session can hold both
52
+ * legacy and native viewports, and every viewport-bearing method already has an
53
+ * already-resolved, self-describing viewport in hand, so per-viewport routing is the
54
+ * runtime truth. `isNextViewport` is true for the native raw PlanarViewport and
55
+ * false for legacy StackViewport/VolumeViewport.
56
+ *
57
+ * BOUNDARY: viewport (re)creation is NOT a segmentation concern. The Next twin never
58
+ * calls `convertStackToVolumeViewport` (that recreates the viewport as ORTHOGRAPHIC
59
+ * and is owned by CornerstoneViewportService); the Legacy twin reaches it through
60
+ * `ISegmentationServiceInternals`, so the off path stays byte-identical.
61
+ */
62
+ export interface ISegmentationBackend {
63
+ /**
64
+ * Decide how a LABELMAP representation is added for `csViewport`, performing any
65
+ * stack->volume promotion the lane requires. Called only inside the LABELMAP gate
66
+ * of `addSegmentationRepresentation` (CONTOUR/SURFACE never reach here).
67
+ */
68
+ classifyAndPrepareLabelmapAdd(
69
+ csViewport: csTypes.IViewport,
70
+ segmentation: cstTypes.Segmentation,
71
+ viewportId: string,
72
+ segmentationId: string,
73
+ representationType: csToolsEnums.SegmentationRepresentations
74
+ ): Promise<LabelmapAddClassification>;
75
+
76
+ /**
77
+ * Build the cornerstone SegmentationPublicInput for a loaded DICOM SEG display set.
78
+ *
79
+ * Dispatched by the session flag at SEG-load (NOT per viewport): no target viewport
80
+ * exists yet, and the data shape (single- vs multi-layer) is fixed at creation.
81
+ *
82
+ * Legacy: a single flattened labelmap layer (today's behavior, byte-identical).
83
+ * Next: when the SEG has overlapping segments, register each conflict-free group as
84
+ * its own labelmap layer under one segmentationId (+ segmentBindings) so cornerstone
85
+ * renders all overlapping segments via the slice path; otherwise identical to Legacy.
86
+ */
87
+ assembleSegmentationDataForSEG(
88
+ params: AssembleSegmentationForSEGParams
89
+ ): cstTypes.SegmentationPublicInput;
90
+
91
+ /**
92
+ * Recenter a viewport on a segment's world-space center point. Returns whether it
93
+ * actually recentered, so the caller can skip the segment highlight when it did not
94
+ * (preserving today's "no jump -> no highlight" behavior).
95
+ *
96
+ * Legacy: `viewport.jumpToWorld(world)` (guarded; absent -> false no-op, as today).
97
+ * Next: a native PlanarViewport has no jumpToWorld -> navigate via a view reference
98
+ * centered on `world` (setViewReference), turning today's silent native no-op into a
99
+ * working jump-to-slice. (In-plane pan-to-center is a separate, deferred refinement.)
100
+ */
101
+ jumpToSegmentCenter(viewport: csTypes.IViewport, world: csTypes.Point3): boolean;
102
+ }
@@ -0,0 +1,44 @@
1
+ import type { Types as csTypes } from '@cornerstonejs/core';
2
+ import type { Types as cstTypes } from '@cornerstonejs/tools';
3
+
4
+ /**
5
+ * The narrow slice of SegmentationService that a segmentation backend is allowed to
6
+ * reach (mirrors `IViewportServiceInternals`). The service `implements` this and
7
+ * passes `this` to each backend, so the legacy twin can delegate the viewport
8
+ * (re)creation / data-volume conversion work back to the shared service methods
9
+ * (which touch servicesManager-owned services) without the backends reaching into
10
+ * unrelated internals. Keeping this surface narrow is what stops the legacy path
11
+ * from drifting as the next backend grows.
12
+ *
13
+ * Only the LEGACY twin uses these; the NEXT twin renders in place and needs none of
14
+ * them (it never converts).
15
+ */
16
+ export interface ISegmentationServiceInternals {
17
+ /**
18
+ * Recreate the stack viewport as an ORTHOGRAPHIC volume viewport (legacy
19
+ * promotion). Owned by the service because it drives viewportGridService /
20
+ * cornerstoneViewportService. Returns true (converted).
21
+ */
22
+ convertStackToVolumeViewport(viewport: csTypes.IViewport): Promise<boolean>;
23
+
24
+ /**
25
+ * Promote a stack viewport to volume only when the segmentation's
26
+ * FrameOfReference matches the viewport's. Returns whether it converted.
27
+ */
28
+ attemptStackToVolumeConversion(
29
+ viewport: csTypes.IStackViewport,
30
+ segmentation: cstTypes.Segmentation,
31
+ viewportId: string,
32
+ segmentationId: string
33
+ ): Promise<boolean>;
34
+
35
+ /**
36
+ * Convert the segmentation DATA to a volume labelmap when its FrameOfReference
37
+ * matches a volume viewport (pure data; no viewport recreation).
38
+ */
39
+ handleVolumeViewport(
40
+ viewport: csTypes.IVolumeViewport,
41
+ segmentation: cstTypes.Segmentation,
42
+ isVolumeSegmentation: boolean
43
+ ): Promise<void>;
44
+ }
@@ -0,0 +1,139 @@
1
+ import type { Types as csTypes } from '@cornerstonejs/core';
2
+ import {
3
+ Enums as csToolsEnums,
4
+ segmentation as cstSegmentation,
5
+ type Types as cstTypes,
6
+ } from '@cornerstonejs/tools';
7
+ import { isVolume3DViewportType, isVolumeViewportType } from '../../../utils/getLegacyViewportType';
8
+ import type {
9
+ AssembleSegmentationForSEGParams,
10
+ ISegmentationBackend,
11
+ LabelmapAddClassification,
12
+ } from './ISegmentationBackend';
13
+ import type { ISegmentationServiceInternals } from './ISegmentationServiceInternals';
14
+
15
+ const { Labelmap: LABELMAP, Surface: SURFACE } = csToolsEnums.SegmentationRepresentations;
16
+ const {
17
+ state: { updateLabelmapSegmentationImageReferences },
18
+ } = cstSegmentation;
19
+
20
+ /**
21
+ * Legacy (default) segmentation backend. Selected when the target viewport is NOT a
22
+ * native GenericViewport (the off path / legacy StackViewport / VolumeViewport).
23
+ * Holds the labelmap-add decision tree verbatim (determine + handleViewportConversion
24
+ * + the stack/volume case handlers) and delegates the servicesManager-coupled work
25
+ * (convertStackToVolumeViewport / attemptStackToVolumeConversion / handleVolumeViewport)
26
+ * back to the service via ISegmentationServiceInternals, so behavior is byte-identical
27
+ * to before the backend split.
28
+ */
29
+ export class LegacySegmentationBackend implements ISegmentationBackend {
30
+ constructor(private readonly service: ISegmentationServiceInternals) {}
31
+
32
+ async classifyAndPrepareLabelmapAdd(
33
+ csViewport: csTypes.IViewport,
34
+ segmentation: cstTypes.Segmentation,
35
+ viewportId: string,
36
+ segmentationId: string,
37
+ // The case handlers return LABELMAP/SURFACE directly (byte-identical to the
38
+ // pre-split handleViewportConversion), so the incoming type is unused here.
39
+ _representationType: csToolsEnums.SegmentationRepresentations
40
+ ): Promise<LabelmapAddClassification> {
41
+ const isVolumeViewport = isVolumeViewportType(csViewport);
42
+ // A missing labelmap representation (stale/partial segmentation state) must not
43
+ // throw on the `'volumeId' in ...` probe; treat it as a non-volume segmentation.
44
+ const labelmapData = segmentation?.representationData?.[LABELMAP];
45
+ const isVolumeSegmentation = !!labelmapData && 'volumeId' in labelmapData;
46
+
47
+ return isVolumeViewport
48
+ ? this.handleVolumeViewportCase(csViewport, segmentation, isVolumeSegmentation)
49
+ : this.handleStackViewportCase(
50
+ csViewport,
51
+ segmentation,
52
+ isVolumeSegmentation,
53
+ viewportId,
54
+ segmentationId
55
+ );
56
+ }
57
+
58
+ private async handleVolumeViewportCase(
59
+ csViewport: csTypes.IViewport,
60
+ segmentation: cstTypes.Segmentation,
61
+ isVolumeSegmentation: boolean
62
+ ): Promise<LabelmapAddClassification> {
63
+ if (isVolume3DViewportType(csViewport)) {
64
+ return { representationTypeToUse: SURFACE, isConverted: false };
65
+ }
66
+
67
+ await this.service.handleVolumeViewport(
68
+ csViewport as csTypes.IVolumeViewport,
69
+ segmentation,
70
+ isVolumeSegmentation
71
+ );
72
+ return { representationTypeToUse: LABELMAP, isConverted: false };
73
+ }
74
+
75
+ private async handleStackViewportCase(
76
+ csViewport: csTypes.IViewport,
77
+ segmentation: cstTypes.Segmentation,
78
+ isVolumeSegmentation: boolean,
79
+ viewportId: string,
80
+ segmentationId: string
81
+ ): Promise<LabelmapAddClassification> {
82
+ if (isVolumeSegmentation) {
83
+ const isConverted = await this.service.convertStackToVolumeViewport(csViewport);
84
+ return { representationTypeToUse: LABELMAP, isConverted };
85
+ }
86
+
87
+ if (updateLabelmapSegmentationImageReferences(viewportId, segmentationId)) {
88
+ return { representationTypeToUse: LABELMAP, isConverted: false };
89
+ }
90
+
91
+ const isConverted = await this.service.attemptStackToVolumeConversion(
92
+ csViewport as csTypes.IStackViewport,
93
+ segmentation,
94
+ viewportId,
95
+ segmentationId
96
+ );
97
+
98
+ return { representationTypeToUse: LABELMAP, isConverted };
99
+ }
100
+
101
+ assembleSegmentationDataForSEG(
102
+ params: AssembleSegmentationForSEGParams
103
+ ): cstTypes.SegmentationPublicInput {
104
+ const { segmentationId, derivedImageIds, referencedImageIds, label, fallbackLabel, segments } =
105
+ params;
106
+
107
+ // Single flattened labelmap layer — byte-identical to the pre-split builder in
108
+ // createSegmentationForSEGDisplaySet. Overlap is collapsed (one voxel = one id).
109
+ return {
110
+ segmentationId,
111
+ representation: {
112
+ type: LABELMAP,
113
+ data: {
114
+ imageIds: derivedImageIds,
115
+ referencedImageIds,
116
+ },
117
+ },
118
+ config: {
119
+ label,
120
+ fallbackLabel,
121
+ segments,
122
+ },
123
+ };
124
+ }
125
+
126
+ jumpToSegmentCenter(viewport: csTypes.IViewport, world: csTypes.Point3): boolean {
127
+ // Byte-identical to the pre-split guarded recenter: legacy stack/volume viewports
128
+ // have jumpToWorld; if absent (e.g. a native viewport reaching the legacy twin),
129
+ // no-op and report it so the caller skips the highlight, exactly as before.
130
+ const legacyViewport = viewport as csTypes.IViewport & {
131
+ jumpToWorld?: (world: csTypes.Point3) => void;
132
+ };
133
+ if (!legacyViewport?.jumpToWorld) {
134
+ return false;
135
+ }
136
+ legacyViewport.jumpToWorld(world);
137
+ return true;
138
+ }
139
+ }
@@ -0,0 +1,159 @@
1
+ import type { Types as csTypes } from '@cornerstonejs/core';
2
+ import {
3
+ Enums as csToolsEnums,
4
+ segmentation as cstSegmentation,
5
+ type Types as cstTypes,
6
+ } from '@cornerstonejs/tools';
7
+ import type {
8
+ AssembleSegmentationForSEGParams,
9
+ ISegmentationBackend,
10
+ LabelmapAddClassification,
11
+ } from './ISegmentationBackend';
12
+
13
+ const { Labelmap: LABELMAP } = csToolsEnums.SegmentationRepresentations;
14
+ const {
15
+ state: { updateLabelmapSegmentationImageReferences },
16
+ } = cstSegmentation;
17
+
18
+ /**
19
+ * Native GenericViewport ("next") segmentation backend. Selected when the target
20
+ * viewport is a native generic viewport (raw PlanarViewport;
21
+ * `isNextViewport(viewport)` is true).
22
+ *
23
+ * The keystone of the native migration: a native PlanarViewport renders a labelmap
24
+ * IN PLACE — cornerstone's `resolveLabelmapRenderPlan` picks `legacy-stack-image`
25
+ * for a stack labelmap (no volumeId, no VTK_VOLUME_SLICE precondition) and the
26
+ * duck-typed image-reference resolver maps it onto the viewport's current image. So
27
+ * this twin NEVER promotes the viewport to an ORTHOGRAPHIC volume viewport: the
28
+ * legacy `convertStackToVolumeViewport` calls `getViewPresentation` /
29
+ * `setViewPresentation`, which the raw PlanarViewport does not implement — it throws
30
+ * (the observed `getViewPresentation is not a function`) and would recreate the
31
+ * viewport, defeating `useNextViewports`.
32
+ *
33
+ * Needs nothing from the host service (it never converts / never touches
34
+ * servicesManager), so unlike the legacy twin it takes no internals handle.
35
+ */
36
+ export class NextSegmentationBackend implements ISegmentationBackend {
37
+ async classifyAndPrepareLabelmapAdd(
38
+ _csViewport: csTypes.IViewport,
39
+ _segmentation: cstTypes.Segmentation,
40
+ viewportId: string,
41
+ segmentationId: string,
42
+ representationType: csToolsEnums.SegmentationRepresentations
43
+ ): Promise<LabelmapAddClassification> {
44
+ // Try the duck-typed in-place resolver so the labelmap's images map onto the
45
+ // viewport's current image when the FrameOfReference matches. Its return value
46
+ // is intentionally ignored: we return isConverted:false UNCONDITIONALLY so we
47
+ // never promote, even on a mount-timing race where the resolver cannot map yet.
48
+ updateLabelmapSegmentationImageReferences(viewportId, segmentationId);
49
+
50
+ return { representationTypeToUse: representationType, isConverted: false };
51
+ }
52
+
53
+ assembleSegmentationDataForSEG(
54
+ params: AssembleSegmentationForSEGParams
55
+ ): cstTypes.SegmentationPublicInput {
56
+ const {
57
+ segmentationId,
58
+ segDisplaySet,
59
+ derivedImageIds,
60
+ referencedImageIds,
61
+ label,
62
+ fallbackLabel,
63
+ segments,
64
+ } = params;
65
+
66
+ const groups = segDisplaySet.labelMapImages ?? [];
67
+ const config = { label, fallbackLabel, segments };
68
+
69
+ // Non-overlapping (or a single group): identical to the legacy single-layer build.
70
+ if (!segDisplaySet.overlappingSegments || groups.length <= 1) {
71
+ return {
72
+ segmentationId,
73
+ representation: {
74
+ type: LABELMAP,
75
+ data: { imageIds: derivedImageIds, referencedImageIds },
76
+ },
77
+ config,
78
+ };
79
+ }
80
+
81
+ // Overlapping SEG: register each conflict-free group as its OWN labelmap layer
82
+ // under one segmentationId. cornerstone's slice path auto-fires for >1 stack layer
83
+ // (shouldUseSliceRendering) and stacks one depth-offset vtkImageSlice actor per
84
+ // layer, so all overlapping segments stay simultaneously visible.
85
+ // ensureLabelmapState preserves a supplied labelmaps/segmentBindings/
86
+ // primaryLabelmapId map via its `||=` guards, so this needs NO cornerstone change.
87
+ const labelmaps: Record<
88
+ string,
89
+ { labelmapId: string; storageKind: 'stack'; imageIds: string[]; referencedImageIds: string[] }
90
+ > = {};
91
+ const segmentBindings: Record<number, { labelmapId: string; labelValue: number }> = {};
92
+
93
+ groups.forEach((group, index) => {
94
+ const labelmapId = `${segmentationId}-storage-${index}`;
95
+ labelmaps[labelmapId] = {
96
+ labelmapId,
97
+ storageKind: 'stack',
98
+ imageIds: group.map(image => image.imageId),
99
+ referencedImageIds,
100
+ };
101
+
102
+ // The adapter bin-packs non-overlapping segments into each group and writes each
103
+ // segment's index as its label value (the colorLUT is segment-indexed, so
104
+ // labelValue === segmentIndex). Group membership is implicit in the pixel data,
105
+ // so recover it by collecting the distinct non-zero values present in the group;
106
+ // those segment indices bind to this layer (so ensureLabelmapState does not
107
+ // default them all onto the primary layer, which would hide layers 1..N-1).
108
+ const valuesInGroup = new Set<number>();
109
+ for (const image of group) {
110
+ const scalarData = image.voxelManager?.getScalarData();
111
+ if (!scalarData) {
112
+ continue;
113
+ }
114
+ for (let i = 0; i < scalarData.length; i++) {
115
+ const value = scalarData[i];
116
+ if (value !== 0) {
117
+ valuesInGroup.add(value);
118
+ }
119
+ }
120
+ }
121
+ valuesInGroup.forEach(value => {
122
+ segmentBindings[value] = { labelmapId, labelValue: value };
123
+ });
124
+ });
125
+
126
+ return {
127
+ segmentationId,
128
+ representation: {
129
+ type: LABELMAP,
130
+ data: {
131
+ // Keep the flattened list for legacy singular readers (getLabelmapImageIds,
132
+ // SEG export); the per-layer truth lives in `labelmaps`.
133
+ imageIds: derivedImageIds,
134
+ referencedImageIds,
135
+ labelmaps,
136
+ segmentBindings,
137
+ primaryLabelmapId: `${segmentationId}-storage-0`,
138
+ },
139
+ },
140
+ config,
141
+ } as cstTypes.SegmentationPublicInput;
142
+ }
143
+
144
+ jumpToSegmentCenter(viewport: csTypes.IViewport, world: csTypes.Point3): boolean {
145
+ // A native PlanarViewport has no jumpToWorld; navigate via a view reference
146
+ // centered on the segment's world point. This snaps to the slice containing
147
+ // `world` along the viewport's current view normal (the core of jump-to-segment).
148
+ // In-plane pan-to-center is a separate, deferred refinement.
149
+ const nativeViewport = viewport as csTypes.IViewport & {
150
+ setViewReference?: (ref: csTypes.ViewReference) => void;
151
+ };
152
+ if (typeof nativeViewport.setViewReference !== 'function') {
153
+ return false;
154
+ }
155
+ nativeViewport.setViewReference({ cameraFocalPoint: world } as csTypes.ViewReference);
156
+ viewport.render();
157
+ return true;
158
+ }
159
+ }
@@ -0,0 +1,4 @@
1
+ export type { ISegmentationBackend, LabelmapAddClassification } from './ISegmentationBackend';
2
+ export type { ISegmentationServiceInternals } from './ISegmentationServiceInternals';
3
+ export { LegacySegmentationBackend } from './LegacySegmentationBackend';
4
+ export { NextSegmentationBackend } from './NextSegmentationBackend';
@@ -0,0 +1,3 @@
1
+ import SegmentationService from './SegmentationService';
2
+
3
+ export default SegmentationService;