@cornerstonejs/tools 1.70.14 → 1.71.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 (65) hide show
  1. package/dist/cjs/index.d.ts +2 -2
  2. package/dist/cjs/index.js +3 -2
  3. package/dist/cjs/index.js.map +1 -1
  4. package/dist/cjs/synchronizers/synchronizers/createVOISynchronizer.js.map +1 -1
  5. package/dist/cjs/tools/OrientationMarkerTool.js +5 -1
  6. package/dist/cjs/tools/OrientationMarkerTool.js.map +1 -1
  7. package/dist/cjs/tools/SculptorTool/CircleSculptCursor.d.ts +20 -0
  8. package/dist/cjs/tools/SculptorTool/CircleSculptCursor.js +110 -0
  9. package/dist/cjs/tools/SculptorTool/CircleSculptCursor.js.map +1 -0
  10. package/dist/cjs/tools/SculptorTool.d.ts +41 -0
  11. package/dist/cjs/tools/SculptorTool.js +298 -0
  12. package/dist/cjs/tools/SculptorTool.js.map +1 -0
  13. package/dist/cjs/tools/distancePointToContour.d.ts +3 -0
  14. package/dist/cjs/tools/distancePointToContour.js +24 -0
  15. package/dist/cjs/tools/distancePointToContour.js.map +1 -0
  16. package/dist/cjs/tools/index.d.ts +2 -1
  17. package/dist/cjs/tools/index.js +3 -1
  18. package/dist/cjs/tools/index.js.map +1 -1
  19. package/dist/cjs/types/ISculptToolShape.d.ts +12 -0
  20. package/dist/cjs/types/ISculptToolShape.js +3 -0
  21. package/dist/cjs/types/ISculptToolShape.js.map +1 -0
  22. package/dist/cjs/types/index.d.ts +2 -1
  23. package/dist/esm/index.js +2 -2
  24. package/dist/esm/index.js.map +1 -1
  25. package/dist/esm/synchronizers/synchronizers/createVOISynchronizer.js.map +1 -1
  26. package/dist/esm/tools/OrientationMarkerTool.js +5 -1
  27. package/dist/esm/tools/OrientationMarkerTool.js.map +1 -1
  28. package/dist/esm/tools/SculptorTool/CircleSculptCursor.js +108 -0
  29. package/dist/esm/tools/SculptorTool/CircleSculptCursor.js.map +1 -0
  30. package/dist/esm/tools/SculptorTool.js +290 -0
  31. package/dist/esm/tools/SculptorTool.js.map +1 -0
  32. package/dist/esm/tools/distancePointToContour.js +19 -0
  33. package/dist/esm/tools/distancePointToContour.js.map +1 -0
  34. package/dist/esm/tools/index.js +2 -1
  35. package/dist/esm/tools/index.js.map +1 -1
  36. package/dist/esm/types/ISculptToolShape.js +2 -0
  37. package/dist/esm/types/ISculptToolShape.js.map +1 -0
  38. package/dist/types/index.d.ts +2 -2
  39. package/dist/types/index.d.ts.map +1 -1
  40. package/dist/types/synchronizers/synchronizers/createVOISynchronizer.d.ts.map +1 -1
  41. package/dist/types/tools/OrientationMarkerTool.d.ts.map +1 -1
  42. package/dist/types/tools/SculptorTool/CircleSculptCursor.d.ts +21 -0
  43. package/dist/types/tools/SculptorTool/CircleSculptCursor.d.ts.map +1 -0
  44. package/dist/types/tools/SculptorTool.d.ts +42 -0
  45. package/dist/types/tools/SculptorTool.d.ts.map +1 -0
  46. package/dist/types/tools/distancePointToContour.d.ts +4 -0
  47. package/dist/types/tools/distancePointToContour.d.ts.map +1 -0
  48. package/dist/types/tools/index.d.ts +2 -1
  49. package/dist/types/tools/index.d.ts.map +1 -1
  50. package/dist/types/types/ISculptToolShape.d.ts +13 -0
  51. package/dist/types/types/ISculptToolShape.d.ts.map +1 -0
  52. package/dist/types/types/index.d.ts +2 -1
  53. package/dist/types/types/index.d.ts.map +1 -1
  54. package/dist/umd/index.js +1 -1
  55. package/dist/umd/index.js.map +1 -1
  56. package/package.json +3 -3
  57. package/src/index.ts +2 -0
  58. package/src/synchronizers/synchronizers/createVOISynchronizer.ts +5 -2
  59. package/src/tools/OrientationMarkerTool.ts +5 -1
  60. package/src/tools/SculptorTool/CircleSculptCursor.ts +212 -0
  61. package/src/tools/SculptorTool.ts +604 -0
  62. package/src/tools/distancePointToContour.ts +35 -0
  63. package/src/tools/index.ts +2 -0
  64. package/src/types/ISculptToolShape.ts +63 -0
  65. package/src/types/index.ts +2 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cornerstonejs/tools",
