@kitware/vtk.js 22.1.4 → 22.1.8

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.
@@ -56,9 +56,7 @@ function vtkMouseBoxSelectionManipulator(publicAPI, model) {
56
56
 
57
57
  var _container$getBoundin = container.getBoundingClientRect(),
58
58
  width = _container$getBoundin.width,
59
- height = _container$getBoundin.height,
60
- top = _container$getBoundin.top,
61
- left = _container$getBoundin.left;
59
+ height = _container$getBoundin.height;
62
60
 
63
61
  var _getBounds = getBounds(),
64
62
  _getBounds2 = _slicedToArray(_getBounds, 4),
@@ -67,10 +65,8 @@ function vtkMouseBoxSelectionManipulator(publicAPI, model) {
67
65
  yMin = _getBounds2[2],
68
66
  yMax = _getBounds2[3];
69
67
 
70
- var xShift = left + window.scrollX;
71
- var yShift = top + window.scrollY;
72
- div.style.left = "".concat(xShift + width * xMin / viewWidth, "px");
73
- div.style.top = "".concat(yShift + height - height * yMax / viewHeight, "px");
68
+ div.style.left = "".concat(width * xMin / viewWidth, "px");
69
+ div.style.top = "".concat(height - height * yMax / viewHeight, "px");
74
70
  div.style.width = "".concat(width * (xMax - xMin) / viewWidth, "px");
75
71
  div.style.height = "".concat(height * (yMax - yMin) / viewHeight, "px");
76
72
  } //-------------------------------------------------------------------------
@@ -80,15 +76,21 @@ function vtkMouseBoxSelectionManipulator(publicAPI, model) {
80
76
  previousPosition = position;
81
77
 
82
78
  if (model.renderSelection) {
79
+ var _view;
80
+
83
81
  // Need window size and location to convert to style
84
82
  if (!view) {
85
83
  view = interactor.getView();
86
84
  }
87
85
 
88
- if (!container && view) {
86
+ if (!container && (_view = view) !== null && _view !== void 0 && _view.getContainer) {
89
87
  container = view.getContainer();
90
88
  }
91
89
 
90
+ if (!container) {
91
+ container = model.container;
92
+ }
93
+
92
94
  if (!div) {
93
95
  div = document.createElement('div');
94
96
  applyStyle(div, model.selectionStyle);
@@ -155,6 +157,7 @@ function vtkMouseBoxSelectionManipulator(publicAPI, model) {
155
157
 
156
158
  function DEFAULT_VALUES(initialValues) {
157
159
  return _objectSpread(_objectSpread({
160
+ // container: null,
158
161
  renderSelection: true
159
162
  }, initialValues), {}, {
160
163
  selectionStyle: _objectSpread(_objectSpread({}, DEFAULT_STYLE), initialValues.selectionStyle)
@@ -172,7 +175,7 @@ function extend(publicAPI, model) {
172
175
 
173
176
  event(publicAPI, model, 'BoxSelectInput'); // Trigger while dragging
174
177
 
175
- setGet(publicAPI, model, ['renderSelection', 'selectionStyle']); // Object specific methods
178
+ setGet(publicAPI, model, ['renderSelection', 'selectionStyle', 'container']); // Object specific methods
176
179
 
177
180
  vtkMouseBoxSelectionManipulator(publicAPI, model);
178
181
  } // ----------------------------------------------------------------------------
@@ -328,8 +328,6 @@ function vtkRenderWindowInteractor(publicAPI, model) {
328
328
  if (animationRequesters.size === 1 && !model.xrAnimation) {
329
329
  model._animationStartTime = Date.now();
330
330
  model._animationFrameCount = 0;
331
- model.lastFrameTime = 0.1;
332
- model.lastFrameStart = Date.now();
333
331
  model.animationRequest = requestAnimationFrame(publicAPI.handleAnimation);
334
332
  publicAPI.startAnimationEvent();
335
333
  }
@@ -375,7 +373,7 @@ function vtkRenderWindowInteractor(publicAPI, model) {
375
373
  model.xrAnimation = false;
376
374
 
377
375
  if (animationRequesters.size !== 0) {
378
- model.FrameTime = -1;
376
+ model.recentAnimationFrameRate = 10.0;
379
377
  model.animationRequest = requestAnimationFrame(publicAPI.handleAnimation);
380
378
  }
381
379
  };
@@ -456,19 +454,12 @@ function vtkRenderWindowInteractor(publicAPI, model) {
456
454
 
457
455
  if (currTime - model._animationStartTime > 1000.0 && model._animationFrameCount > 1) {
458
456
  model.recentAnimationFrameRate = 1000.0 * (model._animationFrameCount - 1) / (currTime - model._animationStartTime);
457
+ model.lastFrameTime = 1.0 / model.recentAnimationFrameRate;
459
458
  publicAPI.animationFrameRateUpdateEvent();
460
459
  model._animationStartTime = currTime;
461
460
  model._animationFrameCount = 1;
462
461
  }
463
462
 
464
- if (model.FrameTime === -1.0) {
465
- model.lastFrameTime = 0.1;
466
- } else {
467
- model.lastFrameTime = (currTime - model.lastFrameStart) / 1000.0;
468
- }
469
-
470
- model.lastFrameTime = Math.max(0.01, model.lastFrameTime);
471
- model.lastFrameStart = currTime;
472
463
  publicAPI.animationEvent();
473
464
  forceRender();
474
465
  model.animationRequest = requestAnimationFrame(publicAPI.handleAnimation);
@@ -933,7 +924,6 @@ function vtkRenderWindowInteractor(publicAPI, model) {
933
924
  };
934
925
 
935
926
  publicAPI.handleVisibilityChange = function () {
936
- model.lastFrameStart = Date.now();
937
927
  model._animationStartTime = Date.now();
938
928
  model._animationFrameCount = 0;
939
929
  };
@@ -957,7 +947,7 @@ function vtkRenderWindowInteractor(publicAPI, model) {
957
947
 
958
948
  superDelete();
959
949
  }; // Use the Page Visibility API to detect when we switch away from or back to
960
- // this tab, and reset the lastFrameStart. When tabs are not active, browsers
950
+ // this tab, and reset the animationFrameStart. When tabs are not active, browsers
961
951
  // will stop calling requestAnimationFrame callbacks.
962
952
 
963
953
 
@@ -1,5 +1,5 @@
1
1
  import _defineProperty from '@babel/runtime/helpers/defineProperty';
2
- import { newInstance as newInstance$1, obj, setGet, vtkWarningMacro as vtkWarningMacro$1, vtkErrorMacro as vtkErrorMacro$1 } from '../../macros.js';
2
+ import { newInstance as newInstance$1, obj, setGet, chain, vtkWarningMacro as vtkWarningMacro$1, vtkErrorMacro as vtkErrorMacro$1 } from '../../macros.js';
3
3
  import { mat4, mat3, vec3 } from 'gl-matrix';
4
4
  import vtkDataArray from '../../Common/Core/DataArray.js';
5
5
  import { VtkDataTypes } from '../../Common/Core/DataArray/Constants.js';
@@ -672,90 +672,86 @@ function vtkOpenGLVolumeMapper(publicAPI, model) {
672
672
  program.setUniform3fv("vClipPlaneNormals", clipPlaneNormals);
673
673
  program.setUniformfv("vClipPlaneDistances", clipPlaneDistances);
674
674
  }
675
- };
675
+ }; // unsubscribe from our listeners
676
+
677
+
678
+ publicAPI.delete = chain(function () {
679
+ if (model._animationRateSubscription) {
680
+ model._animationRateSubscription.unsubscribe();
681
+
682
+ model._animationRateSubscription = null;
683
+ }
684
+ }, publicAPI.delete);
676
685
 
677
686
  publicAPI.getRenderTargetSize = function () {
678
- if (model.lastXYF > 1.43) {
679
- var sz = model.framebuffer.getSize();
680
- return [model.fvp[0] * sz[0], model.fvp[1] * sz[1]];
687
+ if (model._useSmallViewport) {
688
+ return [model._smallViewportWidth, model._smallViewportHeight];
681
689
  }
682
690
 
683
691
  return model.openGLRenderWindow.getFramebufferSize();
684
692
  };
685
693
 
686
694
  publicAPI.renderPieceStart = function (ren, actor) {
687
- if (model.renderable.getAutoAdjustSampleDistances()) {
688
- var rwi = ren.getVTKWindow().getInteractor();
689
- var rft = rwi.getLastFrameTime(); // console.log(`last frame time ${Math.floor(1.0 / rft)}`);
690
- // frame time is typically for a couple frames prior
691
- // which makes it messy, so keep long running averages
692
- // of frame times and pixels rendered
693
-
694
- model.avgFrameTime = 0.97 * model.avgFrameTime + 0.03 * rft;
695
- model.avgWindowArea = 0.97 * model.avgWindowArea + 0.03 / (model.lastXYF * model.lastXYF);
696
-
697
- if (ren.getVTKWindow().getInteractor().isAnimating()) {
698
- // compute target xy factor
699
- var txyf = Math.sqrt(model.avgFrameTime * rwi.getDesiredUpdateRate() / model.avgWindowArea); // limit subsampling to a factor of 10
700
-
701
- if (txyf > 10.0) {
702
- txyf = 10.0;
703
- }
695
+ var rwi = ren.getVTKWindow().getInteractor();
696
+ model._useSmallViewport = false;
697
+
698
+ if (rwi.isAnimating() && model._lastScale > 1.5) {
699
+ model._useSmallViewport = true;
700
+ }
701
+
702
+ if (!model._animationRateSubscription) {
703
+ // when the animation frame rate changes recompute the scale factor
704
+ model._animationRateSubscription = rwi.onAnimationFrameRateUpdate(function () {
705
+ if (model.renderable.getAutoAdjustSampleDistances()) {
706
+ var frate = rwi.getRecentAnimationFrameRate();
707
+ var adjustment = rwi.getDesiredUpdateRate() / frate; // only change if we are off by 15%
708
+
709
+ if (adjustment > 1.15 || adjustment < 0.85) {
710
+ model._lastScale *= adjustment;
711
+ } // clamp scale to some reasonable values.
712
+ // Below 1.5 we will just be using full resolution as that is close enough
713
+ // Above 400 seems like a lot so we limit to that 1/20th per axis
704
714
 
705
- model.targetXYF = txyf;
706
- } else {
707
- model.targetXYF = Math.sqrt(model.avgFrameTime * rwi.getStillUpdateRate() / model.avgWindowArea);
708
- } // have some inertia to change states around 1.43
709
715
 
716
+ if (model._lastScale > 400) {
717
+ model._lastScale = 400;
718
+ }
719
+
720
+ if (model._lastScale < 1.5) {
721
+ model._lastScale = 1.5;
722
+ }
723
+ } else {
724
+ model._lastScale = model.renderable.getImageSampleDistance() * model.renderable.getImageSampleDistance();
725
+ }
726
+
727
+ var size = model.openGLRenderWindow.getFramebufferSize();
728
+ model._smallViewportWidth = Math.ceil(size[0] / Math.sqrt(model._lastScale));
729
+ model._smallViewportHeight = Math.ceil(size[1] / Math.sqrt(model._lastScale));
730
+ });
731
+ } // use/create/resize framebuffer if needed
710
732
 
711
- if (model.targetXYF < 1.53 && model.targetXYF > 1.33) {
712
- model.targetXYF = model.lastXYF;
713
- } // and add some inertia to change at all
714
733
 
734
+ if (model._useSmallViewport) {
735
+ var size = model.openGLRenderWindow.getFramebufferSize(); // adjust viewportSize to always be at most the dest fo size
715
736
 
716
- if (Math.abs(1.0 - model.targetXYF / model.lastXYF) < 0.1) {
717
- model.targetXYF = model.lastXYF;
737
+ if (model._smallViewportHeight > size[1]) {
738
+ model._smallViewportHeight = size[1];
718
739
  }
719
740
 
720
- model.lastXYF = model.targetXYF;
721
- } else {
722
- model.lastXYF = model.renderable.getImageSampleDistance();
723
- } // only use FBO beyond this value
724
-
725
-
726
- if (model.lastXYF <= 1.43) {
727
- model.lastXYF = 1.0;
728
- } // console.log(`last target ${model.lastXYF} ${model.targetXYF}`);
729
- // console.log(`awin aft ${model.avgWindowArea} ${model.avgFrameTime}`);
730
-
731
-
732
- var xyf = model.lastXYF;
733
- var size = model.openGLRenderWindow.getFramebufferSize(); // const newSize = [
734
- // Math.floor((size[0] / xyf) + 0.5),
735
- // Math.floor((size[1] / xyf) + 0.5)];
736
- // const diag = vtkBoundingBox.getDiagonalLength(model.currentInput.getBounds());
737
- // // so what is the resulting sample size roughly
738
- // console.log(`sam size ${diag / newSize[0]} ${diag / newSize[1]} ${model.renderable.getImageSampleDistance()}`);
739
- // // if the sample distance is getting far from the image sample dist
740
- // if (2.0 * diag / (newSize[0] + newSize[1]) > 4 * model.renderable.getSampleDistance()) {
741
- // model.renderable.setSampleDistance(4.0 * model.renderable.getSampleDistance());
742
- // }
743
- // if (2.0 * diag / (newSize[0] + newSize[1]) < 0.25 * model.renderable.getSampleDistance()) {
744
- // model.renderable.setSampleDistance(0.25 * model.renderable.getSampleDistance());
745
- // }
746
- // create/resize framebuffer if needed
741
+ if (model._smallViewportWidth > size[0]) {
742
+ model._smallViewportWidth = size[0];
743
+ }
747
744
 
748
- if (xyf > 1.43) {
749
745
  model.framebuffer.saveCurrentBindingsAndBuffers();
750
746
 
751
747
  if (model.framebuffer.getGLFramebuffer() === null) {
752
- model.framebuffer.create(Math.floor(size[0] * 0.7), Math.floor(size[1] * 0.7));
748
+ model.framebuffer.create(size[0], size[1]);
753
749
  model.framebuffer.populateFramebuffer();
754
750
  } else {
755
751
  var fbSize = model.framebuffer.getSize();
756
752
 
757
- if (fbSize[0] !== Math.floor(size[0] * 0.7) || fbSize[1] !== Math.floor(size[1] * 0.7)) {
758
- model.framebuffer.create(Math.floor(size[0] * 0.7), Math.floor(size[1] * 0.7));
753
+ if (fbSize[0] !== size[0] || fbSize[1] !== size[1]) {
754
+ model.framebuffer.create(size[0], size[1]);
759
755
  model.framebuffer.populateFramebuffer();
760
756
  }
761
757
  }
@@ -765,8 +761,8 @@ function vtkOpenGLVolumeMapper(publicAPI, model) {
765
761
  gl.clearColor(0.0, 0.0, 0.0, 0.0);
766
762
  gl.colorMask(true, true, true, true);
767
763
  gl.clear(gl.COLOR_BUFFER_BIT);
768
- gl.viewport(0, 0, size[0] / xyf, size[1] / xyf);
769
- model.fvp = [Math.floor(size[0] / xyf) / Math.floor(size[0] * 0.7), Math.floor(size[1] / xyf) / Math.floor(size[1] * 0.7)];
764
+ gl.viewport(0, 0, model._smallViewportWidth, model._smallViewportHeight);
765
+ model.fvp = [model._smallViewportWidth / size[0], model._smallViewportHeight / size[1]];
770
766
  }
771
767
 
772
768
  model.context.disable(model.context.DEPTH_TEST); // make sure the BOs are up to date
@@ -817,7 +813,7 @@ function vtkOpenGLVolumeMapper(publicAPI, model) {
817
813
  model.zBufferTexture.deactivate();
818
814
  }
819
815
 
820
- if (model.lastXYF > 1.43) {
816
+ if (model._useSmallViewport) {
821
817
  // now copy the framebuffer with the volume into the
822
818
  // regular buffer
823
819
  model.framebuffer.restorePreviousBindingsAndBuffers();
@@ -1006,8 +1002,7 @@ function vtkOpenGLVolumeMapper(publicAPI, model) {
1006
1002
  var dims = image.getDimensions();
1007
1003
  model.scalarTexture.releaseGraphicsResources(model.openGLRenderWindow);
1008
1004
  model.scalarTexture.resetFormatAndType();
1009
- model.scalarTexture.create3DFilterableFromRaw(dims[0], dims[1], dims[2], numComp, scalars.getDataType(), scalars.getData(), model.renderable.getPreferSizeOverAccuracy()); // console.log(model.scalarTexture.get());
1010
-
1005
+ model.scalarTexture.create3DFilterableFromRaw(dims[0], dims[1], dims[2], numComp, scalars.getDataType(), scalars.getData(), model.renderable.getPreferSizeOverAccuracy());
1011
1006
  model.scalarTextureString = toString;
1012
1007
  }
1013
1008
 
@@ -1125,7 +1120,8 @@ function extend(publicAPI, model) {
1125
1120
  model.idxNormalMatrix = mat3.identity(new Float64Array(9));
1126
1121
  model.modelToView = mat4.identity(new Float64Array(16));
1127
1122
  model.projectionToView = mat4.identity(new Float64Array(16));
1128
- model.projectionToWorld = mat4.identity(new Float64Array(16)); // Build VTK API
1123
+ model.projectionToWorld = mat4.identity(new Float64Array(16));
1124
+ model._lastScale = 1.0; // Build VTK API
1129
1125
 
1130
1126
  setGet(publicAPI, model, ['context']); // Object methods
1131
1127
 
@@ -3,11 +3,11 @@ import vtkBoundingBox, { STATIC } from '../../../Common/DataModel/BoundingBox.js
3
3
  import vtkCubeSource from '../../../Filters/Sources/CubeSource.js';
4
4
  import vtkCutter from '../../../Filters/Core/Cutter.js';
5
5
  import vtkPlane from '../../../Common/DataModel/Plane.js';
6
- import { g as subtract, l as normalize, j as cross, Q as multiplyAccumulate, S as signedAngleBetweenVectors } from '../../../Common/Core/Math/index.js';
6
+ import { g as subtract, l as normalize, j as cross, t as multiplyScalar, Q as multiplyAccumulate, S as signedAngleBetweenVectors } from '../../../Common/Core/Math/index.js';
7
7
  import vtkMatrixBuilder from '../../../Common/Core/MatrixBuilder.js';
8
8
  import { ViewTypes } from '../../Core/WidgetManager/Constants.js';
9
9
 
10
- var EPSILON = 0.00001;
10
+ var EPSILON = 10e-7;
11
11
  /**
12
12
  * Fit the plane defined by origin, p1, p2 onto the bounds.
13
13
  * Plane is untouched if does not intersect bounds.
@@ -15,6 +15,7 @@ var EPSILON = 0.00001;
15
15
  * @param {Array} origin
16
16
  * @param {Array} p1
17
17
  * @param {Array} p2
18
+ * @return {Boolean} false if no bounds have been found, else true
18
19
  */
19
20
 
20
21
  function boundPlane(bounds, origin, p1, p2) {
@@ -26,19 +27,26 @@ function boundPlane(bounds, origin, p1, p2) {
26
27
  normalize(v2);
27
28
  var n = [0, 0, 1];
28
29
  cross(v1, v2, n);
29
- normalize(n);
30
+ normalize(n); // Inflate bounds in order to avoid precision error when cutting cubesource
31
+
32
+ var inflatedBounds = _toConsumableArray(bounds);
33
+
34
+ var eps = [].concat(n);
35
+ multiplyScalar(eps, EPSILON);
36
+ vtkBoundingBox.addBounds(inflatedBounds, bounds[0] + eps[0], bounds[1] + eps[0], bounds[2] + eps[1], bounds[3] + eps[1], bounds[4] + eps[2], bounds[5] + eps[2]);
37
+ vtkBoundingBox.addBounds(inflatedBounds, bounds[0] - eps[0], bounds[1] - eps[0], bounds[2] - eps[1], bounds[3] - eps[1], bounds[4] - eps[2], bounds[5] - eps[2]);
30
38
  var plane = vtkPlane.newInstance();
31
39
  plane.setOrigin.apply(plane, _toConsumableArray(origin));
32
40
  plane.setNormal.apply(plane, n);
33
41
  var cubeSource = vtkCubeSource.newInstance();
34
- cubeSource.setBounds(bounds);
42
+ cubeSource.setBounds(inflatedBounds);
35
43
  var cutter = vtkCutter.newInstance();
36
44
  cutter.setCutFunction(plane);
37
45
  cutter.setInputConnection(cubeSource.getOutputPort());
38
46
  var cutBounds = cutter.getOutputData();
39
47
 
40
48
  if (cutBounds.getNumberOfPoints() === 0) {
41
- return;
49
+ return false;
42
50
  }
43
51
 
44
52
  var localBounds = STATIC.computeLocalBounds(cutBounds.getPoints(), v1, v2, n);
@@ -48,6 +56,8 @@ function boundPlane(bounds, origin, p1, p2) {
48
56
  p1[i] = localBounds[1] * v1[i] + localBounds[2] * v2[i] + localBounds[4] * n[i];
49
57
  p2[i] = localBounds[0] * v1[i] + localBounds[3] * v2[i] + localBounds[4] * n[i];
50
58
  }
59
+
60
+ return true;
51
61
  } // Project point (inPoint) to the bounds of the image according to a plane
52
62
  // defined by two vectors (v1, v2)
53
63
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kitware/vtk.js",
3
- "version": "22.1.4",
3
+ "version": "22.1.8",
4
4
  "description": "Visualization Toolkit for the Web",
5
5
  "keywords": [
6
6
  "3d",