@cornerstonejs/tools 5.10.3 → 5.10.5
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/stateManagement/segmentation/helpers/isSegmentationOverlayCompatible.js +13 -2
- package/dist/esm/tools/displayTools/Surface/surfaceDisplay.js +8 -3
- package/dist/esm/tools/segmentation/RectangleScissorsTool.js +3 -0
- package/dist/esm/tools/segmentation/strategies/BrushStrategy.d.ts +2 -0
- package/dist/esm/tools/segmentation/strategies/compositions/regionFill.js +12 -6
- package/dist/esm/tools/segmentation/strategies/fillCircle.d.ts +5 -0
- package/dist/esm/tools/segmentation/strategies/fillCircle.js +63 -21
- package/dist/esm/tools/segmentation/strategies/fillRectangle.d.ts +2 -0
- package/dist/esm/tools/segmentation/strategies/fillRectangle.js +79 -26
- package/dist/esm/tools/segmentation/strategies/fillSphere.js +46 -52
- package/dist/esm/tools/segmentation/strategies/utils/brushVoxelSlab.d.ts +59 -0
- package/dist/esm/tools/segmentation/strategies/utils/brushVoxelSlab.js +254 -0
- package/dist/esm/utilities/genericViewportToolHelpers.d.ts +1 -0
- package/dist/esm/utilities/genericViewportToolHelpers.js +7 -0
- package/dist/esm/utilities/index.d.ts +2 -2
- package/dist/esm/utilities/index.js +2 -2
- package/dist/esm/utilities/sampleAreaAnnotationVoxels.d.ts +1 -0
- package/dist/esm/utilities/sampleAreaAnnotationVoxels.js +2 -2
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/package.json +3 -3
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { cache, metaData } from '@cornerstonejs/core';
|
|
1
|
+
import { Enums, cache, metaData } from '@cornerstonejs/core';
|
|
2
2
|
import { SegmentationRepresentations } from '../../../enums/index.js';
|
|
3
3
|
import { getSegmentation } from '../getSegmentation.js';
|
|
4
4
|
import { getLabelmaps } from '../labelmapModel/index.js';
|
|
@@ -67,6 +67,14 @@ function stackViewportReferencesImages(viewport, layers) {
|
|
|
67
67
|
const referencedImageIdSet = new Set(referencedImageIds);
|
|
68
68
|
return viewportImageIds.some((imageId) => referencedImageIdSet.has(imageId));
|
|
69
69
|
}
|
|
70
|
+
function mountsAVolume(viewport) {
|
|
71
|
+
try {
|
|
72
|
+
return (viewport.getAllVolumeIds?.() ?? []).length > 0;
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
70
78
|
export function isSegmentationOverlayCompatible(viewport, segmentationId, representationType) {
|
|
71
79
|
if (representationType !== SegmentationRepresentations.Labelmap) {
|
|
72
80
|
return true;
|
|
@@ -79,8 +87,11 @@ export function isSegmentationOverlayCompatible(viewport, segmentationId, repres
|
|
|
79
87
|
return true;
|
|
80
88
|
}
|
|
81
89
|
const layers = getLabelmaps(segmentation);
|
|
82
|
-
const
|
|
90
|
+
const exposesVolumeApi = typeof viewport
|
|
83
91
|
.getAllVolumeIds === 'function';
|
|
92
|
+
const isVolumeViewport = exposesVolumeApi &&
|
|
93
|
+
(viewport.type !== Enums.ViewportType.PLANAR_NEXT ||
|
|
94
|
+
mountsAVolume(viewport));
|
|
84
95
|
return isVolumeViewport
|
|
85
96
|
? volumeViewportSharesFrameOfReference(viewport, layers)
|
|
86
97
|
: stackViewportReferencesImages(viewport, layers);
|
|
@@ -9,6 +9,7 @@ import { computeAndAddRepresentation } from '../../../utilities/segmentation/com
|
|
|
9
9
|
import { internalGetHiddenSegmentIndices } from '../../../stateManagement/segmentation/helpers/internalGetHiddenSegmentIndices.js';
|
|
10
10
|
import { utilities as cornerstoneUtilities } from '@cornerstonejs/core';
|
|
11
11
|
const cs3dLogger = cornerstoneUtilities.logger.toolsLog.getLogger('tools.displayTools.Surface.surfaceDisplay');
|
|
12
|
+
const polySegConversionBySegmentation = new Map();
|
|
12
13
|
function removeRepresentation(viewportId, segmentationId, renderImmediate = false) {
|
|
13
14
|
const enabledElement = getEnabledElementByViewportId(viewportId);
|
|
14
15
|
if (!enabledElement) {
|
|
@@ -31,10 +32,14 @@ async function render(viewport, representation) {
|
|
|
31
32
|
if (!SurfaceData &&
|
|
32
33
|
getPolySeg()?.canComputeRequestedRepresentation(segmentationId, Representations.Surface)) {
|
|
33
34
|
const polySeg = getPolySeg();
|
|
34
|
-
|
|
35
|
-
if (!
|
|
36
|
-
|
|
35
|
+
let conversion = polySegConversionBySegmentation.get(segmentationId);
|
|
36
|
+
if (!conversion) {
|
|
37
|
+
conversion = computeAndAddRepresentation(segmentationId, Representations.Surface, () => polySeg.computeSurfaceData(segmentationId, { viewport })).finally(() => {
|
|
38
|
+
polySegConversionBySegmentation.delete(segmentationId);
|
|
39
|
+
});
|
|
40
|
+
polySegConversionBySegmentation.set(segmentationId, conversion);
|
|
37
41
|
}
|
|
42
|
+
SurfaceData = await conversion;
|
|
38
43
|
}
|
|
39
44
|
else if (!SurfaceData && !getPolySeg()) {
|
|
40
45
|
cs3dLogger.debug(`No surface data found for segmentationId ${segmentationId} and PolySeg add-on is not configured. Unable to convert from other representations to surface. Please register PolySeg using cornerstoneTools.init({ addons: { polySeg } }) to enable automatic conversion.`);
|
|
@@ -177,6 +177,7 @@ class RectangleScissorsTool extends LabelmapBaseTool {
|
|
|
177
177
|
const { element } = eventDetail;
|
|
178
178
|
const { annotation, newAnnotation, hasMoved } = this.editData;
|
|
179
179
|
const { data } = annotation;
|
|
180
|
+
const { viewPlaneNormal, viewUp } = annotation.metadata;
|
|
180
181
|
if (newAnnotation && !hasMoved) {
|
|
181
182
|
return;
|
|
182
183
|
}
|
|
@@ -187,6 +188,8 @@ class RectangleScissorsTool extends LabelmapBaseTool {
|
|
|
187
188
|
const operationData = {
|
|
188
189
|
...this.editData,
|
|
189
190
|
points: data.handles.points,
|
|
191
|
+
viewPlaneNormal,
|
|
192
|
+
viewUp,
|
|
190
193
|
createMemo: this.createMemo.bind(this),
|
|
191
194
|
};
|
|
192
195
|
this.editData = null;
|
|
@@ -4,6 +4,7 @@ import type { LabelmapToolOperationDataAny } from '../../../types/LabelmapToolOp
|
|
|
4
4
|
import type vtkImageData from '@kitware/vtk.js/Common/DataModel/ImageData';
|
|
5
5
|
import type { LabelmapMemo } from '../../../utilities/segmentation/createLabelmapMemo.js';
|
|
6
6
|
import type { LabelmapEditTransaction } from '../../../stateManagement/segmentation/helpers/labelmapSegmentationState.js';
|
|
7
|
+
import type { BrushVoxelSlabFill } from './utils/brushVoxelSlab.js';
|
|
7
8
|
export type InitializedOperationData = LabelmapToolOperationDataAny & {
|
|
8
9
|
operationName?: string;
|
|
9
10
|
centerSegmentIndexInfo: {
|
|
@@ -17,6 +18,7 @@ export type InitializedOperationData = LabelmapToolOperationDataAny & {
|
|
|
17
18
|
centerWorld: Types.Point3;
|
|
18
19
|
isInObject: (point: Types.Point3) => boolean;
|
|
19
20
|
isInObjectBoundsIJK: Types.BoundsIJK;
|
|
21
|
+
brushVoxelSlabFill?: BrushVoxelSlabFill;
|
|
20
22
|
viewport: Types.IViewport;
|
|
21
23
|
imageVoxelManager: Types.IVoxelManager<number> | Types.IVoxelManager<Types.RGB>;
|
|
22
24
|
segmentationVoxelManager: Types.IVoxelManager<number>;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import StrategyCallbacks from '../../../../enums/StrategyCallbacks.js';
|
|
2
|
+
import { forEachBrushFillVoxel } from '../utils/brushVoxelSlab.js';
|
|
2
3
|
export default {
|
|
3
4
|
[StrategyCallbacks.Fill]: (operationData) => {
|
|
4
|
-
const { segmentsLocked, segmentationImageData, segmentationVoxelManager, brushStrategy, centerIJK, } = operationData;
|
|
5
|
+
const { segmentsLocked, segmentationImageData, segmentationVoxelManager, brushStrategy, centerIJK, brushVoxelSlabFill, } = operationData;
|
|
5
6
|
const isWithinThreshold = brushStrategy.createIsInThreshold?.(operationData);
|
|
6
7
|
const { setValue } = brushStrategy;
|
|
7
8
|
const callback = isWithinThreshold
|
|
@@ -13,11 +14,16 @@ export default {
|
|
|
13
14
|
setValue(operationData, data);
|
|
14
15
|
}
|
|
15
16
|
: (data) => setValue(operationData, data);
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
if (brushVoxelSlabFill) {
|
|
18
|
+
forEachBrushFillVoxel(brushVoxelSlabFill, segmentationVoxelManager, callback);
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
segmentationVoxelManager.forEach(callback, {
|
|
22
|
+
imageData: segmentationImageData,
|
|
23
|
+
isInObject: operationData.isInObject,
|
|
24
|
+
boundsIJK: operationData.isInObjectBoundsIJK,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
21
27
|
segmentationVoxelManager.addPoint(centerIJK);
|
|
22
28
|
},
|
|
23
29
|
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { vec3 } from 'gl-matrix';
|
|
1
2
|
import type { Types } from '@cornerstonejs/core';
|
|
2
3
|
import type vtkImageData from '@kitware/vtk.js/Common/DataModel/ImageData';
|
|
3
4
|
import BrushStrategy from './BrushStrategy.js';
|
|
@@ -9,6 +10,10 @@ declare function createPointInEllipse(cornersInWorld?: Types.Point3[], options?:
|
|
|
9
10
|
xRadius?: number;
|
|
10
11
|
yRadius?: number;
|
|
11
12
|
aspectRatio?: [number, number];
|
|
13
|
+
viewRight?: vec3;
|
|
14
|
+
viewUp?: vec3;
|
|
15
|
+
viewNormal?: vec3;
|
|
16
|
+
depthRadius?: number;
|
|
12
17
|
}): (pointLPS: Types.Point3 | null, pointIJK?: Types.Point3) => boolean;
|
|
13
18
|
declare const CIRCLE_STRATEGY: BrushStrategy;
|
|
14
19
|
declare const CIRCLE_THRESHOLD_STRATEGY: BrushStrategy;
|
|
@@ -5,6 +5,8 @@ import BrushStrategy from './BrushStrategy.js';
|
|
|
5
5
|
import { StrategyCallbacks } from '../../../enums/index.js';
|
|
6
6
|
import compositions from './compositions/index.js';
|
|
7
7
|
import { pointInSphere } from '../../../utilities/math/sphere/index.js';
|
|
8
|
+
import { applyBrushFill, createCircleBrushFill } from './utils/brushVoxelSlab.js';
|
|
9
|
+
import { getViewSlabDepthOfViewport } from '../../../utilities/genericViewportToolHelpers.js';
|
|
8
10
|
const { transformWorldToIndex, transformIndexToWorld, isEqual, getNormalizedAspectRatio, } = csUtils;
|
|
9
11
|
export function getEllipseCornersFromCanvasCoordinates(canvasCoordinates) {
|
|
10
12
|
const [bottom, top, left, right] = canvasCoordinates;
|
|
@@ -16,19 +18,23 @@ export function getEllipseCornersFromCanvasCoordinates(canvasCoordinates) {
|
|
|
16
18
|
}
|
|
17
19
|
function createCircleCornersForCenter(center, viewUp, viewRight, yRadius, xRadius) {
|
|
18
20
|
const centerVec = vec3.fromValues(center[0], center[1], center[2]);
|
|
19
|
-
const
|
|
20
|
-
vec3.scaleAndAdd(
|
|
21
|
-
|
|
22
|
-
vec3.
|
|
23
|
-
|
|
24
|
-
vec3.scaleAndAdd(
|
|
25
|
-
const
|
|
26
|
-
vec3.scaleAndAdd(
|
|
21
|
+
const topRight = vec3.create();
|
|
22
|
+
vec3.scaleAndAdd(topRight, centerVec, viewUp, yRadius);
|
|
23
|
+
vec3.scaleAndAdd(topRight, topRight, viewRight, xRadius);
|
|
24
|
+
const topLeft = vec3.create();
|
|
25
|
+
vec3.scaleAndAdd(topLeft, centerVec, viewUp, yRadius);
|
|
26
|
+
vec3.scaleAndAdd(topLeft, topLeft, viewRight, -xRadius);
|
|
27
|
+
const bottomRight = vec3.create();
|
|
28
|
+
vec3.scaleAndAdd(bottomRight, centerVec, viewUp, -yRadius);
|
|
29
|
+
vec3.scaleAndAdd(bottomRight, bottomRight, viewRight, xRadius);
|
|
30
|
+
const bottomLeft = vec3.create();
|
|
31
|
+
vec3.scaleAndAdd(bottomLeft, centerVec, viewUp, -yRadius);
|
|
32
|
+
vec3.scaleAndAdd(bottomLeft, bottomLeft, viewRight, -xRadius);
|
|
27
33
|
return [
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
34
|
+
topRight,
|
|
35
|
+
topLeft,
|
|
36
|
+
bottomRight,
|
|
37
|
+
bottomLeft,
|
|
32
38
|
];
|
|
33
39
|
}
|
|
34
40
|
function createStrokePredicate(centers, xRadius, yRadius) {
|
|
@@ -141,32 +147,59 @@ const initializeCircle = {
|
|
|
141
147
|
xRadius,
|
|
142
148
|
yRadius,
|
|
143
149
|
aspectRatio,
|
|
150
|
+
viewRight,
|
|
151
|
+
viewUp: normalizedViewUp,
|
|
152
|
+
viewNormal: normalizedPlaneNormal,
|
|
144
153
|
});
|
|
145
154
|
operationData.isInObjectBoundsIJK = boundsIJK;
|
|
155
|
+
const viewThicknessWorld = getViewSlabDepthOfViewport(viewport);
|
|
156
|
+
applyBrushFill(operationData, createCircleBrushFill({
|
|
157
|
+
segmentationImageData,
|
|
158
|
+
viewUp: normalizedViewUp,
|
|
159
|
+
viewPlaneNormal: normalizedPlaneNormal,
|
|
160
|
+
centerWorld: operationData.centerWorld,
|
|
161
|
+
xRadius,
|
|
162
|
+
yRadius,
|
|
163
|
+
strokeCentersWorld: strokeCenters,
|
|
164
|
+
viewThicknessWorld,
|
|
165
|
+
}));
|
|
146
166
|
},
|
|
147
167
|
};
|
|
148
168
|
function createPointInEllipse(cornersInWorld = [], options = {}) {
|
|
149
169
|
if (!cornersInWorld || cornersInWorld.length !== 4) {
|
|
150
170
|
throw new Error('createPointInEllipse: cornersInWorld must have 4 points');
|
|
151
171
|
}
|
|
152
|
-
const [topLeft, bottomRight,
|
|
172
|
+
const [topLeft, bottomRight, , topRight] = cornersInWorld;
|
|
153
173
|
const aspectRatio = options.aspectRatio || [1, 1];
|
|
174
|
+
const segmentationImageData = options.segmentationImageData;
|
|
175
|
+
const { viewRight, viewUp, viewNormal } = options;
|
|
176
|
+
const spacing = segmentationImageData?.getSpacing?.();
|
|
177
|
+
const direction = segmentationImageData?.getDirection?.();
|
|
178
|
+
const spacingInNormal = spacing && direction && viewNormal
|
|
179
|
+
? csUtils.getSpacingInNormalDirection({ spacing, direction }, viewNormal)
|
|
180
|
+
: spacing
|
|
181
|
+
? Math.max(...spacing, Number.EPSILON)
|
|
182
|
+
: 1;
|
|
183
|
+
const planeTolerance = Math.max(spacingInNormal / 2, Number.EPSILON);
|
|
154
184
|
const center = vec3.create();
|
|
155
185
|
vec3.add(center, topLeft, bottomRight);
|
|
156
186
|
vec3.scale(center, center, 0.5);
|
|
157
187
|
const majorAxisVec = vec3.create();
|
|
158
188
|
vec3.subtract(majorAxisVec, topRight, topLeft);
|
|
159
189
|
const originalRadius = vec3.length(majorAxisVec) / 2;
|
|
160
|
-
vec3.normalize(majorAxisVec, majorAxisVec);
|
|
161
|
-
const minorAxisVec = vec3.create();
|
|
162
|
-
vec3.subtract(minorAxisVec, bottomLeft, topLeft);
|
|
163
|
-
vec3.normalize(minorAxisVec, minorAxisVec);
|
|
164
190
|
const xRadius = originalRadius / aspectRatio[0];
|
|
165
191
|
const yRadius = originalRadius / aspectRatio[1];
|
|
192
|
+
const invXRadiusSquared = 1 / (xRadius * xRadius);
|
|
193
|
+
const invYRadiusSquared = 1 / (yRadius * yRadius);
|
|
194
|
+
const invZRadiusSquared = options.depthRadius > 0
|
|
195
|
+
? 1 / (options.depthRadius * options.depthRadius)
|
|
196
|
+
: null;
|
|
166
197
|
const xRadiusForStroke = options.xRadius ?? xRadius;
|
|
167
198
|
const yRadiusForStroke = options.yRadius ?? yRadius;
|
|
168
199
|
const strokePredicate = createStrokePredicate(options.strokePointsWorld || [], xRadiusForStroke, yRadiusForStroke);
|
|
169
|
-
|
|
200
|
+
const isSphere = isEqual(xRadius, yRadius) &&
|
|
201
|
+
(invZRadiusSquared === null || isEqual(options.depthRadius, xRadius));
|
|
202
|
+
if (isSphere) {
|
|
170
203
|
const radius = xRadius;
|
|
171
204
|
const sphereObj = {
|
|
172
205
|
center,
|
|
@@ -200,9 +233,18 @@ function createPointInEllipse(cornersInWorld = [], options = {}) {
|
|
|
200
233
|
}
|
|
201
234
|
const pointVec = vec3.create();
|
|
202
235
|
vec3.subtract(pointVec, worldPoint, center);
|
|
203
|
-
const
|
|
204
|
-
const
|
|
205
|
-
|
|
236
|
+
const xDist = vec3.dot(pointVec, viewRight);
|
|
237
|
+
const yDist = vec3.dot(pointVec, viewUp);
|
|
238
|
+
const xTerm = xDist * xDist * invXRadiusSquared;
|
|
239
|
+
const yTerm = yDist * yDist * invYRadiusSquared;
|
|
240
|
+
const zDist = vec3.dot(pointVec, viewNormal);
|
|
241
|
+
if (invZRadiusSquared !== null) {
|
|
242
|
+
return xTerm + yTerm + zDist * zDist * invZRadiusSquared <= 1;
|
|
243
|
+
}
|
|
244
|
+
if (xTerm + yTerm <= 1) {
|
|
245
|
+
return Math.abs(zDist) <= planeTolerance;
|
|
246
|
+
}
|
|
247
|
+
return false;
|
|
206
248
|
};
|
|
207
249
|
}
|
|
208
250
|
const CIRCLE_STRATEGY = new BrushStrategy('Circle', compositions.regionFill, compositions.setValue, initializeCircle, compositions.determineSegmentIndex, compositions.preview, compositions.labelmapStatistics);
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import type { Types } from '@cornerstonejs/core';
|
|
1
2
|
import BrushStrategy from './BrushStrategy.js';
|
|
3
|
+
export declare function orderRectangleCorners(pts: Types.Point3[]): Types.Point3[];
|
|
2
4
|
declare const RECTANGLE_STRATEGY: BrushStrategy;
|
|
3
5
|
declare const RECTANGLE_THRESHOLD_STRATEGY: BrushStrategy;
|
|
4
6
|
declare const fillInsideRectangle: (enabledElement: any, operationData: any) => unknown;
|
|
@@ -1,14 +1,49 @@
|
|
|
1
1
|
import { vec3 } from 'gl-matrix';
|
|
2
|
-
import { utilities as csUtils
|
|
3
|
-
import { getBoundingBoxAroundShapeIJK } from '../../../utilities/boundingBox/index.js';
|
|
4
|
-
import getViewportICamera from '../../../utilities/getViewportICamera.js';
|
|
2
|
+
import { utilities as csUtils } from '@cornerstonejs/core';
|
|
5
3
|
import BrushStrategy from './BrushStrategy.js';
|
|
6
4
|
import { StrategyCallbacks } from '../../../enums/index.js';
|
|
7
5
|
import compositions from './compositions/index.js';
|
|
6
|
+
import { applyBrushFill, createRectangleBrushFill, } from './utils/brushVoxelSlab.js';
|
|
8
7
|
const { transformWorldToIndex } = csUtils;
|
|
8
|
+
export function orderRectangleCorners(pts) {
|
|
9
|
+
if (pts.length < 3) {
|
|
10
|
+
return [...pts];
|
|
11
|
+
}
|
|
12
|
+
const center = vec3.create();
|
|
13
|
+
pts.forEach((p) => vec3.add(center, center, p));
|
|
14
|
+
vec3.scale(center, center, 1 / pts.length);
|
|
15
|
+
const radials = pts.map((p) => vec3.subtract(vec3.create(), p, center));
|
|
16
|
+
let axisInPlane = radials[0];
|
|
17
|
+
let maxLenSq = vec3.squaredLength(axisInPlane);
|
|
18
|
+
for (const radial of radials) {
|
|
19
|
+
const lenSq = vec3.squaredLength(radial);
|
|
20
|
+
if (lenSq > maxLenSq) {
|
|
21
|
+
maxLenSq = lenSq;
|
|
22
|
+
axisInPlane = radial;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
const e1 = vec3.normalize(vec3.create(), axisInPlane);
|
|
26
|
+
const normal = vec3.create();
|
|
27
|
+
const candidate = vec3.create();
|
|
28
|
+
for (const radial of radials) {
|
|
29
|
+
vec3.cross(candidate, e1, radial);
|
|
30
|
+
if (vec3.squaredLength(candidate) > vec3.squaredLength(normal)) {
|
|
31
|
+
vec3.copy(normal, candidate);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
vec3.normalize(normal, normal);
|
|
35
|
+
const e2 = vec3.normalize(vec3.create(), vec3.cross(vec3.create(), normal, e1));
|
|
36
|
+
return [...pts].sort((a, b) => {
|
|
37
|
+
const ra = vec3.subtract(vec3.create(), a, center);
|
|
38
|
+
const rb = vec3.subtract(vec3.create(), b, center);
|
|
39
|
+
const angleA = Math.atan2(vec3.dot(ra, e2), vec3.dot(ra, e1));
|
|
40
|
+
const angleB = Math.atan2(vec3.dot(rb, e2), vec3.dot(rb, e1));
|
|
41
|
+
return angleA - angleB;
|
|
42
|
+
});
|
|
43
|
+
}
|
|
9
44
|
const initializeRectangle = {
|
|
10
45
|
[StrategyCallbacks.Initialize]: (operationData) => {
|
|
11
|
-
const { points,
|
|
46
|
+
const { points, segmentationImageData, viewPlaneNormal, } = operationData;
|
|
12
47
|
if (!points) {
|
|
13
48
|
return;
|
|
14
49
|
}
|
|
@@ -19,22 +54,38 @@ const initializeRectangle = {
|
|
|
19
54
|
vec3.scale(center, center, 1 / points.length);
|
|
20
55
|
operationData.centerWorld = center;
|
|
21
56
|
operationData.centerIJK = transformWorldToIndex(segmentationImageData, center);
|
|
22
|
-
const
|
|
57
|
+
const orderedPoints = orderRectangleCorners(points);
|
|
58
|
+
const { boundsIJK, pointInShapeFn } = createPointInRectangle(orderedPoints, segmentationImageData);
|
|
23
59
|
operationData.isInObject = pointInShapeFn;
|
|
24
60
|
operationData.isInObjectBoundsIJK = boundsIJK;
|
|
61
|
+
applyBrushFill(operationData, createRectangleBrushFill({
|
|
62
|
+
segmentationImageData,
|
|
63
|
+
cornersWorld: orderedPoints,
|
|
64
|
+
viewPlaneNormal: viewPlaneNormal,
|
|
65
|
+
}));
|
|
25
66
|
},
|
|
26
67
|
};
|
|
27
|
-
function createPointInRectangle(
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
68
|
+
function createPointInRectangle(orderedPoints, segmentationImageData) {
|
|
69
|
+
const [p0, p1, , p3] = orderedPoints;
|
|
70
|
+
const rectangleCornersIJK = orderedPoints.map((world) => transformWorldToIndex(segmentationImageData, world));
|
|
71
|
+
const dims = segmentationImageData.getDimensions();
|
|
72
|
+
const cornerIValues = rectangleCornersIJK.map((p) => p[0]);
|
|
73
|
+
const cornerJValues = rectangleCornersIJK.map((p) => p[1]);
|
|
74
|
+
const cornerKValues = rectangleCornersIJK.map((p) => p[2]);
|
|
75
|
+
const boundsIJK = [
|
|
76
|
+
[
|
|
77
|
+
Math.max(0, Math.floor(Math.min(...cornerIValues))),
|
|
78
|
+
Math.min(dims[0] - 1, Math.ceil(Math.max(...cornerIValues))),
|
|
79
|
+
],
|
|
80
|
+
[
|
|
81
|
+
Math.max(0, Math.floor(Math.min(...cornerJValues))),
|
|
82
|
+
Math.min(dims[1] - 1, Math.ceil(Math.max(...cornerJValues))),
|
|
83
|
+
],
|
|
84
|
+
[
|
|
85
|
+
Math.max(0, Math.floor(Math.min(...cornerKValues))),
|
|
86
|
+
Math.min(dims[2] - 1, Math.ceil(Math.max(...cornerKValues))),
|
|
87
|
+
],
|
|
88
|
+
];
|
|
38
89
|
const axisU = vec3.create();
|
|
39
90
|
const axisV = vec3.create();
|
|
40
91
|
vec3.subtract(axisU, p1, p0);
|
|
@@ -46,24 +97,26 @@ function createPointInRectangle(viewport, points, segmentationImageData) {
|
|
|
46
97
|
const normal = vec3.create();
|
|
47
98
|
vec3.cross(normal, axisU, axisV);
|
|
48
99
|
vec3.normalize(normal, normal);
|
|
49
|
-
const direction = segmentationImageData.getDirection();
|
|
50
100
|
const spacing = segmentationImageData.getSpacing();
|
|
51
|
-
const
|
|
52
|
-
const
|
|
101
|
+
const direction = segmentationImageData.getDirection();
|
|
102
|
+
const projectedSpacing = csUtils.getSpacingInNormalDirection({
|
|
53
103
|
direction,
|
|
54
104
|
spacing,
|
|
55
|
-
},
|
|
105
|
+
}, normal);
|
|
106
|
+
const thickness = projectedSpacing;
|
|
107
|
+
const inPlaneSpacing = Math.min(spacing[0], spacing[1]);
|
|
108
|
+
const inPlaneTolerance = inPlaneSpacing / 2;
|
|
56
109
|
const pointInShapeFn = (pointLPS) => {
|
|
57
110
|
const v = vec3.create();
|
|
58
111
|
vec3.subtract(v, pointLPS, p0);
|
|
59
112
|
const u = vec3.dot(v, axisU);
|
|
60
113
|
const vproj = vec3.dot(v, axisV);
|
|
61
|
-
const
|
|
62
|
-
return (u >= -
|
|
63
|
-
u <= uLen +
|
|
64
|
-
vproj >= -
|
|
65
|
-
vproj <= vLen +
|
|
66
|
-
|
|
114
|
+
const distanceToPlane = Math.abs(vec3.dot(v, normal));
|
|
115
|
+
return (u >= -inPlaneTolerance &&
|
|
116
|
+
u <= uLen + inPlaneTolerance &&
|
|
117
|
+
vproj >= -inPlaneTolerance &&
|
|
118
|
+
vproj <= vLen + inPlaneTolerance &&
|
|
119
|
+
distanceToPlane <= thickness);
|
|
67
120
|
};
|
|
68
121
|
return { boundsIJK, pointInShapeFn };
|
|
69
122
|
}
|
|
@@ -4,11 +4,12 @@ import BrushStrategy from './BrushStrategy.js';
|
|
|
4
4
|
import compositions from './compositions/index.js';
|
|
5
5
|
import StrategyCallbacks from '../../../enums/StrategyCallbacks.js';
|
|
6
6
|
import { createEllipseInPoint, getEllipseCornersFromCanvasCoordinates, } from './fillCircle.js';
|
|
7
|
+
import { applyBrushFill, createSphereBrushFill } from './utils/brushVoxelSlab.js';
|
|
7
8
|
const { transformWorldToIndex, getNormalizedAspectRatio } = csUtils;
|
|
8
9
|
import { getSphereBoundsInfoFromViewport } from '../../../utilities/getSphereBoundsInfo.js';
|
|
9
10
|
const sphereComposition = {
|
|
10
11
|
[StrategyCallbacks.Initialize]: (operationData) => {
|
|
11
|
-
const { points, viewport, segmentationImageData } = operationData;
|
|
12
|
+
const { points, viewport, segmentationImageData, viewUp, viewPlaneNormal } = operationData;
|
|
12
13
|
if (!points) {
|
|
13
14
|
return;
|
|
14
15
|
}
|
|
@@ -22,7 +23,6 @@ const sphereComposition = {
|
|
|
22
23
|
}
|
|
23
24
|
operationData.centerWorld = center;
|
|
24
25
|
operationData.centerIJK = transformWorldToIndex(segmentationImageData, center);
|
|
25
|
-
const baseExtent = getSphereBoundsInfoFromViewport(points.slice(0, 2), segmentationImageData, viewport);
|
|
26
26
|
const canvasCoordinates = points.map((p) => viewport.worldToCanvas(p));
|
|
27
27
|
const corners = getEllipseCornersFromCanvasCoordinates(canvasCoordinates);
|
|
28
28
|
const cornersInWorld = corners.map((corner) => viewport.canvasToWorld(corner));
|
|
@@ -33,73 +33,67 @@ const sphereComposition = {
|
|
|
33
33
|
const xRadius = points.length >= 2
|
|
34
34
|
? vec3.distance(points[2], points[3]) / 2 / aspectRatio[0]
|
|
35
35
|
: 0;
|
|
36
|
-
const
|
|
37
|
-
|
|
36
|
+
const normalizedViewUp = vec3.fromValues(viewUp[0], viewUp[1], viewUp[2]);
|
|
37
|
+
vec3.normalize(normalizedViewUp, normalizedViewUp);
|
|
38
|
+
const normalizedPlaneNormal = vec3.fromValues(viewPlaneNormal[0], viewPlaneNormal[1], viewPlaneNormal[2]);
|
|
39
|
+
vec3.normalize(normalizedPlaneNormal, normalizedPlaneNormal);
|
|
40
|
+
const viewRight = vec3.create();
|
|
41
|
+
vec3.cross(viewRight, normalizedViewUp, normalizedPlaneNormal);
|
|
42
|
+
vec3.normalize(viewRight, viewRight);
|
|
43
|
+
const baseExtent = getSphereBoundsInfoFromViewport(points.slice(0, 2), segmentationImageData, viewport);
|
|
44
|
+
const strokeCenters = operationData.strokePointsWorld?.length
|
|
38
45
|
? operationData.strokePointsWorld
|
|
39
46
|
: [operationData.centerWorld];
|
|
40
47
|
const baseBounds = baseExtent.boundsIJK;
|
|
41
48
|
const baseCenterIJK = operationData.centerIJK;
|
|
42
|
-
const boundsForStroke = strokeCenters.reduce((
|
|
49
|
+
const boundsForStroke = strokeCenters.reduce((accumulated, centerPoint) => {
|
|
43
50
|
if (!centerPoint) {
|
|
44
|
-
return
|
|
51
|
+
return accumulated;
|
|
45
52
|
}
|
|
46
53
|
const translatedCenterIJK = transformWorldToIndex(segmentationImageData, centerPoint);
|
|
47
|
-
const
|
|
48
|
-
translatedCenterIJK[
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
];
|
|
57
|
-
if (!acc) {
|
|
58
|
-
return translatedBounds;
|
|
54
|
+
const translated = [0, 1, 2].map((axis) => {
|
|
55
|
+
const delta = translatedCenterIJK[axis] - baseCenterIJK[axis];
|
|
56
|
+
return [
|
|
57
|
+
baseBounds[axis][0] + delta,
|
|
58
|
+
baseBounds[axis][1] + delta,
|
|
59
|
+
];
|
|
60
|
+
});
|
|
61
|
+
if (!accumulated) {
|
|
62
|
+
return translated;
|
|
59
63
|
}
|
|
60
|
-
return [
|
|
61
|
-
[
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
],
|
|
65
|
-
[
|
|
66
|
-
Math.min(acc[1][0], translatedBounds[1][0]),
|
|
67
|
-
Math.max(acc[1][1], translatedBounds[1][1]),
|
|
68
|
-
],
|
|
69
|
-
[
|
|
70
|
-
Math.min(acc[2][0], translatedBounds[2][0]),
|
|
71
|
-
Math.max(acc[2][1], translatedBounds[2][1]),
|
|
72
|
-
],
|
|
73
|
-
];
|
|
64
|
+
return [0, 1, 2].map((axis) => [
|
|
65
|
+
Math.min(accumulated[axis][0], translated[axis][0]),
|
|
66
|
+
Math.max(accumulated[axis][1], translated[axis][1]),
|
|
67
|
+
]);
|
|
74
68
|
}, null);
|
|
75
69
|
const boundsToUse = boundsForStroke ?? baseExtent.boundsIJK;
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
[
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
[
|
|
84
|
-
Math.max(0, Math.min(boundsToUse[1][0], dimensions[1] - 1)),
|
|
85
|
-
Math.max(0, Math.min(boundsToUse[1][1], dimensions[1] - 1)),
|
|
86
|
-
],
|
|
87
|
-
[
|
|
88
|
-
Math.max(0, Math.min(boundsToUse[2][0], dimensions[2] - 1)),
|
|
89
|
-
Math.max(0, Math.min(boundsToUse[2][1], dimensions[2] - 1)),
|
|
90
|
-
],
|
|
91
|
-
];
|
|
92
|
-
}
|
|
93
|
-
else {
|
|
94
|
-
operationData.isInObjectBoundsIJK = boundsToUse;
|
|
95
|
-
}
|
|
70
|
+
const dimensions = segmentationImageData?.getDimensions();
|
|
71
|
+
operationData.isInObjectBoundsIJK = dimensions
|
|
72
|
+
? [0, 1, 2].map((axis) => [
|
|
73
|
+
Math.max(0, Math.min(boundsToUse[axis][0], dimensions[axis] - 1)),
|
|
74
|
+
Math.max(0, Math.min(boundsToUse[axis][1], dimensions[axis] - 1)),
|
|
75
|
+
])
|
|
76
|
+
: boundsToUse;
|
|
96
77
|
operationData.isInObject = createEllipseInPoint(cornersInWorld, {
|
|
97
78
|
strokePointsWorld: operationData.strokePointsWorld,
|
|
98
79
|
segmentationImageData,
|
|
99
80
|
xRadius,
|
|
100
81
|
yRadius,
|
|
101
82
|
aspectRatio,
|
|
83
|
+
viewRight,
|
|
84
|
+
viewUp: normalizedViewUp,
|
|
85
|
+
viewNormal: normalizedPlaneNormal,
|
|
86
|
+
depthRadius: Math.max(xRadius, yRadius),
|
|
102
87
|
});
|
|
88
|
+
applyBrushFill(operationData, createSphereBrushFill({
|
|
89
|
+
segmentationImageData,
|
|
90
|
+
viewUp: normalizedViewUp,
|
|
91
|
+
viewPlaneNormal: normalizedPlaneNormal,
|
|
92
|
+
centerWorld: operationData.centerWorld,
|
|
93
|
+
xRadius,
|
|
94
|
+
yRadius,
|
|
95
|
+
strokeCentersWorld: strokeCenters,
|
|
96
|
+
}));
|
|
103
97
|
},
|
|
104
98
|
};
|
|
105
99
|
const SPHERE_STRATEGY = new BrushStrategy('Sphere', compositions.regionFill, compositions.setValue, sphereComposition, compositions.determineSegmentIndex, compositions.preview, compositions.labelmapStatistics, compositions.ensureSegmentationVolumeFor3DManipulation);
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { Types } from '@cornerstonejs/core';
|
|
2
|
+
import { utilities as csUtils } from '@cornerstonejs/core';
|
|
3
|
+
import type vtkImageData from '@kitware/vtk.js/Common/DataModel/ImageData';
|
|
4
|
+
export declare const brushFillLog: import("packages/utils/dist/esm").Logger;
|
|
5
|
+
type SlabDepthCoverage = csUtils.voxelSlab.SlabDepthCoverage;
|
|
6
|
+
type VoxelSlabShape = csUtils.voxelSlab.VoxelSlabShape;
|
|
7
|
+
type BrushVolume = {
|
|
8
|
+
dimensions: Types.Point3;
|
|
9
|
+
direction: Types.Mat3;
|
|
10
|
+
spacing: Types.Point3;
|
|
11
|
+
origin: Types.Point3;
|
|
12
|
+
};
|
|
13
|
+
export interface BrushVoxelSlabFill {
|
|
14
|
+
volume: BrushVolume;
|
|
15
|
+
planePoint: Types.Point3;
|
|
16
|
+
viewPlaneNormal: Types.Point3;
|
|
17
|
+
thicknessWorld: number;
|
|
18
|
+
depthCoverage: SlabDepthCoverage;
|
|
19
|
+
bounds: Types.BoundsIJK;
|
|
20
|
+
shape: VoxelSlabShape;
|
|
21
|
+
}
|
|
22
|
+
export declare function createCircleBrushFill(operationData: {
|
|
23
|
+
segmentationImageData: vtkImageData;
|
|
24
|
+
viewUp: Types.Point3;
|
|
25
|
+
viewPlaneNormal: Types.Point3;
|
|
26
|
+
centerWorld: Types.Point3;
|
|
27
|
+
xRadius: number;
|
|
28
|
+
yRadius: number;
|
|
29
|
+
strokeCentersWorld?: Types.Point3[];
|
|
30
|
+
viewThicknessWorld?: number;
|
|
31
|
+
}): BrushVoxelSlabFill | null;
|
|
32
|
+
export declare function createSphereBrushFill(operationData: {
|
|
33
|
+
segmentationImageData: vtkImageData;
|
|
34
|
+
viewUp: Types.Point3;
|
|
35
|
+
viewPlaneNormal: Types.Point3;
|
|
36
|
+
centerWorld: Types.Point3;
|
|
37
|
+
xRadius: number;
|
|
38
|
+
yRadius: number;
|
|
39
|
+
strokeCentersWorld?: Types.Point3[];
|
|
40
|
+
}): BrushVoxelSlabFill | null;
|
|
41
|
+
export declare function createRectangleBrushFill(operationData: {
|
|
42
|
+
segmentationImageData: vtkImageData;
|
|
43
|
+
cornersWorld: Types.Point3[];
|
|
44
|
+
viewPlaneNormal?: Types.Point3;
|
|
45
|
+
}): BrushVoxelSlabFill | null;
|
|
46
|
+
export declare function createBrushFillPredicate(fill: BrushVoxelSlabFill, imageData?: vtkImageData): (pointLPS: Types.Point3 | null, pointIJK?: Types.Point3) => boolean;
|
|
47
|
+
export declare function applyBrushFill(operationData: {
|
|
48
|
+
segmentationImageData?: vtkImageData;
|
|
49
|
+
brushVoxelSlabFill?: BrushVoxelSlabFill | null;
|
|
50
|
+
isInObject?: (pointLPS: any, pointIJK: any) => boolean;
|
|
51
|
+
isInObjectBoundsIJK?: Types.BoundsIJK;
|
|
52
|
+
}, fill: BrushVoxelSlabFill | null): void;
|
|
53
|
+
export declare function forEachBrushFillVoxel(fill: BrushVoxelSlabFill, voxelManager: Types.IVoxelManager<number>, callback: (args: {
|
|
54
|
+
value: number;
|
|
55
|
+
index: number;
|
|
56
|
+
pointIJK: Types.Point3;
|
|
57
|
+
pointLPS: Types.Point3;
|
|
58
|
+
}) => void): void;
|
|
59
|
+
export {};
|
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
import { vec3 } from 'gl-matrix';
|
|
2
|
+
import { utilities as csUtils } from '@cornerstonejs/core';
|
|
3
|
+
import { getShapeIndexBounds } from '../../../../utilities/sampleAreaAnnotationVoxels.js';
|
|
4
|
+
export const brushFillLog = csUtils.logger.toolsLog.getLogger('segmentation', 'brushVoxelSlab');
|
|
5
|
+
const { createEllipseShape, createRectangleShape, createUnionShape, getSlabEpsilon, getSlabHalfWidth, getVoxelThicknessAlongNormal, isSlabDepthLowInclusive, iterateVoxelsInShape, resolveReferencePlaneThickness, signedDistanceToPlane, } = csUtils.voxelSlab;
|
|
6
|
+
function volumeFromImageData(imageData) {
|
|
7
|
+
return {
|
|
8
|
+
dimensions: imageData.getDimensions(),
|
|
9
|
+
direction: imageData.getDirection(),
|
|
10
|
+
spacing: imageData.getSpacing(),
|
|
11
|
+
origin: imageData.getOrigin(),
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
function getViewRight(viewUp, viewPlaneNormal) {
|
|
15
|
+
const right = vec3.cross(vec3.create(), viewUp, viewPlaneNormal);
|
|
16
|
+
return vec3.normalize(right, right);
|
|
17
|
+
}
|
|
18
|
+
function densifyStrokeCenters(centers, stepWorld) {
|
|
19
|
+
if (centers.length <= 1 || !(stepWorld > 0)) {
|
|
20
|
+
return centers;
|
|
21
|
+
}
|
|
22
|
+
const dense = [centers[0]];
|
|
23
|
+
for (let index = 1; index < centers.length; index++) {
|
|
24
|
+
const from = centers[index - 1];
|
|
25
|
+
const to = centers[index];
|
|
26
|
+
const delta = [to[0] - from[0], to[1] - from[1], to[2] - from[2]];
|
|
27
|
+
const length = Math.hypot(delta[0], delta[1], delta[2]);
|
|
28
|
+
const steps = Math.max(1, Math.ceil(length / stepWorld));
|
|
29
|
+
for (let step = 1; step <= steps; step++) {
|
|
30
|
+
const t = step / steps;
|
|
31
|
+
dense.push([
|
|
32
|
+
from[0] + delta[0] * t,
|
|
33
|
+
from[1] + delta[1] * t,
|
|
34
|
+
from[2] + delta[2] * t,
|
|
35
|
+
]);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return dense;
|
|
39
|
+
}
|
|
40
|
+
function buildBrushFill({ segmentationImageData, planePoint, viewPlaneNormal, centersWorld, boundsMargin, viewThicknessWorld, createShape, }) {
|
|
41
|
+
if (!centersWorld.length) {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
const volume = volumeFromImageData(segmentationImageData);
|
|
45
|
+
const voxelThickness = getVoxelThicknessAlongNormal(volume, viewPlaneNormal);
|
|
46
|
+
const shapes = centersWorld
|
|
47
|
+
.map((centerWorld) => createShape({ volume, planePoint, viewPlaneNormal, centerWorld }))
|
|
48
|
+
.filter(Boolean);
|
|
49
|
+
if (!shapes.length) {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
const shape = createUnionShape(shapes);
|
|
53
|
+
const requiredThickness = shape.getRequiredThickness();
|
|
54
|
+
const carriesOwnDepth = requiredThickness > 0;
|
|
55
|
+
const depthCoverage = carriesOwnDepth
|
|
56
|
+
? 'overlapping'
|
|
57
|
+
: 'centerInside';
|
|
58
|
+
const thicknessWorld = resolveReferencePlaneThickness(carriesOwnDepth ? requiredThickness : viewThicknessWorld, voxelThickness);
|
|
59
|
+
return {
|
|
60
|
+
volume,
|
|
61
|
+
planePoint,
|
|
62
|
+
viewPlaneNormal,
|
|
63
|
+
thicknessWorld,
|
|
64
|
+
depthCoverage,
|
|
65
|
+
bounds: getShapeIndexBounds(centersWorld, volume, segmentationImageData, viewPlaneNormal, getSlabHalfWidth(thicknessWorld, voxelThickness, depthCoverage), boundsMargin),
|
|
66
|
+
shape,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
export function createCircleBrushFill(operationData) {
|
|
70
|
+
const { segmentationImageData, viewUp, viewPlaneNormal, centerWorld, xRadius, yRadius, viewThicknessWorld, } = operationData;
|
|
71
|
+
if (!(xRadius > 0) || !(yRadius > 0)) {
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
const viewRight = getViewRight(viewUp, viewPlaneNormal);
|
|
75
|
+
const centers = operationData.strokeCentersWorld?.length
|
|
76
|
+
? operationData.strokeCentersWorld
|
|
77
|
+
: [centerWorld];
|
|
78
|
+
return buildBrushFill({
|
|
79
|
+
segmentationImageData,
|
|
80
|
+
planePoint: centerWorld,
|
|
81
|
+
viewPlaneNormal,
|
|
82
|
+
centersWorld: densifyStrokeCenters(centers, Math.min(xRadius, yRadius) / 2),
|
|
83
|
+
boundsMargin: Math.max(xRadius, yRadius),
|
|
84
|
+
viewThicknessWorld,
|
|
85
|
+
createShape: ({ volume, planePoint, centerWorld: center }) => createEllipseShape({
|
|
86
|
+
volume,
|
|
87
|
+
planePoint,
|
|
88
|
+
viewPlaneNormal,
|
|
89
|
+
centerWorld: center,
|
|
90
|
+
majorAxis: viewRight,
|
|
91
|
+
majorRadius: xRadius,
|
|
92
|
+
minorRadius: yRadius,
|
|
93
|
+
}),
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
export function createSphereBrushFill(operationData) {
|
|
97
|
+
const { segmentationImageData, viewUp, viewPlaneNormal, centerWorld, xRadius, yRadius, } = operationData;
|
|
98
|
+
if (!(xRadius > 0) || !(yRadius > 0)) {
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
101
|
+
const depthRadius = Math.max(xRadius, yRadius);
|
|
102
|
+
const viewRight = getViewRight(viewUp, viewPlaneNormal);
|
|
103
|
+
const centers = operationData.strokeCentersWorld?.length
|
|
104
|
+
? operationData.strokeCentersWorld
|
|
105
|
+
: [centerWorld];
|
|
106
|
+
return buildBrushFill({
|
|
107
|
+
segmentationImageData,
|
|
108
|
+
planePoint: centerWorld,
|
|
109
|
+
viewPlaneNormal,
|
|
110
|
+
centersWorld: densifyStrokeCenters(centers, Math.min(xRadius, yRadius) / 2),
|
|
111
|
+
boundsMargin: depthRadius,
|
|
112
|
+
createShape: ({ volume, planePoint, centerWorld: center }) => createEllipseShape({
|
|
113
|
+
volume,
|
|
114
|
+
planePoint,
|
|
115
|
+
viewPlaneNormal,
|
|
116
|
+
centerWorld: center,
|
|
117
|
+
majorAxis: viewRight,
|
|
118
|
+
majorRadius: xRadius,
|
|
119
|
+
minorRadius: yRadius,
|
|
120
|
+
depthRadius,
|
|
121
|
+
}),
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
export function createRectangleBrushFill(operationData) {
|
|
125
|
+
const { segmentationImageData, cornersWorld } = operationData;
|
|
126
|
+
if (cornersWorld.length < 4) {
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
const [p0, p1, , p3] = cornersWorld;
|
|
130
|
+
const majorAxis = vec3.sub(vec3.create(), p1, p0);
|
|
131
|
+
const minorAxis = vec3.sub(vec3.create(), p3, p0);
|
|
132
|
+
const majorHalfLength = vec3.length(majorAxis) / 2;
|
|
133
|
+
const minorHalfLength = vec3.length(minorAxis) / 2;
|
|
134
|
+
if (!(majorHalfLength > 0) || !(minorHalfLength > 0)) {
|
|
135
|
+
return null;
|
|
136
|
+
}
|
|
137
|
+
const normal = vec3.cross(vec3.create(), majorAxis, minorAxis);
|
|
138
|
+
if (!(vec3.squaredLength(normal) > 0)) {
|
|
139
|
+
if (!operationData.viewPlaneNormal) {
|
|
140
|
+
return null;
|
|
141
|
+
}
|
|
142
|
+
vec3.copy(normal, operationData.viewPlaneNormal);
|
|
143
|
+
}
|
|
144
|
+
vec3.normalize(normal, normal);
|
|
145
|
+
const center = vec3.lerp(vec3.create(), p0, cornersWorld[2], 0.5);
|
|
146
|
+
return buildBrushFill({
|
|
147
|
+
segmentationImageData,
|
|
148
|
+
planePoint: center,
|
|
149
|
+
viewPlaneNormal: normal,
|
|
150
|
+
centersWorld: [center],
|
|
151
|
+
boundsMargin: Math.hypot(majorHalfLength, minorHalfLength),
|
|
152
|
+
createShape: ({ volume, planePoint, viewPlaneNormal, centerWorld }) => createRectangleShape({
|
|
153
|
+
volume,
|
|
154
|
+
planePoint,
|
|
155
|
+
viewPlaneNormal,
|
|
156
|
+
centerWorld,
|
|
157
|
+
majorAxis: majorAxis,
|
|
158
|
+
majorHalfLength,
|
|
159
|
+
minorHalfLength,
|
|
160
|
+
}),
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
export function createBrushFillPredicate(fill, imageData) {
|
|
164
|
+
const { planePoint, viewPlaneNormal, shape } = fill;
|
|
165
|
+
const voxelThickness = getVoxelThicknessAlongNormal(fill.volume, viewPlaneNormal);
|
|
166
|
+
const halfWidth = getSlabHalfWidth(fill.thicknessWorld, voxelThickness, fill.depthCoverage);
|
|
167
|
+
const epsilon = getSlabEpsilon(voxelThickness);
|
|
168
|
+
const halfOpen = isSlabDepthLowInclusive(fill.depthCoverage);
|
|
169
|
+
const depthLow = halfOpen ? -halfWidth - epsilon : -halfWidth + epsilon;
|
|
170
|
+
const depthHigh = halfWidth - epsilon;
|
|
171
|
+
const scratch = [0, 0, 0];
|
|
172
|
+
return (pointLPS, pointIJK) => {
|
|
173
|
+
let world = pointLPS;
|
|
174
|
+
if (!world) {
|
|
175
|
+
if (!pointIJK || !imageData) {
|
|
176
|
+
return false;
|
|
177
|
+
}
|
|
178
|
+
world = imageData.indexToWorld(pointIJK, scratch);
|
|
179
|
+
}
|
|
180
|
+
const depth = signedDistanceToPlane(world, planePoint, viewPlaneNormal);
|
|
181
|
+
const withinDepth = halfOpen
|
|
182
|
+
? depth >= depthLow && depth < depthHigh
|
|
183
|
+
: depth > depthLow && depth < depthHigh;
|
|
184
|
+
return withinDepth && shape.containsPoint(world);
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
export function applyBrushFill(operationData, fill) {
|
|
188
|
+
if (!fill) {
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
operationData.brushVoxelSlabFill = fill;
|
|
192
|
+
operationData.isInObject = createBrushFillPredicate(fill, operationData.segmentationImageData);
|
|
193
|
+
operationData.isInObjectBoundsIJK = fill.bounds;
|
|
194
|
+
}
|
|
195
|
+
export function forEachBrushFillVoxel(fill, voxelManager, callback) {
|
|
196
|
+
const iteration = iterateVoxelsInShape({
|
|
197
|
+
volume: fill.volume,
|
|
198
|
+
planePoint: fill.planePoint,
|
|
199
|
+
viewPlaneNormal: fill.viewPlaneNormal,
|
|
200
|
+
referencePlaneThickness: fill.thicknessWorld,
|
|
201
|
+
depthCoverage: fill.depthCoverage,
|
|
202
|
+
bounds: fill.bounds,
|
|
203
|
+
getShapeRuns: fill.shape.getRuns,
|
|
204
|
+
});
|
|
205
|
+
const debug = (brushFillLog.getLevel?.() ?? 5) <= 1;
|
|
206
|
+
const depths = [];
|
|
207
|
+
let minDepth = Infinity;
|
|
208
|
+
let maxDepth = -Infinity;
|
|
209
|
+
let painted = 0;
|
|
210
|
+
for (const { ijk, center } of iteration) {
|
|
211
|
+
if (debug) {
|
|
212
|
+
const depth = (center[0] - fill.planePoint[0]) * fill.viewPlaneNormal[0] +
|
|
213
|
+
(center[1] - fill.planePoint[1]) * fill.viewPlaneNormal[1] +
|
|
214
|
+
(center[2] - fill.planePoint[2]) * fill.viewPlaneNormal[2];
|
|
215
|
+
depths.push(depth);
|
|
216
|
+
minDepth = Math.min(minDepth, depth);
|
|
217
|
+
maxDepth = Math.max(maxDepth, depth);
|
|
218
|
+
}
|
|
219
|
+
painted++;
|
|
220
|
+
const pointIJK = [ijk[0], ijk[1], ijk[2]];
|
|
221
|
+
const index = voxelManager.toIndex(pointIJK);
|
|
222
|
+
callback({
|
|
223
|
+
value: voxelManager.getAtIndex(index),
|
|
224
|
+
index,
|
|
225
|
+
pointIJK,
|
|
226
|
+
pointLPS: [center[0], center[1], center[2]],
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
if (!debug) {
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
if (!painted) {
|
|
233
|
+
brushFillLog.debug('brush fill painted=0');
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
const voxelThickness = getVoxelThicknessAlongNormal(fill.volume, fill.viewPlaneNormal);
|
|
237
|
+
const layers = new Set(depths.map((depth) => Math.round((depth / voxelThickness) * 10) / 10));
|
|
238
|
+
const sorted = [...layers].sort((a, b) => a - b);
|
|
239
|
+
const span = (maxDepth - minDepth) / voxelThickness;
|
|
240
|
+
const halfWidth = getSlabHalfWidth(fill.thicknessWorld, voxelThickness, fill.depthCoverage);
|
|
241
|
+
brushFillLog.debug(`brush fill painted=${painted} T_v=${voxelThickness.toFixed(4)} ` +
|
|
242
|
+
`coverage=${fill.depthCoverage} ` +
|
|
243
|
+
`halfWidth=${halfWidth.toFixed(4)} ` +
|
|
244
|
+
`halfWidth/T_v=${(halfWidth / voxelThickness).toFixed(4)} ` +
|
|
245
|
+
`depthSpanInVoxels=${span.toFixed(4)} ` +
|
|
246
|
+
`distinctLayers=${sorted.length} ` +
|
|
247
|
+
`${span < 1 ? 'ONE PLANE' : 'MORE THAN ONE PLANE'}`, {
|
|
248
|
+
minDepth,
|
|
249
|
+
maxDepth,
|
|
250
|
+
layersInVoxels: sorted.length <= 24 ? sorted : `${sorted.length} values`,
|
|
251
|
+
planePoint: fill.planePoint,
|
|
252
|
+
viewPlaneNormal: fill.viewPlaneNormal,
|
|
253
|
+
});
|
|
254
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type Types } from '@cornerstonejs/core';
|
|
2
2
|
export declare function getSlabThicknessOrDefault(viewport: Types.IViewport): number;
|
|
3
|
+
export declare function getViewSlabDepthOfViewport(viewport: Types.IViewport): number | undefined;
|
|
3
4
|
export declare function jumpToFocalPoint(viewport: Types.IViewport, cameraFocalPoint: Types.Point3): void;
|
|
4
5
|
export declare function navigatePlanarViewportToPoint(viewport: Types.IViewport, worldPoint: Types.Point3): boolean;
|
|
5
6
|
export interface NativeSourceProperties {
|
|
@@ -7,6 +7,13 @@ export function getSlabThicknessOrDefault(viewport) {
|
|
|
7
7
|
}
|
|
8
8
|
return viewport.getSlabThickness();
|
|
9
9
|
}
|
|
10
|
+
export function getViewSlabDepthOfViewport(viewport) {
|
|
11
|
+
const slabThickness = viewport.getSlabThickness?.();
|
|
12
|
+
if (!Number.isFinite(slabThickness)) {
|
|
13
|
+
return undefined;
|
|
14
|
+
}
|
|
15
|
+
return csUtils.getViewSlabDepth(csUtils.isGenericViewport(viewport) ? slabThickness : slabThickness * 2);
|
|
16
|
+
}
|
|
10
17
|
export function jumpToFocalPoint(viewport, cameraFocalPoint) {
|
|
11
18
|
if (csUtils.isGenericViewport(viewport)) {
|
|
12
19
|
viewport.setViewReference({ cameraFocalPoint });
|
|
@@ -45,7 +45,7 @@ import { moveAnnotationToViewPlane } from './moveAnnotationToViewPlane.js';
|
|
|
45
45
|
import { safeStructuredClone } from './safeStructuredClone.js';
|
|
46
46
|
import getOrCreateImageVolume from './segmentation/getOrCreateImageVolume.js';
|
|
47
47
|
import * as usFanExtraction from '../tools/annotation/UltrasoundPleuraBLineTool/utils/fanExtraction.js';
|
|
48
|
-
import { jumpToFocalPoint } from './genericViewportToolHelpers.js';
|
|
48
|
+
import { jumpToFocalPoint, getViewSlabDepthOfViewport } from './genericViewportToolHelpers.js';
|
|
49
49
|
import pickIntensityPointInSlab, { getSlabIntensityPickContext } from './pickIntensityPointInSlab.js';
|
|
50
50
|
export * from './defaultGetTextLines.js';
|
|
51
|
-
export { math, planar, spatial, viewportFilters, drawing, debounce, dynamicVolume, throttle, orientation, isObject, touch, triggerEvent, calibrateImageSpacing, getCalibratedLengthUnitsAndScale, getCalibratedProbeUnitsAndValue, getCalibratedAspect, getPixelValueUnits, getPixelValueUnitsImageId, segmentation, contours, triggerAnnotationRenderForViewportIds, triggerAnnotationRenderForToolGroupIds, triggerAnnotationRender, getSphereBoundsInfo, sampleAreaAnnotationVoxels, getAnnotationNearPoint, getViewportForAnnotation, getAnnotationNearPointOnEnabledElement, viewport, cine, boundingBox, draw3D, rectangleROITool, planarFreehandROITool, stackPrefetch, stackContextPrefetch, roundNumber, pointToString, polyDataUtils, voi, AnnotationMultiSlice, contourSegmentation, annotationHydration, getClosestImageIdForStackViewport, pointInSurroundingSphereCallback, normalizeViewportPlane, IslandRemoval, geometricSurfaceUtils, usFanExtraction, setAnnotationLabel, moveAnnotationToViewPlane, safeStructuredClone, getOrCreateImageVolume, jumpToFocalPoint, pickIntensityPointInSlab, getSlabIntensityPickContext, };
|
|
51
|
+
export { math, planar, spatial, viewportFilters, drawing, debounce, dynamicVolume, throttle, orientation, isObject, touch, triggerEvent, calibrateImageSpacing, getCalibratedLengthUnitsAndScale, getCalibratedProbeUnitsAndValue, getCalibratedAspect, getPixelValueUnits, getPixelValueUnitsImageId, segmentation, contours, triggerAnnotationRenderForViewportIds, triggerAnnotationRenderForToolGroupIds, triggerAnnotationRender, getSphereBoundsInfo, sampleAreaAnnotationVoxels, getAnnotationNearPoint, getViewportForAnnotation, getAnnotationNearPointOnEnabledElement, viewport, cine, boundingBox, draw3D, rectangleROITool, planarFreehandROITool, stackPrefetch, stackContextPrefetch, roundNumber, pointToString, polyDataUtils, voi, AnnotationMultiSlice, contourSegmentation, annotationHydration, getClosestImageIdForStackViewport, pointInSurroundingSphereCallback, normalizeViewportPlane, IslandRemoval, geometricSurfaceUtils, usFanExtraction, setAnnotationLabel, moveAnnotationToViewPlane, safeStructuredClone, getOrCreateImageVolume, jumpToFocalPoint, getViewSlabDepthOfViewport, pickIntensityPointInSlab, getSlabIntensityPickContext, };
|
|
@@ -45,7 +45,7 @@ import { moveAnnotationToViewPlane } from './moveAnnotationToViewPlane.js';
|
|
|
45
45
|
import { safeStructuredClone } from './safeStructuredClone.js';
|
|
46
46
|
import getOrCreateImageVolume from './segmentation/getOrCreateImageVolume.js';
|
|
47
47
|
import * as usFanExtraction from '../tools/annotation/UltrasoundPleuraBLineTool/utils/fanExtraction.js';
|
|
48
|
-
import { jumpToFocalPoint } from './genericViewportToolHelpers.js';
|
|
48
|
+
import { jumpToFocalPoint, getViewSlabDepthOfViewport, } from './genericViewportToolHelpers.js';
|
|
49
49
|
import pickIntensityPointInSlab, { getSlabIntensityPickContext, } from './pickIntensityPointInSlab.js';
|
|
50
50
|
export * from './defaultGetTextLines.js';
|
|
51
|
-
export { math, planar, spatial, viewportFilters, drawing, debounce, dynamicVolume, throttle, orientation, isObject, touch, triggerEvent, calibrateImageSpacing, getCalibratedLengthUnitsAndScale, getCalibratedProbeUnitsAndValue, getCalibratedAspect, getPixelValueUnits, getPixelValueUnitsImageId, segmentation, contours, triggerAnnotationRenderForViewportIds, triggerAnnotationRenderForToolGroupIds, triggerAnnotationRender, getSphereBoundsInfo, sampleAreaAnnotationVoxels, getAnnotationNearPoint, getViewportForAnnotation, getAnnotationNearPointOnEnabledElement, viewport, cine, boundingBox, draw3D, rectangleROITool, planarFreehandROITool, stackPrefetch, stackContextPrefetch, roundNumber, pointToString, polyDataUtils, voi, AnnotationMultiSlice, contourSegmentation, annotationHydration, getClosestImageIdForStackViewport, pointInSurroundingSphereCallback, normalizeViewportPlane, IslandRemoval, geometricSurfaceUtils, usFanExtraction, setAnnotationLabel, moveAnnotationToViewPlane, safeStructuredClone, getOrCreateImageVolume, jumpToFocalPoint, pickIntensityPointInSlab, getSlabIntensityPickContext, };
|
|
51
|
+
export { math, planar, spatial, viewportFilters, drawing, debounce, dynamicVolume, throttle, orientation, isObject, touch, triggerEvent, calibrateImageSpacing, getCalibratedLengthUnitsAndScale, getCalibratedProbeUnitsAndValue, getCalibratedAspect, getPixelValueUnits, getPixelValueUnitsImageId, segmentation, contours, triggerAnnotationRenderForViewportIds, triggerAnnotationRenderForToolGroupIds, triggerAnnotationRender, getSphereBoundsInfo, sampleAreaAnnotationVoxels, getAnnotationNearPoint, getViewportForAnnotation, getAnnotationNearPointOnEnabledElement, viewport, cine, boundingBox, draw3D, rectangleROITool, planarFreehandROITool, stackPrefetch, stackContextPrefetch, roundNumber, pointToString, polyDataUtils, voi, AnnotationMultiSlice, contourSegmentation, annotationHydration, getClosestImageIdForStackViewport, pointInSurroundingSphereCallback, normalizeViewportPlane, IslandRemoval, geometricSurfaceUtils, usFanExtraction, setAnnotationLabel, moveAnnotationToViewPlane, safeStructuredClone, getOrCreateImageVolume, jumpToFocalPoint, getViewSlabDepthOfViewport, pickIntensityPointInSlab, getSlabIntensityPickContext, };
|
|
@@ -42,3 +42,4 @@ export interface AreaAnnotationVoxelsOptions {
|
|
|
42
42
|
storePointData?: boolean;
|
|
43
43
|
}
|
|
44
44
|
export default function sampleAreaAnnotationVoxels({ annotation, image, voxelManager, points, boundsMargin, createShape, planePoint: planePointOverride, minimumPoints, onSample, storePointData, }: AreaAnnotationVoxelsOptions): AreaAnnotationVoxel[];
|
|
45
|
+
export declare function getShapeIndexBounds(points: Types.Point3[], volume: Pick<AreaAnnotationVolume, 'dimensions' | 'direction' | 'spacing'>, imageData: any, viewPlaneNormal: Types.Point3, halfWidth: number, margin: number): Types.BoundsIJK;
|
|
@@ -25,7 +25,7 @@ export default function sampleAreaAnnotationVoxels({ annotation, image, voxelMan
|
|
|
25
25
|
planePoint,
|
|
26
26
|
viewPlaneNormal,
|
|
27
27
|
referencePlaneThickness: slabThickness,
|
|
28
|
-
bounds:
|
|
28
|
+
bounds: getShapeIndexBounds(points, volume, imageData, viewPlaneNormal, getMembershipHalfWidth(slabThickness, voxelThickness), boundsMargin),
|
|
29
29
|
getShapeRuns: shape.getRuns,
|
|
30
30
|
voxelManager,
|
|
31
31
|
onSample,
|
|
@@ -46,7 +46,7 @@ function resolveAnnotationNormal(metadata) {
|
|
|
46
46
|
? asUnitNormal(normal)
|
|
47
47
|
: undefined;
|
|
48
48
|
}
|
|
49
|
-
function
|
|
49
|
+
export function getShapeIndexBounds(points, volume, imageData, viewPlaneNormal, halfWidth, margin) {
|
|
50
50
|
const { dimensions, direction, spacing } = volume;
|
|
51
51
|
const indexPoints = points.map((point) => imageData.worldToIndex(point));
|
|
52
52
|
const boundingBox = getBoundingBoxAroundShapeIJK(indexPoints);
|
package/dist/esm/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "5.10.
|
|
1
|
+
export declare const version = "5.10.5";
|
package/dist/esm/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '5.10.
|
|
1
|
+
export const version = '5.10.5';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cornerstonejs/tools",
|
|
3
|
-
"version": "5.10.
|
|
3
|
+
"version": "5.10.5",
|
|
4
4
|
"description": "Cornerstone3D Tools",
|
|
5
5
|
"types": "./dist/esm/index.d.ts",
|
|
6
6
|
"module": "./dist/esm/index.js",
|
|
@@ -126,11 +126,11 @@
|
|
|
126
126
|
"lodash.get": "4.4.2"
|
|
127
127
|
},
|
|
128
128
|
"devDependencies": {
|
|
129
|
-
"@cornerstonejs/core": "5.10.
|
|
129
|
+
"@cornerstonejs/core": "5.10.5",
|
|
130
130
|
"canvas": "3.2.0"
|
|
131
131
|
},
|
|
132
132
|
"peerDependencies": {
|
|
133
|
-
"@cornerstonejs/core": "5.10.
|
|
133
|
+
"@cornerstonejs/core": "5.10.5",
|
|
134
134
|
"@kitware/vtk.js": "36.4.1",
|
|
135
135
|
"@types/d3-array": "3.2.1",
|
|
136
136
|
"@types/d3-interpolate": "3.0.4",
|