@cornerstonejs/tools 1.49.2 → 1.50.0

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.
Files changed (68) hide show
  1. package/dist/cjs/tools/annotation/LivewireContourTool.d.ts +5 -0
  2. package/dist/cjs/tools/annotation/LivewireContourTool.js +133 -44
  3. package/dist/cjs/tools/annotation/LivewireContourTool.js.map +1 -1
  4. package/dist/cjs/types/ToolSpecificAnnotationTypes.d.ts +1 -1
  5. package/dist/cjs/utilities/contours/findHandlePolylineIndex.d.ts +2 -0
  6. package/dist/cjs/utilities/contours/findHandlePolylineIndex.js +35 -0
  7. package/dist/cjs/utilities/contours/findHandlePolylineIndex.js.map +1 -0
  8. package/dist/cjs/utilities/contours/index.d.ts +2 -1
  9. package/dist/cjs/utilities/contours/index.js +3 -1
  10. package/dist/cjs/utilities/contours/index.js.map +1 -1
  11. package/dist/cjs/utilities/contours/interpolation/interpolate.js +1 -1
  12. package/dist/cjs/utilities/contours/interpolation/interpolate.js.map +1 -1
  13. package/dist/cjs/utilities/contours/reverseIfAntiClockwise.d.ts +1 -1
  14. package/dist/cjs/utilities/contours/reverseIfAntiClockwise.js +5 -5
  15. package/dist/cjs/utilities/contours/reverseIfAntiClockwise.js.map +1 -1
  16. package/dist/cjs/utilities/livewire/LiveWirePath.d.ts +3 -0
  17. package/dist/cjs/utilities/livewire/LiveWirePath.js +12 -0
  18. package/dist/cjs/utilities/livewire/LiveWirePath.js.map +1 -1
  19. package/dist/cjs/utilities/livewire/LivewireScissors.d.ts +2 -1
  20. package/dist/cjs/utilities/livewire/LivewireScissors.js +26 -7
  21. package/dist/cjs/utilities/livewire/LivewireScissors.js.map +1 -1
  22. package/dist/cjs/utilities/segmentation/InterpolationManager/InterpolationManager.js +1 -0
  23. package/dist/cjs/utilities/segmentation/InterpolationManager/InterpolationManager.js.map +1 -1
  24. package/dist/esm/tools/annotation/LivewireContourTool.js +131 -44
  25. package/dist/esm/tools/annotation/LivewireContourTool.js.map +1 -1
  26. package/dist/esm/utilities/contours/findHandlePolylineIndex.js +32 -0
  27. package/dist/esm/utilities/contours/findHandlePolylineIndex.js.map +1 -0
  28. package/dist/esm/utilities/contours/index.js +2 -1
  29. package/dist/esm/utilities/contours/index.js.map +1 -1
  30. package/dist/esm/utilities/contours/interpolation/interpolate.js +1 -1
  31. package/dist/esm/utilities/contours/interpolation/interpolate.js.map +1 -1
  32. package/dist/esm/utilities/contours/reverseIfAntiClockwise.js +5 -5
  33. package/dist/esm/utilities/contours/reverseIfAntiClockwise.js.map +1 -1
  34. package/dist/esm/utilities/livewire/LiveWirePath.js +12 -0
  35. package/dist/esm/utilities/livewire/LiveWirePath.js.map +1 -1
  36. package/dist/esm/utilities/livewire/LivewireScissors.js +26 -7
  37. package/dist/esm/utilities/livewire/LivewireScissors.js.map +1 -1
  38. package/dist/esm/utilities/segmentation/InterpolationManager/InterpolationManager.js +1 -0
  39. package/dist/esm/utilities/segmentation/InterpolationManager/InterpolationManager.js.map +1 -1
  40. package/dist/types/tools/annotation/LivewireContourTool.d.ts +5 -0
  41. package/dist/types/tools/annotation/LivewireContourTool.d.ts.map +1 -1
  42. package/dist/types/types/ToolSpecificAnnotationTypes.d.ts +1 -1
  43. package/dist/types/types/ToolSpecificAnnotationTypes.d.ts.map +1 -1
  44. package/dist/types/utilities/contours/findHandlePolylineIndex.d.ts +3 -0
  45. package/dist/types/utilities/contours/findHandlePolylineIndex.d.ts.map +1 -0
  46. package/dist/types/utilities/contours/index.d.ts +2 -1
  47. package/dist/types/utilities/contours/index.d.ts.map +1 -1
  48. package/dist/types/utilities/contours/interpolation/interpolate.d.ts.map +1 -1
  49. package/dist/types/utilities/contours/reverseIfAntiClockwise.d.ts +1 -1
  50. package/dist/types/utilities/contours/reverseIfAntiClockwise.d.ts.map +1 -1
  51. package/dist/types/utilities/livewire/LiveWirePath.d.ts +3 -0
  52. package/dist/types/utilities/livewire/LiveWirePath.d.ts.map +1 -1
  53. package/dist/types/utilities/livewire/LivewireScissors.d.ts +2 -1
  54. package/dist/types/utilities/livewire/LivewireScissors.d.ts.map +1 -1
  55. package/dist/types/utilities/segmentation/InterpolationManager/InterpolationManager.d.ts.map +1 -1
  56. package/dist/umd/index.js +1 -1
  57. package/dist/umd/index.js.map +1 -1
  58. package/package.json +3 -3
  59. package/src/tools/annotation/EllipticalROITool.ts +1 -1
  60. package/src/tools/annotation/LivewireContourTool.ts +220 -71
  61. package/src/types/ToolSpecificAnnotationTypes.ts +2 -0
  62. package/src/utilities/contours/findHandlePolylineIndex.ts +52 -0
  63. package/src/utilities/contours/index.ts +2 -0
  64. package/src/utilities/contours/interpolation/interpolate.ts +3 -2
  65. package/src/utilities/contours/reverseIfAntiClockwise.ts +11 -13
  66. package/src/utilities/livewire/LiveWirePath.ts +24 -0
  67. package/src/utilities/livewire/LivewireScissors.ts +52 -8
  68. package/src/utilities/segmentation/InterpolationManager/InterpolationManager.ts +1 -0
