@cornerstonejs/tools 3.0.0-beta.2 → 3.0.0-beta.3
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 +29 -0
- package/dist/esm/config.js +23 -0
- package/dist/esm/enums/StrategyCallbacks.d.ts +3 -1
- package/dist/esm/enums/StrategyCallbacks.js +2 -0
- package/dist/esm/enums/WorkerTypes.d.ts +3 -1
- package/dist/esm/enums/WorkerTypes.js +2 -0
- package/dist/esm/init.d.ts +2 -1
- package/dist/esm/init.js +2 -0
- package/dist/esm/stateManagement/segmentation/helpers/normalizeSegmentationInput.js +1 -1
- package/dist/esm/stateManagement/segmentation/helpers/validateSegmentationInput.js +1 -1
- package/dist/esm/stateManagement/segmentation/index.d.ts +3 -2
- package/dist/esm/stateManagement/segmentation/index.js +3 -2
- package/dist/esm/tools/displayTools/Contour/contourDisplay.js +8 -6
- package/dist/esm/tools/displayTools/Labelmap/index.d.ts +1 -1
- package/dist/esm/tools/displayTools/Labelmap/index.js +1 -1
- package/dist/esm/tools/displayTools/Labelmap/labelmapDisplay.js +14 -5
- package/dist/esm/tools/displayTools/Surface/surfaceDisplay.js +13 -8
- package/dist/esm/tools/segmentation/BrushTool.js +1 -9
- package/dist/esm/tools/segmentation/CircleScissorsTool.js +0 -1
- package/dist/esm/tools/segmentation/LabelmapBaseTool.d.ts +1 -2
- package/dist/esm/tools/segmentation/LabelmapBaseTool.js +10 -49
- package/dist/esm/tools/segmentation/RectangleScissorsTool.js +0 -1
- package/dist/esm/tools/segmentation/SphereScissorsTool.js +0 -1
- package/dist/esm/tools/segmentation/strategies/BrushStrategy.d.ts +21 -10
- package/dist/esm/tools/segmentation/strategies/BrushStrategy.js +8 -8
- package/dist/esm/tools/segmentation/strategies/compositions/determineSegmentIndex.js +7 -10
- package/dist/esm/tools/segmentation/strategies/compositions/dynamicThreshold.js +15 -14
- package/dist/esm/tools/segmentation/strategies/compositions/ensureImageVolume.d.ts +4 -0
- package/dist/esm/tools/segmentation/strategies/compositions/ensureImageVolume.js +35 -0
- package/dist/esm/tools/segmentation/strategies/compositions/ensureSegmentationVolume.d.ts +4 -0
- package/dist/esm/tools/segmentation/strategies/compositions/ensureSegmentationVolume.js +20 -0
- package/dist/esm/tools/segmentation/strategies/compositions/index.d.ts +7 -10
- package/dist/esm/tools/segmentation/strategies/compositions/index.js +4 -2
- package/dist/esm/tools/segmentation/strategies/compositions/islandRemovalComposition.js +3 -2
- package/dist/esm/tools/segmentation/strategies/compositions/labelmapStatistics.d.ts +1 -1
- package/dist/esm/tools/segmentation/strategies/compositions/labelmapStatistics.js +6 -97
- package/dist/esm/tools/segmentation/strategies/compositions/preview.js +3 -3
- package/dist/esm/tools/segmentation/strategies/compositions/threshold.js +5 -6
- package/dist/esm/tools/segmentation/strategies/fillCircle.js +2 -2
- package/dist/esm/tools/segmentation/strategies/fillSphere.js +3 -3
- package/dist/esm/tools/segmentation/strategies/utils/getStrategyData.d.ts +7 -3
- package/dist/esm/tools/segmentation/strategies/utils/getStrategyData.js +78 -34
- package/dist/esm/tools/segmentation/strategies/utils/isWithinThreshold.d.ts +2 -7
- package/dist/esm/tools/segmentation/strategies/utils/isWithinThreshold.js +5 -4
- package/dist/esm/types/CalculatorTypes.d.ts +2 -0
- package/dist/esm/types/LabelmapToolOperationData.d.ts +1 -1
- package/dist/esm/types/index.d.ts +3 -4
- package/dist/esm/utilities/getPixelValueUnits.d.ts +2 -1
- package/dist/esm/utilities/getPixelValueUnits.js +5 -1
- package/dist/esm/utilities/index.d.ts +3 -2
- package/dist/esm/utilities/index.js +3 -2
- package/dist/esm/utilities/math/basic/BasicStatsCalculator.d.ts +6 -1
- package/dist/esm/utilities/math/basic/BasicStatsCalculator.js +27 -2
- package/dist/esm/utilities/math/vec2/liangBarksyClip.d.ts +1 -1
- package/dist/esm/utilities/registerComputeWorker.d.ts +1 -0
- package/dist/esm/{stateManagement/segmentation/polySeg/registerPolySegWorker.js → utilities/registerComputeWorker.js} +4 -4
- package/dist/esm/utilities/segmentation/brushThresholdForToolGroup.d.ts +5 -1
- package/dist/esm/utilities/segmentation/brushThresholdForToolGroup.js +12 -13
- package/dist/esm/{stateManagement/segmentation/polySeg → utilities/segmentation}/computeAndAddRepresentation.d.ts +1 -1
- package/dist/esm/{stateManagement/segmentation/polySeg → utilities/segmentation}/computeAndAddRepresentation.js +4 -6
- package/dist/esm/utilities/segmentation/getOrCreateSegmentationVolume.d.ts +2 -0
- package/dist/esm/utilities/segmentation/getOrCreateSegmentationVolume.js +21 -0
- package/dist/esm/utilities/segmentation/getStatistics.d.ts +5 -0
- package/dist/esm/utilities/segmentation/getStatistics.js +210 -0
- package/dist/esm/utilities/segmentation/index.d.ts +6 -1
- package/dist/esm/utilities/segmentation/index.js +6 -1
- package/dist/esm/{tools/displayTools/Labelmap → utilities/segmentation}/validateLabelmap.d.ts +2 -2
- package/dist/esm/workers/computeWorker.js +78 -0
- package/package.json +3 -3
- package/dist/esm/stateManagement/segmentation/helpers/clipAndCacheSurfacesForViewport.d.ts +0 -16
- package/dist/esm/stateManagement/segmentation/helpers/clipAndCacheSurfacesForViewport.js +0 -88
- package/dist/esm/stateManagement/segmentation/polySeg/Contour/computeAndAddContourRepresentation.d.ts +0 -4
- package/dist/esm/stateManagement/segmentation/polySeg/Contour/computeAndAddContourRepresentation.js +0 -6
- package/dist/esm/stateManagement/segmentation/polySeg/Contour/contourComputationStrategies.d.ts +0 -8
- package/dist/esm/stateManagement/segmentation/polySeg/Contour/contourComputationStrategies.js +0 -103
- package/dist/esm/stateManagement/segmentation/polySeg/Contour/utils/createAndAddContourSegmentationsFromClippedSurfaces.d.ts +0 -3
- package/dist/esm/stateManagement/segmentation/polySeg/Contour/utils/createAndAddContourSegmentationsFromClippedSurfaces.js +0 -71
- package/dist/esm/stateManagement/segmentation/polySeg/Contour/utils/extractContourData.d.ts +0 -3
- package/dist/esm/stateManagement/segmentation/polySeg/Contour/utils/extractContourData.js +0 -16
- package/dist/esm/stateManagement/segmentation/polySeg/Contour/utils/updateContoursOnCameraModified.d.ts +0 -1
- package/dist/esm/stateManagement/segmentation/polySeg/Contour/utils/updateContoursOnCameraModified.js +0 -25
- package/dist/esm/stateManagement/segmentation/polySeg/Labelmap/computeAndAddLabelmapRepresentation.d.ts +0 -2
- package/dist/esm/stateManagement/segmentation/polySeg/Labelmap/computeAndAddLabelmapRepresentation.js +0 -13
- package/dist/esm/stateManagement/segmentation/polySeg/Labelmap/convertContourToLabelmap.d.ts +0 -7
- package/dist/esm/stateManagement/segmentation/polySeg/Labelmap/convertContourToLabelmap.js +0 -143
- package/dist/esm/stateManagement/segmentation/polySeg/Labelmap/convertSurfaceToLabelmap.d.ts +0 -6
- package/dist/esm/stateManagement/segmentation/polySeg/Labelmap/convertSurfaceToLabelmap.js +0 -49
- package/dist/esm/stateManagement/segmentation/polySeg/Labelmap/labelmapComputationStrategies.d.ts +0 -6
- package/dist/esm/stateManagement/segmentation/polySeg/Labelmap/labelmapComputationStrategies.js +0 -96
- package/dist/esm/stateManagement/segmentation/polySeg/Surface/computeAndAddSurfaceRepresentation.d.ts +0 -4
- package/dist/esm/stateManagement/segmentation/polySeg/Surface/computeAndAddSurfaceRepresentation.js +0 -7
- package/dist/esm/stateManagement/segmentation/polySeg/Surface/convertContourToSurface.d.ts +0 -3
- package/dist/esm/stateManagement/segmentation/polySeg/Surface/convertContourToSurface.js +0 -37
- package/dist/esm/stateManagement/segmentation/polySeg/Surface/convertLabelmapToSurface.d.ts +0 -3
- package/dist/esm/stateManagement/segmentation/polySeg/Surface/convertLabelmapToSurface.js +0 -44
- package/dist/esm/stateManagement/segmentation/polySeg/Surface/createAndCacheSurfacesFromRaw.d.ts +0 -5
- package/dist/esm/stateManagement/segmentation/polySeg/Surface/createAndCacheSurfacesFromRaw.js +0 -33
- package/dist/esm/stateManagement/segmentation/polySeg/Surface/surfaceComputationStrategies.d.ts +0 -12
- package/dist/esm/stateManagement/segmentation/polySeg/Surface/surfaceComputationStrategies.js +0 -75
- package/dist/esm/stateManagement/segmentation/polySeg/Surface/updateSurfaceData.d.ts +0 -1
- package/dist/esm/stateManagement/segmentation/polySeg/Surface/updateSurfaceData.js +0 -59
- package/dist/esm/stateManagement/segmentation/polySeg/canComputeRequestedRepresentation.d.ts +0 -3
- package/dist/esm/stateManagement/segmentation/polySeg/canComputeRequestedRepresentation.js +0 -58
- package/dist/esm/stateManagement/segmentation/polySeg/index.d.ts +0 -5
- package/dist/esm/stateManagement/segmentation/polySeg/index.js +0 -5
- package/dist/esm/stateManagement/segmentation/polySeg/registerPolySegWorker.d.ts +0 -1
- package/dist/esm/tools/segmentation/strategies/compositions/labelmapInterpolation.d.ts +0 -12
- package/dist/esm/tools/segmentation/strategies/compositions/labelmapInterpolation.js +0 -60
- package/dist/esm/tools/segmentation/strategies/utils/getItkImage.d.ts +0 -1
- package/dist/esm/tools/segmentation/strategies/utils/getItkImage.js +0 -49
- package/dist/esm/types/PolySeg.d.ts +0 -6
- package/dist/esm/types/PolySeg.js +0 -0
- package/dist/esm/workers/polySegConverters.js +0 -382
- /package/dist/esm/{geometricSurfaceUtils.d.ts → utilities/geometricSurfaceUtils.d.ts} +0 -0
- /package/dist/esm/{geometricSurfaceUtils.js → utilities/geometricSurfaceUtils.js} +0 -0
- /package/dist/esm/{tools/displayTools/Labelmap → utilities/segmentation}/validateLabelmap.js +0 -0
- /package/dist/esm/workers/{polySegConverters.d.ts → computeWorker.d.ts} +0 -0
package/dist/esm/stateManagement/segmentation/polySeg/Labelmap/labelmapComputationStrategies.js
DELETED
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import { VolumeViewport, volumeLoader, imageLoader } from '@cornerstonejs/core';
|
|
2
|
-
import { getUniqueSegmentIndices } from '../../../../utilities/segmentation/getUniqueSegmentIndices';
|
|
3
|
-
import { getSegmentation } from '../../getSegmentation';
|
|
4
|
-
import { convertContourToStackLabelmap, convertContourToVolumeLabelmap, } from './convertContourToLabelmap';
|
|
5
|
-
import { convertSurfaceToVolumeLabelmap } from './convertSurfaceToLabelmap';
|
|
6
|
-
import { computeStackLabelmapFromVolume } from '../../helpers/computeStackLabelmapFromVolume';
|
|
7
|
-
export async function computeLabelmapData(segmentationId, options = {}) {
|
|
8
|
-
const segmentIndices = options.segmentIndices?.length
|
|
9
|
-
? options.segmentIndices
|
|
10
|
-
: getUniqueSegmentIndices(segmentationId);
|
|
11
|
-
let rawLabelmapData;
|
|
12
|
-
const segmentation = getSegmentation(segmentationId);
|
|
13
|
-
const representationData = segmentation.representationData;
|
|
14
|
-
try {
|
|
15
|
-
if (representationData.Contour) {
|
|
16
|
-
rawLabelmapData = await computeLabelmapFromContourSegmentation(segmentationId, {
|
|
17
|
-
segmentIndices,
|
|
18
|
-
...options,
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
else if (representationData.Surface) {
|
|
22
|
-
rawLabelmapData = await computeLabelmapFromSurfaceSegmentation(segmentation.segmentationId, {
|
|
23
|
-
segmentIndices,
|
|
24
|
-
...options,
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
catch (error) {
|
|
29
|
-
console.error(error);
|
|
30
|
-
throw error;
|
|
31
|
-
}
|
|
32
|
-
if (!rawLabelmapData) {
|
|
33
|
-
throw new Error('Not enough data to convert to surface, currently only support converting volume labelmap to surface if available');
|
|
34
|
-
}
|
|
35
|
-
return rawLabelmapData;
|
|
36
|
-
}
|
|
37
|
-
async function computeLabelmapFromContourSegmentation(segmentationId, options = {}) {
|
|
38
|
-
const isVolume = options.viewport
|
|
39
|
-
? options.viewport instanceof VolumeViewport
|
|
40
|
-
: true;
|
|
41
|
-
if (isVolume && !options.viewport) {
|
|
42
|
-
throw new Error('Cannot compute labelmap from contour segmentation without providing the viewport');
|
|
43
|
-
}
|
|
44
|
-
const segmentIndices = options.segmentIndices?.length
|
|
45
|
-
? options.segmentIndices
|
|
46
|
-
: getUniqueSegmentIndices(segmentationId);
|
|
47
|
-
const segmentation = getSegmentation(segmentationId);
|
|
48
|
-
const representationData = segmentation.representationData.Contour;
|
|
49
|
-
const convertFunction = isVolume
|
|
50
|
-
? convertContourToVolumeLabelmap
|
|
51
|
-
: convertContourToStackLabelmap;
|
|
52
|
-
const result = await convertFunction(representationData, {
|
|
53
|
-
segmentIndices,
|
|
54
|
-
viewport: options.viewport,
|
|
55
|
-
});
|
|
56
|
-
return result;
|
|
57
|
-
}
|
|
58
|
-
async function computeLabelmapFromSurfaceSegmentation(segmentationId, options = {}) {
|
|
59
|
-
const { viewport } = options;
|
|
60
|
-
const isVolume = viewport ? viewport instanceof VolumeViewport : true;
|
|
61
|
-
const segmentIndices = options.segmentIndices?.length
|
|
62
|
-
? options.segmentIndices
|
|
63
|
-
: getUniqueSegmentIndices(segmentationId);
|
|
64
|
-
const segmentation = getSegmentation(segmentationId);
|
|
65
|
-
const segmentsGeometryIds = new Map();
|
|
66
|
-
const representationData = segmentation.representationData.Surface;
|
|
67
|
-
representationData.geometryIds.forEach((geometryId, segmentIndex) => {
|
|
68
|
-
if (segmentIndices.includes(segmentIndex)) {
|
|
69
|
-
segmentsGeometryIds.set(segmentIndex, geometryId);
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
if (isVolume && !viewport) {
|
|
73
|
-
throw new Error('Cannot compute labelmap from surface segmentation without providing the viewport');
|
|
74
|
-
}
|
|
75
|
-
let segmentationVolume;
|
|
76
|
-
if (isVolume) {
|
|
77
|
-
const volumeId = viewport.getVolumeId();
|
|
78
|
-
segmentationVolume =
|
|
79
|
-
volumeLoader.createAndCacheDerivedLabelmapVolume(volumeId);
|
|
80
|
-
}
|
|
81
|
-
else {
|
|
82
|
-
const imageIds = options.viewport.getImageIds();
|
|
83
|
-
const segImages = imageLoader.createAndCacheDerivedLabelmapImages(imageIds);
|
|
84
|
-
const segImageIds = segImages.map((image) => image.imageId);
|
|
85
|
-
segmentationVolume = await volumeLoader.createAndCacheVolumeFromImages('generatedSegmentationVolumeId', segImageIds);
|
|
86
|
-
}
|
|
87
|
-
const result = await convertSurfaceToVolumeLabelmap({ geometryIds: segmentsGeometryIds }, segmentationVolume);
|
|
88
|
-
if (isVolume) {
|
|
89
|
-
return result;
|
|
90
|
-
}
|
|
91
|
-
const stackData = (await computeStackLabelmapFromVolume({
|
|
92
|
-
volumeId: segmentationVolume.volumeId,
|
|
93
|
-
}));
|
|
94
|
-
return stackData;
|
|
95
|
-
}
|
|
96
|
-
export { computeLabelmapFromContourSegmentation };
|
package/dist/esm/stateManagement/segmentation/polySeg/Surface/computeAndAddSurfaceRepresentation.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { SegmentationRepresentations } from '../../../../enums';
|
|
2
|
-
import { computeAndAddRepresentation } from '../computeAndAddRepresentation';
|
|
3
|
-
import { computeSurfaceData } from './surfaceComputationStrategies';
|
|
4
|
-
import { updateSurfaceData } from './updateSurfaceData';
|
|
5
|
-
export function computeAndAddSurfaceRepresentation(segmentationId, options = {}) {
|
|
6
|
-
return computeAndAddRepresentation(segmentationId, SegmentationRepresentations.Surface, () => computeSurfaceData(segmentationId, options), () => updateSurfaceData(segmentationId));
|
|
7
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { Enums, eventTarget, triggerEvent, getWebWorkerManager, } from '@cornerstonejs/core';
|
|
2
|
-
import { getAnnotation } from '../../../annotation/annotationState';
|
|
3
|
-
import { WorkerTypes } from '../../../../enums';
|
|
4
|
-
const workerManager = getWebWorkerManager();
|
|
5
|
-
const triggerWorkerProgress = (eventTarget, progress, id) => {
|
|
6
|
-
triggerEvent(eventTarget, Enums.Events.WEB_WORKER_PROGRESS, {
|
|
7
|
-
progress,
|
|
8
|
-
type: WorkerTypes.POLYSEG_CONTOUR_TO_SURFACE,
|
|
9
|
-
id,
|
|
10
|
-
});
|
|
11
|
-
};
|
|
12
|
-
export async function convertContourToSurface(contourRepresentationData, segmentIndex) {
|
|
13
|
-
const { annotationUIDsMap } = contourRepresentationData;
|
|
14
|
-
const polylines = [];
|
|
15
|
-
const numPointsArray = [];
|
|
16
|
-
const annotationUIDs = annotationUIDsMap.get(segmentIndex);
|
|
17
|
-
for (const annotationUID of annotationUIDs) {
|
|
18
|
-
const annotation = getAnnotation(annotationUID);
|
|
19
|
-
const { polyline } = annotation.data
|
|
20
|
-
.contour;
|
|
21
|
-
numPointsArray.push(polyline.length);
|
|
22
|
-
polyline.forEach((polyline) => polylines.push(...polyline));
|
|
23
|
-
}
|
|
24
|
-
triggerWorkerProgress(eventTarget, 0, segmentIndex);
|
|
25
|
-
const results = await workerManager.executeTask('polySeg', 'convertContourToSurface', {
|
|
26
|
-
polylines,
|
|
27
|
-
numPointsArray,
|
|
28
|
-
}, {
|
|
29
|
-
callbacks: [
|
|
30
|
-
(progress) => {
|
|
31
|
-
triggerWorkerProgress(eventTarget, progress, segmentIndex);
|
|
32
|
-
},
|
|
33
|
-
],
|
|
34
|
-
});
|
|
35
|
-
triggerWorkerProgress(eventTarget, 100, segmentIndex);
|
|
36
|
-
return results;
|
|
37
|
-
}
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import type { Types } from '@cornerstonejs/core';
|
|
2
|
-
import type { LabelmapSegmentationData } from '../../../../types/LabelmapTypes';
|
|
3
|
-
export declare function convertLabelmapToSurface(labelmapRepresentationData: LabelmapSegmentationData, segmentIndex: number): Promise<Types.SurfaceData>;
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { cache, eventTarget, getWebWorkerManager, triggerEvent, Enums, } from '@cornerstonejs/core';
|
|
2
|
-
import { computeVolumeLabelmapFromStack } from '../../helpers/computeVolumeLabelmapFromStack';
|
|
3
|
-
import { WorkerTypes } from '../../../../enums';
|
|
4
|
-
const workerManager = getWebWorkerManager();
|
|
5
|
-
const triggerWorkerProgress = (eventTarget, progress, id) => {
|
|
6
|
-
triggerEvent(eventTarget, Enums.Events.WEB_WORKER_PROGRESS, {
|
|
7
|
-
progress,
|
|
8
|
-
type: WorkerTypes.POLYSEG_LABELMAP_TO_SURFACE,
|
|
9
|
-
id,
|
|
10
|
-
});
|
|
11
|
-
};
|
|
12
|
-
export async function convertLabelmapToSurface(labelmapRepresentationData, segmentIndex) {
|
|
13
|
-
let volumeId;
|
|
14
|
-
if (labelmapRepresentationData.volumeId) {
|
|
15
|
-
volumeId = labelmapRepresentationData
|
|
16
|
-
.volumeId;
|
|
17
|
-
}
|
|
18
|
-
else {
|
|
19
|
-
const { imageIds } = labelmapRepresentationData;
|
|
20
|
-
({ volumeId } = await computeVolumeLabelmapFromStack({
|
|
21
|
-
imageIds,
|
|
22
|
-
}));
|
|
23
|
-
}
|
|
24
|
-
const volume = cache.getVolume(volumeId);
|
|
25
|
-
const scalarData = volume.voxelManager.getCompleteScalarDataArray();
|
|
26
|
-
const { dimensions, spacing, origin, direction } = volume;
|
|
27
|
-
triggerWorkerProgress(eventTarget, 0, segmentIndex);
|
|
28
|
-
const results = await workerManager.executeTask('polySeg', 'convertLabelmapToSurface', {
|
|
29
|
-
scalarData,
|
|
30
|
-
dimensions,
|
|
31
|
-
spacing,
|
|
32
|
-
origin,
|
|
33
|
-
direction,
|
|
34
|
-
segmentIndex,
|
|
35
|
-
}, {
|
|
36
|
-
callbacks: [
|
|
37
|
-
(progress) => {
|
|
38
|
-
triggerWorkerProgress(eventTarget, progress, segmentIndex);
|
|
39
|
-
},
|
|
40
|
-
],
|
|
41
|
-
});
|
|
42
|
-
triggerWorkerProgress(eventTarget, 100, segmentIndex);
|
|
43
|
-
return results;
|
|
44
|
-
}
|
package/dist/esm/stateManagement/segmentation/polySeg/Surface/createAndCacheSurfacesFromRaw.d.ts
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type { RawSurfacesData } from './surfaceComputationStrategies';
|
|
2
|
-
import type { PolySegConversionOptions } from '../../../../types';
|
|
3
|
-
export declare function createAndCacheSurfacesFromRaw(segmentationId: string, rawSurfacesData: RawSurfacesData, options?: PolySegConversionOptions): Promise<{
|
|
4
|
-
geometryIds: Map<number, string>;
|
|
5
|
-
}>;
|
package/dist/esm/stateManagement/segmentation/polySeg/Surface/createAndCacheSurfacesFromRaw.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { Enums, geometryLoader } from '@cornerstonejs/core';
|
|
2
|
-
import { getSegmentIndexColor } from '../../config/segmentationColor';
|
|
3
|
-
import { getSegmentation } from '../../getSegmentation';
|
|
4
|
-
export async function createAndCacheSurfacesFromRaw(segmentationId, rawSurfacesData, options = {}) {
|
|
5
|
-
const segmentation = getSegmentation(segmentationId);
|
|
6
|
-
const geometryIds = new Map();
|
|
7
|
-
const promises = Object.keys(rawSurfacesData).map(async (index) => {
|
|
8
|
-
const rawSurfaceData = rawSurfacesData[index];
|
|
9
|
-
const segmentIndex = rawSurfaceData.segmentIndex;
|
|
10
|
-
const color = getSegmentIndexColor(options.viewport.id, segmentation.segmentationId, segmentIndex).slice(0, 3);
|
|
11
|
-
if (!color) {
|
|
12
|
-
throw new Error('No color found for segment index, unable to create surface');
|
|
13
|
-
}
|
|
14
|
-
const closedSurface = {
|
|
15
|
-
id: `segmentation_${segmentation.segmentationId}_surface_${segmentIndex}`,
|
|
16
|
-
color,
|
|
17
|
-
frameOfReferenceUID: 'test-frameOfReferenceUID',
|
|
18
|
-
points: rawSurfaceData.data.points,
|
|
19
|
-
polys: rawSurfaceData.data.polys,
|
|
20
|
-
segmentIndex,
|
|
21
|
-
};
|
|
22
|
-
const geometryId = closedSurface.id;
|
|
23
|
-
geometryIds.set(segmentIndex, geometryId);
|
|
24
|
-
return geometryLoader.createAndCacheGeometry(geometryId, {
|
|
25
|
-
type: Enums.GeometryType.SURFACE,
|
|
26
|
-
geometryData: closedSurface,
|
|
27
|
-
});
|
|
28
|
-
});
|
|
29
|
-
await Promise.all(promises);
|
|
30
|
-
return {
|
|
31
|
-
geometryIds,
|
|
32
|
-
};
|
|
33
|
-
}
|
package/dist/esm/stateManagement/segmentation/polySeg/Surface/surfaceComputationStrategies.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { Types } from '@cornerstonejs/core';
|
|
2
|
-
import type { PolySegConversionOptions } from '../../../../types';
|
|
3
|
-
export type RawSurfacesData = {
|
|
4
|
-
segmentIndex: number;
|
|
5
|
-
data: Types.SurfaceData;
|
|
6
|
-
}[];
|
|
7
|
-
export declare function computeSurfaceData(segmentationId: string, options?: PolySegConversionOptions): Promise<{
|
|
8
|
-
geometryIds: Map<number, string>;
|
|
9
|
-
}>;
|
|
10
|
-
declare function computeSurfaceFromLabelmapSegmentation(segmentationId: any, options?: PolySegConversionOptions): Promise<RawSurfacesData>;
|
|
11
|
-
declare function computeSurfaceFromContourSegmentation(segmentationId: string, options?: PolySegConversionOptions): Promise<RawSurfacesData>;
|
|
12
|
-
export { computeSurfaceFromContourSegmentation, computeSurfaceFromLabelmapSegmentation, };
|
package/dist/esm/stateManagement/segmentation/polySeg/Surface/surfaceComputationStrategies.js
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { getUniqueSegmentIndices } from '../../../../utilities/segmentation/getUniqueSegmentIndices';
|
|
2
|
-
import { getSegmentation } from '../../getSegmentation';
|
|
3
|
-
import { convertContourToSurface } from './convertContourToSurface';
|
|
4
|
-
import { createAndCacheSurfacesFromRaw } from './createAndCacheSurfacesFromRaw';
|
|
5
|
-
import { convertLabelmapToSurface } from './convertLabelmapToSurface';
|
|
6
|
-
export async function computeSurfaceData(segmentationId, options = {}) {
|
|
7
|
-
const segmentIndices = options.segmentIndices?.length
|
|
8
|
-
? options.segmentIndices
|
|
9
|
-
: getUniqueSegmentIndices(segmentationId);
|
|
10
|
-
let rawSurfacesData;
|
|
11
|
-
const segmentation = getSegmentation(segmentationId);
|
|
12
|
-
const representationData = segmentation.representationData;
|
|
13
|
-
try {
|
|
14
|
-
if (representationData.Contour) {
|
|
15
|
-
rawSurfacesData = await computeSurfaceFromContourSegmentation(segmentationId, {
|
|
16
|
-
segmentIndices,
|
|
17
|
-
...options,
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
else if (representationData.Labelmap) {
|
|
21
|
-
rawSurfacesData = await computeSurfaceFromLabelmapSegmentation(segmentation.segmentationId, {
|
|
22
|
-
segmentIndices,
|
|
23
|
-
...options,
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
catch (error) {
|
|
28
|
-
console.error(error);
|
|
29
|
-
throw error;
|
|
30
|
-
}
|
|
31
|
-
if (!rawSurfacesData) {
|
|
32
|
-
throw new Error('Not enough data to convert to surface, currently only support converting volume labelmap to surface if available');
|
|
33
|
-
}
|
|
34
|
-
const surfacesData = await createAndCacheSurfacesFromRaw(segmentationId, rawSurfacesData, options);
|
|
35
|
-
return surfacesData;
|
|
36
|
-
}
|
|
37
|
-
async function computeSurfaceFromLabelmapSegmentation(segmentationId, options = {}) {
|
|
38
|
-
const segmentation = getSegmentation(segmentationId);
|
|
39
|
-
if (!segmentation?.representationData?.Labelmap) {
|
|
40
|
-
console.warn('Only support surface update from labelmaps');
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
const labelmapRepresentationData = segmentation.representationData.Labelmap;
|
|
44
|
-
const segmentIndices = options.segmentIndices || getUniqueSegmentIndices(segmentationId);
|
|
45
|
-
const promises = segmentIndices.map((index) => {
|
|
46
|
-
const surface = convertLabelmapToSurface(labelmapRepresentationData, index);
|
|
47
|
-
return surface;
|
|
48
|
-
});
|
|
49
|
-
const surfaces = await Promise.allSettled(promises);
|
|
50
|
-
const errors = surfaces.filter((p) => p.status === 'rejected');
|
|
51
|
-
if (errors.length > 0) {
|
|
52
|
-
console.error(errors);
|
|
53
|
-
throw new Error('Failed to convert labelmap to surface');
|
|
54
|
-
}
|
|
55
|
-
const rawSurfacesData = surfaces
|
|
56
|
-
.map((surface, index) => {
|
|
57
|
-
if (surface.status === 'fulfilled') {
|
|
58
|
-
return { segmentIndex: segmentIndices[index], data: surface.value };
|
|
59
|
-
}
|
|
60
|
-
})
|
|
61
|
-
.filter(Boolean);
|
|
62
|
-
return rawSurfacesData;
|
|
63
|
-
}
|
|
64
|
-
async function computeSurfaceFromContourSegmentation(segmentationId, options = {}) {
|
|
65
|
-
const segmentation = getSegmentation(segmentationId);
|
|
66
|
-
const contourRepresentationData = segmentation.representationData.Contour;
|
|
67
|
-
const segmentIndices = options.segmentIndices || getUniqueSegmentIndices(segmentationId);
|
|
68
|
-
const promises = segmentIndices.map(async (index) => {
|
|
69
|
-
const surface = await convertContourToSurface(contourRepresentationData, index);
|
|
70
|
-
return { segmentIndex: index, data: surface };
|
|
71
|
-
});
|
|
72
|
-
const surfaces = await Promise.all(promises);
|
|
73
|
-
return surfaces;
|
|
74
|
-
}
|
|
75
|
-
export { computeSurfaceFromContourSegmentation, computeSurfaceFromLabelmapSegmentation, };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function updateSurfaceData(segmentationId: any): Promise<void>;
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { cache } from '@cornerstonejs/core';
|
|
2
|
-
import { getUniqueSegmentIndices } from '../../../../utilities/segmentation/getUniqueSegmentIndices';
|
|
3
|
-
import { getViewportIdsWithSegmentation } from '../../getViewportIdsWithSegmentation';
|
|
4
|
-
import { getSegmentation } from '../../getSegmentation';
|
|
5
|
-
import { triggerSegmentationModified } from '../../triggerSegmentationEvents';
|
|
6
|
-
import { getSegmentationRepresentation } from '../../getSegmentationRepresentation';
|
|
7
|
-
import { SegmentationRepresentations } from '../../../../enums';
|
|
8
|
-
import { computeSurfaceFromLabelmapSegmentation } from './surfaceComputationStrategies';
|
|
9
|
-
import { createAndCacheSurfacesFromRaw } from './createAndCacheSurfacesFromRaw';
|
|
10
|
-
export async function updateSurfaceData(segmentationId) {
|
|
11
|
-
const surfacesObj = await computeSurfaceFromLabelmapSegmentation(segmentationId);
|
|
12
|
-
if (!surfacesObj) {
|
|
13
|
-
return;
|
|
14
|
-
}
|
|
15
|
-
const segmentation = getSegmentation(segmentationId);
|
|
16
|
-
const indices = getUniqueSegmentIndices(segmentationId);
|
|
17
|
-
if (!indices.length) {
|
|
18
|
-
const geometryIds = segmentation.representationData.Surface.geometryIds;
|
|
19
|
-
geometryIds.forEach((geometryId) => {
|
|
20
|
-
const geometry = cache.getGeometry(geometryId);
|
|
21
|
-
const surface = geometry.data;
|
|
22
|
-
surface.points = [];
|
|
23
|
-
surface.polys = [];
|
|
24
|
-
});
|
|
25
|
-
triggerSegmentationModified(segmentationId);
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
const promises = surfacesObj.map(({ data, segmentIndex }) => {
|
|
29
|
-
const geometryId = `segmentation_${segmentationId}_surface_${segmentIndex}`;
|
|
30
|
-
const geometry = cache.getGeometry(geometryId);
|
|
31
|
-
if (!geometry) {
|
|
32
|
-
const viewportIds = getViewportIdsWithSegmentation(segmentationId);
|
|
33
|
-
return viewportIds.map((viewportId) => {
|
|
34
|
-
const surfaceRepresentation = getSegmentationRepresentation(viewportId, {
|
|
35
|
-
segmentationId,
|
|
36
|
-
type: SegmentationRepresentations.Surface,
|
|
37
|
-
});
|
|
38
|
-
return [surfaceRepresentation].map((surfaceRepresentation) => {
|
|
39
|
-
segmentation.representationData.Surface.geometryIds.set(segmentIndex, geometryId);
|
|
40
|
-
return createAndCacheSurfacesFromRaw(segmentationId, [{ segmentIndex, data }], {
|
|
41
|
-
segmentationId: surfaceRepresentation.segmentationId,
|
|
42
|
-
});
|
|
43
|
-
});
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
else if (indices.includes(segmentIndex)) {
|
|
47
|
-
const surface = geometry.data;
|
|
48
|
-
surface.points = data.points;
|
|
49
|
-
surface.polys = data.polys;
|
|
50
|
-
}
|
|
51
|
-
else {
|
|
52
|
-
const surface = geometry.data;
|
|
53
|
-
surface.points = [];
|
|
54
|
-
surface.polys = [];
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
await Promise.all(promises);
|
|
58
|
-
triggerSegmentationModified(segmentationId);
|
|
59
|
-
}
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { SegmentationRepresentations } from '../../../enums';
|
|
2
|
-
import { getSegmentation } from '../getSegmentation';
|
|
3
|
-
import { validate as validateLabelmap } from '../../../tools/displayTools/Labelmap/validateLabelmap';
|
|
4
|
-
const conversionPaths = new Map([
|
|
5
|
-
[
|
|
6
|
-
SegmentationRepresentations.Labelmap,
|
|
7
|
-
new Set([
|
|
8
|
-
SegmentationRepresentations.Surface,
|
|
9
|
-
SegmentationRepresentations.Contour,
|
|
10
|
-
]),
|
|
11
|
-
],
|
|
12
|
-
[
|
|
13
|
-
SegmentationRepresentations.Contour,
|
|
14
|
-
new Set([
|
|
15
|
-
SegmentationRepresentations.Labelmap,
|
|
16
|
-
SegmentationRepresentations.Surface,
|
|
17
|
-
]),
|
|
18
|
-
],
|
|
19
|
-
[
|
|
20
|
-
SegmentationRepresentations.Surface,
|
|
21
|
-
new Set([SegmentationRepresentations.Labelmap]),
|
|
22
|
-
],
|
|
23
|
-
]);
|
|
24
|
-
function canComputeRequestedRepresentation(segmentationId, type) {
|
|
25
|
-
const { representationData } = getSegmentation(segmentationId);
|
|
26
|
-
const existingRepresentationTypes = getExistingRepresentationTypes(representationData);
|
|
27
|
-
return existingRepresentationTypes.some((existingRepresentationType) => canConvertFromTo(existingRepresentationType, type));
|
|
28
|
-
}
|
|
29
|
-
function getExistingRepresentationTypes(representationData) {
|
|
30
|
-
const supportedTypes = [];
|
|
31
|
-
Object.keys(representationData).forEach((representationType) => {
|
|
32
|
-
const representationTypeData = representationData[representationType];
|
|
33
|
-
let validateFn;
|
|
34
|
-
switch (representationType) {
|
|
35
|
-
case SegmentationRepresentations.Labelmap:
|
|
36
|
-
validateFn = validateLabelmap;
|
|
37
|
-
break;
|
|
38
|
-
}
|
|
39
|
-
if (validateFn) {
|
|
40
|
-
try {
|
|
41
|
-
validateFn(representationTypeData);
|
|
42
|
-
supportedTypes.push(representationType);
|
|
43
|
-
}
|
|
44
|
-
catch (error) {
|
|
45
|
-
console.warn(`Validation failed for labelmap of type ${representationType}`);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
else {
|
|
49
|
-
supportedTypes.push(representationType);
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
return supportedTypes;
|
|
53
|
-
}
|
|
54
|
-
async function canConvertFromTo(fromRepresentationType, toRepresentationType) {
|
|
55
|
-
return (conversionPaths.get(fromRepresentationType)?.has(toRepresentationType) ||
|
|
56
|
-
false);
|
|
57
|
-
}
|
|
58
|
-
export { canComputeRequestedRepresentation };
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { computeAndAddSurfaceRepresentation } from './Surface/computeAndAddSurfaceRepresentation';
|
|
2
|
-
import { computeAndAddLabelmapRepresentation } from './Labelmap/computeAndAddLabelmapRepresentation';
|
|
3
|
-
import { computeAndAddContourRepresentation } from './Contour/computeAndAddContourRepresentation';
|
|
4
|
-
import { canComputeRequestedRepresentation } from './canComputeRequestedRepresentation';
|
|
5
|
-
export { canComputeRequestedRepresentation, computeAndAddSurfaceRepresentation, computeAndAddLabelmapRepresentation, computeAndAddContourRepresentation, };
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { computeAndAddSurfaceRepresentation } from './Surface/computeAndAddSurfaceRepresentation';
|
|
2
|
-
import { computeAndAddLabelmapRepresentation } from './Labelmap/computeAndAddLabelmapRepresentation';
|
|
3
|
-
import { computeAndAddContourRepresentation } from './Contour/computeAndAddContourRepresentation';
|
|
4
|
-
import { canComputeRequestedRepresentation } from './canComputeRequestedRepresentation';
|
|
5
|
-
export { canComputeRequestedRepresentation, computeAndAddSurfaceRepresentation, computeAndAddLabelmapRepresentation, computeAndAddContourRepresentation, };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function registerPolySegWorker(): void;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { InitializedOperationData } from '../BrushStrategy';
|
|
2
|
-
type MorphologicalContourInterpolationOptions = {
|
|
3
|
-
label?: number;
|
|
4
|
-
axis?: number;
|
|
5
|
-
noHeuristicAlignment?: boolean;
|
|
6
|
-
noUseDistanceTransform?: boolean;
|
|
7
|
-
useCustomSlicePositions?: boolean;
|
|
8
|
-
};
|
|
9
|
-
declare const _default: {
|
|
10
|
-
interpolate: (operationData: InitializedOperationData, configuration: MorphologicalContourInterpolationOptions) => Promise<InitializedOperationData>;
|
|
11
|
-
};
|
|
12
|
-
export default _default;
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { utilities, peerImport } from '@cornerstonejs/core';
|
|
2
|
-
import StrategyCallbacks from '../../../../enums/StrategyCallbacks';
|
|
3
|
-
import getItkImage from '../utils/getItkImage';
|
|
4
|
-
import { triggerSegmentationDataModified } from '../../../../stateManagement/segmentation/triggerSegmentationEvents';
|
|
5
|
-
import PreviewMethods from './preview';
|
|
6
|
-
export default {
|
|
7
|
-
[StrategyCallbacks.Interpolate]: async (operationData, configuration) => {
|
|
8
|
-
const { segmentationImageData, segmentIndex, preview, segmentationVoxelManager, previewSegmentIndex, previewVoxelManager, } = operationData;
|
|
9
|
-
if (preview) {
|
|
10
|
-
const callback = ({ index }) => {
|
|
11
|
-
segmentationVoxelManager.setAtIndex(index, segmentIndex);
|
|
12
|
-
};
|
|
13
|
-
previewVoxelManager.forEach(callback);
|
|
14
|
-
}
|
|
15
|
-
let itkModule;
|
|
16
|
-
try {
|
|
17
|
-
itkModule = await peerImport('@itk-wasm/morphological-contour-interpolation');
|
|
18
|
-
if (!itkModule) {
|
|
19
|
-
throw new Error('Module not found');
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
catch (error) {
|
|
23
|
-
console.warn("Warning: '@itk-wasm/morphological-contour-interpolation' module not found. Please install it separately.");
|
|
24
|
-
return operationData;
|
|
25
|
-
}
|
|
26
|
-
let inputImage;
|
|
27
|
-
try {
|
|
28
|
-
inputImage = await getItkImage(segmentationImageData, 'interpolation');
|
|
29
|
-
if (!inputImage) {
|
|
30
|
-
throw new Error('Failed to get ITK image');
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
catch (error) {
|
|
34
|
-
console.warn('Warning: Failed to get ITK image for interpolation');
|
|
35
|
-
return operationData;
|
|
36
|
-
}
|
|
37
|
-
const outputPromise = itkModule.morphologicalContourInterpolation(inputImage, {
|
|
38
|
-
...configuration,
|
|
39
|
-
label: segmentIndex,
|
|
40
|
-
webWorker: false,
|
|
41
|
-
});
|
|
42
|
-
outputPromise.then((value) => {
|
|
43
|
-
const { outputImage } = value;
|
|
44
|
-
const previewColors = operationData.configuration?.preview?.previewColors;
|
|
45
|
-
const assignIndex = previewSegmentIndex ?? (previewColors ? 255 : segmentIndex);
|
|
46
|
-
operationData.previewColors ||= previewColors;
|
|
47
|
-
operationData.previewSegmentIndex ||= previewColors ? 255 : undefined;
|
|
48
|
-
PreviewMethods[StrategyCallbacks.Initialize](operationData);
|
|
49
|
-
segmentationVoxelManager.forEach(({ value: originalValue, index }) => {
|
|
50
|
-
const newValue = outputImage.data[index];
|
|
51
|
-
if (newValue === originalValue) {
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
previewVoxelManager.setAtIndex(index, assignIndex);
|
|
55
|
-
});
|
|
56
|
-
triggerSegmentationDataModified(operationData.segmentationId, previewVoxelManager.getArrayOfModifiedSlices(), assignIndex);
|
|
57
|
-
});
|
|
58
|
-
return operationData;
|
|
59
|
-
},
|
|
60
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export default function getItkImage(imageData: any, imageName?: string): Promise<unknown>;
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { peerImport } from '@cornerstonejs/core';
|
|
2
|
-
export default async function getItkImage(imageData, imageName) {
|
|
3
|
-
let Image, ImageType, IntTypes, FloatTypes, PixelTypes;
|
|
4
|
-
try {
|
|
5
|
-
const itkModule = await peerImport('itk-wasm');
|
|
6
|
-
if (!itkModule) {
|
|
7
|
-
throw new Error('Module not found');
|
|
8
|
-
}
|
|
9
|
-
({ Image, ImageType, IntTypes, FloatTypes, PixelTypes } = itkModule);
|
|
10
|
-
}
|
|
11
|
-
catch (error) {
|
|
12
|
-
console.warn("Warning: 'itk-wasm' module not found. Please install it separately.");
|
|
13
|
-
return null;
|
|
14
|
-
}
|
|
15
|
-
const dataTypesMap = {
|
|
16
|
-
Int8: IntTypes.Int8,
|
|
17
|
-
UInt8: IntTypes.UInt8,
|
|
18
|
-
Int16: IntTypes.Int16,
|
|
19
|
-
UInt16: IntTypes.UInt16,
|
|
20
|
-
Int32: IntTypes.Int32,
|
|
21
|
-
UInt32: IntTypes.UInt32,
|
|
22
|
-
Int64: IntTypes.Int64,
|
|
23
|
-
UInt64: IntTypes.UInt64,
|
|
24
|
-
Float32: FloatTypes.Float32,
|
|
25
|
-
Float64: FloatTypes.Float64,
|
|
26
|
-
};
|
|
27
|
-
const { voxelManager } = imageData.get('voxelManager');
|
|
28
|
-
const { numberOfComponents } = imageData.get('numberOfComponents');
|
|
29
|
-
const scalarData = voxelManager.getCompleteScalarDataArray();
|
|
30
|
-
const dimensions = imageData.getDimensions();
|
|
31
|
-
const origin = imageData.getOrigin();
|
|
32
|
-
const spacing = imageData.getSpacing();
|
|
33
|
-
const directionArray = imageData.getDirection();
|
|
34
|
-
const direction = new Float64Array(directionArray);
|
|
35
|
-
const dataType = scalarData.constructor.name
|
|
36
|
-
.replace(/^Ui/, 'UI')
|
|
37
|
-
.replace(/Array$/, '');
|
|
38
|
-
const metadata = undefined;
|
|
39
|
-
const imageType = new ImageType(dimensions.length, dataTypesMap[dataType], PixelTypes.Scalar, numberOfComponents);
|
|
40
|
-
const image = new Image(imageType);
|
|
41
|
-
image.name = imageName;
|
|
42
|
-
image.origin = origin;
|
|
43
|
-
image.spacing = spacing;
|
|
44
|
-
image.direction = direction;
|
|
45
|
-
image.size = dimensions;
|
|
46
|
-
image.metadata = metadata;
|
|
47
|
-
image.data = scalarData;
|
|
48
|
-
return image;
|
|
49
|
-
}
|
|
File without changes
|