@kitware/vtk.js 23.1.0 → 23.3.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.
@@ -53,6 +53,7 @@ function _addPoint(bounds) {
53
53
  bounds[3] = yMax > (arguments.length <= 2 ? undefined : arguments[2]) ? yMax : arguments.length <= 2 ? undefined : arguments[2];
54
54
  bounds[4] = zMin < (arguments.length <= 3 ? undefined : arguments[3]) ? zMin : arguments.length <= 3 ? undefined : arguments[3];
55
55
  bounds[5] = zMax > (arguments.length <= 3 ? undefined : arguments[3]) ? zMax : arguments.length <= 3 ? undefined : arguments[3];
56
+ return bounds;
56
57
  }
57
58
 
58
59
  function _addBounds(bounds, xMin, xMax, yMin, yMax, zMin, zMax) {
@@ -79,6 +80,8 @@ function _addBounds(bounds, xMin, xMax, yMin, yMax, zMin, zMax) {
79
80
  bounds[4] = Math.min(zMin, _zMin);
80
81
  bounds[5] = Math.max(zMax, _zMax);
81
82
  }
83
+
84
+ return bounds;
82
85
  }
83
86
 
84
87
  function _setMinPoint(bounds, x, y, z) {
@@ -124,6 +127,7 @@ function _inflate(bounds, delta) {
124
127
  bounds[3] += delta;
125
128
  bounds[4] -= delta;
126
129
  bounds[5] += delta;
130
+ return bounds;
127
131
  }
128
132
 
129
133
  function _scale(bounds, sx, sy, sz) {
@@ -233,6 +237,8 @@ function _getCorners(bounds, corners) {
233
237
  }
234
238
  }
235
239
  }
240
+
241
+ return corners;
236
242
  } // Computes the two corners with minimal and miximal coordinates
237
243
 
