@cornerstonejs/tools 1.57.2 → 1.58.1
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/cjs/drawingSvg/drawPath.js +1 -1
- package/dist/cjs/drawingSvg/drawPath.js.map +1 -1
- package/dist/cjs/enums/WorkerTypes.d.ts +1 -1
- package/dist/cjs/enums/WorkerTypes.js +1 -1
- package/dist/cjs/enums/WorkerTypes.js.map +1 -1
- package/dist/cjs/stateManagement/segmentation/helpers/clipAndCacheSurfacesForViewport.d.ts +17 -0
- package/dist/cjs/stateManagement/segmentation/helpers/clipAndCacheSurfacesForViewport.js +112 -0
- package/dist/cjs/stateManagement/segmentation/helpers/clipAndCacheSurfacesForViewport.js.map +1 -0
- package/dist/cjs/stateManagement/segmentation/polySeg/Contour/computeAndAddContourRepresentation.d.ts +3 -1
- package/dist/cjs/stateManagement/segmentation/polySeg/Contour/computeAndAddContourRepresentation.js +4 -1
- package/dist/cjs/stateManagement/segmentation/polySeg/Contour/computeAndAddContourRepresentation.js.map +1 -1
- package/dist/cjs/stateManagement/segmentation/polySeg/Contour/contourComputationStrategies.d.ts +8 -0
- package/dist/cjs/stateManagement/segmentation/polySeg/Contour/contourComputationStrategies.js +121 -0
- package/dist/cjs/stateManagement/segmentation/polySeg/Contour/contourComputationStrategies.js.map +1 -0
- package/dist/cjs/stateManagement/segmentation/polySeg/Contour/utils/createAndAddContourSegmentationsFromClippedSurfaces.d.ts +3 -0
- package/dist/cjs/stateManagement/segmentation/polySeg/Contour/utils/createAndAddContourSegmentationsFromClippedSurfaces.js +73 -0
- package/dist/cjs/stateManagement/segmentation/polySeg/Contour/utils/createAndAddContourSegmentationsFromClippedSurfaces.js.map +1 -0
- package/dist/cjs/stateManagement/segmentation/polySeg/Contour/utils/extractContourData.d.ts +3 -0
- package/dist/cjs/stateManagement/segmentation/polySeg/Contour/utils/extractContourData.js +25 -0
- package/dist/cjs/stateManagement/segmentation/polySeg/Contour/utils/extractContourData.js.map +1 -0
- package/dist/cjs/stateManagement/segmentation/polySeg/Contour/utils/updateContoursOnCameraModified.d.ts +1 -0
- package/dist/cjs/stateManagement/segmentation/polySeg/Contour/utils/updateContoursOnCameraModified.js +41 -0
- package/dist/cjs/stateManagement/segmentation/polySeg/Contour/utils/updateContoursOnCameraModified.js.map +1 -0
- package/dist/cjs/stateManagement/segmentation/polySeg/Labelmap/convertContourToLabelmap.js +2 -2
- package/dist/cjs/stateManagement/segmentation/polySeg/Labelmap/convertContourToLabelmap.js.map +1 -1
- package/dist/cjs/stateManagement/segmentation/polySeg/Labelmap/convertSurfaceToLabelmap.js +1 -1
- package/dist/cjs/stateManagement/segmentation/polySeg/Labelmap/convertSurfaceToLabelmap.js.map +1 -1
- package/dist/cjs/stateManagement/segmentation/polySeg/Labelmap/labelmapComputationStrategies.js.map +1 -1
- package/dist/cjs/stateManagement/segmentation/polySeg/Surface/convertContourToSurface.js +1 -1
- package/dist/cjs/stateManagement/segmentation/polySeg/Surface/convertContourToSurface.js.map +1 -1
- package/dist/cjs/stateManagement/segmentation/polySeg/Surface/convertLabelmapToSurface.js +1 -1
- package/dist/cjs/stateManagement/segmentation/polySeg/Surface/convertLabelmapToSurface.js.map +1 -1
- package/dist/cjs/stateManagement/segmentation/polySeg/computeAndAddRepresentation.js +1 -1
- package/dist/cjs/stateManagement/segmentation/polySeg/computeAndAddRepresentation.js.map +1 -1
- package/dist/cjs/stateManagement/segmentation/triggerSegmentationEvents.js +2 -0
- package/dist/cjs/stateManagement/segmentation/triggerSegmentationEvents.js.map +1 -1
- package/dist/cjs/store/ToolGroupManager/getToolGroupForViewport.d.ts +1 -1
- package/dist/cjs/store/ToolGroupManager/getToolGroupForViewport.js +5 -0
- package/dist/cjs/store/ToolGroupManager/getToolGroupForViewport.js.map +1 -1
- package/dist/cjs/tools/base/BaseTool.js +3 -0
- package/dist/cjs/tools/base/BaseTool.js.map +1 -1
- package/dist/cjs/tools/base/ContourSegmentationBaseTool.js.map +1 -1
- package/dist/cjs/tools/displayTools/Contour/contourDisplay.js +13 -5
- package/dist/cjs/tools/displayTools/Contour/contourDisplay.js.map +1 -1
- package/dist/cjs/tools/displayTools/Labelmap/labelmapDisplay.js +1 -1
- package/dist/cjs/tools/displayTools/Labelmap/labelmapDisplay.js.map +1 -1
- package/dist/cjs/tools/displayTools/SegmentationDisplayTool.d.ts +1 -0
- package/dist/cjs/tools/displayTools/SegmentationDisplayTool.js +17 -0
- package/dist/cjs/tools/displayTools/SegmentationDisplayTool.js.map +1 -1
- package/dist/cjs/tools/displayTools/Surface/addOrUpdateSurfaceToElement.js +4 -47
- package/dist/cjs/tools/displayTools/Surface/addOrUpdateSurfaceToElement.js.map +1 -1
- package/dist/cjs/tools/displayTools/Surface/surfaceDisplay.d.ts +3 -9
- package/dist/cjs/tools/displayTools/Surface/surfaceDisplay.js +7 -148
- package/dist/cjs/tools/displayTools/Surface/surfaceDisplay.js.map +1 -1
- package/dist/cjs/types/PolySeg.d.ts +1 -1
- package/dist/cjs/utilities/contourSegmentation/addContourSegmentationAnnotation.js +4 -1
- package/dist/cjs/utilities/contourSegmentation/addContourSegmentationAnnotation.js.map +1 -1
- package/dist/cjs/utilities/contourSegmentation/removeContourSegmentationAnnotation.js +3 -0
- package/dist/cjs/utilities/contourSegmentation/removeContourSegmentationAnnotation.js.map +1 -1
- package/dist/cjs/utilities/math/polyline/getAABB.d.ts +3 -1
- package/dist/cjs/utilities/math/polyline/getAABB.js +30 -4
- package/dist/cjs/utilities/math/polyline/getAABB.js.map +1 -1
- package/dist/cjs/utilities/planar/index.d.ts +3 -1
- package/dist/cjs/utilities/planar/index.js +4 -1
- package/dist/cjs/utilities/planar/index.js.map +1 -1
- package/dist/cjs/utilities/planar/isPlaneIntersectingAABB.d.ts +1 -0
- package/dist/cjs/utilities/planar/isPlaneIntersectingAABB.js +32 -0
- package/dist/cjs/utilities/planar/isPlaneIntersectingAABB.js.map +1 -0
- package/dist/cjs/utilities/segmentation/getUniqueSegmentIndices.d.ts +3 -1
- package/dist/cjs/utilities/segmentation/getUniqueSegmentIndices.js +97 -47
- package/dist/cjs/utilities/segmentation/getUniqueSegmentIndices.js.map +1 -1
- package/dist/cjs/workers/polySegConverters.js +73 -0
- package/dist/cjs/workers/polySegConverters.js.map +1 -1
- package/dist/esm/drawingSvg/drawPath.js +1 -1
- package/dist/esm/drawingSvg/drawPath.js.map +1 -1
- package/dist/esm/enums/WorkerTypes.js +1 -1
- package/dist/esm/enums/WorkerTypes.js.map +1 -1
- package/dist/esm/stateManagement/segmentation/helpers/clipAndCacheSurfacesForViewport.js +91 -0
- package/dist/esm/stateManagement/segmentation/helpers/clipAndCacheSurfacesForViewport.js.map +1 -0
- package/dist/esm/stateManagement/segmentation/polySeg/Contour/computeAndAddContourRepresentation.js +4 -1
- package/dist/esm/stateManagement/segmentation/polySeg/Contour/computeAndAddContourRepresentation.js.map +1 -1
- package/dist/esm/stateManagement/segmentation/polySeg/Contour/contourComputationStrategies.js +105 -0
- package/dist/esm/stateManagement/segmentation/polySeg/Contour/contourComputationStrategies.js.map +1 -0
- package/dist/esm/stateManagement/segmentation/polySeg/Contour/utils/createAndAddContourSegmentationsFromClippedSurfaces.js +72 -0
- package/dist/esm/stateManagement/segmentation/polySeg/Contour/utils/createAndAddContourSegmentationsFromClippedSurfaces.js.map +1 -0
- package/dist/esm/stateManagement/segmentation/polySeg/Contour/utils/extractContourData.js +21 -0
- package/dist/esm/stateManagement/segmentation/polySeg/Contour/utils/extractContourData.js.map +1 -0
- package/dist/esm/stateManagement/segmentation/polySeg/Contour/utils/updateContoursOnCameraModified.js +26 -0
- package/dist/esm/stateManagement/segmentation/polySeg/Contour/utils/updateContoursOnCameraModified.js.map +1 -0
- package/dist/esm/stateManagement/segmentation/polySeg/Labelmap/convertContourToLabelmap.js +2 -2
- package/dist/esm/stateManagement/segmentation/polySeg/Labelmap/convertContourToLabelmap.js.map +1 -1
- package/dist/esm/stateManagement/segmentation/polySeg/Labelmap/convertSurfaceToLabelmap.js +1 -1
- package/dist/esm/stateManagement/segmentation/polySeg/Labelmap/convertSurfaceToLabelmap.js.map +1 -1
- package/dist/esm/stateManagement/segmentation/polySeg/Labelmap/labelmapComputationStrategies.js +1 -1
- package/dist/esm/stateManagement/segmentation/polySeg/Labelmap/labelmapComputationStrategies.js.map +1 -1
- package/dist/esm/stateManagement/segmentation/polySeg/Surface/convertContourToSurface.js +1 -1
- package/dist/esm/stateManagement/segmentation/polySeg/Surface/convertContourToSurface.js.map +1 -1
- package/dist/esm/stateManagement/segmentation/polySeg/Surface/convertLabelmapToSurface.js +1 -1
- package/dist/esm/stateManagement/segmentation/polySeg/Surface/convertLabelmapToSurface.js.map +1 -1
- package/dist/esm/stateManagement/segmentation/polySeg/computeAndAddRepresentation.js +1 -1
- package/dist/esm/stateManagement/segmentation/polySeg/computeAndAddRepresentation.js.map +1 -1
- package/dist/esm/stateManagement/segmentation/triggerSegmentationEvents.js +2 -0
- package/dist/esm/stateManagement/segmentation/triggerSegmentationEvents.js.map +1 -1
- package/dist/esm/store/ToolGroupManager/getToolGroupForViewport.js +4 -0
- package/dist/esm/store/ToolGroupManager/getToolGroupForViewport.js.map +1 -1
- package/dist/esm/tools/base/BaseTool.js +3 -0
- package/dist/esm/tools/base/BaseTool.js.map +1 -1
- package/dist/esm/tools/base/ContourSegmentationBaseTool.js.map +1 -1
- package/dist/esm/tools/displayTools/Contour/contourDisplay.js +13 -5
- package/dist/esm/tools/displayTools/Contour/contourDisplay.js.map +1 -1
- package/dist/esm/tools/displayTools/Labelmap/labelmapDisplay.js +1 -1
- package/dist/esm/tools/displayTools/Labelmap/labelmapDisplay.js.map +1 -1
- package/dist/esm/tools/displayTools/SegmentationDisplayTool.js +17 -0
- package/dist/esm/tools/displayTools/SegmentationDisplayTool.js.map +1 -1
- package/dist/esm/tools/displayTools/Surface/addOrUpdateSurfaceToElement.js +3 -46
- package/dist/esm/tools/displayTools/Surface/addOrUpdateSurfaceToElement.js.map +1 -1
- package/dist/esm/tools/displayTools/Surface/surfaceDisplay.js +8 -139
- package/dist/esm/tools/displayTools/Surface/surfaceDisplay.js.map +1 -1
- package/dist/esm/utilities/contourSegmentation/addContourSegmentationAnnotation.js +4 -1
- package/dist/esm/utilities/contourSegmentation/addContourSegmentationAnnotation.js.map +1 -1
- package/dist/esm/utilities/contourSegmentation/removeContourSegmentationAnnotation.js +3 -0
- package/dist/esm/utilities/contourSegmentation/removeContourSegmentationAnnotation.js.map +1 -1
- package/dist/esm/utilities/math/polyline/getAABB.js +30 -4
- package/dist/esm/utilities/math/polyline/getAABB.js.map +1 -1
- package/dist/esm/utilities/planar/index.js +3 -1
- package/dist/esm/utilities/planar/index.js.map +1 -1
- package/dist/esm/utilities/planar/isPlaneIntersectingAABB.js +28 -0
- package/dist/esm/utilities/planar/isPlaneIntersectingAABB.js.map +1 -0
- package/dist/esm/utilities/segmentation/getUniqueSegmentIndices.js +92 -44
- package/dist/esm/utilities/segmentation/getUniqueSegmentIndices.js.map +1 -1
- package/dist/esm/workers/polySegConverters.js +74 -1
- package/dist/esm/workers/polySegConverters.js.map +1 -1
- package/dist/types/drawingSvg/drawPath.d.ts.map +1 -1
- package/dist/types/enums/WorkerTypes.d.ts +1 -1
- package/dist/types/enums/WorkerTypes.d.ts.map +1 -1
- package/dist/types/stateManagement/segmentation/helpers/clipAndCacheSurfacesForViewport.d.ts +18 -0
- package/dist/types/stateManagement/segmentation/helpers/clipAndCacheSurfacesForViewport.d.ts.map +1 -0
- package/dist/types/stateManagement/segmentation/polySeg/Contour/computeAndAddContourRepresentation.d.ts +3 -1
- package/dist/types/stateManagement/segmentation/polySeg/Contour/computeAndAddContourRepresentation.d.ts.map +1 -1
- package/dist/types/stateManagement/segmentation/polySeg/Contour/contourComputationStrategies.d.ts +9 -0
- package/dist/types/stateManagement/segmentation/polySeg/Contour/contourComputationStrategies.d.ts.map +1 -0
- package/dist/types/stateManagement/segmentation/polySeg/Contour/utils/createAndAddContourSegmentationsFromClippedSurfaces.d.ts +4 -0
- package/dist/types/stateManagement/segmentation/polySeg/Contour/utils/createAndAddContourSegmentationsFromClippedSurfaces.d.ts.map +1 -0
- package/dist/types/stateManagement/segmentation/polySeg/Contour/utils/extractContourData.d.ts +4 -0
- package/dist/types/stateManagement/segmentation/polySeg/Contour/utils/extractContourData.d.ts.map +1 -0
- package/dist/types/stateManagement/segmentation/polySeg/Contour/utils/updateContoursOnCameraModified.d.ts +2 -0
- package/dist/types/stateManagement/segmentation/polySeg/Contour/utils/updateContoursOnCameraModified.d.ts.map +1 -0
- package/dist/types/stateManagement/segmentation/polySeg/Labelmap/labelmapComputationStrategies.d.ts.map +1 -1
- package/dist/types/stateManagement/segmentation/triggerSegmentationEvents.d.ts.map +1 -1
- package/dist/types/store/ToolGroupManager/getToolGroupForViewport.d.ts +1 -1
- package/dist/types/store/ToolGroupManager/getToolGroupForViewport.d.ts.map +1 -1
- package/dist/types/tools/base/BaseTool.d.ts.map +1 -1
- package/dist/types/tools/base/ContourSegmentationBaseTool.d.ts.map +1 -1
- package/dist/types/tools/displayTools/Contour/contourDisplay.d.ts.map +1 -1
- package/dist/types/tools/displayTools/SegmentationDisplayTool.d.ts +1 -0
- package/dist/types/tools/displayTools/SegmentationDisplayTool.d.ts.map +1 -1
- package/dist/types/tools/displayTools/Surface/addOrUpdateSurfaceToElement.d.ts.map +1 -1
- package/dist/types/tools/displayTools/Surface/surfaceDisplay.d.ts +3 -9
- package/dist/types/tools/displayTools/Surface/surfaceDisplay.d.ts.map +1 -1
- package/dist/types/types/PolySeg.d.ts +1 -1
- package/dist/types/types/PolySeg.d.ts.map +1 -1
- package/dist/types/utilities/contourSegmentation/addContourSegmentationAnnotation.d.ts.map +1 -1
- package/dist/types/utilities/contourSegmentation/removeContourSegmentationAnnotation.d.ts.map +1 -1
- package/dist/types/utilities/math/polyline/getAABB.d.ts +3 -1
- package/dist/types/utilities/math/polyline/getAABB.d.ts.map +1 -1
- package/dist/types/utilities/planar/index.d.ts +3 -1
- package/dist/types/utilities/planar/index.d.ts.map +1 -1
- package/dist/types/utilities/planar/isPlaneIntersectingAABB.d.ts +2 -0
- package/dist/types/utilities/planar/isPlaneIntersectingAABB.d.ts.map +1 -0
- package/dist/types/utilities/segmentation/getUniqueSegmentIndices.d.ts +3 -1
- package/dist/types/utilities/segmentation/getUniqueSegmentIndices.d.ts.map +1 -1
- package/dist/umd/985.index.js +1 -1
- package/dist/umd/985.index.js.map +1 -1
- package/dist/umd/index.js +1 -1
- package/dist/umd/index.js.map +1 -1
- package/package.json +4 -4
- package/src/drawingSvg/drawPath.ts +3 -1
- package/src/enums/WorkerTypes.ts +1 -1
- package/src/stateManagement/segmentation/helpers/clipAndCacheSurfacesForViewport.ts +203 -0
- package/src/stateManagement/segmentation/polySeg/Contour/computeAndAddContourRepresentation.ts +9 -2
- package/src/stateManagement/segmentation/polySeg/Contour/contourComputationStrategies.ts +201 -0
- package/src/stateManagement/segmentation/polySeg/Contour/utils/createAndAddContourSegmentationsFromClippedSurfaces.ts +103 -0
- package/src/stateManagement/segmentation/polySeg/Contour/utils/extractContourData.ts +38 -0
- package/src/stateManagement/segmentation/polySeg/Contour/utils/updateContoursOnCameraModified.ts +58 -0
- package/src/stateManagement/segmentation/polySeg/Labelmap/convertContourToLabelmap.ts +2 -2
- package/src/stateManagement/segmentation/polySeg/Labelmap/convertSurfaceToLabelmap.ts +1 -1
- package/src/stateManagement/segmentation/polySeg/Labelmap/labelmapComputationStrategies.ts +3 -8
- package/src/stateManagement/segmentation/polySeg/Surface/convertContourToSurface.ts +1 -1
- package/src/stateManagement/segmentation/polySeg/Surface/convertLabelmapToSurface.ts +1 -1
- package/src/stateManagement/segmentation/polySeg/computeAndAddRepresentation.ts +1 -1
- package/src/stateManagement/segmentation/triggerSegmentationEvents.ts +5 -0
- package/src/store/ToolGroupManager/getToolGroupForViewport.ts +8 -1
- package/src/tools/base/BaseTool.ts +7 -0
- package/src/tools/base/ContourSegmentationBaseTool.ts +5 -0
- package/src/tools/displayTools/Contour/contourDisplay.ts +29 -11
- package/src/tools/displayTools/Labelmap/labelmapDisplay.ts +1 -1
- package/src/tools/displayTools/SegmentationDisplayTool.ts +26 -0
- package/src/tools/displayTools/Surface/addOrUpdateSurfaceToElement.ts +3 -65
- package/src/tools/displayTools/Surface/surfaceDisplay.ts +12 -247
- package/src/types/PolySeg.ts +1 -1
- package/src/utilities/contourSegmentation/addContourSegmentationAnnotation.ts +9 -1
- package/src/utilities/contourSegmentation/removeContourSegmentationAnnotation.ts +4 -0
- package/src/utilities/math/polyline/getAABB.ts +58 -4
- package/src/utilities/planar/index.ts +3 -0
- package/src/utilities/planar/isPlaneIntersectingAABB.ts +56 -0
- package/src/utilities/segmentation/getUniqueSegmentIndices.ts +115 -49
- package/src/workers/polySegConverters.js +117 -1
- package/dist/cjs/tools/displayTools/registerDisplayToolsWorker.d.ts +0 -1
- package/dist/cjs/tools/displayTools/registerDisplayToolsWorker.js +0 -27
- package/dist/cjs/tools/displayTools/registerDisplayToolsWorker.js.map +0 -1
- package/dist/cjs/workers/clippingPlaneWorker.d.ts +0 -1
- package/dist/cjs/workers/clippingPlaneWorker.js +0 -63
- package/dist/cjs/workers/clippingPlaneWorker.js.map +0 -1
- package/dist/esm/tools/displayTools/registerDisplayToolsWorker.js +0 -23
- package/dist/esm/tools/displayTools/registerDisplayToolsWorker.js.map +0 -1
- package/dist/esm/workers/clippingPlaneWorker.js +0 -58
- package/dist/esm/workers/clippingPlaneWorker.js.map +0 -1
- package/dist/types/tools/displayTools/registerDisplayToolsWorker.d.ts +0 -2
- package/dist/types/tools/displayTools/registerDisplayToolsWorker.d.ts.map +0 -1
- package/dist/types/workers/clippingPlaneWorker.d.ts +0 -2
- package/dist/types/workers/clippingPlaneWorker.d.ts.map +0 -1
- package/dist/umd/444.index.js +0 -3
- package/dist/umd/444.index.js.LICENSE.txt +0 -5
- package/dist/umd/444.index.js.map +0 -1
- package/src/tools/displayTools/registerDisplayToolsWorker.ts +0 -34
- package/src/workers/clippingPlaneWorker.js +0 -87
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
VolumeViewport,
|
|
4
|
-
volumeLoader,
|
|
5
|
-
utilities,
|
|
6
|
-
} from '@cornerstonejs/core';
|
|
1
|
+
import { VolumeViewport, volumeLoader, utilities } from '@cornerstonejs/core';
|
|
2
|
+
import type { Types } from '@cornerstonejs/core';
|
|
7
3
|
import { getUniqueSegmentIndices } from '../../../../utilities/segmentation';
|
|
8
4
|
import { getSegmentation } from '../../segmentationState';
|
|
9
5
|
import {
|
|
@@ -16,7 +12,6 @@ import {
|
|
|
16
12
|
} from './convertContourToLabelmap';
|
|
17
13
|
import { convertSurfaceToVolumeLabelmap } from './convertSurfaceToLabelmap';
|
|
18
14
|
import { computeStackSegmentationFromVolume } from '../../convertVolumeToStackSegmentation';
|
|
19
|
-
import { PixelDataTypedArray } from '@cornerstonejs/core/dist/types/types';
|
|
20
15
|
import { PolySegConversionOptions } from '../../../../types';
|
|
21
16
|
|
|
22
17
|
export type RawLabelmapData =
|
|
@@ -166,7 +161,7 @@ async function computeLabelmapFromSurfaceSegmentation(
|
|
|
166
161
|
segmentationVolume = await volumeLoader.createLocalSegmentationVolume(
|
|
167
162
|
{
|
|
168
163
|
...volumeProps,
|
|
169
|
-
scalarData: volumeProps.scalarData as PixelDataTypedArray,
|
|
164
|
+
scalarData: volumeProps.scalarData as Types.PixelDataTypedArray,
|
|
170
165
|
referencedImageIds: imageIds,
|
|
171
166
|
},
|
|
172
167
|
volumeId
|
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
SegmentationRepresentationRemovedEventDetail,
|
|
13
13
|
SegmentationRemovedEventDetail,
|
|
14
14
|
} from '../../types/EventTypes';
|
|
15
|
+
import { setSegmentationDirty } from '../../utilities/segmentation/getUniqueSegmentIndices';
|
|
15
16
|
|
|
16
17
|
/**
|
|
17
18
|
* Trigger an event that a segmentation is removed
|
|
@@ -143,6 +144,10 @@ function triggerSegmentationDataModified(
|
|
|
143
144
|
modifiedSlicesToUse,
|
|
144
145
|
};
|
|
145
146
|
|
|
147
|
+
// set it to dirty to force the next call to getUniqueSegmentIndices to
|
|
148
|
+
// recalculate the segment indices
|
|
149
|
+
setSegmentationDirty(segmentationId);
|
|
150
|
+
|
|
146
151
|
triggerEvent(eventTarget, Events.SEGMENTATION_DATA_MODIFIED, eventDetail);
|
|
147
152
|
}
|
|
148
153
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { getRenderingEngines } from '@cornerstonejs/core';
|
|
1
2
|
import { state } from '../index';
|
|
2
3
|
import { IToolGroup } from '../../types';
|
|
3
4
|
|
|
@@ -17,8 +18,14 @@ import { IToolGroup } from '../../types';
|
|
|
17
18
|
*/
|
|
18
19
|
function getToolGroupForViewport(
|
|
19
20
|
viewportId: string,
|
|
20
|
-
renderingEngineId
|
|
21
|
+
renderingEngineId?: string
|
|
21
22
|
): IToolGroup | undefined {
|
|
23
|
+
if (!renderingEngineId) {
|
|
24
|
+
renderingEngineId = getRenderingEngines().find((re) =>
|
|
25
|
+
re.getViewports().find((vp) => vp.id === viewportId)
|
|
26
|
+
)?.id;
|
|
27
|
+
}
|
|
28
|
+
|
|
22
29
|
const toolGroupFilteredByIds = state.toolGroups.filter((tg) =>
|
|
23
30
|
tg.viewportsInfo.some(
|
|
24
31
|
(vp) =>
|
|
@@ -104,6 +104,13 @@ abstract class BaseTool implements IBaseTool {
|
|
|
104
104
|
callbackType: StrategyCallbacks | string
|
|
105
105
|
): any {
|
|
106
106
|
const { strategies, activeStrategy } = this.configuration;
|
|
107
|
+
|
|
108
|
+
if (!strategies[activeStrategy]) {
|
|
109
|
+
throw new Error(
|
|
110
|
+
`applyActiveStrategyCallback: active strategy ${activeStrategy} not found, check tool configuration or spellings`
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
|
|
107
114
|
return strategies[activeStrategy][callbackType]?.call(
|
|
108
115
|
this,
|
|
109
116
|
enabledElement,
|
|
@@ -196,6 +196,11 @@ abstract class ContourSegmentationBaseTool extends ContourBaseTool {
|
|
|
196
196
|
const segmentsLocked = segmentLocking.getLockedSegments(segmentationId);
|
|
197
197
|
const annotationLocked = segmentsLocked.includes(segmentIndex as never);
|
|
198
198
|
|
|
199
|
+
// Todo: we should really get styles every time we render, since it is getting
|
|
200
|
+
// the style for the visibility and that goes through the segment indices
|
|
201
|
+
// calculation which is expensive. We should cache the styles and only update
|
|
202
|
+
// them if the segmentation representation modified event is triggered.
|
|
203
|
+
|
|
199
204
|
const segmentColor = segmentationConfig.color.getColorForSegmentIndex(
|
|
200
205
|
toolGroupId,
|
|
201
206
|
segmentationRepresentationUID,
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
getEnabledElementByIds,
|
|
3
3
|
Types,
|
|
4
|
-
StackViewport,
|
|
5
4
|
BaseVolumeViewport,
|
|
6
5
|
} from '@cornerstonejs/core';
|
|
7
6
|
|
|
@@ -15,6 +14,9 @@ import {
|
|
|
15
14
|
import { addOrUpdateVTKContourSets } from './vtkContour/addOrUpdateVTKContourSets';
|
|
16
15
|
import removeContourFromElement from './removeContourFromElement';
|
|
17
16
|
import { deleteConfigCache } from './vtkContour/contourConfigCache';
|
|
17
|
+
import { polySeg } from '../../../stateManagement/segmentation';
|
|
18
|
+
|
|
19
|
+
let polySegConversionInProgress = false;
|
|
18
20
|
|
|
19
21
|
/**
|
|
20
22
|
* It removes a segmentation representation from the tool group's viewports and
|
|
@@ -72,19 +74,35 @@ async function render(
|
|
|
72
74
|
return;
|
|
73
75
|
}
|
|
74
76
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
77
|
+
let contourData = segmentation.representationData[Representations.Contour];
|
|
78
|
+
|
|
79
|
+
if (
|
|
80
|
+
!contourData &&
|
|
81
|
+
polySeg.canComputeRequestedRepresentation(
|
|
82
|
+
representationConfig.segmentationRepresentationUID
|
|
83
|
+
) &&
|
|
84
|
+
!polySegConversionInProgress
|
|
85
|
+
) {
|
|
86
|
+
polySegConversionInProgress = true;
|
|
87
|
+
|
|
88
|
+
contourData = await polySeg.computeAndAddContourRepresentation(
|
|
89
|
+
segmentationId,
|
|
90
|
+
{
|
|
91
|
+
segmentationRepresentationUID:
|
|
92
|
+
representationConfig.segmentationRepresentationUID,
|
|
93
|
+
viewport,
|
|
94
|
+
}
|
|
95
|
+
);
|
|
81
96
|
}
|
|
82
97
|
|
|
83
|
-
//
|
|
98
|
+
// From here to below it is basically the legacy geometryId based
|
|
99
|
+
// contour rendering via vtkActors that has some bugs for display,
|
|
100
|
+
// as it sometimes appear and sometimes not, and it is not clear.
|
|
101
|
+
// We have moved to the new SVG based contours via our annotation tools
|
|
102
|
+
// check out annotationUIDsMap in the ContourSegmentationData type
|
|
103
|
+
const { geometryIds } = contourData;
|
|
84
104
|
|
|
85
|
-
if (!(viewport instanceof BaseVolumeViewport)) {
|
|
86
|
-
// We don't have a good way to handle stack viewports for contours at the moment.
|
|
87
|
-
// Plus, if we add a segmentation to one viewport, it gets added to all the viewports in the toolGroup too.
|
|
105
|
+
if (!geometryIds?.length || !(viewport instanceof BaseVolumeViewport)) {
|
|
88
106
|
return;
|
|
89
107
|
}
|
|
90
108
|
|
|
@@ -143,7 +143,7 @@ async function render(
|
|
|
143
143
|
let actorEntry = viewport.getActor(segmentationRepresentationUID);
|
|
144
144
|
|
|
145
145
|
if (
|
|
146
|
-
!
|
|
146
|
+
!labelmapData &&
|
|
147
147
|
polySeg.canComputeRequestedRepresentation(segmentationRepresentationUID) &&
|
|
148
148
|
!polySegConversionInProgress
|
|
149
149
|
) {
|
|
@@ -18,7 +18,11 @@ import {
|
|
|
18
18
|
import { surfaceDisplay } from './Surface';
|
|
19
19
|
import { contourDisplay } from './Contour';
|
|
20
20
|
import { labelmapDisplay } from './Labelmap';
|
|
21
|
+
import SegmentationRepresentations from '../../enums/SegmentationRepresentations';
|
|
22
|
+
import { addTool, state } from '../../store';
|
|
23
|
+
import PlanarFreehandContourSegmentationTool from '../annotation/PlanarFreehandContourSegmentationTool';
|
|
21
24
|
|
|
25
|
+
const planarContourToolName = PlanarFreehandContourSegmentationTool.toolName;
|
|
22
26
|
/**
|
|
23
27
|
* In Cornerstone3DTools, displaying of segmentations are handled by the SegmentationDisplayTool.
|
|
24
28
|
* Generally, any Segmentation can be viewed in various representations such as
|
|
@@ -151,6 +155,12 @@ class SegmentationDisplayTool extends BaseTool {
|
|
|
151
155
|
[Representations.Surface]: surfaceDisplay,
|
|
152
156
|
};
|
|
153
157
|
|
|
158
|
+
if (representation.type === SegmentationRepresentations.Contour) {
|
|
159
|
+
// if the representation is contour we need to make sure
|
|
160
|
+
// that the planarFreeHandTool is added to the toolGroup
|
|
161
|
+
this.addPlanarFreeHandToolIfAbsent(toolGroupId);
|
|
162
|
+
}
|
|
163
|
+
|
|
154
164
|
const display = renderers[representation.type];
|
|
155
165
|
|
|
156
166
|
for (const viewport of toolGroupViewports) {
|
|
@@ -174,6 +184,22 @@ class SegmentationDisplayTool extends BaseTool {
|
|
|
174
184
|
});
|
|
175
185
|
};
|
|
176
186
|
|
|
187
|
+
addPlanarFreeHandToolIfAbsent(toolGroupId) {
|
|
188
|
+
// if it is contour we should check if the toolGroup and more importantly
|
|
189
|
+
// the cornerstoneTools have the planarFreeHandTool added
|
|
190
|
+
if (!(planarContourToolName in state.tools)) {
|
|
191
|
+
addTool(PlanarFreehandContourSegmentationTool);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
const toolGroup = getToolGroup(toolGroupId);
|
|
195
|
+
|
|
196
|
+
// check if toolGroup has this tool
|
|
197
|
+
if (!toolGroup.hasTool(planarContourToolName)) {
|
|
198
|
+
toolGroup.addTool(planarContourToolName);
|
|
199
|
+
toolGroup.setToolPassive(planarContourToolName);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
177
203
|
/**
|
|
178
204
|
* Merge the toolGroup specific configuration with the default global configuration
|
|
179
205
|
* @param toolGroupId
|
|
@@ -1,19 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
getEnabledElement,
|
|
3
|
-
Enums,
|
|
4
|
-
VolumeViewport3D,
|
|
5
|
-
} from '@cornerstonejs/core';
|
|
1
|
+
import { getEnabledElement } from '@cornerstonejs/core';
|
|
6
2
|
import type { Types } from '@cornerstonejs/core';
|
|
7
3
|
import vtkMapper from '@kitware/vtk.js/Rendering/Core/Mapper';
|
|
8
4
|
import vtkActor from '@kitware/vtk.js/Rendering/Core/Actor';
|
|
9
|
-
import vtkClipClosedSurface from '@kitware/vtk.js/Filters/General/ClipClosedSurface';
|
|
10
5
|
import vtkPolyData from '@kitware/vtk.js/Common/DataModel/PolyData';
|
|
11
6
|
import vtkCellArray from '@kitware/vtk.js/Common/Core/CellArray';
|
|
12
|
-
import {
|
|
13
|
-
generateCacheId,
|
|
14
|
-
getOrCreatePolyData,
|
|
15
|
-
getSurfaceActorUID,
|
|
16
|
-
} from './surfaceDisplay';
|
|
7
|
+
import { getSurfaceActorUID } from '../../../stateManagement/segmentation/helpers/clipAndCacheSurfacesForViewport';
|
|
17
8
|
|
|
18
9
|
function addOrUpdateSurfaceToElement(
|
|
19
10
|
element: HTMLDivElement,
|
|
@@ -92,44 +83,7 @@ function addOrUpdateSurfaceToElement(
|
|
|
92
83
|
const mapper = vtkMapper.newInstance({});
|
|
93
84
|
|
|
94
85
|
let clippingFilter;
|
|
95
|
-
|
|
96
|
-
clippingFilter = vtkClipClosedSurface.newInstance({
|
|
97
|
-
clippingPlanes: [],
|
|
98
|
-
activePlaneId: 2,
|
|
99
|
-
passPointData: false,
|
|
100
|
-
});
|
|
101
|
-
clippingFilter.setInputData(surfacePolyData);
|
|
102
|
-
clippingFilter.setGenerateOutline(true);
|
|
103
|
-
clippingFilter.setGenerateFaces(false);
|
|
104
|
-
clippingFilter.update();
|
|
105
|
-
const filteredData = clippingFilter.getOutputData();
|
|
106
|
-
mapper.setInputData(filteredData);
|
|
107
|
-
|
|
108
|
-
// @ts-ignore
|
|
109
|
-
const viewportPlanes = viewport.getClippingPlanesForActor?.();
|
|
110
|
-
|
|
111
|
-
const evt = {
|
|
112
|
-
detail: {
|
|
113
|
-
actorEntry: {
|
|
114
|
-
actor: {
|
|
115
|
-
getMapper: () => mapper,
|
|
116
|
-
},
|
|
117
|
-
clippingFilter,
|
|
118
|
-
uid: actorUID,
|
|
119
|
-
},
|
|
120
|
-
vtkPlanes: viewportPlanes,
|
|
121
|
-
},
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
updateSurfacePlanes(evt);
|
|
125
|
-
|
|
126
|
-
element.addEventListener(
|
|
127
|
-
Enums.Events.CLIPPING_PLANES_UPDATED,
|
|
128
|
-
updateSurfacePlanes
|
|
129
|
-
);
|
|
130
|
-
} else {
|
|
131
|
-
mapper.setInputData(surfacePolyData);
|
|
132
|
-
}
|
|
86
|
+
mapper.setInputData(surfacePolyData);
|
|
133
87
|
|
|
134
88
|
const actor = vtkActor.newInstance();
|
|
135
89
|
actor.setMapper(mapper);
|
|
@@ -155,20 +109,4 @@ function addOrUpdateSurfaceToElement(
|
|
|
155
109
|
}, 0);
|
|
156
110
|
}
|
|
157
111
|
|
|
158
|
-
/**
|
|
159
|
-
* Updates the clipping planes of a surface and caches the resulting poly data
|
|
160
|
-
*/
|
|
161
|
-
function updateSurfacePlanes(evt) {
|
|
162
|
-
const { actorEntry, vtkPlanes, viewport } = evt.detail;
|
|
163
|
-
if (!actorEntry?.clippingFilter || vtkPlanes.length === 0) {
|
|
164
|
-
return;
|
|
165
|
-
}
|
|
166
|
-
const sliceIndex = viewport.getSliceIndex();
|
|
167
|
-
const mapper = actorEntry.actor.getMapper();
|
|
168
|
-
const { viewPlaneNormal } = viewport.getCamera();
|
|
169
|
-
const cacheId = generateCacheId(viewport, viewPlaneNormal, sliceIndex);
|
|
170
|
-
const polyData = getOrCreatePolyData(actorEntry, cacheId, vtkPlanes);
|
|
171
|
-
mapper.setInputData(polyData);
|
|
172
|
-
}
|
|
173
|
-
|
|
174
112
|
export default addOrUpdateSurfaceToElement;
|
|
@@ -1,42 +1,18 @@
|
|
|
1
|
-
import vtkPolyData from '@kitware/vtk.js/Common/DataModel/PolyData';
|
|
2
|
-
import vtkCellArray from '@kitware/vtk.js/Common/Core/CellArray';
|
|
3
1
|
import {
|
|
4
2
|
cache,
|
|
5
3
|
getEnabledElementByIds,
|
|
6
4
|
Types,
|
|
7
|
-
Enums,
|
|
8
|
-
getWebWorkerManager,
|
|
9
|
-
eventTarget,
|
|
10
|
-
triggerEvent,
|
|
11
|
-
utilities,
|
|
12
5
|
VolumeViewport3D,
|
|
13
6
|
} from '@cornerstonejs/core';
|
|
14
7
|
|
|
15
8
|
import * as SegmentationState from '../../../stateManagement/segmentation/segmentationState';
|
|
16
9
|
import Representations from '../../../enums/SegmentationRepresentations';
|
|
17
10
|
import { getToolGroup } from '../../../store/ToolGroupManager';
|
|
18
|
-
import {
|
|
19
|
-
SegmentationRepresentationConfig,
|
|
20
|
-
ToolGroupSpecificRepresentation,
|
|
21
|
-
} from '../../../types/SegmentationStateTypes';
|
|
22
|
-
import { registerDisplayToolsWorker } from '../registerDisplayToolsWorker';
|
|
11
|
+
import { ToolGroupSpecificRepresentation } from '../../../types/SegmentationStateTypes';
|
|
23
12
|
|
|
24
13
|
import removeSurfaceFromElement from './removeSurfaceFromElement';
|
|
25
14
|
import addOrUpdateSurfaceToElement from './addOrUpdateSurfaceToElement';
|
|
26
15
|
import { polySeg } from '../../../stateManagement/segmentation';
|
|
27
|
-
import { pointToString } from '../../../utilities';
|
|
28
|
-
import { WorkerTypes } from '../../../enums';
|
|
29
|
-
const workerManager = getWebWorkerManager();
|
|
30
|
-
|
|
31
|
-
const polyDataCache = new Map();
|
|
32
|
-
const currentViewportNormal = new Map();
|
|
33
|
-
|
|
34
|
-
const triggerWorkerProgress = (eventTarget, progress) => {
|
|
35
|
-
triggerEvent(eventTarget, Enums.Events.WEB_WORKER_PROGRESS, {
|
|
36
|
-
progress,
|
|
37
|
-
type: WorkerTypes.DISPLAY_TOOL_CLIP_SURFACE,
|
|
38
|
-
});
|
|
39
|
-
};
|
|
40
16
|
|
|
41
17
|
/**
|
|
42
18
|
* It removes a segmentation representation from the tool group's viewports and
|
|
@@ -82,16 +58,10 @@ function removeSegmentationRepresentation(
|
|
|
82
58
|
*/
|
|
83
59
|
async function render(
|
|
84
60
|
viewport: Types.IVolumeViewport,
|
|
85
|
-
representation: ToolGroupSpecificRepresentation
|
|
86
|
-
toolGroupConfig: SegmentationRepresentationConfig
|
|
61
|
+
representation: ToolGroupSpecificRepresentation
|
|
87
62
|
): Promise<void> {
|
|
88
|
-
const {
|
|
89
|
-
|
|
90
|
-
active,
|
|
91
|
-
segmentationId,
|
|
92
|
-
segmentationRepresentationUID,
|
|
93
|
-
segmentsHidden,
|
|
94
|
-
} = representation;
|
|
63
|
+
const { colorLUTIndex, segmentationId, segmentationRepresentationUID } =
|
|
64
|
+
representation;
|
|
95
65
|
|
|
96
66
|
const segmentation = SegmentationState.getSegmentation(segmentationId);
|
|
97
67
|
|
|
@@ -99,6 +69,12 @@ async function render(
|
|
|
99
69
|
return;
|
|
100
70
|
}
|
|
101
71
|
|
|
72
|
+
if (!(viewport instanceof VolumeViewport3D)) {
|
|
73
|
+
throw new Error(
|
|
74
|
+
'Surface rendering is only supported in 3D viewports, if you need to visualize the surface cuts in 2D viewports, you can use the Contour representation, see polySeg converters'
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
|
|
102
78
|
let SurfaceData = segmentation.representationData[Representations.Surface];
|
|
103
79
|
|
|
104
80
|
if (
|
|
@@ -134,18 +110,7 @@ async function render(
|
|
|
134
110
|
const surfaces = [];
|
|
135
111
|
geometryIds.forEach((geometryId, segmentIndex) => {
|
|
136
112
|
const geometry = cache.getGeometry(geometryId);
|
|
137
|
-
if (!geometry) {
|
|
138
|
-
throw new Error(`No Surfaces found for geometryId ${geometryId}`);
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
if (geometry.type !== Enums.GeometryType.SURFACE) {
|
|
142
|
-
// Todo: later we can support converting other geometries to Surfaces
|
|
143
|
-
throw new Error(
|
|
144
|
-
`Geometry type ${geometry.type} not supported for rendering.`
|
|
145
|
-
);
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
if (!geometry.data) {
|
|
113
|
+
if (!geometry?.data) {
|
|
149
114
|
console.warn(
|
|
150
115
|
`No Surfaces found for geometryId ${geometryId}. Skipping render.`
|
|
151
116
|
);
|
|
@@ -166,18 +131,6 @@ async function render(
|
|
|
166
131
|
surfaces.push(surface);
|
|
167
132
|
});
|
|
168
133
|
|
|
169
|
-
if (!(viewport instanceof VolumeViewport3D)) {
|
|
170
|
-
// const { viewPlaneNormal } = viewport.getCamera();
|
|
171
|
-
// currentViewportNormal.set(surface.id, structuredClone(viewPlaneNormal));
|
|
172
|
-
// if the viewport is not 3D means we should calculate
|
|
173
|
-
// the clipping planes for the surface and cache the results
|
|
174
|
-
generateAndCacheClippedSurfaces(
|
|
175
|
-
surfaces,
|
|
176
|
-
viewport,
|
|
177
|
-
segmentationRepresentationUID
|
|
178
|
-
);
|
|
179
|
-
}
|
|
180
|
-
|
|
181
134
|
viewport.render();
|
|
182
135
|
}
|
|
183
136
|
|
|
@@ -206,197 +159,9 @@ function _removeSurfaceFromToolGroupViewports(
|
|
|
206
159
|
}
|
|
207
160
|
}
|
|
208
161
|
|
|
209
|
-
async function generateAndCacheClippedSurfaces(
|
|
210
|
-
surfaces: Types.ISurface[],
|
|
211
|
-
viewport: Types.IVolumeViewport | Types.IStackViewport,
|
|
212
|
-
segmentationRepresentationUID: string
|
|
213
|
-
) {
|
|
214
|
-
registerDisplayToolsWorker();
|
|
215
|
-
|
|
216
|
-
// All planes is an array of planes pairs for each slice, so we should loop over them and
|
|
217
|
-
// add the planes to the clipping filter and cache the results for that slice
|
|
218
|
-
|
|
219
|
-
// Fix these ts ignores
|
|
220
|
-
// @ts-ignore
|
|
221
|
-
const planesInfo = viewport.getSlicesClippingPlanes?.();
|
|
222
|
-
|
|
223
|
-
if (!planesInfo) {
|
|
224
|
-
// this means it is probably the stack viewport not being ready
|
|
225
|
-
// in terms of planes which we should wait for the first render to
|
|
226
|
-
// get the planes
|
|
227
|
-
return;
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
// @ts-ignore
|
|
231
|
-
const currentSliceIndex = viewport.getSliceIndex();
|
|
232
|
-
|
|
233
|
-
// Reorder planesInfo based on proximity to currentSliceIndex
|
|
234
|
-
planesInfo.sort((a, b) => {
|
|
235
|
-
const diffA = Math.abs(a.sliceIndex - currentSliceIndex);
|
|
236
|
-
const diffB = Math.abs(b.sliceIndex - currentSliceIndex);
|
|
237
|
-
return diffA - diffB;
|
|
238
|
-
});
|
|
239
|
-
|
|
240
|
-
const pointsAndPolys = surfaces.map((surface) => {
|
|
241
|
-
const id = surface.id;
|
|
242
|
-
const points = surface.getPoints();
|
|
243
|
-
const polys = surface.getPolys();
|
|
244
|
-
|
|
245
|
-
return { id, points, polys };
|
|
246
|
-
});
|
|
247
|
-
|
|
248
|
-
const camera = viewport.getCamera();
|
|
249
|
-
|
|
250
|
-
function cameraModifiedCallback(evt: Types.EventTypes.CameraModifiedEvent) {
|
|
251
|
-
const { camera } = evt.detail;
|
|
252
|
-
const { viewPlaneNormal } = camera;
|
|
253
|
-
|
|
254
|
-
// Note: I think choosing one of the surfaces to see
|
|
255
|
-
// if the viewPlaneNormal is the same for all surfaces is ok enough
|
|
256
|
-
// to decide if we should recompute the clipping planes
|
|
257
|
-
const surface1 = surfaces[0];
|
|
258
|
-
|
|
259
|
-
if (
|
|
260
|
-
utilities.isEqual(viewPlaneNormal, currentViewportNormal.get(surface1.id))
|
|
261
|
-
) {
|
|
262
|
-
return;
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
currentViewportNormal.set(surface1.id, viewPlaneNormal);
|
|
266
|
-
|
|
267
|
-
workerManager.terminate('displayTools');
|
|
268
|
-
|
|
269
|
-
setTimeout(() => {
|
|
270
|
-
generateAndCacheClippedSurfaces(
|
|
271
|
-
surfaces,
|
|
272
|
-
viewport,
|
|
273
|
-
segmentationRepresentationUID
|
|
274
|
-
);
|
|
275
|
-
}, 0);
|
|
276
|
-
|
|
277
|
-
viewport.render();
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
// Remove the existing event listener
|
|
281
|
-
viewport.element.removeEventListener(
|
|
282
|
-
Enums.Events.CAMERA_MODIFIED,
|
|
283
|
-
cameraModifiedCallback as EventListener
|
|
284
|
-
);
|
|
285
|
-
|
|
286
|
-
// Add the event listener
|
|
287
|
-
viewport.element.addEventListener(
|
|
288
|
-
Enums.Events.CAMERA_MODIFIED,
|
|
289
|
-
cameraModifiedCallback as EventListener
|
|
290
|
-
);
|
|
291
|
-
|
|
292
|
-
triggerWorkerProgress(eventTarget, 0);
|
|
293
|
-
|
|
294
|
-
await workerManager
|
|
295
|
-
.executeTask(
|
|
296
|
-
'displayTools',
|
|
297
|
-
'clipSurfaceWithPlanes',
|
|
298
|
-
{
|
|
299
|
-
planesInfo,
|
|
300
|
-
pointsAndPolys,
|
|
301
|
-
},
|
|
302
|
-
{
|
|
303
|
-
callbacks: [
|
|
304
|
-
// progress callback
|
|
305
|
-
({ progress }) => {
|
|
306
|
-
triggerWorkerProgress(eventTarget, progress);
|
|
307
|
-
},
|
|
308
|
-
// update cache callback
|
|
309
|
-
({ sliceIndex, polyDataResults }) => {
|
|
310
|
-
polyDataResults.forEach((polyDataResult, surfaceId) => {
|
|
311
|
-
const actorUID = `${segmentationRepresentationUID}_${surfaceId}`;
|
|
312
|
-
const cacheId = generateCacheId(
|
|
313
|
-
viewport,
|
|
314
|
-
camera.viewPlaneNormal,
|
|
315
|
-
sliceIndex
|
|
316
|
-
);
|
|
317
|
-
updatePolyDataCache(actorUID, cacheId, polyDataResult);
|
|
318
|
-
});
|
|
319
|
-
},
|
|
320
|
-
],
|
|
321
|
-
}
|
|
322
|
-
)
|
|
323
|
-
.catch((error) => {
|
|
324
|
-
console.error(error);
|
|
325
|
-
});
|
|
326
|
-
|
|
327
|
-
triggerWorkerProgress(eventTarget, 100);
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
export function getSurfaceActorUID(
|
|
331
|
-
segmentationRepresentationUID: string,
|
|
332
|
-
surfaceId: string
|
|
333
|
-
) {
|
|
334
|
-
return `${segmentationRepresentationUID}_${surfaceId}`;
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
// Helper function to generate a cache ID
|
|
338
|
-
export function generateCacheId(viewport, viewPlaneNormal, sliceIndex) {
|
|
339
|
-
return `${viewport.id}-${pointToString(viewPlaneNormal)}-${sliceIndex}`;
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
// Helper function to get or create PolyData
|
|
343
|
-
export function getOrCreatePolyData(actorEntry, cacheId, vtkPlanes) {
|
|
344
|
-
let actorCache = polyDataCache.get(actorEntry.uid);
|
|
345
|
-
if (!actorCache) {
|
|
346
|
-
actorCache = new Map();
|
|
347
|
-
polyDataCache.set(actorEntry.uid, actorCache);
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
let polyData = actorCache.get(cacheId);
|
|
351
|
-
if (!polyData) {
|
|
352
|
-
const clippingFilter = actorEntry.clippingFilter;
|
|
353
|
-
clippingFilter.setClippingPlanes(vtkPlanes);
|
|
354
|
-
try {
|
|
355
|
-
clippingFilter.update();
|
|
356
|
-
polyData = clippingFilter.getOutputData();
|
|
357
|
-
actorCache.set(cacheId, polyData);
|
|
358
|
-
} catch (e) {
|
|
359
|
-
console.error('Error clipping surface', e);
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
return polyData;
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
// Helper function to update PolyData cache
|
|
366
|
-
export function updatePolyDataCache(actorUID, cacheId, polyDataResult) {
|
|
367
|
-
const { points, lines } = polyDataResult;
|
|
368
|
-
const polyData = vtkPolyData.newInstance();
|
|
369
|
-
polyData.getPoints().setData(points, 3);
|
|
370
|
-
const linesArray = vtkCellArray.newInstance({
|
|
371
|
-
values: Int16Array.from(lines),
|
|
372
|
-
});
|
|
373
|
-
polyData.setLines(linesArray);
|
|
374
|
-
|
|
375
|
-
let actorCache = polyDataCache.get(actorUID);
|
|
376
|
-
if (!actorCache) {
|
|
377
|
-
actorCache = new Map();
|
|
378
|
-
polyDataCache.set(actorUID, actorCache);
|
|
379
|
-
}
|
|
380
|
-
actorCache.set(cacheId, polyData);
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
// Helper function to get and sort planes info based on slice index
|
|
384
|
-
export function getSortedPlanesInfo(viewport) {
|
|
385
|
-
const planesInfo = viewport.getSlicesClippingPlanes?.();
|
|
386
|
-
const currentSliceIndex = viewport.getSliceIndex();
|
|
387
|
-
|
|
388
|
-
// Sort planesInfo based on proximity to currentSliceIndex
|
|
389
|
-
planesInfo.sort((a, b) => {
|
|
390
|
-
const diffA = Math.abs(a.sliceIndex - currentSliceIndex);
|
|
391
|
-
const diffB = Math.abs(b.sliceIndex - currentSliceIndex);
|
|
392
|
-
return diffA - diffB;
|
|
393
|
-
});
|
|
394
|
-
return planesInfo;
|
|
395
|
-
}
|
|
396
|
-
|
|
397
162
|
export default {
|
|
398
163
|
render,
|
|
399
164
|
removeSegmentationRepresentation,
|
|
400
165
|
};
|
|
401
166
|
|
|
402
|
-
export { render, removeSegmentationRepresentation
|
|
167
|
+
export { render, removeSegmentationRepresentation };
|
package/src/types/PolySeg.ts
CHANGED