@kitware/vtk.js 22.1.7 → 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.
|
@@ -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.
|
|
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
|
|
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.
|
|
679
|
-
|
|
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
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
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 (
|
|
717
|
-
model.
|
|
737
|
+
if (model._smallViewportHeight > size[1]) {
|
|
738
|
+
model._smallViewportHeight = size[1];
|
|
718
739
|
}
|
|
719
740
|
|
|
720
|
-
model.
|
|
721
|
-
|
|
722
|
-
|
|
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(
|
|
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] !==
|
|
758
|
-
model.framebuffer.create(
|
|
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,
|
|
769
|
-
model.fvp = [
|
|
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.
|
|
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());
|
|
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));
|
|
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
|
|