Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optional vtkjs #893

Merged
merged 47 commits into from
Nov 2, 2018
Merged
Show file tree
Hide file tree
Changes from 37 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
a58bcab
Initial commit
aashish24 Dec 10, 2016
61da520
Fixed build that works with vtk.js
aashish24 Dec 10, 2016
6f20a82
Got vtk.js sphere to show up
aashish24 Dec 26, 2016
0680182
Cleaned up vtk implementation
aashish24 Dec 26, 2016
f14bab9
Some more cleanup
aashish24 Jan 5, 2017
11e3d49
Got something to show up
aashish24 Jan 6, 2017
02510cd
Fixed webpack configuration to work with latest vtk-js.
sankhesh Jan 25, 2018
cf6857f
Remove alias to vtk and just keep it external
sankhesh Jan 26, 2018
d19f3ac
Working point feature and sphere source
sankhesh Jan 26, 2018
bb1d32b
Initial change to pass camera parameters to vtk
sankhesh Feb 2, 2018
5dc7af3
Working vtk-js integration
sankhesh Feb 28, 2018
326a6c1
Support actor properties
sankhesh Mar 19, 2018
a6b0d17
Explicitly use the user provided projection transform
sankhesh Mar 19, 2018
fd1803e
Working passing of key matrices between geojs and vtk-js
sankhesh Jun 7, 2018
9b5b6cd
Working vtkjs-geojs interation integration
sankhesh Jun 7, 2018
44a07ed
Transform to map gcs in vtk-js renderer
sankhesh Jun 18, 2018
b82571d
Schedule render instead of calling vtk-js render each frame
sankhesh Jun 18, 2018
0f5784e
Code cleanup
sankhesh Jun 18, 2018
fbb996e
Use vtkGlyph3DMapper instead of multiple actors
sankhesh Jun 19, 2018
f857c65
Example of vtk-js integration
sankhesh Jun 22, 2018
6fb7225
Code comment convention cleanup
sankhesh Jul 12, 2018
0887369
Merge remote-tracking branch 'sankhesh/vtk-renderer' into optional-vtkjs
zachmullen Aug 9, 2018
5ec8c41
Merge branch 'dual-builds' into optional-vtkjs
zachmullen Aug 9, 2018
5dd9841
Reintroduce sinon dev dependency
zachmullen Aug 9, 2018
847d423
Make Unreleased changelog section for new note
zachmullen Aug 10, 2018
9c8eccb
Update version number in tutorial comment
zachmullen Aug 10, 2018
f3b30a3
Merge branch 'master' into optional-vtkjs
zachmullen Aug 10, 2018
d5bded8
Exclude vtk.js from lean bundle
zachmullen Aug 10, 2018
f91a505
Runtime conditional support pattern for vtkjsRenderer
zachmullen Aug 10, 2018
354159d
Make pointFeature depend on vtkjsRenderer.vtkjs
zachmullen Aug 10, 2018
07a2193
Downgrade sinon back to previously used version
zachmullen Aug 10, 2018
9ac8ae9
Change const -> var
zachmullen Aug 10, 2018
05b20e5
Merge branch 'master' into optional-vtkjs
manthey Aug 31, 2018
7026107
Merge remote-tracking branch 'origin/master' into optional-vtkjs
zachmullen Oct 23, 2018
cff7a47
Fix global name of vtk module
zachmullen Oct 23, 2018
83f86c8
Eslint auto-fixes
zachmullen Oct 23, 2018
841b00c
Fix typo in vtkjsRenderer.supported
zachmullen Oct 23, 2018
cf1dc09
Update to working vtk.js version
zachmullen Oct 23, 2018
0ecd708
Make vtk.js example load
zachmullen Oct 24, 2018
85fd89e
Clean up vtkjs example code
zachmullen Oct 24, 2018
3472f2b
Improve comments in vtkjs example
zachmullen Oct 24, 2018
0a490be
Hack some fixes for the vtkjs renderer and pointFeature.
manthey Oct 29, 2018
bd6b88a
Merge branch 'master' into optional-vtkjs
manthey Oct 30, 2018
d4a5cdb
More fixups for the vtkjs renderer.
manthey Oct 30, 2018
79f3a98
Keep points the same pixel size on zoom.
manthey Oct 30, 2018
c12131e
Support one color for the points.
manthey Oct 30, 2018
154bb5f
Update documentation strings and change log.
manthey Oct 30, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions examples/vtkjs/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
var exampleDebug = {};

