8000 Handle streamtube coordinates in string format and handle different data orders in isosurface and volume by archmoj · Pull Request #4431 · plotly/plotly.js · GitHub
[go: up one dir, main page]

Skip to content
8000

Handle streamtube coordinates in string format and handle different data orders in isosurface and volume #4431

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

Merged
merged 11 commits into from
Dec 30, 2019
Merged
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
Apply streamtube processGrid in isosurface and volume
- add image tests for various grid fill orders
- add jasmine tests for various grid fill orders and data types
  • Loading branch information
archmoj committed Dec 24, 2019
commit 5a95dab4d4aff34a718311c056d616bcc41732ff
12 changes: 9 additions & 3 deletions src/traces/isosurface/calc.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,28 @@
'use strict';

var colorscaleCalc = require('../../components/colorscale/calc');
var processGrid = require('../streamtube/calc').processGrid;

module.exports = function calc(gd, trace) {
trace._len = Math.min(trace.x.length, trace.y.length, trace.z.length, trace.value.length);

var grid = processGrid(trace);
trace._gridFill = grid.fill;
trace._Xs = grid.Xs;
trace._Ys = grid.Ys;
trace._Zs = grid.Zs;
trace._len = grid.len;

var min = Infinity;
var max = -Infinity;
var len = trace.value.length;
for(var i = 0; i < len; i++) {
for(var i = 0; i < trace._len; i++) {
var v = trace.value[i];
min = Math.min(min, v);
max = Math.max(max, v);
}

trace._minValues = min;
trace._maxValues = max;

trace._vMin = (trace.isomin === undefined || trace.isomin === null) ? min : trace.isomin;
trace._vMax = (trace.isomax === undefined || trace.isomin === null) ? max : trace.isomax;

Expand Down
36 changes: 23 additions & 13 deletions src/traces/isosurface/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,11 @@
'use strict';

var createMesh = require('gl-mesh3d');

var Lib = require('../../lib');

var parseColorScale = require('../../lib/gl_format_color').parseColorScale;
var str2RgbaArray = require('../../lib/str2rgbarray');
var extractOpts = require('../../components/colorscale').extractOpts;
var zip3 = require('../../plots/gl3d/zip3');

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

var findNearestOnAxis = function(w, arr) {
for(var q = arr.length - 1; q > 0; q--) {
var min = Math.min(arr[q], arr[q - 1]);
Expand Down Expand Up @@ -136,6 +129,8 @@ proto.dispose = function() {
this.mesh.dispose();
};

var GRID_TYPES = ['xyz', 'xzy', 'yxz', 'yzx', 'zxy', 'zyx'];

function generateIsoMeshes(data) {
data._i = [];
data._j = [];
Expand All @@ -154,17 +149,32 @@ function generateIsoMeshes(data) {
var numVertices;
var beginVertextLength;

var Xs = distinctVals(data.x.slice(0, data._len));
var Ys = distinctVals(data.y.slice(0, data._len));
var Zs = distinctVals(data.z.slice(0, data._len));
var Xs = data._Xs;
var Ys = data._Ys;
var Zs = data._Zs;

var width = Xs.length;
var height = Ys.length;
var depth = Zs.length;

function getIndex(i, j, k) {
return k + depth * j + depth * height * i;
}
var filled = GRID_TYPES.indexOf(data._gridFill.replace(/-/g, '').replace(/\+/g, ''));

var getIndex = function(i, j, k) {
switch(filled) {
case 5: // 'zyx'
return k + depth * j + depth * height * i;
case 4: // 'zxy'
return k + depth * i + depth * width * j;
case 3: // 'yzx'
return j + height * k + height * depth * i;
case 2: // 'yxz'
return j + height * i + height * width * k;
case 1: // 'xzy'
return i + width * k + width * depth * j;
default: // case 0: // 'xyz'
return i + width * j + width * height * k;
}
};

var minValues = data._minValues;
var maxValues = data._maxValues;
Expand Down
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.
227 changes: 227 additions & 0 deletions test/image/mocks/gl3d_directions-isosurface1.json

Large diffs are not rendered by default.

227 changes: 227 additions & 0 deletions test/image/mocks/gl3d_directions-isosurface2.json

Large diffs are not rendered by default.

146 changes: 146 additions & 0 deletions test/jasmine/tests/isosurface_test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var Plotly = require('@lib');
var Lib = require('@src/lib');

var supplyAllDefaults = require('../assets/supply_defaults');
var createGraphDiv = require('../assets/create_graph_div');
Expand Down Expand Up @@ -391,3 +392,148 @@ describe('Test isosurface', function() {
});
});
});

describe('Test isosurface grid', function() {
var gd;

beforeEach(function() {
gd = createGraphDiv();
});

afterEach(function() {
Plotly.purge(gd);
destroyGraphDiv();
});

[ // list of directions
'number',
'string',
'typedArray'
].forEach(function(format) {
[ // list of directions
[-1, -1, -1],
[-1, -1, 1],
[-1, 1, -1],
[1, -1, -1],
[1, 1, -1],
[1, -1, 1],
[-1, 1, 1],
[1, 1, 1]
].forEach(function(dir) {
it('@gl should work with grid steps: ' + dir + ' and values in ' + format + ' format.', function(done) {
var x = [];
var y = [];
var z = [];
var v = [];

for(var i = 0; i < 3; i++) {
for(var j = 0; j < 4; j++) {
for(var k = 0; k < 5; k++) {
var newX = i * dir[0];
var newY = j * dir[1];
var newZ = k * dir[2];
var newV = (
newX * newX +
newY * newY +
newZ * newZ
);

if(format === 'string') {
newV = String(newV);
newX = String(newX);
newY = String(newY);
newZ = String(newZ);
}

v.push(newV);
x.push(newX);
y.push(newY);
z.push(newZ);
}
}
}

if(format === 'typedArray') {
v = new Int32Array(v);
x = new Float32Array(x);
y = new Float32Array(y);
z = new Float64Array(z);
}

var fig = {
data: [{
type: 'isosurface',
x: x,
y: y,
z: z,
value: v
}]
};

function _assert(msg, exp) {
var scene = gd._fullLayout.scene._scene;
var objs = scene.glplot.objects;
expect(objs.length).toBe(1, 'one gl-vis object - ' + msg);
expect(exp.positionsLength).toBe(objs[0].positions.length, 'positions length - ' + msg);
expect(exp.cellsLength).toBe(objs[0].cells.length, 'cells length - ' + msg);
}

Plotly.plot(gd, fig).then(function() {
_assert('lengths', {
positionsLength: 372,
cellsLength: 104
});
})
.catch(failTest)
.then(done);
});
});
});

it('@gl should return blank mesh grid if encountered arbitrary coordinates', function(done) {
var x = [];
var y = [];
var z = [];
var v = [];

Lib.seedPseudoRandom();

for(var n = 0; n < 1000; n++) {
x.push((10 * Lib.pseudoRandom()) | 0);
y.push((10 * Lib.pseudoRandom()) | 0);
z.push((10 * Lib.pseudoRandom()) | 0);
v.push((10 * Lib.pseudoRandom()) | 0);
}

var fig = {
data: [{
type: 'isosurface',
x: x,
y: y,
z: z,
value: v
}]
};

function _assert(msg, exp) {
var scene = gd._fullLayout.scene._scene;
var objs = scene.glplot.objects;
expect(objs.length).toBe(1, 'one gl-vis object - ' + msg);
expect(exp.positionsLength).toBe(objs[0].positions.length, 'positions length - ' + msg);
expect(exp.cellsLength).toBe(objs[0].cells.length, 'cells length - ' + msg);
}

spyOn(Lib, 'warn');

Plotly.plot(gd, fig).then(function() {
_assert('arbitrary coordinates', {
positionsLength: 0,
cellsLength: 0
});
}).then(function() {
expect(Lib.warn).toHaveBeenCalledWith('Encountered arbitrary coordinates! Unable to input data grid.');
})
.catch(failTest)
.then(done);
});
});
Loading
0