@cornerstonejs/core 1.74.7 → 1.75.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/core",
3
- "version": "1.74.7",
3
+ "version": "1.75.0",
4
4
  "description": "",
5
5
  "main": "src/index.ts",
6
6
  "types": "dist/types/index.d.ts",
@@ -47,5 +47,5 @@
47
47
  "type": "individual",
48
48
  "url": "https://ohif.org/donate"
49
49
  },
50
- "gitHead": "920867f2eff21665e60e9c585f5afb67d2ee2387"
50
+ "gitHead": "76cc2c23137bd1aceb0d2e5939f42a8c8e9dbf00"
51
51
  }
@@ -66,13 +66,7 @@ async function createVolumeActor(
66
66
  volumeActor.getProperty().setIndependentComponents(false);
67
67
  }
68
68
 
69
- // If the volume is composed of imageIds, we can apply a default VOI based
70
- // on either the metadata or the min/max of the middle slice. Example of other
71
- // types of volumes which might not be composed of imageIds would be e.g., nrrd, nifti
72
- // format volumes
73
- if (imageVolume.imageIds?.length) {
74
- await setDefaultVolumeVOI(volumeActor, imageVolume, useNativeDataType);
75
- }
69
+ await setDefaultVolumeVOI(volumeActor, imageVolume, useNativeDataType);
76
70
 
