@cornerstonejs/adapters 0.1.4 → 0.2.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,21 +1,20 @@
1
1
  {
2
2
  "name": "@cornerstonejs/adapters",
3
- "version": "0.1.4",
3
+ "version": "0.2.0",
4
4
  "description": "Adapters for Cornerstone3D to/from formats including DICOM SR and others",
5
5
  "src": "src/index.js",
6
6
  "main": "src/index.js",
7
7
  "files": [
8
- "build",
9
- "build/@cornerstonejs",
8
+ "dist",
10
9
  "src"
11
10
  ],
12
11
  "directories": {
13
12
  "example": "examples",
14
- "build": "build"
13
+ "build": "dist"
15
14
  },
16
15
  "exports": {
17
- ".": "./build/@cornerstonejs/adapters.js",
18
- "./es": "./build/@cornerstonejs/adapters.es.js"
16
+ ".": "./dist/@cornerstonejs/adapters.js",
17
+ "./es": "./dist/@cornerstonejs/adapters.es.js"
19
18
  },
20
19
  "publishConfig": {
21
20
  "access": "public"
@@ -23,7 +22,7 @@
23
22
  "scripts": {
24
23
  "test": "jest --testTimeout 60000",
25
24
  "build": "rollup -c",
26
- "build:examples": "npm run build && npx cpx 'build/**/*.{js,map}' examples/js",
25
+ "build:examples": "npm run build && npx cpx 'dist/**/*.{js,map}' examples/js",
27
26
  "start": "rollup -c -w",
28
27
  "format": "prettier --write 'src/**/*.js' 'test/**/*.js'",
29
28
  "lint": "eslint --fix ."
@@ -70,5 +69,5 @@
70
69
  "ndarray": "^1.0.19",
71
70
  "pako": "^2.0.4"
72
71
  },
73
- "gitHead": "100fd0c005ba2a0e12ad5eb75df9b9c2127b39f1"
72
+ "gitHead": "4bf312b91b14fad16638d488064a0a6c097e3514"
74
73
  }
@@ -0,0 +1,125 @@
1
+ import { utilities } from "dcmjs";
2
+ import CORNERSTONE_3D_TAG from "./cornerstone3DTag";
3
+ import MeasurementReport from "./MeasurementReport";
4
+
5
+ const { CobbAngle: TID300CobbAngle } = utilities.TID300;
6
+
7
+ const MEASUREMENT_TYPE = "CobbAngle";
8
+ const trackingIdentifierTextValue = `${CORNERSTONE_3D_TAG}:${MEASUREMENT_TYPE}`;
9
+
10
+ class CobbAngle {
11
+ // TODO: this function is required for all Cornerstone Tool Adapters, since it is called by MeasurementReport.
12
+ static getMeasurementData(
13
+ MeasurementGroup,
14
+ sopInstanceUIDToImageIdMap,
15
+ imageToWorldCoords,
16
+ metadata
17
+ ) {
18
+ const { defaultState, NUMGroup, SCOORDGroup, ReferencedFrameNumber } =
19
+ MeasurementReport.getSetupMeasurementData(
20
+ MeasurementGroup,
21
+ sopInstanceUIDToImageIdMap,
22
+ metadata,
23
+ CobbAngle.toolType
24
+ );
25
+
26
+ const referencedImageId =
27
+ defaultState.annotation.metadata.referencedImageId;
28
+
29
+ const { GraphicData } = SCOORDGroup;
30
+ const worldCoords = [];
31
+ for (let i = 0; i < GraphicData.length; i += 2) {
32
+ const point = imageToWorldCoords(referencedImageId, [
33
+ GraphicData[i],
34
+ GraphicData[i + 1]
35
+ ]);
36
+ worldCoords.push(point);
37
+ }
38
+
39
+ const state = defaultState;
40
+
41
+ state.annotation.data = {
42
+ handles: {
43
+ points: [
44
+ worldCoords[0],
45
+ worldCoords[1],
46
+ worldCoords[2],
47
+ worldCoords[3]
48
+ ],
49
+ activeHandleIndex: 0,
50
+ textBox: {
51
+ hasMoved: false
52
+ }
53
+ },
54
+ cachedStats: {
55
+ [`imageId:${referencedImageId}`]: {
56
+ angle: NUMGroup
57
+ ? NUMGroup.MeasuredValueSequence.NumericValue
58
+ : null
59
+ }
60
+ },
61
+ frameNumber: ReferencedFrameNumber
62
+ };
63
+
64
+ return state;
65
+ }
66
+
67
+ static getTID300RepresentationArguments(tool, worldToImageCoords) {
68
+ const { data, finding, findingSites, metadata } = tool;
69
+ const { cachedStats = {}, handles } = data;
70
+
71
+ const { referencedImageId } = metadata;
72
+
73
+ if (!referencedImageId) {
74
+ throw new Error(
75
+ "CobbAngle.getTID300RepresentationArguments: referencedImageId is not defined"
76
+ );
77
+ }
78
+
79
+ const start1 = worldToImageCoords(referencedImageId, handles.points[0]);
80
+ const end1 = worldToImageCoords(referencedImageId, handles.points[1]);
81
+
82
+ const start2 = worldToImageCoords(referencedImageId, handles.points[2]);
83
+ const end2 = worldToImageCoords(referencedImageId, handles.points[3]);
84
+
85
+ const point1 = { x: start1[0], y: start1[1] };
86
+ const point2 = { x: end1[0], y: end1[1] };
87
+ const point3 = { x: start2[0], y: start2[1] };
88
+ const point4 = { x: end2[0], y: end2[1] };
89
+
90
+ const { angle } = cachedStats[`imageId:${referencedImageId}`] || {};
91
+
92
+ return {
93
+ point1,
94
+ point2,
95
+ point3,
96
+ point4,
97
+ rAngle: angle,
98
+ trackingIdentifierTextValue,
99
+ finding,
100
+ findingSites: findingSites || []
101
+ };
102
+ }
103
+ }
104
+
105
+ CobbAngle.toolType = MEASUREMENT_TYPE;
106
+ CobbAngle.utilityToolType = MEASUREMENT_TYPE;
107
+ console.log("TID300CobbAngle=", TID300CobbAngle);
108
+ CobbAngle.TID300Representation = TID300CobbAngle;
109
+ CobbAngle.isValidCornerstoneTrackingIdentifier = TrackingIdentifier => {
110
+ if (!TrackingIdentifier.includes(":")) {
111
+ return false;
112
+ }
113
+
114
+ const [cornerstone3DTag, toolType] = TrackingIdentifier.split(":");
115
+
116
+ if (cornerstone3DTag !== CORNERSTONE_3D_TAG) {
117
+ return false;
118
+ }
119
+
120
+ return toolType === MEASUREMENT_TYPE;
121
+ };
122
+
123
+ MeasurementReport.registerTool(CobbAngle);
124
+
125
+ export default CobbAngle;
@@ -4,6 +4,7 @@ import CORNERSTONE_3D_TAG from "./cornerstone3DTag";
4
4
 
5
5
  import ArrowAnnotate from "./ArrowAnnotate";
6
6
  import Bidirectional from "./Bidirectional";
7
+ import CobbAngle from "./CobbAngle";
7
8
  import EllipticalROI from "./EllipticalROI";
8
9
  import Length from "./Length";
9
10
  import PlanarFreehandROI from "./PlanarFreehandROI";
@@ -11,6 +12,7 @@ import Probe from "./Probe";
11
12
 
12
13
  const Cornerstone3D = {
13
14
  Bidirectional,
15
+ CobbAngle,
14
16
  Length,
15
17
  EllipticalROI,
16
18
  ArrowAnnotate,