Working passing of key matrices between geojs and vtk-js
The caveat is that geojs needs to call resetCamera and setClippingRange
on vtk-js camera.
MODIFY
src/camera.js
src/camera.js
// reset view to the identity
this._resetView();
+ console.log('center', center, 'size', size, 'rotation', rotation);
w = Math.abs(size.width);
h = Math.abs(size.height);
c_ar = w / h;
scale[1] = 2 / h;
}
+ console.log('Before scale', this._view);
scale[2] = 1;
this._scale(scale);
+ console.log('After scale', this._view);
+ console.log('Before rotation', this._view);
if (rotation) {
this._rotate(rotation);
+ console.log('After rotation', this._view);
}
// translate to the new center.
translate[1] = -center.y;
translate[2] = 0;
+ console.log('Before Translation', this._view);
this._translate(translate);
+ console.log('After Translation', this._view);
return this;
};

MODIFY
src/vtkjs/pointFeature.js
src/vtkjs/pointFeature.js
@@ -64,7 +64,8 @@ var vtkjs_pointFeature = function (arg) {
////////////////////////////////////////////////////////////////////////////
this._build = function () {
var i, j, i3, posVal, posFunc,
- radius, radiusVal, nonzeroZ,
+ radius, radiusVal,
+ // nonzeroZ,
numPts = m_this.data().length,
position = new Array(numPts * 3),
data = m_this.data(),
@@ -84,8 +85,10 @@ var vtkjs_pointFeature = function (arg) {
posVal = posFunc(data[i]);
position[i3] = posVal.x;
position[i3 + 1] = posVal.y;
+ // position[i3 + 2] = 0.0;
position[i3 + 2] = posVal.z || 0;
- nonzeroZ = nonzeroZ || position[i3 + 2];
+ // console.log('Point positions: ', position);
+ // nonzeroZ = nonzeroZ || position[i3 + 2];
}
// position = transform.transformCoordinates(
// m_this.gcs(), m_this.layer().map().gcs(),
@@ -104,7 +107,7 @@ var vtkjs_pointFeature = function (arg) {
var source = vtkSphereSource.newInstance();
source.setRadius(radFunc());
source.setCenter(position[i3], position[i3 + 1], position[i3 + 2]);
- source.setThetaResolution(20);
+ source.setThetaResolution(30);
var actor = vtkActor.newInstance();
var mapper = vtkMapper.newInstance();
mapper.setInputConnection(source.getOutputPort());
@@ -136,6 +139,11 @@ var vtkjs_pointFeature = function (arg) {
m_this.updateTime().getMTime() < m_this.getMTime()) {
m_this._build();
}
+ // if (m_actors) {
+ // m_actors.forEach(function(actor) {
+ // actor.getMapper().update();
+ // });
+ // }
m_this.updateTime().modified();
};

MODIFY
src/vtkjs/vtkjsRenderer.js
src/vtkjs/vtkjsRenderer.js
@@ -42,6 +42,7 @@ var vtkjsRenderer = function (arg) {
const fullScreenRenderer = vtkFullScreenRenderWindow.newInstance({ background: [0.1, 0.5, 0.5] });
const vtkjsren = fullScreenRenderer.getRenderer();
vtkjsren.getActiveCamera().setUserProvidedProjectionMatrix(true);
+ vtkjsren.getActiveCamera().setUserProvidedViewMatrix(true);
const renderWindow = fullScreenRenderer.getRenderWindow();
/// TODO: Move this API to the base class
@@ -135,9 +136,8 @@ var vtkjsRenderer = function (arg) {
// m_this.layer().map().scheduleAnimationFrame(this._renderFrame, true);
// return m_this;
- // m_this.contextRenderer().resetCamera();
- // renderWindow.render();
m_this.contextRenderer().resetCamera();
+ // renderWindow.render();
m_this._updateRendererCamera();
renderWindow.render();
};
@@ -182,8 +182,18 @@ var vtkjsRenderer = function (arg) {
// console.log(`VTKJS: projMat: ${m_this.contextRenderer().getActiveCamera().getProjectionMatrix()}`);
// console.log(`GEOJS: projMat: ${proj}`);
// m_this.contextRenderer().getActiveCamera().computeViewParametersFromPhysicalMatrix(view);
- m_this.contextRenderer().getActiveCamera().setViewMatrix(view);
- m_this.contextRenderer().getActiveCamera().setProjectionMatrix(proj);
+ const viewmat = mat4.create();
+ mat4.copy(viewmat, view);
+ // viewmat[0] = 1;
+ // viewmat[5] = 1;
+ // mat4.transpose(viewmat, viewmat);
+ const projmat = mat4.create();
+ mat4.copy(projmat, proj);
+ m_this.contextRenderer().getActiveCamera().setClippingRange(camera.constructor.bounds.near,
+ camera.constructor.bounds.far);
+ m_this.contextRenderer().getActiveCamera().setViewMatrix(viewmat);
+ m_this.contextRenderer().getActiveCamera().setProjectionMatrix(projmat);
+ // console.log('VTK: ', m_this.contextRenderer().getActiveCamera().getViewMatrix());
// camera.view = m_this.contextRenderer().getActiveCamera().getViewMatrix();
// camera.projectionMatrix = m_this.contextRenderer().getActiveCamera().getProjectionMatrix();
};

Working passing of key matrices between geojs and vtk-js

The caveat is that geojs needs to call resetCamera and setClippingRange
on vtk-js camera.