@cornerstonejs/tools 1.73.0 → 1.74.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cornerstonejs/tools",
3
- "version": "1.73.0",
3
+ "version": "1.74.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.73.0",
32
+ "@cornerstonejs/core": "^1.74.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": "7d9375494668c1b3857c560643e490470d35523d"
62
+ "gitHead": "092b216feafeede75c7dff4ddd415f034a218f19"
63
63
  }
@@ -1,3 +1,5 @@
1
+ import type { Types } from '@cornerstonejs/core';
2
+
1
3
  type Statistics = {
2
4
  name: string;
3
5
  label?: string;
@@ -8,12 +10,13 @@ type Statistics = {
8
10
  type NamedStatistics = {
9
11
  mean: Statistics & { name: 'mean' };
10
12
  max: Statistics & { name: 'max' };
13
+ min: Statistics & { name: 'min' };
11
14
  stdDev: Statistics & { name: 'stdDev' };
12
- stdDevWithSumSquare: Statistics & { name: 'stdDevWithSumSquare' };
13
15
  count: Statistics & { name: 'count' };
14
16
  area?: Statistics & { name: 'area' };
15
17
  volume?: Statistics & { name: 'volume' };
16
- circumferance?: Statistics & { name: 'circumferance' };
18
+ circumference?: Statistics & { name: 'circumference' };
19
+ pointsInShape?: Types.PointsManager<Types.Point3>;
17
20
  array: Statistics[];
18
21
  };
19
22
 
@@ -1,113 +1,143 @@
1
- import { NamedStatistics, Statistics } from '../../../types';
1
+ import { utilities } from '@cornerstonejs/core';
2
+ import { NamedStatistics } from '../../../types';
2
3
  import Calculator from './Calculator';
3
4
 
5
+ const { PointsManager } = utilities;
6
+
4
7
  export default class BasicStatsCalculator extends Calculator {
5
8
  private static max = [-Infinity];
9
+ private static min = [Infinity];
6
10
  private static sum = [0];
7
- private static sumSquares = [0];
8
- private static squaredDiffSum = [0];
9
11
  private static count = 0;
10
12
 
13
+ // private static sumSquares = [0];
14
+ // Values for Welford's algorithm
15
+ private static runMean = [0];
16
+ private static m2 = [0];
17
+
18
+ // Collect the points to be returned
19
+ private static pointsInShape = PointsManager.create3(1024);
20
+
21
+ public static statsInit(options: { noPointsCollection: boolean }) {
22
+ if (options.noPointsCollection) {
23
+ BasicStatsCalculator.pointsInShape = null;
24
+ }
25
+ }
26
+
11
27
  /**
12
- * This callback is used when we verify if the point is in the annotion drawn so we can get every point
13
- * in the shape to calculate the statistics
14
- * @param value of the point in the shape of the annotation
28
+ * This callback is used when we verify if the point is in the annotation drawn
29
+ * so we can get every point in the shape to calculate the statistics
15
30
  */
16
- static statsCallback = ({ value: newValue }): void => {
31
+ static statsCallback = ({ value: newValue, pointLPS = null }): void => {
17
32
  if (
18
33
  Array.isArray(newValue) &&
19
34
  newValue.length > 1 &&
20
35
  this.max.length === 1
21
36
  ) {
22
37
  this.max.push(this.max[0], this.max[0]);
38
+ this.min.push(this.min[0], this.min[0]);
23
39
  this.sum.push(this.sum[0], this.sum[0]);
24
- this.sumSquares.push(this.sumSquares[0], this.sumSquares[0]);
25
- this.squaredDiffSum.push(this.squaredDiffSum[0], this.squaredDiffSum[0]);
40
+ this.runMean.push(0, 0);
41
+ // this.sumSquares.push(this.sumSquares[0], this.sumSquares[0]);
42
+ this.m2.push(this.m2[0], this.m2[0]);
26
43
  }
27
44
 
45
+ this.pointsInShape?.push(pointLPS);
28
46
  const newArray = Array.isArray(newValue) ? newValue : [newValue];
47
+
29
48
  this.count += 1;
49
+ this.max.map((it, idx) => {
50
+ const value = newArray[idx];
30
51
 
31
- this.max.forEach(
32
- (it, idx) => (this.max[idx] = Math.max(it, newArray[idx]))
33
- );
34
- this.sum.map((it, idx) => (this.sum[idx] += newArray[idx]));
35
- this.sumSquares.map(
36
- (it, idx) => (this.sumSquares[idx] += newArray[idx] ** 2)
37
- );
38
- this.squaredDiffSum.map(
39
- (it, idx) =>
40
- (this.squaredDiffSum[idx] += Math.pow(
41
- newArray[idx] - this.sum[idx] / this.count,
42
- 2
43
- ))
44
- );
52
+ const delta = value - this.runMean[idx];
53
+ this.sum[idx] += value;
54
+ this.runMean[idx] += delta / this.count;
55
+ const delta2 = value - this.runMean[idx];
56
+ this.m2[idx] += delta * delta2;
57
+ // this.sumSquares[idx] += value * value;
58
+
59
+ this.min[idx] = Math.min(this.min[idx], value);
60
+ this.max[idx] = Math.max(it, value);
61
+ });
45
62
  };
46
63
 
47
64
  /**
48
- * Basic function that calculates statictics for a given array of points.
65
+ * Basic function that calculates statistics for a given array of points.
49
66
  * @returns An object that contains :
50
67
  * max : The maximum value of the array
51
68
  * mean : mean of the array
52
69
  * stdDev : standard deviation of the array
53
- * stdDevWithSumSquare : standard deviation of the array using sum²
54
70
  * array : An array of hte above values, in order.
55
71
  */
56
72
 
57
- static getStatistics = (): NamedStatistics => {
73
+ static getStatistics = (options?: { unit: string }): NamedStatistics => {
58
74
  const mean = this.sum.map((sum) => sum / this.count);
59
- const stdDev = this.squaredDiffSum.map((squaredDiffSum) =>
75
+ const stdDev = this.m2.map((squaredDiffSum) =>
60
76
  Math.sqrt(squaredDiffSum / this.count)
61
77
  );
62
- const stdDevWithSumSquare = this.sumSquares.map((it, idx) =>
63
- Math.sqrt(this.sumSquares[idx] / this.count - mean[idx] ** 2)
64
- );
78
+ // const stdDevWithSumSquare = this.sumSquares.map((it, idx) =>
79
+ // Math.sqrt(this.sumSquares[idx] / this.count - mean[idx] ** 2)
80
+ // );
81
+
82
+ const unit = options?.unit || null;
65
83
 
66
84
  const named: NamedStatistics = {
67
85
  max: {
68
86
  name: 'max',
69
87
  label: 'Max Pixel',
70
88
  value: singleArrayAsNumber(this.max),
71
- unit: null,
89
+ unit,
90
+ },
91
+ min: {
92
+ name: 'min',
93
+ label: 'Min Pixel',
94
+ value: singleArrayAsNumber(this.min),
95
+ unit,
72
96
  },
73
97
  mean: {
74
98
  name: 'mean',
75
99
  label: 'Mean Pixel',
76
100
  value: singleArrayAsNumber(mean),
77
- unit: null,
101
+ unit,
78
102
  },
79
103
  stdDev: {
80
104
  name: 'stdDev',
81
105
  label: 'Standard Deviation',
82
106
  value: singleArrayAsNumber(stdDev),
83
- unit: null,
84
- },
85
- stdDevWithSumSquare: {
86
- name: 'stdDevWithSumSquare',
87
- value: singleArrayAsNumber(stdDevWithSumSquare),
88
- unit: null,
107
+ unit,
89
108
  },
109
+ // stdDevWithSumSquare: {
110
+ // name: 'stdDevWithSumSquare',
111
+ // value: singleArrayAsNumber(stdDevWithSumSquare),
112
+ // unit,
113
+ // },
90
114
  count: {
91
115
  name: 'count',
92
116
  label: 'Pixel Count',
93
117
  value: this.count,
94
118
  unit: null,
95
119
  },
120
+ pointsInShape: this.pointsInShape,
96
121
  array: [],
97
122
  };
98
123
  named.array.push(
99
124
  named.max,
100
125
  named.mean,
101
126
  named.stdDev,
102
- named.stdDevWithSumSquare,
127
+ // Use the stdDev twice to preserve old ordering - this is updated to be
128
+ // correct value with Welford's algorithm now.
129
+ named.stdDev,
103
130
  named.count
104
131
  );
105
132
 
106
133
  this.max = [-Infinity];
134
+ this.min = [Infinity];
107
135
  this.sum = [0];
108
- this.sumSquares = [0];
109
- this.squaredDiffSum = [0];
136
+ // this.sumSquares = [0];
137
+ this.m2 = [0];
138
+ this.runMean = [0];
110
139
  this.count = 0;
140
+ this.pointsInShape = PointsManager.create3(1024);
111
141
 
112
142
  return named;
113
143
  };