@kitware/vtk.js 22.5.4 → 22.5.5

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.
@@ -221,22 +221,6 @@ function vtkScalarBarActorHelper(publicAPI, model) {
221
221
  model.lastRedrawTime.modified();
222
222
  model.forceViewUpdate = false;
223
223
  }
224
- }; // The text atlas is an image and as loading images is async we call this when
225
- // the promise resolves. The old texture is used until then
226
-
227
-
228
- publicAPI.completedImage = function (doUpdate) {
229
- if (model.nextImage && model.nextImage.complete) {
230
- model.tmTexture.setImage(model.nextImage);
231
- model.nextImage = null;
232
- model._tmAtlas = model._nextAtlas;
233
- model._nextAtlas = null;
234
-
235
- if (doUpdate) {
236
- model.forceViewUpdate = true;
237
- model.renderWindow.render();
238
- }
239
- }
240
224
  }; // create the texture map atlas that contains the rendering of
241
225
  // all the text strings. Only needs to be called when the text strings
242
226
  // have changed (labels and ticks)
@@ -317,19 +301,10 @@ function vtkScalarBarActorHelper(publicAPI, model) {
317
301
  applyTextStyle(model.tmContext, value.textStyle);
318
302
  model.tmContext.fillText(key, 1, value.startingHeight + value.height - 1);
319
303
  });
320
- var image = new Image();
321
- image.src = model.tmCanvas.toDataURL('image/png');
322
- model.nextImage = image;
323
- model._nextAtlas = newTmAtlas;
324
-
325
- if (image.complete) {
326
- publicAPI.completedImage(false);
327
- } else {
328
- image.addEventListener('load', function () {
329
- publicAPI.completedImage(true);
330
- });
331
- }
304
+ model.tmTexture.setCanvas(model.tmCanvas); // mark as modified since the canvas typically doesn't change
332
305
 
306
+ model.tmTexture.modified();
307
+ model._tmAtlas = newTmAtlas;
333
308
  return results;
334
309
  };
335
310
 
@@ -13,14 +13,52 @@ function vtkTexture(publicAPI, model) {
13
13
  publicAPI.modified();
14
14
  };
15
15
 
16
+ publicAPI.setJsImageData = function (imageData) {
17
+ if (model.jsImageData === imageData) {
18
+ return;
19
+ } // clear other entries
20
+
21
+
22
+ if (imageData !== null) {
23
+ publicAPI.setInputData(null);
24
+ publicAPI.setInputConnection(null);
25
+ model.image = null;
26
+ model.canvas = null;
27
+ }
28
+
29
+ model.jsImageData = imageData;
30
+ model.imageLoaded = true;
31
+ publicAPI.modified();
32
+ };
33
+
34
+ publicAPI.setCanvas = function (canvas) {
35
+ if (model.canvas === canvas) {
36
+ return;
37
+ } // clear other entries
38
+
39
+
40
+ if (canvas !== null) {
41
+ publicAPI.setInputData(null);
42
+ publicAPI.setInputConnection(null);
43
+ model.image = null;
44
+ model.jsImageData = null;
45
+ }
46
+
47
+ model.canvas = canvas;
48
+ publicAPI.modified();
49
+ };
50
+
16
51
  publicAPI.setImage = function (image) {
17
52
  if (model.image === image) {
18
53
  return;
19
- }
54
+ } // clear other entries
55
+
20
56
 
21
57
  if (image !== null) {
22
58
  publicAPI.setInputData(null);
23
59
  publicAPI.setInputConnection(null);
60
+ model.canvas = null;
61
+ model.jsImageData = null;
24
62
  }
25
63
 
26
64
  model.image = image;
@@ -44,7 +82,9 @@ var DEFAULT_VALUES = {
44
82
  interpolate: false,
45
83
  edgeClamp: false,
46
84
  image: null,
47
- imageLoaded: false
85
+ canvas: null,
86
+ imageLoaded: false,
87
+ jsImageData: null
48
88
  }; // ----------------------------------------------------------------------------
49
89
 