77
71
  if (callback) {
78
72
  callback({ volumeActor, volumeId });
@@ -21,6 +21,7 @@ const REQUEST_TYPE = RequestType.Prefetch;
21
21
  * Finally it sets the VOI on the volumeActor transferFunction
22
22
  * @param volumeActor - The volume actor
23
23
  * @param imageVolume - The image volume that we want to set the VOI for.
24
+ * @param useNativeDataType - The image data type is native or Float32Array
24
25
  */
25
26
  async function setDefaultVolumeVOI(
26
27
  volumeActor: VolumeActor,
@@ -29,27 +30,27 @@ async function setDefaultVolumeVOI(
29
30
  ): Promise<void> {
30
31
  let voi = getVOIFromMetadata(imageVolume);
31
32
 
32
- if (!voi) {
33
+ if (!voi && imageVolume?.imageIds?.length) {
33
34
  voi = await getVOIFromMinMax(imageVolume, useNativeDataType);
35
+ voi = handlePreScaledVolume(imageVolume, voi);
34
36
  }
35
-
36
- if (!voi || voi.lower === undefined || voi.upper === undefined) {
37
- throw new Error(
38
- 'Could not get VOI from metadata, nor from the min max of the image middle slice'
39
- );
40
- }
41
-
42
- voi = handlePreScaledVolume(imageVolume, voi);
43
- const { lower, upper } = voi;
44
-
45
- if (lower === 0 && upper === 0) {
37
+ // if (!voi || voi.lower === undefined || voi.upper === undefined) {
38
+ // throw new Error(
39
+ // 'Could not get VOI from metadata, nor from the min max of the image middle slice'
40
+ // );
41
+ // }
42
+ if (
43
+ (voi?.lower === 0 && voi?.upper === 0) ||
44
+ voi?.lower === undefined ||
45
+ voi?.upper === undefined
46
+ ) {
46
47
  return;
47
48
  }
48
49
 
49
50
  volumeActor
50
51
  .getProperty()
51
52
  .getRGBTransferFunction(0)
52
- .setMappingRange(lower, upper);
53
+ .setMappingRange(voi.lower, voi.upper);
53
54
  }
54
55
 
55
56
  function handlePreScaledVolume(imageVolume: IImageVolume, voi: VOIRange) {
@@ -77,35 +78,36 @@ function handlePreScaledVolume(imageVolume: IImageVolume, voi: VOIRange) {
77
78
  }
78
79
 
79
80
  /**
80
- * Get the VOI from the metadata of the middle slice of the image volume. It checks
81
- * the metadata for the VOI and if it is not found, it returns null
81
+ * Get the VOI from the metadata of the middle slice of the image volume or the metadata of the image volume
82
+ * It checks the metadata for the VOI and if it is not found, it returns null
82
83
  *
83
84
  * @param imageVolume - The image volume that we want to get the VOI from.
84
85
  * @returns VOIRange with lower and upper values
85
86
  */
86
87
  function getVOIFromMetadata(imageVolume: IImageVolume): VOIRange {
87
- const { imageIds } = imageVolume;
88
-
89
- const imageIdIndex = Math.floor(imageIds.length / 2);
90
- const imageId = imageIds[imageIdIndex];
91
-
92
- const voiLutModule = metaData.get('voiLutModule', imageId);
93
-
94
- if (voiLutModule && voiLutModule.windowWidth && voiLutModule.windowCenter) {
95
- const { windowWidth, windowCenter } = voiLutModule;
96
-
97
- const voi = {
98
- windowWidth: Array.isArray(windowWidth) ? windowWidth[0] : windowWidth,
99
- windowCenter: Array.isArray(windowCenter)
100
- ? windowCenter[0]
101
- : windowCenter,
102
- };
103
-
88
+ const { imageIds, metadata } = imageVolume;
89
+ let voi;
90
+ if (imageIds.length) {
91
+ const imageIdIndex = Math.floor(imageIds.length / 2);
92
+ const imageId = imageIds[imageIdIndex];
93
+ const voiLutModule = metaData.get('voiLutModule', imageId);
94
+ if (voiLutModule && voiLutModule.windowWidth && voiLutModule.windowCenter) {
95
+ const { windowWidth, windowCenter } = voiLutModule;
96
+ voi = {
97
+ windowWidth: Array.isArray(windowWidth) ? windowWidth[0] : windowWidth,
98
+ windowCenter: Array.isArray(windowCenter)
99
+ ? windowCenter[0]
100
+ : windowCenter,
101
+ };
102
+ }
103
+ } else {
104
+ voi = metadata?.voiLut?.[0];
105
+ }
106
+ if (voi) {
104
107
  const { lower, upper } = windowLevel.toLowHighRange(
105
108
  Number(voi.windowWidth),
106
109
  Number(voi.windowCenter)
107
110
  );
108
-
109
111
  return {
110
112
  lower,
111
113
  upper,
@@ -118,6 +120,7 @@ function getVOIFromMetadata(imageVolume: IImageVolume): VOIRange {
118
120
  * and max pixel values, it calculates the VOI.
119
121
  *
120
122
  * @param imageVolume - The image volume that we want to get the VOI from.
123
+ * @param useNativeDataType - The image data type is native or Float32Array
121
124
  * @returns The VOIRange with lower and upper values
122
125
  */
123
126
  async function getVOIFromMinMax(
@@ -218,7 +221,7 @@ function _getImageScalarDataFromImageVolume(
218
221
  voxelsPerImage
219
222
  ) {
220
223
  const { scalarData } = imageVolume;
221
- const { volumeBuffer } = scalarData;
224
+ const { buffer } = scalarData;
222
225
  if (scalarData.BYTES_PER_ELEMENT !== bytePerPixel) {
223
226
  byteOffset *= scalarData.BYTES_PER_ELEMENT / bytePerPixel;
224
227
  }
@@ -226,11 +229,7 @@ function _getImageScalarDataFromImageVolume(
226
229
  const TypedArray = scalarData.constructor;
227
230
  const imageScalarData = new TypedArray(voxelsPerImage);
228
231
 
229
- const volumeBufferView = new TypedArray(
230
- volumeBuffer,
231
- byteOffset,
232
- voxelsPerImage
233
- );
232
+ const volumeBufferView = new TypedArray(buffer, byteOffset, voxelsPerImage);
234
233
 
235
234
  imageScalarData.set(volumeBufferView);
236
235