@cornerstonejs/tools 5.6.7 → 5.6.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.
@@ -1,4 +1,4 @@
1
- import type { Types } from '@cornerstonejs/core';
1
+ import { type Types } from '@cornerstonejs/core';
2
2
  import type { ContourSegmentationAnnotation } from '../../types/index.js';
3
3
  export declare function addContourStroke(viewport: Types.IViewport, sourceAnnotation: ContourSegmentationAnnotation): void;
4
4
  export declare function removeContourStroke(viewport: Types.IViewport, sourceAnnotation: ContourSegmentationAnnotation): void;
@@ -1,8 +1,9 @@
1
+ import { utilities as csUtils } from '@cornerstonejs/core';
1
2
  import { ContourWindingDirection } from '../../types/ContourAnnotation.js';
2
3
  import { applyBoolean, BooleanOp, splitSelfIntersections, } from './clipperBooleanOps.js';
3
4
  import { unifyWeaklyConnectedPolygons } from './bridgeWeaklyConnected.js';
4
5
  import { convertContourPolylineToCanvasSpace, createNewAnnotationFromPolyline, getContourHolesData, updateViewportsForAnnotations, } from './sharedOperations.js';
5
- import { getAllAnnotations } from '../../stateManagement/annotation/annotationState.js';
6
+ import { getAllAnnotations, getAnnotation, } from '../../stateManagement/annotation/annotationState.js';
6
7
  import { addAnnotation, addChildAnnotation, removeAnnotation, } from '../../stateManagement/annotation/annotationState.js';
7
8
  import { addContourSegmentationAnnotation } from './addContourSegmentationAnnotation.js';
8
9
  import { removeContourSegmentationAnnotation } from './removeContourSegmentationAnnotation.js';
@@ -11,6 +12,7 @@ import areSameSegment from './areSameSegment.js';
11
12
  import isContourSegmentationAnnotation from './isContourSegmentationAnnotation.js';
12
13
  import { hasToolByName } from '../../store/addTool.js';
13
14
  const DEFAULT_CONTOUR_SEG_TOOL_NAME = 'PlanarFreehandContourSegmentationTool';
15
+ const { DefaultHistoryMemo } = csUtils.HistoryMemo;
14
16
  export function addContourStroke(viewport, sourceAnnotation) {
15
17
  applyStroke(viewport, sourceAnnotation, BooleanOp.Union);
16
18
  }
