@cornerstonejs/tools 2.19.14 → 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
|
@@ -1,382 +0,0 @@
|
|
|
1
|
-
import { expose } from 'comlink';
|
|
2
|
-
import { utilities } from '@cornerstonejs/core';
|
|
3
|
-
import vtkImageData from '@kitware/vtk.js/Common/DataModel/ImageData';
|
|
4
|
-
import vtkDataArray from '@kitware/vtk.js/Common/Core/DataArray';
|
|
5
|
-
import vtkPlane from '@kitware/vtk.js/Common/DataModel/Plane';
|
|
6
|
-
import vtkPolyData from '@kitware/vtk.js/Common/DataModel/PolyData';
|
|
7
|
-
import vtkContourLoopExtraction from '@kitware/vtk.js/Filters/General/ContourLoopExtraction';
|
|
8
|
-
import vtkCutter from '@kitware/vtk.js/Filters/Core/Cutter';
|
|
9
|
-
import { getBoundingBoxAroundShapeWorld } from '../utilities/boundingBox';
|
|
10
|
-
import { containsPoint, getAABB, projectTo2D, } from '../utilities/math/polyline';
|
|
11
|
-
import { isPlaneIntersectingAABB } from '../utilities/planar';
|
|
12
|
-
import { checkStandardBasis, rotatePoints } from '../geometricSurfaceUtils';
|
|
13
|
-
const polySegConverters = {
|
|
14
|
-
polySeg: null,
|
|
15
|
-
polySegInitializing: false,
|
|
16
|
-
polySegInitializingPromise: null,
|
|
17
|
-
async initializePolySeg(progressCallback) {
|
|
18
|
-
let ICRPolySeg;
|
|
19
|
-
try {
|
|
20
|
-
ICRPolySeg = (await import('@icr/polyseg-wasm')).default;
|
|
21
|
-
}
|
|
22
|
-
catch (error) {
|
|
23
|
-
console.error(error);
|
|
24
|
-
console.debug("Warning: '@icr/polyseg-wasm' module not found. Please install it separately.");
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
if (this.polySegInitializing) {
|
|
28
|
-
await this.polySegInitializingPromise;
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
if (this.polySeg?.instance) {
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
this.polySegInitializing = true;
|
|
35
|
-
this.polySegInitializingPromise = new Promise((resolve) => {
|
|
36
|
-
this.polySeg = new ICRPolySeg();
|
|
37
|
-
this.polySeg
|
|
38
|
-
.initialize({
|
|
39
|
-
updateProgress: progressCallback,
|
|
40
|
-
})
|
|
41
|
-
.then(() => {
|
|
42
|
-
this.polySegInitializing = false;
|
|
43
|
-
resolve();
|
|
44
|
-
});
|
|
45
|
-
});
|
|
46
|
-
await this.polySegInitializingPromise;
|
|
47
|
-
},
|
|
48
|
-
async convertContourToSurface(args, ...callbacks) {
|
|
49
|
-
const { polylines, numPointsArray } = args;
|
|
50
|
-
const [progressCallback] = callbacks;
|
|
51
|
-
await this.initializePolySeg(progressCallback);
|
|
52
|
-
const results = await this.polySeg.instance.convertContourRoiToSurface(polylines, numPointsArray);
|
|
53
|
-
return results;
|
|
54
|
-
},
|
|
55
|
-
async convertLabelmapToSurface(args, ...callbacks) {
|
|
56
|
-
const [progressCallback] = callbacks;
|
|
57
|
-
await this.initializePolySeg(progressCallback);
|
|
58
|
-
const results = this.polySeg.instance.convertLabelmapToSurface(args.scalarData, args.dimensions, args.spacing, args.direction, args.origin, [args.segmentIndex]);
|
|
59
|
-
const rotationInfo = checkStandardBasis(args.direction);
|
|
60
|
-
if (!rotationInfo.isStandard) {
|
|
61
|
-
const rotatedPoints = rotatePoints(rotationInfo.rotationMatrix, args.origin, results.points);
|
|
62
|
-
results.points = [...rotatedPoints];
|
|
63
|
-
}
|
|
64
|
-
return results;
|
|
65
|
-
},
|
|
66
|
-
async convertContourToVolumeLabelmap(args, ...callbacks) {
|
|
67
|
-
const [progressCallback] = callbacks;
|
|
68
|
-
await this.initializePolySeg(progressCallback);
|
|
69
|
-
const { segmentIndices, scalarData, annotationUIDsInSegmentMap, dimensions, origin, direction, spacing, } = args;
|
|
70
|
-
const segmentationVoxelManager = utilities.VoxelManager.createScalarVolumeVoxelManager({
|
|
71
|
-
dimensions,
|
|
72
|
-
scalarData,
|
|
73
|
-
});
|
|
74
|
-
const imageData = vtkImageData.newInstance();
|
|
75
|
-
imageData.setDimensions(dimensions);
|
|
76
|
-
imageData.setOrigin(origin);
|
|
77
|
-
imageData.setDirection(direction);
|
|
78
|
-
imageData.setSpacing(spacing);
|
|
79
|
-
const scalarArray = vtkDataArray.newInstance({
|
|
80
|
-
name: 'Pixels',
|
|
81
|
-
numberOfComponents: 1,
|
|
82
|
-
values: scalarData,
|
|
83
|
-
});
|
|
84
|
-
imageData.getPointData().setScalars(scalarArray);
|
|
85
|
-
imageData.modified();
|
|
86
|
-
for (const index of segmentIndices) {
|
|
87
|
-
const annotations = annotationUIDsInSegmentMap.get(index);
|
|
88
|
-
for (const annotation of annotations) {
|
|
89
|
-
if (!annotation.polyline) {
|
|
90
|
-
continue;
|
|
91
|
-
}
|
|
92
|
-
const { polyline, holesPolyline } = annotation;
|
|
93
|
-
const bounds = getBoundingBoxAroundShapeWorld(polyline);
|
|
94
|
-
const [iMin, jMin, kMin] = utilities.transformWorldToIndex(imageData, [
|
|
95
|
-
bounds[0][0],
|
|
96
|
-
bounds[1][0],
|
|
97
|
-
bounds[2][0],
|
|
98
|
-
]);
|
|
99
|
-
const [iMax, jMax, kMax] = utilities.transformWorldToIndex(imageData, [
|
|
100
|
-
bounds[0][1],
|
|
101
|
-
bounds[1][1],
|
|
102
|
-
bounds[2][1],
|
|
103
|
-
]);
|
|
104
|
-
const { projectedPolyline, sharedDimensionIndex } = projectTo2D(polyline);
|
|
105
|
-
const holes = holesPolyline?.map((hole) => {
|
|
106
|
-
const { projectedPolyline: projectedHole } = projectTo2D(hole);
|
|
107
|
-
return projectedHole;
|
|
108
|
-
});
|
|
109
|
-
const firstDim = (sharedDimensionIndex + 1) % 3;
|
|
110
|
-
const secondDim = (sharedDimensionIndex + 2) % 3;
|
|
111
|
-
const voxels = utilities.VoxelManager.createScalarVolumeVoxelManager({
|
|
112
|
-
dimensions,
|
|
113
|
-
scalarData,
|
|
114
|
-
});
|
|
115
|
-
voxels.forEach(({ pointIJK }) => {
|
|
116
|
-
segmentationVoxelManager.setAtIJKPoint(pointIJK, index);
|
|
117
|
-
}, {
|
|
118
|
-
imageData,
|
|
119
|
-
isInObject: (pointLPS) => {
|
|
120
|
-
const point2D = [pointLPS[firstDim], pointLPS[secondDim]];
|
|
121
|
-
const isInside = containsPoint(projectedPolyline, point2D, {
|
|
122
|
-
holes,
|
|
123
|
-
});
|
|
124
|
-
return isInside;
|
|
125
|
-
},
|
|
126
|
-
boundsIJK: [
|
|
127
|
-
[iMin, iMax],
|
|
128
|
-
[jMin, jMax],
|
|
129
|
-
[kMin, kMax],
|
|
130
|
-
],
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
return segmentationVoxelManager.scalarData;
|
|
135
|
-
},
|
|
136
|
-
async convertContourToStackLabelmap(args, ...callbacks) {
|
|
137
|
-
const [progressCallback] = callbacks;
|
|
138
|
-
await this.initializePolySeg(progressCallback);
|
|
139
|
-
const { segmentationsInfo, annotationUIDsInSegmentMap, segmentIndices } = args;
|
|
140
|
-
const segmentationVoxelManagers = new Map();
|
|
141
|
-
segmentationsInfo.forEach((segmentationInfo, referencedImageId) => {
|
|
142
|
-
const { dimensions, scalarData, direction, spacing, origin } = segmentationInfo;
|
|
143
|
-
const manager = utilities.VoxelManager.createScalarVolumeVoxelManager({
|
|
144
|
-
dimensions,
|
|
145
|
-
scalarData,
|
|
146
|
-
});
|
|
147
|
-
const imageData = vtkImageData.newInstance();
|
|
148
|
-
imageData.setDimensions(dimensions);
|
|
149
|
-
imageData.setOrigin(origin);
|
|
150
|
-
imageData.setDirection(direction);
|
|
151
|
-
imageData.setSpacing(spacing);
|
|
152
|
-
const scalarArray = vtkDataArray.newInstance({
|
|
153
|
-
name: 'Pixels',
|
|
154
|
-
numberOfComponents: 1,
|
|
155
|
-
values: scalarData,
|
|
156
|
-
});
|
|
157
|
-
imageData.getPointData().setScalars(scalarArray);
|
|
158
|
-
imageData.modified();
|
|
159
|
-
segmentationVoxelManagers.set(referencedImageId, { manager, imageData });
|
|
160
|
-
});
|
|
161
|
-
for (const index of segmentIndices) {
|
|
162
|
-
const annotations = annotationUIDsInSegmentMap.get(index);
|
|
163
|
-
for (const annotation of annotations) {
|
|
164
|
-
if (!annotation.polyline) {
|
|
165
|
-
continue;
|
|
166
|
-
}
|
|
167
|
-
const { polyline, holesPolyline, referencedImageId } = annotation;
|
|
168
|
-
const bounds = getBoundingBoxAroundShapeWorld(polyline);
|
|
169
|
-
const { manager: segmentationVoxelManager, imageData } = segmentationVoxelManagers.get(referencedImageId);
|
|
170
|
-
const [iMin, jMin, kMin] = utilities.transformWorldToIndex(imageData, [
|
|
171
|
-
bounds[0][0],
|
|
172
|
-
bounds[1][0],
|
|
173
|
-
bounds[2][0],
|
|
174
|
-
]);
|
|
175
|
-
const [iMax, jMax, kMax] = utilities.transformWorldToIndex(imageData, [
|
|
176
|
-
bounds[0][1],
|
|
177
|
-
bounds[1][1],
|
|
178
|
-
bounds[2][1],
|
|
179
|
-
]);
|
|
180
|
-
const { projectedPolyline, sharedDimensionIndex } = projectTo2D(polyline);
|
|
181
|
-
const holes = holesPolyline?.map((hole) => {
|
|
182
|
-
const { projectedPolyline: projectedHole } = projectTo2D(hole);
|
|
183
|
-
return projectedHole;
|
|
184
|
-
});
|
|
185
|
-
const firstDim = (sharedDimensionIndex + 1) % 3;
|
|
186
|
-
const secondDim = (sharedDimensionIndex + 2) % 3;
|
|
187
|
-
const voxels = utilities.VoxelManager.createImageVoxelManager({
|
|
188
|
-
width: imageData.getDimensions()[0],
|
|
189
|
-
height: imageData.getDimensions()[1],
|
|
190
|
-
scalarData: imageData.getPointData().getScalars().getData(),
|
|
191
|
-
});
|
|
192
|
-
voxels.forEach(({ pointIJK }) => {
|
|
193
|
-
segmentationVoxelManager.setAtIJKPoint(pointIJK, index);
|
|
194
|
-
}, {
|
|
195
|
-
imageData,
|
|
196
|
-
isInObject: (pointLPS) => {
|
|
197
|
-
const point2D = [pointLPS[firstDim], pointLPS[secondDim]];
|
|
198
|
-
const isInside = containsPoint(projectedPolyline, point2D, {
|
|
199
|
-
holes,
|
|
200
|
-
});
|
|
201
|
-
return isInside;
|
|
202
|
-
},
|
|
203
|
-
boundsIJK: [
|
|
204
|
-
[iMin, iMax],
|
|
205
|
-
[jMin, jMax],
|
|
206
|
-
[kMin, kMax],
|
|
207
|
-
],
|
|
208
|
-
});
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
segmentationsInfo.forEach((segmentationInfo, referencedImageId) => {
|
|
212
|
-
const { manager: segmentationVoxelManager } = segmentationVoxelManagers.get(referencedImageId);
|
|
213
|
-
segmentationInfo.scalarData = segmentationVoxelManager.scalarData;
|
|
214
|
-
});
|
|
215
|
-
return segmentationsInfo;
|
|
216
|
-
},
|
|
217
|
-
async convertSurfaceToVolumeLabelmap(args, ...callbacks) {
|
|
218
|
-
const [progressCallback] = callbacks;
|
|
219
|
-
await this.initializePolySeg(progressCallback);
|
|
220
|
-
const results = this.polySeg.instance.convertSurfaceToLabelmap(args.points, args.polys, args.dimensions, args.spacing, args.direction, args.origin);
|
|
221
|
-
return results;
|
|
222
|
-
},
|
|
223
|
-
async convertSurfacesToVolumeLabelmap(args, ...callbacks) {
|
|
224
|
-
const [progressCallback] = callbacks;
|
|
225
|
-
await this.initializePolySeg(progressCallback);
|
|
226
|
-
const { segmentsInfo } = args;
|
|
227
|
-
const promises = Array.from(segmentsInfo.keys()).map((segmentIndex) => {
|
|
228
|
-
const { points, polys } = segmentsInfo.get(segmentIndex);
|
|
229
|
-
const result = this.polySeg.instance.convertSurfaceToLabelmap(points, polys, args.dimensions, args.spacing, args.direction, args.origin);
|
|
230
|
-
return {
|
|
231
|
-
...result,
|
|
232
|
-
segmentIndex,
|
|
233
|
-
};
|
|
234
|
-
});
|
|
235
|
-
const results = await Promise.all(promises);
|
|
236
|
-
const targetImageData = vtkImageData.newInstance();
|
|
237
|
-
targetImageData.setDimensions(args.dimensions);
|
|
238
|
-
targetImageData.setOrigin(args.origin);
|
|
239
|
-
targetImageData.setSpacing(args.spacing);
|
|
240
|
-
targetImageData.setDirection(args.direction);
|
|
241
|
-
const totalSize = args.dimensions[0] * args.dimensions[1] * args.dimensions[2];
|
|
242
|
-
const scalarArray = vtkDataArray.newInstance({
|
|
243
|
-
name: 'Pixels',
|
|
244
|
-
numberOfComponents: 1,
|
|
245
|
-
values: new Uint8Array(totalSize),
|
|
246
|
-
});
|
|
247
|
-
targetImageData.getPointData().setScalars(scalarArray);
|
|
248
|
-
targetImageData.modified();
|
|
249
|
-
const { dimensions } = args;
|
|
250
|
-
const scalarData = targetImageData.getPointData().getScalars().getData();
|
|
251
|
-
const segmentationVoxelManager = utilities.VoxelManager.createScalarVolumeVoxelManager({
|
|
252
|
-
dimensions,
|
|
253
|
-
scalarData,
|
|
254
|
-
});
|
|
255
|
-
const outputVolumesInfo = results.map((result) => {
|
|
256
|
-
const { data, dimensions, direction, origin, spacing } = result;
|
|
257
|
-
const volume = vtkImageData.newInstance();
|
|
258
|
-
volume.setDimensions(dimensions);
|
|
259
|
-
volume.setOrigin(origin);
|
|
260
|
-
volume.setSpacing(spacing);
|
|
261
|
-
volume.setDirection(direction);
|
|
262
|
-
const scalarArray = vtkDataArray.newInstance({
|
|
263
|
-
name: 'Pixels',
|
|
264
|
-
numberOfComponents: 1,
|
|
265
|
-
values: data,
|
|
266
|
-
});
|
|
267
|
-
volume.getPointData().setScalars(scalarArray);
|
|
268
|
-
volume.modified();
|
|
269
|
-
const voxelManager = utilities.VoxelManager.createScalarVolumeVoxelManager({
|
|
270
|
-
dimensions,
|
|
271
|
-
scalarData: data,
|
|
272
|
-
});
|
|
273
|
-
const extent = volume.getExtent();
|
|
274
|
-
return {
|
|
275
|
-
volume,
|
|
276
|
-
voxelManager,
|
|
277
|
-
extent,
|
|
278
|
-
scalarData: data,
|
|
279
|
-
segmentIndex: result.segmentIndex,
|
|
280
|
-
};
|
|
281
|
-
});
|
|
282
|
-
const voxels = utilities.VoxelManager.createScalarVolumeVoxelManager({
|
|
283
|
-
dimensions: targetImageData.getDimensions(),
|
|
284
|
-
scalarData: targetImageData.getPointData().getScalars().getData(),
|
|
285
|
-
});
|
|
286
|
-
voxels.forEach(({ pointIJK, pointLPS }) => {
|
|
287
|
-
try {
|
|
288
|
-
for (const volumeInfo of outputVolumesInfo) {
|
|
289
|
-
const { volume, extent, voxelManager, segmentIndex } = volumeInfo;
|
|
290
|
-
const index = volume.worldToIndex(pointLPS);
|
|
291
|
-
if (index[0] < extent[0] ||
|
|
292
|
-
index[0] > extent[1] ||
|
|
293
|
-
index[1] < extent[2] ||
|
|
294
|
-
index[1] > extent[3] ||
|
|
295
|
-
index[2] < extent[4] ||
|
|
296
|
-
index[2] > extent[5]) {
|
|
297
|
-
continue;
|
|
298
|
-
}
|
|
299
|
-
const roundedIndex = index.map(Math.round);
|
|
300
|
-
const value = voxelManager.getAtIJK(...roundedIndex);
|
|
301
|
-
if (value > 0) {
|
|
302
|
-
segmentationVoxelManager.setAtIJKPoint(pointIJK, segmentIndex);
|
|
303
|
-
break;
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
catch (error) {
|
|
308
|
-
}
|
|
309
|
-
}, { imageData: targetImageData });
|
|
310
|
-
return segmentationVoxelManager.scalarData;
|
|
311
|
-
},
|
|
312
|
-
getSurfacesAABBs({ surfacesInfo }) {
|
|
313
|
-
const aabbs = new Map();
|
|
314
|
-
for (const { points, id } of surfacesInfo) {
|
|
315
|
-
const aabb = getAABB(points, { numDimensions: 3 });
|
|
316
|
-
aabbs.set(id, aabb);
|
|
317
|
-
}
|
|
318
|
-
return aabbs;
|
|
319
|
-
},
|
|
320
|
-
cutSurfacesIntoPlanes({ planesInfo, surfacesInfo, surfacesAABB = new Map() }, progressCallback, updateCacheCallback) {
|
|
321
|
-
const numberOfPlanes = planesInfo.length;
|
|
322
|
-
const cutter = vtkCutter.newInstance();
|
|
323
|
-
const plane1 = vtkPlane.newInstance();
|
|
324
|
-
cutter.setCutFunction(plane1);
|
|
325
|
-
const surfacePolyData = vtkPolyData.newInstance();
|
|
326
|
-
try {
|
|
327
|
-
for (const [index, planeInfo] of planesInfo.entries()) {
|
|
328
|
-
const { sliceIndex, planes } = planeInfo;
|
|
329
|
-
const polyDataResults = new Map();
|
|
330
|
-
for (const polyDataInfo of surfacesInfo) {
|
|
331
|
-
const { points, polys, id, segmentIndex } = polyDataInfo;
|
|
332
|
-
const aabb3 = surfacesAABB.get(id) || getAABB(points, { numDimensions: 3 });
|
|
333
|
-
if (!surfacesAABB.has(id)) {
|
|
334
|
-
surfacesAABB.set(id, aabb3);
|
|
335
|
-
}
|
|
336
|
-
const { minX, minY, minZ, maxX, maxY, maxZ } = aabb3;
|
|
337
|
-
const { origin, normal } = planes[0];
|
|
338
|
-
if (!isPlaneIntersectingAABB(origin, normal, minX, minY, minZ, maxX, maxY, maxZ)) {
|
|
339
|
-
continue;
|
|
340
|
-
}
|
|
341
|
-
surfacePolyData.getPoints().setData(points, 3);
|
|
342
|
-
surfacePolyData.getPolys().setData(polys, 3);
|
|
343
|
-
surfacePolyData.modified();
|
|
344
|
-
cutter.setInputData(surfacePolyData);
|
|
345
|
-
plane1.setOrigin(origin);
|
|
346
|
-
plane1.setNormal(normal);
|
|
347
|
-
try {
|
|
348
|
-
cutter.update();
|
|
349
|
-
}
|
|
350
|
-
catch (e) {
|
|
351
|
-
console.warn('Error during clipping', e);
|
|
352
|
-
continue;
|
|
353
|
-
}
|
|
354
|
-
const polyData = cutter.getOutputData();
|
|
355
|
-
const cutterOutput = polyData;
|
|
356
|
-
cutterOutput.buildLinks();
|
|
357
|
-
const loopExtraction = vtkContourLoopExtraction.newInstance();
|
|
358
|
-
loopExtraction.setInputData(cutterOutput);
|
|
359
|
-
const loopOutput = loopExtraction.getOutputData();
|
|
360
|
-
if (polyData) {
|
|
361
|
-
polyDataResults.set(segmentIndex, {
|
|
362
|
-
points: loopOutput.getPoints().getData(),
|
|
363
|
-
lines: loopOutput.getLines().getData(),
|
|
364
|
-
numberOfCells: loopOutput.getLines().getNumberOfCells(),
|
|
365
|
-
segmentIndex,
|
|
366
|
-
});
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
progressCallback({ progress: (index + 1) / numberOfPlanes });
|
|
370
|
-
updateCacheCallback({ sliceIndex, polyDataResults });
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
catch (e) {
|
|
374
|
-
console.warn('Error during processing', e);
|
|
375
|
-
}
|
|
376
|
-
finally {
|
|
377
|
-
surfacesInfo = null;
|
|
378
|
-
plane1.delete();
|
|
379
|
-
}
|
|
380
|
-
},
|
|
381
|
-
};
|
|
382
|
-
expose(polySegConverters);
|
|
File without changes
|
|
File without changes
|
/package/dist/esm/{tools/displayTools/Labelmap → utilities/segmentation}/validateLabelmap.js
RENAMED
|
File without changes
|
|
File without changes
|