@cornerstonejs/tools 1.65.1 → 1.65.3

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 (41) hide show
  1. package/dist/cjs/enums/StrategyCallbacks.d.ts +2 -1
  2. package/dist/cjs/enums/StrategyCallbacks.js +1 -0
  3. package/dist/cjs/enums/StrategyCallbacks.js.map +1 -1
  4. package/dist/cjs/tools/annotation/PlanarFreehandROITool.js +1 -1
  5. package/dist/cjs/tools/annotation/PlanarFreehandROITool.js.map +1 -1
  6. package/dist/cjs/tools/segmentation/BrushTool.js +16 -4
  7. package/dist/cjs/tools/segmentation/BrushTool.js.map +1 -1
  8. package/dist/cjs/tools/segmentation/strategies/BrushStrategy.d.ts +3 -0
  9. package/dist/cjs/tools/segmentation/strategies/BrushStrategy.js +1 -0
  10. package/dist/cjs/tools/segmentation/strategies/BrushStrategy.js.map +1 -1
  11. package/dist/cjs/tools/segmentation/strategies/compositions/dynamicThreshold.d.ts +1 -0
  12. package/dist/cjs/tools/segmentation/strategies/compositions/dynamicThreshold.js +20 -0
  13. package/dist/cjs/tools/segmentation/strategies/compositions/dynamicThreshold.js.map +1 -1
  14. package/dist/cjs/tools/segmentation/strategies/compositions/index.d.ts +1 -0
  15. package/dist/esm/enums/StrategyCallbacks.js +1 -0
  16. package/dist/esm/enums/StrategyCallbacks.js.map +1 -1
  17. package/dist/esm/tools/annotation/PlanarFreehandROITool.js +1 -1
  18. package/dist/esm/tools/annotation/PlanarFreehandROITool.js.map +1 -1
  19. package/dist/esm/tools/segmentation/BrushTool.js +16 -4
  20. package/dist/esm/tools/segmentation/BrushTool.js.map +1 -1
  21. package/dist/esm/tools/segmentation/strategies/BrushStrategy.js +1 -0
  22. package/dist/esm/tools/segmentation/strategies/BrushStrategy.js.map +1 -1
  23. package/dist/esm/tools/segmentation/strategies/compositions/dynamicThreshold.js +20 -0
  24. package/dist/esm/tools/segmentation/strategies/compositions/dynamicThreshold.js.map +1 -1
  25. package/dist/types/enums/StrategyCallbacks.d.ts +2 -1
  26. package/dist/types/enums/StrategyCallbacks.d.ts.map +1 -1
  27. package/dist/types/tools/segmentation/BrushTool.d.ts.map +1 -1
  28. package/dist/types/tools/segmentation/strategies/BrushStrategy.d.ts +3 -0
  29. package/dist/types/tools/segmentation/strategies/BrushStrategy.d.ts.map +1 -1
  30. package/dist/types/tools/segmentation/strategies/compositions/dynamicThreshold.d.ts +1 -0
  31. package/dist/types/tools/segmentation/strategies/compositions/dynamicThreshold.d.ts.map +1 -1
  32. package/dist/types/tools/segmentation/strategies/compositions/index.d.ts +1 -0
  33. package/dist/types/tools/segmentation/strategies/compositions/index.d.ts.map +1 -1
  34. package/dist/umd/index.js +1 -1
  35. package/dist/umd/index.js.map +1 -1
  36. package/package.json +3 -3
  37. package/src/enums/StrategyCallbacks.ts +3 -0
  38. package/src/tools/annotation/PlanarFreehandROITool.ts +1 -1
  39. package/src/tools/segmentation/BrushTool.ts +21 -5
  40. package/src/tools/segmentation/strategies/BrushStrategy.ts +4 -0
  41. package/src/tools/segmentation/strategies/compositions/dynamicThreshold.ts +43 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cornerstonejs/tools",
3
- "version": "1.65.1",
3
+ "version": "1.65.3",
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.65.1",
32
+ "@cornerstonejs/core": "^1.65.3",
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": "b8cf31075c8069d9124c2d12e9360baf9bae267e"
62
+ "gitHead": "7059912b7d083525acdc48af7d0d38eec27efa64"
63
63
  }
@@ -47,6 +47,9 @@ enum StrategyCallbacks {
47
47
 
48
48
  // Internal Details
49
49
  INTERNAL_setValue = 'setValue',
50
+
51
+ /** inner circle size */
52
+ ComputeInnerCircleRadius = 'computeInnerCircleRadius',
50
53
  }
51
54
 
52
55
  export default StrategyCallbacks;
