@kitware/vtk.js 27.1.2 → 27.2.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.
|
@@ -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);
|
|
@@ -272,7 +272,7 @@ function extend(publicAPI, model) {
|
|
|
272
272
|
|
|
273
273
|
macro.obj(publicAPI, model);
|
|
274
274
|
macro.algo(publicAPI, model, 6, 0);
|
|
275
|
-
macro.get(publicAPI, model, ['canvas', 'image', 'jsImageData', 'imageLoaded']);
|
|
275
|
+
macro.get(publicAPI, model, ['canvas', 'image', 'jsImageData', 'imageLoaded', 'resizable']);
|
|
276
276
|
macro.setGet(publicAPI, model, ['repeat', 'edgeClamp', 'interpolate', 'mipLevel']);
|
|
277
277
|
vtkTexture(publicAPI, model);
|
|
278
278
|
} // ----------------------------------------------------------------------------
|
|
@@ -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().
|
|
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.
|
|
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();
|
|
@@ -728,7 +728,9 @@ function vtkOpenGLTexture(publicAPI, model) {
|
|
|
728
728
|
|
|
729
729
|
function useTexStorage(dataType) {
|
|
730
730
|
if (model._openGLRenderWindow) {
|
|
731
|
-
|
|
731
|
+
var _model$renderable;
|
|
732
|
+
|
|
733
|
+
if (model.resizable || (_model$renderable = model.renderable) !== null && _model$renderable !== void 0 && _model$renderable.getResizable()) {
|
|
732
734
|
// Cannot use texStorage if the texture is supposed to be resizable.
|
|
733
735
|
return false;
|
|
734
736
|
}
|
|
@@ -879,7 +881,7 @@ function vtkOpenGLTexture(publicAPI, model) {
|
|
|
879
881
|
tempData = invertedData[6 * j + _i3];
|
|
880
882
|
}
|
|
881
883
|
|
|
882
|
-
if (
|
|
884
|
+
if (useTexStorage(dataType)) {
|
|
883
885
|
if (tempData != null) {
|
|
884
886
|
model.context.texSubImage2D(model.context.TEXTURE_CUBE_MAP_POSITIVE_X + _i3, j, 0, 0, w, h, model.format, model.openGLDataType, tempData);
|
|
885
887
|
}
|
|
@@ -1040,7 +1042,7 @@ function vtkOpenGLTexture(publicAPI, model) {
|
|
|
1040
1042
|
return true;
|
|
1041
1043
|
}
|
|
1042
1044
|
|
|
1043
|
-
function
|
|
1045
|
+
function setUseHalfFloat(dataType, offset, scale, preferSizeOverAccuracy) {
|
|
1044
1046
|
publicAPI.getOpenGLDataType(dataType);
|
|
1045
1047
|
var useHalfFloat = false;
|
|
1046
1048
|
|
|
@@ -1049,20 +1051,70 @@ function vtkOpenGLTexture(publicAPI, model) {
|
|
|
1049
1051
|
} else {
|
|
1050
1052
|
var halfFloatExt = model.context.getExtension('OES_texture_half_float');
|
|
1051
1053
|
useHalfFloat = halfFloatExt && model.openGLDataType === halfFloatExt.HALF_FLOAT_OES;
|
|
1052
|
-
}
|
|
1053
|
-
|
|
1054
|
-
if (!useHalfFloat) {
|
|
1055
|
-
return false;
|
|
1056
1054
|
} // Don't consider halfFloat and convert back to Float when the range of data does not generate an accurate halfFloat
|
|
1057
1055
|
// AND it is not preferable to have a smaller texture than an exact texture.
|
|
1058
1056
|
|
|
1059
1057
|
|
|
1060
|
-
|
|
1061
|
-
|
|
1058
|
+
var isHalfFloat = useHalfFloat && (hasExactHalfFloat(offset, scale) || preferSizeOverAccuracy);
|
|
1059
|
+
model.useHalfFloat = isHalfFloat;
|
|
1060
|
+
}
|
|
1061
|
+
|
|
1062
|
+
function processDataArray(dataArray, preferSizeOverAccuracy) {
|
|
1063
|
+
var numComps = dataArray.getNumberOfComponents();
|
|
1064
|
+
var dataType = dataArray.getDataType();
|
|
1065
|
+
var data = dataArray.getData(); // Compute min max from array
|
|
1066
|
+
// Using the vtkDataArray.getRange() enables caching
|
|
1067
|
+
|
|
1068
|
+
var minArray = new Array(numComps);
|
|
1069
|
+
var maxArray = new Array(numComps);
|
|
1070
|
+
|
|
1071
|
+
for (var c = 0; c < numComps; ++c) {
|
|
1072
|
+
var _dataArray$getRange = dataArray.getRange(c),
|
|
1073
|
+
_dataArray$getRange2 = _slicedToArray(_dataArray$getRange, 2),
|
|
1074
|
+
min = _dataArray$getRange2[0],
|
|
1075
|
+
max = _dataArray$getRange2[1];
|
|
1076
|
+
|
|
1077
|
+
minArray[c] = min;
|
|
1078
|
+
maxArray[c] = max;
|
|
1062
1079
|
}
|
|
1063
1080
|
|
|
1064
|
-
|
|
1065
|
-
|
|
1081
|
+
var scaleOffsets = computeScaleOffsets(minArray, maxArray, numComps); // preferSizeOverAccuracy will override norm16 due to bug with norm16 implementation
|
|
1082
|
+
// https://bugs.chromium.org/p/chromium/issues/detail?id=1408247
|
|
1083
|
+
|
|
1084
|
+
setUseHalfFloat(dataType, scaleOffsets.offset, scaleOffsets.scale, preferSizeOverAccuracy); // since our default is to use half float, in case that we can't use it
|
|
1085
|
+
// we need to use another type
|
|
1086
|
+
|
|
1087
|
+
if (!model.useHalfFloat) {
|
|
1088
|
+
publicAPI.getOpenGLDataType(dataType, true);
|
|
1089
|
+
}
|
|
1090
|
+
|
|
1091
|
+
return {
|
|
1092
|
+
numComps: numComps,
|
|
1093
|
+
dataType: dataType,
|
|
1094
|
+
data: data,
|
|
1095
|
+
scaleOffsets: scaleOffsets
|
|
1096
|
+
};
|
|
1097
|
+
}
|
|
1098
|
+
|
|
1099
|
+
publicAPI.create2DFilterableFromRaw = function (width, height, numberOfComponents, dataType, values) {
|
|
1100
|
+
var preferSizeOverAccuracy = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : false;
|
|
1101
|
+
return publicAPI.create2DFilterableFromDataArray(width, height, vtkDataArray.newInstance({
|
|
1102
|
+
numberOfComponents: numberOfComponents,
|
|
1103
|
+
dataType: dataType,
|
|
1104
|
+
values: values
|
|
1105
|
+
}), preferSizeOverAccuracy);
|
|
1106
|
+
};
|
|
1107
|
+
|
|
1108
|
+
publicAPI.create2DFilterableFromDataArray = function (width, height, dataArray) {
|
|
1109
|
+
var preferSizeOverAccuracy = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
1110
|
+
|
|
1111
|
+
var _processDataArray = processDataArray(dataArray, preferSizeOverAccuracy),
|
|
1112
|
+
numComps = _processDataArray.numComps,
|
|
1113
|
+
dataType = _processDataArray.dataType,
|
|
1114
|
+
data = _processDataArray.data;
|
|
1115
|
+
|
|
1116
|
+
publicAPI.create2DFromRaw(width, height, numComps, dataType, data);
|
|
1117
|
+
}; //----------------------------------------------------------------------------
|
|
1066
1118
|
|
|
1067
1119
|
|
|
1068
1120
|
publicAPI.create3DFromRaw = function (width, height, depth, numComps, dataType, data) {
|
|
@@ -1131,37 +1183,20 @@ function vtkOpenGLTexture(publicAPI, model) {
|
|
|
1131
1183
|
|
|
1132
1184
|
publicAPI.create3DFilterableFromDataArray = function (width, height, depth, dataArray) {
|
|
1133
1185
|
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
1186
|
|
|
1140
|
-
var
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
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
|
|
1187
|
+
var _processDataArray2 = processDataArray(dataArray, preferSizeOverAccuracy),
|
|
1188
|
+
numComps = _processDataArray2.numComps,
|
|
1189
|
+
dataType = _processDataArray2.dataType,
|
|
1190
|
+
data = _processDataArray2.data,
|
|
1191
|
+
scaleOffsets = _processDataArray2.scaleOffsets;
|
|
1158
1192
|
|
|
1193
|
+
var numPixelsIn = width * height * depth;
|
|
1159
1194
|
var offset = [];
|
|
1160
1195
|
var scale = [];
|
|
1161
1196
|
|
|
1162
|
-
for (var
|
|
1163
|
-
offset[
|
|
1164
|
-
scale[
|
|
1197
|
+
for (var c = 0; c < numComps; ++c) {
|
|
1198
|
+
offset[c] = 0.0;
|
|
1199
|
+
scale[c] = 1.0;
|
|
1165
1200
|
} // store the information, we will need it later
|
|
1166
1201
|
// offset and scale are the offset and scale required to get
|
|
1167
1202
|
// the texture value back to data values ala
|
|
@@ -1177,29 +1212,24 @@ function vtkOpenGLTexture(publicAPI, model) {
|
|
|
1177
1212
|
width: width,
|
|
1178
1213
|
height: height,
|
|
1179
1214
|
depth: depth
|
|
1180
|
-
}; //
|
|
1181
|
-
//
|
|
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
|
|
1215
|
+
}; // Create a copy of scale and offset to avoid aliasing issues
|
|
1216
|
+
// Original is read only, copy is read/write
|
|
1217
|
+
// Use the copy as volumeInfo.scale and volumeInfo.offset
|
|
1189
1218
|
|
|
1219
|
+
var scaleOffsetsCopy = structuredClone(scaleOffsets); // WebGL2 path, we have 3d textures etc
|
|
1190
1220
|
|
|
1191
1221
|
if (model._openGLRenderWindow.getWebgl2()) {
|
|
1192
1222
|
if (model.oglNorm16Ext && !model.useHalfFloat && dataType === VtkDataTypes.SHORT) {
|
|
1193
|
-
for (var
|
|
1194
|
-
model.volumeInfo.scale[
|
|
1223
|
+
for (var _c = 0; _c < numComps; ++_c) {
|
|
1224
|
+
model.volumeInfo.scale[_c] = 32767.0;
|
|
1195
1225
|
}
|
|
1196
1226
|
|
|
1197
1227
|
return publicAPI.create3DFromRaw(width, height, depth, numComps, dataType, data);
|
|
1198
1228
|
}
|
|
1199
1229
|
|
|
1200
1230
|
if (model.oglNorm16Ext && !model.useHalfFloat && dataType === VtkDataTypes.UNSIGNED_SHORT) {
|
|
1201
|
-
for (var
|
|
1202
|
-
model.volumeInfo.scale[
|
|
1231
|
+
for (var _c2 = 0; _c2 < numComps; ++_c2) {
|
|
1232
|
+
model.volumeInfo.scale[_c2] = 65535.0;
|
|
1203
1233
|
}
|
|
1204
1234
|
|
|
1205
1235
|
return publicAPI.create3DFromRaw(width, height, depth, numComps, dataType, data);
|
|
@@ -1210,8 +1240,8 @@ function vtkOpenGLTexture(publicAPI, model) {
|
|
|
1210
1240
|
}
|
|
1211
1241
|
|
|
1212
1242
|
if (dataType === VtkDataTypes.UNSIGNED_CHAR) {
|
|
1213
|
-
for (var
|
|
1214
|
-
model.volumeInfo.scale[
|
|
1243
|
+
for (var _c3 = 0; _c3 < numComps; ++_c3) {
|
|
1244
|
+
model.volumeInfo.scale[_c3] = 255.0;
|
|
1215
1245
|
}
|
|
1216
1246
|
|
|
1217
1247
|
return publicAPI.create3DFromRaw(width, height, depth, numComps, dataType, data);
|
|
@@ -1247,9 +1277,9 @@ function vtkOpenGLTexture(publicAPI, model) {
|
|
|
1247
1277
|
var dataTypeToUse = VtkDataTypes.UNSIGNED_CHAR; // unsigned char gets used as is
|
|
1248
1278
|
|
|
1249
1279
|
if (dataType === VtkDataTypes.UNSIGNED_CHAR) {
|
|
1250
|
-
for (var
|
|
1251
|
-
scaleOffsetsCopy.offset[
|
|
1252
|
-
scaleOffsetsCopy.scale[
|
|
1280
|
+
for (var _c4 = 0; _c4 < numComps; ++_c4) {
|
|
1281
|
+
scaleOffsetsCopy.offset[_c4] = 0.0;
|
|
1282
|
+
scaleOffsetsCopy.scale[_c4] = 255.0;
|
|
1253
1283
|
}
|
|
1254
1284
|
} else if (model.context.getExtension('OES_texture_float') && model.context.getExtension('OES_texture_float_linear')) {
|
|
1255
1285
|
// use float textures scaled to 0.0 to 1.0
|