@cornerstonejs/tools 2.0.0-beta.22 → 2.0.0-beta.24
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/eventListeners/segmentation/labelmap/onLabelmapSegmentationDataModified.js +27 -23
- package/dist/esm/eventListeners/segmentation/segmentationDataModifiedEventListener.js +2 -2
- package/dist/esm/index.d.ts +2 -2
- package/dist/esm/index.js +2 -2
- package/dist/esm/stateManagement/index.d.ts +2 -0
- package/dist/esm/stateManagement/index.js +2 -2
- package/dist/esm/stateManagement/segmentation/SegmentationRenderingEngine.d.ts +1 -2
- package/dist/esm/stateManagement/segmentation/SegmentationStateManager.d.ts +3 -0
- package/dist/esm/stateManagement/segmentation/SegmentationStateManager.js +59 -11
- package/dist/esm/stateManagement/segmentation/getStackSegmentationImageIdsForViewport.d.ts +1 -0
- package/dist/esm/stateManagement/segmentation/getStackSegmentationImageIdsForViewport.js +5 -0
- package/dist/esm/stateManagement/segmentation/segmentationState.d.ts +2 -1
- package/dist/esm/stateManagement/segmentation/segmentationState.js +2 -1
- package/dist/esm/tools/annotation/BidirectionalTool.js +6 -6
- package/dist/esm/tools/annotation/CircleROITool.js +12 -12
- package/dist/esm/tools/annotation/DragProbeTool.js +2 -2
- package/dist/esm/tools/annotation/EllipticalROITool.js +11 -11
- package/dist/esm/tools/annotation/HeightTool.js +4 -4
- package/dist/esm/tools/annotation/LengthTool.js +4 -4
- package/dist/esm/tools/annotation/PlanarFreehandROITool.d.ts +4 -4
- package/dist/esm/tools/annotation/PlanarFreehandROITool.js +19 -19
- package/dist/esm/tools/annotation/ProbeTool.js +8 -8
- package/dist/esm/tools/annotation/RectangleROITool.js +11 -11
- package/dist/esm/tools/annotation/SplineROITool.js +6 -6
- package/dist/esm/tools/index.d.ts +1 -3
- package/dist/esm/tools/index.js +1 -3
- package/dist/esm/tools/segmentation/BrushTool.d.ts +38 -0
- package/dist/esm/tools/segmentation/BrushTool.js +40 -7
- package/dist/esm/tools/segmentation/CircleROIStartEndThresholdTool.js +8 -8
- package/dist/esm/tools/segmentation/RectangleROIStartEndThresholdTool.js +8 -8
- package/dist/esm/tools/segmentation/strategies/BrushStrategy.js +10 -5
- package/dist/esm/tools/segmentation/strategies/compositions/islandRemoval.js +1 -1
- package/dist/esm/tools/segmentation/strategies/compositions/preview.js +2 -2
- package/dist/esm/tools/segmentation/strategies/compositions/setValue.js +6 -4
- package/dist/esm/tools/segmentation/strategies/fillSphere.js +5 -14
- package/dist/esm/types/LabelmapToolOperationData.d.ts +5 -0
- package/dist/esm/types/ToolSpecificAnnotationTypes.d.ts +2 -2
- package/dist/esm/utilities/contours/generateContourSetsFromLabelmap.js +7 -7
- package/dist/esm/utilities/getCalibratedUnits.d.ts +2 -2
- package/dist/esm/utilities/getCalibratedUnits.js +13 -13
- package/dist/esm/utilities/segmentation/getSegmentIndexAtLabelmapBorder.js +7 -3
- package/dist/esm/utilities/segmentation/isLineInSegment.js +3 -3
- package/dist/umd/index.js +1 -1
- package/dist/umd/index.js.map +1 -1
- package/package.json +3 -3
- package/dist/esm/tools/StackScrollToolMouseWheelTool.d.ts +0 -16
- package/dist/esm/tools/StackScrollToolMouseWheelTool.js +0 -33
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import StrategyCallbacks from '../../../../enums/StrategyCallbacks';
|
|
2
|
+
import { triggerEvent, eventTarget } from '@cornerstonejs/core';
|
|
2
3
|
export default {
|
|
3
4
|
[StrategyCallbacks.INTERNAL_setValue]: (operationData, { value, index }) => {
|
|
4
|
-
const { segmentsLocked, segmentIndex, previewVoxelManager, previewSegmentIndex, segmentationVoxelManager, } = operationData;
|
|
5
|
+
const { segmentsLocked, segmentIndex, previewVoxelManager, previewSegmentIndex, segmentationVoxelManager, segmentationId, } = operationData;
|
|
5
6
|
const existingValue = segmentationVoxelManager.getAtIndex(index);
|
|
7
|
+
let changed = false;
|
|
6
8
|
if (segmentIndex === null) {
|
|
7
9
|
const oldValue = previewVoxelManager.getAtIndex(index);
|
|
8
10
|
if (oldValue !== undefined) {
|
|
9
|
-
previewVoxelManager.setAtIndex(index, oldValue);
|
|
11
|
+
changed = previewVoxelManager.setAtIndex(index, oldValue);
|
|
10
12
|
}
|
|
11
13
|
return;
|
|
12
14
|
}
|
|
@@ -15,13 +17,13 @@ export default {
|
|
|
15
17
|
}
|
|
16
18
|
if (existingValue === previewSegmentIndex) {
|
|
17
19
|
if (previewVoxelManager.getAtIndex(index) === undefined) {
|
|
18
|
-
segmentationVoxelManager.setAtIndex(index, segmentIndex);
|
|
20
|
+
changed = segmentationVoxelManager.setAtIndex(index, segmentIndex);
|
|
19
21
|
}
|
|
20
22
|
else {
|
|
21
23
|
return;
|
|
22
24
|
}
|
|
23
25
|
}
|
|
24
26
|
const useSegmentIndex = previewSegmentIndex ?? segmentIndex;
|
|
25
|
-
previewVoxelManager.setAtIndex(index, useSegmentIndex);
|
|
27
|
+
changed = previewVoxelManager.setAtIndex(index, useSegmentIndex);
|
|
26
28
|
},
|
|
27
29
|
};
|
|
@@ -21,20 +21,11 @@ const sphereComposition = {
|
|
|
21
21
|
operationData.centerIJK = transformWorldToIndex(segmentationImageData, center);
|
|
22
22
|
const { boundsIJK: newBoundsIJK, topLeftWorld, bottomRightWorld, } = getSphereBoundsInfo(points.slice(0, 2), segmentationImageData, viewport);
|
|
23
23
|
segmentationVoxelManager.boundsIJK = newBoundsIJK;
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
else {
|
|
32
|
-
segmentationVoxelManager.isInObject = createEllipseInPoint({
|
|
33
|
-
topLeftWorld,
|
|
34
|
-
bottomRightWorld,
|
|
35
|
-
center,
|
|
36
|
-
});
|
|
37
|
-
}
|
|
24
|
+
segmentationVoxelManager.isInObject = createEllipseInPoint({
|
|
25
|
+
topLeftWorld,
|
|
26
|
+
bottomRightWorld,
|
|
27
|
+
center,
|
|
28
|
+
});
|
|
38
29
|
},
|
|
39
30
|
};
|
|
40
31
|
const SPHERE_STRATEGY = new BrushStrategy('Sphere', compositions.regionFill, compositions.setValue, sphereComposition, compositions.determineSegmentIndex, compositions.preview);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Types } from '@cornerstonejs/core';
|
|
2
2
|
import type { LabelmapSegmentationDataStack, LabelmapSegmentationDataVolume } from './LabelmapTypes';
|
|
3
|
+
import type vtkImageData from '@kitware/vtk.js/Common/DataModel/ImageData';
|
|
3
4
|
type LabelmapToolOperationData = {
|
|
4
5
|
segmentationId: string;
|
|
5
6
|
segmentIndex: number;
|
|
@@ -11,6 +12,10 @@ type LabelmapToolOperationData = {
|
|
|
11
12
|
segmentationRepresentationUID: string;
|
|
12
13
|
points: Types.Point3[];
|
|
13
14
|
voxelManager: any;
|
|
15
|
+
override: {
|
|
16
|
+
voxelManager: Types.IVoxelManager<number>;
|
|
17
|
+
imageData: vtkImageData;
|
|
18
|
+
};
|
|
14
19
|
preview: any;
|
|
15
20
|
toolGroupId: string;
|
|
16
21
|
};
|
|
@@ -7,7 +7,7 @@ export interface ROICachedStats {
|
|
|
7
7
|
[targetId: string]: {
|
|
8
8
|
Modality: string;
|
|
9
9
|
area: number;
|
|
10
|
-
|
|
10
|
+
areaUnit: string;
|
|
11
11
|
max: number;
|
|
12
12
|
mean: number;
|
|
13
13
|
stdDev: number;
|
|
@@ -130,7 +130,7 @@ export type SplineROIAnnotation = ContourAnnotation & {
|
|
|
130
130
|
[targetId: string]: {
|
|
131
131
|
Modality: string;
|
|
132
132
|
area: number;
|
|
133
|
-
|
|
133
|
+
areaUnit: string;
|
|
134
134
|
};
|
|
135
135
|
};
|
|
136
136
|
};
|
|
@@ -15,13 +15,13 @@ function generateContourSetsFromLabelmap({ segmentations }) {
|
|
|
15
15
|
return;
|
|
16
16
|
}
|
|
17
17
|
const numSlices = vol.dimensions[2];
|
|
18
|
-
const
|
|
18
|
+
const voxelManager = vol.voxelManager;
|
|
19
19
|
const pixelsPerSlice = vol.dimensions[0] * vol.dimensions[1];
|
|
20
20
|
for (let z = 0; z < numSlices; z++) {
|
|
21
21
|
for (let y = 0; y < vol.dimensions[1]; y++) {
|
|
22
22
|
const index = y * vol.dimensions[0] + z * pixelsPerSlice;
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
voxelManager.setAtIndex(index, 0);
|
|
24
|
+
voxelManager.setAtIndex(index + vol.dimensions[0] - 1, 0);
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
const ContourSets = [];
|
|
@@ -41,13 +41,13 @@ function generateContourSetsFromLabelmap({ segmentations }) {
|
|
|
41
41
|
});
|
|
42
42
|
const { containedSegmentIndices } = segment;
|
|
43
43
|
for (let sliceIndex = 0; sliceIndex < numSlices; sliceIndex++) {
|
|
44
|
-
if (isSliceEmptyForSegment(sliceIndex,
|
|
44
|
+
if (isSliceEmptyForSegment(sliceIndex, voxelManager, pixelsPerSlice, segIndex)) {
|
|
45
45
|
continue;
|
|
46
46
|
}
|
|
47
47
|
const frameStart = sliceIndex * pixelsPerSlice;
|
|
48
48
|
try {
|
|
49
49
|
for (let i = 0; i < pixelsPerSlice; i++) {
|
|
50
|
-
const value =
|
|
50
|
+
const value = voxelManager.getAtIndex(i + frameStart);
|
|
51
51
|
if (value === segIndex || containedSegmentIndices?.has(value)) {
|
|
52
52
|
scalars.setValue(i + frameStart, 1);
|
|
53
53
|
}
|
|
@@ -96,11 +96,11 @@ function generateContourSetsFromLabelmap({ segmentations }) {
|
|
|
96
96
|
}
|
|
97
97
|
return ContourSets;
|
|
98
98
|
}
|
|
99
|
-
function isSliceEmptyForSegment(sliceIndex,
|
|
99
|
+
function isSliceEmptyForSegment(sliceIndex, voxelManager, pixelsPerSlice, segIndex) {
|
|
100
100
|
const startIdx = sliceIndex * pixelsPerSlice;
|
|
101
101
|
const endIdx = startIdx + pixelsPerSlice;
|
|
102
102
|
for (let i = startIdx; i < endIdx; i++) {
|
|
103
|
-
if (
|
|
103
|
+
if (voxelManager.getAtIndex(i) === segIndex) {
|
|
104
104
|
return false;
|
|
105
105
|
}
|
|
106
106
|
}
|
|
@@ -27,16 +27,16 @@ const EPS = 1e-3;
|
|
|
27
27
|
const SQUARE = '\xb2';
|
|
28
28
|
const getCalibratedLengthUnitsAndScale = (image, handles) => {
|
|
29
29
|
const { calibration, hasPixelSpacing } = image;
|
|
30
|
-
let
|
|
31
|
-
let
|
|
30
|
+
let unit = hasPixelSpacing ? 'mm' : PIXEL_UNITS;
|
|
31
|
+
let areaUnit = unit + SQUARE;
|
|
32
32
|
let scale = 1;
|
|
33
33
|
let calibrationType = '';
|
|
34
34
|
if (!calibration ||
|
|
35
35
|
(!calibration.type && !calibration.sequenceOfUltrasoundRegions)) {
|
|
36
|
-
return {
|
|
36
|
+
return { unit, areaUnit, scale };
|
|
37
37
|
}
|
|
38
38
|
if (calibration.type === CalibrationTypes.UNCALIBRATED) {
|
|
39
|
-
return {
|
|
39
|
+
return { unit: PIXEL_UNITS, areaUnit: PIXEL_UNITS + SQUARE, scale };
|
|
40
40
|
}
|
|
41
41
|
if (calibration.sequenceOfUltrasoundRegions) {
|
|
42
42
|
let imageIndex1, imageIndex2;
|
|
@@ -57,14 +57,14 @@ const getCalibratedLengthUnitsAndScale = (image, handles) => {
|
|
|
57
57
|
imageIndex2[1] >= region.regionLocationMinY0 &&
|
|
58
58
|
imageIndex2[1] <= region.regionLocationMaxY1);
|
|
59
59
|
if (!regions?.length) {
|
|
60
|
-
return {
|
|
60
|
+
return { unit, areaUnit, scale };
|
|
61
61
|
}
|
|
62
62
|
regions = regions.filter((region) => SUPPORTED_REGION_DATA_TYPES.includes(region.regionDataType) &&
|
|
63
63
|
SUPPORTED_LENGTH_VARIANT.includes(`${region.physicalUnitsXDirection},${region.physicalUnitsYDirection}`));
|
|
64
64
|
if (!regions.length) {
|
|
65
65
|
return {
|
|
66
|
-
|
|
67
|
-
|
|
66
|
+
unit: PIXEL_UNITS,
|
|
67
|
+
areaUnit: PIXEL_UNITS + SQUARE,
|
|
68
68
|
scale,
|
|
69
69
|
};
|
|
70
70
|
}
|
|
@@ -75,13 +75,13 @@ const getCalibratedLengthUnitsAndScale = (image, handles) => {
|
|
|
75
75
|
if (isSamePhysicalDelta) {
|
|
76
76
|
scale = 1 / physicalDeltaX;
|
|
77
77
|
calibrationType = 'US Region';
|
|
78
|
-
|
|
79
|
-
|
|
78
|
+
unit = UNIT_MAPPING[region.physicalUnitsXDirection] || 'unknown';
|
|
79
|
+
areaUnit = unit + SQUARE;
|
|
80
80
|
}
|
|
81
81
|
else {
|
|
82
82
|
return {
|
|
83
|
-
|
|
84
|
-
|
|
83
|
+
unit: PIXEL_UNITS,
|
|
84
|
+
areaUnit: PIXEL_UNITS + SQUARE,
|
|
85
85
|
scale,
|
|
86
86
|
};
|
|
87
87
|
}
|
|
@@ -99,8 +99,8 @@ const getCalibratedLengthUnitsAndScale = (image, handles) => {
|
|
|
99
99
|
calibrationType = calibration.type;
|
|
100
100
|
}
|
|
101
101
|
return {
|
|
102
|
-
|
|
103
|
-
|
|
102
|
+
unit: unit + (calibrationType ? ` ${calibrationType}` : ''),
|
|
103
|
+
areaUnit: areaUnit + (calibrationType ? ` ${calibrationType}` : ''),
|
|
104
104
|
scale,
|
|
105
105
|
};
|
|
106
106
|
};
|
|
@@ -4,14 +4,16 @@ import { isVolumeSegmentation } from '../../tools/segmentation/strategies/utils/
|
|
|
4
4
|
export function getSegmentIndexAtLabelmapBorder(segmentationId, worldPoint, { viewport, searchRadius }) {
|
|
5
5
|
const segmentation = getSegmentation(segmentationId);
|
|
6
6
|
const labelmapData = segmentation.representationData.LABELMAP;
|
|
7
|
-
if (isVolumeSegmentation(labelmapData)) {
|
|
7
|
+
if (isVolumeSegmentation(labelmapData, viewport)) {
|
|
8
8
|
const { volumeId } = labelmapData;
|
|
9
9
|
const segmentationVolume = cache.getVolume(volumeId);
|
|
10
10
|
if (!segmentationVolume) {
|
|
11
11
|
return;
|
|
12
12
|
}
|
|
13
|
+
const voxelManager = segmentationVolume.voxelManager;
|
|
13
14
|
const imageData = segmentationVolume.imageData;
|
|
14
|
-
const
|
|
15
|
+
const indexIJK = utilities.transformWorldToIndex(imageData, worldPoint);
|
|
16
|
+
const segmentIndex = voxelManager.getAtIJK(indexIJK[0], indexIJK[1], indexIJK[2]);
|
|
15
17
|
const canvasPoint = viewport.worldToCanvas(worldPoint);
|
|
16
18
|
const onEdge = isSegmentOnEdgeCanvas(canvasPoint, segmentIndex, viewport, imageData, searchRadius);
|
|
17
19
|
return onEdge ? segmentIndex : undefined;
|
|
@@ -69,7 +71,9 @@ function isSegmentOnEdgeCanvas(canvasPoint, segmentIndex, viewport, imageData, s
|
|
|
69
71
|
const getNeighborIndex = (deltaI, deltaJ) => {
|
|
70
72
|
const neighborCanvas = [canvasPoint[0] + deltaI, canvasPoint[1] + deltaJ];
|
|
71
73
|
const worldPoint = viewport.canvasToWorld(neighborCanvas);
|
|
72
|
-
|
|
74
|
+
const voxelManager = imageData.get('voxelManager').voxelManager;
|
|
75
|
+
const indexIJK = utilities.transformWorldToIndex(imageData, worldPoint);
|
|
76
|
+
return voxelManager.getAtIJK(indexIJK[0], indexIJK[1], indexIJK[2]);
|
|
73
77
|
};
|
|
74
78
|
return isSegmentOnEdge(getNeighborIndex, segmentIndex, searchRadius);
|
|
75
79
|
}
|
|
@@ -25,7 +25,7 @@ function createIsInSegment(segVolumeId, segmentIndex, containedSegmentIndices) {
|
|
|
25
25
|
console.warn(`No volume found for ${segVolumeId}`);
|
|
26
26
|
return;
|
|
27
27
|
}
|
|
28
|
-
const
|
|
28
|
+
const voxelManager = vol.voxelManager;
|
|
29
29
|
const width = vol.dimensions[0];
|
|
30
30
|
const pixelsPerSlice = width * vol.dimensions[1];
|
|
31
31
|
return {
|
|
@@ -34,14 +34,14 @@ function createIsInSegment(segVolumeId, segmentIndex, containedSegmentIndices) {
|
|
|
34
34
|
const ijk = vol.imageData.worldToIndex(point).map(Math.round);
|
|
35
35
|
const [i, j, k] = ijk;
|
|
36
36
|
const index = i + j * width + k * pixelsPerSlice;
|
|
37
|
-
const value =
|
|
37
|
+
const value = voxelManager.getAtIndex(index);
|
|
38
38
|
return value === segmentIndex || containedSegmentIndices?.has(value);
|
|
39
39
|
},
|
|
40
40
|
toIJK: (point) => vol.imageData.worldToIndex(point),
|
|
41
41
|
testIJK: (ijk) => {
|
|
42
42
|
const [i, j, k] = ijk;
|
|
43
43
|
const index = Math.round(i) + Math.round(j) * width + Math.round(k) * pixelsPerSlice;
|
|
44
|
-
const value =
|
|
44
|
+
const value = voxelManager.getAtIndex(index);
|
|
45
45
|
return value === segmentIndex || containedSegmentIndices?.has(value);
|
|
46
46
|
},
|
|
47
47
|
};
|