@cornerstonejs/core 1.70.7 → 1.70.8

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.
Files changed (65) hide show
  1. package/dist/cjs/RenderingEngine/StackViewport.d.ts +1 -0
  2. package/dist/cjs/RenderingEngine/StackViewport.js +1 -0
  3. package/dist/cjs/RenderingEngine/StackViewport.js.map +1 -1
  4. package/dist/cjs/RenderingEngine/helpers/setDefaultVolumeVOI.js +1 -0
  5. package/dist/cjs/RenderingEngine/helpers/setDefaultVolumeVOI.js.map +1 -1
  6. package/dist/cjs/index.d.ts +2 -2
  7. package/dist/cjs/index.js +3 -1
  8. package/dist/cjs/index.js.map +1 -1
  9. package/dist/cjs/init.d.ts +2 -1
  10. package/dist/cjs/init.js +47 -3
  11. package/dist/cjs/init.js.map +1 -1
  12. package/dist/cjs/types/Cornerstone3DConfig.d.ts +1 -0
  13. package/dist/cjs/utilities/generateVolumePropsFromImageIds.js +4 -3
  14. package/dist/cjs/utilities/generateVolumePropsFromImageIds.js.map +1 -1
  15. package/dist/cjs/utilities/hasFloatScalingParameters.d.ts +2 -0
  16. package/dist/cjs/utilities/hasFloatScalingParameters.js +9 -0
  17. package/dist/cjs/utilities/hasFloatScalingParameters.js.map +1 -0
  18. package/dist/cjs/utilities/index.d.ts +2 -1
  19. package/dist/cjs/utilities/index.js +3 -1
  20. package/dist/cjs/utilities/index.js.map +1 -1
  21. package/dist/cjs/utilities/loadImageToCanvas.js +4 -2
  22. package/dist/cjs/utilities/loadImageToCanvas.js.map +1 -1
  23. package/dist/esm/RenderingEngine/StackViewport.js +1 -0
  24. package/dist/esm/RenderingEngine/StackViewport.js.map +1 -1
  25. package/dist/esm/RenderingEngine/helpers/setDefaultVolumeVOI.js +1 -0
  26. package/dist/esm/RenderingEngine/helpers/setDefaultVolumeVOI.js.map +1 -1
  27. package/dist/esm/index.js +2 -2
  28. package/dist/esm/index.js.map +1 -1
  29. package/dist/esm/init.js +44 -1
  30. package/dist/esm/init.js.map +1 -1
  31. package/dist/esm/utilities/generateVolumePropsFromImageIds.js +5 -4
  32. package/dist/esm/utilities/generateVolumePropsFromImageIds.js.map +1 -1
  33. package/dist/esm/utilities/hasFloatScalingParameters.js +5 -0
  34. package/dist/esm/utilities/hasFloatScalingParameters.js.map +1 -0
  35. package/dist/esm/utilities/index.js +2 -1
  36. package/dist/esm/utilities/index.js.map +1 -1
  37. package/dist/esm/utilities/loadImageToCanvas.js +4 -2
  38. package/dist/esm/utilities/loadImageToCanvas.js.map +1 -1
  39. package/dist/types/RenderingEngine/StackViewport.d.ts +1 -0
  40. package/dist/types/RenderingEngine/StackViewport.d.ts.map +1 -1
  41. package/dist/types/RenderingEngine/helpers/setDefaultVolumeVOI.d.ts.map +1 -1
  42. package/dist/types/index.d.ts +2 -2
  43. package/dist/types/index.d.ts.map +1 -1
  44. package/dist/types/init.d.ts +2 -1
  45. package/dist/types/init.d.ts.map +1 -1
  46. package/dist/types/types/Cornerstone3DConfig.d.ts +1 -0
  47. package/dist/types/types/Cornerstone3DConfig.d.ts.map +1 -1
  48. package/dist/types/utilities/generateVolumePropsFromImageIds.d.ts.map +1 -1
  49. package/dist/types/utilities/hasFloatScalingParameters.d.ts +3 -0
  50. package/dist/types/utilities/hasFloatScalingParameters.d.ts.map +1 -0
  51. package/dist/types/utilities/index.d.ts +2 -1
  52. package/dist/types/utilities/index.d.ts.map +1 -1
  53. package/dist/types/utilities/loadImageToCanvas.d.ts.map +1 -1
  54. package/dist/umd/index.js +1 -1
  55. package/dist/umd/index.js.map +1 -1
  56. package/package.json +2 -2
  57. package/src/RenderingEngine/StackViewport.ts +1 -0
  58. package/src/RenderingEngine/helpers/setDefaultVolumeVOI.ts +1 -0
  59. package/src/index.ts +2 -0
  60. package/src/init.ts +65 -16
  61. package/src/types/Cornerstone3DConfig.ts +5 -0
  62. package/src/utilities/generateVolumePropsFromImageIds.ts +9 -5
  63. package/src/utilities/hasFloatScalingParameters.ts +15 -0
  64. package/src/utilities/index.ts +2 -0
  65. package/src/utilities/loadImageToCanvas.ts +5 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cornerstonejs/core",