238
244
  function _computeCornerPoints(bounds, point1, point2) {
@@ -242,6 +248,7 @@ function _computeCornerPoints(bounds, point1, point2) {
242
248
  point2[0] = bounds[1];
243
249
  point2[1] = bounds[3];
244
250
  point2[2] = bounds[5];
251
+ return point1;
245
252
  }
246
253
 
247
254
  function _computeScale(bounds) {
@@ -557,9 +564,7 @@ var BoundingBox = /*#__PURE__*/function () {
557
564
  this.bounds = refBounds;
558
565
 
559
566
  if (!this.bounds) {
560
- this.bounds = new Float64Array(6);
561
-
562
- _setBounds(this.bounds, INIT_BOUNDS);
567
+ this.bounds = new Float64Array(INIT_BOUNDS);
563
568
  }
564
569
  }
565
570
 
@@ -1,7 +1,7 @@
1
1
  import _defineProperty from '@babel/runtime/helpers/defineProperty';
2
2
  import macro from '../../macros.js';
3
3
  import vtkAbstractImageInterpolator from './AbstractImageInterpolator.js';
4
- import { vtkInterpolationMathRound, vtkInterpolationMathClamp, vtkInterpolationMathMirror, vtkInterpolationMathWrap, vtkInterpolationWeights, vtkInterpolationMathFloor } from './AbstractImageInterpolator/InterpolationInfo.js';
4
+ import { vtkInterpolationMathRound, vtkInterpolationMathClamp, vtkInterpolationMathMirror, vtkInterpolationMathWrap, vtkInterpolationMathFloor, vtkInterpolationWeights } from './AbstractImageInterpolator/InterpolationInfo.js';
5
5
  import { InterpolationMode, ImageBorderMode } from './AbstractImageInterpolator/Constants.js';
6
6
 
7
7
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
@@ -92,10 +92,80 @@ function vtkImageInterpolator(publicAPI, model) {
92
92
  }
93
93
  };
94
94
 
95
+ publicAPI.interpolateLinear = function (interpolationInfo, point, value) {
96
+ var inExt = interpolationInfo.extent;
97
+ var inInc = interpolationInfo.increments;
98
+ var numscalars = interpolationInfo.numberOfComponents;
99
+ var floorX = vtkInterpolationMathFloor(point[0]);
100
+ var floorY = vtkInterpolationMathFloor(point[1]);
101
+ var floorZ = vtkInterpolationMathFloor(point[2]);
102
+ var inIdX0 = floorX.floored;
103
+ var inIdY0 = floorY.floored;
104
+ var inIdZ0 = floorZ.floored;
105
+ var fx = floorX.error;
106
+ var fy = floorY.error;
107
+ var fz = floorZ.error;
108
+ var inIdX1 = inIdX0 + (fx !== 0);
109
+ var inIdY1 = inIdY0 + (fy !== 0);
110
+ var inIdZ1 = inIdZ0 + (fz !== 0);
111
+
112
+ switch (interpolationInfo.borderMode) {
113
+ case ImageBorderMode.REPEAT:
114
+ inIdX0 = vtkInterpolationMathWrap(inIdX0, inExt[0], inExt[1]);
115
+ inIdY0 = vtkInterpolationMathWrap(inIdY0, inExt[2], inExt[3]);
116
+ inIdZ0 = vtkInterpolationMathWrap(inIdZ0, inExt[4], inExt[5]);
117
+ inIdX1 = vtkInterpolationMathWrap(inIdX1, inExt[0], inExt[1]);
118
+ inIdY1 = vtkInterpolationMathWrap(inIdY1, inExt[2], inExt[3]);
119
+ inIdZ1 = vtkInterpolationMathWrap(inIdZ1, inExt[4], inExt[5]);
120
+ break;
121
+
122
+ case ImageBorderMode.MIRROR:
123
+ inIdX0 = vtkInterpolationMathMirror(inIdX0, inExt[0], inExt[1]);
124
+ inIdY0 = vtkInterpolationMathMirror(inIdY0, inExt[2], inExt[3]);
125
+ inIdZ0 = vtkInterpolationMathMirror(inIdZ0, inExt[4], inExt[5]);
126
+ inIdX1 = vtkInterpolationMathMirror(inIdX1, inExt[0], inExt[1]);
127
+ inIdY1 = vtkInterpolationMathMirror(inIdY1, inExt[2], inExt[3]);
128
+ inIdZ1 = vtkInterpolationMathMirror(inIdZ1, inExt[4], inExt[5]);
129
+ break;
130
+
131
+ default:
132
+ inIdX0 = vtkInterpolationMathClamp(inIdX0, inExt[0], inExt[1]);
133
+ inIdY0 = vtkInterpolationMathClamp(inIdY0, inExt[2], inExt[3]);
134
+ inIdZ0 = vtkInterpolationMathClamp(inIdZ0, inExt[4], inExt[5]);
135
+ inIdX1 = vtkInterpolationMathClamp(inIdX1, inExt[0], inExt[1]);
136
+ inIdY1 = vtkInterpolationMathClamp(inIdY1, inExt[2], inExt[3]);
137
+ inIdZ1 = vtkInterpolationMathClamp(inIdZ1, inExt[4], inExt[5]);
138
+ break;
139
+ }
140
+
141
+ var factX0 = inIdX0 * inInc[0];
142
+ var factX1 = inIdX1 * inInc[0];
143
+ var factY0 = inIdY0 * inInc[1];
144
+ var factY1 = inIdY1 * inInc[1];
145
+ var factZ0 = inIdZ0 * inInc[2];
146
+ var factZ1 = inIdZ1 * inInc[2];
147
+ var i00 = factY0 + factZ0;
148
+ var i01 = factY0 + factZ1;
149
+ var i10 = factY1 + factZ0;
150
+ var i11 = factY1 + factZ1;
151
+ var rx = 1 - fx;
152
+ var ry = 1 - fy;
153
+ var rz = 1 - fz;
154
+ var ryrz = ry * rz;
155
+ var fyrz = fy * rz;
156
+ var ryfz = ry * fz;
157
+ var fyfz = fy * fz;
158
+ var inPtr = interpolationInfo.pointer;
159
+
160
+ for (var i = 0; i < numscalars; ++i) {
161
+ value[i] = rx * (ryrz * inPtr[factX0 + i00 + i * 4] + ryfz * inPtr[factX0 + i01 + i * 4] + fyrz * inPtr[factX0 + i10 + i * 4] + fyfz * inPtr[factX0 + i11 + i * 4]) + fx * (ryrz * inPtr[factX1 + i00 + i * 4] + ryfz * inPtr[factX1 + i01 + i * 4] + fyrz * inPtr[factX1 + i10 + i * 4] + fyfz * inPtr[factX1 + i11 + i * 4]);
162
+ }
163
+ };
164
+
95
165
  publicAPI.interpolatePoint = function (interpolationInfo, point, value) {
96
166
  switch (model.interpolationMode) {
97
167
  case InterpolationMode.LINEAR:
98
- console.log('LINEAR not implemented');
168
+ publicAPI.interpolateLinear(interpolationInfo, point, value);
99
169
  break;
100
170
 
101
171
  case InterpolationMode.CUBIC:
@@ -123,10 +193,115 @@ function vtkImageInterpolator(publicAPI, model) {
123
193
  }
124
194
  };
125
195
 
196
+ publicAPI.interpolateRowLinear = function (weights, idX, idY, idZ, outPtr, n) {
197
+ var stepX = weights.kernelSize[0];
198
+ var stepY = weights.kernelSize[1];
199
+ var stepZ = weights.kernelSize[2];
200
+ var idXtemp = idX * stepX;
201
+ var idYtemp = idY * stepY;
202
+ var idZtemp = idZ * stepZ;
203
+ var fX = weights.weights[0].subarray(idXtemp);
204
+ var fY = weights.weights[1].subarray(idYtemp);
205
+ var fZ = weights.weights[2].subarray(idZtemp);
206
+ var iX = weights.positions[0].subarray(idXtemp);
207
+ var iY = weights.positions[1].subarray(idYtemp);
208
+ var iZ = weights.positions[2].subarray(idZtemp);
209
+ var inPtr = weights.pointer; // get the number of components per pixel
210
+
211
+ var numscalars = weights.numberOfComponents; // create a 2x2 bilinear kernel in local variables
212
+
213
+ var i00 = iY.subarray(iZ[0]);
214
+ var i01 = i00;
215
+ var i10 = i00;
216
+ var i11 = i00;
217
+ var ry = 1;
218
+ var fy = 0;
219
+ var rz = 1;
220
+ var fz = 0;
221
+
222
+ if (stepY === 2) {
223
+ i10 = iY[1].subarray(iZ[0]);
224
+ i11 = i10;
225
+ ry = fY[0];
226
+ fy = fY[1];
227
+ }
228
+
229
+ if (stepZ === 2) {
230
+ i01 = iY[0].subarray(iZ[1]);
231
+ i11 = i01;
232
+ rz = fZ[0];
233
+ fz = fZ[1];
234
+ }
235
+
236
+ if (stepY + stepZ === 4) {
237
+ i11 = iY[1].subarray(iZ[1]);
238
+ }
239
+
240
+ var ryrz = ry * rz;
241
+ var ryfz = ry * fz;
242
+ var fyrz = fy * rz;
243
+ var fyfz = fy * fz;
244
+
245
+ if (stepX === 1) {
246
+ if (fy === 0 && fz === 0) {
247
+ // no interpolation needed at all
248
+ for (var i = n; i > 0; --i) {
249
+ for (var j = 0; j < numscalars; j++) {
250
+ outPtr[j + n - i] = inPtr[i00 + iX[n - i] + j];
251
+ }
252
+ }
253
+ } else if (fy === 0) {
254
+ // only need linear z interpolation
255
+ for (var _i = n; _i > 0; --_i) {
256
+ for (var _j = 0; _j < numscalars; _j++) {
257
+ outPtr[_j + n - _i] = rz * inPtr[iX[n - _i] + i00 + _j * 4] + fz * inPtr[iX[n - _i] + i01 + _j * 4];
258
+ }
259
+ }
260
+ } else {
261
+ // interpolate in y and z but not in x
262
+ for (var _i2 = n; _i2 > 0; --_i2) {
263
+ for (var _j2 = 0; _j2 < numscalars; _j2++) {
264
+ outPtr[_j2 + n - _i2] = ryrz * inPtr[iX[n - _i2] + i00 + _j2 * 4] + ryfz * inPtr[iX[n - _i2] + i01 + _j2 * 4] + fyrz * inPtr[iX[n - _i2] + i10 + _j2 * 4] + fyfz * inPtr[iX[n - _i2] + i11 + _j2 * 4];
265
+ }
266
+ }
267
+ }
268
+ } else if (fz === 0) {
269
+ var x = 0; // bilinear interpolation in x,y
270
+
271
+ for (var _i3 = n; _i3 > 0; --_i3) {
272
+ var rx = fX[0 + 2 * x];
273
+ var fx = fX[1 + 2 * x];
274
+ var t0 = iX[0 + 2 * x];
275
+ var t1 = iX[1 + 2 * x];
276
+
277
+ for (var _j3 = 0; _j3 < numscalars; _j3++) {
278
+ outPtr[_j3 + n - _i3] = rx * (ry * inPtr[t0 + i00 + _j3 * 4] + fy * inPtr[t0 + i10 + _j3 * 4]) + fx * (ry * inPtr[t1 + i00 + _j3 * 4] + fy * inPtr[t1 + i10 + _j3 * 4]);
279
+ }
280
+
281
+ x++;
282
+ }
283
+ } else {
284
+ var _x = 0; // do full trilinear interpolation
285
+
286
+ for (var _i4 = n; _i4 > 0; --_i4) {
287
+ var _rx = fX[0 + 2 * _x];
288
+ var _fx = fX[1 + 2 * _x];
289
+ var _t = iX[0 + 2 * _x];
290
+ var _t2 = iX[1 + 2 * _x];
291
+
292
+ for (var _j4 = 0; _j4 < numscalars; _j4++) {
293
+ outPtr[_j4] = _rx * (ryrz * inPtr[_t + i00 + _j4 * 4] + ryfz * inPtr[_t + i01 + _j4 * 4] + fyrz * inPtr[_t + i10 + _j4 * 4] + fyfz * inPtr[_t + i11 + _j4 * 4]) + _fx * (ryrz * inPtr[_t2 + i00 + _j4 * 4] + ryfz * inPtr[_t2 + i01 + _j4 * 4] + fyrz * inPtr[_t2 + i10 + _j4 * 4] + fyfz * inPtr[_t2 + i11 + _j4 * 4]);
294
+ }
295
+
296
+ _x++;
297
+ }
298
+ }
299
+ };
300
+
126
301
  publicAPI.interpolateRow = function (weights, xIdx, yIdx, zIdx, value, n) {
127
302
  switch (model.interpolationMode) {
128
303
  case InterpolationMode.LINEAR:
129
- console.log('LINEAR not implemented');
304
+ publicAPI.interpolateRowLinear(weights, xIdx, yIdx, zIdx, value, n);
130
305
  break;
131
306
 
132
307
  case InterpolationMode.CUBIC:
@@ -311,9 +486,9 @@ function vtkImageInterpolator(publicAPI, model) {
311
486
 
312
487
  if (!validClip) {
313
488
  // output extent doesn't itersect input extent
314
- for (var _j = 0; _j < 3; _j++) {
315
- clipExt[2 * _j] = outExt[2 * _j];
316
- clipExt[2 * _j + 1] = outExt[2 * _j] - 1;
489
+ for (var _j5 = 0; _j5 < 3; _j5++) {
490
+ clipExt[2 * _j5] = outExt[2 * _j5];
491
+ clipExt[2 * _j5 + 1] = outExt[2 * _j5] - 1;
317
492
  }
318
493
  }
319
494
  };
@@ -1000,7 +1000,7 @@ function extend(publicAPI, model) {
1000
1000
  macro.obj(publicAPI, model); // Also make it an algorithm with one input and one output
1001
1001
 
1002
1002
  macro.algo(publicAPI, model, 1, 1);
1003
- macro.setGet(publicAPI, model, ['outputDimensionality', 'outputScalarType', 'scalarShift', 'scalarScale', 'transformInputSampling', 'autoCropOutput', 'wrap', 'mirror', 'border', 'backgroundColor', 'slabMode', 'slabTrapezoidIntegration', 'slabNumberOfSlices', 'slabSliceSpacingFraction']);
1003
+ macro.setGet(publicAPI, model, ['outputDimensionality', 'outputScalarType', 'scalarShift', 'scalarScale', 'transformInputSampling', 'autoCropOutput', 'wrap', 'mirror', 'border', 'backgroundColor', 'interpolationMode', 'slabMode', 'slabTrapezoidIntegration', 'slabNumberOfSlices', 'slabSliceSpacingFraction']);
1004
1004
  macro.setGetArray(publicAPI, model, ['outputOrigin', 'outputSpacing'], 3);
1005
1005
  macro.setGetArray(publicAPI, model, ['outputExtent'], 6);
1006
1006
  setNullArray(publicAPI, model, ['outputOrigin', 'outputSpacing', 'outputExtent']);
@@ -1,6 +1,7 @@
1
1
  import macro from '../../macros.js';
2
2
  import vtkOpenGLFramebuffer from './Framebuffer.js';
3
3
  import vtkRenderPass from '../SceneGraph/RenderPass.js';
4
+ import vtkOpenGLOrderIndependentTranslucentPass from './OrderIndependentTranslucentPass.js';
4
5
 
5
6
  function vtkForwardPass(publicAPI, model) {
6
7
  // Set our className
@@ -72,8 +73,11 @@ function vtkForwardPass(publicAPI, model) {
72
73
  }
73
74
 
74
75
  if (model.translucentActorCount > 0) {
75
- publicAPI.setCurrentOperation('translucentPass');
76
- renNode.traverse(publicAPI);
76
+ if (!model.translucentPass) {
77
+ model.translucentPass = vtkOpenGLOrderIndependentTranslucentPass.newInstance();
78
+ }
79
+
80
+ model.translucentPass.traverse(viewNode, renNode, publicAPI);
77
81
  }
78
82
 
79
83
  if (model.volumeCount > 0) {
@@ -136,7 +140,7 @@ function extend(publicAPI, model) {
136
140
  Object.assign(model, DEFAULT_VALUES, initialValues); // Build VTK API
137
141
 
138
142
  vtkRenderPass.extend(publicAPI, model, initialValues);
139
- macro.get(publicAPI, model, ['framebuffer']); // Object methods
143
+ macro.get(publicAPI, model, ['framebuffer', 'opaqueActorCount', 'translucentActorCount', 'volumeCount']); // Object methods
140
144
 
141
145
  vtkForwardPass(publicAPI, model);
142
146
  } // ----------------------------------------------------------------------------
@@ -1,4 +1,4 @@
1
- import { newInstance as newInstance$1, obj, setGet, vtkErrorMacro } from '../../macros.js';
1
+ import { newInstance as newInstance$1, obj, vtkErrorMacro, getArray } from '../../macros.js';
2
2
  import vtkOpenGLTexture from './Texture.js';
3
3
  import { VtkDataTypes } from '../../Common/Core/DataArray/Constants.js';
4
4
  import { Filter } from './Texture/Constants.js';
@@ -23,6 +23,11 @@ function vtkFramebuffer(publicAPI, model) {
23
23
  };
24
24
 
25
25
  publicAPI.saveCurrentBindings = function (modeIn) {
26
+ if (!model.context) {
27
+ vtkErrorMacro('you must set the OpenGLRenderWindow before calling saveCurrentBindings');
28
+ return;
29
+ }
30
+
26
31
  var gl = model.context;
27
32
  model.previousDrawBinding = gl.getParameter(model.context.FRAMEBUFFER_BINDING);
28
33
  model.previousActiveFramebuffer = model.openGLRenderWindow.getActiveFramebuffer();
@@ -38,6 +43,11 @@ function vtkFramebuffer(publicAPI, model) {
38
43
  };
39
44
 
40
45
  publicAPI.restorePreviousBindings = function (modeIn) {
46
+ if (!model.context) {
47
+ vtkErrorMacro('you must set the OpenGLRenderWindow before calling restorePreviousBindings');
48
+ return;
49
+ }
50
+
41
51
  var gl = model.context;
42
52
  gl.bindFramebuffer(gl.FRAMEBUFFER, model.previousDrawBinding);
43
53
  model.openGLRenderWindow.setActiveFramebuffer(model.previousActiveFramebuffer);
@@ -47,16 +57,28 @@ function vtkFramebuffer(publicAPI, model) {
47
57
  };
48
58
 
49
59
  publicAPI.bind = function () {
50
- model.context.bindFramebuffer(model.context.FRAMEBUFFER, model.glFramebuffer);
60
+ var modeArg = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
61
+ var mode = modeArg;
62
+
63
+ if (mode === null) {
64
+ mode = model.context.FRAMEBUFFER;
65
+ }
66
+
67
+ model.context.bindFramebuffer(mode, model.glFramebuffer);
51
68
 
52
- if (model.colorTexture) {
53
- model.colorTexture.bind();
69
+ for (var i = 0; i < model.colorBuffers.length; i++) {
70
+ model.colorBuffers[i].bind();
54
71
  }
55
72
 
56
73
  model.openGLRenderWindow.setActiveFramebuffer(publicAPI);
57
74
  };
58
75
 
59
76
  publicAPI.create = function (width, height) {
77
+ if (!model.context) {
78
+ vtkErrorMacro('you must set the OpenGLRenderWindow before calling create');
79
+ return;
80
+ }
81
+
60
82
  model.glFramebuffer = model.context.createFramebuffer();
61
83
  model.glFramebuffer.width = width;
62
84
  model.glFramebuffer.height = height;
@@ -65,6 +87,12 @@ function vtkFramebuffer(publicAPI, model) {
65
87
  publicAPI.setColorBuffer = function (texture) {
66
88
  var attachment = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
67
89
  var gl = model.context;
90
+
91
+ if (!gl) {
92
+ vtkErrorMacro('you must set the OpenGLRenderWindow before calling setColorBuffer');
93
+ return;
94
+ }
95
+
68
96
  var glAttachment = gl.COLOR_ATTACHMENT0;
69
97
 
70
98
  if (attachment > 0) {
@@ -76,13 +104,19 @@ function vtkFramebuffer(publicAPI, model) {
76
104
  }
77
105
  }
78
106
 
79
- model.colorTexture = texture;
107
+ model.colorBuffers[attachment] = texture;
80
108
  gl.framebufferTexture2D(gl.FRAMEBUFFER, glAttachment, gl.TEXTURE_2D, texture.getHandle(), 0);
81
109
  };
82
110
 
83
111
  publicAPI.removeColorBuffer = function () {
84
112
  var attachment = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
85
113
  var gl = model.context;
114
+
115
+ if (!gl) {
116
+ vtkErrorMacro('you must set the OpenGLRenderWindow before calling removeColorBuffer');
117
+ return;
118
+ }
119
+
86
120
  var glAttachment = gl.COLOR_ATTACHMENT0;
87
121
 
88
122
  if (attachment > 0) {
@@ -95,9 +129,15 @@ function vtkFramebuffer(publicAPI, model) {
95
129
  }
96
130
 
97
131
  gl.framebufferTexture2D(gl.FRAMEBUFFER, glAttachment, gl.TEXTURE_2D, null, 0);
132
+ model.colorBuffers = model.colorBuffers.splice(attachment, 1);
98
133
  };
99
134
 
100
135
  publicAPI.setDepthBuffer = function (texture) {
136
+ if (!model.context) {
137
+ vtkErrorMacro('you must set the OpenGLRenderWindow before calling setDepthBuffer');
138
+ return;
139
+ }
140
+
101
141
  if (model.openGLRenderWindow.getWebgl2()) {
102
142
  var gl = model.context;
103
143
  gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.TEXTURE_2D, texture.getHandle(), 0);
@@ -107,6 +147,11 @@ function vtkFramebuffer(publicAPI, model) {
107
147
  };
108
148
 
109
149
  publicAPI.removeDepthBuffer = function () {
150
+ if (!model.context) {
151
+ vtkErrorMacro('you must set the OpenGLRenderWindow before calling removeDepthBuffer');
152
+ return;
153
+ }
154
+
110
155
  if (model.openGLRenderWindow.getWebgl2()) {
111
156
  var gl = model.context;
112
157
  gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.TEXTURE_2D, null, 0);
@@ -137,10 +182,6 @@ function vtkFramebuffer(publicAPI, model) {
137
182
  if (model.glFramebuffer) {
138
183
  model.context.deleteFramebuffer(model.glFramebuffer);
139
184
  }
140
-
141
- if (model.colorTexture) {
142
- model.colorTexture.releaseGraphicsResources();
143
- }
144
185
  };
145
186
 
146
187
  publicAPI.getSize = function () {
@@ -155,6 +196,11 @@ function vtkFramebuffer(publicAPI, model) {
155
196
  };
156
197
 
157
198
  publicAPI.populateFramebuffer = function () {
199
+ if (!model.context) {
200
+ vtkErrorMacro('you must set the OpenGLRenderWindow before calling populateFrameBuffer');
201
+ return;
202
+ }
203
+
158
204
  publicAPI.bind();
159
205
  var gl = model.context;
160
206
  var texture = vtkOpenGLTexture.newInstance();
@@ -169,6 +215,11 @@ function vtkFramebuffer(publicAPI, model) {
169
215
  gl.bindRenderbuffer(gl.RENDERBUFFER, model.depthTexture);
170
216
  gl.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_COMPONENT16, model.glFramebuffer.width, model.glFramebuffer.height);
171
217
  gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.RENDERBUFFER, model.depthTexture);
218
+ }; // For backwards compatibility. Use getColorBuffers()[0] going forward.
219
+
220
+
221
+ publicAPI.getColorTexture = function () {
222
+ return model.colorBuffers[0];
172
223
  };
173
224
  } // ----------------------------------------------------------------------------
174
225
  // Object factory
@@ -178,7 +229,7 @@ function vtkFramebuffer(publicAPI, model) {
178
229
  var DEFAULT_VALUES = {
179
230
  openGLRenderWindow: null,
180
231
  glFramebuffer: null,
181
- colorTexture: null,
232
+ colorBuffers: null,
182
233
  depthTexture: null,
183
234
  previousDrawBinding: 0,
184
235
  previousReadBinding: 0,
@@ -192,7 +243,13 @@ function extend(publicAPI, model) {
192
243
  Object.assign(model, DEFAULT_VALUES, initialValues); // Build VTK API
193
244
 
194
245
  obj(publicAPI, model);
195
- setGet(publicAPI, model, ['colorTexture']); // For more macro methods, see "Sources/macros.js"
246
+
247
+ if (model.colorBuffers) {
248
+ vtkErrorMacro('you cannot initialize colorBuffers through the constructor. You should call setColorBuffer() instead.');
249
+ }
250
+
251
+ model.colorBuffers = [];
252
+ getArray(publicAPI, model, ['colorBuffers']); // For more macro methods, see "Sources/macros.js"
196
253
  // Object specific methods
197
254
 
198
255
  vtkFramebuffer(publicAPI, model);
@@ -41,6 +41,7 @@ function vtkOpenGLImageMapper(publicAPI, model) {
41
41
 
42
42
  publicAPI.buildPass = function (prepass) {
43
43
  if (prepass) {
44
+ model.currentRenderPass = null;
44
45
  model.openGLImageSlice = publicAPI.getFirstAncestorOfType('vtkOpenGLImageSlice');
45
46
  model.openGLRenderer = publicAPI.getFirstAncestorOfType('vtkOpenGLRenderer');
46
47
  model.openGLRenderWindow = model.openGLRenderer.getParent();
@@ -58,8 +59,9 @@ function vtkOpenGLImageMapper(publicAPI, model) {
58
59
  }
59
60
  };
60
61
 
61
- publicAPI.translucentPass = function (prepass) {
62
+ publicAPI.translucentPass = function (prepass, renderPass) {
62
63
  if (prepass) {
64
+ model.currentRenderPass = renderPass;
63
65
  publicAPI.render();
64
66
  }
65
67
  };
@@ -95,7 +97,12 @@ function vtkOpenGLImageMapper(publicAPI, model) {
95
97
  };
96
98
 
97
99
  publicAPI.buildShaders = function (shaders, ren, actor) {
98
- publicAPI.getShaderTemplate(shaders, ren, actor);
100
+ publicAPI.getShaderTemplate(shaders, ren, actor); // apply any renderPassReplacements
101
+
102
+ if (model.lastRenderPassShaderReplacement) {
103
+ model.lastRenderPassShaderReplacement(shaders);
104
+ }
105
+
99
106
  publicAPI.replaceShaderValues(shaders, ren, actor);
100
107
  };
101
108
 
@@ -240,9 +247,21 @@ function vtkOpenGLImageMapper(publicAPI, model) {
240
247
  // input modified
241
248
  // light complexity changed
242
249
  var tNumComp = model.openGLTexture.getComponents();
243
- var iComp = actor.getProperty().getIndependentComponents();
250
+ var iComp = actor.getProperty().getIndependentComponents(); // has the render pass shader replacement changed? Two options
251
+
252
+ var needRebuild = false;
253
+
254
+ if (!model.currentRenderPass && model.lastRenderPassShaderReplacement) {
255
+ needRebuild = true;
256
+ model.lastRenderPassShaderReplacement = null;
257
+ }
258
+
259
+ if (model.currentRenderPass && model.currentRenderPass.getShaderReplacement() !== model.lastRenderPassShaderReplacement) {
260
+ model.lastRenderPassShaderReplacement = model.currentRenderPass.getShaderReplacement();
261
+ needRebuild = true;
262
+ }
244
263
 
245
- if (model.lastHaveSeenDepthRequest !== model.haveSeenDepthRequest || cellBO.getProgram() === 0 || model.lastTextureComponents !== tNumComp || model.lastIndependentComponents !== iComp) {
264
+ if (needRebuild || model.lastHaveSeenDepthRequest !== model.haveSeenDepthRequest || cellBO.getProgram() === 0 || model.lastTextureComponents !== tNumComp || model.lastIndependentComponents !== iComp) {
246
265
  model.lastHaveSeenDepthRequest = model.haveSeenDepthRequest;
247
266
  model.lastTextureComponents = tNumComp;
248
267
  model.lastIndependentComponents = iComp;
@@ -0,0 +1,293 @@
1
+ import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
2
+ import macro from '../../macros.js';
3
+ import vtkOpenGLTexture from './Texture.js';
4
+ import vtkOpenGLFramebuffer from './Framebuffer.js';
5
+ import vtkRenderPass from '../SceneGraph/RenderPass.js';
6
+ import vtkDataArray from '../../Common/Core/DataArray.js';
7
+ import vtkHelper from './Helper.js';
8
+ import vtkProperty from '../Core/Property.js';
9
+ import vtkShaderProgram from './ShaderProgram.js';
10
+ import vtkVertexArrayObject from './VertexArrayObject.js';
11
+
12
+ var Representation = vtkProperty.Representation;
13
+ var vtkErrorMacro = macro.vtkErrorMacro; // ----------------------------------------------------------------------------
14
+
15
+ function translucentShaderReplacement(shaders) {
16
+ var substituteRes = vtkShaderProgram.substitute(shaders.Fragment, '//VTK::RenderPassFragmentShader::Impl', "\n float weight = gl_FragData[0].a * pow(max(1.1 - gl_FragCoord.z, 0.0), 2.0);\n gl_FragData[0] = vec4(gl_FragData[0].rgb*weight, gl_FragData[0].a);\n gl_FragData[1].r = weight;\n ", false);
17
+ shaders.Fragment = substituteRes.result;
18
+ }
19
+
20
+ var oitpFragTemplate = "//VTK::System::Dec\n\nin vec2 tcoord;\n\nuniform sampler2D translucentRTexture;\nuniform sampler2D translucentRGBATexture;\n\n// the output of this shader\n//VTK::Output::Dec\n\nvoid main()\n{\n vec4 t1Color = texture(translucentRGBATexture, tcoord);\n float t2Color = texture(translucentRTexture, tcoord).r;\n gl_FragData[0] = vec4(t1Color.rgb/max(t2Color,0.01), 1.0 - t1Color.a);\n}\n";
21
+
22
+ function vtkOpenGLOrderIndependentTranslucentPass(publicAPI, model) {
23
+ // Set our className
24
+ model.classHierarchy.push('vtkOpenGLOrderIndependentTranslucentPass'); // build vertices etc
25
+
26
+ publicAPI.createVertexBuffer = function () {
27
+ // 4 corner points in clipping space in order (x, y, z) where z is always set to -1
28
+ // prettier-ignore
29
+ var ptsArray = new Float32Array([-1, -1, -1, 1, -1, -1, -1, 1, -1, 1, 1, -1]); // 4 corresponding corner points in texture space in order (x, y)
30
+
31
+ var tcoordArray = new Float32Array([0, 0, 1, 0, 0, 1, 1, 1]); // a square defined as cell relation ship in order (cell_size, v1, v2, v3, v4)
32
+
33
+ var cellArray = new Uint16Array([4, 0, 1, 3, 2]);
34
+ var points = vtkDataArray.newInstance({
35
+ numberOfComponents: 3,
36
+ values: ptsArray
37
+ });
38
+ points.setName('points');
39
+ var tcoords = vtkDataArray.newInstance({
40
+ numberOfComponents: 2,
41
+ values: tcoordArray
42
+ });
43
+ tcoords.setName('tcoords');
44
+ var cells = vtkDataArray.newInstance({
45
+ numberOfComponents: 1,
46
+ values: cellArray
47
+ });
48
+ model.tris.getCABO().createVBO(cells, 'polys', Representation.SURFACE, {
49
+ points: points,
50
+ tcoords: tcoords,
51
+ cellOffset: 0
52
+ });
53
+ model.VBOBuildTime.modified();
54
+ };
55
+
56
+ publicAPI.createFramebuffer = function (viewNode) {
57
+ var _model$framebuffer;
58
+
59
+ var size = viewNode.getSize();
60
+ var gl = viewNode.getContext();
61
+ model.framebuffer = vtkOpenGLFramebuffer.newInstance();
62
+ model.framebuffer.setOpenGLRenderWindow(viewNode);
63
+
64
+ (_model$framebuffer = model.framebuffer).create.apply(_model$framebuffer, _toConsumableArray(size));
65
+
66
+ model.framebuffer.saveCurrentBindingsAndBuffers();
67
+ model.framebuffer.bind();
68
+ model.translucentRGBATexture = vtkOpenGLTexture.newInstance();
69
+ model.translucentRGBATexture.setInternalFormat(gl.RGBA16F);
70
+ model.translucentRGBATexture.setFormat(gl.RGBA);
71
+ model.translucentRGBATexture.setOpenGLDataType(gl.HALF_FLOAT);
72
+ model.translucentRGBATexture.setOpenGLRenderWindow(viewNode);
73
+ model.translucentRGBATexture.create2DFromRaw(size[0], size[1], 4, 'Float32Array', null);
74
+ model.translucentRTexture = vtkOpenGLTexture.newInstance();
75
+ model.translucentRTexture.setInternalFormat(gl.R16F);
76
+ model.translucentRTexture.setFormat(gl.RED);
77
+ model.translucentRTexture.setOpenGLDataType(gl.HALF_FLOAT);
78
+ model.translucentRTexture.setOpenGLRenderWindow(viewNode);
79
+ model.translucentRTexture.create2DFromRaw(size[0], size[1], 1, 'Float32Array', null);
80
+ model.translucentZTexture = vtkOpenGLTexture.newInstance();
81
+ model.translucentZTexture.setOpenGLRenderWindow(viewNode);
82
+ model.translucentZTexture.createDepthFromRaw(size[0], size[1], 'Float32Array', null);
83
+ model.framebuffer.setColorBuffer(model.translucentRGBATexture, 0);
84
+ model.framebuffer.setColorBuffer(model.translucentRTexture, 1);
85
+ model.framebuffer.setDepthBuffer(model.translucentZTexture);
86
+ };
87
+
88
+ publicAPI.createCopyShader = function (viewNode) {
89
+ model.copyShader = viewNode.getShaderCache().readyShaderProgramArray(['//VTK::System::Dec', 'attribute vec4 vertexDC;', 'attribute vec2 tcoordTC;', 'varying vec2 tcoord;', 'void main() { tcoord = tcoordTC; gl_Position = vertexDC; }'].join('\n'), oitpFragTemplate, '');
90
+ };
91
+
92
+ publicAPI.createVBO = function (viewNode) {
93
+ var gl = viewNode.getContext();
94
+ model.tris.setOpenGLRenderWindow(viewNode);
95
+ publicAPI.createVertexBuffer();
96
+ var program = model.copyShader; // prepare the vertex and triangle data for the image plane to render to
97
+
98
+ model.tris.getCABO().bind();
99
+
100
+ if (!model.copyVAO.addAttributeArray(program, model.tris.getCABO(), 'vertexDC', model.tris.getCABO().getVertexOffset(), model.tris.getCABO().getStride(), gl.FLOAT, 3, gl.FALSE)) {
101
+ vtkErrorMacro('Error setting vertexDC in copy shader VAO.');
102
+ }
103
+
104
+ if (!model.copyVAO.addAttributeArray(program, model.tris.getCABO(), 'tcoordTC', model.tris.getCABO().getTCoordOffset(), model.tris.getCABO().getStride(), gl.FLOAT, 2, gl.FALSE)) {
105
+ vtkErrorMacro('Error setting vertexDC in copy shader VAO.');
106
+ }
107
+ };
108
+
109
+ publicAPI.traverse = function (viewNode, renNode, forwardPass) {
110
+ if (model.deleted) {
111
+ return;
112
+ }
113
+
114
+ var size = viewNode.getSize();
115
+ var gl = viewNode.getContext();
116
+
117
+ if (gl === null) {
118
+ // nothing to do -> no render context
119
+ // traverse delegate passes -> has to be done in order for the vtk render-pipeline to work correctly
120
+ model.delegates.forEach(function (val) {
121
+ val.traverse(viewNode, publicAPI);
122
+ });
123
+ return;
124
+ } // if we lack the webgl2 and half floatsupport just do
125
+ // basic alpha blending
126
+
127
+
128
+ if (!viewNode.getWebgl2() || !gl.getExtension('EXT_color_buffer_half_float') && !gl.getExtension('EXT_color_buffer_float')) {
129
+ console.log('fallback');
130
+ publicAPI.setCurrentOperation('translucentPass');
131
+ renNode.traverse(publicAPI);
132
+ return;
133
+ } // prepare framebuffer // allocate framebuffer if needed and bind it
134
+
135
+
136
+ if (model.framebuffer === null) {
137
+ publicAPI.createFramebuffer(viewNode);
138
+ } else {
139
+ var fbSize = model.framebuffer.getSize();
140
+
141
+ if (fbSize === null || fbSize[0] !== size[0] || fbSize[1] !== size[1]) {
142
+ model.framebuffer.releaseGraphicsResources();
143
+ model.translucentRGBATexture.releaseGraphicsResources(viewNode);
144
+ model.translucentRTexture.releaseGraphicsResources(viewNode);
145
+ model.translucentZTexture.releaseGraphicsResources(viewNode);
146
+ publicAPI.createFramebuffer(viewNode);
147
+ } else {
148
+ // store framebuffer bindings to restore them later
149
+ model.framebuffer.saveCurrentBindingsAndBuffers();
150
+ model.framebuffer.bind();
151
+ }
152
+ }
153
+
154
+ gl.drawBuffers([gl.COLOR_ATTACHMENT0]);
155
+ gl.clearBufferfv(gl.COLOR, 0, [0.0, 0.0, 0.0, 0.0]);
156
+ gl.clearBufferfv(gl.DEPTH, 0, [1.0]);
157
+ gl.colorMask(false, false, false, false); // rerender the opaque pass to set the depth buffer
158
+ // TODO remove when webgl1 is deprecated and instead
159
+ // have the forward pass use a texture backed zbuffer
160
+
161
+ if (forwardPass.getOpaqueActorCount() > 0) {
162
+ forwardPass.setCurrentOperation('opaquePass');
163
+ renNode.traverse(forwardPass);
164
+ }
165
+
166
+ gl.colorMask(true, true, true, true);
167
+ gl.drawBuffers([gl.COLOR_ATTACHMENT0, gl.COLOR_ATTACHMENT1]);
168
+ gl.clearBufferfv(gl.COLOR, 0, [0.0, 0.0, 0.0, 1.0]);
169
+ gl.clearBufferfv(gl.COLOR, 1, [0.0, 0.0, 0.0, 0.0]);
170
+ gl.enable(gl.DEPTH_TEST);
171
+ gl.enable(gl.BLEND); // basic gist is we accumulate color into RGB We compute final opacity
172
+ // into A We store accumulated opacity into R of the R texture.
173
+
174
+ gl.blendFuncSeparate(gl.ONE, gl.ONE, gl.ZERO, gl.ONE_MINUS_SRC_ALPHA); // now do the translucent rendering
175
+
176
+ publicAPI.setCurrentOperation('translucentPass');
177
+ renNode.traverse(publicAPI);
178
+ gl.drawBuffers([gl.NONE]);
179
+ model.framebuffer.restorePreviousBindingsAndBuffers(); // gl.drawBuffers([gl.BACK]);
180
+ // make sure the copy shader is ready
181
+
182
+ if (model.copyShader === null) {
183
+ publicAPI.createCopyShader(viewNode);
184
+ } else {
185
+ viewNode.getShaderCache().readyShaderProgram(model.copyShader);
186
+ } // make sure we have a VAO
187
+
188
+
189
+ if (!model.copyVAO) {
190
+ model.copyVAO = vtkVertexArrayObject.newInstance();
191
+ model.copyVAO.setOpenGLRenderWindow(viewNode);
192
+ }
193
+
194
+ model.copyVAO.bind(); // make sure the VBO is up to date
195
+
196
+ if (model.VBOBuildTime.getMTime() < publicAPI.getMTime()) {
197
+ publicAPI.createVBO(viewNode);
198
+ }
199
+
200
+ gl.blendFuncSeparate(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
201
+ gl.depthMask(false);
202
+ gl.depthFunc(gl.ALWAYS);
203
+ gl.viewport(0, 0, size[0], size[1]);
204
+ gl.scissor(0, 0, size[0], size[1]); // activate texture
205
+
206
+ model.translucentRGBATexture.activate();
207
+ model.copyShader.setUniformi('translucentRGBATexture', model.translucentRGBATexture.getTextureUnit());
208
+ model.translucentRTexture.activate();
209
+ model.copyShader.setUniformi('translucentRTexture', model.translucentRTexture.getTextureUnit()); // render quad
210
+
211
+ gl.drawArrays(gl.TRIANGLES, 0, model.tris.getCABO().getElementCount());
212
+ gl.depthMask(true);
213
+ gl.depthFunc(gl.LEQUAL);
214
+ model.translucentRGBATexture.deactivate();
215
+ model.translucentRTexture.deactivate();
216
+ };
217
+
218
+ publicAPI.getShaderReplacement = function () {
219
+ return translucentShaderReplacement;
220
+ };
221
+
222
+ publicAPI.releaseGraphicsResources = function (viewNode) {
223
+ if (model.framebuffer) {
224
+ model.framebuffer.releaseGraphicsResources(viewNode);
225
+ model.framebuffer = null;
226
+ }
227
+
228
+ if (model.translucentRGBATexture) {
229
+ model.translucentRGBATexture.releaseGraphicsResources(viewNode);
230
+ model.translucentRGBATexture = null;
231
+ }
232
+
233
+ if (model.translucentRTexture) {
234
+ model.translucentRTexture.releaseGraphicsResources(viewNode);
235
+ model.translucentRTexture = null;
236
+ }
237
+
238
+ if (model.translucentZTexture) {
239
+ model.translucentZTexture.releaseGraphicsResources(viewNode);
240
+ model.translucentZTexture = null;
241
+ }
242
+
243
+ if (model.copyVAO) {
244
+ model.copyVAO.releaseGraphicsResources(viewNode);
245
+ model.copyVAO = null;
246
+ }
247
+
248
+ if (model.copyShader) {
249
+ model.copyShader.releaseGraphicsResources(viewNode);
250
+ model.copyShader = null;
251
+ }
252
+
253
+ if (model.tris) {
254
+ model.tris.releaseGraphicsResources(viewNode);
255
+ model.tris = null;
256
+ }
257
+
258
+ publicAPI.modified();
259
+ };
260
+ } // ----------------------------------------------------------------------------
261
+ // Object factory
262
+ // ----------------------------------------------------------------------------
263
+
264
+
265
+ var DEFAULT_VALUES = {
266
+ framebuffer: null,
267
+ copyShader: null,
268
+ tris: null
269
+ }; // ----------------------------------------------------------------------------
270
+
271
+ function extend(publicAPI, model) {
272
+ var initialValues = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
273
+ Object.assign(model, DEFAULT_VALUES, initialValues); // Build VTK API
274
+
275
+ vtkRenderPass.extend(publicAPI, model, initialValues);
276
+ model.VBOBuildTime = {};
277
+ macro.obj(model.VBOBuildTime, {
278
+ mtime: 0
279
+ });
280
+ model.tris = vtkHelper.newInstance();
281
+ macro.get(publicAPI, model, ['framebuffer']); // Object methods
282
+
283
+ vtkOpenGLOrderIndependentTranslucentPass(publicAPI, model);
284
+ } // ----------------------------------------------------------------------------
285
+
286
+ var newInstance = macro.newInstance(extend, 'vtkOpenGLOrderIndependentTranslucentPass'); // ----------------------------------------------------------------------------
287
+
288
+ var vtkOpenGLOrderIndependentTranslucentPass$1 = {
289
+ newInstance: newInstance,
290
+ extend: extend
291
+ };
292
+
293
+ export { vtkOpenGLOrderIndependentTranslucentPass$1 as default, extend, newInstance };
@@ -46,6 +46,7 @@ function vtkOpenGLPolyDataMapper(publicAPI, model) {
46
46
 
47
47
  publicAPI.buildPass = function (prepass) {
48
48
  if (prepass) {
49
+ model.currentRenderPass = null;
49
50
  model.openGLActor = publicAPI.getFirstAncestorOfType('vtkOpenGLActor');
50
51
  model.openGLRenderer = model.openGLActor.getFirstAncestorOfType('vtkOpenGLRenderer');
51
52
  model.openGLRenderWindow = model.openGLRenderer.getParent();
@@ -54,8 +55,9 @@ function vtkOpenGLPolyDataMapper(publicAPI, model) {
54
55
  }; // Renders myself
55
56
 
56
57
 
57
- publicAPI.translucentPass = function (prepass) {
58
+ publicAPI.translucentPass = function (prepass, renderPass) {
58
59
  if (prepass) {
60
+ model.currentRenderPass = renderPass;
59
61
  publicAPI.render();
60
62
  }
61
63
  };
@@ -92,7 +94,12 @@ function vtkOpenGLPolyDataMapper(publicAPI, model) {
92
94
  };
93
95
 
94
96
  publicAPI.buildShaders = function (shaders, ren, actor) {
95
- publicAPI.getShaderTemplate(shaders, ren, actor); // user specified pre replacements
97
+ publicAPI.getShaderTemplate(shaders, ren, actor); // apply any renderPassReplacements
98
+
99
+ if (model.lastRenderPassShaderReplacement) {
100
+ model.lastRenderPassShaderReplacement(shaders);
101
+ } // user specified pre replacements
102
+
96
103
 
97
104
  var openGLSpec = model.renderable.getViewSpecificProperties().OpenGL;
98
105
  var shaderReplacements = null;
@@ -603,6 +610,17 @@ function vtkOpenGLPolyDataMapper(publicAPI, model) {
603
610
  lastLightCount: numberOfLights
604
611
  }, true);
605
612
  needRebuild = true;
613
+ } // has the render pass shader replacement changed? Two options
614
+
615
+
616
+ if (!model.currentRenderPass && model.lastRenderPassShaderReplacement) {
617
+ needRebuild = true;
618
+ model.lastRenderPassShaderReplacement = null;
619
+ }
620
+
621
+ if (model.currentRenderPass && model.currentRenderPass.getShaderReplacement() !== model.lastRenderPassShaderReplacement) {
622
+ model.lastRenderPassShaderReplacement = model.currentRenderPass.getShaderReplacement();
623
+ needRebuild = true;
606
624
  } // has something changed that would require us to recreate the shader?
607
625
  // candidates are
608
626
  // property modified (representation interpolation and lighting)
@@ -46,8 +46,16 @@ function vtkShaderCache(publicAPI, model) {
46
46
  if (gl2) {
47
47
  nVSSource = vtkShaderProgram.substitute(nVSSource, 'varying', 'out').result;
48
48
  nFSSource = vtkShaderProgram.substitute(nFSSource, 'varying', 'in').result;
49
- nFSSource = vtkShaderProgram.substitute(nFSSource, 'gl_FragData\\[0\\]', 'fragOutput0').result;
50
- nFSSource = vtkShaderProgram.substitute(nFSSource, '//VTK::Output::Dec', 'layout(location = 0) out vec4 fragOutput0;').result;
49
+ var shaderOutputs = '';
50
+ var outputCount = 0;
51
+
52
+ while (nFSSource.includes("gl_FragData[".concat(outputCount, "]"))) {
53
+ nFSSource = vtkShaderProgram.substitute(nFSSource, "gl_FragData\\[".concat(outputCount, "\\]"), "fragOutput".concat(outputCount)).result;
54
+ shaderOutputs += "layout(location = ".concat(outputCount, ") out vec4 fragOutput").concat(outputCount, ";\n");
55
+ outputCount++;
56
+ }
57
+
58
+ nFSSource = vtkShaderProgram.substitute(nFSSource, '//VTK::Output::Dec', shaderOutputs).result;
51
59
  } // nFSSource = ShaderProgram.substitute(nFSSource, 'gl_FragData\\[0\\]',
52
60
  // 'gl_FragColor').result;
53
61
 
@@ -456,7 +456,11 @@ function vtkOpenGLTexture(publicAPI, model) {
456
456
 
457
457
  publicAPI.getOpenGLDataType = function (vtkScalarType) {
458
458
  var useHalfFloatType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
459
- model.openGLDataType = publicAPI.getDefaultDataType(vtkScalarType, useHalfFloatType);
459
+
460
+ if (!model.openGLDataType) {
461
+ model.openGLDataType = publicAPI.getDefaultDataType(vtkScalarType, useHalfFloatType);
462
+ }
463
+
460
464
  return model.openGLDataType;
461
465
  };
462
466
 
@@ -561,13 +565,17 @@ function vtkOpenGLTexture(publicAPI, model) {
561
565
 
562
566
  if (dataType !== VtkDataTypes.FLOAT && model.openGLDataType === model.context.FLOAT) {
563
567
  for (var idx = 0; idx < data.length; idx++) {
564
- var newArray = new Float32Array(pixCount);
568
+ if (data[idx]) {
569
+ var newArray = new Float32Array(pixCount);
565
570
 
566
- for (var i = 0; i < pixCount; i++) {
567
- newArray[i] = data[idx][i];
568
- }
571
+ for (var i = 0; i < pixCount; i++) {
572
+ newArray[i] = data[idx][i];
573
+ }
569
574
 
570
- pixData.push(newArray);
575
+ pixData.push(newArray);
576
+ } else {
577
+ pixData.push(null);
578
+ }
571
579
  }
572
580
  } // if the opengl data type is ubyte
573
581
  // then the data array must be u8, we currently simply truncate the data
@@ -575,13 +583,17 @@ function vtkOpenGLTexture(publicAPI, model) {
575
583
 
576
584
  if (dataType !== VtkDataTypes.UNSIGNED_CHAR && model.openGLDataType === model.context.UNSIGNED_BYTE) {
577
585
  for (var _idx = 0; _idx < data.length; _idx++) {
578
- var _newArray = new Uint8Array(pixCount);
586
+ if (data[_idx]) {
587
+ var _newArray = new Uint8Array(pixCount);
579
588
 
580
- for (var _i = 0; _i < pixCount; _i++) {
581
- _newArray[_i] = data[_idx][_i];
582
- }
589
+ for (var _i = 0; _i < pixCount; _i++) {
590
+ _newArray[_i] = data[_idx][_i];
591
+ }
583
592
 
584
- pixData.push(_newArray);
593
+ pixData.push(_newArray);
594
+ } else {
595
+ pixData.push(null);
596
+ }
585
597
  }
586
598
  } // if the opengl data type is half float
587
599
  // then the data array must be u16
@@ -592,13 +604,17 @@ function vtkOpenGLTexture(publicAPI, model) {
592
604
 
593
605
  if (halfFloat) {
594
606
  for (var _idx2 = 0; _idx2 < data.length; _idx2++) {
595
- var _newArray2 = new Uint16Array(pixCount);
607
+ if (data[_idx2]) {
608
+ var _newArray2 = new Uint16Array(pixCount);
596
609
 
597
- for (var _i2 = 0; _i2 < pixCount; _i2++) {
598
- _newArray2[_i2] = HalfFloat.toHalf(data[_idx2][_i2]);
599
- }
610
+ for (var _i2 = 0; _i2 < pixCount; _i2++) {
611
+ _newArray2[_i2] = HalfFloat.toHalf(data[_idx2][_i2]);
612
+ }
600
613
 
601
- pixData.push(_newArray2);
614
+ pixData.push(_newArray2);
615
+ } else {
616
+ pixData.push(null);
617
+ }
602
618
  }
603
619
  } // The output has to be filled
604
620
 
@@ -1,3 +1,3 @@
1
- var vtkPolyDataFS = "//VTK::System::Dec\n\n/*=========================================================================\n\n Program: Visualization Toolkit\n Module: vtkPolyDataFS.glsl\n\n Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen\n All rights reserved.\n See Copyright.txt or http://www.kitware.com/Copyright.htm for details.\n\n This software is distributed WITHOUT ANY WARRANTY; without even\n the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR\n PURPOSE. See the above copyright notice for more information.\n\n=========================================================================*/\n// Template for the polydata mappers fragment shader\n\nuniform int PrimitiveIDOffset;\n\n// VC position of this fragment\n//VTK::PositionVC::Dec\n\n// optional color passed in from the vertex shader, vertexColor\n//VTK::Color::Dec\n\n// optional surface normal declaration\n//VTK::Normal::Dec\n\n// extra lighting parameters\n//VTK::Light::Dec\n\n// Texture coordinates\n//VTK::TCoord::Dec\n\n// picking support\n//VTK::Picking::Dec\n\n// Depth Peeling Support\n//VTK::DepthPeeling::Dec\n\n// clipping plane vars\n//VTK::Clip::Dec\n\n// the output of this shader\n//VTK::Output::Dec\n\n// Apple Bug\n//VTK::PrimID::Dec\n\n// handle coincident offsets\n//VTK::Coincident::Dec\n\n//VTK::ZBuffer::Dec\n\nvoid main()\n{\n // VC position of this fragment. This should not branch/return/discard.\n //VTK::PositionVC::Impl\n\n // Place any calls that require uniform flow (e.g. dFdx) here.\n //VTK::UniformFlow::Impl\n\n // Set gl_FragDepth here (gl_FragCoord.z by default)\n //VTK::Depth::Impl\n\n // Early depth peeling abort:\n //VTK::DepthPeeling::PreColor\n\n // Apple Bug\n //VTK::PrimID::Impl\n\n //VTK::Clip::Impl\n\n //VTK::Color::Impl\n\n // Generate the normal if we are not passed in one\n //VTK::Normal::Impl\n\n //VTK::TCoord::Impl\n\n //VTK::Light::Impl\n\n if (gl_FragData[0].a <= 0.0)\n {\n discard;\n }\n\n //VTK::DepthPeeling::Impl\n\n //VTK::Picking::Impl\n\n // handle coincident offsets\n //VTK::Coincident::Impl\n\n //VTK::ZBuffer::Impl\n}\n";
1
+ var vtkPolyDataFS = "//VTK::System::Dec\n\n/*=========================================================================\n\n Program: Visualization Toolkit\n Module: vtkPolyDataFS.glsl\n\n Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen\n All rights reserved.\n See Copyright.txt or http://www.kitware.com/Copyright.htm for details.\n\n This software is distributed WITHOUT ANY WARRANTY; without even\n the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR\n PURPOSE. See the above copyright notice for more information.\n\n=========================================================================*/\n// Template for the polydata mappers fragment shader\n\nuniform int PrimitiveIDOffset;\n\n// VC position of this fragment\n//VTK::PositionVC::Dec\n\n// optional color passed in from the vertex shader, vertexColor\n//VTK::Color::Dec\n\n// optional surface normal declaration\n//VTK::Normal::Dec\n\n// extra lighting parameters\n//VTK::Light::Dec\n\n// Texture coordinates\n//VTK::TCoord::Dec\n\n// picking support\n//VTK::Picking::Dec\n\n// Depth Peeling Support\n//VTK::DepthPeeling::Dec\n\n// clipping plane vars\n//VTK::Clip::Dec\n\n// the output of this shader\n//VTK::Output::Dec\n\n// Apple Bug\n//VTK::PrimID::Dec\n\n// handle coincident offsets\n//VTK::Coincident::Dec\n\n//VTK::ZBuffer::Dec\n\nvoid main()\n{\n // VC position of this fragment. This should not branch/return/discard.\n //VTK::PositionVC::Impl\n\n // Place any calls that require uniform flow (e.g. dFdx) here.\n //VTK::UniformFlow::Impl\n\n // Set gl_FragDepth here (gl_FragCoord.z by default)\n //VTK::Depth::Impl\n\n // Early depth peeling abort:\n //VTK::DepthPeeling::PreColor\n\n // Apple Bug\n //VTK::PrimID::Impl\n\n //VTK::Clip::Impl\n\n //VTK::Color::Impl\n\n // Generate the normal if we are not passed in one\n //VTK::Normal::Impl\n\n //VTK::TCoord::Impl\n\n //VTK::Light::Impl\n\n if (gl_FragData[0].a <= 0.0)\n {\n discard;\n }\n\n //VTK::DepthPeeling::Impl\n\n //VTK::Picking::Impl\n\n // handle coincident offsets\n //VTK::Coincident::Impl\n\n //VTK::ZBuffer::Impl\n\n //VTK::RenderPassFragmentShader::Impl\n}\n";
2
2
 
3
3
  export { vtkPolyDataFS as v };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kitware/vtk.js",
3
- "version": "23.1.0",
3
+ "version": "23.3.0",
4
4
  "description": "Visualization Toolkit for the Web",
5
5
  "keywords": [
6
6
  "3d",