@cornerstonejs/tools 5.10.6 → 5.10.8
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/eventDispatchers/mouseEventHandlers/mouseDownActivate.js +3 -1
- package/dist/esm/eventDispatchers/touchEventHandlers/touchStartActivate.js +3 -1
- package/dist/esm/stateManagement/segmentation/SegmentationStateManager.js +8 -5
- package/dist/esm/stateManagement/segmentation/segmentLocking.js +1 -1
- package/dist/esm/tools/SliceIntersectionTool.js +30 -24
- package/dist/esm/tools/base/AnnotationTool.d.ts +5 -1
- package/dist/esm/tools/base/AnnotationTool.js +7 -0
- package/dist/esm/tools/segmentation/CircleROIStartEndThresholdTool.d.ts +1 -1
- package/dist/esm/tools/segmentation/CircleROIStartEndThresholdTool.js +27 -22
- package/dist/esm/tools/segmentation/LabelmapBaseTool.d.ts +4 -1
- package/dist/esm/tools/segmentation/LabelmapBaseTool.js +65 -8
- package/dist/esm/tools/segmentation/LabelmapEditWithContour.d.ts +10 -6
- package/dist/esm/tools/segmentation/LabelmapEditWithContour.js +137 -54
- package/dist/esm/tools/segmentation/RectangleROIStartEndThresholdTool.d.ts +2 -40
- package/dist/esm/tools/segmentation/RectangleROIStartEndThresholdTool.js +28 -23
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/package.json +3 -3
|
@@ -17,7 +17,9 @@ export default function mouseDownActivate(evt) {
|
|
|
17
17
|
if (activeTool.addNewAnnotation) {
|
|
18
18
|
try {
|
|
19
19
|
const annotation = activeTool.addNewAnnotation(evt, 'mouse');
|
|
20
|
-
|
|
20
|
+
if (annotation?.annotationUID) {
|
|
21
|
+
setAnnotationSelected(annotation.annotationUID);
|
|
22
|
+
}
|
|
21
23
|
}
|
|
22
24
|
catch (error) {
|
|
23
25
|
cs3dLogger.warn('Error adding new annotation, viewport not ready:', error);
|
|
@@ -17,7 +17,9 @@ export default function touchStartActivate(evt) {
|
|
|
17
17
|
if (activeTool.addNewAnnotation) {
|
|
18
18
|
try {
|
|
19
19
|
const annotation = activeTool.addNewAnnotation(evt, 'touch');
|
|
20
|
-
|
|
20
|
+
if (annotation?.annotationUID) {
|
|
21
|
+
setAnnotationSelected(annotation.annotationUID);
|
|
22
|
+
}
|
|
21
23
|
}
|
|
22
24
|
catch (error) {
|
|
23
25
|
cs3dLogger.warn('Error adding new annotation, viewport not ready:', error);
|
|
@@ -229,7 +229,11 @@ export default class SegmentationStateManager {
|
|
|
229
229
|
delete state.viewportSegRepresentations[viewportId];
|
|
230
230
|
}
|
|
231
231
|
else if (activeRepresentationRemoved) {
|
|
232
|
-
state.viewportSegRepresentations[viewportId]
|
|
232
|
+
const remainingRepresentations = state.viewportSegRepresentations[viewportId];
|
|
233
|
+
const hasActiveRepresentation = remainingRepresentations.some((representation) => representation.active);
|
|
234
|
+
if (!hasActiveRepresentation) {
|
|
235
|
+
remainingRepresentations[0].active = true;
|
|
236
|
+
}
|
|
233
237
|
}
|
|
234
238
|
}
|
|
235
239
|
});
|
|
@@ -240,10 +244,9 @@ export default class SegmentationStateManager {
|
|
|
240
244
|
removedRepresentations.forEach((representation) => {
|
|
241
245
|
triggerSegmentationRepresentationRemoved(viewportId, representation.segmentationId, representation.type);
|
|
242
246
|
});
|
|
243
|
-
const
|
|
244
|
-
if (
|
|
245
|
-
|
|
246
|
-
triggerSegmentationRepresentationModified(viewportId, remainingRepresentations[0].segmentationId, remainingRepresentations[0].type);
|
|
247
|
+
const activeRepresentation = this.getSegmentationRepresentations(viewportId).find((representation) => representation.active);
|
|
248
|
+
if (activeRepresentation) {
|
|
249
|
+
triggerSegmentationRepresentationModified(viewportId, activeRepresentation.segmentationId, activeRepresentation.type);
|
|
247
250
|
}
|
|
248
251
|
return removedRepresentations;
|
|
249
252
|
}
|
|
@@ -21,7 +21,7 @@ function isSegmentIndexLocked(segmentationId, segmentIndex) {
|
|
|
21
21
|
throw new Error(`No segmentation state found for ${segmentationId}`);
|
|
22
22
|
}
|
|
23
23
|
const { segments } = segmentation;
|
|
24
|
-
return segments[segmentIndex]
|
|
24
|
+
return segments?.[segmentIndex]?.locked === true;
|
|
25
25
|
}
|
|
26
26
|
function setSegmentIndexLocked(segmentationId, segmentIndex, locked = true) {
|
|
27
27
|
const segmentation = getSegmentation(segmentationId);
|
|
@@ -140,7 +140,7 @@ class SliceIntersectionTool extends AnnotationTool {
|
|
|
140
140
|
if (!enabledElement) {
|
|
141
141
|
return false;
|
|
142
142
|
}
|
|
143
|
-
return !!this._findLineNear(enabledElement.viewport.id, canvasCoords, LINE_PROXIMITY, true);
|
|
143
|
+
return !!this._findLineNear(enabledElement.viewport.id, canvasCoords, LINE_PROXIMITY, { includeHandles: true });
|
|
144
144
|
};
|
|
145
145
|
this.toolSelectedCallback = (evt, _annotation) => {
|
|
146
146
|
const { element, currentPoints } = evt.detail;
|
|
@@ -217,7 +217,7 @@ class SliceIntersectionTool extends AnnotationTool {
|
|
|
217
217
|
if (!this._isPlanarViewport(viewport)) {
|
|
218
218
|
return false;
|
|
219
219
|
}
|
|
220
|
-
const lineInfo = this._findLineNear(viewport.id, currentPoints.canvas, LINE_PROXIMITY, true);
|
|
220
|
+
const lineInfo = this._findLineNear(viewport.id, currentPoints.canvas, LINE_PROXIMITY, { includeHandles: true, includeSlabLines: true });
|
|
221
221
|
let needsRedraw = false;
|
|
222
222
|
if (lineInfo) {
|
|
223
223
|
if (this._activeGroupId !== lineInfo.groupId ||
|
|
@@ -499,7 +499,7 @@ class SliceIntersectionTool extends AnnotationTool {
|
|
|
499
499
|
this._appendSlabGeometry(lineInfo, targetViewport, targetPlane, leaderViewport, leaderPlane);
|
|
500
500
|
this._appendBoundaryGeometry(lineInfo, targetViewport, targetPlane, leaderViewport, leaderPlane);
|
|
501
501
|
if (isActive) {
|
|
502
|
-
this._appendHandles(lineInfo,
|
|
502
|
+
this._appendHandles(lineInfo, leaderViewport);
|
|
503
503
|
}
|
|
504
504
|
return lineInfo;
|
|
505
505
|
}
|
|
@@ -606,7 +606,7 @@ class SliceIntersectionTool extends AnnotationTool {
|
|
|
606
606
|
spacing: Number.isFinite(spacing) ? spacing : 0,
|
|
607
607
|
};
|
|
608
608
|
}
|
|
609
|
-
_appendHandles(lineInfo,
|
|
609
|
+
_appendHandles(lineInfo, leaderViewport) {
|
|
610
610
|
const { rotatable, slabThicknessControls, showSlabThickness } = this.configuration;
|
|
611
611
|
const [start, end] = lineInfo.canvasPoints;
|
|
612
612
|
const volumeMode = this._isVolumeModeViewport(leaderViewport);
|
|
@@ -617,32 +617,22 @@ class SliceIntersectionTool extends AnnotationTool {
|
|
|
617
617
|
]);
|
|
618
618
|
}
|
|
619
619
|
if (slabThicknessControls && showSlabThickness && volumeMode) {
|
|
620
|
-
lineInfo.slabHandles = this._computeSlabHandles(lineInfo
|
|
620
|
+
lineInfo.slabHandles = this._computeSlabHandles(lineInfo);
|
|
621
621
|
}
|
|
622
622
|
}
|
|
623
|
-
_computeSlabHandles(lineInfo
|
|
623
|
+
_computeSlabHandles(lineInfo) {
|
|
624
624
|
const [start, end] = lineInfo.canvasPoints;
|
|
625
625
|
const anchorCanvas = [
|
|
626
626
|
start[0] + (end[0] - start[0]) * SLAB_HANDLE_LINE_FRACTION,
|
|
627
627
|
start[1] + (end[1] - start[1]) * SLAB_HANDLE_LINE_FRACTION,
|
|
628
628
|
];
|
|
629
|
-
const
|
|
630
|
-
const
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
];
|
|
637
|
-
const plusCanvas = targetViewport.worldToCanvas(plusWorld);
|
|
638
|
-
const canvasOffset = Math.hypot(plusCanvas[0] - anchorCanvas[0], plusCanvas[1] - anchorCanvas[1]);
|
|
639
|
-
if (canvasOffset >= MIN_SLAB_HANDLE_CANVAS_OFFSET) {
|
|
640
|
-
const minusWorld = [
|
|
641
|
-
anchorWorld[0] - normal[0] * (slabThickness / 2),
|
|
642
|
-
anchorWorld[1] - normal[1] * (slabThickness / 2),
|
|
643
|
-
anchorWorld[2] - normal[2] * (slabThickness / 2),
|
|
644
|
-
];
|
|
645
|
-
return [plusCanvas, targetViewport.worldToCanvas(minusWorld)];
|
|
629
|
+
const minimumOffsetSquared = MIN_SLAB_HANDLE_CANVAS_OFFSET * MIN_SLAB_HANDLE_CANVAS_OFFSET;
|
|
630
|
+
const handles = lineInfo.slabLineSegments
|
|
631
|
+
.map(([segmentStart, segmentEnd]) => lineSegment.distanceToPointSquaredInfo(segmentStart, segmentEnd, anchorCanvas))
|
|
632
|
+
.filter((info) => info.distanceSquared >= minimumOffsetSquared)
|
|
633
|
+
.map((info) => info.point);
|
|
634
|
+
if (handles.length) {
|
|
635
|
+
return handles;
|
|
646
636
|
}
|
|
647
637
|
const direction = vec2.normalize(vec2.create(), vec2.subtract(vec2.create(), end, start));
|
|
648
638
|
const perpendicular = [-direction[1], direction[0]];
|
|
@@ -951,7 +941,7 @@ class SliceIntersectionTool extends AnnotationTool {
|
|
|
951
941
|
targetViewportId: lineInfo.targetViewportId,
|
|
952
942
|
});
|
|
953
943
|
}
|
|
954
|
-
_findLineNear(viewportId, canvasCoords, proximity, includeHandles = false) {
|
|
944
|
+
_findLineNear(viewportId, canvasCoords, proximity, { includeHandles = false, includeSlabLines = false, } = {}) {
|
|
955
945
|
const lines = this._renderedLines.get(viewportId) ?? [];
|
|
956
946
|
const handleReach = this.configuration.handleRadius + proximity;
|
|
957
947
|
for (const lineInfo of lines) {
|
|
@@ -969,6 +959,22 @@ class SliceIntersectionTool extends AnnotationTool {
|
|
|
969
959
|
}
|
|
970
960
|
}
|
|
971
961
|
}
|
|
962
|
+
if (includeSlabLines && this.configuration.slabThicknessControls) {
|
|
963
|
+
let slabLineInfo = null;
|
|
964
|
+
let slabLineDistance = Infinity;
|
|
965
|
+
for (const lineInfo of lines) {
|
|
966
|
+
for (const [segmentStart, segmentEnd] of lineInfo.slabLineSegments) {
|
|
967
|
+
const distance = lineSegment.distanceToPoint(segmentStart, segmentEnd, canvasCoords);
|
|
968
|
+
if (distance <= proximity && distance < slabLineDistance) {
|
|
969
|
+
slabLineDistance = distance;
|
|
970
|
+
slabLineInfo = lineInfo;
|
|
971
|
+
}
|
|
972
|
+
}
|
|
973
|
+
}
|
|
974
|
+
if (slabLineInfo) {
|
|
975
|
+
return slabLineInfo;
|
|
976
|
+
}
|
|
977
|
+
}
|
|
972
978
|
return null;
|
|
973
979
|
}
|
|
974
980
|
_getViewportsInfo() {
|
|
@@ -23,7 +23,7 @@ declare abstract class AnnotationTool extends AnnotationDisplayTool {
|
|
|
23
23
|
static createAndAddAnnotation(viewport: any, ...annotationBaseData: any[]): void;
|
|
24
24
|
static toolName: any;
|
|
25
25
|
constructor(toolProps: PublicToolProps, defaultToolProps: ToolProps);
|
|
26
|
-
abstract addNewAnnotation(evt: EventTypes.InteractionEventType, interactionType: InteractionTypes): Annotation;
|
|
26
|
+
abstract addNewAnnotation(evt: EventTypes.InteractionEventType, interactionType: InteractionTypes): Annotation | null;
|
|
27
27
|
abstract cancel(element: HTMLDivElement): any;
|
|
28
28
|
abstract handleSelectedCallback(evt: EventTypes.InteractionEventType, annotation: Annotation, handle: ToolHandle, interactionType: InteractionTypes): void;
|
|
29
29
|
abstract toolSelectedCallback(evt: EventTypes.InteractionEventType, annotation: Annotation, interactionType: InteractionTypes, canvasCoords?: Types.Point2): void;
|
|
@@ -47,6 +47,10 @@ declare abstract class AnnotationTool extends AnnotationDisplayTool {
|
|
|
47
47
|
}): boolean;
|
|
48
48
|
static isSuvScaled(viewport: Types.IStackViewport | Types.IVolumeViewport, targetId: string, imageId?: string): boolean;
|
|
49
49
|
isSuvScaled: typeof AnnotationTool.isSuvScaled;
|
|
50
|
+
protected getTargetVolume(viewport: Types.IViewport): {
|
|
51
|
+
targetId: string;
|
|
52
|
+
imageVolume: Types.IImageVolume;
|
|
53
|
+
} | null;
|
|
50
54
|
protected getAnnotationStyle(context: {
|
|
51
55
|
annotation: Annotation;
|
|
52
56
|
styleSpecifier: StyleSpecifier;
|
|
@@ -196,6 +196,13 @@ class AnnotationTool extends AnnotationDisplayTool {
|
|
|
196
196
|
const scalingModule = imageId && metaData.get('scalingModule', imageId);
|
|
197
197
|
return typeof scalingModule?.suvbw === 'number';
|
|
198
198
|
}
|
|
199
|
+
getTargetVolume(viewport) {
|
|
200
|
+
const targetId = this.getTargetId(viewport);
|
|
201
|
+
const imageVolume = targetId
|
|
202
|
+
? cache.getVolume(csUtils.getVolumeId(targetId))
|
|
203
|
+
: undefined;
|
|
204
|
+
return imageVolume ? { targetId, imageVolume } : null;
|
|
205
|
+
}
|
|
199
206
|
getAnnotationStyle(context) {
|
|
200
207
|
const { annotation, styleSpecifier } = context;
|
|
201
208
|
const getStyle = (property) => this.getStyle(property, styleSpecifier, annotation);
|
|
@@ -16,7 +16,7 @@ declare class CircleROIStartEndThresholdTool extends CircleROITool {
|
|
|
16
16
|
isDrawing: boolean;
|
|
17
17
|
isHandleOutsideImage: boolean;
|
|
18
18
|
constructor(toolProps?: PublicToolProps, defaultToolProps?: ToolProps);
|
|
19
|
-
addNewAnnotation: (evt: EventTypes.InteractionEventType) => Annotation;
|
|
19
|
+
addNewAnnotation: (evt: EventTypes.InteractionEventType) => Annotation | null;
|
|
20
20
|
_endCallback: (evt: EventTypes.InteractionEventType) => void;
|
|
21
21
|
renderAnnotation: (enabledElement: Types.IEnabledElement, svgDrawingHelper: SVGDrawingHelper) => boolean;
|
|
22
22
|
_computeProjectionPoints(annotation: CircleROIStartEndThresholdAnnotation, imageVolume: Types.IImageVolume): void;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { StackViewport,
|
|
1
|
+
import { StackViewport, getEnabledElement, utilities as csUtils, utilities as coreUtils, } from '@cornerstonejs/core';
|
|
2
2
|
import { vec3 } from 'gl-matrix';
|
|
3
3
|
import { addAnnotation, removeAnnotation, getAnnotations, } from '../../stateManagement/annotation/annotationState.js';
|
|
4
4
|
import { isAnnotationLocked } from '../../stateManagement/annotation/annotationLocking.js';
|
|
@@ -44,19 +44,19 @@ class CircleROIStartEndThresholdTool extends CircleROITool {
|
|
|
44
44
|
const worldPos = currentPoints.world;
|
|
45
45
|
const enabledElement = getEnabledElement(element);
|
|
46
46
|
const { viewport } = enabledElement;
|
|
47
|
-
this.isDrawing = true;
|
|
48
47
|
const camera = viewport.getCamera();
|
|
49
48
|
const { viewPlaneNormal, viewUp } = camera;
|
|
50
|
-
let referencedImageId, imageVolume, volumeId;
|
|
51
49
|
if (viewport instanceof StackViewport) {
|
|
52
50
|
throw new Error('Stack Viewport Not implemented');
|
|
53
51
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
imageVolume = cache.getVolume(volumeId);
|
|
58
|
-
referencedImageId = csUtils.getClosestImageId(imageVolume, worldPos, viewPlaneNormal);
|
|
52
|
+
const target = this.getTargetVolume(viewport);
|
|
53
|
+
if (!target) {
|
|
54
|
+
return null;
|
|
59
55
|
}
|
|
56
|
+
const volumeId = csUtils.getVolumeId(target.targetId);
|
|
57
|
+
const imageVolume = target.imageVolume;
|
|
58
|
+
const referencedImageId = csUtils.getClosestImageId(imageVolume, worldPos, viewPlaneNormal);
|
|
59
|
+
this.isDrawing = true;
|
|
60
60
|
const spacingInNormal = csUtils.getSpacingInNormalDirection(imageVolume, viewPlaneNormal);
|
|
61
61
|
const startCoord = this._getStartCoordinate(worldPos, spacingInNormal, viewPlaneNormal);
|
|
62
62
|
const endCoord = this._getEndCoordinate(worldPos, spacingInNormal, viewPlaneNormal);
|
|
@@ -148,9 +148,10 @@ class CircleROIStartEndThresholdTool extends CircleROITool {
|
|
|
148
148
|
this.configuration.preventHandleOutsideImage) {
|
|
149
149
|
removeAnnotation(annotation.annotationUID);
|
|
150
150
|
}
|
|
151
|
-
const
|
|
152
|
-
|
|
153
|
-
|
|
151
|
+
const target = this.getTargetVolume(enabledElement.viewport);
|
|
152
|
+
if (target) {
|
|
153
|
+
this._computePointsInsideVolume(annotation, target.imageVolume, target.targetId, enabledElement);
|
|
154
|
+
}
|
|
154
155
|
triggerAnnotationRenderForViewportIds(viewportIdsToRender);
|
|
155
156
|
if (newAnnotation) {
|
|
156
157
|
triggerAnnotationCompleted(annotation);
|
|
@@ -221,12 +222,10 @@ class CircleROIStartEndThresholdTool extends CircleROITool {
|
|
|
221
222
|
isMiddleSlice = true;
|
|
222
223
|
}
|
|
223
224
|
data.handles.points[0][this._getIndexOfCoordinatesForViewplaneNormal(viewplaneNormal)] = middleCoordinate;
|
|
224
|
-
const
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
this._throttledCalculateCachedStats(annotation, annotationEnabledElement);
|
|
229
|
-
}
|
|
225
|
+
const annotationViewport = annotationEnabledElement?.viewport;
|
|
226
|
+
if (annotation.invalidated &&
|
|
227
|
+
annotationViewport?.hasVolumeId?.(metadata.volumeId)) {
|
|
228
|
+
this._throttledCalculateCachedStats(annotation, annotationEnabledElement);
|
|
230
229
|
}
|
|
231
230
|
if (!viewport.getRenderingEngine()) {
|
|
232
231
|
cs3dLogger.warn('Rendering Engine has been destroyed');
|
|
@@ -364,7 +363,8 @@ class CircleROIStartEndThresholdTool extends CircleROITool {
|
|
|
364
363
|
const basePos1 = viewport.canvasToWorld(baseTopLeftCanvas);
|
|
365
364
|
const basePos2 = viewport.canvasToWorld(baseBottomRightCanvas);
|
|
366
365
|
const { worldWidth, worldHeight } = getWorldWidthAndHeightFromTwoPoints(viewPlaneNormal, viewUp, basePos1, basePos2);
|
|
367
|
-
const
|
|
366
|
+
const indexCoordinates = data.handles.points.map((point) => image.imageData.worldToIndex(point));
|
|
367
|
+
const measureInfo = getCalibratedLengthUnitsAndScale(image, indexCoordinates);
|
|
368
368
|
const aspect = getCalibratedAspect(image);
|
|
369
369
|
const area = Math.abs(Math.PI *
|
|
370
370
|
(worldWidth / measureInfo.scale / 2) *
|
|
@@ -373,7 +373,8 @@ class CircleROIStartEndThresholdTool extends CircleROITool {
|
|
|
373
373
|
isPreScaled: isViewportPreScaled(viewport, targetId),
|
|
374
374
|
isSuvScaled: this.isSuvScaled(viewport, targetId, annotation.metadata.referencedImageId),
|
|
375
375
|
};
|
|
376
|
-
const
|
|
376
|
+
const modality = imageVolume?.metadata?.Modality;
|
|
377
|
+
const modalityUnit = getPixelValueUnits(modality, annotation.metadata.referencedImageId, modalityUnitOptions);
|
|
377
378
|
for (let i = 0; i < projectionPoints.length; i++) {
|
|
378
379
|
if (!imageVolume) {
|
|
379
380
|
continue;
|
|
@@ -437,7 +438,7 @@ class CircleROIStartEndThresholdTool extends CircleROITool {
|
|
|
437
438
|
const stats = this.configuration.statsCalculator.getStatistics();
|
|
438
439
|
data.cachedStats.pointsInVolume = pointsInsideVolume;
|
|
439
440
|
data.cachedStats.statistics = {
|
|
440
|
-
Modality:
|
|
441
|
+
Modality: modality,
|
|
441
442
|
area,
|
|
442
443
|
mean: stats.mean?.value,
|
|
443
444
|
stdDev: stats.stdDev?.value,
|
|
@@ -451,8 +452,12 @@ class CircleROIStartEndThresholdTool extends CircleROITool {
|
|
|
451
452
|
const data = annotation.data;
|
|
452
453
|
const { viewport } = enabledElement;
|
|
453
454
|
const { cachedStats } = data;
|
|
454
|
-
const
|
|
455
|
-
|
|
455
|
+
const target = this.getTargetVolume(viewport);
|
|
456
|
+
if (!target) {
|
|
457
|
+
annotation.invalidated = false;
|
|
458
|
+
return cachedStats;
|
|
459
|
+
}
|
|
460
|
+
const { targetId, imageVolume } = target;
|
|
456
461
|
this._computeProjectionPoints(annotation, imageVolume);
|
|
457
462
|
this._computePointsInsideVolume(annotation, imageVolume, targetId, enabledElement);
|
|
458
463
|
annotation.invalidated = false;
|
|
@@ -3,6 +3,7 @@ import { BaseTool } from '../base/index.js';
|
|
|
3
3
|
import type vtkImageData from '@kitware/vtk.js/Common/DataModel/ImageData';
|
|
4
4
|
import * as LabelmapMemo from '../../utilities/segmentation/createLabelmapMemo.js';
|
|
5
5
|
import type { LabelmapToolOperationData } from '../../types/LabelmapToolOperationData.js';
|
|
6
|
+
import type { Annotations } from '../../types/index.js';
|
|
6
7
|
export type PreviewData = {
|
|
7
8
|
preview: unknown;
|
|
8
9
|
timer?: number;
|
|
@@ -114,7 +115,9 @@ export default class LabelmapBaseTool extends BaseTool {
|
|
|
114
115
|
rejectPreview(element?: HTMLDivElement): void;
|
|
115
116
|
acceptPreview(element?: HTMLDivElement): void;
|
|
116
117
|
static viewportContoursToLabelmap(viewport: Types.IViewport, options?: {
|
|
117
|
-
removeContours
|
|
118
|
+
removeContours?: boolean;
|
|
119
|
+
annotationFilter?: (annotations: Annotations) => Annotations;
|
|
120
|
+
strokeStartPoint?: Types.Point3;
|
|
118
121
|
}): void;
|
|
119
122
|
}
|
|
120
123
|
export {};
|
|
@@ -17,6 +17,8 @@ import { fillInsideCircle } from './strategies/index.js';
|
|
|
17
17
|
import getViewportLabelmapRenderMode from '../../stateManagement/segmentation/helpers/getViewportLabelmapRenderMode.js';
|
|
18
18
|
import { getOrCreateLabelmapVolume, resolveLabelmapForSegment, } from '../../stateManagement/segmentation/helpers/labelmapSegmentationState.js';
|
|
19
19
|
import getViewportICamera from '../../utilities/getViewportICamera.js';
|
|
20
|
+
import { getHiddenSegmentIndices } from '../../stateManagement/segmentation/config/segmentationVisibility.js';
|
|
21
|
+
import { removeContourSegmentationAnnotation } from '../../utilities/contourSegmentation/removeContourSegmentationAnnotation.js';
|
|
20
22
|
import triggerAnnotationRenderForViewportIds from '../../utilities/triggerAnnotationRenderForViewportIds.js';
|
|
21
23
|
import { resetElementCursor } from '../../cursors/elementCursor.js';
|
|
22
24
|
const { asUnitNormal } = csUtils.voxelSlab;
|
|
@@ -324,12 +326,15 @@ class LabelmapBaseTool extends BaseTool {
|
|
|
324
326
|
static viewportContoursToLabelmap(viewport, options) {
|
|
325
327
|
const removeContours = options?.removeContours ?? true;
|
|
326
328
|
const annotations = getAllAnnotations();
|
|
327
|
-
const
|
|
328
|
-
|
|
329
|
+
const polylineAnnotations = annotations.filter((annotation) => annotation.data.contour?.polyline?.length);
|
|
330
|
+
const contourAnnotations = options?.annotationFilter
|
|
331
|
+
? options.annotationFilter(polylineAnnotations)
|
|
332
|
+
: polylineAnnotations;
|
|
333
|
+
if (!contourAnnotations.length) {
|
|
329
334
|
return;
|
|
330
335
|
}
|
|
331
|
-
const
|
|
332
|
-
if (!
|
|
336
|
+
const viewAnnotations = filterAnnotationsForDisplay(viewport, contourAnnotations);
|
|
337
|
+
if (!viewAnnotations?.length) {
|
|
333
338
|
return;
|
|
334
339
|
}
|
|
335
340
|
const brushInstance = new LabelmapBaseTool({}, {
|
|
@@ -354,12 +359,15 @@ class LabelmapBaseTool extends BaseTool {
|
|
|
354
359
|
spacing: imageData.getSpacing(),
|
|
355
360
|
origin: imageData.getOrigin(),
|
|
356
361
|
};
|
|
357
|
-
|
|
362
|
+
const isSegmentEditable = createSegmentEditableLookup(viewport.id, segmentationId);
|
|
363
|
+
for (const annotation of viewAnnotations) {
|
|
358
364
|
const { polyline } = annotation.data.contour;
|
|
359
365
|
const camera = viewport.getCamera();
|
|
360
366
|
const viewPlaneNormal = asUnitNormal(annotation.metadata?.viewPlaneNormal ?? camera.viewPlaneNormal);
|
|
361
367
|
const activeIndex = getActiveSegmentIndex(segmentationId);
|
|
362
|
-
const startPoint =
|
|
368
|
+
const startPoint = options?.strokeStartPoint ||
|
|
369
|
+
annotation.data.handles?.[0] ||
|
|
370
|
+
polyline[0];
|
|
363
371
|
const startIndex = imageData.worldToIndex(startPoint).map(Math.round);
|
|
364
372
|
const startValue = segmentationVoxels.getAtIJKPoint(startIndex) || 0;
|
|
365
373
|
let hasZeroIndex = false;
|
|
@@ -375,25 +383,39 @@ class LabelmapBaseTool extends BaseTool {
|
|
|
375
383
|
}
|
|
376
384
|
}
|
|
377
385
|
const hasBoth = hasZeroIndex && hasPositiveIndex;
|
|
378
|
-
|
|
386
|
+
let segmentIndex = hasBoth
|
|
379
387
|
? startValue
|
|
380
388
|
: startValue === 0
|
|
381
389
|
? activeIndex
|
|
382
390
|
: 0;
|
|
391
|
+
if (!isSegmentEditable(segmentIndex)) {
|
|
392
|
+
segmentIndex = activeIndex;
|
|
393
|
+
}
|
|
394
|
+
if (!isSegmentEditable(segmentIndex)) {
|
|
395
|
+
if (removeContours) {
|
|
396
|
+
removeContourAnnotation(annotation);
|
|
397
|
+
}
|
|
398
|
+
continue;
|
|
399
|
+
}
|
|
383
400
|
for (const ijk of iterateContourFillVoxels({
|
|
384
401
|
volume,
|
|
385
402
|
polyline,
|
|
386
403
|
viewPlaneNormal,
|
|
387
404
|
imageData,
|
|
388
405
|
})) {
|
|
406
|
+
const currentSegmentIndex = segmentationVoxels.getAtIJK(ijk[0], ijk[1], ijk[2]);
|
|
407
|
+
if (!isSegmentEditable(currentSegmentIndex)) {
|
|
408
|
+
continue;
|
|
409
|
+
}
|
|
389
410
|
previewVoxels.setAtIJK(ijk[0], ijk[1], ijk[2], segmentIndex);
|
|
390
411
|
}
|
|
391
412
|
if (removeContours) {
|
|
392
|
-
|
|
413
|
+
removeContourAnnotation(annotation);
|
|
393
414
|
}
|
|
394
415
|
}
|
|
395
416
|
const slices = previewVoxels.getArrayOfModifiedSlices();
|
|
396
417
|
triggerSegmentationDataModified(segmentationId, slices);
|
|
418
|
+
brushInstance.doneEditMemo();
|
|
397
419
|
}
|
|
398
420
|
}
|
|
399
421
|
LabelmapBaseTool.previewData = {
|
|
@@ -405,6 +427,41 @@ LabelmapBaseTool.previewData = {
|
|
|
405
427
|
isDrag: false,
|
|
406
428
|
};
|
|
407
429
|
export default LabelmapBaseTool;
|
|
430
|
+
const SEGMENT_UNKNOWN = 0;
|
|
431
|
+
const SEGMENT_EDITABLE = 1;
|
|
432
|
+
const SEGMENT_BLOCKED = 2;
|
|
433
|
+
function createSegmentEditableLookup(viewportId, segmentationId) {
|
|
434
|
+
const segments = getSegmentation(segmentationId)?.segments;
|
|
435
|
+
const hiddenSegmentIndices = getHiddenSegmentIndices(viewportId, {
|
|
436
|
+
segmentationId,
|
|
437
|
+
type: SegmentationRepresentations.Labelmap,
|
|
438
|
+
});
|
|
439
|
+
let cache = new Uint8Array(64);
|
|
440
|
+
return function isSegmentEditable(segmentIndex) {
|
|
441
|
+
if (!(segmentIndex > 0)) {
|
|
442
|
+
return true;
|
|
443
|
+
}
|
|
444
|
+
if (segmentIndex >= cache.length) {
|
|
445
|
+
const grown = new Uint8Array(Math.max(segmentIndex + 1, cache.length * 2));
|
|
446
|
+
grown.set(cache);
|
|
447
|
+
cache = grown;
|
|
448
|
+
}
|
|
449
|
+
const cached = cache[segmentIndex];
|
|
450
|
+
if (cached !== SEGMENT_UNKNOWN) {
|
|
451
|
+
return cached === SEGMENT_EDITABLE;
|
|
452
|
+
}
|
|
453
|
+
const isEditable = segments?.[segmentIndex]?.locked !== true &&
|
|
454
|
+
!hiddenSegmentIndices.has(segmentIndex);
|
|
455
|
+
cache[segmentIndex] = isEditable ? SEGMENT_EDITABLE : SEGMENT_BLOCKED;
|
|
456
|
+
return isEditable;
|
|
457
|
+
};
|
|
458
|
+
}
|
|
459
|
+
function removeContourAnnotation(annotation) {
|
|
460
|
+
removeAnnotation(annotation.annotationUID);
|
|
461
|
+
if (annotation.data?.segmentation) {
|
|
462
|
+
removeContourSegmentationAnnotation(annotation);
|
|
463
|
+
}
|
|
464
|
+
}
|
|
408
465
|
function lightenColor(r, g, b, a, factor = 0.4) {
|
|
409
466
|
return [
|
|
410
467
|
Math.round(r + (255 - r) * factor),
|
|
@@ -1,21 +1,25 @@
|
|
|
1
1
|
import PlanarFreehandContourSegmentationTool from '../annotation/PlanarFreehandContourSegmentationTool.js';
|
|
2
2
|
import type { PublicToolProps } from '../../types/index.js';
|
|
3
|
+
import type { Segmentation } from '../../types/SegmentationStateTypes.js';
|
|
3
4
|
declare class LabelMapEditWithContourTool extends PlanarFreehandContourSegmentationTool {
|
|
4
5
|
static toolName: string;
|
|
5
6
|
static annotationsToViewportMap: Map<any, any>;
|
|
6
|
-
private
|
|
7
|
-
private
|
|
8
|
-
static
|
|
7
|
+
private static temporaryContourData;
|
|
8
|
+
private static temporaryContourViewports;
|
|
9
|
+
private static clearTemporaryContourRecords;
|
|
10
|
+
private static getViewportContourKey;
|
|
9
11
|
constructor(toolProps?: PublicToolProps);
|
|
12
|
+
private initializeAddNewAnnotationHandler;
|
|
10
13
|
protected initializeListeners(): void;
|
|
11
14
|
protected cleanUpListeners(): void;
|
|
12
|
-
protected checkContourSegmentation(viewportId: string): Promise<boolean>;
|
|
13
|
-
protected
|
|
14
|
-
protected onSegmentationModified(evt: any): void;
|
|
15
|
+
protected checkContourSegmentation(viewportId: string, activeSeg: Segmentation): Promise<boolean>;
|
|
16
|
+
protected createMemo(element: any, annotation: any, options?: any): void;
|
|
15
17
|
onSetToolEnabled(): void;
|
|
16
18
|
onSetToolActive(): void;
|
|
17
19
|
onSetToolDisabled(): void;
|
|
18
20
|
annotationModified(evt: any): void;
|
|
21
|
+
private static hasContourContent;
|
|
22
|
+
private static cleanupTemporaryContourRepresentation;
|
|
19
23
|
annotationCompleted(evt: any): void;
|
|
20
24
|
}
|
|
21
25
|
export default LabelMapEditWithContourTool;
|
|
@@ -1,12 +1,21 @@
|
|
|
1
1
|
import { Events, SegmentationRepresentations } from '../../enums/index.js';
|
|
2
|
-
import { eventTarget, utilities, getRenderingEngine, } from '@cornerstonejs/core';
|
|
2
|
+
import { eventTarget, utilities, getRenderingEngine, getEnabledElement, } from '@cornerstonejs/core';
|
|
3
3
|
import PlanarFreehandContourSegmentationTool from '../annotation/PlanarFreehandContourSegmentationTool.js';
|
|
4
4
|
import BrushTool from './BrushTool.js';
|
|
5
5
|
import * as segmentation from '../../stateManagement/segmentation/index.js';
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
|
|
6
|
+
import { getSegmentationRepresentation } from '../../stateManagement/segmentation/getSegmentationRepresentation.js';
|
|
7
|
+
import { getActiveSegmentIndex } from '../../stateManagement/segmentation/getActiveSegmentIndex.js';
|
|
8
|
+
import { isSegmentIndexLocked } from '../../stateManagement/segmentation/segmentLocking.js';
|
|
9
|
+
import { getSegmentIndexVisibility } from '../../stateManagement/segmentation/config/segmentationVisibility.js';
|
|
10
|
+
const cs3dLogger = utilities.logger.toolsLog.getLogger('tools.segmentation.LabelmapEditWithContour');
|
|
9
11
|
class LabelMapEditWithContourTool extends PlanarFreehandContourSegmentationTool {
|
|
12
|
+
static clearTemporaryContourRecords() {
|
|
13
|
+
LabelMapEditWithContourTool.temporaryContourData.clear();
|
|
14
|
+
LabelMapEditWithContourTool.temporaryContourViewports.clear();
|
|
15
|
+
}
|
|
16
|
+
static getViewportContourKey(viewportId, segmentationId) {
|
|
17
|
+
return `${viewportId}\u0000${segmentationId}`;
|
|
18
|
+
}
|
|
10
19
|
constructor(toolProps = {}) {
|
|
11
20
|
const initialProps = utilities.deepMerge({
|
|
12
21
|
configuration: {
|
|
@@ -15,74 +24,81 @@ class LabelMapEditWithContourTool extends PlanarFreehandContourSegmentationTool
|
|
|
15
24
|
},
|
|
16
25
|
}, toolProps);
|
|
17
26
|
super(initialProps);
|
|
18
|
-
this.
|
|
19
|
-
|
|
20
|
-
|
|
27
|
+
this.initializeAddNewAnnotationHandler();
|
|
28
|
+
}
|
|
29
|
+
initializeAddNewAnnotationHandler() {
|
|
30
|
+
const originalAddNewAnnotation = this.addNewAnnotation.bind(this);
|
|
31
|
+
this.addNewAnnotation = (evt) => {
|
|
32
|
+
const { element } = evt.detail;
|
|
33
|
+
const enabledElement = getEnabledElement(element);
|
|
34
|
+
if (enabledElement) {
|
|
35
|
+
const viewportId = enabledElement.viewport.id;
|
|
36
|
+
const activeSeg = segmentation.getActiveSegmentation(viewportId);
|
|
37
|
+
if (!activeSeg) {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
const activeSegIndex = getActiveSegmentIndex(activeSeg.segmentationId);
|
|
41
|
+
if (activeSegIndex === undefined) {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
const isSegmentLocked = isSegmentIndexLocked(activeSeg.segmentationId, activeSegIndex);
|
|
45
|
+
const isSegmentHidden = !getSegmentIndexVisibility(viewportId, {
|
|
46
|
+
segmentationId: activeSeg.segmentationId,
|
|
47
|
+
type: SegmentationRepresentations.Labelmap,
|
|
48
|
+
}, activeSegIndex);
|
|
49
|
+
if (isSegmentLocked || isSegmentHidden) {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
LabelMapEditWithContourTool.clearTemporaryContourRecords();
|
|
53
|
+
this.checkContourSegmentation(viewportId, activeSeg).catch((error) => {
|
|
54
|
+
cs3dLogger.warn('Failed to add the temporary contour representation:', error);
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
return originalAddNewAnnotation(evt);
|
|
58
|
+
};
|
|
21
59
|
}
|
|
22
60
|
initializeListeners() {
|
|
23
61
|
LabelMapEditWithContourTool.annotationsToViewportMap.clear();
|
|
24
|
-
LabelMapEditWithContourTool.viewportIdsChecked = [];
|
|
25
62
|
eventTarget.addEventListener(Events.ANNOTATION_MODIFIED, this.annotationModified);
|
|
26
63
|
eventTarget.addEventListener(Events.ANNOTATION_COMPLETED, this.annotationCompleted);
|
|
27
|
-
eventTarget.addEventListener(Events.TOOLGROUP_VIEWPORT_ADDED, this.onViewportAddedToToolGroupBinded);
|
|
28
|
-
eventTarget.addEventListener(Events.SEGMENTATION_MODIFIED, this.onSegmentationModifiedBinded);
|
|
29
|
-
eventTarget.addEventListener(Events.SEGMENTATION_REPRESENTATION_MODIFIED, this.onSegmentationModifiedBinded);
|
|
30
64
|
}
|
|
31
65
|
cleanUpListeners() {
|
|
32
66
|
LabelMapEditWithContourTool.annotationsToViewportMap.clear();
|
|
33
|
-
LabelMapEditWithContourTool.
|
|
67
|
+
LabelMapEditWithContourTool.clearTemporaryContourRecords();
|
|
34
68
|
eventTarget.removeEventListener(Events.ANNOTATION_MODIFIED, this.annotationModified);
|
|
35
69
|
eventTarget.removeEventListener(Events.ANNOTATION_COMPLETED, this.annotationCompleted);
|
|
36
|
-
eventTarget.removeEventListener(Events.TOOLGROUP_VIEWPORT_ADDED, this.onViewportAddedToToolGroup.bind(this));
|
|
37
|
-
eventTarget.removeEventListener(Events.SEGMENTATION_MODIFIED, this.onSegmentationModified.bind(this));
|
|
38
|
-
eventTarget.removeEventListener(Events.SEGMENTATION_REPRESENTATION_MODIFIED, this.onSegmentationModified.bind(this));
|
|
39
70
|
}
|
|
40
|
-
async checkContourSegmentation(viewportId) {
|
|
41
|
-
if (LabelMapEditWithContourTool.viewportIdsChecked.includes(viewportId)) {
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
const activeSeg = segmentation.getActiveSegmentation(viewportId);
|
|
71
|
+
async checkContourSegmentation(viewportId, activeSeg) {
|
|
45
72
|
if (!activeSeg) {
|
|
46
73
|
cs3dLogger.info('No active segmentation detected');
|
|
47
74
|
return false;
|
|
48
75
|
}
|
|
49
76
|
const segmentationId = activeSeg.segmentationId;
|
|
50
77
|
if (!activeSeg.representationData.Contour) {
|
|
51
|
-
LabelMapEditWithContourTool.viewportIdsChecked.push(viewportId);
|
|
52
|
-
await segmentation.addContourRepresentationToViewport(viewportId, [
|
|
53
|
-
{
|
|
54
|
-
segmentationId,
|
|
55
|
-
type: SegmentationRepresentations.Contour,
|
|
56
|
-
},
|
|
57
|
-
]);
|
|
58
78
|
segmentation.addRepresentationData({
|
|
59
79
|
segmentationId,
|
|
60
80
|
type: SegmentationRepresentations.Contour,
|
|
61
81
|
data: {},
|
|
62
82
|
});
|
|
83
|
+
LabelMapEditWithContourTool.temporaryContourData.add(segmentationId);
|
|
63
84
|
}
|
|
64
|
-
|
|
65
|
-
|
|
85
|
+
const hasViewportContour = getSegmentationRepresentation(viewportId, {
|
|
86
|
+
segmentationId,
|
|
87
|
+
type: SegmentationRepresentations.Contour,
|
|
88
|
+
});
|
|
89
|
+
if (!hasViewportContour) {
|
|
90
|
+
await segmentation.addContourRepresentationToViewport(viewportId, [
|
|
91
|
+
{
|
|
92
|
+
segmentationId,
|
|
93
|
+
type: SegmentationRepresentations.Contour,
|
|
94
|
+
},
|
|
95
|
+
]);
|
|
96
|
+
LabelMapEditWithContourTool.temporaryContourViewports.add(LabelMapEditWithContourTool.getViewportContourKey(viewportId, segmentationId));
|
|
66
97
|
}
|
|
67
98
|
return true;
|
|
68
99
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
if (toolGroupId !== this.toolGroupId) {
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
this.checkContourSegmentation(viewportId);
|
|
75
|
-
}
|
|
76
|
-
onSegmentationModified(evt) {
|
|
77
|
-
const { segmentationId } = evt.detail || {};
|
|
78
|
-
if (!segmentationId) {
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
const representations = getSegmentationRepresentationsBySegmentationId(segmentationId);
|
|
82
|
-
if (!representations) {
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
|
-
representations.forEach(async ({ viewportId }) => await this.checkContourSegmentation(viewportId));
|
|
100
|
+
createMemo(element, annotation, options) {
|
|
101
|
+
return;
|
|
86
102
|
}
|
|
87
103
|
onSetToolEnabled() {
|
|
88
104
|
this.initializeListeners();
|
|
@@ -95,30 +111,97 @@ class LabelMapEditWithContourTool extends PlanarFreehandContourSegmentationTool
|
|
|
95
111
|
}
|
|
96
112
|
annotationModified(evt) {
|
|
97
113
|
const { annotation, renderingEngineId, viewportId } = evt.detail;
|
|
114
|
+
if (annotation?.metadata?.toolName !== LabelMapEditWithContourTool.toolName) {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
98
117
|
const viewport = getRenderingEngine(renderingEngineId)?.getViewport(viewportId);
|
|
99
118
|
if (!viewport) {
|
|
100
119
|
return;
|
|
101
120
|
}
|
|
102
121
|
LabelMapEditWithContourTool.annotationsToViewportMap.set(annotation.annotationUID, viewport);
|
|
103
122
|
}
|
|
123
|
+
static hasContourContent(contourData) {
|
|
124
|
+
if (contourData.geometryIds?.length) {
|
|
125
|
+
return true;
|
|
126
|
+
}
|
|
127
|
+
const { annotationUIDsMap } = contourData;
|
|
128
|
+
if (!annotationUIDsMap) {
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
for (const annotationUIDs of annotationUIDsMap.values()) {
|
|
132
|
+
if (annotationUIDs.size) {
|
|
133
|
+
return true;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return false;
|
|
137
|
+
}
|
|
138
|
+
static cleanupTemporaryContourRepresentation(viewport, annotation) {
|
|
139
|
+
const segmentationId = annotation?.data?.segmentation?.segmentationId;
|
|
140
|
+
if (!segmentationId) {
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
const viewportKey = LabelMapEditWithContourTool.getViewportContourKey(viewport.id, segmentationId);
|
|
144
|
+
const ownsViewportContour = LabelMapEditWithContourTool.temporaryContourViewports.has(viewportKey);
|
|
145
|
+
const ownsContourData = LabelMapEditWithContourTool.temporaryContourData.has(segmentationId);
|
|
146
|
+
if (!ownsViewportContour && !ownsContourData) {
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
const segmentationState = segmentation.state.getSegmentation(segmentationId);
|
|
150
|
+
const contourData = segmentationState?.representationData?.Contour;
|
|
151
|
+
if (contourData &&
|
|
152
|
+
LabelMapEditWithContourTool.hasContourContent(contourData)) {
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
if (ownsViewportContour) {
|
|
156
|
+
LabelMapEditWithContourTool.temporaryContourViewports.delete(viewportKey);
|
|
157
|
+
segmentation.removeContourRepresentation(viewport.id, segmentationId);
|
|
158
|
+
}
|
|
159
|
+
if (!ownsContourData || !segmentationState) {
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
LabelMapEditWithContourTool.temporaryContourData.delete(segmentationId);
|
|
163
|
+
const representationData = utilities.deepClone(segmentationState.representationData);
|
|
164
|
+
delete representationData.Contour;
|
|
165
|
+
segmentation.updateSegmentations([
|
|
166
|
+
{
|
|
167
|
+
segmentationId,
|
|
168
|
+
payload: {
|
|
169
|
+
representationData,
|
|
170
|
+
},
|
|
171
|
+
},
|
|
172
|
+
], true);
|
|
173
|
+
}
|
|
104
174
|
annotationCompleted(evt) {
|
|
105
175
|
const { annotation } = evt.detail;
|
|
106
|
-
const { polyline } = annotation.data?.contour || {};
|
|
107
176
|
if (annotation?.metadata?.toolName !== LabelMapEditWithContourTool.toolName) {
|
|
108
177
|
return;
|
|
109
178
|
}
|
|
110
|
-
|
|
179
|
+
const annotationUID = annotation.annotationUID;
|
|
180
|
+
const viewport = LabelMapEditWithContourTool.annotationsToViewportMap.get(annotationUID);
|
|
181
|
+
if (!viewport) {
|
|
111
182
|
return;
|
|
112
183
|
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
184
|
+
const polyline = annotation.data?.contour?.polyline;
|
|
185
|
+
const segmentationData = annotation.data
|
|
186
|
+
?.segmentation;
|
|
187
|
+
if (polyline?.length >= 3 && segmentationData) {
|
|
188
|
+
BrushTool.viewportContoursToLabelmap(viewport, {
|
|
189
|
+
strokeStartPoint: polyline[0],
|
|
190
|
+
annotationFilter: (annotations) => annotations.filter((candidate) => {
|
|
191
|
+
const candidateSegmentation = candidate.data?.segmentation;
|
|
192
|
+
return (candidateSegmentation?.segmentationId ===
|
|
193
|
+
segmentationData.segmentationId &&
|
|
194
|
+
candidateSegmentation?.segmentIndex ===
|
|
195
|
+
segmentationData.segmentIndex);
|
|
196
|
+
}),
|
|
197
|
+
});
|
|
118
198
|
}
|
|
199
|
+
LabelMapEditWithContourTool.cleanupTemporaryContourRepresentation(viewport, annotation);
|
|
200
|
+
LabelMapEditWithContourTool.annotationsToViewportMap.delete(annotationUID);
|
|
119
201
|
}
|
|
120
202
|
}
|
|
121
203
|
LabelMapEditWithContourTool.toolName = 'LabelMapEditWithContour';
|
|
122
204
|
LabelMapEditWithContourTool.annotationsToViewportMap = new Map();
|
|
123
|
-
LabelMapEditWithContourTool.
|
|
205
|
+
LabelMapEditWithContourTool.temporaryContourData = new Set();
|
|
206
|
+
LabelMapEditWithContourTool.temporaryContourViewports = new Set();
|
|
124
207
|
export default LabelMapEditWithContourTool;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Types } from '@cornerstonejs/core';
|
|
2
2
|
import { vec3 } from 'gl-matrix';
|
|
3
3
|
import type { PublicToolProps, ToolProps, EventTypes, SVGDrawingHelper, Annotation } from '../../types/index.js';
|
|
4
|
-
import type { RectangleROIStartEndThresholdAnnotation
|
|
4
|
+
import type { RectangleROIStartEndThresholdAnnotation } from '../../types/ToolSpecificAnnotationTypes.js';
|
|
5
5
|
import RectangleROITool from '../annotation/RectangleROITool.js';
|
|
6
6
|
declare class RectangleROIStartEndThresholdTool extends RectangleROITool {
|
|
7
7
|
static toolName: any;
|
|
@@ -18,45 +18,7 @@ declare class RectangleROIStartEndThresholdTool extends RectangleROITool {
|
|
|
18
18
|
constructor(toolProps?: PublicToolProps, defaultToolProps?: ToolProps);
|
|
19
19
|
private _isCoordinateTuple;
|
|
20
20
|
private _resolveViewPlaneCoordinate;
|
|
21
|
-
addNewAnnotation: (evt: EventTypes.InteractionEventType) =>
|
|
22
|
-
highlighted: boolean;
|
|
23
|
-
invalidated: boolean;
|
|
24
|
-
metadata: {
|
|
25
|
-
viewPlaneNormal: Types.Point3;
|
|
26
|
-
enabledElement: Types.IEnabledElement;
|
|
27
|
-
viewUp: Types.Point3;
|
|
28
|
-
FrameOfReferenceUID: string;
|
|
29
|
-
referencedImageId: any;
|
|
30
|
-
toolName: string;
|
|
31
|
-
volumeId: any;
|
|
32
|
-
spacingInNormal: number;
|
|
33
|
-
};
|
|
34
|
-
data: {
|
|
35
|
-
label: string;
|
|
36
|
-
startCoordinate: number;
|
|
37
|
-
endCoordinate: number;
|
|
38
|
-
cachedStats: {
|
|
39
|
-
pointsInVolume: any[];
|
|
40
|
-
projectionPoints: any[];
|
|
41
|
-
projectionPointsImageIds: any[];
|
|
42
|
-
statistics: ROICachedStats;
|
|
43
|
-
};
|
|
44
|
-
handles: {
|
|
45
|
-
textBox: {
|
|
46
|
-
hasMoved: boolean;
|
|
47
|
-
worldPosition: Types.Point3;
|
|
48
|
-
worldBoundingBox: {
|
|
49
|
-
topLeft: Types.Point3;
|
|
50
|
-
topRight: Types.Point3;
|
|
51
|
-
bottomLeft: Types.Point3;
|
|
52
|
-
bottomRight: Types.Point3;
|
|
53
|
-
};
|
|
54
|
-
};
|
|
55
|
-
points: Types.Point3[];
|
|
56
|
-
activeHandleIndex: any;
|
|
57
|
-
};
|
|
58
|
-
};
|
|
59
|
-
};
|
|
21
|
+
addNewAnnotation: (evt: EventTypes.InteractionEventType) => Annotation | null;
|
|
60
22
|
_endCallback: (evt: EventTypes.InteractionEventType) => void;
|
|
61
23
|
_computeProjectionPoints(annotation: RectangleROIStartEndThresholdAnnotation, imageVolume: Types.IImageVolume): void;
|
|
62
24
|
_computePointsInsideVolume(annotation: any, targetId: any, imageVolume: any, enabledElement: any): void;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getEnabledElement,
|
|
1
|
+
import { getEnabledElement, StackViewport, utilities as csUtils, } from '@cornerstonejs/core';
|
|
2
2
|
import { getCalibratedLengthUnitsAndScale } from '../../utilities/getCalibratedUnits.js';
|
|
3
3
|
import { vec3 } from 'gl-matrix';
|
|
4
4
|
import { addAnnotation, getAnnotations, removeAnnotation, } from '../../stateManagement/index.js';
|
|
@@ -40,19 +40,19 @@ class RectangleROIStartEndThresholdTool extends RectangleROITool {
|
|
|
40
40
|
const worldPos = currentPoints.world;
|
|
41
41
|
const enabledElement = getEnabledElement(element);
|
|
42
42
|
const { viewport, renderingEngine } = enabledElement;
|
|
43
|
-
this.isDrawing = true;
|
|
44
43
|
const camera = viewport.getCamera();
|
|
45
44
|
const { viewPlaneNormal, viewUp } = camera;
|
|
46
|
-
let referencedImageId, imageVolume, volumeId;
|
|
47
45
|
if (viewport instanceof StackViewport) {
|
|
48
46
|
throw new Error('Stack Viewport Not implemented');
|
|
49
47
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
imageVolume = cache.getVolume(volumeId);
|
|
54
|
-
referencedImageId = csUtils.getClosestImageId(imageVolume, worldPos, viewPlaneNormal);
|
|
48
|
+
const target = this.getTargetVolume(viewport);
|
|
49
|
+
if (!target) {
|
|
50
|
+
return null;
|
|
55
51
|
}
|
|
52
|
+
const volumeId = csUtils.getVolumeId(target.targetId);
|
|
53
|
+
const imageVolume = target.imageVolume;
|
|
54
|
+
const referencedImageId = csUtils.getClosestImageId(imageVolume, worldPos, viewPlaneNormal);
|
|
55
|
+
this.isDrawing = true;
|
|
56
56
|
const spacingInNormal = csUtils.getSpacingInNormalDirection(imageVolume, viewPlaneNormal);
|
|
57
57
|
const startCoord = this._getStartCoordinate(worldPos, viewPlaneNormal);
|
|
58
58
|
const endCoord = this._getEndCoordinate(worldPos, spacingInNormal, viewPlaneNormal);
|
|
@@ -137,10 +137,11 @@ class RectangleROIStartEndThresholdTool extends RectangleROITool {
|
|
|
137
137
|
this.configuration.preventHandleOutsideImage) {
|
|
138
138
|
removeAnnotation(annotation.annotationUID);
|
|
139
139
|
}
|
|
140
|
-
const
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
140
|
+
const target = this.getTargetVolume(enabledElement.viewport);
|
|
141
|
+
if (target) {
|
|
142
|
+
this._computeProjectionPoints(annotation, target.imageVolume);
|
|
143
|
+
this._computePointsInsideVolume(annotation, target.targetId, target.imageVolume, enabledElement);
|
|
144
|
+
}
|
|
144
145
|
triggerAnnotationRenderForViewportIds(viewportIdsToRender);
|
|
145
146
|
if (newAnnotation) {
|
|
146
147
|
triggerAnnotationCompleted(annotation);
|
|
@@ -195,12 +196,10 @@ class RectangleROIStartEndThresholdTool extends RectangleROITool {
|
|
|
195
196
|
roundedCoord > Math.max(roundedStartCoord, roundedEndCoord)) {
|
|
196
197
|
continue;
|
|
197
198
|
}
|
|
198
|
-
const
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
this._throttledCalculateCachedStats(annotation, annotationEnabledElement);
|
|
203
|
-
}
|
|
199
|
+
const annotationViewport = annotationEnabledElement?.viewport;
|
|
200
|
+
if (annotation.invalidated &&
|
|
201
|
+
annotationViewport?.hasVolumeId?.(metadata.volumeId)) {
|
|
202
|
+
this._throttledCalculateCachedStats(annotation, annotationEnabledElement);
|
|
204
203
|
}
|
|
205
204
|
let firstOrLastSlice = false;
|
|
206
205
|
if (roundedCoord === roundedStartCoord ||
|
|
@@ -323,14 +322,16 @@ class RectangleROIStartEndThresholdTool extends RectangleROITool {
|
|
|
323
322
|
const worldPos1 = data.handles.points[0];
|
|
324
323
|
const worldPos2 = data.handles.points[3];
|
|
325
324
|
const { worldWidth, worldHeight } = getWorldWidthAndHeightFromCorners(viewPlaneNormal, viewUp, worldPos1, worldPos2);
|
|
326
|
-
const
|
|
325
|
+
const indexCoordinates = data.handles.points.map((point) => image.imageData.worldToIndex(point));
|
|
326
|
+
const measureInfo = getCalibratedLengthUnitsAndScale(image, indexCoordinates);
|
|
327
327
|
const area = Math.abs(worldWidth * worldHeight) /
|
|
328
328
|
(measureInfo.scale * measureInfo.scale);
|
|
329
329
|
const modalityUnitOptions = {
|
|
330
330
|
isPreScaled: isViewportPreScaled(viewport, targetId),
|
|
331
331
|
isSuvScaled: this.isSuvScaled(viewport, targetId, annotation.metadata.referencedImageId),
|
|
332
332
|
};
|
|
333
|
-
const
|
|
333
|
+
const modality = imageVolume?.metadata?.Modality;
|
|
334
|
+
const modalityUnit = getPixelValueUnits(modality, annotation.metadata.referencedImageId, modalityUnitOptions);
|
|
334
335
|
for (let i = 0; i < projectionPoints.length; i++) {
|
|
335
336
|
if (!imageVolume) {
|
|
336
337
|
continue;
|
|
@@ -375,7 +376,7 @@ class RectangleROIStartEndThresholdTool extends RectangleROITool {
|
|
|
375
376
|
const stats = this.configuration.statsCalculator.getStatistics();
|
|
376
377
|
data.cachedStats.pointsInVolume = pointsInsideVolume;
|
|
377
378
|
data.cachedStats.statistics = {
|
|
378
|
-
Modality:
|
|
379
|
+
Modality: modality,
|
|
379
380
|
area,
|
|
380
381
|
mean: stats.mean?.value,
|
|
381
382
|
stdDev: stats.stdDev?.value,
|
|
@@ -389,8 +390,12 @@ class RectangleROIStartEndThresholdTool extends RectangleROITool {
|
|
|
389
390
|
const data = annotation.data;
|
|
390
391
|
const { viewport } = enabledElement;
|
|
391
392
|
const { cachedStats } = data;
|
|
392
|
-
const
|
|
393
|
-
|
|
393
|
+
const target = this.getTargetVolume(viewport);
|
|
394
|
+
if (!target) {
|
|
395
|
+
annotation.invalidated = false;
|
|
396
|
+
return cachedStats;
|
|
397
|
+
}
|
|
398
|
+
const { targetId, imageVolume } = target;
|
|
394
399
|
this._computeProjectionPoints(annotation, imageVolume);
|
|
395
400
|
this._computePointsInsideVolume(annotation, targetId, imageVolume, enabledElement);
|
|
396
401
|
annotation.invalidated = false;
|
package/dist/esm/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "5.10.
|
|
1
|
+
export declare const version = "5.10.8";
|
package/dist/esm/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '5.10.
|
|
1
|
+
export const version = '5.10.8';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cornerstonejs/tools",
|
|
3
|
-
"version": "5.10.
|
|
3
|
+
"version": "5.10.8",
|
|
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.8",
|
|
130
130
|
"canvas": "3.2.0"
|
|
131
131
|
},
|
|
132
132
|
"peerDependencies": {
|
|
133
|
-
"@cornerstonejs/core": "5.10.
|
|
133
|
+
"@cornerstonejs/core": "5.10.8",
|
|
134
134
|
"@kitware/vtk.js": "36.4.1",
|
|
135
135
|
"@types/d3-array": "3.2.1",
|
|
136
136
|
"@types/d3-interpolate": "3.0.4",
|