@cornerstonejs/tools 5.10.7 → 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.
@@ -17,7 +17,7 @@ export default function mouseDownActivate(evt) {
17
17
  if (activeTool.addNewAnnotation) {
18
18
  try {
19
19
  const annotation = activeTool.addNewAnnotation(evt, 'mouse');
20
- if (annotation) {
20
+ if (annotation?.annotationUID) {
21
21
  setAnnotationSelected(annotation.annotationUID);
22
22
  }
23
23
  }
@@ -17,7 +17,7 @@ export default function touchStartActivate(evt) {
17
17
  if (activeTool.addNewAnnotation) {
18
18
  try {
19
19
  const annotation = activeTool.addNewAnnotation(evt, 'touch');
20
- if (annotation) {
20
+ if (annotation?.annotationUID) {
21
21
  setAnnotationSelected(annotation.annotationUID);
22
22
  }
23
23
  }
@@ -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][0].active = true;
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 remainingRepresentations = this.getSegmentationRepresentations(viewportId);
244
- if (remainingRepresentations.length > 0 &&
245
- remainingRepresentations[0].active) {
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].locked;
24
+ return segments?.[segmentIndex]?.locked === true;
25
25
  }
26
26
  function setSegmentIndexLocked(segmentationId, segmentIndex, locked = true) {
27
27
  const segmentation = getSegmentation(segmentationId);
@@ -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: boolean;
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 viewAnnotations = filterAnnotationsForDisplay(viewport, annotations);
328
- if (!viewAnnotations?.length) {
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 contourAnnotations = viewAnnotations.filter((annotation) => annotation.data.contour?.polyline?.length);
332
- if (!contourAnnotations.length) {
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
- for (const annotation of contourAnnotations) {
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 = annotation.data.handles?.[0] || polyline[0];
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
- const segmentIndex = hasBoth
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
- removeAnnotation(annotation.annotationUID);
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 onViewportAddedToToolGroupBinded;
7
- private onSegmentationModifiedBinded;
8
- static viewportIdsChecked: any[];
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 onViewportAddedToToolGroup(evt: any): void;
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 { getSegmentationRepresentationsBySegmentationId } from '../../stateManagement/segmentation/getSegmentationRepresentation.js';
7
- import { utilities as cornerstoneUtilities } from '@cornerstonejs/core';
8
- const cs3dLogger = cornerstoneUtilities.logger.toolsLog.getLogger('tools.segmentation.LabelmapEditWithContour');
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.onViewportAddedToToolGroupBinded =
19
- this.onViewportAddedToToolGroup.bind(this);
20
- this.onSegmentationModifiedBinded = this.onSegmentationModified.bind(this);
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.viewportIdsChecked = [];
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
- else {
65
- LabelMapEditWithContourTool.viewportIdsChecked.push(viewportId);
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
- onViewportAddedToToolGroup(evt) {
70
- const { toolGroupId, viewportId } = evt.detail;
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
- if (!polyline) {
179
+ const annotationUID = annotation.annotationUID;
180
+ const viewport = LabelMapEditWithContourTool.annotationsToViewportMap.get(annotationUID);
181
+ if (!viewport) {
111
182
  return;
112
183
  }
113
- if (LabelMapEditWithContourTool.annotationsToViewportMap.has(annotation.annotationUID)) {
114
- const viewport = LabelMapEditWithContourTool.annotationsToViewportMap.get(annotation.annotationUID);
115
- if (polyline.length > 3) {
116
- BrushTool.viewportContoursToLabelmap(viewport);
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.viewportIdsChecked = [];
205
+ LabelMapEditWithContourTool.temporaryContourData = new Set();
206
+ LabelMapEditWithContourTool.temporaryContourViewports = new Set();
124
207
  export default LabelMapEditWithContourTool;
@@ -1 +1 @@
1
- export declare const version = "5.10.7";
1
+ export declare const version = "5.10.8";
@@ -1 +1 @@
1
- export const version = '5.10.7';
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.7",
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.7",
129
+ "@cornerstonejs/core": "5.10.8",
130
130
  "canvas": "3.2.0"
131
131
  },
132
132
  "peerDependencies": {
133
- "@cornerstonejs/core": "5.10.7",
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",