@cornerstonejs/tools 1.65.3 → 1.65.5

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 (88) hide show
  1. package/dist/cjs/stateManagement/annotation/annotationSelection.js +2 -1
  2. package/dist/cjs/stateManagement/annotation/annotationSelection.js.map +1 -1
  3. package/dist/cjs/tools/MIPJumpToClickTool.js +2 -1
  4. package/dist/cjs/tools/MIPJumpToClickTool.js.map +1 -1
  5. package/dist/cjs/tools/StackScrollToolMouseWheelTool.js +2 -1
  6. package/dist/cjs/tools/StackScrollToolMouseWheelTool.js.map +1 -1
  7. package/dist/cjs/tools/annotation/CircleROITool.js +4 -4
  8. package/dist/cjs/tools/annotation/CircleROITool.js.map +1 -1
  9. package/dist/cjs/tools/annotation/EllipticalROITool.js +5 -5
  10. package/dist/cjs/tools/annotation/EllipticalROITool.js.map +1 -1
  11. package/dist/cjs/tools/annotation/PlanarFreehandROITool.js +4 -4
  12. package/dist/cjs/tools/annotation/PlanarFreehandROITool.js.map +1 -1
  13. package/dist/cjs/tools/annotation/RectangleROITool.js +4 -4
  14. package/dist/cjs/tools/annotation/RectangleROITool.js.map +1 -1
  15. package/dist/cjs/tools/base/AnnotationDisplayTool.js +2 -1
  16. package/dist/cjs/tools/base/AnnotationDisplayTool.js.map +1 -1
  17. package/dist/cjs/tools/base/AnnotationTool.js +2 -1
  18. package/dist/cjs/tools/base/AnnotationTool.js.map +1 -1
  19. package/dist/cjs/tools/base/BaseTool.js +2 -1
  20. package/dist/cjs/tools/base/BaseTool.js.map +1 -1
  21. package/dist/cjs/types/CalculatorTypes.d.ts +29 -1
  22. package/dist/cjs/types/index.d.ts +2 -2
  23. package/dist/cjs/utilities/getVolumeId.d.ts +1 -0
  24. package/dist/cjs/utilities/getVolumeId.js +16 -0
  25. package/dist/cjs/utilities/getVolumeId.js.map +1 -0
  26. package/dist/cjs/utilities/math/basic/BasicStatsCalculator.d.ts +2 -2
  27. package/dist/cjs/utilities/math/basic/BasicStatsCalculator.js +34 -11
  28. package/dist/cjs/utilities/math/basic/BasicStatsCalculator.js.map +1 -1
  29. package/dist/cjs/utilities/math/basic/Calculator.d.ts +2 -2
  30. package/dist/cjs/utilities/math/basic/Calculator.js.map +1 -1
  31. package/dist/esm/stateManagement/annotation/annotationSelection.js +1 -1
  32. package/dist/esm/stateManagement/annotation/annotationSelection.js.map +1 -1
  33. package/dist/esm/tools/MIPJumpToClickTool.js +2 -1
  34. package/dist/esm/tools/MIPJumpToClickTool.js.map +1 -1
  35. package/dist/esm/tools/StackScrollToolMouseWheelTool.js +2 -1
  36. package/dist/esm/tools/StackScrollToolMouseWheelTool.js.map +1 -1
  37. package/dist/esm/tools/annotation/CircleROITool.js +4 -4
  38. package/dist/esm/tools/annotation/CircleROITool.js.map +1 -1
  39. package/dist/esm/tools/annotation/EllipticalROITool.js +5 -5
  40. package/dist/esm/tools/annotation/EllipticalROITool.js.map +1 -1
  41. package/dist/esm/tools/annotation/PlanarFreehandROITool.js +4 -4
  42. package/dist/esm/tools/annotation/PlanarFreehandROITool.js.map +1 -1
  43. package/dist/esm/tools/annotation/RectangleROITool.js +4 -4
  44. package/dist/esm/tools/annotation/RectangleROITool.js.map +1 -1
  45. package/dist/esm/tools/base/AnnotationDisplayTool.js +2 -1
  46. package/dist/esm/tools/base/AnnotationDisplayTool.js.map +1 -1
  47. package/dist/esm/tools/base/AnnotationTool.js +2 -1
  48. package/dist/esm/tools/base/AnnotationTool.js.map +1 -1
  49. package/dist/esm/tools/base/BaseTool.js +2 -1
  50. package/dist/esm/tools/base/BaseTool.js.map +1 -1
  51. package/dist/esm/utilities/getVolumeId.js +12 -0
  52. package/dist/esm/utilities/getVolumeId.js.map +1 -0
  53. package/dist/esm/utilities/math/basic/BasicStatsCalculator.js +34 -11
  54. package/dist/esm/utilities/math/basic/BasicStatsCalculator.js.map +1 -1
  55. package/dist/esm/utilities/math/basic/Calculator.js.map +1 -1
  56. package/dist/types/tools/MIPJumpToClickTool.d.ts.map +1 -1
  57. package/dist/types/tools/StackScrollToolMouseWheelTool.d.ts.map +1 -1
  58. package/dist/types/tools/base/AnnotationDisplayTool.d.ts.map +1 -1
  59. package/dist/types/tools/base/AnnotationTool.d.ts.map +1 -1
  60. package/dist/types/tools/base/BaseTool.d.ts.map +1 -1
  61. package/dist/types/types/CalculatorTypes.d.ts +29 -1
  62. package/dist/types/types/CalculatorTypes.d.ts.map +1 -1
  63. package/dist/types/types/index.d.ts +2 -2
  64. package/dist/types/types/index.d.ts.map +1 -1
  65. package/dist/types/utilities/getVolumeId.d.ts +2 -0
  66. package/dist/types/utilities/getVolumeId.d.ts.map +1 -0
  67. package/dist/types/utilities/math/basic/BasicStatsCalculator.d.ts +2 -2
  68. package/dist/types/utilities/math/basic/BasicStatsCalculator.d.ts.map +1 -1
  69. package/dist/types/utilities/math/basic/Calculator.d.ts +2 -2
  70. package/dist/types/utilities/math/basic/Calculator.d.ts.map +1 -1
  71. package/dist/umd/index.js +1 -1
  72. package/dist/umd/index.js.map +1 -1
  73. package/package.json +3 -3
  74. package/src/stateManagement/annotation/annotationSelection.ts +1 -1
  75. package/src/tools/MIPJumpToClickTool.ts +2 -1
  76. package/src/tools/StackScrollToolMouseWheelTool.ts +2 -1
  77. package/src/tools/annotation/CircleROITool.ts +4 -4
  78. package/src/tools/annotation/EllipticalROITool.ts +5 -5
  79. package/src/tools/annotation/PlanarFreehandROITool.ts +4 -4
  80. package/src/tools/annotation/RectangleROITool.ts +4 -4
  81. package/src/tools/base/AnnotationDisplayTool.ts +2 -1
  82. package/src/tools/base/AnnotationTool.ts +2 -1
  83. package/src/tools/base/BaseTool.ts +2 -1
  84. package/src/types/CalculatorTypes.ts +14 -1
  85. package/src/types/index.ts +4 -1
  86. package/src/utilities/getVolumeId.ts +13 -0
  87. package/src/utilities/math/basic/BasicStatsCalculator.ts +44 -14
  88. package/src/utilities/math/basic/Calculator.ts +5 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cornerstonejs/tools",
