@kitware/vtk.js 25.14.2 → 25.15.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.
@@ -270,7 +270,7 @@ export interface vtkOpenGLRenderWindow extends vtkOpenGLRenderWindowBase {
270
270
  * @param {Number} numComps
271
271
  * @param {Boolean} useFloat
272
272
  */
273
- getDefaultTextureInternalFormat(vtktype: VtkDataTypes, numComps: number, useFloat: boolean): void;
273
+ getDefaultTextureInternalFormat(vtktype: VtkDataTypes, numComps: number, oglNorm16Ext?: unknown): void;
274
274
 
275
275
  /**
276
276
  *
@@ -536,7 +536,9 @@ function vtkOpenGLRenderWindow(publicAPI, model) {
536
536
  return -1;
537
537
  };
538
538
 
539
- publicAPI.getDefaultTextureInternalFormat = function (vtktype, numComps, useFloat) {
539
+ publicAPI.getDefaultTextureInternalFormat = function (vtktype, numComps) {
540
+ var oglNorm16Ext = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
541
+
540
542
  if (model.webgl2) {
541
543
  switch (vtktype) {
542
544
  case VtkDataTypes.UNSIGNED_CHAR:
@@ -555,6 +557,40 @@ function vtkOpenGLRenderWindow(publicAPI, model) {
555
557
  return model.context.RGBA8;
556
558
  }
557
559
 
560
+ case oglNorm16Ext && VtkDataTypes.UNSIGNED_SHORT:
561
+ switch (numComps) {
562
+ case 1:
563
+ return oglNorm16Ext.R16_EXT;
564
+
565
+ case 2:
566
+ return oglNorm16Ext.RG16_EXT;
567
+
568
+ case 3:
569
+ return oglNorm16Ext.RGB16_EXT;
570
+
571
+ case 4:
572
+ default:
573
+ return oglNorm16Ext.RGBA16_EXT;
574
+ }
575
+
576
+ // prioritize norm16 over float
577
+
578
+ case oglNorm16Ext && VtkDataTypes.SHORT:
579
+ switch (numComps) {
580
+ case 1:
581
+ return oglNorm16Ext.R16_SNORM_EXT;
582
+
583
+ case 2:
584
+ return oglNorm16Ext.RG16_SNORM_EXT;
585
+
586
+ case 3:
587
+ return oglNorm16Ext.RGB16_SNORM_EXT;
588
+
589
+ case 4:
590
+ default:
591
+ return oglNorm16Ext.RGBA16_SNORM_EXT;
592
+ }
593
+
558
594
  case VtkDataTypes.FLOAT:
559
595
  default:
560
596
  switch (numComps) {
@@ -20,8 +20,6 @@ var vtkDebugMacro = vtkDebugMacro$1,
20
20
  // ----------------------------------------------------------------------------
21
21
 
22
22
  function vtkOpenGLTexture(publicAPI, model) {
23
- var _this = this;
24
-
25
23
  // Set our className
26
24
  model.classHierarchy.push('vtkOpenGLTexture'); // Renders myself
27
25
 
@@ -313,14 +311,11 @@ function vtkOpenGLTexture(publicAPI, model) {
313
311
  publicAPI.getDefaultInternalFormat = function (vtktype, numComps) {
314
312
  var result = 0; // try default next
315
313
 
316
- result = model._openGLRenderWindow.getDefaultTextureInternalFormat(vtktype, numComps, false);
314
+ result = model._openGLRenderWindow.getDefaultTextureInternalFormat(vtktype, numComps, model.oglNorm16Ext);
317
315
 
318
316
  if (result) {
319
317
  return result;
320
- } // try floating point
321
-
322
-
323
- result = _this._openGLRenderWindow.getDefaultTextureInternalFormat(vtktype, numComps, true);
318
+ }
324
319
 
325
320
  if (!result) {
326
321
  vtkDebugMacro('Unsupported internal texture type!');
@@ -396,8 +391,6 @@ function vtkOpenGLTexture(publicAPI, model) {
396
391
 
397
392
 
398
393
  publicAPI.getDefaultDataType = function (vtkScalarType) {
399
- var useHalfFloatType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
400
-
401
394
  // DON'T DEAL with VTK_CHAR as this is platform dependent.
402
395
  if (model._openGLRenderWindow.getWebgl2()) {
403
396
  switch (vtkScalarType) {
@@ -405,11 +398,20 @@ function vtkOpenGLTexture(publicAPI, model) {
405
398
  // return model.context.BYTE;
406
399
  case VtkDataTypes.UNSIGNED_CHAR:
407
400
  return model.context.UNSIGNED_BYTE;
401
+ // prefer norm16 since that is accurate compared to
402
+ // half float which is not
403
+
404
+ case model.oglNorm16Ext && VtkDataTypes.SHORT:
405
+ return model.context.SHORT;
408
406
 
409
- case useHalfFloatType && VtkDataTypes.SHORT:
407
+ case model.oglNorm16Ext && VtkDataTypes.UNSIGNED_SHORT:
408
+ return model.context.UNSIGNED_SHORT;
409
+ // use half float type
410
+
411
+ case model.useHalfFloat && VtkDataTypes.SHORT:
410
412
  return model.context.HALF_FLOAT;
411
413
 
412
- case useHalfFloatType && VtkDataTypes.UNSIGNED_SHORT:
414
+ case model.useHalfFloat && VtkDataTypes.UNSIGNED_SHORT:
413
415
  return model.context.HALF_FLOAT;
414
416
  // case VtkDataTypes.INT:
415
417
  // return model.context.INT;
@@ -459,10 +461,10 @@ function vtkOpenGLTexture(publicAPI, model) {
459
461
 
460
462
 
461
463
  publicAPI.getOpenGLDataType = function (vtkScalarType) {
462
- var useHalfFloatType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
464
+ var forceUpdate = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
463
465
 
464
- if (!model.openGLDataType) {
465
- model.openGLDataType = publicAPI.getDefaultDataType(vtkScalarType, useHalfFloatType);
466
+ if (!model.openGLDataType || forceUpdate) {
467
+ model.openGLDataType = publicAPI.getDefaultDataType(vtkScalarType);
466
468
  }
467
469
 
468
470
  return model.openGLDataType;
@@ -1000,8 +1002,7 @@ function vtkOpenGLTexture(publicAPI, model) {
1000
1002
  }
1001
1003
 
1002
1004
  function checkUseHalfFloat(dataType, offset, scale, preferSizeOverAccuracy) {
1003
- var useHalfFloatType = true;
1004
- publicAPI.getOpenGLDataType(dataType, useHalfFloatType);
1005
+ publicAPI.getOpenGLDataType(dataType);
1005
1006
  var useHalfFloat = false;
1006
1007
 
1007
1008
  if (model._openGLRenderWindow.getWebgl2()) {
@@ -1027,8 +1028,7 @@ function vtkOpenGLTexture(publicAPI, model) {
1027
1028
 
1028
1029
  publicAPI.create3DFromRaw = function (width, height, depth, numComps, dataType, data) {
1029
1030
  // Permit OpenGLDataType to be half float, if applicable, for 3D
1030
- var useHalfFloatType = true;
1031
- publicAPI.getOpenGLDataType(dataType, useHalfFloatType); // Now determine the texture parameters using the arguments.
1031
+ publicAPI.getOpenGLDataType(dataType); // Now determine the texture parameters using the arguments.
1032
1032
 
1033
1033
  publicAPI.getInternalFormat(dataType, numComps);
1034
1034
  publicAPI.getFormat(dataType, numComps);
@@ -1056,6 +1056,7 @@ function vtkOpenGLTexture(publicAPI, model) {
1056
1056
  var scaledData = scaleTextureToHighestPowerOfTwo(pixData); // Source texture data from the PBO.
1057
1057
  // model.context.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true);
1058
1058
  // model.context.pixelStorei(model.context.UNPACK_ALIGNMENT, 1);
1059
+ // openGLDataType
1059
1060
 
1060
1061
  model.context.texImage3D(model.target, 0, model.internalFormat, model.width, model.height, model.depth, 0, model.format, model.openGLDataType, scaledData[0]);
1061
1062
 
@@ -1100,17 +1101,40 @@ function vtkOpenGLTexture(publicAPI, model) {
1100
1101
  computedScale = _computeScaleOffsets.scale;
1101
1102
 
1102
1103
  model.volumeInfo.dataComputedScale = computedScale;
1103
- model.volumeInfo.dataComputedOffset = computedOffset;
1104
- var useHalfFloat = checkUseHalfFloat(dataType, computedOffset, computedScale, preferSizeOverAccuracy); // WebGL2 path, we have 3d textures etc
1104
+ model.volumeInfo.dataComputedOffset = computedOffset; // if we can use norm16, there is no need to use halfFloat then
1105
+
1106
+ model.useHalfFloat = model.oglNorm16Ext ? false : checkUseHalfFloat(dataType, computedOffset, computedScale, preferSizeOverAccuracy); // since our default is to use half float, in case that we can't use it
1107
+ // we need to use another type
1108
+
1109
+ if (!model.useHalfFloat) {
1110
+ publicAPI.getOpenGLDataType(dataType, true);
1111
+ } // WebGL2 path, we have 3d textures etc
1112
+
1105
1113
 
1106
1114
  if (model._openGLRenderWindow.getWebgl2()) {
1107
- if (dataType === VtkDataTypes.FLOAT || useHalfFloat && (dataType === VtkDataTypes.SHORT || dataType === VtkDataTypes.UNSIGNED_SHORT)) {
1115
+ if (dataType === VtkDataTypes.FLOAT || model.useHalfFloat && (dataType === VtkDataTypes.SHORT || dataType === VtkDataTypes.UNSIGNED_SHORT)) {
1108
1116
  return publicAPI.create3DFromRaw(width, height, depth, numComps, dataType, data);
1109
1117
  }
1110
1118
 
1111
- if (dataType === VtkDataTypes.UNSIGNED_CHAR) {
1119
+ if (model.oglNorm16Ext && dataType === VtkDataTypes.SHORT) {
1112
1120
  for (var _c3 = 0; _c3 < numComps; ++_c3) {
1113
- model.volumeInfo.scale[_c3] = 255.0;
1121
+ model.volumeInfo.scale[_c3] = 32767.0;
1122
+ }
1123
+
1124
+ return publicAPI.create3DFromRaw(width, height, depth, numComps, dataType, data);
1125
+ }
1126
+
1127
+ if (model.oglNorm16Ext && dataType === VtkDataTypes.UNSIGNED_SHORT) {
1128
+ for (var _c4 = 0; _c4 < numComps; ++_c4) {
1129
+ model.volumeInfo.scale[_c4] = 65535.0;
1130
+ }
1131
+
1132
+ return publicAPI.create3DFromRaw(width, height, depth, numComps, dataType, data);
1133
+ }
1134
+
1135
+ if (dataType === VtkDataTypes.UNSIGNED_CHAR) {
1136
+ for (var _c5 = 0; _c5 < numComps; ++_c5) {
1137
+ model.volumeInfo.scale[_c5] = 255.0;
1114
1138
  }
1115
1139
 
1116
1140
  return publicAPI.create3DFromRaw(width, height, depth, numComps, dataType, data);
@@ -1149,9 +1173,9 @@ function vtkOpenGLTexture(publicAPI, model) {
1149
1173
  var dataTypeToUse = VtkDataTypes.UNSIGNED_CHAR; // unsigned char gets used as is
1150
1174
 
1151
1175
  if (dataType === VtkDataTypes.UNSIGNED_CHAR) {
1152
- for (var _c4 = 0; _c4 < numComps; ++_c4) {
1153
- res.offset[_c4] = 0.0;
1154
- res.scale[_c4] = 255.0;
1176
+ for (var _c6 = 0; _c6 < numComps; ++_c6) {
1177
+ res.offset[_c6] = 0.0;
1178
+ res.scale[_c6] = 255.0;
1155
1179
  }
1156
1180
  } else if (model.context.getExtension('OES_texture_float') && model.context.getExtension('OES_texture_float_linear')) {
1157
1181
  // use float textures scaled to 0.0 to 1.0
@@ -1326,7 +1350,13 @@ var DEFAULT_VALUES = {
1326
1350
  maxLOD: 1000.0,
1327
1351
  baseLevel: 0,
1328
1352
  maxLevel: 1000,
1329
- generateMipmap: false
1353
+ generateMipmap: false,
1354
+ // use half float by default, but it will get set
1355
+ // to false if the context does not support it or
1356
+ // the voxel intensity range is out of the accurate
1357
+ // range of half float
1358
+ useHalfFloat: true,
1359
+ oglNorm16Ext: null
1330
1360
  }; // ----------------------------------------------------------------------------
1331
1361
 
1332
1362
  function extend(publicAPI, model) {
@@ -1344,7 +1374,7 @@ function extend(publicAPI, model) {
1344
1374
  }); // Build VTK API
1345
1375
 
1346
1376
  set(publicAPI, model, ['format', 'openGLDataType']);
1347
- setGet(publicAPI, model, ['keyMatrixTime', 'minificationFilter', 'magnificationFilter', 'wrapS', 'wrapT', 'wrapR', 'generateMipmap']);
1377
+ setGet(publicAPI, model, ['keyMatrixTime', 'minificationFilter', 'magnificationFilter', 'wrapS', 'wrapT', 'wrapR', 'generateMipmap', 'oglNorm16Ext']);
1348
1378
  get(publicAPI, model, ['width', 'height', 'volumeInfo', 'components', 'handle', 'target']); // Object methods
1349
1379
 
1350
1380
  vtkOpenGLTexture(publicAPI, model);
@@ -671,8 +671,10 @@ function vtkOpenGLVolumeMapper(publicAPI, model) {
671
671
  program.setUniformf("oscale".concat(_i3), oscale);
672
672
  var cfun = vprop.getRGBTransferFunction(target);
673
673
  var cRange = cfun.getRange();
674
- program.setUniformf("cshift".concat(_i3), (volInfo.offset[_i3] - cRange[0]) / (cRange[1] - cRange[0]));
675
- program.setUniformf("cscale".concat(_i3), sscale / (cRange[1] - cRange[0]));
674
+ var cshift = (volInfo.offset[_i3] - cRange[0]) / (cRange[1] - cRange[0]);
675
+ var cScale = sscale / (cRange[1] - cRange[0]);
676
+ program.setUniformf("cshift".concat(_i3), cshift);
677
+ program.setUniformf("cscale".concat(_i3), cScale);
676
678
  }
677
679
 
678
680
  if (model.gopacity) {
@@ -1094,7 +1096,9 @@ function vtkOpenGLVolumeMapper(publicAPI, model) {
1094
1096
 
1095
1097
  if (model.scalarTextureString !== toString) {
1096
1098
  // Build the textures
1097
- var dims = image.getDimensions();
1099
+ var dims = image.getDimensions(); // Use norm16 for scalar texture if the extension is available
1100
+
1101
+ model.scalarTexture.setOglNorm16Ext(model.context.getExtension('EXT_texture_norm16'));
1098
1102
  model.scalarTexture.releaseGraphicsResources(model._openGLRenderWindow);
1099
1103
  model.scalarTexture.resetFormatAndType();
1100
1104
  model.scalarTexture.create3DFilterableFromRaw(dims[0], dims[1], dims[2], numComp, scalars.getDataType(), scalars.getData(), model.renderable.getPreferSizeOverAccuracy());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kitware/vtk.js",
3
- "version": "25.14.2",
3
+ "version": "25.15.0",
4
4
  "description": "Visualization Toolkit for the Web",
5
5
  "keywords": [
6
6
  "3d",