@kitware/vtk.js 27.1.2 → 27.2.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.
@@ -356,7 +356,9 @@ var DEFAULT_VALUES = {
356
356
  flip: false
357
357
  },
358
358
  renderToRectangle: false,
359
- sliceAtFocalPoint: false
359
+ sliceAtFocalPoint: false,
360
+ preferSizeOverAccuracy: false // Whether to use halfFloat representation of float, when it is inaccurate
361
+
360
362
  }; // ----------------------------------------------------------------------------
361
363
 
362
364
  function extend(publicAPI, model) {
@@ -365,7 +367,7 @@ function extend(publicAPI, model) {
365
367
 
366
368
  vtkAbstractImageMapper.extend(publicAPI, model, initialValues);
367
369
  macro.get(publicAPI, model, ['slicingMode']);
368
- macro.setGet(publicAPI, model, ['closestIJKAxis', 'renderToRectangle', 'sliceAtFocalPoint']);
370
+ macro.setGet(publicAPI, model, ['closestIJKAxis', 'renderToRectangle', 'sliceAtFocalPoint', 'preferSizeOverAccuracy']);
369
371
  CoincidentTopologyHelper.implementCoincidentTopologyMethods(publicAPI, model); // Object methods
370
372
 
371
373
  vtkImageMapper(publicAPI, model);
@@ -688,9 +688,11 @@ function vtkOpenGLImageMapper(publicAPI, model) {
688
688
  } // rebuild the VBO if the data has changed
689
689
 
690
690
 
691
- var toString = "".concat(slice, "A").concat(image.getMTime(), "A").concat(imgScalars.getMTime(), "B").concat(publicAPI.getMTime(), "C").concat(model.renderable.getSlicingMode(), "D").concat(actor.getProperty().getMTime());
691
+ var toString = "".concat(slice, "A").concat(image.getMTime(), "A").concat(imgScalars.getMTime(), "B").concat(publicAPI.getMTime(), "C").concat(model.renderable.getSlicingMode(), "D").concat(actor.getProperty().getInterpolationType());
692
692
 
693
693
  if (model.VBOBuildString !== toString) {
694
+ var _model$renderable$get2, _model$renderable;
695
+
694
696
  // Build the VBOs
695
697
  var dims = image.getDimensions();
696
698
 
@@ -803,7 +805,7 @@ function vtkOpenGLImageMapper(publicAPI, model) {
803
805
  vtkErrorMacro('Reformat slicing not yet supported.');
804
806
  }
805
807
 
806
- model.openGLTexture.create2DFromRaw(dims[0], dims[1], numComp, imgScalars.getDataType(), scalars);
808
+ model.openGLTexture.create2DFilterableFromRaw(dims[0], dims[1], numComp, imgScalars.getDataType(), scalars, (_model$renderable$get2 = (_model$renderable = model.renderable).getPreferSizeOverAccuracy) === null || _model$renderable$get2 === void 0 ? void 0 : _model$renderable$get2.call(_model$renderable));
807
809
  model.openGLTexture.activate();
808
810
  model.openGLTexture.sendParameters();
809
811
  model.openGLTexture.deactivate();
@@ -1040,7 +1040,7 @@ function vtkOpenGLTexture(publicAPI, model) {
1040
1040
  return true;
1041
1041
  }
1042
1042
 
1043
- function checkUseHalfFloat(dataType, offset, scale, preferSizeOverAccuracy) {
1043
+ function setUseHalfFloat(dataType, offset, scale, preferSizeOverAccuracy) {
1044
1044
  publicAPI.getOpenGLDataType(dataType);
1045
1045
  var useHalfFloat = false;
1046
1046
 
@@ -1049,20 +1049,70 @@ function vtkOpenGLTexture(publicAPI, model) {
1049
1049
  } else {
1050
1050
  var halfFloatExt = model.context.getExtension('OES_texture_half_float');
1051
1051
  useHalfFloat = halfFloatExt && model.openGLDataType === halfFloatExt.HALF_FLOAT_OES;
1052
- }
1053
-
1054
- if (!useHalfFloat) {
1055
- return false;
1056
1052
  } // Don't consider halfFloat and convert back to Float when the range of data does not generate an accurate halfFloat
1057
1053
  // AND it is not preferable to have a smaller texture than an exact texture.
1058
1054
 
1059
1055
 
1060
- if (!hasExactHalfFloat(offset, scale) && !preferSizeOverAccuracy) {
1061
- return false;
1056
+ var isHalfFloat = useHalfFloat && (hasExactHalfFloat(offset, scale) || preferSizeOverAccuracy);
1057
+ model.useHalfFloat = isHalfFloat;
1058
+ }
1059
+
1060
+ function processDataArray(dataArray, preferSizeOverAccuracy) {
1061
+ var numComps = dataArray.getNumberOfComponents();
1062
+ var dataType = dataArray.getDataType();
1063
+ var data = dataArray.getData(); // Compute min max from array
1064
+ // Using the vtkDataArray.getRange() enables caching
1065
+
1066
+ var minArray = new Array(numComps);
1067
+ var maxArray = new Array(numComps);
1068
+
1069
+ for (var c = 0; c < numComps; ++c) {
1070
+ var _dataArray$getRange = dataArray.getRange(c),
1071
+ _dataArray$getRange2 = _slicedToArray(_dataArray$getRange, 2),
1072
+ min = _dataArray$getRange2[0],
1073
+ max = _dataArray$getRange2[1];
1074
+
1075
+ minArray[c] = min;
1076
+ maxArray[c] = max;
1062
1077
  }
1063
1078
 
1064
- return true;
1065
- } //----------------------------------------------------------------------------
1079
+ var scaleOffsets = computeScaleOffsets(minArray, maxArray, numComps); // preferSizeOverAccuracy will override norm16 due to bug with norm16 implementation
1080
+ // https://bugs.chromium.org/p/chromium/issues/detail?id=1408247
1081
+
1082
+ setUseHalfFloat(dataType, scaleOffsets.offset, scaleOffsets.scale, preferSizeOverAccuracy); // since our default is to use half float, in case that we can't use it
1083
+ // we need to use another type
1084
+
1085
+ if (!model.useHalfFloat) {
1086
+ publicAPI.getOpenGLDataType(dataType, true);
1087
+ }
1088
+
1089
+ return {
1090
+ numComps: numComps,
1091
+ dataType: dataType,
1092
+ data: data,
1093
+ scaleOffsets: scaleOffsets
1094
+ };
1095
+ }
1096
+
1097
+ publicAPI.create2DFilterableFromRaw = function (width, height, numberOfComponents, dataType, values) {
1098
+ var preferSizeOverAccuracy = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : false;
1099
+ return publicAPI.create2DFilterableFromDataArray(width, height, vtkDataArray.newInstance({
1100
+ numberOfComponents: numberOfComponents,
1101
+ dataType: dataType,
1102
+ values: values
1103
+ }), preferSizeOverAccuracy);
1104
+ };
1105
+
1106
+ publicAPI.create2DFilterableFromDataArray = function (width, height, dataArray) {
1107
+ var preferSizeOverAccuracy = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
1108
+
1109
+ var _processDataArray = processDataArray(dataArray, preferSizeOverAccuracy),
1110
+ numComps = _processDataArray.numComps,
1111
+ dataType = _processDataArray.dataType,
1112
+ data = _processDataArray.data;
1113
+
1114
+ publicAPI.create2DFromRaw(width, height, numComps, dataType, data);
1115
+ }; //----------------------------------------------------------------------------
1066
1116
 
1067
1117
 
1068
1118
  publicAPI.create3DFromRaw = function (width, height, depth, numComps, dataType, data) {
@@ -1131,37 +1181,20 @@ function vtkOpenGLTexture(publicAPI, model) {
1131
1181
 
1132
1182
  publicAPI.create3DFilterableFromDataArray = function (width, height, depth, dataArray) {
1133
1183
  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
1184
 
1157
- var scaleOffsetsCopy = structuredClone(scaleOffsets); // initialize offset/scale
1185
+ var _processDataArray2 = processDataArray(dataArray, preferSizeOverAccuracy),
1186
+ numComps = _processDataArray2.numComps,
1187
+ dataType = _processDataArray2.dataType,
1188
+ data = _processDataArray2.data,
1189
+ scaleOffsets = _processDataArray2.scaleOffsets;
1158
1190
 
1191
+ var numPixelsIn = width * height * depth;
1159
1192
  var offset = [];
1160
1193
  var scale = [];
1161
1194
 
1162
- for (var _c = 0; _c < numComps; ++_c) {
1163
- offset[_c] = 0.0;
1164
- scale[_c] = 1.0;
1195
+ for (var c = 0; c < numComps; ++c) {
1196
+ offset[c] = 0.0;
1197
+ scale[c] = 1.0;
1165
1198
  } // store the information, we will need it later
1166
1199
  // offset and scale are the offset and scale required to get
1167
1200
  // the texture value back to data values ala
@@ -1177,29 +1210,24 @@ function vtkOpenGLTexture(publicAPI, model) {
1177
1210
  width: width,
1178
1211
  height: height,
1179
1212
  depth: depth
1180
- }; // preferSizeOverAccuracy will override norm16 due to bug with norm16 implementation
1181
- // https://bugs.chromium.org/p/chromium/issues/detail?id=1408247
1182
-
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
1184
- // we need to use another type
1185
-
1186
- if (!model.useHalfFloat) {
1187
- publicAPI.getOpenGLDataType(dataType, true);
1188
- } // WebGL2 path, we have 3d textures etc
1213
+ }; // Create a copy of scale and offset to avoid aliasing issues
1214
+ // Original is read only, copy is read/write
1215
+ // Use the copy as volumeInfo.scale and volumeInfo.offset
1189
1216
 
1217
+ var scaleOffsetsCopy = structuredClone(scaleOffsets); // WebGL2 path, we have 3d textures etc
1190
1218
 
1191
1219
  if (model._openGLRenderWindow.getWebgl2()) {
1192
1220
  if (model.oglNorm16Ext && !model.useHalfFloat && dataType === VtkDataTypes.SHORT) {
1193
- for (var _c2 = 0; _c2 < numComps; ++_c2) {
1194
- model.volumeInfo.scale[_c2] = 32767.0;
1221
+ for (var _c = 0; _c < numComps; ++_c) {
1222
+ model.volumeInfo.scale[_c] = 32767.0;
1195
1223
  }
1196
1224
 
1197
1225
  return publicAPI.create3DFromRaw(width, height, depth, numComps, dataType, data);
1198
1226
  }
1199
1227
 
1200
1228
  if (model.oglNorm16Ext && !model.useHalfFloat && dataType === VtkDataTypes.UNSIGNED_SHORT) {
1201
- for (var _c3 = 0; _c3 < numComps; ++_c3) {
1202
- model.volumeInfo.scale[_c3] = 65535.0;
1229
+ for (var _c2 = 0; _c2 < numComps; ++_c2) {
1230
+ model.volumeInfo.scale[_c2] = 65535.0;
1203
1231
  }
1204
1232
 
1205
1233
  return publicAPI.create3DFromRaw(width, height, depth, numComps, dataType, data);
@@ -1210,8 +1238,8 @@ function vtkOpenGLTexture(publicAPI, model) {
1210
1238
  }
1211
1239
 
1212
1240
  if (dataType === VtkDataTypes.UNSIGNED_CHAR) {
1213
- for (var _c4 = 0; _c4 < numComps; ++_c4) {
1214
- model.volumeInfo.scale[_c4] = 255.0;
1241
+ for (var _c3 = 0; _c3 < numComps; ++_c3) {
1242
+ model.volumeInfo.scale[_c3] = 255.0;
1215
1243
  }
1216
1244
 
1217
1245
  return publicAPI.create3DFromRaw(width, height, depth, numComps, dataType, data);
@@ -1247,9 +1275,9 @@ function vtkOpenGLTexture(publicAPI, model) {
1247
1275
  var dataTypeToUse = VtkDataTypes.UNSIGNED_CHAR; // unsigned char gets used as is
1248
1276
 
1249
1277
  if (dataType === VtkDataTypes.UNSIGNED_CHAR) {
1250
- for (var _c5 = 0; _c5 < numComps; ++_c5) {
1251
- scaleOffsetsCopy.offset[_c5] = 0.0;
1252
- scaleOffsetsCopy.scale[_c5] = 255.0;
1278
+ for (var _c4 = 0; _c4 < numComps; ++_c4) {
1279
+ scaleOffsetsCopy.offset[_c4] = 0.0;
1280
+ scaleOffsetsCopy.scale[_c4] = 255.0;
1253
1281
  }
1254
1282
  } else if (model.context.getExtension('OES_texture_float') && model.context.getExtension('OES_texture_float_linear')) {
1255
1283
  // use float textures scaled to 0.0 to 1.0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kitware/vtk.js",
3
- "version": "27.1.2",
3
+ "version": "27.2.0",
4
4
  "description": "Visualization Toolkit for the Web",
5
5
  "keywords": [
6
6
  "3d",