3
- "version": "1.70.14",
3
+ "version": "1.71.0",
4
4
  "description": "Cornerstone3D Tools",
5
5
  "main": "src/index.ts",
6
6
  "types": "dist/types/index.d.ts",
@@ -29,7 +29,7 @@
29
29
  "webpack:watch": "webpack --mode development --progress --watch --config ./.webpack/webpack.dev.js"
30
30
  },
31
31
  "dependencies": {
32
- "@cornerstonejs/core": "^1.70.14",
32
+ "@cornerstonejs/core": "^1.71.0",
33
33
  "@icr/polyseg-wasm": "0.4.0",
34
34
  "@types/offscreencanvas": "2019.7.3",
35
35
  "comlink": "^4.4.1",
@@ -59,5 +59,5 @@
59
59
  "type": "individual",
60
60
  "url": "https://ohif.org/donate"
61
61
  },
62
- "gitHead": "e511c3f4b11596cfedb30b071b42c9c68d71d018"
62
+ "gitHead": "03c01970a50a7383de86bb15c8d4f344a8ff7d25"
63
63
  }
package/src/index.ts CHANGED
@@ -71,6 +71,7 @@ import {
71
71
  OverlayGridTool,
72
72
  SegmentationIntersectionTool,
73
73
  EraserTool,
74
+ SculptorTool,
74
75
  SegmentSelectTool,
75
76
  } from './tools';
76
77
 