3
- "version": "1.65.3",
3
+ "version": "1.65.5",
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.3",
32
+ "@cornerstonejs/core": "^1.65.5",
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": "7059912b7d083525acdc48af7d0d38eec27efa64"
62
+ "gitHead": "bc54ae70cb2180d5ce42cc7eaa17633f0bb5f34a"
63
63
  }
@@ -94,7 +94,7 @@ function getAnnotationsSelected(): Array<string> {
94
94
  function getAnnotationsSelectedByToolName(toolName: string): Array<string> {
95
95
  return getAnnotationsSelected().filter((annotationUID) => {
96
96
  const annotation = getAnnotation(annotationUID);
97
- return annotation.metadata.toolName === toolName;
97
+ return annotation?.metadata?.toolName === toolName;
98
98
  });
99
99
  }
100
100
 
@@ -5,6 +5,7 @@ import { getPointInLineOfSightWithCriteria } from '../utilities/planar';
5
5
  import jumpToWorld from '../utilities/viewport/jumpToWorld';
6
6
  import { PublicToolProps, ToolProps } from '../types';
7
7
  import { getToolGroupForViewport } from '../store/ToolGroupManager';
8
+ import { getVolumeId } from '../utilities/getVolumeId';
8
9
 
9
10
  /**
10
11
  * On a Maximum Intensity Projection (MIP) viewport, MIPJumpToClickTool allows the
@@ -54,7 +55,7 @@ class MIPJumpToClickTool extends BaseTool {
54
55
  );
55
56
  }
56
57
 
57
- const volumeId = targetId.split(/volumeId:|\?/)[1];
58
+ const volumeId = getVolumeId(targetId);
58
59
 
59
60
  // 3. Criteria function to search for the point (maximum intensity)
60
61
  let maxIntensity = -Infinity;
@@ -2,6 +2,7 @@ import { getEnabledElement } from '@cornerstonejs/core';
2
2
  import { BaseTool } from './base';
3
3
  import { MouseWheelEventType } from '../types/EventTypes';
4
4
  import scroll from '../utilities/scroll';
5
+ import { getVolumeId } from '../utilities/getVolumeId';
5
6
 
6
7
  /**
7
8
  * The StackScrollMouseWheelTool is a tool that allows the user to scroll through a
@@ -35,7 +36,7 @@ class StackScrollMouseWheelTool extends BaseTool {
35
36
  const delta = direction * (invert ? -1 : 1);
36
37
 
37
38
  const targetId = this.getTargetId(viewport);
38
- const volumeId = targetId.split(/volumeId:|\?/)[1];
39
+ const volumeId = getVolumeId(targetId);
39
40
 
40
41
  scroll(viewport, {
41
42
  delta,
@@ -980,10 +980,10 @@ class CircleROITool extends AnnotationTool {
980
980
  cachedStats[targetId] = {
981
981
  Modality: metadata.Modality,
982
982
  area,
983
- mean: stats[1]?.value,
984
- max: stats[0]?.value,
985
- stdDev: stats[2]?.value,
986
- statsArray: stats,
983
+ mean: stats.mean?.value,
984
+ max: stats.max?.value,
985
+ stdDev: stats.stdDev?.value,
986
+ statsArray: stats.array,
987
987
  pointsInShape: pointsInShape,
988
988
  isEmptyArea,
989
989
  areaUnit: getCalibratedAreaUnits(null, image),
@@ -1099,11 +1099,11 @@ class EllipticalROITool extends AnnotationTool {
1099
1099
  cachedStats[targetId] = {
1100
1100
  Modality: metadata.Modality,
1101
1101
  area,
1102
- mean: stats[1]?.value,
1103
- max: stats[0]?.value,
1104
- stdDev: stats[2]?.value,
1105
- statsArray: stats,
1106
- pointsInShape: pointsInShape,
1102
+ mean: stats.mean?.value,
1103
+ max: stats.max?.value,
1104
+ stdDev: stats.stdDev?.value,
1105
+ statsArray: stats.array,
1106
+ pointsInShape,
1107
1107
  isEmptyArea,
1108
1108
  areaUnit: getCalibratedAreaUnits(null, image),
1109
1109
  modalityUnit,
@@ -835,10 +835,10 @@ class PlanarFreehandROITool extends ContourSegmentationBaseTool {
835
835
  cachedStats[targetId] = {
836
836
  Modality: metadata.Modality,
837
837
  area,
838
- mean: stats[1]?.value,
839
- max: stats[0]?.value,
840
- stdDev: stats[3]?.value,
841
- statsArray: stats,
838
+ mean: stats.mean?.value,
839
+ max: stats.max?.value,
840
+ stdDev: stats.stdDev?.value,
841
+ statsArray: stats.array,
842
842
  pointsInShape: pointsInShape,
843
843
  areaUnit: getCalibratedAreaUnits(null, image),
844
844
  modalityUnit,
@@ -954,10 +954,10 @@ class RectangleROITool extends AnnotationTool {
954
954
  cachedStats[targetId] = {
955
955
  Modality: metadata.Modality,
956
956
  area,
957
- mean: stats[1]?.value,
958
- stdDev: stats[2]?.value,
959
- max: stats[0]?.value,
960
- statsArray: stats,
957
+ mean: stats.mean?.value,
958
+ stdDev: stats.stdDev?.value,
959
+ max: stats.max?.value,
960
+ statsArray: stats.array,
961
961
  pointsInShape: pointsInShape,
962
962
  areaUnit: getCalibratedAreaUnits(null, image),
963
963
  modalityUnit,
@@ -15,6 +15,7 @@ import filterAnnotationsForDisplay from '../../utilities/planar/filterAnnotation
15
15
  import { getStyleProperty } from '../../stateManagement/annotation/config/helpers';
16
16
  import { getState } from '../../stateManagement/annotation/config';
17
17
  import { StyleSpecifier } from '../../types/AnnotationStyle';
18
+ import { getVolumeId } from '../../utilities/getVolumeId';
18
19
 
19
20
  /**
20
21
  * Abstract class for tools which create and display annotations on the
@@ -137,7 +138,7 @@ abstract class AnnotationDisplayTool extends BaseTool {
137
138
  } else if (viewport instanceof VideoViewport) {
138
139
  referencedImageId = targetId.split('videoId:')[1];
139
140
  } else {
140
- const volumeId = targetId.split(/volumeId:|\?/)[1];
141
+ const volumeId = getVolumeId(targetId);
141
142
  const imageVolume = cache.getVolume(volumeId);
142
143
 
143
144
  referencedImageId = utilities.getClosestImageId(
@@ -24,6 +24,7 @@ import {
24
24
  import { addAnnotation } from '../../stateManagement/annotation/annotationState';
25
25
  import { StyleSpecifier } from '../../types/AnnotationStyle';
26
26
  import { triggerAnnotationModified } from '../../stateManagement/annotation/helpers/state';
27
+ import { getVolumeId } from '../../utilities/getVolumeId';
27
28
 
28
29
  /**
29
30
  * Abstract class for tools which create and display annotations on the
@@ -368,7 +369,7 @@ abstract class AnnotationTool extends AnnotationDisplayTool {
368
369
  imageId?: string
369
370
  ): boolean {
370
371
  if (viewport instanceof BaseVolumeViewport) {
371
- const volumeId = targetId.split(/volumeId:|\?/)[1];
372
+ const volumeId = getVolumeId(targetId);
372
373
  const volume = cache.getVolume(volumeId);
373
374
  return volume.scaling?.PT !== undefined;
374
375
  }
@@ -3,6 +3,7 @@ import { Types } from '@cornerstonejs/core';
3
3
  import ToolModes from '../../enums/ToolModes';
4
4
  import StrategyCallbacks from '../../enums/StrategyCallbacks';
5
5
  import { InteractionTypes, ToolProps, PublicToolProps } from '../../types';
6
+ import { getVolumeId } from '../../utilities/getVolumeId';
6
7
 
7
8
  export interface IBaseTool {
8
9
  /** ToolGroup ID the tool instance belongs to */
@@ -208,7 +209,7 @@ abstract class BaseTool implements IBaseTool {
208
209
 
209
210
  return viewports[0].getImageData();
210
211
  } else if (targetId.startsWith('volumeId:')) {
211
- const volumeId = targetId.split(/volumeId:|\?/)[1];
212
+ const volumeId = getVolumeId(targetId);
212
213
  const viewports = utilities.getViewportsWithVolumeId(
213
214
  volumeId,
214
215
  renderingEngine.id
@@ -1,7 +1,20 @@
1
1
  type Statistics = {
2
2
  name: string;
3
+ label?: string;
3
4
  value: number | number[];
4
5
  unit: null | string;
5
6
  };
6
7
 
7
- export type { Statistics };
8
+ type NamedStatistics = {
9
+ mean: Statistics & { name: 'mean' };
10
+ max: Statistics & { name: 'max' };
11
+ stdDev: Statistics & { name: 'stdDev' };
12
+ stdDevWithSumSquare: Statistics & { name: 'stdDevWithSumSquare' };
13
+ count: Statistics & { name: 'count' };
14
+ area?: Statistics & { name: 'area' };
15
+ volume?: Statistics & { name: 'volume' };
16
+ circumferance?: Statistics & { name: 'circumferance' };
17
+ array: Statistics[];
18
+ };
19
+
20
+ export type { Statistics, NamedStatistics };
@@ -64,7 +64,7 @@ import type { ContourSegmentationData } from './ContourTypes';
64
64
  import type IAnnotationManager from './IAnnotationManager';
65
65
  import type AnnotationGroupSelector from './AnnotationGroupSelector';
66
66
  import type AnnotationRenderContext from './AnnotationRenderContext';
67
- import type { Statistics } from './CalculatorTypes';
67
+ import type { Statistics, NamedStatistics } from './CalculatorTypes';
68
68
  import type { CanvasCoordinates } from '../utilities/math/ellipse/getCanvasEllipseCorners';
69
69
  import {
70
70
  LabelmapToolOperationData,
@@ -162,6 +162,9 @@ export type {
162
162
  ContourSegmentationData,
163
163
  //Statistics
164
164
  Statistics,
165
+ NamedStatistics,
166
+
167
+ // Labelmap data
165
168
  LabelmapToolOperationData,
166
169
  LabelmapToolOperationDataStack,
167
170
  LabelmapToolOperationDataVolume,
@@ -0,0 +1,13 @@
1
+ export const getVolumeId = (targetId: string) => {
2
+ const prefix = 'volumeId:';
3
+ const str = targetId.includes(prefix)
4
+ ? targetId.substring(prefix.length)
5
+ : targetId;
6
+
7
+ if (str.startsWith('nifti:')) {
8
+ return str;
9
+ }
10
+
11
+ const index = str.indexOf('?');
12
+ return index === -1 ? str : str.substring(0, index);
13
+ };
@@ -1,4 +1,4 @@
1
- import { Statistics } from '../../../types';
1
+ import { NamedStatistics, Statistics } from '../../../types';
2
2
  import Calculator from './Calculator';
3
3
 
4
4
  export default class BasicStatsCalculator extends Calculator {
@@ -46,15 +46,15 @@ export default class BasicStatsCalculator extends Calculator {
46
46
 
47
47
  /**
48
48
  * Basic function that calculates statictics for a given array of points.
49
- * @param points
50
49
  * @returns An object that contains :
51
50
  * max : The maximum value of the array
52
51
  * mean : mean of the array
53
52
  * stdDev : standard deviation of the array
54
53
  * stdDevWithSumSquare : standard deviation of the array using sum²
54
+ * array : An array of hte above values, in order.
55
55
  */
56
56
 
57
- static getStatistics = (): Statistics[] => {
57
+ static getStatistics = (): NamedStatistics => {
58
58
  const mean = this.sum.map((sum) => sum / this.count);
59
59
  const stdDev = this.squaredDiffSum.map((squaredDiffSum) =>
60
60
  Math.sqrt(squaredDiffSum / this.count)
@@ -62,7 +62,46 @@ export default class BasicStatsCalculator extends Calculator {
62
62
  const stdDevWithSumSquare = this.sumSquares.map((it, idx) =>
63
63
  Math.sqrt(this.sumSquares[idx] / this.count - mean[idx] ** 2)
64
64
  );
65
- const currentMax = this.max;
65
+
66
+ const named: NamedStatistics = {
67
+ max: {
68
+ name: 'max',
69
+ label: 'Max Pixel',
70
+ value: singleArrayAsNumber(this.max),
71
+ unit: null,
72
+ },
73
+ mean: {
74
+ name: 'mean',
75
+ label: 'Mean Pixel',
76
+ value: singleArrayAsNumber(mean),
77
+ unit: null,
78
+ },
79
+ stdDev: {
80
+ name: 'stdDev',
81
+ label: 'Standard Deviation',
82
+ value: singleArrayAsNumber(stdDev),
83
+ unit: null,
84
+ },
85
+ stdDevWithSumSquare: {
86
+ name: 'stdDevWithSumSquare',
87
+ value: singleArrayAsNumber(stdDevWithSumSquare),
88
+ unit: null,
89
+ },
90
+ count: {
91
+ name: 'count',
92
+ label: 'Pixel Count',
93
+ value: this.count,
94
+ unit: null,
95
+ },
96
+ array: [],
97
+ };
98
+ named.array.push(
99
+ named.max,
100
+ named.mean,
101
+ named.stdDev,
102
+ named.stdDevWithSumSquare,
103
+ named.count
104
+ );
66
105
 
67
106
  this.max = [-Infinity];
68
107
  this.sum = [0];
@@ -70,16 +109,7 @@ export default class BasicStatsCalculator extends Calculator {
70
109
  this.squaredDiffSum = [0];
71
110
  this.count = 0;
72
111
 
73
- return [
74
- { name: 'max', value: singleArrayAsNumber(currentMax), unit: null },
75
- { name: 'mean', value: singleArrayAsNumber(mean), unit: null },
76
- { name: 'stdDev', value: singleArrayAsNumber(stdDev), unit: null },
77
- {
78
- name: 'stdDevWithSumSquare',
79
- value: singleArrayAsNumber(stdDevWithSumSquare),
80
- unit: null,
81
- },
82
- ];
112
+ return named;
83
113
  };
84
114
  }
85
115
 
@@ -1,8 +1,11 @@
1
- import { Statistics } from '../../../types';
1
+ import { NamedStatistics } from '../../../types';
2
2
 
3
3
  abstract class Calculator {
4
4
  static run: ({ value }) => void;
5
- static getStatistics: () => Statistics[];
5
+ /**
6
+ * Gets the statistics as both an array of values, as well as the named values.
7
+ */
8
+ static getStatistics: () => NamedStatistics;
6
9
  }
7
10
 
8
11
  export default Calculator;