@kitware/vtk.js 27.1.0 → 27.1.1

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.
@@ -222,7 +222,7 @@ function vtkOpenGLImageResliceMapper(publicAPI, model) {
222
222
  model.openGLTexture.getOglNorm16Ext(model.context.getExtension('EXT_texture_norm16'));
223
223
  model.openGLTexture.releaseGraphicsResources(model._openGLRenderWindow);
224
224
  model.openGLTexture.resetFormatAndType();
225
- model.openGLTexture.create3DFilterableFromRaw(dims[0], dims[1], dims[2], numComp, scalars.getDataType(), scalars.getData());
225
+ model.openGLTexture.create3DFilterableFromDataArray(dims[0], dims[1], dims[2], scalars);
226
226
  model.openGLTextureString = _toString;
227
227
  }
228
228
  }
@@ -1,8 +1,9 @@
1
1
  import _defineProperty from '@babel/runtime/helpers/defineProperty';
2
+ import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
2
3
  import Constants from './Texture/Constants.js';
3
4
  import HalfFloat from '../../Common/Core/HalfFloat.js';
4
5
  import { newInstance as newInstance$1, obj, set, setGet, get, moveToProtected, newTypedArray, vtkDebugMacro as vtkDebugMacro$1, vtkErrorMacro as vtkErrorMacro$1, vtkWarningMacro as vtkWarningMacro$1 } from '../../macros.js';
5
- import vtkDataArray, { STATIC } from '../../Common/Core/DataArray.js';
6
+ import vtkDataArray from '../../Common/Core/DataArray.js';
6
7
  import { Q as isPowerOfTwo, M as nearestPowerOfTwo } from '../../Common/Core/Math/index.js';
7
8
  import vtkViewNode from '../SceneGraph/ViewNode.js';
8
9
  import { registerOverride } from './ViewNodeFactory.js';
@@ -1005,29 +1006,16 @@ function vtkOpenGLTexture(publicAPI, model) {
1005
1006
 
1006
1007
  publicAPI.deactivate();
1007
1008
  return true;
1008
- };
1009
+ }; // Compute scale and offset per component from min and max per component
1009
1010
 
