@cornerstonejs/tools 0.57.1 → 0.58.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": "0.57.1",
3
+ "version": "0.58.0",
4
4
  "description": "Cornerstone3D Tools",
5
5
  "main": "dist/umd/index.js",
6
6
  "types": "dist/esm/index.d.ts",
@@ -26,7 +26,7 @@
26
26
  "webpack:watch": "webpack --mode development --progress --watch --config ./.webpack/webpack.dev.js"
27
27
  },
28
28
  "dependencies": {
29
- "@cornerstonejs/core": "^0.37.0",
29
+ "@cornerstonejs/core": "^0.38.0",
30
30
  "lodash.clonedeep": "4.5.0",
31
31
  "lodash.get": "^4.4.2"
32
32
  },
@@ -52,5 +52,5 @@
52
52
  "type": "individual",
53
53
  "url": "https://ohif.org/donate"
54
54
  },
55
- "gitHead": "c340fede4008457cd754df259b40a9dfff912668"
55
+ "gitHead": "9a2711ca032949079e7b96ba332b6e01b3316da8"
56
56
  }
@@ -0,0 +1,68 @@
1
+ import { Enums, Types } from '@cornerstonejs/core';
2
+
3
+ /**
4
+ * Gets the scalar data for a series of time frames from a 4D volume, returns an
5
+ * array of scalar data after performing AVERAGE, SUM or SUBTRACT to be used to
6
+ * create a 3D volume
7
+ *
8
+ * @param dynamicVolume4D: volume to compute time frame data from
9
+ * @param operation: operation to perform on time frame data, operations include
10
+ * SUM, AVERAGE, and SUBTRACT (can only be used with 2 time frames provided)
11
+ * @param frameNumbers: an array of frame indexs to perform the operation on, if
12
+ * left empty, all frames will be used
13
+ * @returns
14
+ */
15
+ function generateImageFromTimeData(
16
+ dynamicVolume: Types.IDynamicImageVolume,
17
+ operation: string,
18
+ frameNumbers?: number[]
19
+ ) {
20
+ // If no time frames provided, use all time frames
21
+ const frames = frameNumbers || [...Array(dynamicVolume.numTimePoints).keys()];
22
+ const numFrames = frames.length;
23
+
24
+ if (frames.length <= 1) {
25
+ throw new Error('Please provide two or more time points');
26
+ }
27
+
28
+ // Gets scalar data for all time frames
29
+ const typedArrays = dynamicVolume.getScalarDataArrays();
30
+
31
+ const arrayLength = typedArrays[0].length;
32
+ const finalArray = new Float32Array(arrayLength);
33
+
34
+ if (operation === Enums.DynamicOperatorType.SUM) {
35
+ for (let i = 0; i < numFrames; i++) {
36
+ const currentArray = typedArrays[frames[i]];
37
+ for (let j = 0; j < arrayLength; j++) {
38
+ finalArray[j] += currentArray[j];
39
+ }
40
+ }
41
+ return finalArray;
42
+ }
43
+
44
+ if (operation === Enums.DynamicOperatorType.SUBTRACT) {
45
+ if (frames.length > 2) {
46
+ throw new Error('Please provide only 2 time points for subtraction.');
47
+ }
48
+ for (let j = 0; j < arrayLength; j++) {
49
+ finalArray[j] += typedArrays[frames[0]][j] - typedArrays[frames[1]][j];
50
+ }
51
+ return finalArray;
52
+ }
53
+
54
+ if (operation === Enums.DynamicOperatorType.AVERAGE) {
55
+ for (let i = 0; i < numFrames; i++) {
56
+ const currentArray = typedArrays[frames[i]];
57
+ for (let j = 0; j < arrayLength; j++) {
58
+ finalArray[j] += currentArray[j];
59
+ }
60
+ }
61
+ for (let k = 0; k < arrayLength; k++) {
62
+ finalArray[k] = finalArray[k] / numFrames;
63
+ }
64
+ return finalArray;
65
+ }
66
+ }
67
+
68
+ export default generateImageFromTimeData;
@@ -83,11 +83,11 @@ function _getTimePointDataCoordinate(frames, coordinate, volume) {
83
83
  const allScalarData = volume.getScalarDataArrays();
84
84
  const value = [];
85
85
 
86
- for (let i = frames[0]; i < frames[0] + frames.length; i++) {
87
- const activeScalarData = allScalarData[i];
86
+ frames.forEach((frame) => {
87
+ const activeScalarData = allScalarData[frame];
88
88
  const scalarIndex = index[2] * zMultiple + index[1] * yMultiple + index[0];
89
89
  value.push(activeScalarData[scalarIndex]);
90
- }
90
+ });
91
91
 
92
92
  return value;
93
93
  }
@@ -98,10 +98,10 @@ function _getTimePointDataMask(frames, indexArray, volume) {
98
98
 
99
99
  for (let i = 0; i < indexArray.length; i++) {
100
100
  const indexValues = [];
101
- for (let j = frames[0]; j < frames[0] + frames.length; j++) {
102
- const activeScalarData = allScalarData[j];
101
+ frames.forEach((frame) => {
102
+ const activeScalarData = allScalarData[frame];
103
103
  indexValues.push(activeScalarData[indexArray[i]]);
104
- }
104
+ });
105
105
  value.push(indexValues);
106
106
  }
107
107
  return value;
@@ -1,2 +1,5 @@
1
1
  import getDataInTime from './getDataInTime';
2
+ import generateImageFromTimeData from './generateImageFromTimeData';
3
+
2
4
  export { getDataInTime };
5
+ export { generateImageFromTimeData };