@@ -847,7 +847,7 @@ class PlanarFreehandROITool extends ContourSegmentationBaseTool {
847
847
 
848
848
  triggerAnnotationModified(
849
849
  annotation,
850
- enabledElement.element,
850
+ enabledElement.viewport.element,
851
851
  ChangeTypes.StatsUpdated
852
852
  );
853
853
 
@@ -108,6 +108,7 @@ class BrushTool extends BaseTool {
108
108
  strategySpecificConfiguration: {
109
109
  THRESHOLD: {
110
110
  threshold: [-150, -70], // E.g. CT Fat // Only used during threshold strategies.
111
+ dynamicRadius: 0, // in voxel counts in each direction, only used during dynamic threshold strategies.
111
112
  },
112
113
  },
113
114
  defaultStrategy: 'FILL_INSIDE_CIRCLE',
@@ -126,8 +127,6 @@ class BrushTool extends BaseTool {
126
127
  // The time to consider a mouse click a drag when moved less than dragMoveDistance
127
128
  dragTimeMs: 500,
128
129
  },
129
- // Whether to show a center circle/position. Set to null to not show
130
- centerRadius: 2,
131
130
  actions: {
132
131
  [StrategyCallbacks.AcceptPreview]: {
133
132
  method: StrategyCallbacks.AcceptPreview,
@@ -584,6 +583,18 @@ class BrushTool extends BaseTool {
584
583
  rightCursorInWorld,
585
584
  ];
586
585
 
586
+ const activeStrategy = this.configuration.activeStrategy;
587
+ const strategy = this.configuration.strategies[activeStrategy];
588
+
589
+ // Note: i don't think this is the best way to implement this
590
+ // but don't think we have a better way to do it for now
591
+ if (typeof strategy.computeInnerCircleRadius === 'function') {
592
+ strategy.computeInnerCircleRadius({
593
+ configuration: this.configuration,
594
+ viewport,
595
+ });
596
+ }
597
+
587
598
  data.invalidated = false;
588
599
  }
589
600
 
@@ -776,15 +787,20 @@ class BrushTool extends BaseTool {
776
787
  }
777
788
  );
778
789
 
779
- const { centerRadius } = this.configuration;
780
- if (centerRadius >= 0) {
790
+ const activeStrategy = this.configuration.activeStrategy;
791
+ const { dynamicRadiusInCanvas } = this.configuration
792
+ .strategySpecificConfiguration[activeStrategy] || {
793
+ dynamicRadiusInCanvas: 0,
794
+ };
795
+
796
+ if (dynamicRadiusInCanvas) {
781
797
  const circleUID1 = '1';
782
798
  drawCircleSvg(
783
799
  svgDrawingHelper,
784
800
  annotationUID,
785
801
  circleUID1,
786
802
  center as Types.Point2,
787
- 2,
803
+ dynamicRadiusInCanvas,
788
804
  {
789
805
  color,
790
806
  }
@@ -34,6 +34,7 @@ export type InitializedOperationData = LabelmapToolOperationDataAny & {
34
34
  previewSegmentIndex?: number;
35
35
 
36
36
  brushStrategy: BrushStrategy;
37
+ configuration?: Record<string, any>;
37
38
  };
38
39
 
39
40
  export type StrategyFunction = (
@@ -110,6 +111,9 @@ export default class BrushStrategy {
110
111
  StrategyCallbacks.Preview,
111
112
  false
112
113
  ),
114
+ [StrategyCallbacks.ComputeInnerCircleRadius]: addListMethod(
115
+ StrategyCallbacks.ComputeInnerCircleRadius
116
+ ),
113
117
  // Add other exposed fields below
114
118
  // initializers is exposed on the function to allow extension of the composition object
115
119
  compositions: null,
@@ -1,4 +1,5 @@
1
1
  import { vec3 } from 'gl-matrix';
2
+ import type { Types } from '@cornerstonejs/core';
2
3
  import type { InitializedOperationData } from '../BrushStrategy';
3
4
  import type BoundsIJK from '../../../../types/BoundsIJK';
4
5
  import StrategyCallbacks from '../../../../enums/StrategyCallbacks';
@@ -65,4 +66,46 @@ export default {
65
66
  }
66
67
  strategySpecificConfiguration.THRESHOLD.threshold = null;
67
68
  },
69
+ /**
70
+ * It computes the inner circle radius in canvas coordinates and stores it
71
+ * in the strategySpecificConfiguration. This is used to show the user
72
+ * the area that is used to compute the threshold.
73
+ */
74
+ [StrategyCallbacks.ComputeInnerCircleRadius]: (
75
+ operationData: InitializedOperationData
76
+ ) => {
77
+ const { configuration, viewport } = operationData;
78
+ const { THRESHOLD: { dynamicRadius = 0 } = {} } =
79
+ configuration.strategySpecificConfiguration || {};
80
+ const { spacing } = (
81
+ viewport as Types.IStackViewport | Types.IVolumeViewport
82
+ ).getImageData();
83
+ const centerCanvas = [
84
+ viewport.element.clientWidth / 2,
85
+ viewport.element.clientHeight / 2,
86
+ ] as Types.Point2;
87
+ const radiusInWorld = dynamicRadius * spacing[0];
88
+ const centerCursorInWorld = viewport.canvasToWorld(centerCanvas);
89
+
90
+ const offSetCenterInWorld = centerCursorInWorld.map(
91
+ (coord) => coord + radiusInWorld
92
+ ) as Types.Point3;
93
+
94
+ const offSetCenterCanvas = viewport.worldToCanvas(offSetCenterInWorld);
95
+ const dynamicRadiusInCanvas = Math.abs(
96
+ centerCanvas[0] - offSetCenterCanvas[0]
97
+ );
98
+
99
+ // this is a bit of a hack, since we have switched to using THRESHOLD
100
+ // as strategy but really strategy names are CIRCLE_THRESHOLD and SPHERE_THRESHOLD
101
+ // and we can't really change the name of the strategy in the configuration
102
+ const { strategySpecificConfiguration, activeStrategy } = configuration;
103
+
104
+ if (!strategySpecificConfiguration[activeStrategy]) {
105
+ strategySpecificConfiguration[activeStrategy] = {};
106
+ }
107
+
108
+ strategySpecificConfiguration[activeStrategy].dynamicRadiusInCanvas =
109
+ dynamicRadiusInCanvas;
110
+ },
68
111
  };