8000 Isosurface traces by kig · Pull Request #2752 · plotly/plotly.js · GitHub
[go: up one dir, main page]

Skip to content

Isosurface traces #2752

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

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Prev Previous commit
Next Next commit
Compute bounds for isosurface
  • Loading branch information
kig committed Aug 24, 2018
commit f7eb9514ff49fa89b619757631aa9fcf60711183
31 changes: 31 additions & 0 deletions src/traces/isosurface/calc.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,35 @@ module.exports = function calc(gd, trace) {
trace._vMax = vMax;

colorscaleCalc(trace, [vMin, vMax], '', 'c');

var x = trace.x;
var y = trace.y;
var z = trace.z;

var xMax = -Infinity;
var xMin = Infinity;
var yMax = -Infinity;
var yMin = Infinity;
var zMax = -Infinity;
var zMin = Infinity;

for(i = 0; i < len; i++) {
var xx = x[i];
xMax = Math.max(xMax, xx);
xMin = Math.min(xMin, xx);

var yy = y[i];
yMax = Math.max(yMax, yy);
yMin = Math.min(yMin, yy);

var zz = z[i];
zMax = Math.max(zMax, zz);
zMin = Math.min(zMin, zz);
}

trace._xbnds = [xMin, xMax];
trace._ybnds = [yMin, yMax];
trace._zbnds = [zMin, zMax];

console.log(trace);
};
28 changes: 19 additions & 9 deletions src/traces/isosurface/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,26 +146,28 @@ function findMaxIndex(xs, value) {
return -1;
}

function toDataCoords(scene, arr, axisName) {
var sceneLayout = scene.fullSceneLayout;
var dataScale = scene.dataScale;
var ax = sceneLayout[axisName];
var scale = dataScale[axisName2scaleIndex[axisName]];
return simpleMap(arr, function(v) { return ax.d2l(v) * scale; });
}

function convert(scene, trace) {
var sceneLayout = scene.fullSceneLayout;
var dataScale = scene.dataScale;
var isosurfaceOpts = {};

function toDataCoords(arr, axisName) {
var ax = sceneLayout[axisName];
var scale = dataScale[axisName2scaleIndex[axisName]];
return simpleMap(arr, function(v) { return ax.d2l(v) * scale; });
}

var xs = getSequence(trace.x);
var ys = getSequence(trace.y);
var zs = getSequence(trace.z);

isosurfaceOpts.dimensions = [xs.length, ys.length, zs.length];
isosurfaceOpts.meshgrid = [
toDataCoords(xs, 'xaxis'),
toDataCoords(ys, 'yaxis'),
toDataCoords(zs, 'zaxis')
toDataCoords(scene, xs, 'xaxis'),
toDataCoords(scene, ys, 'yaxis'),
toDataCoords(scene, zs, 'zaxis')
];


Expand Down Expand Up @@ -232,6 +234,14 @@ function createIsosurfaceTrace(scene, data) {

var meshData = convert(scene, data);
var mesh = isosurfacePlot.createTriMesh(gl, meshData);
var trace = data;
var xbnds = toDataCoords(scene, trace._xbnds, 'xaxis');
var ybnds = toDataCoords(scene, trace._ybnds, 'yaxis');
var zbnds = toDataCoords(scene, trace._zbnds, 'zaxis');
mesh.bounds = [
[xbnds[0], ybnds[0], zbnds[0]],
[xbnds[1], ybnds[1], zbnds[1]],
];

var isosurface = new Isosurface(scene, data.uid);
isosurface.mesh = mesh;
Expand Down
3847
0