// Run after the DOM loads
$(function () {
'use strict';

var capitals;
$.when(
/* Fetch capitals */
$.ajax({url: 'capitals.json'}).done(function (resp) {
capitals = resp;
})
).then(function () {

// Set map defaults to a reasonable center and zoom level
var mapParams = {
node: '#map',
center: {x: 0, y: 0},
zoom: 2.5,
clampBoundsX: false,
clampBoundsY: false,
clampZoom: false,
discreteZoom: false
};
// Set the tile layer defaults
var layerParams = {
zIndex: 0,
minLevel: 4,
keepLower: true,
wrapX: false,
wrapY: false
};
// Create a map object
var map = geo.map(mapParams);
// Add the tile layer with the specified parameters
var osmLayer = map.createLayer('osm', layerParams);
// Set the vtk feature layer params
var vtkLayerParams = {
renderer: 'vtkjs'
};
// Create a vtk point feature layer
var vtkLayer = map.createLayer('feature', vtkLayerParams);
var pointFeature = vtkLayer
.createFeature('point', {
selectionAPI: true,
style: {
radius: 100, // sphere radius (~0.1km)
fillColor: 'red',
fillOpacity: function () {
return Math.random();
}
}
})
.data(capitals) // bind data
.position(function (d) {
return {x: d.longitude, y: d.latitude}; // position accessor
})
.draw();

// Make variables available as a global for easier debug
exampleDebug.map = map;
exampleDebug.mapParams = mapParams;
exampleDebug.layerParams = layerParams;
exampleDebug.osmLayer = osmLayer;
exampleDebug.vtkLayerParams = vtkLayerParams;
exampleDebug.vtkLayer = vtkLayer;
exampleDebug.pointFeature = pointFeature;
});
});
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
},
"optionalDependencies": {
"d3": "^3.5.16",
"hammerjs": "^2.0.8"
"hammerjs": "^2.0.8",
"vtk.js": "^5.15.6"
},
"devDependencies": {
"babel-core": "^6.26.0",
Expand Down Expand Up @@ -89,7 +90,8 @@
"raw-body": "^2.1.6",
"resemblejs": "^2.9.0",
"serve-index": "^1.9.1",
"sinon": "^1.17.3",
"sinon": "^1.17.7",
"string-replace-loader": "1.0.5",
"string-replace-webpack-plugin": "^0.1.3",
"style-loader": "^0.21.0",
"stylus": "^0.54.5",
Expand Down
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ module.exports = $.extend({
d3: require('./d3'),
gl: require('./gl'),
canvas: require('./canvas'),
vtkjs: require('./vtkjs'),
gui: require('./ui')
}, require('./registry'));

Expand Down
2 changes: 1 addition & 1 deletion src/ui/legendWidget.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ var legendWidget = function (arg) {

/**
* Get the widget's size
* @return {{width: number, height: number}} The size in pixels
* @returns {{width: number, height: number}} The size in pixels
*/
this.size = function () {
var width = 1, height;
Expand Down
8 changes: 4 additions & 4 deletions src/ui/sliderWidget.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ var sliderWidget = function (arg) {
* Add an icon from a path string. Returns a d3 group element.
*
* @function
* @argument {String} icon svg path string
* @argument {string} icon svg path string
* @argument {Array} base where to append the element (d3 selection)
* @argument {Number} cx Center x-coordinate
* @argument {Number} cy Center y-coordinate
* @argument {Number} size Icon size in pixels
* @argument {number} cx Center x-coordinate
* @argument {number} cy Center y-coordinate
* @argument {number} size Icon size in pixels
* @returns {object}
* @private
*/
Expand Down
7 changes: 7 additions & 0 deletions src/vtkjs/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/**
* @namespace geo.vtkjs
*/
module.exports = {
pointFeature: require('./pointFeature'),
vtkjsRenderer: require('./vtkjsRenderer')
};
146 changes: 146 additions & 0 deletions src/vtkjs/pointFeature.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
var inherit = require('../inherit');
var registerFeature = require('../registry').registerFeature;
var pointFeature = require('../pointFeature');

/**
* Create a new instance of pointFeature
*
* @class geo.vtkjs.pointFeature
* @extends geo.pointFeature
* @returns {geo.vtkjs.pointFeature}
*/
var vtkjs_pointFeature = function (arg) {
'use strict';
if (!(this instanceof vtkjs_pointFeature)) {
return new vtkjs_pointFeature(arg);
}
arg = arg || {};
pointFeature.call(this, arg);

var transform = require('../transform');
var object = require('../object');
var vtk = require('./vtkjsRenderer').vtkjs;
var vtkActor = vtk.Rendering.Core.vtkActor;
var vtkMapper = vtk.Rendering.Core.vtkGlyph3DMapper;
var vtkPointSet = vtk.Common.DataModel.vtkPointSet;
var vtkSphereSource = vtk.Filters.Sources.vtkSphereSource;

object.call(this);

/**
* Member variables
*
* @private
*/
var m_this = this,
s_exit = this._exit,
m_actor = null,
m_pointSet = null,
m_source = null,
s_update = this._update;

/**
* Create pipeline
*/
this._createPipeline = function () {
m_pointSet = vtkPointSet.newInstance();
m_source = vtkSphereSource.newInstance();
m_source.setThetaResolution(30);
m_source.setPhiResolution(30);
var mapper = vtkMapper.newInstance();
mapper.setInputData(m_pointSet, 0);
mapper.setInputConnection(m_source.getOutputPort(), 1);
m_actor = vtkActor.newInstance();
m_actor.setMapper(mapper);
this.renderer().contextRenderer().addActor(m_actor);
};

/**
* Initialize
*/
this._init = function () {
m_this.renderer().contextRenderer().setLayer(1);
this._createPipeline();
};

/**
* Build this feature
*/
this._build = function () {
var i, i3, posVal,
nonzeroZ,
numPts = m_this.data().length,
position = new Array(numPts * 3),
data = m_this.data(),
posFunc = m_this.position(),
radFunc = m_this.style.get('radius'),
colorFunc = m_this.style.get('fillColor'),
opacityFunc = m_this.style.get('fillOpacity');

/* It is more efficient to do a transform on a single array rather than on
* an array of arrays or an array of objects. */
for (i = i3 = 0; i < numPts; i += 1, i3 += 3) {
posVal = posFunc(data[i]);
position[i3] = posVal.x;
position[i3 + 1] = posVal.y;
position[i3 + 2] = posVal.z || 0;
nonzeroZ = nonzeroZ || position[i3 + 2];
m_actor.getProperty().setOpacity(opacityFunc(data[i]));
}
position = transform.transformCoordinates(
m_this.gcs(), m_this.layer().map().gcs(),
position, 3);

if (!nonzeroZ && m_this.gcs() !== m_this.layer().map().gcs()) {
for (i = i3 = 0; i < numPts; i += 1, i3 += 3) {
position[i3 + 2] = 0;
}
}

/* Some transforms modify the z-coordinate. If we started with all zero z
* coordinates, don't modify them. This could be changed if the
* z-coordinate space of the gl cube is scaled appropriately. */
m_pointSet.getPoints().setData(position, 3);
m_source.setRadius(radFunc());
m_actor.getProperty().setColor(colorFunc()['r'],
colorFunc()['g'],
colorFunc()['b']);
m_this.buildTime().modified();

console.debug('built vtkjs point feature');
};

/**
* Update
*
*/
this._update = function () {

s_update.call(m_this);

if (m_this.dataTime().getMTime() >= m_this.buildTime().getMTime() ||
m_this.updateTime().getMTime() < m_this.getMTime()) {
m_this._build();
}

m_this.updateTime().modified();
};

/**
* Destroy
*/
this._exit = function () {
m_this.renderer().contextRenderer().removeActor(m_actor);
s_exit();
};

m_this._init();
return this;
};

inherit(vtkjs_pointFeature, pointFeature);

// Now register it
registerFeature('vtkjs', 'point', vtkjs_pointFeature);

module.exports = vtkjs_pointFeature;
Loading