@@ -1,6 +1,8 @@
1
- import type { Types } from '@cornerstonejs/core';
1
+ import { Types, utilities } from '@cornerstonejs/core';
2
+
2
3
  import { BucketQueue } from '../BucketQueue';
3
4
 
5
+ const { isEqual } = utilities;
4
6
  const MAX_UINT32 = 4294967295;
5
7
  const TWO_THIRD_PI = 2 / (3 * Math.PI);
6
8
 
@@ -102,6 +104,48 @@ export class LivewireScissors {
102
104
  this.priorityQueueNew.push(startPointIndex);
103
105
  }
104
106
 
107
+ /**
108
+ * Returns a smoothing path count for how many items to remove.
109
+ * This will remove points, up to count which have a high gradient, up to
110
+ * count of them where the clip value is larger than that provided.
111
+ *
112
+ * @returns Count of items to remove from the path.
113
+ */
114
+ public smoothPathCount(
115
+ pathPoints: Types.Point2[],
116
+ lastPoint: Types.Point2,
117
+ count = 5,
118
+ clipValue = 0.85
119
+ ) {
120
+ const lastIndex =
121
+ (lastPoint &&
122
+ pathPoints.findIndex((point) => isEqual(point, lastPoint))) ||
123
+ -1;
124
+ if (pathPoints.length - lastIndex < count * 2) {
125
+ // If a nearby point is clicked, just add it anyways, because that means
126
+ // the user actually wants the given point
127
+ return 0;
128
+ }
129
+ let removeCount = 0;
130
+ for (
131
+ let i = pathPoints.length - 1;
132
+ i > pathPoints.length - count && i > 0;
133
+ i--
134
+ ) {
135
+ const weighted = this._getWeightedDistance(
136
+ pathPoints[i],
137
+ pathPoints[i - 1]
138
+ );
139
+ if (weighted < clipValue) {
140
+ return removeCount ? removeCount + 2 : 0;
141
+ }
142
+ removeCount++;
143
+ }
144
+ // Tried all of them, they were all too big, so assume they are really moving
145
+ // along a high gradient.
146
+ return 0;
147
+ }
148
+
105
149
  /**
106
150
  * Runs Dijsktra until it finds a path from the start point to the target
107
151
  * point. Once it reaches the target point all the state is preserved in order
@@ -156,20 +200,20 @@ export class LivewireScissors {
156
200
  // Update the cost of all neighbors that have higher costs
157
201
  for (let i = 0, len = neighborsPoints.length; i < len; i++) {
158
202
  const neighborPoint = neighborsPoints[i];
159
- const neighbordPointIndex = index(neighborPoint[1], neighborPoint[0]);
203
+ const neighborPointIndex = index(neighborPoint[1], neighborPoint[0]);
160
204
  const dist = this._getWeightedDistance(point, neighborPoint);
161
205
  const neighborCost = cost[pointIndex] + dist;
162
206
 
163
- if (neighborCost < cost[neighbordPointIndex]) {
164
- if (cost[neighbordPointIndex] !== Infinity) {
207
+ if (neighborCost < cost[neighborPointIndex]) {
208
+ if (cost[neighborPointIndex] !== Infinity) {
165
209
  // The item needs to be removed from the priority queue and
166
210
  // re-added in order to be moved to the right bucket.
167
- priorityQueue.remove(neighbordPointIndex);
211
+ priorityQueue.remove(neighborPointIndex);
168
212
  }
169
213
 
170
- cost[neighbordPointIndex] = neighborCost;
171
- parents[neighbordPointIndex] = pointIndex;
172
- priorityQueue.push(neighbordPointIndex);
214
+ cost[neighborPointIndex] = neighborCost;
215
+ parents[neighborPointIndex] = pointIndex;
216
+ priorityQueue.push(neighborPointIndex);
173
217
  }
174
218
  }
175
219
  }
@@ -154,6 +154,7 @@ export default class InterpolationManager {
154
154
  );
155
155
  return;
156
156
  }
157
+ annotation.autoGenerated = false;
157
158
 
158
159
  const sliceData: Types.ImageSliceData = getSliceData(viewport);
159
160
  const viewportData: InterpolationViewportData = {