@@ -128,6 +129,7 @@ export {
128
129
  ReferenceCursors,
129
130
  ReferenceLines,
130
131
  ScaleOverlayTool,
132
+ SculptorTool,
131
133
  EraserTool,
132
134
  // Segmentation Display
133
135
  SegmentationDisplayTool,
@@ -5,7 +5,7 @@ import Synchronizer from '../../store/SynchronizerManager/Synchronizer';
5
5
 
6
6
  type VOISynchronizerOptions = {
7
7
  syncInvertState: boolean;
8
- syncColormap :boolean;
8
+ syncColormap: boolean;
9
9
  };
10
10
 
11
11
  /**
@@ -24,7 +24,10 @@ export default function createVOISynchronizer(
24
24
  options: VOISynchronizerOptions
25
25
  ): Synchronizer {
26
26
  // = { syncInvertState: true } if options is not provided or undefined or {}
27
- options = Object.assign({ syncInvertState: true, syncColormap:true }, options);
27
+ options = Object.assign(
28
+ { syncInvertState: true, syncColormap: true },
29
+ options
30
+ );
28
31
 
29
32
  const VOISynchronizer = createSynchronizer(
30
33
  synchronizerName,
@@ -170,10 +170,14 @@ class OrientationMarkerTool extends BaseTool {
170
170
  const resizeObserver = new ResizeObserver(() => {
171
171
  // Todo: i wish there was a better way to do this
172
172
  setTimeout(() => {
173
- const { viewport } = getEnabledElementByIds(
173
+ const element = getEnabledElementByIds(
174
174
  viewportId,
175
175
  renderingEngineId
176
176
  );
177
+ if (!element) {
178
+ return;
179
+ }
180
+ const { viewport } = element;
177
181
  this.resize(viewportId);
178
182
  viewport.render();
179
183
  }, 100);
@@ -0,0 +1,212 @@
1
+ import type { Types } from '@cornerstonejs/core';
2
+ import { getEnabledElement } from '@cornerstonejs/core';
3
+ import { ISculptToolShape } from '../../types/ISculptToolShape';
4
+ import { SculptData } from '../SculptorTool';
5
+ import { distancePointToContour } from '../distancePointToContour';
6
+ import { drawCircle as drawCircleSvg } from '../../drawingSvg';
7
+ import { point } from '../../utilities/math';
8
+ import {
9
+ SVGDrawingHelper,
10
+ EventTypes,
11
+ ContourAnnotationData,
12
+ } from '../../types';
13
+
14
+ export type PushedHandles = {
15
+ first?: number;
16
+ last?: number;
17
+ };
18
+
19
+ /**
20
+ * Implements a dynamic radius circle sculpt tool to edit contour annotations.
21
+ * This tool changes radius based on the nearest point on a contour tool.
22
+ *
23
+ * TODO: Update this tool to allow modifying spline and other handle containing
24
+ * contours.
25
+ */
26
+ class CircleSculptCursor implements ISculptToolShape {
27
+ static shapeName = 'Circle';
28
+
29
+ private toolInfo = {
30
+ toolSize: null,
31
+ maxToolSize: null,
32
+ };
33
+
34
+ /**
35
+ * Renders a circle at the current sculpt tool location
36
+ */
37
+ renderShape(
38
+ svgDrawingHelper: SVGDrawingHelper,
39
+ canvasLocation: Types.Point2,
40
+ options: any
41
+ ): void {
42
+ const circleUID = '0';
43
+ drawCircleSvg(
44
+ svgDrawingHelper,
45
+ 'SculptorTool',
46
+ circleUID,
47
+ canvasLocation,
48
+ this.toolInfo.toolSize,
49
+ options
50
+ );
51
+ }
52
+
53
+ /**
54
+ * Pushes the points radially away from the mouse if they are
55
+ * contained within the shape defined by the freehandSculpter tool
56
+ */
57
+ pushHandles(
58
+ viewport: Types.IViewport,
59
+ sculptData: SculptData
60
+ ): PushedHandles {
61
+ const { points, mouseCanvasPoint } = sculptData;
62
+ const pushedHandles: PushedHandles = { first: undefined, last: undefined };
63
+
64
+ for (let i = 0; i < points.length; i++) {
65
+ const handleCanvasPoint = viewport.worldToCanvas(points[i]);
66
+ const distanceToHandle = point.distanceToPoint(
67
+ handleCanvasPoint,
68
+ mouseCanvasPoint
69
+ );
70
+
71
+ if (distanceToHandle > this.toolInfo.toolSize) {
72
+ continue;
73
+ }
74
+
75
+ // Push point if inside circle, to edge of circle.
76
+ this.pushOneHandle(i, distanceToHandle, sculptData);
77
+ if (pushedHandles.first === undefined) {
78
+ pushedHandles.first = i;
79
+ pushedHandles.last = i;
80
+ } else {
81
+ pushedHandles.last = i;
82
+ }
83
+ }
84
+
85
+ return pushedHandles;
86
+ }
87
+
88
+ /**
89
+ * Sets up the basic tool size from the element, where the tool size
90
+ * is set at minimum to 1/12 of the minimum of the width and height.
91
+ */
92
+ configureToolSize(evt: EventTypes.InteractionEventType): void {
93
+ const toolInfo = this.toolInfo;
94
+
95
+ if (toolInfo.toolSize && toolInfo.maxToolSize) {
96
+ return;
97
+ }
98
+
99
+ const eventData = evt.detail;
100
+ const element = eventData.element;
101
+ const minDim = Math.min(element.clientWidth, element.clientHeight);
102
+ const maxRadius = minDim / 12;
103
+
104
+ toolInfo.toolSize = maxRadius;
105
+ toolInfo.maxToolSize = maxRadius;
106
+ }
107
+
108
+ /**
109
+ * Adjusts the tool size based on computing the nearest point to the active
110
+ * annotation object, and using the distance to the cursor point, clipping that
111
+ * to at most the configured radius.
112
+ */
113
+ updateToolSize(
114
+ canvasCoords: Types.Point2,
115
+ viewport: Types.IViewport,
116
+ activeAnnotation: ContourAnnotationData
117
+ ): void {
118
+ const toolInfo = this.toolInfo;
119
+ const radius = distancePointToContour(
120
+ viewport,
121
+ activeAnnotation,
122
+ canvasCoords
123
+ );
124
+ if (radius > 0) {
125
+ toolInfo.toolSize = Math.min(toolInfo.maxToolSize, radius);
126
+ }
127
+ }
128
+
129
+ /**
130
+ * Returns the maximum spacing between handles for this tool adjustment.
131
+ */
132
+ getMaxSpacing(minSpacing: number): number {
133
+ return Math.max(this.toolInfo.toolSize / 4, minSpacing);
134
+ }
135
+
136
+ /**
137
+ * Returns the index position of data to start inserting new tool information
138
+ * into the freeform.
139
+ */
140
+ getInsertPosition(
141
+ previousIndex: number,
142
+ nextIndex: number,
143
+ sculptData: SculptData
144
+ ): Types.Point3 {
145
+ let insertPosition: Types.Point2;
146
+ const { points, element, mouseCanvasPoint } = sculptData;
147
+ const toolSize = this.toolInfo.toolSize;
148
+ const enabledElement = getEnabledElement(element);
149
+ const { viewport } = enabledElement;
150
+ const previousCanvasPoint = viewport.worldToCanvas(points[previousIndex]);
151
+ const nextCanvasPoint = viewport.worldToCanvas(points[nextIndex]);
152
+
153
+ const midPoint: Types.Point2 = [
154
+ (previousCanvasPoint[0] + nextCanvasPoint[0]) / 2.0,
155
+ (previousCanvasPoint[1] + nextCanvasPoint[1]) / 2.0,
156
+ ];
157
+
158
+ const distanceToMidPoint = point.distanceToPoint(
159
+ mouseCanvasPoint,
160
+ midPoint
161
+ );
162
+
163
+ if (distanceToMidPoint < toolSize) {
164
+ const directionUnitVector = {
165
+ x: (midPoint[0] - mouseCanvasPoint[0]) / distanceToMidPoint,
166
+ y: (midPoint[1] - mouseCanvasPoint[1]) / distanceToMidPoint,
167
+ };
168
+
169
+ insertPosition = [
170
+ mouseCanvasPoint[0] + toolSize * directionUnitVector.x,
171
+ mouseCanvasPoint[1] + toolSize * directionUnitVector.y,
172
+ ];
173
+ } else {
174
+ insertPosition = midPoint;
175
+ }
176
+
177
+ const worldPosition = viewport.canvasToWorld(insertPosition);
178
+
179
+ return worldPosition;
180
+ }
181
+
182
+ /**
183
+ * Adds a new point into the sculpt data.
184
+ */
185
+ private pushOneHandle(
186
+ i: number,
187
+ distanceToHandle: number,
188
+ sculptData: SculptData
189
+ ): void {
190
+ const { points, mousePoint } = sculptData;
191
+ const toolSize = this.toolInfo.toolSize;
192
+ const handle = points[i];
193
+
194
+ const directionUnitVector = {
195
+ x: (handle[0] - mousePoint[0]) / distanceToHandle,
196
+ y: (handle[1] - mousePoint[1]) / distanceToHandle,
197
+ z: (handle[2] - mousePoint[2]) / distanceToHandle,
198
+ };
199
+
200
+ const position = {
201
+ x: mousePoint[0] + toolSize * directionUnitVector.x,
202
+ y: mousePoint[1] + toolSize * directionUnitVector.y,
203
+ z: mousePoint[2] + toolSize * directionUnitVector.z,
204
+ };
205
+
206
+ handle[0] = position.x;
207
+ handle[1] = position.y;
208
+ handle[2] = position.z;
209
+ }
210
+ }
211
+
212
+ export default CircleSculptCursor;