50
90
  function extend(publicAPI, model) {
@@ -53,8 +93,8 @@ function extend(publicAPI, model) {
53
93
 
54
94
  macro.obj(publicAPI, model);
55
95
  macro.algo(publicAPI, model, 6, 0);
56
- macro.get(publicAPI, model, ['imageLoaded']);
57
- macro.setGet(publicAPI, model, ['repeat', 'edgeClamp', 'interpolate', 'image']);
96
+ macro.get(publicAPI, model, ['canvas', 'image', 'jsImageData', 'imageLoaded']);
97
+ macro.setGet(publicAPI, model, ['repeat', 'edgeClamp', 'interpolate']);
58
98
  vtkTexture(publicAPI, model);
59
99
  } // ----------------------------------------------------------------------------
60
100
 
@@ -78,7 +78,36 @@ function vtkOpenGLTexture(publicAPI, model) {
78
78
  publicAPI.sendParameters();
79
79
  model.textureBuildTime.modified();
80
80
  }
81
- } // if we have Inputdata
81
+ } // if we have a canvas
82
+
83
+
84
+ if (model.renderable.getCanvas() !== null) {
85
+ if (model.renderable.getInterpolate()) {
86
+ model.generateMipmap = true;
87
+ publicAPI.setMinificationFilter(Filter.LINEAR_MIPMAP_LINEAR);
88
+ }
89
+
90
+ var canvas = model.renderable.getCanvas();
91
+ publicAPI.create2DFromRaw(canvas.width, canvas.height, 4, VtkDataTypes.UNSIGNED_CHAR, canvas, true);
92
+ publicAPI.activate();
93
+ publicAPI.sendParameters();
94
+ model.textureBuildTime.modified();
95
+ } // if we have jsImageData
96
+
97
+
98
+ if (model.renderable.getJsImageData() !== null) {
99
+ var jsid = model.renderable.getJsImageData();
100
+
101
+ if (model.renderable.getInterpolate()) {
102
+ model.generateMipmap = true;
103
+ publicAPI.setMinificationFilter(Filter.LINEAR_MIPMAP_LINEAR);
104
+ }
105
+
106
+ publicAPI.create2DFromRaw(jsid.width, jsid.height, 4, VtkDataTypes.UNSIGNED_CHAR, jsid.data, true);
107
+ publicAPI.activate();
108
+ publicAPI.sendParameters();
109
+ model.textureBuildTime.modified();
110
+ } // if we have InputData
82
111
 
83
112
 
84
113
  var input = model.renderable.getInputData(0);