1010
- function computeScaleOffsets(numComps, numPixelsIn, data) {
1011
- // compute min and max values per component
1012
- var min = [];
1013
- var max = [];
1014
1011
 
1015
- for (var c = 0; c < numComps; ++c) {
1016
- var range = STATIC.fastComputeRange(data, c, numComps);
1017
- min[c] = range.min;
1018
- max[c] = range.max;
1019
- }
1012
+ function computeScaleOffsets(min, max, numComps) {
1013
+ var offset = new Array(numComps);
1014
+ var scale = new Array(numComps);
1020
1015
 
1021
- var offset = [];
1022
- var scale = [];
1023
-
1024
- for (var _c = 0; _c < numComps; ++_c) {
1025
- if (min[_c] === max[_c]) {
1026
- max[_c] = min[_c] + 1.0;
1027
- }
1028
-
1029
- offset[_c] = min[_c];
1030
- scale[_c] = max[_c] - min[_c];
1016
+ for (var c = 0; c < numComps; ++c) {
1017
+ offset[c] = min[c];
1018
+ scale[c] = max[c] - min[c] || 1.0;
1031
1019
  }
1032
1020
 
1033
1021
  return {
@@ -1127,18 +1115,53 @@ function vtkOpenGLTexture(publicAPI, model) {
1127
1115
  return true;
1128
1116
  }; //----------------------------------------------------------------------------
1129
1117
  // This method simulates a 3D texture using 2D
1118
+ // Prefer create3DFilterableFromDataArray to enable caching of min and max values
1130
1119
 
1131
1120
 
1132
- publicAPI.create3DFilterableFromRaw = function (width, height, depth, numComps, dataType, data) {
1121
+ publicAPI.create3DFilterableFromRaw = function (width, height, depth, numberOfComponents, dataType, values) {
1133
1122
  var preferSizeOverAccuracy = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : false;
1134
- var numPixelsIn = width * height * depth; // initialize offset/scale
1123
+ return publicAPI.create3DFilterableFromDataArray(width, height, depth, vtkDataArray.newInstance({
1124
+ numberOfComponents: numberOfComponents,
1125
+ dataType: dataType,
1126
+ values: values
1127
+ }), preferSizeOverAccuracy);
1128
+ }; //----------------------------------------------------------------------------
1129
+ // This method create a 3D texture from dimensions and a DataArray
1130
+
1131
+
1132
+ publicAPI.create3DFilterableFromDataArray = function (width, height, depth, dataArray) {
1133
+ var preferSizeOverAccuracy = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
1134
+ var numComps = dataArray.getNumberOfComponents();
1135
+ var dataType = dataArray.getDataType();
1136
+ var data = dataArray.getData();
1137
+ var numPixelsIn = width * height * depth; // Compute min max from array
1138
+ // Using the vtkDataArray.getRange() enables caching
1139
+
1140
+ var minArray = new Array(numComps);
1141
+ var maxArray = new Array(numComps);
1142
+
1143
+ for (var c = 0; c < numComps; ++c) {
1144
+ var _dataArray$getRange = dataArray.getRange(c),
1145
+ _dataArray$getRange2 = _slicedToArray(_dataArray$getRange, 2),
1146
+ min = _dataArray$getRange2[0],
1147
+ max = _dataArray$getRange2[1];
1148
+
1149
+ minArray[c] = min;
1150
+ maxArray[c] = max;
1151
+ }
1152
+
1153
+ var scaleOffsets = computeScaleOffsets(minArray, maxArray, numComps); // Create a copy of scale and offset to avoid aliasing issues
1154
+ // Original is read only, copy is read/write
1155
+ // Use the copy as volumeInfo.scale and volumeInfo.offset
1156
+
1157
+ var scaleOffsetsCopy = structuredClone(scaleOffsets); // initialize offset/scale
1135
1158
 
1136
1159
  var offset = [];
1137
1160
  var scale = [];
1138
1161
 
1139
- for (var c = 0; c < numComps; ++c) {
1140
- offset[c] = 0.0;
1141
- scale[c] = 1.0;
1162
+ for (var _c = 0; _c < numComps; ++_c) {
1163
+ offset[_c] = 0.0;
1164
+ scale[_c] = 1.0;
1142
1165
  } // store the information, we will need it later
1143
1166
  // offset and scale are the offset and scale required to get
1144
1167
  // the texture value back to data values ala
@@ -1149,21 +1172,15 @@ function vtkOpenGLTexture(publicAPI, model) {
1149
1172
  model.volumeInfo = {
1150
1173
  scale: scale,
1151
1174
  offset: offset,
1175
+ dataComputedScale: scaleOffsets.scale,
1176
+ dataComputedOffset: scaleOffsets.offset,
1152
1177
  width: width,
1153
1178
  height: height,
1154
1179
  depth: depth
1155
- }; // Check if we can accurately use halfFloat or whether it is preferred to have a smaller size texture
1156
- // compute min and max values
1157
-
1158
- var _computeScaleOffsets = computeScaleOffsets(numComps, numPixelsIn, data),
1159
- computedOffset = _computeScaleOffsets.offset,
1160
- computedScale = _computeScaleOffsets.scale;
1161
-
1162
- model.volumeInfo.dataComputedScale = computedScale;
1163
- model.volumeInfo.dataComputedOffset = computedOffset; // preferSizeOverAccuracy will override norm16 due to bug with norm16 implementation
1180
+ }; // preferSizeOverAccuracy will override norm16 due to bug with norm16 implementation
1164
1181
  // https://bugs.chromium.org/p/chromium/issues/detail?id=1408247
1165
1182
 
1166
- model.useHalfFloat = checkUseHalfFloat(dataType, computedOffset, computedScale, preferSizeOverAccuracy); // since our default is to use half float, in case that we can't use it
1183
+ model.useHalfFloat = checkUseHalfFloat(dataType, scaleOffsets.offset, scaleOffsets.scale, preferSizeOverAccuracy); // since our default is to use half float, in case that we can't use it
1167
1184
  // we need to use another type
1168
1185
 
1169
1186
  if (!model.useHalfFloat) {
@@ -1201,19 +1218,19 @@ function vtkOpenGLTexture(publicAPI, model) {
1201
1218
  } // otherwise convert to float
1202
1219
 
1203
1220
 
1204
- var _newArray = new Float32Array(numPixelsIn * numComps); // compute min and max values
1221
+ var _newArray = new Float32Array(numPixelsIn * numComps); // use computed scale and offset
1205
1222
 
1206
1223
 
1207
- model.volumeInfo.offset = computedOffset;
1208
- model.volumeInfo.scale = computedScale;
1224
+ model.volumeInfo.offset = scaleOffsetsCopy.offset;
1225
+ model.volumeInfo.scale = scaleOffsetsCopy.scale;
1209
1226
  var count = 0;
1210
- var scaleInverse = computedScale.map(function (s) {
1227
+ var scaleInverse = scaleOffsetsCopy.scale.map(function (s) {
1211
1228
  return 1 / s;
1212
1229
  });
1213
1230
 
1214
1231
  for (var i = 0; i < numPixelsIn; i++) {
1215
1232
  for (var nc = 0; nc < numComps; nc++) {
1216
- _newArray[count] = (data[count] - computedOffset[nc]) * scaleInverse[nc];
1233
+ _newArray[count] = (data[count] - scaleOffsetsCopy.offset[nc]) * scaleInverse[nc];
1217
1234
  count++;
1218
1235
  }
1219
1236
  }
@@ -1221,10 +1238,7 @@ function vtkOpenGLTexture(publicAPI, model) {
1221
1238
  return publicAPI.create3DFromRaw(width, height, depth, numComps, VtkDataTypes.FLOAT, _newArray);
1222
1239
  } // not webgl2, deal with webgl1, no 3d textures
1223
1240
  // and maybe no float textures
1224
- // compute min and max values
1225
-
1226
1241
 
1227
- var res = computeScaleOffsets(numComps, numPixelsIn, data);
1228
1242
 
1229
1243
  var volCopyData = function volCopyData(outArray, outIdx, inValue, smin, smax) {
1230
1244
  outArray[outIdx] = inValue;
@@ -1234,8 +1248,8 @@ function vtkOpenGLTexture(publicAPI, model) {
1234
1248
 
1235
1249
  if (dataType === VtkDataTypes.UNSIGNED_CHAR) {
1236
1250
  for (var _c5 = 0; _c5 < numComps; ++_c5) {
1237
- res.offset[_c5] = 0.0;
1238
- res.scale[_c5] = 255.0;
1251
+ scaleOffsetsCopy.offset[_c5] = 0.0;
1252
+ scaleOffsetsCopy.scale[_c5] = 255.0;
1239
1253
  }
1240
1254
  } else if (model.context.getExtension('OES_texture_float') && model.context.getExtension('OES_texture_float_linear')) {
1241
1255
  // use float textures scaled to 0.0 to 1.0
@@ -1310,8 +1324,8 @@ function vtkOpenGLTexture(publicAPI, model) {
1310
1324
  model.volumeInfo.yreps = yreps;
1311
1325
  model.volumeInfo.xstride = xstride;
1312
1326
  model.volumeInfo.ystride = ystride;
1313
- model.volumeInfo.offset = res.offset;
1314
- model.volumeInfo.scale = res.scale; // OK stuff the data into the 2d TEXTURE
1327
+ model.volumeInfo.offset = scaleOffsetsCopy.offset;
1328
+ model.volumeInfo.scale = scaleOffsetsCopy.scale; // OK stuff the data into the 2d TEXTURE
1315
1329
  // first allocate the new texture
1316
1330
 
1317
1331
  var newArray;
@@ -1340,7 +1354,7 @@ function vtkOpenGLTexture(publicAPI, model) {
1340
1354
  for (var tileX = 0; tileX < tileWidth; tileX++) {
1341
1355
  // copy value
1342
1356
  for (var _nc = 0; _nc < numComps; _nc++) {
1343
- volCopyData(newArray, outIdx, data[inOffset + xstride * tileX * numComps + _nc], res.offset[_nc], res.scale[_nc]);
1357
+ volCopyData(newArray, outIdx, data[inOffset + xstride * tileX * numComps + _nc], scaleOffsetsCopy.offset[_nc], scaleOffsetsCopy.scale[_nc]);
1344
1358
  outIdx++;
1345
1359
  }
1346
1360
  }
@@ -1127,7 +1127,7 @@ function vtkOpenGLVolumeMapper(publicAPI, model) {
1127
1127
  model.scalarTexture.setOglNorm16Ext(model.context.getExtension('EXT_texture_norm16'));
1128
1128
  model.scalarTexture.releaseGraphicsResources(model._openGLRenderWindow);
1129
1129
  model.scalarTexture.resetFormatAndType();
1130
- model.scalarTexture.create3DFilterableFromRaw(dims[0], dims[1], dims[2], numComp, scalars.getDataType(), scalars.getData(), model.renderable.getPreferSizeOverAccuracy());
1130
+ model.scalarTexture.create3DFilterableFromDataArray(dims[0], dims[1], dims[2], scalars, model.renderable.getPreferSizeOverAccuracy());
1131
1131
  model.scalarTextureString = toString;
1132
1132
  }
1133
1133
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kitware/vtk.js",
3
- "version": "27.1.0",
3
+ "version": "27.1.1",
4
4
  "description": "Visualization Toolkit for the Web",
5
5
  "keywords": [
6
6
  "3d",