@cornerstonejs/tools 1.63.1 → 1.63.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cornerstonejs/tools",
3
- "version": "1.63.1",
3
+ "version": "1.63.2",
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.63.1",
32
+ "@cornerstonejs/core": "^1.63.2",
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": "e4fcacba07b254d69218c70e5e549a696115f008"
62
+ "gitHead": "315d09daf27cd6dd46d33b62a59b6cf2050116c9"
63
63
  }
@@ -1,4 +1,4 @@
1
- import { getEnabledElement } from '@cornerstonejs/core';
1
+ import { getEnabledElement, utilities } from '@cornerstonejs/core';
2
2
  import {
3
3
  resetElementCursor,
4
4
  hideElementCursor,
@@ -190,9 +190,9 @@ function mouseUpDrawCallback(evt: EventTypes.InteractionEventType): void {
190
190
  this.configuration.closeContourProximity
191
191
  )
192
192
  ) {
193
- this.completeDrawOpenContour(element, contourHoleProcessingEnabled);
193
+ this.completeDrawOpenContour(element, { contourHoleProcessingEnabled });
194
194
  } else {
195
- this.completeDrawClosedContour(element, contourHoleProcessingEnabled);
195
+ this.completeDrawClosedContour(element, { contourHoleProcessingEnabled });
196
196
  }
197
197
  }
198
198
 
@@ -201,10 +201,19 @@ function mouseUpDrawCallback(evt: EventTypes.InteractionEventType): void {
201
201
  */
202
202
  function completeDrawClosedContour(
203
203
  element: HTMLDivElement,
204
- contourHoleProcessingEnabled: boolean
204
+ options: {
205
+ contourHoleProcessingEnabled: boolean;
206
+ minPointsToSave: number;
207
+ }
205
208
  ): boolean {
206
209
  this.removeCrossedLinesOnCompleteDraw();
210
+
207
211
  const { canvasPoints } = this.drawData;
212
+ const { contourHoleProcessingEnabled, minPointsToSave } = options ?? {};
213
+
214
+ if (minPointsToSave && canvasPoints.length < minPointsToSave) {
215
+ return false;
216
+ }
208
217
 
209
218
  // check and halt if necessary the drawing process, last chance to complete drawing and fire events.
210
219
  if (this.haltDrawing(element, canvasPoints)) {
@@ -280,7 +289,13 @@ function removeCrossedLinesOnCompleteDraw(): void {
280
289
  if (lineSegment) {
281
290
  const indexToRemoveUpTo = lineSegment[1];
282
291
 
283
- this.drawData.canvasPoints = canvasPoints.splice(0, indexToRemoveUpTo);
292
+ // It is better to remove the last point when the user just moved the mouse
293
+ // cursor back than deleting the entire contour
294
+ if (indexToRemoveUpTo === 1) {
295
+ this.drawData.canvasPoints = canvasPoints.splice(1);
296
+ } else {
297
+ this.drawData.canvasPoints = canvasPoints.splice(0, indexToRemoveUpTo);
298
+ }
284
299
  }
285
300
  }
286
301
 
@@ -289,9 +304,12 @@ function removeCrossedLinesOnCompleteDraw(): void {
289
304
  */
290
305
  function completeDrawOpenContour(
291
306
  element: HTMLDivElement,
292
- contourHoleProcessingEnabled: boolean
307
+ options: {
308
+ contourHoleProcessingEnabled: boolean;
309
+ }
293
310
  ): boolean {
294
311
  const { canvasPoints } = this.drawData;
312
+ const { contourHoleProcessingEnabled } = options ?? {};
295
313
 
296
314
  // check and halt if necessary the drawing process, last chance to complete drawing and fire events.
297
315
  if (this.haltDrawing(element, canvasPoints)) {
@@ -392,7 +410,7 @@ function applyCreateOnCross(
392
410
  ): void {
393
411
  const eventDetail = evt.detail;
394
412
  const { element } = eventDetail;
395
- const { canvasPoints } = this.drawData;
413
+ const { canvasPoints, contourHoleProcessingEnabled } = this.drawData;
396
414
  const { annotation, viewportIdsToRender } = this.commonData;
397
415
 
398
416
  // Add points between the end point and crossing point
@@ -405,12 +423,24 @@ function applyCreateOnCross(
405
423
  // Remove last point which will be a duplicate now.
406
424
  canvasPoints.pop();
407
425
 
408
- // Remove points up to just before the crossing index
409
- for (let i = 0; i < crossingIndex; i++) {
410
- canvasPoints.shift();
426
+ const remainingPoints = canvasPoints.slice(crossingIndex);
427
+ const newArea = polyline.getArea(remainingPoints);
428
+
429
+ // User just moved the mouse back and the last points must be removed
430
+ // otherwise the entire contour drawn would be lost.
431
+ if (utilities.isEqual(newArea, 0)) {
432
+ canvasPoints.splice(crossingIndex + 1);
433
+ return;
411
434
  }
412
435
 
413
- if (this.completeDrawClosedContour(element)) {
436
+ canvasPoints.splice(0, crossingIndex);
437
+
438
+ // There is no contour with less than 3 points.
439
+ // It's possible to have a contour with very few points after removing
440
+ // crossed lines which is not enough to save as a contour.
441
+ const options = { contourHoleProcessingEnabled, minPointsToSave: 3 };
442
+
443
+ if (this.completeDrawClosedContour(element, options)) {
414
444
  // pos complete operation
415
445
  this.activateClosedContourEdit(evt, annotation, viewportIdsToRender);
416
446
  }
@@ -433,9 +463,9 @@ function cancelDrawing(element: HTMLElement) {
433
463
  this.configuration.closeContourProximity
434
464
  )
435
465
  ) {
436
- this.completeDrawOpenContour(element, contourHoleProcessingEnabled);
466
+ this.completeDrawOpenContour(element, { contourHoleProcessingEnabled });
437
467
  } else {
438
- this.completeDrawClosedContour(element, contourHoleProcessingEnabled);
468
+ this.completeDrawClosedContour(element, { contourHoleProcessingEnabled });
439
469
  }
440
470
  }
441
471
 
@@ -16,11 +16,16 @@ const addCanvasPointsToArray = (
16
16
  const enabledElement = getEnabledElement(element);
17
17
  const { viewport } = enabledElement;
18
18
 
19
+ if (!canvasPoints.length) {
20
+ canvasPoints.push(newCanvasPoint);
21
+ console.log('>>>>> !canvasPoints. :: RETURN');
22
+ return 1;
23
+ }
24
+
19
25
  const lastWorldPos = viewport.canvasToWorld(
20
26
  canvasPoints[canvasPoints.length - 1]
21
27
  );
22
28
  const newWorldPos = viewport.canvasToWorld(newCanvasPoint);
23
-
24
29
  const worldPosDiff = vec3.create();
25
30
 
26
31
  vec3.subtract(worldPosDiff, newWorldPos, lastWorldPos);
@@ -13,6 +13,10 @@ import type { Types } from '@cornerstonejs/core';
13
13
  * @returns Area of the polyline (with signal)
14
14
  */
15
15
  export default function getSignedArea(polyline: Types.Point2[]): number {
16
+ if (polyline.length < 3) {
17
+ return 0;
18
+ }
19
+
16
20
  // Reference point can be any point on the same plane
17
21
  const refPoint = polyline[0];
18
22
  let area = 0;