@cornerstonejs/core 2.2.15 → 2.2.17

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.
@@ -2,6 +2,12 @@ import macro from '@kitware/vtk.js/macros';
2
2
  import vtkOpenGLTexture from '@kitware/vtk.js/Rendering/OpenGL/Texture';
3
3
  import cache from '../../cache/cache';
4
4
  import { getConstructorFromType } from '../../utilities/getBufferConfiguration';
5
+ function convertDataType(data, targetDataType) {
6
+ const Constructor = getConstructorFromType(targetDataType);
7
+ const convertedData = new Constructor(data.length);
8
+ convertedData.set(data);
9
+ return convertedData;
10
+ }
5
11
  function vtkStreamingOpenGLTexture(publicAPI, model) {
6
12
  model.classHierarchy.push('vtkStreamingOpenGLTexture');
7
13
  model.updatedFrames = [];
@@ -52,10 +58,14 @@ function vtkStreamingOpenGLTexture(publicAPI, model) {
52
58
  if (!image) {
53
59
  continue;
54
60
  }
55
- const data = image.voxelManager.getScalarData();
61
+ let data = image.voxelManager.getScalarData();
56
62
  const gl = model.context;
57
- const dataType = data.constructor.name;
58
- const [pixData] = publicAPI.updateArrayDataTypeForGL(dataType, [data]);
63
+ if (volume.dataType !== data.constructor.name) {
64
+ data = convertDataType(data, volume.dataType);
65
+ }
66
+ const [pixData] = publicAPI.updateArrayDataTypeForGL(volume.dataType, [
67
+ data,
68
+ ]);
59
69
  publicAPI.bind();
60
70
  const zOffset = i;
61
71
  gl.texSubImage3D(model.target, 0, 0, 0, zOffset, model.width, model.height, 1, model.format, model.openGLDataType, pixData);
@@ -89,8 +99,12 @@ function vtkStreamingOpenGLTexture(publicAPI, model) {
89
99
  constructor = data.constructor;
90
100
  }
91
101
  const gl = model.context;
92
- const dataType = data.constructor.name;
93
- const [pixData] = publicAPI.updateArrayDataTypeForGL(dataType, [data]);
102
+ if (volume.dataType !== data.constructor.name) {
103
+ data = convertDataType(data, volume.dataType);
104
+ }
105
+ const [pixData] = publicAPI.updateArrayDataTypeForGL(volume.dataType, [
106
+ data,
107
+ ]);
94
108
  publicAPI.bind();
95
109
  let zOffset = i;
96
110
  gl.texSubImage3D(model.target, 0, 0, 0, zOffset, model.width, model.height, 1, model.format, model.openGLDataType, pixData);
@@ -4,6 +4,13 @@ import sortImageIdsAndGetSpacing from './sortImageIdsAndGetSpacing';
4
4
  import getScalingParameters from './getScalingParameters';
5
5
  import { hasFloatScalingParameters } from './hasFloatScalingParameters';
6
6
  import { canRenderFloatTextures } from '../init';
7
+ import cache from '../cache/cache';
8
+ const constructorToTypedArray = {
9
+ Uint8Array: 'Uint8Array',
10
+ Int16Array: 'Int16Array',
11
+ Uint16Array: 'Uint16Array',
12
+ Float32Array: 'Float32Array',
13
+ };
7
14
  function generateVolumePropsFromImageIds(imageIds, volumeId) {
8
15
  const volumeMetadata = makeVolumeMetadata(imageIds);
9
16
  const { ImageOrientationPatient, PixelSpacing, Columns, Rows } = volumeMetadata;
@@ -36,6 +43,10 @@ function generateVolumePropsFromImageIds(imageIds, volumeId) {
36
43
  function _determineDataType(imageIds, volumeMetadata) {
37
44
  const { BitsAllocated, PixelRepresentation } = volumeMetadata;
38
45
  const signed = PixelRepresentation === 1;
46
+ const cachedDataType = _getDataTypeFromCache(imageIds);
47
+ if (cachedDataType) {
48
+ return cachedDataType;
49
+ }
39
50
  const [firstIndex, middleIndex, lastIndex] = [
40
51
  0,
41
52
  Math.floor(imageIds.length / 2),
@@ -70,4 +81,17 @@ function _determineDataType(imageIds, volumeMetadata) {
70
81
  throw new Error(`Bits allocated of ${BitsAllocated} is not defined to generate scalarData for the volume.`);
71
82
  }
72
83
  }
84
+ function _getDataTypeFromCache(imageIds) {
85
+ const indices = [0, Math.floor(imageIds.length / 2), imageIds.length - 1];
86
+ const images = indices.map((i) => cache.getImage(imageIds[i]));
87
+ if (!images.every(Boolean)) {
88
+ return null;
89
+ }
90
+ const constructorName = images[0].getPixelData().constructor.name;
91
+ if (images.every((img) => img.getPixelData().constructor.name === constructorName) &&
92
+ constructorName in constructorToTypedArray) {
93
+ return constructorToTypedArray[constructorName];
94
+ }
95
+ return null;
96
+ }
73
97
  export { generateVolumePropsFromImageIds };
@@ -1,5 +1,8 @@
1
1
  export default function getViewportImageCornersInWorld(viewport) {
2
- const { imageData, dimensions } = viewport.getImageData();
2
+ const { imageData, dimensions } = viewport.getImageData() || {};
3
+ if (!imageData || !dimensions) {
4
+ return [];
5
+ }
3
6
  const { canvas } = viewport;
4
7
  const ratio = window.devicePixelRatio;
5
8
  const topLeftCanvas = [0, 0];
@@ -2,6 +2,8 @@ declare const imageRetrieveMetadataProvider: {
2
2
  IMAGE_RETRIEVE_CONFIGURATION: string;
3
3
  clear: () => void;
4
4
  add: (key: string, payload: any) => void;
5
+ clone: () => Map<string, unknown>;
6
+ restore: (state: Map<string, unknown>) => void;
5
7
  get: (type: string, ...queries: string[]) => unknown;
6
8
  };
7
9
  export default imageRetrieveMetadataProvider;
@@ -9,6 +9,15 @@ const imageRetrieveMetadataProvider = {
9
9
  add: (key, payload) => {
10
10
  retrieveConfigurationState.set(key, payload);
11
11
  },
12
+ clone: () => {
13
+ return new Map(retrieveConfigurationState);
14
+ },
15
+ restore: (state) => {
16
+ retrieveConfigurationState.clear();
17
+ state.forEach((value, key) => {
18
+ retrieveConfigurationState.set(key, value);
19
+ });
20
+ },
12
21
  get: (type, ...queries) => {
13
22
  if (type === IMAGE_RETRIEVE_CONFIGURATION) {
14
23
  return queries
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cornerstonejs/core",
3
- "version": "2.2.15",
3
+ "version": "2.2.17",
4
4
  "description": "",
5
5
  "module": "./dist/esm/index.js",
6
6
  "types": "./dist/esm/index.d.ts",
@@ -83,5 +83,5 @@
83
83
  "type": "individual",
84
84
  "url": "https://ohif.org/donate"
85
85
  },
86
- "gitHead": "8ced02a99bf153c9d268449db47f5abfe4a557b3"
86
+ "gitHead": "5652ca06035e63a5d19be9cfe711afc38c67e6b2"
87
87
  }