@@ -43,18 +45,20 @@ function applyStroke(viewport, sourceAnnotation, op) {
43
45
  const resultPolygons = op === BooleanOp.Union
44
46
  ? unifyWeaklyConnectedPolygons(booleanResult)
45
47
  : booleanResult;
46
- const toRemove = [sourceAnnotation];
48
+ const previousAnnotations = [];
47
49
  for (const t of targets) {
48
- toRemove.push(t);
50
+ previousAnnotations.push(t);
49
51
  for (const h of getContourHolesData(viewport, t)) {
50
- toRemove.push(h.annotation);
52
+ previousAnnotations.push(h.annotation);
51
53
  }
52
54
  }
55
+ const toRemove = [sourceAnnotation, ...previousAnnotations];
53
56
  for (const annotation of toRemove) {
54
57
  removeAnnotationCompletely(annotation);
55
58
  }
56
59
  const template = targets[0] ?? sourceAnnotation;
57
60
  const { element } = viewport;
61
+ const resultAnnotations = [];
58
62
  for (const polygon of resultPolygons) {
59
63
  if (polygon.outer.length < 3) {
60
64
  continue;
@@ -62,6 +66,7 @@ function applyStroke(viewport, sourceAnnotation, op) {
62
66
  const parent = createNewAnnotationFromPolyline(viewport, template, polygon.outer, ContourWindingDirection.Clockwise);
63
67
  addAnnotation(parent, element);
64
68
  addContourSegmentationAnnotation(parent);
69
+ resultAnnotations.push(parent);
65
70
  polygon.holes?.forEach((holePolyline) => {
66
71
  if (holePolyline.length < 3) {
67
72
  return;
@@ -69,12 +74,52 @@ function applyStroke(viewport, sourceAnnotation, op) {
69
74
  const hole = createNewAnnotationFromPolyline(viewport, template, holePolyline, ContourWindingDirection.CounterClockwise);
70
75
  addAnnotation(hole, element);
71
76
  addChildAnnotation(parent, hole);
77
+ resultAnnotations.push(hole);
72
78
  triggerAnnotationModified(hole, element);
73
79
  });
74
80
  triggerAnnotationModified(parent, element);
75
81
  }
82
+ replaceContourStrokeHistory(sourceAnnotation, previousAnnotations, resultAnnotations, viewport);
76
83
  updateViewportsForAnnotations(viewport, toRemove);
77
84
  }
85
+ function replaceContourStrokeHistory(sourceAnnotation, previousAnnotations, resultAnnotations, viewport) {
86
+ const memo = {
87
+ id: sourceAnnotation.annotationUID,
88
+ operationType: 'annotation',
89
+ restoreMemo: (isUndo = true) => {
90
+ const annotationsToRemove = isUndo
91
+ ? resultAnnotations
92
+ : previousAnnotations;
93
+ const annotationsToAdd = isUndo ? previousAnnotations : resultAnnotations;
94
+ removeStoredAnnotations(annotationsToRemove);
95
+ addStoredAnnotations(annotationsToAdd, viewport.element);
96
+ updateViewportsForAnnotations(viewport, [
97
+ ...annotationsToRemove,
98
+ ...annotationsToAdd,
99
+ ]);
100
+ },
101
+ };
102
+ DefaultHistoryMemo.replaceCurrentMemo(memo, (currentMemo) => currentMemo.id === sourceAnnotation.annotationUID &&
103
+ currentMemo.operationType === 'annotation');
104
+ }
105
+ function removeStoredAnnotations(annotations) {
106
+ for (let i = annotations.length - 1; i >= 0; i--) {
107
+ const annotation = annotations[i];
108
+ if (getAnnotation(annotation.annotationUID)) {
109
+ removeAnnotation(annotation.annotationUID);
110
+ }
111
+ removeContourSegmentationAnnotation(annotation);
112
+ }
113
+ }
114
+ function addStoredAnnotations(annotations, element) {
115
+ for (const annotation of annotations) {
116
+ if (getAnnotation(annotation.annotationUID)) {
117
+ continue;
118
+ }
119
+ addAnnotation(annotation, element);
120
+ addContourSegmentationAnnotation(annotation);
121
+ }
122
+ }
78
123
  function collectSamePlaneSegmentTargets(viewport, sourceAnnotation) {
79
124
  const sourceUID = sourceAnnotation.annotationUID;
80
125
  return getAllAnnotations().filter((candidate) => {
@@ -1 +1 @@
1
- export declare const version = "5.6.7";
1
+ export declare const version = "5.6.8";
@@ -1 +1 @@
1
- export const version = '5.6.7';
1
+ export const version = '5.6.8';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cornerstonejs/tools",
3
- "version": "5.6.7",
3
+ "version": "5.6.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.6.7",
129
+ "@cornerstonejs/core": "5.6.8",
130
130
  "canvas": "3.2.0"
131
131
  },
132
132
  "peerDependencies": {
133
- "@cornerstonejs/core": "5.6.7",
133
+ "@cornerstonejs/core": "5.6.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",
@@ -149,5 +149,5 @@
149
149
  "type": "individual",
150
150
  "url": "https://ohif.org/donate"
151
151
  },
152
- "gitHead": "bee51c33d95c44284da74cd5cb1444d7a5d45e25"
152
+ "gitHead": "fe3a8e991252b353447ac6383c0dc76b9e4f68a5"
153
153
  }