@cornerstonejs/tools 1.35.2 → 1.36.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/drawingSvg/drawEllipse.js +6 -42
- package/dist/cjs/drawingSvg/drawEllipse.js.map +1 -1
- package/dist/cjs/drawingSvg/drawEllipseByCoordinates.d.ts +4 -0
- package/dist/cjs/drawingSvg/drawEllipseByCoordinates.js +53 -0
- package/dist/cjs/drawingSvg/drawEllipseByCoordinates.js.map +1 -0
- package/dist/cjs/drawingSvg/index.d.ts +2 -1
- package/dist/cjs/drawingSvg/index.js +3 -1
- package/dist/cjs/drawingSvg/index.js.map +1 -1
- package/dist/cjs/eventListeners/segmentation/imageChangeEventListener.js +3 -0
- package/dist/cjs/eventListeners/segmentation/imageChangeEventListener.js.map +1 -1
- package/dist/cjs/stateManagement/segmentation/SegmentationStateManager.d.ts +5 -4
- package/dist/cjs/stateManagement/segmentation/SegmentationStateManager.js +6 -10
- package/dist/cjs/stateManagement/segmentation/SegmentationStateManager.js.map +1 -1
- package/dist/cjs/stateManagement/segmentation/addSegmentationRepresentation.d.ts +3 -0
- package/dist/cjs/stateManagement/segmentation/addSegmentationRepresentation.js +87 -0
- package/dist/cjs/stateManagement/segmentation/addSegmentationRepresentation.js.map +1 -0
- package/dist/cjs/stateManagement/segmentation/addSegmentationRepresentations.js +2 -29
- package/dist/cjs/stateManagement/segmentation/addSegmentationRepresentations.js.map +1 -1
- package/dist/cjs/stateManagement/segmentation/config/segmentationColor.d.ts +4 -5
- package/dist/cjs/stateManagement/segmentation/config/segmentationColor.js.map +1 -1
- package/dist/cjs/stateManagement/segmentation/helpers/getRepresentationSpecificConfig.d.ts +2 -0
- package/dist/cjs/stateManagement/segmentation/helpers/getRepresentationSpecificConfig.js +19 -0
- package/dist/cjs/stateManagement/segmentation/helpers/getRepresentationSpecificConfig.js.map +1 -0
- package/dist/cjs/stateManagement/segmentation/segmentationState.d.ts +6 -4
- package/dist/cjs/stateManagement/segmentation/segmentationState.js +6 -1
- package/dist/cjs/stateManagement/segmentation/segmentationState.js.map +1 -1
- package/dist/cjs/store/ToolGroupManager/ToolGroup.d.ts +1 -1
- package/dist/cjs/store/ToolGroupManager/ToolGroup.js +2 -1
- package/dist/cjs/store/ToolGroupManager/ToolGroup.js.map +1 -1
- package/dist/cjs/tools/annotation/EllipticalROITool.js +2 -12
- package/dist/cjs/tools/annotation/EllipticalROITool.js.map +1 -1
- package/dist/cjs/tools/annotation/SplineROITool.js +9 -34
- package/dist/cjs/tools/annotation/SplineROITool.js.map +1 -1
- package/dist/cjs/tools/displayTools/Contour/contourDisplay.d.ts +1 -3
- package/dist/cjs/tools/displayTools/Contour/contourDisplay.js +0 -33
- package/dist/cjs/tools/displayTools/Contour/contourDisplay.js.map +1 -1
- package/dist/cjs/tools/displayTools/Labelmap/labelmapDisplay.d.ts +9 -3
- package/dist/cjs/tools/displayTools/Labelmap/labelmapDisplay.js +13 -37
- package/dist/cjs/tools/displayTools/Labelmap/labelmapDisplay.js.map +1 -1
- package/dist/cjs/tools/displayTools/Surface/surfaceDisplay.d.ts +1 -3
- package/dist/cjs/tools/displayTools/Surface/surfaceDisplay.js +0 -32
- package/dist/cjs/tools/displayTools/Surface/surfaceDisplay.js.map +1 -1
- package/dist/cjs/types/SegmentationStateTypes.d.ts +5 -3
- package/dist/cjs/types/index.d.ts +2 -2
- package/dist/esm/drawingSvg/drawEllipse.js +6 -42
- package/dist/esm/drawingSvg/drawEllipse.js.map +1 -1
- package/dist/esm/drawingSvg/drawEllipseByCoordinates.js +48 -0
- package/dist/esm/drawingSvg/drawEllipseByCoordinates.js.map +1 -0
- package/dist/esm/drawingSvg/index.js +2 -1
- package/dist/esm/drawingSvg/index.js.map +1 -1
- package/dist/esm/eventListeners/segmentation/imageChangeEventListener.js +3 -0
- package/dist/esm/eventListeners/segmentation/imageChangeEventListener.js.map +1 -1
- package/dist/esm/stateManagement/segmentation/SegmentationStateManager.js +6 -10
- package/dist/esm/stateManagement/segmentation/SegmentationStateManager.js.map +1 -1
- package/dist/esm/stateManagement/segmentation/addSegmentationRepresentation.js +49 -0
- package/dist/esm/stateManagement/segmentation/addSegmentationRepresentation.js.map +1 -0
- package/dist/esm/stateManagement/segmentation/addSegmentationRepresentations.js +2 -24
- package/dist/esm/stateManagement/segmentation/addSegmentationRepresentations.js.map +1 -1
- package/dist/esm/stateManagement/segmentation/config/segmentationColor.js.map +1 -1
- package/dist/esm/stateManagement/segmentation/helpers/getRepresentationSpecificConfig.js +12 -0
- package/dist/esm/stateManagement/segmentation/helpers/getRepresentationSpecificConfig.js.map +1 -0
- package/dist/esm/stateManagement/segmentation/segmentationState.js +5 -1
- package/dist/esm/stateManagement/segmentation/segmentationState.js.map +1 -1
- package/dist/esm/store/ToolGroupManager/ToolGroup.js +2 -1
- package/dist/esm/store/ToolGroupManager/ToolGroup.js.map +1 -1
- package/dist/esm/tools/annotation/EllipticalROITool.js +3 -13
- package/dist/esm/tools/annotation/EllipticalROITool.js.map +1 -1
- package/dist/esm/tools/annotation/SplineROITool.js +2 -4
- package/dist/esm/tools/annotation/SplineROITool.js.map +1 -1
- package/dist/esm/tools/displayTools/Contour/contourDisplay.js +1 -34
- package/dist/esm/tools/displayTools/Contour/contourDisplay.js.map +1 -1
- package/dist/esm/tools/displayTools/Labelmap/labelmapDisplay.js +6 -33
- package/dist/esm/tools/displayTools/Labelmap/labelmapDisplay.js.map +1 -1
- package/dist/esm/tools/displayTools/Surface/surfaceDisplay.js +1 -33
- package/dist/esm/tools/displayTools/Surface/surfaceDisplay.js.map +1 -1
- package/dist/types/drawingSvg/drawEllipse.d.ts.map +1 -1
- package/dist/types/drawingSvg/drawEllipseByCoordinates.d.ts +5 -0
- package/dist/types/drawingSvg/drawEllipseByCoordinates.d.ts.map +1 -0
- package/dist/types/drawingSvg/index.d.ts +2 -1
- package/dist/types/drawingSvg/index.d.ts.map +1 -1
- package/dist/types/eventListeners/segmentation/imageChangeEventListener.d.ts.map +1 -1
- package/dist/types/stateManagement/segmentation/SegmentationStateManager.d.ts +5 -4
- package/dist/types/stateManagement/segmentation/SegmentationStateManager.d.ts.map +1 -1
- package/dist/types/stateManagement/segmentation/addSegmentationRepresentation.d.ts +4 -0
- package/dist/types/stateManagement/segmentation/addSegmentationRepresentation.d.ts.map +1 -0
- package/dist/types/stateManagement/segmentation/addSegmentationRepresentations.d.ts.map +1 -1
- package/dist/types/stateManagement/segmentation/config/segmentationColor.d.ts +4 -5
- package/dist/types/stateManagement/segmentation/config/segmentationColor.d.ts.map +1 -1
- package/dist/types/stateManagement/segmentation/helpers/getRepresentationSpecificConfig.d.ts +3 -0
- package/dist/types/stateManagement/segmentation/helpers/getRepresentationSpecificConfig.d.ts.map +1 -0
- package/dist/types/stateManagement/segmentation/segmentationState.d.ts +6 -4
- package/dist/types/stateManagement/segmentation/segmentationState.d.ts.map +1 -1
- package/dist/types/store/ToolGroupManager/ToolGroup.d.ts +1 -1
- package/dist/types/store/ToolGroupManager/ToolGroup.d.ts.map +1 -1
- package/dist/types/tools/annotation/EllipticalROITool.d.ts.map +1 -1
- package/dist/types/tools/annotation/SplineROITool.d.ts.map +1 -1
- package/dist/types/tools/displayTools/Contour/contourDisplay.d.ts +1 -3
- package/dist/types/tools/displayTools/Contour/contourDisplay.d.ts.map +1 -1
- package/dist/types/tools/displayTools/Labelmap/labelmapDisplay.d.ts +9 -3
- package/dist/types/tools/displayTools/Labelmap/labelmapDisplay.d.ts.map +1 -1
- package/dist/types/tools/displayTools/Surface/surfaceDisplay.d.ts +1 -3
- package/dist/types/tools/displayTools/Surface/surfaceDisplay.d.ts.map +1 -1
- package/dist/types/types/SegmentationStateTypes.d.ts +5 -3
- package/dist/types/types/SegmentationStateTypes.d.ts.map +1 -1
- package/dist/types/types/index.d.ts +2 -2
- package/dist/types/types/index.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/drawingSvg/drawEllipse.ts +15 -55
- package/src/drawingSvg/drawEllipseByCoordinates.ts +73 -0
- package/src/drawingSvg/index.ts +2 -0
- package/src/eventListeners/segmentation/imageChangeEventListener.ts +5 -0
- package/src/stateManagement/segmentation/SegmentationStateManager.ts +10 -17
- package/src/stateManagement/segmentation/addSegmentationRepresentation.ts +86 -0
- package/src/stateManagement/segmentation/addSegmentationRepresentations.ts +2 -43
- package/src/stateManagement/segmentation/config/segmentationColor.ts +4 -6
- package/src/stateManagement/segmentation/helpers/getRepresentationSpecificConfig.ts +15 -0
- package/src/stateManagement/segmentation/segmentationState.ts +9 -3
- package/src/store/ToolGroupManager/ToolGroup.ts +4 -6
- package/src/tools/annotation/EllipticalROITool.ts +5 -15
- package/src/tools/annotation/SplineROITool.ts +3 -3
- package/src/tools/displayTools/Contour/contourDisplay.ts +0 -61
- package/src/tools/displayTools/Labelmap/labelmapDisplay.ts +11 -66
- package/src/tools/displayTools/Surface/surfaceDisplay.ts +0 -60
- package/src/types/SegmentationStateTypes.ts +7 -12
- package/src/types/index.ts +0 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cornerstonejs/tools",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.36.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.36.0",
|
|
33
33
|
"comlink": "^4.4.1",
|
|
34
34
|
"lodash.clonedeep": "4.5.0",
|
|
35
35
|
"lodash.get": "^4.4.2"
|
|
@@ -53,5 +53,5 @@
|
|
|
53
53
|
"type": "individual",
|
|
54
54
|
"url": "https://ohif.org/donate"
|
|
55
55
|
},
|
|
56
|
-
"gitHead": "
|
|
56
|
+
"gitHead": "616ef6915f122cab6d1e27e2d02ebc95484a4e37"
|
|
57
57
|
}
|
|
@@ -2,8 +2,7 @@ import type { Types } from '@cornerstonejs/core';
|
|
|
2
2
|
import { SVGDrawingHelper } from '../types';
|
|
3
3
|
|
|
4
4
|
import _getHash from './_getHash';
|
|
5
|
-
import
|
|
6
|
-
import setNewAttributesIfValid from './setNewAttributesIfValid';
|
|
5
|
+
import drawEllipseByCoordinates from './drawEllipseByCoordinates';
|
|
7
6
|
|
|
8
7
|
function drawEllipse(
|
|
9
8
|
svgDrawingHelper: SVGDrawingHelper,
|
|
@@ -13,59 +12,20 @@ function drawEllipse(
|
|
|
13
12
|
corner2: Types.Point2,
|
|
14
13
|
options = {},
|
|
15
14
|
dataId = ''
|
|
16
|
-
)
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
const svgns = 'http://www.w3.org/2000/svg';
|
|
31
|
-
const svgNodeHash = _getHash(annotationUID, 'ellipse', ellipseUID);
|
|
32
|
-
const existingEllipse = svgDrawingHelper.getSvgNode(svgNodeHash);
|
|
33
|
-
|
|
34
|
-
const w = Math.abs(corner1[0] - corner2[0]);
|
|
35
|
-
const h = Math.abs(corner1[1] - corner2[1]);
|
|
36
|
-
const xMin = Math.min(corner1[0], corner2[0]);
|
|
37
|
-
const yMin = Math.min(corner1[1], corner2[1]);
|
|
38
|
-
|
|
39
|
-
const center = [xMin + w / 2, yMin + h / 2];
|
|
40
|
-
const radiusX = w / 2;
|
|
41
|
-
const radiusY = h / 2;
|
|
42
|
-
|
|
43
|
-
const attributes = {
|
|
44
|
-
cx: `${center[0]}`,
|
|
45
|
-
cy: `${center[1]}`,
|
|
46
|
-
rx: `${radiusX}`,
|
|
47
|
-
ry: `${radiusY}`,
|
|
48
|
-
stroke: color,
|
|
49
|
-
fill: 'transparent',
|
|
50
|
-
'stroke-width': strokeWidth,
|
|
51
|
-
'stroke-dasharray': lineDash,
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
if (existingEllipse) {
|
|
55
|
-
setAttributesIfNecessary(attributes, existingEllipse);
|
|
56
|
-
|
|
57
|
-
svgDrawingHelper.setNodeTouched(svgNodeHash);
|
|
58
|
-
} else {
|
|
59
|
-
const svgEllipseElement = document.createElementNS(svgns, 'ellipse');
|
|
60
|
-
|
|
61
|
-
if (dataId !== '') {
|
|
62
|
-
svgEllipseElement.setAttribute('data-id', dataId);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
setNewAttributesIfValid(attributes, svgEllipseElement);
|
|
66
|
-
|
|
67
|
-
svgDrawingHelper.appendNode(svgEllipseElement, svgNodeHash);
|
|
68
|
-
}
|
|
15
|
+
){
|
|
16
|
+
const top: Types.Point2 = [ (corner1[0] + corner2[0]) / 2, corner1[1] ];
|
|
17
|
+
const bottom: Types.Point2 = [ (corner1[0] + corner2[0]) / 2, corner2[1] ];
|
|
18
|
+
const left: Types.Point2 = [ corner1[0], (corner1[1] + corner2[1]) / 2];
|
|
19
|
+
const right: Types.Point2 = [ corner2[0], (corner1[1] + corner2[1]) / 2];
|
|
20
|
+
|
|
21
|
+
drawEllipseByCoordinates(
|
|
22
|
+
svgDrawingHelper,
|
|
23
|
+
annotationUID,
|
|
24
|
+
ellipseUID,
|
|
25
|
+
[bottom, top, left, right],
|
|
26
|
+
options = {},
|
|
27
|
+
dataId = ''
|
|
28
|
+
)
|
|
69
29
|
}
|
|
70
30
|
|
|
71
31
|
export default drawEllipse;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
2
|
|
2
|
+
import type { Types } from '@cornerstonejs/core';
|
|
3
|
+
import { SVGDrawingHelper } from '../types';
|
|
4
|
+
|
|
5
|
+
import _getHash from './_getHash';
|
|
6
|
+
import setAttributesIfNecessary from './setAttributesIfNecessary';
|
|
7
|
+
import setNewAttributesIfValid from './setNewAttributesIfValid';
|
|
8
|
+
|
|
9
|
+
function drawEllipseByCoordinates(
|
|
10
|
+
svgDrawingHelper: SVGDrawingHelper,
|
|
11
|
+
annotationUID: string,
|
|
12
|
+
ellipseUID: string,
|
|
13
|
+
canvasCoordinates: [Types.Point2, Types.Point2, Types.Point2, Types.Point2],
|
|
14
|
+
options = {},
|
|
15
|
+
dataId = ''
|
|
16
|
+
): void {
|
|
17
|
+
const { color, width, lineWidth, lineDash } = Object.assign(
|
|
18
|
+
{
|
|
19
|
+
color: 'dodgerblue',
|
|
20
|
+
width: '2',
|
|
21
|
+
lineWidth: undefined,
|
|
22
|
+
lineDash: undefined,
|
|
23
|
+
},
|
|
24
|
+
options
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
// for supporting both lineWidth and width options
|
|
28
|
+
const strokeWidth = lineWidth || width;
|
|
29
|
+
|
|
30
|
+
const svgns = 'http://www.w3.org/2000/svg';
|
|
31
|
+
const svgNodeHash = _getHash(annotationUID, 'ellipse', ellipseUID);
|
|
32
|
+
const existingEllipse = svgDrawingHelper.getSvgNode(svgNodeHash);
|
|
33
|
+
|
|
34
|
+
const [bottom, top, left, right] = canvasCoordinates;
|
|
35
|
+
|
|
36
|
+
const w = Math.hypot(left[0] - right[0], left[1] - right[1]);
|
|
37
|
+
const h = Math.hypot(top[0] - bottom[0], top[1] - bottom[1]);
|
|
38
|
+
const angle = Math.atan2(left[1] - right[1], left[0] - right[0]) * 180 / Math.PI;
|
|
39
|
+
|
|
40
|
+
const center = [(left[0] + right[0]) / 2 , ( top[1] + bottom[1] ) / 2];
|
|
41
|
+
const radiusX = w / 2;
|
|
42
|
+
const radiusY = h / 2;
|
|
43
|
+
|
|
44
|
+
const attributes = {
|
|
45
|
+
cx: `${center[0]}`,
|
|
46
|
+
cy: `${center[1]}`,
|
|
47
|
+
rx: `${radiusX}`,
|
|
48
|
+
ry: `${radiusY}`,
|
|
49
|
+
stroke: color,
|
|
50
|
+
fill: 'transparent',
|
|
51
|
+
'transform': `rotate(${angle} ${center[0]} ${center[1]})`,
|
|
52
|
+
'stroke-width': strokeWidth,
|
|
53
|
+
'stroke-dasharray': lineDash,
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
if (existingEllipse) {
|
|
57
|
+
setAttributesIfNecessary(attributes, existingEllipse);
|
|
58
|
+
|
|
59
|
+
svgDrawingHelper.setNodeTouched(svgNodeHash);
|
|
60
|
+
} else {
|
|
61
|
+
const svgEllipseElement = document.createElementNS(svgns, 'ellipse');
|
|
62
|
+
|
|
63
|
+
if (dataId !== '') {
|
|
64
|
+
svgEllipseElement.setAttribute('data-id', dataId);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
setNewAttributesIfValid(attributes, svgEllipseElement);
|
|
68
|
+
|
|
69
|
+
svgDrawingHelper.appendNode(svgEllipseElement, svgNodeHash);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export default drawEllipseByCoordinates;
|
package/src/drawingSvg/index.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import draw from './draw';
|
|
2
2
|
import drawCircle from './drawCircle';
|
|
3
3
|
import drawEllipse from './drawEllipse';
|
|
4
|
+
import drawEllipseByCoordinates from './drawEllipseByCoordinates';
|
|
4
5
|
import drawHandles from './drawHandles';
|
|
5
6
|
import drawLine from './drawLine';
|
|
6
7
|
import drawPolyline from './drawPolyline';
|
|
@@ -16,6 +17,7 @@ export {
|
|
|
16
17
|
draw,
|
|
17
18
|
drawCircle,
|
|
18
19
|
drawEllipse,
|
|
20
|
+
drawEllipseByCoordinates,
|
|
19
21
|
drawHandles,
|
|
20
22
|
drawLine,
|
|
21
23
|
drawPolyline,
|
|
@@ -71,6 +71,11 @@ function _imageChangeEventListener(evt) {
|
|
|
71
71
|
) as { viewport: Types.IStackViewport };
|
|
72
72
|
|
|
73
73
|
const toolGroup = getToolGroupForViewport(viewportId, renderingEngineId);
|
|
74
|
+
|
|
75
|
+
if (!toolGroup) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
|
|
74
79
|
let toolGroupSegmentationRepresentations =
|
|
75
80
|
SegmentationState.getSegmentationRepresentations(toolGroup.id) || [];
|
|
76
81
|
|
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
import { utilities as csUtils } from '@cornerstonejs/core';
|
|
2
1
|
import cloneDeep from 'lodash.clonedeep';
|
|
3
|
-
|
|
4
|
-
import
|
|
2
|
+
import type { Types } from '@cornerstonejs/core';
|
|
3
|
+
import { utilities as csUtils } from '@cornerstonejs/core';
|
|
5
4
|
|
|
6
5
|
import { SegmentationRepresentations } from '../../enums';
|
|
7
6
|
import getDefaultContourConfig from '../../tools/displayTools/Contour/contourConfig';
|
|
8
7
|
import getDefaultLabelmapConfig from '../../tools/displayTools/Labelmap/labelmapConfig';
|
|
9
8
|
import type {
|
|
10
|
-
ColorLUT,
|
|
11
9
|
RepresentationConfig,
|
|
12
10
|
Segmentation,
|
|
13
11
|
SegmentationRepresentationConfig,
|
|
@@ -77,10 +75,14 @@ export default class SegmentationStateManager {
|
|
|
77
75
|
* @param lutIndex - The index of the color LUT to retrieve.
|
|
78
76
|
* @returns A ColorLUT object.
|
|
79
77
|
*/
|
|
80
|
-
getColorLUT(lutIndex: number): ColorLUT | undefined {
|
|
78
|
+
getColorLUT(lutIndex: number): Types.ColorLUT | undefined {
|
|
81
79
|
return this.state.colorLUT[lutIndex];
|
|
82
80
|
}
|
|
83
81
|
|
|
82
|
+
getNextColorLUTIndex(): number {
|
|
83
|
+
return this.state.colorLUT.length;
|
|
84
|
+
}
|
|
85
|
+
|
|
84
86
|
/**
|
|
85
87
|
* Reset the state to the default state
|
|
86
88
|
*/
|
|
@@ -104,8 +106,6 @@ export default class SegmentationStateManager {
|
|
|
104
106
|
* @param segmentation - Segmentation
|
|
105
107
|
*/
|
|
106
108
|
addSegmentation(segmentation: Segmentation): void {
|
|
107
|
-
this._initDefaultColorLUTIfNecessary();
|
|
108
|
-
|
|
109
109
|
// Check if the segmentation already exists with the segmentationId
|
|
110
110
|
if (this.getSegmentation(segmentation.segmentationId)) {
|
|
111
111
|
throw new Error(
|
|
@@ -433,12 +433,12 @@ export default class SegmentationStateManager {
|
|
|
433
433
|
* @param colorLUT - ColorLUT
|
|
434
434
|
* @param lutIndex - The index of the color LUT table to add.
|
|
435
435
|
*/
|
|
436
|
-
addColorLUT(colorLUT: ColorLUT, lutIndex: number): void {
|
|
436
|
+
addColorLUT(colorLUT: Types.ColorLUT, lutIndex: number): void {
|
|
437
437
|
if (this.state.colorLUT[lutIndex]) {
|
|
438
|
-
console.
|
|
438
|
+
console.warn('Color LUT table already exists, overwriting');
|
|
439
439
|
}
|
|
440
440
|
|
|
441
|
-
this.state.colorLUT[lutIndex] = colorLUT;
|
|
441
|
+
this.state.colorLUT[lutIndex] = structuredClone(colorLUT);
|
|
442
442
|
}
|
|
443
443
|
|
|
444
444
|
/**
|
|
@@ -500,13 +500,6 @@ export default class SegmentationStateManager {
|
|
|
500
500
|
|
|
501
501
|
// 5. if added/removed segmentation is is inactive, do nothing
|
|
502
502
|
}
|
|
503
|
-
|
|
504
|
-
_initDefaultColorLUTIfNecessary() {
|
|
505
|
-
// if colorLUTTable is not specified or the default one is not found
|
|
506
|
-
if (this.state.colorLUT.length === 0 || !this.state.colorLUT[0]) {
|
|
507
|
-
this.addColorLUT(CORNERSTONE_COLOR_LUT as ColorLUT, 0);
|
|
508
|
-
}
|
|
509
|
-
}
|
|
510
503
|
}
|
|
511
504
|
|
|
512
505
|
const defaultSegmentationStateManager = new SegmentationStateManager('DEFAULT');
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { utilities } from '@cornerstonejs/core';
|
|
2
|
+
import type { Types } from '@cornerstonejs/core';
|
|
3
|
+
import {
|
|
4
|
+
SegmentationRepresentationConfig,
|
|
5
|
+
RepresentationPublicInput,
|
|
6
|
+
ToolGroupSpecificRepresentation,
|
|
7
|
+
} from '../../types/SegmentationStateTypes';
|
|
8
|
+
import Representations from '../../enums/SegmentationRepresentations';
|
|
9
|
+
import * as SegmentationConfig from './config/segmentationConfig';
|
|
10
|
+
import {
|
|
11
|
+
addSegmentationRepresentation as addSegmentationRepresentationToState,
|
|
12
|
+
getNextColorLUTIndex,
|
|
13
|
+
addColorLUT,
|
|
14
|
+
} from './segmentationState';
|
|
15
|
+
import { getRepresentationSpecificConfig } from './helpers/getRepresentationSpecificConfig';
|
|
16
|
+
import CORNERSTONE_COLOR_LUT from '../../constants/COLOR_LUT';
|
|
17
|
+
|
|
18
|
+
async function addSegmentationRepresentation(
|
|
19
|
+
toolGroupId: string,
|
|
20
|
+
representationInput: RepresentationPublicInput,
|
|
21
|
+
toolGroupSpecificConfig?: SegmentationRepresentationConfig
|
|
22
|
+
): Promise<string> {
|
|
23
|
+
const { segmentationId, options = {} } = representationInput;
|
|
24
|
+
const segmentationRepresentationUID = utilities.uuidv4();
|
|
25
|
+
|
|
26
|
+
// Todo: make segmentsHidden also an option that can get passed by
|
|
27
|
+
// the user
|
|
28
|
+
const segmentsHidden = new Set() as Set<number>;
|
|
29
|
+
|
|
30
|
+
const colorLUTOrIndexInput = options.colorLUTOrIndex;
|
|
31
|
+
let colorLUTIndexToUse;
|
|
32
|
+
|
|
33
|
+
if (typeof colorLUTOrIndexInput === 'number') {
|
|
34
|
+
colorLUTIndexToUse = colorLUTOrIndexInput;
|
|
35
|
+
} else {
|
|
36
|
+
const nextIndex = getNextColorLUTIndex();
|
|
37
|
+
const colorLUTToAdd = Array.isArray(colorLUTOrIndexInput)
|
|
38
|
+
? colorLUTOrIndexInput
|
|
39
|
+
: CORNERSTONE_COLOR_LUT;
|
|
40
|
+
addColorLUT(colorLUTToAdd as Types.ColorLUT, nextIndex);
|
|
41
|
+
colorLUTIndexToUse = nextIndex;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const toolGroupSpecificRepresentation: ToolGroupSpecificRepresentation = {
|
|
45
|
+
segmentationId,
|
|
46
|
+
segmentationRepresentationUID,
|
|
47
|
+
type: Representations.Labelmap,
|
|
48
|
+
segmentsHidden,
|
|
49
|
+
colorLUTIndex: colorLUTIndexToUse,
|
|
50
|
+
active: true,
|
|
51
|
+
segmentationRepresentationSpecificConfig: {},
|
|
52
|
+
segmentSpecificConfig: {},
|
|
53
|
+
config: getRepresentationSpecificConfig(representationInput),
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
// Update the toolGroup specific configuration
|
|
57
|
+
if (toolGroupSpecificConfig) {
|
|
58
|
+
// Since setting configuration on toolGroup will trigger a segmentationRepresentation
|
|
59
|
+
// update event, we don't want to trigger the event twice, so we suppress
|
|
60
|
+
// the first one
|
|
61
|
+
const currentToolGroupConfig =
|
|
62
|
+
SegmentationConfig.getToolGroupSpecificConfig(toolGroupId);
|
|
63
|
+
|
|
64
|
+
const mergedConfig = utilities.deepMerge(
|
|
65
|
+
currentToolGroupConfig,
|
|
66
|
+
toolGroupSpecificConfig
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
SegmentationConfig.setToolGroupSpecificConfig(toolGroupId, {
|
|
70
|
+
renderInactiveSegmentations:
|
|
71
|
+
mergedConfig.renderInactiveSegmentations || true,
|
|
72
|
+
representations: {
|
|
73
|
+
...mergedConfig.representations,
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
addSegmentationRepresentationToState(
|
|
79
|
+
toolGroupId,
|
|
80
|
+
toolGroupSpecificRepresentation
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
return segmentationRepresentationUID;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export { addSegmentationRepresentation };
|
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
import _cloneDeep from 'lodash.clonedeep';
|
|
2
1
|
import {
|
|
3
2
|
SegmentationRepresentationConfig,
|
|
4
3
|
RepresentationPublicInput,
|
|
5
4
|
} from '../../types/SegmentationStateTypes';
|
|
6
|
-
import Representations from '../../enums/SegmentationRepresentations';
|
|
7
5
|
import { getToolGroup } from '../../store/ToolGroupManager';
|
|
8
6
|
|
|
9
|
-
import {
|
|
10
|
-
import { contourDisplay } from '../../tools/displayTools/Contour';
|
|
11
|
-
import { surfaceDisplay } from '../../tools/displayTools/Surface';
|
|
7
|
+
import { addSegmentationRepresentation } from './addSegmentationRepresentation';
|
|
12
8
|
|
|
13
9
|
/**
|
|
14
10
|
* Set the specified segmentation representations on the viewports of the specified
|
|
@@ -33,7 +29,7 @@ async function addSegmentationRepresentations(
|
|
|
33
29
|
}
|
|
34
30
|
|
|
35
31
|
const promises = representationInputArray.map((representationInput) => {
|
|
36
|
-
return
|
|
32
|
+
return addSegmentationRepresentation(
|
|
37
33
|
toolGroupId,
|
|
38
34
|
representationInput,
|
|
39
35
|
toolGroupSpecificRepresentationConfig
|
|
@@ -45,41 +41,4 @@ async function addSegmentationRepresentations(
|
|
|
45
41
|
return segmentationRepresentationUIDs;
|
|
46
42
|
}
|
|
47
43
|
|
|
48
|
-
async function _addSegmentationRepresentation(
|
|
49
|
-
toolGroupId: string,
|
|
50
|
-
representationInput: RepresentationPublicInput,
|
|
51
|
-
toolGroupSpecificRepresentationConfig?: SegmentationRepresentationConfig
|
|
52
|
-
): Promise<string> {
|
|
53
|
-
let segmentationRepresentationUID;
|
|
54
|
-
|
|
55
|
-
if (representationInput.type === Representations.Labelmap) {
|
|
56
|
-
segmentationRepresentationUID =
|
|
57
|
-
await labelmapDisplay.addSegmentationRepresentation(
|
|
58
|
-
toolGroupId,
|
|
59
|
-
representationInput,
|
|
60
|
-
toolGroupSpecificRepresentationConfig
|
|
61
|
-
);
|
|
62
|
-
} else if (representationInput.type === Representations.Contour) {
|
|
63
|
-
segmentationRepresentationUID =
|
|
64
|
-
await contourDisplay.addSegmentationRepresentation(
|
|
65
|
-
toolGroupId,
|
|
66
|
-
representationInput,
|
|
67
|
-
toolGroupSpecificRepresentationConfig
|
|
68
|
-
);
|
|
69
|
-
} else if (representationInput.type === Representations.Surface) {
|
|
70
|
-
segmentationRepresentationUID =
|
|
71
|
-
await surfaceDisplay.addSegmentationRepresentation(
|
|
72
|
-
toolGroupId,
|
|
73
|
-
representationInput,
|
|
74
|
-
toolGroupSpecificRepresentationConfig
|
|
75
|
-
);
|
|
76
|
-
} else {
|
|
77
|
-
throw new Error(
|
|
78
|
-
`The representation type ${representationInput.type} is not supported`
|
|
79
|
-
);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
return segmentationRepresentationUID;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
44
|
export default addSegmentationRepresentations;
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { utilities } from '@cornerstonejs/core';
|
|
2
|
+
import type { Types } from '@cornerstonejs/core';
|
|
2
3
|
import * as SegmentationState from '../../../stateManagement/segmentation/segmentationState';
|
|
3
|
-
import { Color } from '../../../types/SegmentationStateTypes';
|
|
4
|
-
import { ColorLUT } from '../../../types/SegmentationStateTypes';
|
|
5
4
|
import { triggerSegmentationRepresentationModified } from '../triggerSegmentationEvents';
|
|
6
|
-
import { SegmentationRepresentations } from '../../../enums';
|
|
7
5
|
|
|
8
6
|
/**
|
|
9
7
|
* addColorLUT - Adds a new color LUT to the state at the given colorLUTIndex.
|
|
@@ -13,7 +11,7 @@ import { SegmentationRepresentations } from '../../../enums';
|
|
|
13
11
|
* @param colorLUT - An array of The colorLUT to set.
|
|
14
12
|
* @returns
|
|
15
13
|
*/
|
|
16
|
-
function addColorLUT(colorLUT: ColorLUT, colorLUTIndex: number): void {
|
|
14
|
+
function addColorLUT(colorLUT: Types.ColorLUT, colorLUTIndex: number): void {
|
|
17
15
|
if (!colorLUT) {
|
|
18
16
|
throw new Error('addColorLUT: colorLUT is required');
|
|
19
17
|
}
|
|
@@ -81,7 +79,7 @@ function getColorForSegmentIndex(
|
|
|
81
79
|
toolGroupId: string,
|
|
82
80
|
segmentationRepresentationUID: string,
|
|
83
81
|
segmentIndex: number
|
|
84
|
-
): Color {
|
|
82
|
+
): Types.Color {
|
|
85
83
|
const segmentationRepresentation =
|
|
86
84
|
SegmentationState.getSegmentationRepresentationByUID(
|
|
87
85
|
toolGroupId,
|
|
@@ -105,7 +103,7 @@ function setColorForSegmentIndex(
|
|
|
105
103
|
toolGroupId: string,
|
|
106
104
|
segmentationRepresentationUID: string,
|
|
107
105
|
segmentIndex: number,
|
|
108
|
-
color: Color
|
|
106
|
+
color: Types.Color
|
|
109
107
|
): void {
|
|
110
108
|
// Get the reference to the color in the colorLUT.
|
|
111
109
|
const colorReference = getColorForSegmentIndex(
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import SegmentationRepresentations from '../../../enums/SegmentationRepresentations';
|
|
2
|
+
import { RepresentationPublicInput } from '../../../types';
|
|
3
|
+
import { getRepresentationRenderingConfig as getLabelmapRenderingConfig } from '../../../tools/displayTools/Labelmap/labelmapDisplay';
|
|
4
|
+
|
|
5
|
+
export function getRepresentationSpecificConfig(
|
|
6
|
+
representationInput: RepresentationPublicInput
|
|
7
|
+
) {
|
|
8
|
+
const { type } = representationInput;
|
|
9
|
+
|
|
10
|
+
if (type === SegmentationRepresentations.Labelmap) {
|
|
11
|
+
return getLabelmapRenderingConfig();
|
|
12
|
+
} else {
|
|
13
|
+
return {};
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import type { Types } from '@cornerstonejs/core';
|
|
1
2
|
import type {
|
|
2
|
-
ColorLUT,
|
|
3
3
|
RepresentationConfig,
|
|
4
4
|
Segmentation,
|
|
5
5
|
SegmentationPublicInput,
|
|
@@ -383,17 +383,22 @@ function removeColorLUT(colorLUTIndex: number): void {
|
|
|
383
383
|
* @param index - The index of the color lut to retrieve.
|
|
384
384
|
* @returns A ColorLUT array.
|
|
385
385
|
*/
|
|
386
|
-
function getColorLUT(index: number): ColorLUT | undefined {
|
|
386
|
+
function getColorLUT(index: number): Types.ColorLUT | undefined {
|
|
387
387
|
const segmentationStateManager = getDefaultSegmentationStateManager();
|
|
388
388
|
return segmentationStateManager.getColorLUT(index);
|
|
389
389
|
}
|
|
390
390
|
|
|
391
|
+
function getNextColorLUTIndex(): number {
|
|
392
|
+
const segmentationStateManager = getDefaultSegmentationStateManager();
|
|
393
|
+
return segmentationStateManager.getNextColorLUTIndex();
|
|
394
|
+
}
|
|
395
|
+
|
|
391
396
|
/**
|
|
392
397
|
* Add a color LUT to the segmentation state manager
|
|
393
398
|
* @param colorLUT - The color LUT array to add.
|
|
394
399
|
* @param index - The index of the color LUT to add.
|
|
395
400
|
*/
|
|
396
|
-
function addColorLUT(colorLUT: ColorLUT, index: number): void {
|
|
401
|
+
function addColorLUT(colorLUT: Types.ColorLUT, index: number): void {
|
|
397
402
|
const segmentationStateManager = getDefaultSegmentationStateManager();
|
|
398
403
|
segmentationStateManager.addColorLUT(colorLUT, index);
|
|
399
404
|
// Todo: trigger event color LUT added
|
|
@@ -426,5 +431,6 @@ export {
|
|
|
426
431
|
// color
|
|
427
432
|
addColorLUT,
|
|
428
433
|
getColorLUT,
|
|
434
|
+
getNextColorLUTIndex,
|
|
429
435
|
removeColorLUT,
|
|
430
436
|
};
|
|
@@ -8,7 +8,6 @@ import {
|
|
|
8
8
|
getRenderingEngines,
|
|
9
9
|
getEnabledElementByIds,
|
|
10
10
|
Settings,
|
|
11
|
-
utilities as csUtils,
|
|
12
11
|
} from '@cornerstonejs/core';
|
|
13
12
|
import type { Types } from '@cornerstonejs/core';
|
|
14
13
|
import { Events } from '../../enums';
|
|
@@ -675,7 +674,7 @@ export default class ToolGroup implements IToolGroup {
|
|
|
675
674
|
* getToolConfiguration('LengthTool', 'firstLevel.secondLevel')
|
|
676
675
|
* // get from LengthTool instance the configuration value as being LengthToolInstance[configuration][firstLevel][secondLevel]
|
|
677
676
|
*/
|
|
678
|
-
getToolConfiguration(toolName: string, configurationPath
|
|
677
|
+
getToolConfiguration(toolName: string, configurationPath?: string): any {
|
|
679
678
|
if (this._toolInstances[toolName] === undefined) {
|
|
680
679
|
console.warn(
|
|
681
680
|
`Tool ${toolName} not present, can't set tool configuration.`
|
|
@@ -683,10 +682,9 @@ export default class ToolGroup implements IToolGroup {
|
|
|
683
682
|
return;
|
|
684
683
|
}
|
|
685
684
|
|
|
686
|
-
const _configuration =
|
|
687
|
-
this._toolInstances[toolName].configuration,
|
|
688
|
-
|
|
689
|
-
);
|
|
685
|
+
const _configuration =
|
|
686
|
+
get(this._toolInstances[toolName].configuration, configurationPath) ||
|
|
687
|
+
this._toolInstances[toolName].configuration;
|
|
690
688
|
|
|
691
689
|
return cloneDeep(_configuration);
|
|
692
690
|
}
|
|
@@ -24,7 +24,7 @@ import { isAnnotationLocked } from '../../stateManagement/annotation/annotationL
|
|
|
24
24
|
import { isAnnotationVisible } from '../../stateManagement/annotation/annotationVisibility';
|
|
25
25
|
import {
|
|
26
26
|
drawCircle as drawCircleSvg,
|
|
27
|
-
|
|
27
|
+
drawEllipseByCoordinates as drawEllipseSvg,
|
|
28
28
|
drawHandles as drawHandlesSvg,
|
|
29
29
|
drawLinkedTextBox as drawLinkedTextBoxSvg,
|
|
30
30
|
} from '../../drawingSvg';
|
|
@@ -787,18 +787,9 @@ class EllipticalROITool extends AnnotationTool {
|
|
|
787
787
|
);
|
|
788
788
|
let canvasCorners;
|
|
789
789
|
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
canvasCoordinates[3], // top
|
|
794
|
-
canvasCoordinates[0], // left
|
|
795
|
-
canvasCoordinates[1], // right
|
|
796
|
-
]);
|
|
797
|
-
} else {
|
|
798
|
-
canvasCorners = <Array<Types.Point2>>(
|
|
799
|
-
getCanvasEllipseCorners(canvasCoordinates) // bottom, top, left, right, keep as is
|
|
800
|
-
);
|
|
801
|
-
}
|
|
790
|
+
canvasCorners = <Array<Types.Point2>>(
|
|
791
|
+
getCanvasEllipseCorners(canvasCoordinates) // bottom, top, left, right, keep as is
|
|
792
|
+
);
|
|
802
793
|
|
|
803
794
|
const { centerPointRadius } = this.configuration;
|
|
804
795
|
|
|
@@ -905,8 +896,7 @@ class EllipticalROITool extends AnnotationTool {
|
|
|
905
896
|
svgDrawingHelper,
|
|
906
897
|
annotationUID,
|
|
907
898
|
ellipseUID,
|
|
908
|
-
|
|
909
|
-
canvasCorners[1],
|
|
899
|
+
canvasCoordinates,
|
|
910
900
|
{
|
|
911
901
|
color,
|
|
912
902
|
lineDash,
|
|
@@ -38,6 +38,9 @@ import {
|
|
|
38
38
|
getCalibratedScale,
|
|
39
39
|
getCalibratedAreaUnits,
|
|
40
40
|
} from '../../utilities';
|
|
41
|
+
import { getViewportIdsWithToolToRender } from '../../utilities/viewportFilters';
|
|
42
|
+
import { getTextBoxCoordsCanvas } from '../../utilities/drawing';
|
|
43
|
+
|
|
41
44
|
import { SplineROIAnnotation } from '../../types/ToolSpecificAnnotationTypes';
|
|
42
45
|
import {
|
|
43
46
|
AnnotationCompletedEventDetail,
|
|
@@ -52,9 +55,6 @@ import { BSpline } from './splines/BSpline';
|
|
|
52
55
|
import * as viewportFilters from '../../utilities/viewportFilters';
|
|
53
56
|
import * as drawing from '../../utilities/drawing';
|
|
54
57
|
|
|
55
|
-
const { getViewportIdsWithToolToRender } = viewportFilters;
|
|
56
|
-
const { getTextBoxCoordsCanvas } = drawing;
|
|
57
|
-
|
|
58
58
|
const SPLINE_MIN_POINTS = 3;
|
|
59
59
|
const SPLINE_CLICK_CLOSE_CURVE_DIST = 10;
|
|
60
60
|
|