@cornerstonejs/tools 5.0.0-beta.1 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/config.d.ts +4 -0
- package/dist/esm/drawingSvg/drawPath.d.ts +3 -0
- package/dist/esm/drawingSvg/drawPath.js +4 -1
- package/dist/esm/eventListeners/keyboard/keyDownListener.js +2 -2
- package/dist/esm/eventListeners/mouse/getMouseEventPoints.d.ts +1 -1
- package/dist/esm/eventListeners/mouse/getMouseEventPoints.js +19 -1
- package/dist/esm/eventListeners/mouse/mouseDoubleClickListener.js +8 -1
- package/dist/esm/eventListeners/mouse/mouseDownListener.js +37 -5
- package/dist/esm/eventListeners/mouse/mouseMoveListener.js +3 -0
- package/dist/esm/eventListeners/segmentation/imageChangeEventListener.js +60 -92
- package/dist/esm/eventListeners/segmentation/labelmap/onLabelmapSegmentationDataModified.js +49 -21
- package/dist/esm/eventListeners/segmentation/labelmap/performStackLabelmapUpdate.js +7 -13
- package/dist/esm/eventListeners/segmentation/labelmap/performVolumeLabelmapUpdate.js +44 -18
- package/dist/esm/eventListeners/touch/getTouchEventPoints.js +27 -4
- package/dist/esm/eventListeners/touch/touchStartListener.js +27 -9
- package/dist/esm/eventListeners/wheel/wheelListener.js +5 -1
- package/dist/esm/index.d.ts +2 -2
- package/dist/esm/index.js +2 -2
- package/dist/esm/init.js +2 -0
- package/dist/esm/stateManagement/annotation/FrameOfReferenceSpecificAnnotationManager.js +10 -4
- package/dist/esm/stateManagement/segmentation/SegmentationRenderingEngine.js +23 -20
- package/dist/esm/stateManagement/segmentation/SegmentationRepresentationDisplayRegistry.d.ts +12 -0
- package/dist/esm/stateManagement/segmentation/SegmentationRepresentationDisplayRegistry.js +7 -0
- package/dist/esm/stateManagement/segmentation/SegmentationStateManager.d.ts +1 -10
- package/dist/esm/stateManagement/segmentation/SegmentationStateManager.js +28 -149
- package/dist/esm/stateManagement/segmentation/addColorLUT.js +7 -1
- package/dist/esm/stateManagement/segmentation/getCurrentLabelmapImageIdForViewport.js +16 -1
- package/dist/esm/stateManagement/segmentation/helpers/clearSegmentValue.js +9 -7
- package/dist/esm/stateManagement/segmentation/helpers/getSegmentationActor.d.ts +1 -1
- package/dist/esm/stateManagement/segmentation/helpers/getSegmentationActor.js +3 -2
- package/dist/esm/stateManagement/segmentation/helpers/getViewportLabelmapRenderMode.d.ts +5 -0
- package/dist/esm/stateManagement/segmentation/helpers/getViewportLabelmapRenderMode.js +58 -0
- package/dist/esm/stateManagement/segmentation/helpers/labelmapImageMapperSupport.d.ts +52 -0
- package/dist/esm/stateManagement/segmentation/helpers/labelmapImageMapperSupport.js +246 -0
- package/dist/esm/stateManagement/segmentation/helpers/labelmapSegmentationState.d.ts +1 -0
- package/dist/esm/stateManagement/segmentation/helpers/labelmapSegmentationState.js +1 -0
- package/dist/esm/stateManagement/segmentation/helpers/normalizeSegmentationInput.js +12 -1
- package/dist/esm/stateManagement/segmentation/internalAddSegmentationRepresentation.js +3 -3
- package/dist/esm/stateManagement/segmentation/labelmapModel/index.d.ts +9 -0
- package/dist/esm/stateManagement/segmentation/labelmapModel/index.js +7 -0
- package/dist/esm/stateManagement/segmentation/labelmapModel/labelmapEditTransaction.d.ts +54 -0
- package/dist/esm/stateManagement/segmentation/labelmapModel/labelmapEditTransaction.js +224 -0
- package/dist/esm/stateManagement/segmentation/labelmapModel/labelmapImageIdMapping.d.ts +6 -0
- package/dist/esm/stateManagement/segmentation/labelmapModel/labelmapImageIdMapping.js +39 -0
- package/dist/esm/stateManagement/segmentation/labelmapModel/labelmapImageReferenceResolver.d.ts +23 -0
- package/dist/esm/stateManagement/segmentation/labelmapModel/labelmapImageReferenceResolver.js +269 -0
- package/dist/esm/stateManagement/segmentation/labelmapModel/labelmapLayerStore.d.ts +15 -0
- package/dist/esm/stateManagement/segmentation/labelmapModel/labelmapLayerStore.js +160 -0
- package/dist/esm/stateManagement/segmentation/labelmapModel/labelmapLegacyAdapter.d.ts +4 -0
- package/dist/esm/stateManagement/segmentation/labelmapModel/labelmapLegacyAdapter.js +42 -0
- package/dist/esm/stateManagement/segmentation/labelmapModel/labelmapSegmentBindings.d.ts +11 -0
- package/dist/esm/stateManagement/segmentation/labelmapModel/labelmapSegmentBindings.js +73 -0
- package/dist/esm/stateManagement/segmentation/labelmapModel/normalizeLabelmapSegmentationData.d.ts +17 -0
- package/dist/esm/stateManagement/segmentation/labelmapModel/normalizeLabelmapSegmentationData.js +75 -0
- package/dist/esm/stateManagement/segmentation/labelmapModel/privateLabelmap.d.ts +5 -0
- package/dist/esm/stateManagement/segmentation/labelmapModel/privateLabelmap.js +106 -0
- package/dist/esm/stateManagement/segmentation/models/SegmentModel.d.ts +11 -0
- package/dist/esm/stateManagement/segmentation/models/SegmentModel.js +19 -0
- package/dist/esm/stateManagement/segmentation/models/SegmentationModel.d.ts +12 -0
- package/dist/esm/stateManagement/segmentation/models/SegmentationModel.js +23 -0
- package/dist/esm/stateManagement/segmentation/removeSegmentationRepresentations.js +6 -10
- package/dist/esm/stateManagement/segmentation/segmentIndex.js +24 -0
- package/dist/esm/stateManagement/segmentation/segmentationEventManager.js +2 -9
- package/dist/esm/stateManagement/segmentation/segmentationState.d.ts +2 -1
- package/dist/esm/stateManagement/segmentation/segmentationState.js +4 -1
- package/dist/esm/store/SynchronizerManager/Synchronizer.d.ts +3 -1
- package/dist/esm/store/state.js +2 -1
- package/dist/esm/synchronizers/callbacks/imageSliceSyncCallback.js +12 -3
- package/dist/esm/synchronizers/callbacks/presentationViewSyncCallback.js +5 -2
- package/dist/esm/synchronizers/callbacks/zoomPanSyncCallback.js +51 -3
- package/dist/esm/synchronizers/synchronizers/createPresentationViewSynchronizer.d.ts +1 -1
- package/dist/esm/tools/AdvancedMagnifyTool.js +4 -1
- package/dist/esm/tools/CrosshairsTool.d.ts +4 -0
- package/dist/esm/tools/CrosshairsTool.js +95 -41
- package/dist/esm/tools/MagnifyTool.js +3 -1
- package/dist/esm/tools/OrientationControllerTool.d.ts +45 -0
- package/dist/esm/tools/OrientationControllerTool.js +454 -0
- package/dist/esm/tools/OrientationMarkerTool.js +4 -4
- package/dist/esm/tools/PanTool.js +26 -3
- package/dist/esm/tools/PlanarRotateTool.js +19 -4
- package/dist/esm/tools/ReferenceCursors.js +7 -1
- package/dist/esm/tools/SculptorTool/CircleSculptCursor.js +1 -1
- package/dist/esm/tools/TrackballRotateTool.js +3 -2
- package/dist/esm/tools/VolumeCroppingControlTool.d.ts +10 -35
- package/dist/esm/tools/VolumeCroppingControlTool.js +179 -699
- package/dist/esm/tools/VolumeCroppingTool.d.ts +34 -32
- package/dist/esm/tools/VolumeCroppingTool.js +813 -532
- package/dist/esm/tools/WindowLevelTool.d.ts +2 -1
- package/dist/esm/tools/WindowLevelTool.js +48 -4
- package/dist/esm/tools/ZoomTool.d.ts +8 -0
- package/dist/esm/tools/ZoomTool.js +92 -11
- package/dist/esm/tools/annotation/AngleTool.js +38 -32
- package/dist/esm/tools/annotation/ArrowAnnotateTool.js +30 -28
- package/dist/esm/tools/annotation/BidirectionalTool.js +51 -49
- package/dist/esm/tools/annotation/CircleROITool.d.ts +1 -0
- package/dist/esm/tools/annotation/CircleROITool.js +89 -51
- package/dist/esm/tools/annotation/CobbAngleTool.js +1 -1
- package/dist/esm/tools/annotation/DragProbeTool.js +1 -1
- package/dist/esm/tools/annotation/ETDRSGridTool.js +1 -1
- package/dist/esm/tools/annotation/EllipticalROITool.js +46 -39
- package/dist/esm/tools/annotation/HeightTool.js +1 -1
- package/dist/esm/tools/annotation/KeyImageTool.js +11 -11
- package/dist/esm/tools/annotation/LabelTool.js +37 -35
- package/dist/esm/tools/annotation/LengthTool.js +35 -33
- package/dist/esm/tools/annotation/LivewireContourSegmentationTool.js +6 -4
- package/dist/esm/tools/annotation/LivewireContourTool.js +4 -8
- package/dist/esm/tools/annotation/PlanarFreehandContourSegmentationTool.js +6 -4
- package/dist/esm/tools/annotation/PlanarFreehandROITool.js +3 -4
- package/dist/esm/tools/annotation/ProbeTool.js +66 -56
- package/dist/esm/tools/annotation/RectangleROITool.js +48 -37
- package/dist/esm/tools/annotation/RegionSegmentPlusTool.js +1 -1
- package/dist/esm/tools/annotation/RegionSegmentTool.js +1 -1
- package/dist/esm/tools/annotation/SplineContourSegmentationTool.js +1 -1
- package/dist/esm/tools/annotation/SplineROITool.js +60 -56
- package/dist/esm/tools/annotation/UltrasoundDirectionalTool.js +1 -1
- package/dist/esm/tools/annotation/UltrasoundPleuraBLineTool/UltrasoundPleuraBLineTool.js +57 -55
- package/dist/esm/tools/annotation/VideoRedactionTool.js +1 -1
- package/dist/esm/tools/base/AnnotationDisplayTool.js +9 -6
- package/dist/esm/tools/base/AnnotationTool.js +2 -1
- package/dist/esm/tools/base/BaseTool.js +16 -10
- package/dist/esm/tools/base/ContourSegmentationBaseTool.js +1 -1
- package/dist/esm/tools/base/GrowCutBaseTool.js +2 -2
- package/dist/esm/tools/displayTools/Labelmap/addLabelmapToElement.d.ts +2 -4
- package/dist/esm/tools/displayTools/Labelmap/addLabelmapToElement.js +15 -85
- package/dist/esm/tools/displayTools/Labelmap/labelmapActorStyle.d.ts +5 -0
- package/dist/esm/tools/displayTools/Labelmap/labelmapActorStyle.js +191 -0
- package/dist/esm/tools/displayTools/Labelmap/labelmapDisplay.d.ts +4 -3
- package/dist/esm/tools/displayTools/Labelmap/labelmapDisplay.js +48 -209
- package/dist/esm/tools/displayTools/Labelmap/labelmapRenderPlan/createLabelmapRenderPlan.d.ts +3 -0
- package/dist/esm/tools/displayTools/Labelmap/labelmapRenderPlan/createLabelmapRenderPlan.js +51 -0
- package/dist/esm/tools/displayTools/Labelmap/labelmapRenderPlan/index.d.ts +4 -0
- package/dist/esm/tools/displayTools/Labelmap/labelmapRenderPlan/index.js +3 -0
- package/dist/esm/tools/displayTools/Labelmap/labelmapRenderPlan/legacyVolumePlan.d.ts +14 -0
- package/dist/esm/tools/displayTools/Labelmap/labelmapRenderPlan/legacyVolumePlan.js +143 -0
- package/dist/esm/tools/displayTools/Labelmap/labelmapRenderPlan/planarGenericVolumeLabelmap.d.ts +40 -0
- package/dist/esm/tools/displayTools/Labelmap/labelmapRenderPlan/planarGenericVolumeLabelmap.js +79 -0
- package/dist/esm/tools/displayTools/Labelmap/labelmapRenderPlan/removeLabelmapRepresentationFromViewport.d.ts +3 -0
- package/dist/esm/tools/displayTools/Labelmap/labelmapRenderPlan/removeLabelmapRepresentationFromViewport.js +18 -0
- package/dist/esm/tools/displayTools/Labelmap/labelmapRenderPlan/resolveLabelmapRenderPlan.d.ts +9 -0
- package/dist/esm/tools/displayTools/Labelmap/labelmapRenderPlan/resolveLabelmapRenderPlan.js +56 -0
- package/dist/esm/tools/displayTools/Labelmap/labelmapRenderPlan/stackImagePlan.d.ts +11 -0
- package/dist/esm/tools/displayTools/Labelmap/labelmapRenderPlan/stackImagePlan.js +35 -0
- package/dist/esm/tools/displayTools/Labelmap/labelmapRenderPlan/types.d.ts +48 -0
- package/dist/esm/tools/displayTools/Labelmap/labelmapRenderPlan/types.js +0 -0
- package/dist/esm/tools/displayTools/Labelmap/labelmapRenderPlan/volumeSliceImageMapperPlan.d.ts +13 -0
- package/dist/esm/tools/displayTools/Labelmap/labelmapRenderPlan/volumeSliceImageMapperPlan.js +34 -0
- package/dist/esm/tools/displayTools/Labelmap/labelmapRenderPlan.d.ts +2 -0
- package/dist/esm/tools/displayTools/Labelmap/labelmapRenderPlan.js +1 -0
- package/dist/esm/tools/displayTools/Labelmap/labelmapRepresentationUID.d.ts +8 -0
- package/dist/esm/tools/displayTools/Labelmap/labelmapRepresentationUID.js +18 -0
- package/dist/esm/tools/displayTools/Labelmap/removeLabelmapFromElement.js +2 -2
- package/dist/esm/tools/displayTools/Labelmap/removeLabelmapRepresentationData.d.ts +3 -0
- package/dist/esm/tools/displayTools/Labelmap/removeLabelmapRepresentationData.js +16 -0
- package/dist/esm/tools/displayTools/Labelmap/syncStackLabelmapActors.d.ts +2 -0
- package/dist/esm/tools/displayTools/Labelmap/syncStackLabelmapActors.js +135 -0
- package/dist/esm/tools/displayTools/Labelmap/volumeLabelmapImageMapper.d.ts +16 -0
- package/dist/esm/tools/displayTools/Labelmap/volumeLabelmapImageMapper.js +267 -0
- package/dist/esm/tools/displayTools/Labelmap/volumeLabelmapSliceData.d.ts +27 -0
- package/dist/esm/tools/displayTools/Labelmap/volumeLabelmapSliceData.js +185 -0
- package/dist/esm/tools/displayTools/registerBuiltInSegmentationRepresentationDisplays.d.ts +1 -0
- package/dist/esm/tools/displayTools/registerBuiltInSegmentationRepresentationDisplays.js +16 -0
- package/dist/esm/tools/index.d.ts +2 -1
- package/dist/esm/tools/index.js +2 -1
- package/dist/esm/tools/segmentation/BrushTool.d.ts +9 -2
- package/dist/esm/tools/segmentation/BrushTool.js +123 -26
- package/dist/esm/tools/segmentation/CircleScissorsTool.js +19 -36
- package/dist/esm/tools/segmentation/LabelmapBaseTool.d.ts +2 -3
- package/dist/esm/tools/segmentation/LabelmapBaseTool.js +77 -46
- package/dist/esm/tools/segmentation/LabelmapEditWithContour.js +3 -3
- package/dist/esm/tools/segmentation/PaintFillTool.js +11 -4
- package/dist/esm/tools/segmentation/RectangleROIStartEndThresholdTool.d.ts +2 -0
- package/dist/esm/tools/segmentation/RectangleROIStartEndThresholdTool.js +16 -8
- package/dist/esm/tools/segmentation/RectangleScissorsTool.js +13 -6
- package/dist/esm/tools/segmentation/SegmentBidirectionalTool.js +63 -61
- package/dist/esm/tools/segmentation/SegmentSelectTool.js +4 -4
- package/dist/esm/tools/segmentation/SphereScissorsTool.js +11 -31
- package/dist/esm/tools/segmentation/strategies/BrushStrategy.d.ts +7 -0
- package/dist/esm/tools/segmentation/strategies/BrushStrategy.js +47 -24
- package/dist/esm/tools/segmentation/strategies/compositions/circularCursor.js +49 -21
- package/dist/esm/tools/segmentation/strategies/compositions/determineSegmentIndex.js +2 -2
- package/dist/esm/tools/segmentation/strategies/compositions/dynamicThreshold.js +5 -1
- package/dist/esm/tools/segmentation/strategies/compositions/islandRemovalComposition.js +2 -2
- package/dist/esm/tools/segmentation/strategies/compositions/preview.js +2 -2
- package/dist/esm/tools/segmentation/strategies/compositions/setValue.js +14 -6
- package/dist/esm/tools/segmentation/strategies/fillCircle.d.ts +3 -1
- package/dist/esm/tools/segmentation/strategies/fillCircle.js +38 -31
- package/dist/esm/tools/segmentation/strategies/fillSphere.js +11 -3
- package/dist/esm/tools/segmentation/strategies/utils/crossLayerErase.d.ts +4 -0
- package/dist/esm/tools/segmentation/strategies/utils/crossLayerErase.js +23 -0
- package/dist/esm/tools/segmentation/strategies/utils/getStrategyData.js +1 -1
- package/dist/esm/tools/segmentation/strategies/utils/handleUseSegmentCenterIndex.js +12 -11
- package/dist/esm/tools/segmentation/strategies/utils/labelmapOverlap.d.ts +4 -0
- package/dist/esm/tools/segmentation/strategies/utils/labelmapOverlap.js +41 -0
- package/dist/esm/tools/segmentation/strategies/utils/overwritePolicy.d.ts +3 -0
- package/dist/esm/tools/segmentation/strategies/utils/overwritePolicy.js +31 -0
- package/dist/esm/tools/segmentation/strategies/utils/segmentSeparation.d.ts +3 -0
- package/dist/esm/tools/segmentation/strategies/utils/segmentSeparation.js +38 -0
- package/dist/esm/tools/segmentation/utils/LazyBrushEditController.d.ts +19 -0
- package/dist/esm/tools/segmentation/utils/LazyBrushEditController.js +55 -0
- package/dist/esm/tools/segmentation/utils/lazyBrushPreview.d.ts +3 -0
- package/dist/esm/tools/segmentation/utils/lazyBrushPreview.js +34 -0
- package/dist/esm/tools/segmentation/utils/shouldUseLazyLabelmapEditing.d.ts +3 -0
- package/dist/esm/tools/segmentation/utils/shouldUseLazyLabelmapEditing.js +42 -0
- package/dist/esm/types/ISynchronizerEventHandler.d.ts +2 -1
- package/dist/esm/types/LabelmapToolOperationData.d.ts +5 -0
- package/dist/esm/types/LabelmapTypes.d.ts +29 -6
- package/dist/esm/types/SegmentationStateTypes.d.ts +6 -0
- package/dist/esm/utilities/calibrateImageSpacing.js +17 -2
- package/dist/esm/utilities/contours/AnnotationToPointData.js +1 -1
- package/dist/esm/utilities/draw3D/addLine3DBetweenPoints.d.ts +7 -0
- package/dist/esm/utilities/draw3D/addLine3DBetweenPoints.js +34 -0
- package/dist/esm/utilities/draw3D/calculateAdaptiveSphereRadius.d.ts +6 -0
- package/dist/esm/utilities/draw3D/calculateAdaptiveSphereRadius.js +7 -0
- package/dist/esm/utilities/draw3D/index.d.ts +2 -0
- package/dist/esm/utilities/draw3D/index.js +2 -0
- package/dist/esm/utilities/drawing/getTextBoxCoordsCanvas.js +22 -14
- package/dist/esm/utilities/getCenterAndRadiusInCanvas.d.ts +6 -0
- package/dist/esm/utilities/getCenterAndRadiusInCanvas.js +26 -0
- package/dist/esm/utilities/getEllipseWorldCoordinates.d.ts +2 -0
- package/dist/esm/utilities/getEllipseWorldCoordinates.js +26 -0
- package/dist/esm/utilities/getSphereBoundsInfo.js +5 -1
- package/dist/esm/utilities/getViewportICamera.d.ts +4 -0
- package/dist/esm/utilities/getViewportICamera.js +23 -0
- package/dist/esm/utilities/getViewportsForAnnotation.js +5 -1
- package/dist/esm/utilities/index.d.ts +2 -1
- package/dist/esm/utilities/index.js +2 -1
- package/dist/esm/utilities/interactionDragCoordinator.d.ts +5 -0
- package/dist/esm/utilities/interactionDragCoordinator.js +16 -0
- package/dist/esm/utilities/math/basic/BasicStatsCalculator.js +9 -7
- package/dist/esm/utilities/pointInSurroundingSphereCallback.js +8 -1
- package/dist/esm/utilities/segmentation/InterpolationManager/InterpolationManager.js +121 -118
- package/dist/esm/utilities/segmentation/SegmentStatsCalculator.js +5 -4
- package/dist/esm/utilities/segmentation/VolumetricCalculator.js +1 -1
- package/dist/esm/utilities/segmentation/createLabelmapVolumeForViewport.js +1 -1
- package/dist/esm/utilities/segmentation/getReferenceVolumeForSegmentation.js +1 -1
- package/dist/esm/utilities/segmentation/getReferenceVolumeForSegmentationVolume.js +11 -2
- package/dist/esm/utilities/segmentation/getSegmentIndexAtLabelmapBorder.js +36 -17
- package/dist/esm/utilities/segmentation/getSegmentIndexAtWorldPoint.js +42 -25
- package/dist/esm/utilities/segmentation/getUniqueSegmentIndices.js +3 -30
- package/dist/esm/utilities/segmentation/index.d.ts +2 -1
- package/dist/esm/utilities/segmentation/index.js +2 -1
- package/dist/esm/utilities/segmentation/utilsForWorker.js +6 -2
- package/dist/esm/utilities/segmentation/validateLabelmap.js +1 -1
- package/dist/esm/utilities/stackPrefetch/stackPrefetch.js +0 -1
- package/dist/esm/utilities/touch/index.js +3 -2
- package/dist/esm/utilities/viewportCapabilities.d.ts +16 -0
- package/dist/esm/utilities/viewportCapabilities.js +18 -0
- package/dist/esm/utilities/viewportFilters/filterViewportsWithParallelNormals.d.ts +1 -1
- package/dist/esm/utilities/viewportFilters/filterViewportsWithParallelNormals.js +12 -4
- package/dist/esm/utilities/viewportFilters/filterViewportsWithSameOrientation.d.ts +1 -1
- package/dist/esm/utilities/viewportFilters/filterViewportsWithSameOrientation.js +11 -4
- package/dist/esm/utilities/viewportFilters/getViewportIdsWithToolToRender.js +1 -1
- package/dist/esm/utilities/viewportPresentation.d.ts +3 -0
- package/dist/esm/utilities/viewportPresentation.js +26 -0
- package/dist/esm/utilities/volumeCropping/computePlanePlaneIntersection.d.ts +6 -0
- package/dist/esm/utilities/volumeCropping/computePlanePlaneIntersection.js +37 -0
- package/dist/esm/utilities/volumeCropping/constants.d.ts +31 -0
- package/dist/esm/utilities/volumeCropping/constants.js +31 -0
- package/dist/esm/utilities/volumeCropping/copyClippingPlanes.d.ts +2 -0
- package/dist/esm/utilities/volumeCropping/copyClippingPlanes.js +6 -0
- package/dist/esm/utilities/volumeCropping/extractVolumeDirectionVectors.d.ts +9 -0
- package/dist/esm/utilities/volumeCropping/extractVolumeDirectionVectors.js +9 -0
- package/dist/esm/utilities/volumeCropping/findLineBoundsIntersection.d.ts +5 -0
- package/dist/esm/utilities/volumeCropping/findLineBoundsIntersection.js +50 -0
- package/dist/esm/utilities/volumeCropping/getColorKeyForPlaneIndex.d.ts +1 -0
- package/dist/esm/utilities/volumeCropping/getColorKeyForPlaneIndex.js +13 -0
- package/dist/esm/utilities/volumeCropping/getOrientationFromNormal.d.ts +2 -0
- package/dist/esm/utilities/volumeCropping/getOrientationFromNormal.js +19 -0
- package/dist/esm/utilities/volumeCropping/index.d.ts +9 -0
- package/dist/esm/utilities/volumeCropping/index.js +9 -0
- package/dist/esm/utilities/volumeCropping/parseCornerKey.d.ts +8 -0
- package/dist/esm/utilities/volumeCropping/parseCornerKey.js +11 -0
- package/dist/esm/utilities/volumeCropping/types.d.ts +5 -0
- package/dist/esm/utilities/volumeCropping/types.js +0 -0
- package/dist/esm/utilities/vtkjs/AnnotatedRhombicuboctahedronActor/index.d.ts +31 -0
- package/dist/esm/utilities/vtkjs/AnnotatedRhombicuboctahedronActor/index.js +391 -0
- package/dist/esm/utilities/vtkjs/OrientationControllerWidget/index.d.ts +69 -0
- package/dist/esm/utilities/vtkjs/OrientationControllerWidget/index.js +804 -0
- package/dist/esm/utilities/vtkjs/RhombicuboctahedronSource/index.d.ts +7 -0
- package/dist/esm/utilities/vtkjs/RhombicuboctahedronSource/index.js +144 -0
- package/dist/esm/utilities/vtkjs/index.d.ts +3 -0
- package/dist/esm/utilities/vtkjs/index.js +3 -0
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/package.json +10 -9
package/dist/esm/stateManagement/segmentation/labelmapModel/labelmapImageReferenceResolver.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { RepresentationsData, Segmentation } from '../../../types/SegmentationStateTypes';
|
|
2
|
+
type GetSegmentation = (segmentationId: string) => Segmentation | undefined;
|
|
3
|
+
declare class LabelmapImageReferenceResolver {
|
|
4
|
+
private readonly getSegmentation;
|
|
5
|
+
private readonly stackLabelmapImageIdReferenceMap;
|
|
6
|
+
private readonly labelmapImageIdReferenceMap;
|
|
7
|
+
private readonly keysBySegmentationId;
|
|
8
|
+
constructor(getSegmentation: GetSegmentation);
|
|
9
|
+
reset(): void;
|
|
10
|
+
removeSegmentation(segmentationId: string): void;
|
|
11
|
+
private setLabelmapImageIds;
|
|
12
|
+
getLabelmapImageIds(representationData: RepresentationsData): any;
|
|
13
|
+
getLabelmapImageIdsForImageId(imageId: string, segmentationId: string): string[];
|
|
14
|
+
updateLabelmapSegmentationImageReferences(viewportId: string, segmentationId: string): string | undefined;
|
|
15
|
+
getCurrentLabelmapImageIdsForViewport(viewportId: string, segmentationId: string): string[] | undefined;
|
|
16
|
+
getCurrentLabelmapImageIdForViewport(viewportId: string, segmentationId: string): string | undefined;
|
|
17
|
+
getStackSegmentationImageIdsForViewport(viewportId: string, segmentationId: string): string[];
|
|
18
|
+
private updateLabelmapSegmentationReferences;
|
|
19
|
+
private updateAllLabelmapSegmentationImageReferences;
|
|
20
|
+
private updateLabelmapImageIdReferenceMap;
|
|
21
|
+
private generateMapKey;
|
|
22
|
+
}
|
|
23
|
+
export default LabelmapImageReferenceResolver;
|
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
import { cache, getEnabledElementByViewportId, } from '@cornerstonejs/core';
|
|
2
|
+
import getViewportLabelmapRenderMode from '../helpers/getViewportLabelmapRenderMode';
|
|
3
|
+
import { ensureLabelmapState } from './normalizeLabelmapSegmentationData';
|
|
4
|
+
import { getLabelmaps } from './labelmapLayerStore';
|
|
5
|
+
import { getLabelmapForSegment } from './labelmapSegmentBindings';
|
|
6
|
+
import { getReferencedImageIdToCurrentImageIdMap } from './labelmapLegacyAdapter';
|
|
7
|
+
import { getLabelmapImageIdsForReferencedImageId } from './labelmapImageIdMapping';
|
|
8
|
+
class LabelmapImageReferenceResolver {
|
|
9
|
+
constructor(getSegmentation) {
|
|
10
|
+
this.stackLabelmapImageIdReferenceMap = new Map();
|
|
11
|
+
this.labelmapImageIdReferenceMap = new Map();
|
|
12
|
+
this.keysBySegmentationId = new Map();
|
|
13
|
+
this.getSegmentation = getSegmentation;
|
|
14
|
+
}
|
|
15
|
+
reset() {
|
|
16
|
+
this.stackLabelmapImageIdReferenceMap.clear();
|
|
17
|
+
this.labelmapImageIdReferenceMap.clear();
|
|
18
|
+
this.keysBySegmentationId.clear();
|
|
19
|
+
}
|
|
20
|
+
removeSegmentation(segmentationId) {
|
|
21
|
+
this.stackLabelmapImageIdReferenceMap.delete(segmentationId);
|
|
22
|
+
const keys = this.keysBySegmentationId.get(segmentationId);
|
|
23
|
+
if (keys) {
|
|
24
|
+
for (const key of keys) {
|
|
25
|
+
this.labelmapImageIdReferenceMap.delete(key);
|
|
26
|
+
}
|
|
27
|
+
this.keysBySegmentationId.delete(segmentationId);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
setLabelmapImageIds(segmentationId, key, labelmapImageIds) {
|
|
31
|
+
this.labelmapImageIdReferenceMap.set(key, labelmapImageIds);
|
|
32
|
+
let keys = this.keysBySegmentationId.get(segmentationId);
|
|
33
|
+
if (!keys) {
|
|
34
|
+
keys = new Set();
|
|
35
|
+
this.keysBySegmentationId.set(segmentationId, keys);
|
|
36
|
+
}
|
|
37
|
+
keys.add(key);
|
|
38
|
+
}
|
|
39
|
+
getLabelmapImageIds(representationData) {
|
|
40
|
+
const labelmapData = representationData.Labelmap;
|
|
41
|
+
let labelmapImageIds;
|
|
42
|
+
if (!labelmapData) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
if (labelmapData?.labelmaps) {
|
|
46
|
+
const imageIds = Object.values(labelmapData.labelmaps).flatMap((layer) => {
|
|
47
|
+
if (layer.imageIds?.length) {
|
|
48
|
+
return layer.imageIds;
|
|
49
|
+
}
|
|
50
|
+
if (layer.volumeId) {
|
|
51
|
+
return cache.getVolume(layer.volumeId)
|
|
52
|
+
?.imageIds;
|
|
53
|
+
}
|
|
54
|
+
return [];
|
|
55
|
+
});
|
|
56
|
+
return Array.from(new Set(imageIds.filter(Boolean)));
|
|
57
|
+
}
|
|
58
|
+
if (labelmapData.imageIds) {
|
|
59
|
+
labelmapImageIds = labelmapData
|
|
60
|
+
.imageIds;
|
|
61
|
+
}
|
|
62
|
+
else if (labelmapData.volumeId) {
|
|
63
|
+
const volumeId = labelmapData
|
|
64
|
+
.volumeId;
|
|
65
|
+
const volume = cache.getVolume(volumeId);
|
|
66
|
+
labelmapImageIds = volume.imageIds;
|
|
67
|
+
}
|
|
68
|
+
return labelmapImageIds;
|
|
69
|
+
}
|
|
70
|
+
getLabelmapImageIdsForImageId(imageId, segmentationId) {
|
|
71
|
+
const segmentation = this.getSegmentation(segmentationId);
|
|
72
|
+
if (!segmentation?.representationData?.Labelmap) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
ensureLabelmapState(segmentation);
|
|
76
|
+
return getReferencedImageIdToCurrentImageIdMap(segmentation).get(imageId);
|
|
77
|
+
}
|
|
78
|
+
updateLabelmapSegmentationImageReferences(viewportId, segmentationId) {
|
|
79
|
+
const segmentation = this.getSegmentation(segmentationId);
|
|
80
|
+
if (!segmentation) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
if (!this.stackLabelmapImageIdReferenceMap.has(segmentationId)) {
|
|
84
|
+
this.stackLabelmapImageIdReferenceMap.set(segmentationId, new Map());
|
|
85
|
+
}
|
|
86
|
+
const { representationData } = segmentation;
|
|
87
|
+
if (!representationData.Labelmap) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
const labelmapImageIds = this.getLabelmapImageIds(representationData);
|
|
91
|
+
const enabledElement = getEnabledElementByViewportId(viewportId);
|
|
92
|
+
if (!enabledElement || !labelmapImageIds?.length) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
return this.updateLabelmapSegmentationReferences(segmentationId, enabledElement.viewport, labelmapImageIds);
|
|
96
|
+
}
|
|
97
|
+
getCurrentLabelmapImageIdsForViewport(viewportId, segmentationId) {
|
|
98
|
+
const enabledElement = getEnabledElementByViewportId(viewportId);
|
|
99
|
+
if (!enabledElement) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
const { viewport } = enabledElement;
|
|
103
|
+
const viewportRenderMode = getViewportLabelmapRenderMode(viewport);
|
|
104
|
+
if (viewportRenderMode !== 'image' ||
|
|
105
|
+
typeof viewport.getCurrentImageId !== 'function') {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
const referenceImageId = viewport.getCurrentImageId();
|
|
109
|
+
const segmentation = this.getSegmentation(segmentationId);
|
|
110
|
+
if (!segmentation) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
ensureLabelmapState(segmentation);
|
|
114
|
+
const viewportImageIds = viewport.getImageIds();
|
|
115
|
+
const currentIndex = viewportImageIds.indexOf(referenceImageId);
|
|
116
|
+
const labelmapImageIds = [];
|
|
117
|
+
getLabelmaps(segmentation).forEach((layer) => {
|
|
118
|
+
const referencedLabelmapImageIds = getLabelmapImageIdsForReferencedImageId(layer, referenceImageId);
|
|
119
|
+
if (referencedLabelmapImageIds.length) {
|
|
120
|
+
labelmapImageIds.push(...referencedLabelmapImageIds);
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
if (currentIndex !== -1 && layer.imageIds?.[currentIndex]) {
|
|
124
|
+
labelmapImageIds.push(layer.imageIds[currentIndex]);
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
layer.imageIds?.some((candidateImageId) => {
|
|
128
|
+
const viewableImageId = viewport.isReferenceViewable({ referencedImageId: candidateImageId }, { asOverlay: true });
|
|
129
|
+
if (viewableImageId) {
|
|
130
|
+
labelmapImageIds.push(candidateImageId);
|
|
131
|
+
}
|
|
132
|
+
return !!viewableImageId;
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
const resolvedImageIds = Array.from(new Set(labelmapImageIds));
|
|
136
|
+
const key = this.generateMapKey({
|
|
137
|
+
segmentationId,
|
|
138
|
+
referenceImageId,
|
|
139
|
+
});
|
|
140
|
+
this.setLabelmapImageIds(segmentationId, key, resolvedImageIds);
|
|
141
|
+
if (!this.stackLabelmapImageIdReferenceMap.has(segmentationId)) {
|
|
142
|
+
this.stackLabelmapImageIdReferenceMap.set(segmentationId, new Map());
|
|
143
|
+
}
|
|
144
|
+
const activeSegmentIndex = Object.keys(segmentation.segments).find((segmentIndex) => segmentation.segments[segmentIndex].active);
|
|
145
|
+
const activeImageId = activeSegmentIndex
|
|
146
|
+
? getLabelmapForSegment(segmentation, Number(activeSegmentIndex))
|
|
147
|
+
?.imageIds?.[currentIndex]
|
|
148
|
+
: undefined;
|
|
149
|
+
this.stackLabelmapImageIdReferenceMap
|
|
150
|
+
.get(segmentationId)
|
|
151
|
+
.set(referenceImageId, activeImageId ?? resolvedImageIds[0]);
|
|
152
|
+
return resolvedImageIds;
|
|
153
|
+
}
|
|
154
|
+
getCurrentLabelmapImageIdForViewport(viewportId, segmentationId) {
|
|
155
|
+
const enabledElement = getEnabledElementByViewportId(viewportId);
|
|
156
|
+
if (!enabledElement) {
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
const { viewport } = enabledElement;
|
|
160
|
+
const viewportRenderMode = getViewportLabelmapRenderMode(viewport);
|
|
161
|
+
if (viewportRenderMode !== 'image' ||
|
|
162
|
+
typeof viewport.getCurrentImageId !== 'function') {
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
const currentImageId = viewport.getCurrentImageId();
|
|
166
|
+
const currentImageIds = this.getCurrentLabelmapImageIdsForViewport(viewportId, segmentationId);
|
|
167
|
+
if (!currentImageIds?.length) {
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
const segmentation = this.getSegmentation(segmentationId);
|
|
171
|
+
const currentIndex = viewport
|
|
172
|
+
.getImageIds()
|
|
173
|
+
.indexOf(currentImageId);
|
|
174
|
+
const activeSegmentIndex = segmentation
|
|
175
|
+
? Object.keys(segmentation.segments).find((segmentIndex) => segmentation.segments[segmentIndex].active)
|
|
176
|
+
: undefined;
|
|
177
|
+
const activeImageId = segmentation && activeSegmentIndex
|
|
178
|
+
? getLabelmapForSegment(segmentation, Number(activeSegmentIndex))
|
|
179
|
+
?.imageIds?.[currentIndex]
|
|
180
|
+
: undefined;
|
|
181
|
+
return activeImageId ?? currentImageIds[0];
|
|
182
|
+
}
|
|
183
|
+
getStackSegmentationImageIdsForViewport(viewportId, segmentationId) {
|
|
184
|
+
const segmentation = this.getSegmentation(segmentationId);
|
|
185
|
+
if (!segmentation) {
|
|
186
|
+
return [];
|
|
187
|
+
}
|
|
188
|
+
this.updateAllLabelmapSegmentationImageReferences(viewportId, segmentationId);
|
|
189
|
+
const enabledElement = getEnabledElementByViewportId(viewportId);
|
|
190
|
+
const imageIds = enabledElement?.viewport.getImageIds?.() ?? [];
|
|
191
|
+
const imageIdMap = getReferencedImageIdToCurrentImageIdMap(segmentation);
|
|
192
|
+
return imageIds.flatMap((imageId) => imageIdMap.get(imageId) ?? []);
|
|
193
|
+
}
|
|
194
|
+
updateLabelmapSegmentationReferences(segmentationId, viewport, labelmapImageIds, updateCallback) {
|
|
195
|
+
const referenceImageId = viewport.getCurrentImageId();
|
|
196
|
+
let viewableLabelmapImageIdFound = false;
|
|
197
|
+
for (const labelmapImageId of labelmapImageIds) {
|
|
198
|
+
const viewableImageId = viewport.isReferenceViewable({ referencedImageId: labelmapImageId }, { asOverlay: true });
|
|
199
|
+
if (viewableImageId) {
|
|
200
|
+
viewableLabelmapImageIdFound = true;
|
|
201
|
+
this.stackLabelmapImageIdReferenceMap
|
|
202
|
+
.get(segmentationId)
|
|
203
|
+
.set(referenceImageId, labelmapImageId);
|
|
204
|
+
this.updateLabelmapImageIdReferenceMap({
|
|
205
|
+
segmentationId,
|
|
206
|
+
referenceImageId,
|
|
207
|
+
labelmapImageId,
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
updateCallback?.(viewport, segmentationId, labelmapImageIds);
|
|
212
|
+
return viewableLabelmapImageIdFound
|
|
213
|
+
? this.stackLabelmapImageIdReferenceMap
|
|
214
|
+
.get(segmentationId)
|
|
215
|
+
.get(referenceImageId)
|
|
216
|
+
: undefined;
|
|
217
|
+
}
|
|
218
|
+
updateAllLabelmapSegmentationImageReferences(viewportId, segmentationId) {
|
|
219
|
+
const segmentation = this.getSegmentation(segmentationId);
|
|
220
|
+
if (!segmentation) {
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
if (!this.stackLabelmapImageIdReferenceMap.has(segmentationId)) {
|
|
224
|
+
this.stackLabelmapImageIdReferenceMap.set(segmentationId, new Map());
|
|
225
|
+
}
|
|
226
|
+
const { representationData } = segmentation;
|
|
227
|
+
if (!representationData.Labelmap) {
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
const labelmapImageIds = this.getLabelmapImageIds(representationData);
|
|
231
|
+
const enabledElement = getEnabledElementByViewportId(viewportId);
|
|
232
|
+
if (!enabledElement || !labelmapImageIds?.length) {
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
const stackViewport = enabledElement.viewport;
|
|
236
|
+
this.updateLabelmapSegmentationReferences(segmentationId, stackViewport, labelmapImageIds, (stackViewport, segmentationId, labelmapImageIds) => {
|
|
237
|
+
const imageIds = stackViewport.getImageIds();
|
|
238
|
+
imageIds.forEach((referenceImageId, index) => {
|
|
239
|
+
for (const labelmapImageId of labelmapImageIds) {
|
|
240
|
+
const viewableImageId = stackViewport.isReferenceViewable({ referencedImageId: labelmapImageId, sliceIndex: index }, { asOverlay: true, withNavigation: true });
|
|
241
|
+
if (viewableImageId) {
|
|
242
|
+
this.stackLabelmapImageIdReferenceMap
|
|
243
|
+
.get(segmentationId)
|
|
244
|
+
.set(referenceImageId, labelmapImageId);
|
|
245
|
+
this.updateLabelmapImageIdReferenceMap({
|
|
246
|
+
segmentationId,
|
|
247
|
+
referenceImageId,
|
|
248
|
+
labelmapImageId,
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
updateLabelmapImageIdReferenceMap({ segmentationId, referenceImageId, labelmapImageId, }) {
|
|
256
|
+
const key = this.generateMapKey({ segmentationId, referenceImageId });
|
|
257
|
+
if (!this.labelmapImageIdReferenceMap.has(key)) {
|
|
258
|
+
this.setLabelmapImageIds(segmentationId, key, [labelmapImageId]);
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
const currentValues = this.labelmapImageIdReferenceMap.get(key) ?? [];
|
|
262
|
+
const newValues = Array.from(new Set([...currentValues, labelmapImageId]));
|
|
263
|
+
this.setLabelmapImageIds(segmentationId, key, newValues);
|
|
264
|
+
}
|
|
265
|
+
generateMapKey({ segmentationId, referenceImageId }) {
|
|
266
|
+
return `${segmentationId}-${referenceImageId}`;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
export default LabelmapImageReferenceResolver;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Types } from '@cornerstonejs/core';
|
|
2
|
+
import type { Segmentation } from '../../../types/SegmentationStateTypes';
|
|
3
|
+
import type { LabelmapSegmentationData, LabelmapLayer } from '../../../types/LabelmapTypes';
|
|
4
|
+
declare function getLabelmap(segmentation: Segmentation, labelmapId: string): LabelmapLayer | undefined;
|
|
5
|
+
declare function getLabelmaps(segmentation: Segmentation): LabelmapLayer[];
|
|
6
|
+
declare function registerLabelmap(segmentation: Segmentation, layer: LabelmapLayer): void;
|
|
7
|
+
declare function removeLabelmap(segmentation: Segmentation, labelmapId: string): void;
|
|
8
|
+
declare function getOrCreateLabelmapVolume(layer: LabelmapLayer): Types.IImageVolume | undefined;
|
|
9
|
+
declare function getLabelmapIds(segmentation: Segmentation): string[];
|
|
10
|
+
declare function getLabelmapDataById(segmentation: Segmentation, labelmapId: string): LabelmapSegmentationData | undefined;
|
|
11
|
+
declare function getScalarArrayLengthFromLabelmap(layer: LabelmapLayer): number;
|
|
12
|
+
declare function getConstructorNameForLabelmap(layer: LabelmapLayer): string;
|
|
13
|
+
declare function getLabelmapForImageId(segmentation: Segmentation, imageId: string): LabelmapLayer | undefined;
|
|
14
|
+
declare function getLabelmapForVolumeId(segmentation: Segmentation, volumeId: string): LabelmapLayer | undefined;
|
|
15
|
+
export { getConstructorNameForLabelmap, getLabelmap, getLabelmapDataById, getLabelmapForImageId, getLabelmapForVolumeId, getLabelmapIds, getLabelmaps, getOrCreateLabelmapVolume, getScalarArrayLengthFromLabelmap, registerLabelmap, removeLabelmap, };
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { cache, imageLoader, volumeLoader } from '@cornerstonejs/core';
|
|
2
|
+
import { ensureLabelmapState } from './normalizeLabelmapSegmentationData';
|
|
3
|
+
import { forEachLabelmapImageReference, hasMultipleLabelmapImagesPerReferencedImageId, } from './labelmapImageIdMapping';
|
|
4
|
+
function getLabelmap(segmentation, labelmapId) {
|
|
5
|
+
return ensureLabelmapState(segmentation)?.labelmaps?.[labelmapId];
|
|
6
|
+
}
|
|
7
|
+
function getLabelmaps(segmentation) {
|
|
8
|
+
const labelmapState = ensureLabelmapState(segmentation);
|
|
9
|
+
if (!labelmapState) {
|
|
10
|
+
return [];
|
|
11
|
+
}
|
|
12
|
+
return Object.values(labelmapState.labelmaps);
|
|
13
|
+
}
|
|
14
|
+
function registerLabelmap(segmentation, layer) {
|
|
15
|
+
const labelmapState = ensureLabelmapState(segmentation);
|
|
16
|
+
if (!labelmapState) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
labelmapState.labelmaps[layer.labelmapId] = layer;
|
|
20
|
+
}
|
|
21
|
+
function removeLabelmap(segmentation, labelmapId) {
|
|
22
|
+
const labelmapState = ensureLabelmapState(segmentation);
|
|
23
|
+
if (!labelmapState) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const layer = labelmapState.labelmaps[labelmapId];
|
|
27
|
+
if (layer?.geometryVolumeId && cache.getVolume(layer.geometryVolumeId)) {
|
|
28
|
+
cache.removeVolumeLoadObject(layer.geometryVolumeId);
|
|
29
|
+
}
|
|
30
|
+
delete labelmapState.labelmaps[labelmapId];
|
|
31
|
+
}
|
|
32
|
+
function getOrCreateLabelmapVolume(layer) {
|
|
33
|
+
const mergedVolume = getOrCreateMergedStackLabelmapVolume(layer);
|
|
34
|
+
if (mergedVolume) {
|
|
35
|
+
return mergedVolume;
|
|
36
|
+
}
|
|
37
|
+
const existingVolumeId = layer.volumeId ?? layer.geometryVolumeId;
|
|
38
|
+
if (existingVolumeId) {
|
|
39
|
+
const cachedVolume = cache.getVolume(existingVolumeId);
|
|
40
|
+
if (cachedVolume) {
|
|
41
|
+
return cachedVolume;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
const imageIds = layer.imageIds ?? [];
|
|
45
|
+
if (!imageIds.length) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const volumeId = layer.volumeId ?? layer.geometryVolumeId ?? `${layer.labelmapId}-geometry`;
|
|
49
|
+
if (!layer.volumeId) {
|
|
50
|
+
layer.geometryVolumeId = volumeId;
|
|
51
|
+
}
|
|
52
|
+
const cachedVolume = cache.getVolume(volumeId);
|
|
53
|
+
if (cachedVolume) {
|
|
54
|
+
return cachedVolume;
|
|
55
|
+
}
|
|
56
|
+
return volumeLoader.createAndCacheVolumeFromImagesSync(volumeId, imageIds);
|
|
57
|
+
}
|
|
58
|
+
function getOrCreateMergedStackLabelmapVolume(layer) {
|
|
59
|
+
if (layer.volumeId || !hasDuplicateReferencedImageIds(layer)) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
const volumeId = layer.geometryVolumeId ?? `${layer.labelmapId}-geometry`;
|
|
63
|
+
const cachedVolume = cache.getVolume(volumeId);
|
|
64
|
+
if (cachedVolume) {
|
|
65
|
+
return cachedVolume;
|
|
66
|
+
}
|
|
67
|
+
const imageIdsByReferencedImageId = new Map();
|
|
68
|
+
forEachLabelmapImageReference(layer, (referencedImageId, imageId) => {
|
|
69
|
+
const imageIdsForReference = imageIdsByReferencedImageId.get(referencedImageId) ?? [];
|
|
70
|
+
imageIdsForReference.push(imageId);
|
|
71
|
+
imageIdsByReferencedImageId.set(referencedImageId, imageIdsForReference);
|
|
72
|
+
});
|
|
73
|
+
const mergedReferencedImageIds = Array.from(imageIdsByReferencedImageId.keys());
|
|
74
|
+
if (!mergedReferencedImageIds.length) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
let mergedImageIndex = 0;
|
|
78
|
+
const mergedImages = imageLoader.createAndCacheDerivedImages(mergedReferencedImageIds, {
|
|
79
|
+
getDerivedImageId: () => `${volumeId}-image-${mergedImageIndex++}`,
|
|
80
|
+
targetBuffer: { type: 'Uint8Array' },
|
|
81
|
+
});
|
|
82
|
+
mergedImages.forEach((mergedImage) => {
|
|
83
|
+
const sourceImageIds = imageIdsByReferencedImageId.get(mergedImage.referencedImageId);
|
|
84
|
+
if (!sourceImageIds?.length) {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
const targetVoxelManager = mergedImage.voxelManager;
|
|
88
|
+
const scalarDataLength = targetVoxelManager.getScalarDataLength();
|
|
89
|
+
sourceImageIds.forEach((sourceImageId) => {
|
|
90
|
+
const sourceImage = cache.getImage(sourceImageId);
|
|
91
|
+
const sourceVoxelManager = sourceImage?.voxelManager;
|
|
92
|
+
if (!sourceVoxelManager) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
const sourceScalarDataLength = sourceVoxelManager.getScalarDataLength();
|
|
96
|
+
const length = Math.min(scalarDataLength, sourceScalarDataLength);
|
|
97
|
+
for (let index = 0; index < length; index++) {
|
|
98
|
+
const value = Number(sourceVoxelManager.getAtIndex(index));
|
|
99
|
+
if (value !== 0) {
|
|
100
|
+
targetVoxelManager.setAtIndex(index, value);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
layer.geometryVolumeId = volumeId;
|
|
106
|
+
return volumeLoader.createAndCacheVolumeFromImagesSync(volumeId, mergedImages.map((image) => image.imageId));
|
|
107
|
+
}
|
|
108
|
+
function hasDuplicateReferencedImageIds(layer) {
|
|
109
|
+
return hasMultipleLabelmapImagesPerReferencedImageId(layer);
|
|
110
|
+
}
|
|
111
|
+
function getLabelmapIds(segmentation) {
|
|
112
|
+
return getLabelmaps(segmentation).map((layer) => layer.labelmapId);
|
|
113
|
+
}
|
|
114
|
+
function getLabelmapDataById(segmentation, labelmapId) {
|
|
115
|
+
const labelmapState = ensureLabelmapState(segmentation);
|
|
116
|
+
const layer = labelmapState?.labelmaps?.[labelmapId];
|
|
117
|
+
if (!labelmapState || !layer) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
return {
|
|
121
|
+
volumeId: layer.volumeId,
|
|
122
|
+
referencedVolumeId: layer.referencedVolumeId,
|
|
123
|
+
imageIds: layer.imageIds,
|
|
124
|
+
referencedImageIds: layer.referencedImageIds,
|
|
125
|
+
sourceRepresentationName: labelmapState.sourceRepresentationName,
|
|
126
|
+
primaryLabelmapId: labelmapId,
|
|
127
|
+
labelmaps: {
|
|
128
|
+
[labelmapId]: layer,
|
|
129
|
+
},
|
|
130
|
+
segmentBindings: Object.fromEntries(Object.entries(labelmapState.segmentBindings).filter(([, binding]) => binding.labelmapId === labelmapId)),
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
function getScalarArrayLengthFromLabelmap(layer) {
|
|
134
|
+
if (layer.volumeId) {
|
|
135
|
+
return cache.getVolume(layer.volumeId)?.voxelManager?.getScalarDataLength();
|
|
136
|
+
}
|
|
137
|
+
const firstImageId = layer.imageIds?.[0];
|
|
138
|
+
const firstImage = firstImageId ? cache.getImage(firstImageId) : null;
|
|
139
|
+
if (!firstImage || !layer.imageIds?.length) {
|
|
140
|
+
return 0;
|
|
141
|
+
}
|
|
142
|
+
return firstImage.voxelManager.getScalarDataLength() * layer.imageIds.length;
|
|
143
|
+
}
|
|
144
|
+
function getConstructorNameForLabelmap(layer) {
|
|
145
|
+
if (layer.volumeId) {
|
|
146
|
+
return cache.getVolume(layer.volumeId)?.voxelManager?.getConstructor()
|
|
147
|
+
?.name;
|
|
148
|
+
}
|
|
149
|
+
const imageId = layer.imageIds?.[0];
|
|
150
|
+
return imageId
|
|
151
|
+
? cache.getImage(imageId)?.voxelManager?.getConstructor()?.name
|
|
152
|
+
: undefined;
|
|
153
|
+
}
|
|
154
|
+
function getLabelmapForImageId(segmentation, imageId) {
|
|
155
|
+
return getLabelmaps(segmentation).find((layer) => layer.imageIds?.includes(imageId));
|
|
156
|
+
}
|
|
157
|
+
function getLabelmapForVolumeId(segmentation, volumeId) {
|
|
158
|
+
return getLabelmaps(segmentation).find((layer) => layer.volumeId === volumeId || layer.geometryVolumeId === volumeId);
|
|
159
|
+
}
|
|
160
|
+
export { getConstructorNameForLabelmap, getLabelmap, getLabelmapDataById, getLabelmapForImageId, getLabelmapForVolumeId, getLabelmapIds, getLabelmaps, getOrCreateLabelmapVolume, getScalarArrayLengthFromLabelmap, registerLabelmap, removeLabelmap, };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Segmentation } from '../../../types/SegmentationStateTypes';
|
|
2
|
+
declare function syncLegacyLabelmapData(segmentation: Segmentation): void;
|
|
3
|
+
declare function getReferencedImageIdToCurrentImageIdMap(segmentation: Segmentation): Map<string, string[]>;
|
|
4
|
+
export { getReferencedImageIdToCurrentImageIdMap, syncLegacyLabelmapData };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { ensureLabelmapState, getSegmentOrder, } from './normalizeLabelmapSegmentationData';
|
|
2
|
+
import { getLabelmaps } from './labelmapLayerStore';
|
|
3
|
+
import { forEachLabelmapImageReference } from './labelmapImageIdMapping';
|
|
4
|
+
function syncOptionalLegacyProperty(target, key, value) {
|
|
5
|
+
if (value == null) {
|
|
6
|
+
delete target[key];
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
target[key] = value;
|
|
10
|
+
}
|
|
11
|
+
function syncLegacyLabelmapData(segmentation) {
|
|
12
|
+
const labelmapState = ensureLabelmapState(segmentation);
|
|
13
|
+
if (!labelmapState) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
const firstSegmentIndex = getSegmentOrder(segmentation)[0] ?? 1;
|
|
17
|
+
const primaryLabelmapId = labelmapState.primaryLabelmapId ??
|
|
18
|
+
labelmapState.segmentBindings[firstSegmentIndex]?.labelmapId ??
|
|
19
|
+
Object.keys(labelmapState.labelmaps)[0];
|
|
20
|
+
const primaryLayer = labelmapState.labelmaps[primaryLabelmapId];
|
|
21
|
+
if (!primaryLayer) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
syncOptionalLegacyProperty(labelmapState, 'volumeId', primaryLayer.volumeId);
|
|
25
|
+
syncOptionalLegacyProperty(labelmapState, 'referencedVolumeId', primaryLayer.referencedVolumeId);
|
|
26
|
+
syncOptionalLegacyProperty(labelmapState, 'imageIds', primaryLayer.imageIds);
|
|
27
|
+
syncOptionalLegacyProperty(labelmapState, 'referencedImageIds', primaryLayer.referencedImageIds);
|
|
28
|
+
}
|
|
29
|
+
function getReferencedImageIdToCurrentImageIdMap(segmentation) {
|
|
30
|
+
const map = new Map();
|
|
31
|
+
getLabelmaps(segmentation).forEach((layer) => {
|
|
32
|
+
forEachLabelmapImageReference(layer, (referenceImageId, labelmapImageId) => {
|
|
33
|
+
const values = map.get(referenceImageId) ?? [];
|
|
34
|
+
if (!values.includes(labelmapImageId)) {
|
|
35
|
+
values.push(labelmapImageId);
|
|
36
|
+
}
|
|
37
|
+
map.set(referenceImageId, values);
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
return map;
|
|
41
|
+
}
|
|
42
|
+
export { getReferencedImageIdToCurrentImageIdMap, syncLegacyLabelmapData };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Segmentation } from '../../../types/SegmentationStateTypes';
|
|
2
|
+
import type { LabelmapLayer, SegmentLabelmapBindingState } from '../../../types/LabelmapTypes';
|
|
3
|
+
declare function getSegmentBinding(segmentation: Segmentation, segmentIndex: number): SegmentLabelmapBindingState | undefined;
|
|
4
|
+
declare function setSegmentBinding(segmentation: Segmentation, segmentIndex: number, binding: SegmentLabelmapBindingState): void;
|
|
5
|
+
declare function getSegmentsOnLabelmap(segmentation: Segmentation, labelmapId: string): number[];
|
|
6
|
+
declare function getSegmentIndexForLabelValue(segmentation: Segmentation, labelmapId: string, labelValue: number): number | undefined;
|
|
7
|
+
declare function getLabelValueForSegment(segmentation: Segmentation, segmentIndex: number): number;
|
|
8
|
+
declare function getLabelmapForSegment(segmentation: Segmentation, segmentIndex: number): LabelmapLayer | undefined;
|
|
9
|
+
declare function resolveLabelmapForSegment(segmentation: Segmentation, segmentIndex: number): LabelmapLayer | undefined;
|
|
10
|
+
declare function removeSegmentBinding(segmentation: Segmentation, segmentIndex: number): void;
|
|
11
|
+
export { getLabelmapForSegment, getLabelValueForSegment, getSegmentBinding, getSegmentIndexForLabelValue, getSegmentsOnLabelmap, removeSegmentBinding, resolveLabelmapForSegment, setSegmentBinding, };
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { ensureLabelmapState } from './normalizeLabelmapSegmentationData';
|
|
2
|
+
import { getLabelmap, getLabelmaps, removeLabelmap, } from './labelmapLayerStore';
|
|
3
|
+
import { syncLegacyLabelmapData } from './labelmapLegacyAdapter';
|
|
4
|
+
function getSegmentBinding(segmentation, segmentIndex) {
|
|
5
|
+
return ensureLabelmapState(segmentation)?.segmentBindings?.[segmentIndex];
|
|
6
|
+
}
|
|
7
|
+
function setSegmentBinding(segmentation, segmentIndex, binding) {
|
|
8
|
+
const labelmapState = ensureLabelmapState(segmentation);
|
|
9
|
+
if (!labelmapState) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
const previousBinding = labelmapState.segmentBindings[segmentIndex];
|
|
13
|
+
if (previousBinding) {
|
|
14
|
+
const previousLayer = labelmapState.labelmaps[previousBinding.labelmapId];
|
|
15
|
+
if (previousLayer?.labelToSegmentIndex) {
|
|
16
|
+
delete previousLayer.labelToSegmentIndex[previousBinding.labelValue];
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
labelmapState.segmentBindings[segmentIndex] = binding;
|
|
20
|
+
const layer = labelmapState.labelmaps[binding.labelmapId];
|
|
21
|
+
if (layer) {
|
|
22
|
+
layer.labelToSegmentIndex ||= {};
|
|
23
|
+
layer.labelToSegmentIndex[binding.labelValue] = segmentIndex;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function getSegmentsOnLabelmap(segmentation, labelmapId) {
|
|
27
|
+
const labelmapState = ensureLabelmapState(segmentation);
|
|
28
|
+
if (!labelmapState) {
|
|
29
|
+
return [];
|
|
30
|
+
}
|
|
31
|
+
return Object.entries(labelmapState.segmentBindings)
|
|
32
|
+
.filter(([, binding]) => binding.labelmapId === labelmapId)
|
|
33
|
+
.map(([segmentIndex]) => Number(segmentIndex))
|
|
34
|
+
.sort((a, b) => a - b);
|
|
35
|
+
}
|
|
36
|
+
function getSegmentIndexForLabelValue(segmentation, labelmapId, labelValue) {
|
|
37
|
+
const layer = getLabelmap(segmentation, labelmapId);
|
|
38
|
+
if (!layer || labelValue == null) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
return layer.labelToSegmentIndex?.[labelValue] ?? labelValue;
|
|
42
|
+
}
|
|
43
|
+
function getLabelValueForSegment(segmentation, segmentIndex) {
|
|
44
|
+
return (getSegmentBinding(segmentation, segmentIndex)?.labelValue ?? segmentIndex);
|
|
45
|
+
}
|
|
46
|
+
function getLabelmapForSegment(segmentation, segmentIndex) {
|
|
47
|
+
const binding = getSegmentBinding(segmentation, segmentIndex);
|
|
48
|
+
if (!binding) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
return getLabelmap(segmentation, binding.labelmapId);
|
|
52
|
+
}
|
|
53
|
+
function resolveLabelmapForSegment(segmentation, segmentIndex) {
|
|
54
|
+
return (getLabelmapForSegment(segmentation, segmentIndex) ??
|
|
55
|
+
getLabelmaps(segmentation)[0]);
|
|
56
|
+
}
|
|
57
|
+
function removeSegmentBinding(segmentation, segmentIndex) {
|
|
58
|
+
const labelmapState = ensureLabelmapState(segmentation);
|
|
59
|
+
const binding = labelmapState?.segmentBindings?.[segmentIndex];
|
|
60
|
+
if (!labelmapState || !binding) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
const layer = labelmapState.labelmaps[binding.labelmapId];
|
|
64
|
+
if (layer?.labelToSegmentIndex) {
|
|
65
|
+
delete layer.labelToSegmentIndex[binding.labelValue];
|
|
66
|
+
}
|
|
67
|
+
delete labelmapState.segmentBindings[segmentIndex];
|
|
68
|
+
if (getSegmentsOnLabelmap(segmentation, binding.labelmapId).length === 0) {
|
|
69
|
+
removeLabelmap(segmentation, binding.labelmapId);
|
|
70
|
+
}
|
|
71
|
+
syncLegacyLabelmapData(segmentation);
|
|
72
|
+
}
|
|
73
|
+
export { getLabelmapForSegment, getLabelValueForSegment, getSegmentBinding, getSegmentIndexForLabelValue, getSegmentsOnLabelmap, removeSegmentBinding, resolveLabelmapForSegment, setSegmentBinding, };
|
package/dist/esm/stateManagement/segmentation/labelmapModel/normalizeLabelmapSegmentationData.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Segmentation } from '../../../types/SegmentationStateTypes';
|
|
2
|
+
import type { LabelmapSegmentationData, LabelmapLayer, SegmentLabelmapBindingState } from '../../../types/LabelmapTypes';
|
|
3
|
+
declare const SOURCE_REPRESENTATION_NAME = "binaryLabelmap";
|
|
4
|
+
type LabelmapSegmentationWithState = LabelmapSegmentationData & {
|
|
5
|
+
labelmaps: {
|
|
6
|
+
[labelmapId: string]: LabelmapLayer;
|
|
7
|
+
};
|
|
8
|
+
segmentBindings: {
|
|
9
|
+
[segmentIndex: number]: SegmentLabelmapBindingState;
|
|
10
|
+
};
|
|
11
|
+
primaryLabelmapId: string;
|
|
12
|
+
};
|
|
13
|
+
declare function getSegmentOrder(segmentation: Segmentation): number[];
|
|
14
|
+
declare function getPrimaryLabelmapId(segmentationId: string): string;
|
|
15
|
+
declare function ensureLabelmapState(segmentation: Segmentation): LabelmapSegmentationWithState | undefined;
|
|
16
|
+
export { SOURCE_REPRESENTATION_NAME, ensureLabelmapState, getPrimaryLabelmapId, getSegmentOrder, };
|
|
17
|
+
export type { LabelmapSegmentationWithState };
|