@cornerstonejs/tools 3.7.1 → 3.7.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/tools/annotation/UltrasoundDirectionalTool.js +21 -0
- package/dist/esm/tools/base/AnnotationTool.js +1 -1
- package/dist/esm/tools/segmentation/LabelmapBaseTool.js +17 -3
- package/dist/esm/tools/segmentation/strategies/BrushStrategy.d.ts +1 -0
- package/dist/esm/tools/segmentation/strategies/BrushStrategy.js +1 -1
- package/dist/esm/tools/segmentation/strategies/compositions/preview.js +4 -18
- package/dist/esm/types/LabelmapToolOperationData.d.ts +1 -1
- package/dist/esm/utilities/index.d.ts +2 -1
- package/dist/esm/utilities/index.js +2 -1
- package/dist/esm/utilities/moveAnnotationToViewPlane.d.ts +3 -0
- package/dist/esm/utilities/moveAnnotationToViewPlane.js +15 -0
- package/package.json +3 -3
|
@@ -11,6 +11,7 @@ import { distanceToPoint } from '../../utilities/math/point';
|
|
|
11
11
|
import triggerAnnotationRenderForViewportIds from '../../utilities/triggerAnnotationRenderForViewportIds';
|
|
12
12
|
import { resetElementCursor, hideElementCursor, } from '../../cursors/elementCursor';
|
|
13
13
|
import { getCalibratedProbeUnitsAndValue } from '../../utilities/getCalibratedUnits';
|
|
14
|
+
import { lineSegment } from '../../utilities/math';
|
|
14
15
|
const { transformWorldToIndex } = csUtils;
|
|
15
16
|
class UltrasoundDirectionalTool extends AnnotationTool {
|
|
16
17
|
static { this.toolName = 'UltrasoundDirectionalTool'; }
|
|
@@ -88,6 +89,26 @@ class UltrasoundDirectionalTool extends AnnotationTool {
|
|
|
88
89
|
return annotation;
|
|
89
90
|
};
|
|
90
91
|
this.isPointNearTool = (element, annotation, canvasCoords, proximity) => {
|
|
92
|
+
const enabledElement = getEnabledElement(element);
|
|
93
|
+
const { viewport } = enabledElement;
|
|
94
|
+
const { data } = annotation;
|
|
95
|
+
const [point1, point2] = data.handles.points;
|
|
96
|
+
const canvasPoint1 = viewport.worldToCanvas(point1);
|
|
97
|
+
const canvasPoint2 = viewport.worldToCanvas(point2);
|
|
98
|
+
const line = {
|
|
99
|
+
start: {
|
|
100
|
+
x: canvasPoint1[0],
|
|
101
|
+
y: canvasPoint1[1],
|
|
102
|
+
},
|
|
103
|
+
end: {
|
|
104
|
+
x: canvasPoint2[0],
|
|
105
|
+
y: canvasPoint2[1],
|
|
106
|
+
},
|
|
107
|
+
};
|
|
108
|
+
const distanceToPoint = lineSegment.distanceToPoint([line.start.x, line.start.y], [line.end.x, line.end.y], [canvasCoords[0], canvasCoords[1]]);
|
|
109
|
+
if (distanceToPoint <= proximity) {
|
|
110
|
+
return true;
|
|
111
|
+
}
|
|
91
112
|
return false;
|
|
92
113
|
};
|
|
93
114
|
this._endCallback = (evt) => {
|
|
@@ -287,7 +287,7 @@ class AnnotationTool extends AnnotationDisplayTool {
|
|
|
287
287
|
else {
|
|
288
288
|
if (viewport instanceof StackViewport) {
|
|
289
289
|
const closestImageIndex = csUtils.getClosestStackImageIndexForPoint(points[0], viewport);
|
|
290
|
-
if (closestImageIndex) {
|
|
290
|
+
if (closestImageIndex !== undefined) {
|
|
291
291
|
referencedImageId = viewport.getImageIds()[closestImageIndex];
|
|
292
292
|
}
|
|
293
293
|
}
|
|
@@ -148,19 +148,25 @@ export default class LabelmapBaseTool extends BaseTool {
|
|
|
148
148
|
const { segmentIndex, segmentationId, brushCursor } = this._hoverData || this.createHoverData(element);
|
|
149
149
|
const { data, metadata = {} } = brushCursor || {};
|
|
150
150
|
const { viewPlaneNormal, viewUp } = metadata;
|
|
151
|
+
const configColor = this.configuration.preview?.previewColors?.[segmentIndex];
|
|
152
|
+
const { viewport } = getEnabledElement(element);
|
|
153
|
+
const segmentColor = getSegmentIndexColor(viewport.id, segmentationId, segmentIndex);
|
|
154
|
+
if (!configColor && !segmentColor) {
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
151
157
|
const operationData = {
|
|
152
158
|
...editData,
|
|
153
159
|
points: data?.handles?.points,
|
|
154
160
|
segmentIndex,
|
|
155
|
-
previewColors: this.configuration.preview?.enabled || this._previewData.preview
|
|
156
|
-
? this.configuration.preview?.previewColors
|
|
157
|
-
: null,
|
|
158
161
|
viewPlaneNormal,
|
|
159
162
|
toolGroupId: this.toolGroupId,
|
|
160
163
|
segmentationId,
|
|
161
164
|
viewUp,
|
|
162
165
|
activeStrategy: this.configuration.activeStrategy,
|
|
163
166
|
configuration: this.configuration,
|
|
167
|
+
previewColor: this.configuration.preview.enabled
|
|
168
|
+
? configColor || lightenColor(...segmentColor)
|
|
169
|
+
: null,
|
|
164
170
|
preview: this._previewData?.preview,
|
|
165
171
|
createMemo: this.createMemo.bind(this),
|
|
166
172
|
};
|
|
@@ -287,3 +293,11 @@ export default class LabelmapBaseTool extends BaseTool {
|
|
|
287
293
|
triggerSegmentationDataModified(segmentationId, slices);
|
|
288
294
|
}
|
|
289
295
|
}
|
|
296
|
+
function lightenColor(r, g, b, a, factor = 0.4) {
|
|
297
|
+
return [
|
|
298
|
+
Math.round(r + (255 - r) * factor),
|
|
299
|
+
Math.round(g + (255 - g) * factor),
|
|
300
|
+
Math.round(b + (255 - b) * factor),
|
|
301
|
+
a,
|
|
302
|
+
];
|
|
303
|
+
}
|
|
@@ -16,6 +16,7 @@ export type InitializedOperationData = LabelmapToolOperationDataAny & {
|
|
|
16
16
|
segmentationImageData: vtkImageData;
|
|
17
17
|
previewVoxelManager: Types.IVoxelManager<number>;
|
|
18
18
|
previewSegmentIndex?: number;
|
|
19
|
+
previewColor?: [number, number, number, number];
|
|
19
20
|
brushStrategy: BrushStrategy;
|
|
20
21
|
activeStrategy: string;
|
|
21
22
|
configuration?: {
|
|
@@ -100,7 +100,7 @@ export default class BrushStrategy {
|
|
|
100
100
|
const { imageVoxelManager, segmentationVoxelManager, segmentationImageData, } = data;
|
|
101
101
|
const previewVoxelManager = operationData.preview?.previewVoxelManager ||
|
|
102
102
|
VoxelManager.createRLEHistoryVoxelManager(segmentationVoxelManager);
|
|
103
|
-
const previewEnabled = !!operationData.
|
|
103
|
+
const previewEnabled = !!operationData.previewColor;
|
|
104
104
|
const previewSegmentIndex = previewEnabled ? 255 : undefined;
|
|
105
105
|
const initializedData = {
|
|
106
106
|
operationName,
|
|
@@ -2,18 +2,10 @@ import { triggerSegmentationDataModified } from '../../../../stateManagement/seg
|
|
|
2
2
|
import StrategyCallbacks from '../../../../enums/StrategyCallbacks';
|
|
3
3
|
import { getSegmentIndexColor, setSegmentIndexColor, } from '../../../../stateManagement/segmentation/config/segmentationColor';
|
|
4
4
|
import { getViewportIdsWithSegmentation } from '../../../../stateManagement/segmentation/getViewportIdsWithSegmentation';
|
|
5
|
-
function lightenColor(r, g, b, a, factor = 0.4) {
|
|
6
|
-
return [
|
|
7
|
-
Math.round(r + (255 - r) * factor),
|
|
8
|
-
Math.round(g + (255 - g) * factor),
|
|
9
|
-
Math.round(b + (255 - b) * factor),
|
|
10
|
-
a,
|
|
11
|
-
];
|
|
12
|
-
}
|
|
13
5
|
export default {
|
|
14
6
|
[StrategyCallbacks.Preview]: function (operationData) {
|
|
15
|
-
const {
|
|
16
|
-
if (!
|
|
7
|
+
const { previewColor, configuration, enabledElement } = operationData;
|
|
8
|
+
if (!previewColor || !configuration) {
|
|
17
9
|
return;
|
|
18
10
|
}
|
|
19
11
|
if (operationData.preview) {
|
|
@@ -30,8 +22,8 @@ export default {
|
|
|
30
22
|
return preview;
|
|
31
23
|
},
|
|
32
24
|
[StrategyCallbacks.Initialize]: (operationData) => {
|
|
33
|
-
const { segmentIndex, previewSegmentIndex,
|
|
34
|
-
if (
|
|
25
|
+
const { segmentIndex, previewSegmentIndex, previewColor, preview, segmentationId, segmentationVoxelManager, } = operationData;
|
|
26
|
+
if (previewColor === undefined || !previewSegmentIndex) {
|
|
35
27
|
operationData.memo = operationData.createMemo(segmentationId, segmentationVoxelManager);
|
|
36
28
|
return;
|
|
37
29
|
}
|
|
@@ -43,12 +35,6 @@ export default {
|
|
|
43
35
|
if (segmentIndex === null) {
|
|
44
36
|
return;
|
|
45
37
|
}
|
|
46
|
-
const configColor = previewColors?.[segmentIndex];
|
|
47
|
-
const segmentColor = getSegmentIndexColor(operationData.viewport.id, operationData.segmentationId, segmentIndex);
|
|
48
|
-
if (!configColor && !segmentColor) {
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
const previewColor = configColor || lightenColor(...segmentColor);
|
|
52
38
|
const viewportIds = getViewportIdsWithSegmentation(operationData.segmentationId);
|
|
53
39
|
viewportIds?.forEach((viewportId) => {
|
|
54
40
|
setSegmentIndexColor(viewportId, operationData.segmentationId, previewSegmentIndex, previewColor);
|
|
@@ -5,7 +5,7 @@ import type { LabelmapMemo } from '../utilities/segmentation/createLabelmapMemo'
|
|
|
5
5
|
type LabelmapToolOperationData = {
|
|
6
6
|
segmentationId: string;
|
|
7
7
|
segmentIndex: number;
|
|
8
|
-
|
|
8
|
+
previewColor?: [number, number, number, number];
|
|
9
9
|
segmentsLocked: number[];
|
|
10
10
|
viewPlaneNormal: number[];
|
|
11
11
|
viewUp: number[];
|
|
@@ -38,4 +38,5 @@ import IslandRemoval from './segmentation/islandRemoval';
|
|
|
38
38
|
import { getPixelValueUnits, getPixelValueUnitsImageId } from './getPixelValueUnits';
|
|
39
39
|
import * as geometricSurfaceUtils from './geometricSurfaceUtils';
|
|
40
40
|
import setAnnotationLabel from './setAnnotationLabel';
|
|
41
|
-
|
|
41
|
+
import { moveAnnotationToViewPlane } from './moveAnnotationToViewPlane';
|
|
42
|
+
export { math, planar, viewportFilters, drawing, debounce, dynamicVolume, throttle, orientation, isObject, touch, triggerEvent, calibrateImageSpacing, getCalibratedLengthUnitsAndScale, getCalibratedProbeUnitsAndValue, getCalibratedAspect, getPixelValueUnits, getPixelValueUnitsImageId, segmentation, contours, triggerAnnotationRenderForViewportIds, triggerAnnotationRenderForToolGroupIds, triggerAnnotationRender, getSphereBoundsInfo, getAnnotationNearPoint, getViewportForAnnotation, getAnnotationNearPointOnEnabledElement, viewport, cine, boundingBox, rectangleROITool, planarFreehandROITool, stackPrefetch, stackContextPrefetch, roundNumber, pointToString, polyDataUtils, voi, AnnotationMultiSlice, contourSegmentation, annotationHydration, getClosestImageIdForStackViewport, pointInSurroundingSphereCallback, normalizeViewportPlane, IslandRemoval, geometricSurfaceUtils, setAnnotationLabel, moveAnnotationToViewPlane, };
|
|
@@ -38,4 +38,5 @@ import IslandRemoval from './segmentation/islandRemoval';
|
|
|
38
38
|
import { getPixelValueUnits, getPixelValueUnitsImageId, } from './getPixelValueUnits';
|
|
39
39
|
import * as geometricSurfaceUtils from './geometricSurfaceUtils';
|
|
40
40
|
import setAnnotationLabel from './setAnnotationLabel';
|
|
41
|
-
|
|
41
|
+
import { moveAnnotationToViewPlane } from './moveAnnotationToViewPlane';
|
|
42
|
+
export { math, planar, viewportFilters, drawing, debounce, dynamicVolume, throttle, orientation, isObject, touch, triggerEvent, calibrateImageSpacing, getCalibratedLengthUnitsAndScale, getCalibratedProbeUnitsAndValue, getCalibratedAspect, getPixelValueUnits, getPixelValueUnitsImageId, segmentation, contours, triggerAnnotationRenderForViewportIds, triggerAnnotationRenderForToolGroupIds, triggerAnnotationRender, getSphereBoundsInfo, getAnnotationNearPoint, getViewportForAnnotation, getAnnotationNearPointOnEnabledElement, viewport, cine, boundingBox, rectangleROITool, planarFreehandROITool, stackPrefetch, stackContextPrefetch, roundNumber, pointToString, polyDataUtils, voi, AnnotationMultiSlice, contourSegmentation, annotationHydration, getClosestImageIdForStackViewport, pointInSurroundingSphereCallback, normalizeViewportPlane, IslandRemoval, geometricSurfaceUtils, setAnnotationLabel, moveAnnotationToViewPlane, };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { StackViewport } from '@cornerstonejs/core';
|
|
2
|
+
import * as vec3 from 'gl-matrix/vec3';
|
|
3
|
+
export function moveAnnotationToViewPlane(annotation, viewport) {
|
|
4
|
+
const { data } = annotation;
|
|
5
|
+
const { points } = data.handles;
|
|
6
|
+
const { focalPoint, viewPlaneNormal } = viewport.getCamera();
|
|
7
|
+
const projectedDistance = vec3.dot(vec3.sub(vec3.create(), points[0], focalPoint), viewPlaneNormal);
|
|
8
|
+
points.forEach((point) => {
|
|
9
|
+
vec3.add(point, point, vec3.scale(vec3.create(), [-viewPlaneNormal[0], -viewPlaneNormal[1], -viewPlaneNormal[2]], projectedDistance));
|
|
10
|
+
});
|
|
11
|
+
if (viewport instanceof StackViewport) {
|
|
12
|
+
annotation.metadata.referencedImageId = viewport.getCurrentImageId();
|
|
13
|
+
}
|
|
14
|
+
return annotation;
|
|
15
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cornerstonejs/tools",
|
|
3
|
-
"version": "3.7.
|
|
3
|
+
"version": "3.7.3",
|
|
4
4
|
"description": "Cornerstone3D Tools",
|
|
5
5
|
"types": "./dist/esm/index.d.ts",
|
|
6
6
|
"module": "./dist/esm/index.js",
|
|
@@ -103,7 +103,7 @@
|
|
|
103
103
|
"canvas": "^2.11.2"
|
|
104
104
|
},
|
|
105
105
|
"peerDependencies": {
|
|
106
|
-
"@cornerstonejs/core": "^3.7.
|
|
106
|
+
"@cornerstonejs/core": "^3.7.3",
|
|
107
107
|
"@kitware/vtk.js": "32.12.1",
|
|
108
108
|
"@types/d3-array": "^3.0.4",
|
|
109
109
|
"@types/d3-interpolate": "^3.0.1",
|
|
@@ -122,5 +122,5 @@
|
|
|
122
122
|
"type": "individual",
|
|
123
123
|
"url": "https://ohif.org/donate"
|
|
124
124
|
},
|
|
125
|
-
"gitHead": "
|
|
125
|
+
"gitHead": "319a7741f4757201093d6b234a92dc6278d26f66"
|
|
126
126
|
}
|