Cleaned up vtk implementation
MODIFY
examples/points/main.js
examples/points/main.js
@@ -52,25 +52,25 @@ $(function () {
});
// Create an osm layer with custom tile url for a white background.
- map.createLayer(
- 'osm',
- {
- url: function () {
- return 'white.jpg';
- }
- }
- );
+ // map.createLayer(
+ // 'osm',
+ // {
+ // url: function () {
+ // return 'white.jpg';
+ // }
+ // }
+ // );
- // Create a gl feature layer
- var vglLayer = map.createLayer(
- 'feature',
- {
- renderer: 'vgl'
- }
- );
+ // // Create a gl feature layer
+ // var vglLayer = map.createLayer(
+ // 'feature',
+ // {
+ // renderer: 'vgl'
+ // }
+ // );
// Create an svg feature layer
- var svgLayer = map.createLayer(
+ var vtkjsLayer = map.createLayer(
'feature',
{
renderer: 'vtkjs'
@@ -90,7 +90,7 @@ $(function () {
opacity: 0.1 // fill opacity
};
});
- makePoints(data, vglLayer, vglColor);
+ // makePoints(data, vglLayer, vglColor);
// Generate some data for svg
data = d3.range(2).map(function (i) {
@@ -101,5 +101,8 @@ $(function () {
opacity: 0.1 // fill opacity
};
});
- makePoints(data, svgLayer, svgColor);
+ makePoints(data, vtkjsLayer, svgColor);
+
+ // TODO: For now we need this extra call.
+ map.draw();
});

MODIFY
src/vtkjs/pointFeature.js
src/vtkjs/pointFeature.js
@@ -45,50 +45,8 @@ var vtkjs_pointFeature = function (arg) {
m_dynamicDraw = arg.dynamicDraw === undefined ? false : arg.dynamicDraw,
m_primitiveShape = 'sprite', // arg can change this, below
s_init = this._init,
- s_update = this._update,
- vertexShaderSource = null,
- fragmentShaderSource = null;
+ s_update = this._update;
- function createVertexShader() {
- // TODO
- }
-
- function createFragmentShader() {
- // TODO
- }
-
- function pointPolygon(x, y, w, h) {
- }
-
- function createGLPoints() {
- // TODO
- }
-
- ////////////////////////////////////////////////////////////////////////////
- /**
- * Return list of actors
- *
- * @returns {vgl.actor[]}
- */
- ////////////////////////////////////////////////////////////////////////////
- this.actors = function () {
- // if (!m_actor) {
- // return [];
- // }
- // return [m_actor];
- };
-
- ////////////////////////////////////////////////////////////////////////////
- /**
- * Return the number of vertices used for each point.
- *
- * @returns {Number}
- */
- ////////////////////////////////////////////////////////////////////////////
- this.verticesPerFeature = function () {
- // var unit = pointPolygon(0, 0, 1, 1);
- // return unit.length / 2;
- };
////////////////////////////////////////////////////////////////////////////
/**
@@ -96,99 +54,6 @@ var vtkjs_pointFeature = function (arg) {
*/
////////////////////////////////////////////////////////////////////////////
this._init = function () {
- // var prog = vgl.shaderProgram(),
- // vertexShader = createVertexShader(),
- // fragmentShader = createFragmentShader(),
- // posAttr = vgl.vertexAttribute('pos'),
- // unitAttr = vgl.vertexAttribute('unit'),
- // radAttr = vgl.vertexAttribute('rad'),
- // strokeWidthAttr = vgl.vertexAttribute('strokeWidth'),
- // fillColorAttr = vgl.vertexAttribute('fillColor'),
- // fillAttr = vgl.vertexAttribute('fill'),
- // strokeColorAttr = vgl.vertexAttribute('strokeColor'),
- // strokeAttr = vgl.vertexAttribute('stroke'),
- // fillOpacityAttr = vgl.vertexAttribute('fillOpacity'),
- // strokeOpacityAttr = vgl.vertexAttribute('strokeOpacity'),
- // modelViewUniform = new vgl.modelViewUniform('modelViewMatrix'),
- // projectionUniform = new vgl.projectionUniform('projectionMatrix'),
- // mat = vgl.material(),
- // blend = vgl.blend(),
- // geom = vgl.geometryData(),
- // sourcePositions = vgl.sourceDataP3fv({'name': 'pos'}),
- // sourceUnits = vgl.sourceDataAnyfv(
- // 2, vgl.vertexAttributeKeysIndexed.One, {'name': 'unit'}),
- // sourceRadius = vgl.sourceDataAnyfv(
- // 1, vgl.vertexAttributeKeysIndexed.Two, {'name': 'rad'}),
- // sourceStrokeWidth = vgl.sourceDataAnyfv(
- // 1, vgl.vertexAttributeKeysIndexed.Three, {'name': 'strokeWidth'}),
- // sourceFillColor = vgl.sourceDataAnyfv(
- // 3, vgl.vertexAttributeKeysIndexed.Four, {'name': 'fillColor'}),
- // sourceFill = vgl.sourceDataAnyfv(
- // 1, vgl.vertexAttributeKeysIndexed.Five, {'name': 'fill'}),
- // sourceStrokeColor = vgl.sourceDataAnyfv(
- // 3, vgl.vertexAttributeKeysIndexed.Six, {'name': 'strokeColor'}),
- // sourceStroke = vgl.sourceDataAnyfv(
- // 1, vgl.vertexAttributeKeysIndexed.Seven, {'name': 'stroke'}),
- // sourceAlpha = vgl.sourceDataAnyfv(
- // 1, vgl.vertexAttributeKeysIndexed.Eight, {'name': 'fillOpacity'}),
- // sourceStrokeOpacity = vgl.sourceDataAnyfv(
- // 1, vgl.vertexAttributeKeysIndexed.Nine, {'name': 'strokeOpacity'}),
- // primitive = new vgl.triangles();
-
- // if (m_primitiveShape === 'sprite') {
- // primitive = new vgl.points();
- // }
-
- // m_pixelWidthUniform = new vgl.floatUniform('pixelWidth',
- // 2.0 / m_this.renderer().width());
- // m_aspectUniform = new vgl.floatUniform('aspect',
- // m_this.renderer().width() / m_this.renderer().height());
-
- // s_init.call(m_this, arg);
- // m_mapper = vgl.mapper({dynamicDraw: m_dynamicDraw});
-
- // // TODO: Right now this is ugly but we will fix it.
- // prog.addVertexAttribute(posAttr, vgl.vertexAttributeKeys.Position);
- // if (m_primitiveShape !== 'sprite') {
- // prog.addVertexAttribute(unitAttr, vgl.vertexAttributeKeysIndexed.One);
- // }
-
- // prog.addVertexAttribute(radAttr, vgl.vertexAttributeKeysIndexed.Two);
- // prog.addVertexAttribute(strokeWidthAttr, vgl.vertexAttributeKeysIndexed.Three);
- // prog.addVertexAttribute(fillColorAttr, vgl.vertexAttributeKeysIndexed.Four);
- // prog.addVertexAttribute(fillAttr, vgl.vertexAttributeKeysIndexed.Five);
- // prog.addVertexAttribute(strokeColorAttr, vgl.vertexAttributeKeysIndexed.Six);
- // prog.addVertexAttribute(strokeAttr, vgl.vertexAttributeKeysIndexed.Seven);
- // prog.addVertexAttribute(fillOpacityAttr, vgl.vertexAttributeKeysIndexed.Eight);
- // prog.addVertexAttribute(strokeOpacityAttr, vgl.vertexAttributeKeysIndexed.Nine);
-
- // prog.addUniform(m_pixelWidthUniform);
- // prog.addUniform(m_aspectUniform);
- // prog.addUniform(modelViewUniform);
- // prog.addUniform(projectionUniform);
-
- // prog.addShader(fragmentShader);
- // prog.addShader(vertexShader);
-
- // mat.addAttribute(prog);
- // mat.addAttribute(blend);
-
- // m_actor = vgl.actor();
- // m_actor.setMaterial(mat);
- // m_actor.setMapper(m_mapper);
-
- // geom.addSource(sourcePositions);
- // geom.addSource(sourceUnits);
- // geom.addSource(sourceRadius);
- // geom.addSource(sourceStrokeWidth);
- // geom.addSource(sourceFillColor);
- // geom.addSource(sourceFill);
- // geom.addSource(sourceStrokeColor);
- // geom.addSource(sourceStroke);
- // geom.addSource(sourceAlpha);
- // geom.addSource(sourceStrokeOpacity);
- // geom.addPrimitive(primitive);
- // m_mapper.setGeometryData(geom);
};
////////////////////////////////////////////////////////////////////////////
@@ -213,6 +78,8 @@ var vtkjs_pointFeature = function (arg) {
m_this.renderer().contextRenderer().addActor(actor);
m_actor = actor;
m_this.buildTime().modified();
+
+ console.debug("built vtkjs point feature");
};
////////////////////////////////////////////////////////////////////////////
@@ -226,21 +93,11 @@ var vtkjs_pointFeature = function (arg) {
s_update.call(m_this);
- // For now build if the data or style changes. In the future we may
- // we able to partially update the data using dynamic gl buffers.
if (m_this.dataTime().getMTime() >= m_this.buildTime().getMTime() ||
m_this.updateTime().getMTime() < m_this.getMTime()) {
m_this._build();
}
- // // Update uniforms
- // m_pixelWidthUniform.set(2.0 / m_this.renderer().width());
- // m_aspectUniform.set(m_this.renderer().width() /
- // m_this.renderer().height());
-
- // m_actor.setVisible(m_this.visible());
- // m_actor.material().setBinNumber(m_this.bin());
-
m_this.updateTime().modified();
};
@@ -250,7 +107,7 @@ var vtkjs_pointFeature = function (arg) {
*/
////////////////////////////////////////////////////////////////////////////
this._exit = function () {
- // m_this.renderer().contextRenderer().removeActor(m_actor);
+ m_this.renderer().contextRenderer().removeActor(m_actor);
s_exit();
};

MODIFY
src/vtkjs/vtkjsRenderer.js
src/vtkjs/vtkjsRenderer.js
@@ -93,7 +93,7 @@ var vtkjsRenderer = function (arg) {
return m_this;
}
- // s_init.call(m_this);
+ s_init.call(m_this);
// var canvas = $(document.createElement('canvas'));
// canvas.attr('class', 'webgl-canvas');
@@ -108,10 +108,10 @@ var vtkjsRenderer = function (arg) {
// m_contextRenderer.setLayer(m_viewer.renderWindow().renderers().length);
// }
// m_this.canvas(canvas);
- // /* Initialize the size of the renderer */
- // var map = m_this.layer().map(),
- // mapSize = map.size();
- // m_this._resize(0, 0, mapSize.width, mapSize.height);
+ /* Initialize the size of the renderer */
+ var map = m_this.layer().map(),
+ mapSize = map.size();
+ m_this._resize(0, 0, mapSize.width, mapSize.height);
// return m_this;
};
@@ -131,9 +131,9 @@ var vtkjsRenderer = function (arg) {
// renderWindow.positionAndResize(x, y, w, h);
// m_updateCamera = true;
- // m_this._render();
+ m_this._render();
- // return m_this;
+ return m_this;
};
////////////////////////////////////////////////////////////////////////////
@@ -176,71 +176,71 @@ var vtkjsRenderer = function (arg) {
// s_exit();
};
- this._updateRendererCamera = function () {
- var renderWindow = m_viewer.renderWindow(),
- map = m_this.layer().map(),
- camera = map.camera(),
- rotation = map.rotation() || 0,
- view = camera.view,
- proj = camera.projectionMatrix;
- if (proj[15]) {
- /* we want positive z to be closer to the camera, but webGL does the
- * converse, so reverse the z coordinates. */
- proj = mat4.scale(util.mat4AsArray(), proj, [1, 1, -1]);
- }
- /* A similar kluge as in the base camera class worldToDisplay4. With this,
- * we can show z values from 0 to 1. */
- proj = mat4.translate(util.mat4AsArray(), proj,
- [0, 0, camera.constructor.bounds.far]);
- /* Check if the rotation is a multiple of 90 */
- var basis = Math.PI / 2,
- angle = rotation % basis, // move to range (-pi/2, pi/2)
- ortho = (Math.min(Math.abs(angle), Math.abs(angle - basis)) < 0.00001);
- renderWindow.renderers().forEach(function (renderer) {
- var cam = renderer.camera();
- if (util.compareArrays(view, cam.viewMatrix()) &&
- util.compareArrays(proj, cam.projectionMatrix()) &&
- m_lastZoom === map.zoom()) {
- return;
- }
- m_lastZoom = map.zoom();
- cam.setViewMatrix(view, true);
- cam.setProjectionMatrix(proj);
- var viewport = camera.viewport;
- /* Test if we should align texels. We won't if the projection matrix
- * is not simple, if there is a rotation that isn't a multiple of 90
- * degrees, if the viewport is not at an integer location, or if the zoom
- * level is not close to an integer.
- * Note that the test for the viewport is strict (val % 1 is non-zero
- * if the value is not an integer), as, in general, the alignment is only
- * non-integral if a percent offset or calculation was used in css
- * somewhere. The test for zoom level always has some allowance for
- * precision, as it is often the result of repeated computations. */
- if (proj[1] || proj[2] || proj[3] || proj[4] || proj[6] || proj[7] ||
- proj[8] || proj[9] || proj[11] || proj[15] !== 1 || !ortho ||
- (viewport.left && viewport.left % 1) ||
- (viewport.top && viewport.top % 1) ||
- (parseFloat(m_lastZoom.toFixed(6)) !==
- parseFloat(m_lastZoom.toFixed(0)))) {
- /* Don't align texels */
- cam.viewAlignment = function () {
- return null;
- };
- } else {
- /* Set information for texel alignment. The rounding factors should
- * probably be divided by window.devicePixelRatio. */
- cam.viewAlignment = function () {
- var align = {
- roundx: 2.0 / viewport.width,
- roundy: 2.0 / viewport.height
- };
- align.dx = (viewport.width % 2) ? align.roundx * 0.5 : 0;
- align.dy = (viewport.height % 2) ? align.roundy * 0.5 : 0;
- return align;
- };
- }
- });
- };
+ // this._updateRendererCamera = function () {
+ // var renderWindow = m_viewer.renderWindow(),
+ // map = m_this.layer().map(),
+ // camera = map.camera(),
+ // rotation = map.rotation() || 0,
+ // view = camera.view,
+ // proj = camera.projectionMatrix;
+ // if (proj[15]) {
+ // /* we want positive z to be closer to the camera, but webGL does the
+ // * converse, so reverse the z coordinates. */
+ // proj = mat4.scale(util.mat4AsArray(), proj, [1, 1, -1]);
+ // }
+ // /* A similar kluge as in the base camera class worldToDisplay4. With this,
+ // * we can show z values from 0 to 1. */
+ // proj = mat4.translate(util.mat4AsArray(), proj,
+ // [0, 0, camera.constructor.bounds.far]);
+ // /* Check if the rotation is a multiple of 90 */
+ // var basis = Math.PI / 2,
+ // angle = rotation % basis, // move to range (-pi/2, pi/2)
+ // ortho = (Math.min(Math.abs(angle), Math.abs(angle - basis)) < 0.00001);
+ // renderWindow.renderers().forEach(function (renderer) {
+ // var cam = renderer.camera();
+ // if (util.compareArrays(view, cam.viewMatrix()) &&
+ // util.compareArrays(proj, cam.projectionMatrix()) &&
+ // m_lastZoom === map.zoom()) {
+ // return;
+ // }
+ // m_lastZoom = map.zoom();
+ // cam.setViewMatrix(view, true);
+ // cam.setProjectionMatrix(proj);
+ // var viewport = camera.viewport;
+ // Test if we should align texels. We won't if the projection matrix
+ // * is not simple, if there is a rotation that isn't a multiple of 90
+ // * degrees, if the viewport is not at an integer location, or if the zoom
+ // * level is not close to an integer.
+ // * Note that the test for the viewport is strict (val % 1 is non-zero
+ // * if the value is not an integer), as, in general, the alignment is only
+ // * non-integral if a percent offset or calculation was used in css
+ // * somewhere. The test for zoom level always has some allowance for
+ // * precision, as it is often the result of repeated computations.
+ // if (proj[1] || proj[2] || proj[3] || proj[4] || proj[6] || proj[7] ||
+ // proj[8] || proj[9] || proj[11] || proj[15] !== 1 || !ortho ||
+ // (viewport.left && viewport.left % 1) ||
+ // (viewport.top && viewport.top % 1) ||
+ // (parseFloat(m_lastZoom.toFixed(6)) !==
+ // parseFloat(m_lastZoom.toFixed(0)))) {
+ // /* Don't align texels */
+ // cam.viewAlignment = function () {
+ // return null;
+ // };
+ // } else {
+ // /* Set information for texel alignment. The rounding factors should
+ // * probably be divided by window.devicePixelRatio. */
+ // cam.viewAlignment = function () {
+ // var align = {
+ // roundx: 2.0 / viewport.width,
+ // roundy: 2.0 / viewport.height
+ // };
+ // align.dx = (viewport.width % 2) ? align.roundx * 0.5 : 0;
+ // align.dy = (viewport.height % 2) ? align.roundy * 0.5 : 0;
+ // return align;
+ // };
+ // }
+ // });
+ // };
// Connect to pan event. This is sufficient, as all zooms and rotations also
// produce a pan
@@ -274,48 +274,4 @@ inherit(vtkjsRenderer, renderer);
registerRenderer('vtkjs', vtkjsRenderer);
-// (function () {
-// 'use strict';
-
-// var checkedWebGL;
-
-// /**
-// * Report if the vgl renderer is supported. This is just a check if webGL is
-// * supported and available.
-// *
-// * @returns {boolean} true if available.
-// */
-// vglRenderer.supported = function () {
-// if (checkedWebGL === undefined) {
-// /* This is extracted from what Modernizr uses. */
-// var canvas, ctx, exts; // eslint-disable-line no-unused-vars
-// try {
-// canvas = document.createElement('canvas');
-// ctx = (canvas.getContext('webgl') ||
-// canvas.getContext('experimental-webgl'));
-// exts = ctx.getSupportedExtensions();
-// checkedWebGL = true;
-// } catch (e) {
-// console.error('No webGL support');
-// checkedWebGL = false;
-// }
-// canvas = undefined;
-// ctx = undefined;
-// exts = undefined;
-// }
-// return checkedWebGL;
-// };
-
-// /**
-// * If the vgl renderer is not supported, supply the name of a renderer that
-// * should be used instead. This asks for the null renderer.
-// *
-// * @returns null for the null renderer.
-// */
-// vglRenderer.fallback = function () {
-// return null;
-// };
-
-// })();
-
module.exports = vtkjsRenderer;

Cleaned up vtk implementation