3
- "version": "1.70.7",
3
+ "version": "1.70.8",
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": "4b6774d20ea66e2fa2815edc042b57565b816959"
50
+ "gitHead": "5a76e12669c559dbfae16854f17687f6705d6397"
51
51
  }
@@ -2064,6 +2064,7 @@ class StackViewport extends Viewport implements IStackViewport, IImagesLoader {
2064
2064
  },
2065
2065
  useRGBA: false,
2066
2066
  transferSyntaxUID,
2067
+ useNativeDataType: this.useNativeDataType,
2067
2068
  priority: 5,
2068
2069
  requestType: RequestType.Interaction,
2069
2070
  additionalDetails,
@@ -166,6 +166,7 @@ async function getVOIFromMinMax(
166
166
  },
167
167
  priority: PRIORITY,
168
168
  requestType: REQUEST_TYPE,
169
+ useNativeDataType,
169
170
  preScale: {
170
171
  enabled: true,
171
172
  scalingParameters: scalingParametersToUse,
package/src/index.ts CHANGED
@@ -42,6 +42,7 @@ import {
42
42
  getConfiguration,
43
43
  setConfiguration,
44
44
  getWebWorkerManager,
45
+ canRenderFloatTextures,
45
46
  } from './init';
46
47
 
47
48
  // Classes
@@ -89,6 +90,7 @@ export {
89
90
  getConfiguration,
90
91
  setConfiguration,
91
92
  getWebWorkerManager,
93
+ canRenderFloatTextures,
92
94
  // enums
93
95
  Enums,
94
96
  CONSTANTS,
package/src/init.ts CHANGED
@@ -13,11 +13,12 @@ import CentralizedWebWorkerManager from './webWorkerManager/webWorkerManager';
13
13
  const defaultConfig: Cornerstone3DConfig = {
14
14
  gpuTier: undefined,
15
15
  detectGPUConfig: {},
16
+ isMobile: false, // is mobile device
16
17
  rendering: {
17
18
  useCPURendering: false,
18
19
  // GPU rendering options
19
20
  preferSizeOverAccuracy: false,
20
- useNorm16Texture: false, // _hasNorm16TextureSupport(),
21
+ useNorm16Texture: false,
21
22
  strictZSpacingForVolumeViewport: true,
22
23
  },
23
24
  // cache
@@ -27,11 +28,12 @@ const defaultConfig: Cornerstone3DConfig = {
27
28
  let config: Cornerstone3DConfig = {
28
29
  gpuTier: undefined,
29
30
  detectGPUConfig: {},
31
+ isMobile: false, // is mobile device
30
32
  rendering: {
31
33
  useCPURendering: false,
32
34
  // GPU rendering options
33
35
  preferSizeOverAccuracy: false,
34
- useNorm16Texture: false, // _hasNorm16TextureSupport(),
36
+ useNorm16Texture: false,
35
37
  strictZSpacingForVolumeViewport: true,
36
38
  },
37
39
  // cache
@@ -77,23 +79,32 @@ function hasSharedArrayBuffer() {
77
79
  }
78
80
  }
79
81
 
80
- // Todo: commenting this out until proper support for int16 textures
81
- // are added to browsers, current implementation is buggy
82
- // function _hasNorm16TextureSupport() {
83
- // const gl = _getGLContext();
82
+ function _hasNorm16TextureSupport() {
83
+ const gl = _getGLContext();
84
+
85
+ if (gl) {
86
+ const ext = (gl as WebGL2RenderingContext).getExtension(
87
+ 'EXT_texture_norm16'
88
+ );
89
+
90
+ if (ext) {
91
+ return true;
92
+ }
93
+ }
84
94
 
85
- // if (gl) {
86
- // const ext = (gl as WebGL2RenderingContext).getExtension(
87
- // 'EXT_texture_norm16'
88
- // );
95
+ return false;
96
+ }
89
97
 
90
- // if (ext) {
91
- // return true;
92
- // }
93
- // }
98
+ function isMobile() {
99
+ const ua = navigator.userAgent;
100
+ return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
101
+ ua
102
+ );
103
+ }
94
104
 
95
- // return false;
96
- // }
105
+ function isMobileIOS() {
106
+ return /iPhone|iPod/.test(navigator.platform);
107
+ }
97
108
 
98
109
  /**
99
110
  * Initialize the cornerstone-core. If the browser has a webgl context and
@@ -112,6 +123,26 @@ async function init(configuration = config): Promise<boolean> {
112
123
  // merge configs
113
124
  config = deepMerge(defaultConfig, configuration);
114
125
 
126
+ config.isMobile = isMobile();
127
+
128
+ if (config.isMobile) {
129
+ // iOS devices don't have support for OES_texture_float_linear
130
+ // and thus we should use native data type if we are on iOS
131
+ if (isMobileIOS()) {
132
+ config.rendering.useNorm16Texture = _hasNorm16TextureSupport();
133
+
134
+ if (!config.rendering.useNorm16Texture) {
135
+ if (configuration.rendering?.preferSizeOverAccuracy) {
136
+ config.rendering.preferSizeOverAccuracy = true;
137
+ } else {
138
+ console.log(
139
+ 'norm16 texture not supported, you can turn on the preferSizeOverAccuracy flag to use native data type, but be aware of the inaccuracy of the rendering in high bits'
140
+ );
141
+ }
142
+ }
143
+ }
144
+ }
145
+
115
146
  // gpuTier
116
147
  const hasWebGLContext = _hasActiveWebGLContext();
117
148
  if (!hasWebGLContext) {
@@ -165,6 +196,23 @@ function setPreferSizeOverAccuracy(status: boolean): void {
165
196
  _updateRenderingPipelinesForAllViewports();
166
197
  }
167
198
 
199
+ /**
200
+ * Only IPhone IOS cannot render float textures right now due to the lack of support for OES_texture_float_linear.
201
+ * So we should not use float textures on IOS devices.
202
+ */
203
+ function canRenderFloatTextures(): boolean {
204
+ const isMobile = config.isMobile;
205
+ if (!isMobile) {
206
+ return true;
207
+ }
208
+
209
+ if (isMobileIOS()) {
210
+ return false;
211
+ }
212
+
213
+ return true;
214
+ }
215
+
168
216
  /**
169
217
  * Resets the cornerstone-core init state if it has been manually
170
218
  * initialized to force use the cpu rendering (e.g., for tests)
@@ -286,4 +334,5 @@ export {
286
334
  getConfiguration,
287
335
  setConfiguration,
288
336
  getWebWorkerManager,
337
+ canRenderFloatTextures,
289
338
  };
@@ -8,6 +8,11 @@ type Cornerstone3DConfig = {
8
8
  * https://github.com/pmndrs/detect-gpu/blob/master/src/index.ts#L82
9
9
  */
10
10
  gpuTier?: TierResult;
11
+
12
+ /**
13
+ * Whether the device is mobile or not.
14
+ */
15
+ isMobile: boolean;
11
16
  /**
12
17
  * When the `gpuTier` is not provided, the `detectGPUConfig` is passed as
13
18
  * an argument to the `getGPUTier` method.
@@ -1,5 +1,9 @@
1
1
  import { vec3 } from 'gl-matrix';
2
- import { getConfiguration, getShouldUseSharedArrayBuffer } from '../init';
2
+ import {
3
+ canRenderFloatTextures,
4
+ getConfiguration,
5
+ getShouldUseSharedArrayBuffer,
6
+ } from '../init';
3
7
  import createFloat32SharedArray from './createFloat32SharedArray';
4
8
  import createInt16SharedArray from './createInt16SharedArray';
5
9
  import createUint16SharedArray from './createUInt16SharedArray';
@@ -7,6 +11,7 @@ import createUint8SharedArray from './createUint8SharedArray';
7
11
  import getScalingParameters from './getScalingParameters';
8
12
  import makeVolumeMetadata from './makeVolumeMetadata';
9
13
  import sortImageIdsAndGetSpacing from './sortImageIdsAndGetSpacing';
14
+ import { hasFloatScalingParameters } from './hasFloatScalingParameters';
10
15
  import { ImageVolumeProps, Mat3, Point3 } from '../types';
11
16
  import cache from '../cache';
12
17
  import { Events } from '../enums';
@@ -36,9 +41,8 @@ function generateVolumePropsFromImageIds(
36
41
 
37
42
  // The prescale is ALWAYS used with modality LUT, so we can assume that
38
43
  // if the rescale slope is not an integer, we need to use Float32
39
- const hasFloatRescale =
40
- scalingParameters.rescaleIntercept % 1 !== 0 ||
41
- scalingParameters.rescaleSlope % 1 !== 0;
44
+ const floatAfterScale = hasFloatScalingParameters(scalingParameters);
45
+ const canRenderFloat = canRenderFloatTextures();
42
46
 
43
47
  const {
44
48
  BitsAllocated,
@@ -110,7 +114,7 @@ function generateVolumePropsFromImageIds(
110
114
  // Temporary fix for 16 bit images to use Float32
111
115
  // until the new dicom image loader handler the conversion
112
116
  // correctly
113
- if (!use16BitDataType || hasFloatRescale) {
117
+ if (!use16BitDataType || (canRenderFloat && floatAfterScale)) {
114
118
  sizeInBytes = length * 4;
115
119
  scalarData = useSharedArrayBuffer
116
120
  ? createFloat32SharedArray(length)
@@ -0,0 +1,15 @@
1
+ import { ScalingParameters } from '../types';
2
+
3
+ /**
4
+ * Checks if the scaling parameters contain a float rescale value.
5
+ * @param scalingParameters - The scaling parameters to check.
6
+ * @returns True if the scaling parameters contain a float rescale value, false otherwise.
7
+ */
8
+ export const hasFloatScalingParameters = (
9
+ scalingParameters: ScalingParameters
10
+ ): boolean => {
11
+ const hasFloatRescale = Object.values(scalingParameters).some(
12
+ (value) => typeof value === 'number' && !Number.isInteger(value)
13
+ );
14
+ return hasFloatRescale;
15
+ };
@@ -71,6 +71,7 @@ import convertToGrayscale from './convertToGrayscale';
71
71
  import getViewportImageIds from './getViewportImageIds';
72
72
  import { getRandomSampleFromArray } from './getRandomSampleFromArray';
73
73
  import { getVolumeId } from './getVolumeId';
74
+ import { hasFloatScalingParameters } from './hasFloatScalingParameters';
74
75
 
75
76
  // name spaces
76
77
  import * as planar from './planar';
@@ -162,4 +163,5 @@ export {
162
163
  getRandomSampleFromArray,
163
164
  getVolumeId,
164
165
  color,
166
+ hasFloatScalingParameters,
165
167
  };
@@ -113,17 +113,20 @@ export default function loadImageToCanvas(
113
113
  );
114
114
  }
115
115
 
116
- const { useNorm16Texture } = getConfiguration().rendering;
116
+ const { useNorm16Texture, preferSizeOverAccuracy } =
117
+ getConfiguration().rendering;
118
+ const useNativeDataType = useNorm16Texture || preferSizeOverAccuracy;
117
119
 
118
120
  // IMPORTANT: Request type should be passed if not the 'interaction'
119
121
  // highest priority will be used for the request type in the imageRetrievalPool
120
122
  const options = {
121
123
  targetBuffer: {
122
- type: useNorm16Texture ? undefined : 'Float32Array',
124
+ type: useNativeDataType ? undefined : 'Float32Array',
123
125
  },
124
126
  preScale: {
125
127
  enabled: true,
126
128
  },
129
+ useNativeDataType,
127
130
  useRGBA: !!useCPURendering,
128
131
  requestType,
129
132
  };