@@ -678,6 +707,7 @@ function vtkOpenGLTexture(publicAPI, model) {
678
707
 
679
708
 
680
709
  publicAPI.create2DFromRaw = function (width, height, numComps, dataType, data) {
710
+ var flip = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : false;
681
711
  // Now determine the texture parameters using the arguments.
682
712
  publicAPI.getOpenGLDataType(dataType);
683
713
  publicAPI.getInternalFormat(dataType, numComps);
@@ -701,13 +731,18 @@ function vtkOpenGLTexture(publicAPI, model) {
701
731
  var dataArray = [data];
702
732
  var pixData = updateArrayDataType(dataType, dataArray);
703
733
  var scaledData = scaleTextureToHighestPowerOfTwo(pixData); // Source texture data from the PBO.
704
- // model.context.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true);
705
734
 
735
+ model.context.pixelStorei(model.context.UNPACK_FLIP_Y_WEBGL, flip);
706
736
  model.context.pixelStorei(model.context.UNPACK_ALIGNMENT, 1);
707
737
  model.context.texImage2D(model.target, 0, model.internalFormat, model.width, model.height, 0, model.format, model.openGLDataType, scaledData[0]);
708
738
 
709
739
  if (model.generateMipmap) {
710
740
  model.context.generateMipmap(model.target);
741
+ } // always reset the flip
742
+
743
+
744
+ if (flip) {
745
+ model.context.pixelStorei(model.context.UNPACK_FLIP_Y_WEBGL, false);
711
746
  }
712
747
 
713
748
  publicAPI.deactivate();
@@ -867,15 +902,7 @@ function vtkOpenGLTexture(publicAPI, model) {
867
902
  var ctx = canvas.getContext('2d');
868
903
  ctx.translate(0, canvas.height);
869
904
  ctx.scale(1, -1);
870
- ctx.drawImage(image, 0, 0, image.width, image.height, 0, 0, canvas.width, canvas.height); // In Chrome 69 on Windows and Ubuntu, there is a bug that prevents some
871
- // canvases from working properly with webGL textures. By getting any
872
- // image data from the canvas, this works around the bug. See
873
- // https://bugs.chromium.org/p/chromium/issues/detail?id=896307
874
-
875
- if (navigator.userAgent.indexOf('Chrome/69') >= 0) {
876
- ctx.getImageData(0, 0, 1, 1);
877
- }
878
-
905
+ ctx.drawImage(image, 0, 0, image.width, image.height, 0, 0, canvas.width, canvas.height);
879
906
  var safeImage = canvas;
880
907
  model.context.texImage2D(model.target, 0, model.internalFormat, model.format, model.openGLDataType, safeImage);
881
908
 
@@ -432,7 +432,7 @@ function vtkWebGPUPolyDataMapper(publicAPI, model) {
432
432
  var textures = actor.getTextures();
433
433
 
434
434
  for (var i = 0; i < textures.length; i++) {
435
- if (textures[i].getInputData()) {
435
+ if (textures[i].getInputData() || textures[i].getJsImageData() || textures[i].getCanvas()) {
436
436
  newTextures.push(textures[i]);
437
437
  }
438
438
 
@@ -445,7 +445,9 @@ function vtkWebGPUPolyDataMapper(publicAPI, model) {
445
445
 
446
446
  for (var _i = 0; _i < newTextures.length; _i++) {
447
447
  var srcTexture = newTextures[_i];
448
- var treq = {};
448
+ var treq = {
449
+ time: srcTexture.getMTime()
450
+ };
449
451
 
450
452
  if (srcTexture.getInputData()) {
451
453
  treq.imageData = srcTexture.getInputData();
@@ -453,6 +455,12 @@ function vtkWebGPUPolyDataMapper(publicAPI, model) {
453
455
  } else if (srcTexture.getImage()) {
454
456
  treq.image = srcTexture.getImage();
455
457
  treq.owner = treq.image;
458
+ } else if (srcTexture.getJsImageData()) {
459
+ treq.jsImageData = srcTexture.getJsImageData();
460
+ treq.owner = treq.jsImageData;
461
+ } else if (srcTexture.getCanvas()) {
462
+ treq.canvas = srcTexture.getCanvas();
463
+ treq.owner = treq.canvas;
456
464
  }
457
465
 
458
466
  var newTex = model.device.getTextureManager().getTexture(treq);
@@ -21,7 +21,7 @@ function vtkWebGPUTexture(publicAPI, model) {
21
21
  model.height = options.height;
22
22
  model.depth = options.depth ? options.depth : 1;
23
23
  var dimension = model.depth === 1 ? '2d' : '3d';
24
- model.format = options.format ? options.format : 'rgbaunorm';
24
+ model.format = options.format ? options.format : 'rgba8unorm';
25
25
  /* eslint-disable no-undef */
26
26
 
27
27
  /* eslint-disable no-bitwise */
@@ -47,7 +47,7 @@ function vtkWebGPUTexture(publicAPI, model) {
47
47
  model.width = options.width;
48
48
  model.height = options.height;
49
49
  model.depth = options.depth ? options.depth : 1;
50
- model.format = options.format ? options.format : 'rgbaunorm';
50
+ model.format = options.format ? options.format : 'rgba8unorm';
51
51
  /* eslint-disable no-undef */
52
52
 
53
53
  /* eslint-disable no-bitwise */
@@ -60,6 +60,27 @@ function vtkWebGPUTexture(publicAPI, model) {
60
60
 
61
61
 
62
62
  publicAPI.writeImageData = function (req) {
63
+ if (req.canvas) {
64
+ model.device.getHandle().queue.copyExternalImageToTexture({
65
+ source: req.canvas,
66
+ flipY: req.flip
67
+ }, {
68
+ texture: model.handle,
69
+ premultipliedAlpha: true
70
+ }, [model.width, model.height, model.depth]);
71
+ model.ready = true;
72
+ return;
73
+ }
74
+
75
+ if (req.jsImageData && !req.nativeArray) {
76
+ req.width = req.jsImageData.width;
77
+ req.height = req.jsImageData.height;
78
+ req.depth = 1;
79
+ req.format = 'rgba8unorm';
80
+ req.flip = true;
81
+ req.nativeArray = req.jsImageData.data;
82
+ }
83
+
63
84
  var tDetails = vtkWebGPUTypes.getDetailsFromTextureFormat(model.format);
64
85
  var bufferBytesPerRow = model.width * tDetails.stride;
65
86
 
@@ -64,11 +64,36 @@ function vtkWebGPUTextureManager(publicAPI, model) {
64
64
 
65
65
 
66
66
  if (req.image) {
67
- req.time = 0;
68
67
  req.width = req.image.width;
69
68
  req.height = req.image.height;
70
69
  req.depth = 1;
71
70
  req.format = 'rgba8unorm';
71
+ } // fill in based on js imageData
72
+
73
+
74
+ if (req.jsImageData) {
75
+ req.width = req.jsImageData.width;
76
+ req.height = req.jsImageData.height;
77
+ req.depth = 1;
78
+ req.format = 'rgba8unorm';
79
+ req.flip = true;
80
+ req.nativeArray = req.jsImageData.data;
81
+ }
82
+
83
+ if (req.canvas) {
84
+ req.width = req.canvas.width;
85
+ req.height = req.canvas.height;
86
+ req.depth = 1;
87
+ req.format = 'rgba8unorm';
88
+ req.flip = true;
89
+ /* eslint-disable no-undef */
90
+
91
+ /* eslint-disable no-bitwise */
92
+
93
+ req.usage = GPUTextureUsage.TEXTURE_BINDING | GPUTextureUsage.COPY_DST | GPUTextureUsage.RENDER_ATTACHMENT;
94
+ /* eslint-enable no-undef */
95
+
96
+ /* eslint-enable no-bitwise */
72
97
  }
73
98
  } // create a texture (used by getTexture)
74
99
 
@@ -79,10 +104,11 @@ function vtkWebGPUTextureManager(publicAPI, model) {
79
104
  width: req.width,
80
105
  height: req.height,
81
106
  depth: req.depth,
82
- format: req.format
107
+ format: req.format,
108
+ usage: req.usage
83
109
  }); // fill the texture if we have data
84
110
 
85
- if (req.nativeArray || req.image) {
111
+ if (req.nativeArray || req.image || req.canvas) {
86
112
  newTex.writeImageData(req);
87
113
  }
88
114
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kitware/vtk.js",
3
- "version": "22.5.4",
3
+ "version": "22.5.5",
4
4
  "description": "Visualization Toolkit for the Web",
5
5
  "keywords": [
6
6
  "3d",