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

Correct streamtube positions and colouring #4271

Merged
merged 16 commits into from
Oct 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
32 changes: 11 additions & 21 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"delaunay-triangulate": "^1.1.6",
"es6-promise": "^3.0.2",
"fast-isnumeric": "^1.1.3",
"gl-cone3d": "^1.4.1",
"gl-cone3d": "^1.5.0",
"gl-contour2d": "^1.1.6",
"gl-error3d": "^1.0.15",
"gl-heatmap2d": "^1.0.5",
Expand All @@ -86,7 +86,7 @@
"gl-scatter3d": "^1.2.2",
"gl-select-box": "^1.0.3",
"gl-spikes2d": "^1.0.2",
"gl-streamtube3d": "^1.3.1",
"gl-streamtube3d": "^1.4.0",
"gl-surface3d": "^1.4.6",
"gl-text": "^1.1.8",
"glslify": "^7.0.0",
Expand Down
126 changes: 115 additions & 11 deletions src/traces/streamtube/calc.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@

'use strict';

var Lib = require('../../lib');
var colorscaleCalc = require('../../components/colorscale/calc');

module.exports = function calc(gd, trace) {
var i;
var i, j, k;

var u = trace.u;
var v = trace.v;
Expand Down Expand Up @@ -56,19 +57,114 @@ module.exports = function calc(gd, trace) {
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 gridFill = '';
var filledX;
var filledY;
var filledZ;
var firstX;
var firstY;
var firstZ;
if(len) {
firstX = x[0];
firstY = y[0];
firstZ = z[0];
}

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

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

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

if(!filledX && x[i] !== firstX) {
filledX = true;
gridFill += 'x';
}
if(!filledY && y[i] !== firstY) {
filledY = true;
gridFill += 'y';
}
if(!filledZ && z[i] !== firstZ) {
filledZ = true;
gridFill += 'z';
}
}
// fill if not filled - case of having dimension(s) with one item
if(!filledX) gridFill += 'x';
if(!filledY) gridFill += 'y';
if(!filledZ) gridFill += 'z';

var Xs = distinctVals(trace.x.slice(0, len));
var Ys = distinctVals(trace.y.slice(0, len));
var Zs = distinctVals(trace.z.slice(0, len));

gridFill = gridFill.replace('x', (x[0] > x[len - 1] ? '-' : '+') + 'x');
gridFill = gridFill.replace('y', (y[0] > y[len - 1] ? '-' : '+') + 'y');
gridFill = gridFill.replace('z', (z[0] > z[len - 1] ? '-' : '+') + 'z');

var empty = function() {
len = 0;
Xs = [];
Ys = [];
Zs = [];
};

// Over-specified mesh case, this would error in tube2mesh
if(!len || len < Xs.length * Ys.length * Zs.length) empty();

var getArray = function(c) { return c === 'x' ? x : c === 'y' ? y : z; };
var getVals = function(c) { return c === 'x' ? Xs : c === 'y' ? Ys : Zs; };
var getDir = function(c) { return (c[len - 1] < c[0]) ? -1 : 1; };

var arrK = getArray(gridFill[1]);
var arrJ = getArray(gridFill[3]);
var arrI = getArray(gridFill[5]);
var nk = getVals(gridFill[1]).length;
var nj = getVals(gridFill[3]).length;
var ni = getVals(gridFill[5]).length;

var arbitrary = false;

var getIndex = function(_i, _j, _k) {
return nk * (nj * _i + _j) + _k;
};

var dirK = getDir(getArray(gridFill[1]));
var dirJ = getDir(getArray(gridFill[3]));
var dirI = getDir(getArray(gridFill[5]));

for(i = 0; i < ni - 1; i++) {
for(j = 0; j < nj - 1; j++) {
for(k = 0; k < nk - 1; k++) {
var q000 = getIndex(i, j, k);
var q001 = getIndex(i, j, k + 1);
var q010 = getIndex(i, j + 1, k);
var q100 = getIndex(i + 1, j, k);

if(
!(arrK[q000] * dirK < arrK[q001] * dirK) ||
!(arrJ[q000] * dirJ < arrJ[q010] * dirJ) ||
!(arrI[q000] * dirI < arrI[q100] * dirI)
) {
arbitrary = true;
}

if(arbitrary) break;
}
if(arbitrary) break;
}
if(arbitrary) break;
}

var zz = z[i];
zMax = Math.max(zMax, zz);
zMin = Math.min(zMin, zz);
if(arbitrary) {
Lib.warn('Encountered arbitrary coordinates! Unable to input data grid.');
empty();
}

for(i = 0; i < slen; i++) {
var sx = startx[i];
xMax = Math.max(xMax, sx);
Expand All @@ -89,4 +185,12 @@ module.exports = function calc(gd, trace) {
trace._xbnds = [xMin, xMax];
trace._ybnds = [yMin, yMax];
trace._zbnds = [zMin, zMax];
trace._Xs = Xs;
trace._Ys = Ys;
trace._Zs = Zs;
trace._gridFill = gridFill;
};

function distinctVals(col) {
return Lib.distinctVals(col).vals;
}
22 changes: 9 additions & 13 deletions src/traces/streamtube/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,6 @@ proto.handlePick = function(selection) {
}
};

function distinctVals(col) {
return Lib.distinctVals(col).vals;
}

function getDfltStartingPositions(vec) {
var len = vec.length;
var s;
Expand Down Expand Up @@ -108,20 +104,20 @@ function convert(scene, trace) {
len
);

var valsx = distinctVals(trace.x.slice(0, len));
var valsy = distinctVals(trace.y.slice(0, len));
var valsz = distinctVals(trace.z.slice(0, len));

// Over-specified mesh case, this would error in tube2mesh
if(valsx.length * valsy.length * valsz.length > len) {
return {positions: [], cells: []};
if(!len) {
return {
positions: [],
cells: []
};
}

var meshx = toDataCoords(valsx, 'xaxis');
var meshy = toDataCoords(valsy, 'yaxis');
var meshz = toDataCoords(valsz, 'zaxis');
var meshx = toDataCoords(trace._Xs, 'xaxis');
var meshy = toDataCoords(trace._Ys, 'yaxis');
var meshz = toDataCoords(trace._Zs, 'zaxis');

tubeOpts.meshgrid = [meshx, meshy, meshz];
tubeOpts.gridFill = trace._gridFill;

var slen = trace._slen;
if(slen) {
Expand Down
Binary file modified test/image/baselines/gl3d_coloraxes.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/gl3d_cone-with-streamtube.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/gl3d_reversescale.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/gl3d_streamtube-first.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/gl3d_streamtube-simple.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/gl3d_streamtube-thin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/gl3d_streamtube-wind.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/gl3d_streamtube_reversed_ranges.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading