@cornerstonejs/tools 1.72.6 → 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/dist/cjs/tools/annotation/PlanarFreehandROITool.d.ts +1 -0
- package/dist/cjs/tools/annotation/PlanarFreehandROITool.js +15 -2
- package/dist/cjs/tools/annotation/PlanarFreehandROITool.js.map +1 -1
- package/dist/cjs/tools/annotation/planarFreehandROITool/renderMethods.js +32 -0
- package/dist/cjs/tools/annotation/planarFreehandROITool/renderMethods.js.map +1 -1
- package/dist/cjs/tools/displayTools/Contour/contourHandler/handleContourSegmentation.js +1 -1
- package/dist/cjs/tools/displayTools/Contour/contourHandler/handleContourSegmentation.js.map +1 -1
- package/dist/cjs/types/CalculatorTypes.d.ts +7 -5
- package/dist/cjs/utilities/math/basic/BasicStatsCalculator.d.ts +12 -4
- package/dist/cjs/utilities/math/basic/BasicStatsCalculator.js +45 -23
- package/dist/cjs/utilities/math/basic/BasicStatsCalculator.js.map +1 -1
- package/dist/esm/tools/annotation/PlanarFreehandROITool.js +15 -2
- package/dist/esm/tools/annotation/PlanarFreehandROITool.js.map +1 -1
- package/dist/esm/tools/annotation/planarFreehandROITool/renderMethods.js +32 -0
- package/dist/esm/tools/annotation/planarFreehandROITool/renderMethods.js.map +1 -1
- package/dist/esm/tools/displayTools/Contour/contourHandler/handleContourSegmentation.js +1 -1
- package/dist/esm/tools/displayTools/Contour/contourHandler/handleContourSegmentation.js.map +1 -1
- package/dist/esm/utilities/math/basic/BasicStatsCalculator.js +44 -23
- package/dist/esm/utilities/math/basic/BasicStatsCalculator.js.map +1 -1
- package/dist/types/tools/annotation/PlanarFreehandROITool.d.ts +1 -0
- package/dist/types/tools/annotation/PlanarFreehandROITool.d.ts.map +1 -1
- package/dist/types/tools/annotation/planarFreehandROITool/renderMethods.d.ts.map +1 -1
- package/dist/types/types/CalculatorTypes.d.ts +7 -5
- package/dist/types/types/CalculatorTypes.d.ts.map +1 -1
- package/dist/types/utilities/math/basic/BasicStatsCalculator.d.ts +12 -4
- package/dist/types/utilities/math/basic/BasicStatsCalculator.d.ts.map +1 -1
- package/dist/umd/index.js +1 -1
- package/dist/umd/index.js.map +1 -1
- package/package.json +3 -3
- package/src/tools/annotation/PlanarFreehandROITool.ts +31 -2
- package/src/tools/annotation/planarFreehandROITool/renderMethods.ts +67 -0
- package/src/tools/displayTools/Contour/contourHandler/handleContourSegmentation.ts +1 -1
- package/src/types/CalculatorTypes.ts +5 -2
- package/src/utilities/math/basic/BasicStatsCalculator.ts +71 -41
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cornerstonejs/tools",
|
|
3
|
-
"version": "1.
|
|
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.
|
|
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": "
|
|
62
|
+
"gitHead": "092b216feafeede75c7dff4ddd415f034a218f19"
|
|
63
63
|
}
|
|
@@ -170,6 +170,12 @@ class PlanarFreehandROITool extends ContourSegmentationBaseTool {
|
|
|
170
170
|
annotation: PlanarFreehandROIAnnotation
|
|
171
171
|
) => void;
|
|
172
172
|
|
|
173
|
+
private renderPointContourWithMarker: (
|
|
174
|
+
enabledElement: Types.IEnabledElement,
|
|
175
|
+
svgDrawingHelper: SVGDrawingHelper,
|
|
176
|
+
annotation: PlanarFreehandROIAnnotation
|
|
177
|
+
) => void;
|
|
178
|
+
|
|
173
179
|
constructor(
|
|
174
180
|
toolProps: PublicToolProps = {},
|
|
175
181
|
defaultToolProps: ToolProps = {
|
|
@@ -242,6 +248,7 @@ class PlanarFreehandROITool extends ContourSegmentationBaseTool {
|
|
|
242
248
|
*/
|
|
243
249
|
epsilon: 0.1,
|
|
244
250
|
},
|
|
251
|
+
displayOnePointAsCrosshairs: false,
|
|
245
252
|
calculateStats: true,
|
|
246
253
|
getTextLines: defaultGetTextLines,
|
|
247
254
|
statsCalculator: BasicStatsCalculator,
|
|
@@ -578,7 +585,18 @@ class PlanarFreehandROITool extends ContourSegmentationBaseTool {
|
|
|
578
585
|
if (!(isDrawing || isEditingOpen || isEditingClosed)) {
|
|
579
586
|
// No annotations are currently being modified, so we can just use the
|
|
580
587
|
// render contour method to render all of them
|
|
581
|
-
|
|
588
|
+
if (
|
|
589
|
+
this.configuration.displayOnePointAsCrosshairs &&
|
|
590
|
+
annotation.data.contour.polyline.length === 1
|
|
591
|
+
) {
|
|
592
|
+
this.renderPointContourWithMarker(
|
|
593
|
+
enabledElement,
|
|
594
|
+
svgDrawingHelper,
|
|
595
|
+
annotation
|
|
596
|
+
);
|
|
597
|
+
} else {
|
|
598
|
+
this.renderContour(enabledElement, svgDrawingHelper, annotation);
|
|
599
|
+
}
|
|
582
600
|
} else {
|
|
583
601
|
// The active annotation will need special rendering treatment. Render all
|
|
584
602
|
// other annotations not being interacted with using the standard renderContour
|
|
@@ -610,7 +628,18 @@ class PlanarFreehandROITool extends ContourSegmentationBaseTool {
|
|
|
610
628
|
);
|
|
611
629
|
}
|
|
612
630
|
} else {
|
|
613
|
-
|
|
631
|
+
if (
|
|
632
|
+
this.configuration.displayOnePointAsCrosshairs &&
|
|
633
|
+
annotation.data.contour.polyline.length === 1
|
|
634
|
+
) {
|
|
635
|
+
this.renderPointContourWithMarker(
|
|
636
|
+
enabledElement,
|
|
637
|
+
svgDrawingHelper,
|
|
638
|
+
annotation
|
|
639
|
+
);
|
|
640
|
+
} else {
|
|
641
|
+
this.renderContour(enabledElement, svgDrawingHelper, annotation);
|
|
642
|
+
}
|
|
614
643
|
}
|
|
615
644
|
|
|
616
645
|
// Todo: return boolean flag for each rendering route in the planar tool.
|
|
@@ -407,6 +407,71 @@ function renderOpenContourBeingEdited(
|
|
|
407
407
|
);
|
|
408
408
|
}
|
|
409
409
|
|
|
410
|
+
/**
|
|
411
|
+
* Renders a point `PlanarFreehandROIAnnotation` annotation by drawing a circle and a crosshair
|
|
412
|
+
*/
|
|
413
|
+
|
|
414
|
+
function renderPointContourWithMarker(
|
|
415
|
+
enabledElement: Types.IEnabledElement,
|
|
416
|
+
svgDrawingHelper: SVGDrawingHelper,
|
|
417
|
+
annotation: PlanarFreehandROIAnnotation
|
|
418
|
+
): void {
|
|
419
|
+
if (annotation.parentAnnotationUID) {
|
|
420
|
+
return;
|
|
421
|
+
}
|
|
422
|
+
const { viewport } = enabledElement;
|
|
423
|
+
const options = this._getRenderingOptions(enabledElement, annotation);
|
|
424
|
+
const canvasPolyline = annotation.data.contour.polyline.map((worldPos) =>
|
|
425
|
+
viewport.worldToCanvas(worldPos)
|
|
426
|
+
);
|
|
427
|
+
const childContours = getContourHolesDataCanvas(annotation, viewport);
|
|
428
|
+
const polylineUID = '1';
|
|
429
|
+
|
|
430
|
+
const center = canvasPolyline[0];
|
|
431
|
+
const radius = 6;
|
|
432
|
+
const numberOfPoints = 100;
|
|
433
|
+
const circlePoints = [];
|
|
434
|
+
|
|
435
|
+
for (let i = 0; i < numberOfPoints; i++) {
|
|
436
|
+
const angle = (i / numberOfPoints) * 2 * Math.PI;
|
|
437
|
+
const x = center[0] + radius * Math.cos(angle);
|
|
438
|
+
const y = center[1] + radius * Math.sin(angle);
|
|
439
|
+
circlePoints.push([x, y]);
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
const crosshair = [
|
|
443
|
+
[center[0] - radius * 2, center[1]],
|
|
444
|
+
[center[0] + radius * 2, center[1]],
|
|
445
|
+
[center[0], center[1] - radius * 2],
|
|
446
|
+
[center[0], center[1] + radius * 2],
|
|
447
|
+
] as Types.Point2[];
|
|
448
|
+
|
|
449
|
+
drawPathSvg(
|
|
450
|
+
svgDrawingHelper,
|
|
451
|
+
annotation.annotationUID,
|
|
452
|
+
polylineUID + '-crosshair_v',
|
|
453
|
+
[crosshair[0], crosshair[1]],
|
|
454
|
+
options
|
|
455
|
+
);
|
|
456
|
+
|
|
457
|
+
drawPathSvg(
|
|
458
|
+
svgDrawingHelper,
|
|
459
|
+
annotation.annotationUID,
|
|
460
|
+
polylineUID + '-crosshair_h',
|
|
461
|
+
[crosshair[2], crosshair[3]],
|
|
462
|
+
options
|
|
463
|
+
);
|
|
464
|
+
|
|
465
|
+
const allContours = [circlePoints, ...childContours];
|
|
466
|
+
|
|
467
|
+
drawPathSvg(
|
|
468
|
+
svgDrawingHelper,
|
|
469
|
+
annotation.annotationUID,
|
|
470
|
+
polylineUID,
|
|
471
|
+
allContours,
|
|
472
|
+
options
|
|
473
|
+
);
|
|
474
|
+
}
|
|
410
475
|
/**
|
|
411
476
|
* Registers the render methods of various contour states to the tool instance.
|
|
412
477
|
*/
|
|
@@ -414,6 +479,8 @@ function registerRenderMethods(toolInstance) {
|
|
|
414
479
|
toolInstance.renderContour = renderContour.bind(toolInstance);
|
|
415
480
|
toolInstance.renderClosedContour = renderClosedContour.bind(toolInstance);
|
|
416
481
|
toolInstance.renderOpenContour = renderOpenContour.bind(toolInstance);
|
|
482
|
+
toolInstance.renderPointContourWithMarker =
|
|
483
|
+
renderPointContourWithMarker.bind(toolInstance);
|
|
417
484
|
toolInstance.renderOpenUShapedContour =
|
|
418
485
|
renderOpenUShapedContour.bind(toolInstance);
|
|
419
486
|
|
|
@@ -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
|
-
|
|
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 {
|
|
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
|
|
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.
|
|
25
|
-
this.
|
|
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
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
(it,
|
|
40
|
-
|
|
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
|
|
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.
|
|
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
|
-
|
|
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
|
|
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
|
|
101
|
+
unit,
|
|
78
102
|
},
|
|
79
103
|
stdDev: {
|
|
80
104
|
name: 'stdDev',
|
|
81
105
|
label: 'Standard Deviation',
|
|
82
106
|
value: singleArrayAsNumber(stdDev),
|
|
83
|
-
unit
|
|
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
|
-
|
|
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.
|
|
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
|
};
|