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 3 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
5 changes: 2 additions & 3 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "git://github.com/gl-vis/gl-streamtube3d.git#82a0dd7a8dc601f48ed4afdc5a3e40394b758deb",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"gl-surface3d": "^1.4.6",
"gl-text": "^1.1.8",
"glslify": "^7.0.0",
Expand Down
111 changes: 100 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,99 @@ 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';
} else if(!filledY && y[i] !== firstY) {
filledY = true;
gridFill += 'y';
} else 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 valsx = distinctVals(trace.x.slice(0, len));
var valsy = distinctVals(trace.y.slice(0, len));
var valsz = distinctVals(trace.z.slice(0, len));

var getArray = function(c) { return c === 'x' ? x : c === 'y' ? y : z; };
var getVals = function(c) { return c === 'x' ? valsx : c === 'y' ? valsy : valsz; };
var getLength = function(c) { return getVals(c).length; };
var getDir = function(c) { return (+(c[c.length - 1] - c[0])) * 2 + 1; };
etpinard marked this conversation as resolved.
Show resolved Hide resolved

var arrK = getArray(gridFill[0]);
var arrJ = getArray(gridFill[1]);
var arrI = getArray(gridFill[2]);
var nk = getLength(gridFill[0]);
var nj = getLength(gridFill[1]);
var ni = getLength(gridFill[2]);

var arbitrary = false;

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

var dirK = getDir(getArray(gridFill[0]));
var dirJ = getDir(getArray(gridFill[1]));
var dirI = getDir(getArray(gridFill[2]));

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.');
len = 0;
}

for(i = 0; i < slen; i++) {
var sx = startx[i];
xMax = Math.max(xMax, sx);
Expand All @@ -89,4 +170,12 @@ module.exports = function calc(gd, trace) {
trace._xbnds = [xMin, xMax];
trace._ybnds = [yMin, yMax];
trace._zbnds = [zMin, zMax];
trace._valsx = valsx;
trace._valsy = valsy;
trace._valsz = valsz;
trace._gridFill = gridFill;
};

function distinctVals(col) {
return Lib.distinctVals(col).vals;
}
11 changes: 4 additions & 7 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,9 +104,9 @@ 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));
var valsx = trace._valsx;
var valsy = trace._valsy;
var valsz = trace._valsz;

// Over-specified mesh case, this would error in tube2mesh
if(valsx.length * valsy.length * valsz.length > len) {
Expand All @@ -122,6 +118,7 @@ function convert(scene, trace) {
var meshz = toDataCoords(valsz, '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.
Binary file added test/image/baselines/gl3d_directions-cone1.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 added test/image/baselines/gl3d_directions-cone2.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