Skip to content

Commit c66a2bb

Browse files
committed
one big change for the API
1 parent 1089724 commit c66a2bb

15 files changed

+33505
-5072
lines changed

src/traces/isosurface/attributes.js

+23-2
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,28 @@ function makeCapAttr(axLetter) {
8484
}
8585

8686
var attrs = module.exports = overrideAll(extendFlat({
87+
88+
width: {
89+
valType: 'integer',
90+
role: 'info',
91+
description: [
92+
'Sets the number of points on X axis.'
93+
].join(' ')
94+
},
95+
height: {
96+
valType: 'integer',
97+
role: 'info',
98+
description: [
99+
'Sets the number of points on Y axis.'
100+
].join(' ')
101+
},
102+
depth: {
103+
valType: 'integer',
104+
role: 'info',
105+
description: [
106+
'Sets the number of points on Z axis.'
107+
].join(' ')
108+
},
87109
x: {
88110
valType: 'data_array',
89111
role: 'info',
@@ -109,8 +131,7 @@ var attrs = module.exports = overrideAll(extendFlat({
109131
valType: 'data_array',
110132
role: 'info',
111133
description: [
112-
'Sets the 4th dimension of the vertices. It should be',
113-
'one dimensional array containing n=X.length*Y.length*Z.length numbers.'
134+
'Sets the 4th dimension (value) of the vertices.'
114135
].join(' ')
115136
},
116137
isomin: {

src/traces/isosurface/convert.js

+42-47
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,15 @@ function IsosurfaceTrace(scene, mesh, uid) {
2626

2727
var proto = IsosurfaceTrace.prototype;
2828

29-
function findNearestOnAxis(w, arr) {
30-
for(var q = arr.length - 1; q > 0; q--) {
31-
var min = Math.min(arr[q], arr[q - 1]);
32-
var max = Math.max(arr[q], arr[q - 1]);
29+
function findNearestOnAxis(w, arr, nPoints, nDim, step) {
30+
var id = nDim;
31+
for(var q = nPoints - 1; q > 0 && id > 0; q -= step) {
32+
id--;
33+
var min = Math.min(arr[q], arr[q - step]);
34+
var max = Math.max(arr[q], arr[q - step]);
3335
if(max > min && min < w && w <= max) {
3436
return {
35-
id: q,
37+
id: id,
3638
distRatio: (max - w) / (max - min)
3739
};
3840
}
@@ -52,14 +54,16 @@ proto.handlePick = function(selection) {
5254
var y = this.data.y[rawId];
5355
var z = this.data.z[rawId];
5456

55-
var i = findNearestOnAxis(x, this.data._Xs).id;
56-
var j = findNearestOnAxis(y, this.data._Ys).id;
57-
var k = findNearestOnAxis(z, this.data._Zs).id;
57+
var width = this.data.width;
58+
var height = this.data.height;
59+
var depth = this.data.depth;
60+
var nPoints = width * height * depth;
5861

59-
var width = this.data._Xs.length;
60-
var height = this.data._Ys.length;
62+
var i = findNearestOnAxis(x, this.data.x, nPoints, width, 1 + depth * height).id;
63+
var j = findNearestOnAxis(y, this.data.y, nPoints, height, 1 + depth).id;
64+
var k = findNearestOnAxis(z, this.data.z, nPoints, depth, 1).id;
6165

62-
var selectIndex = selection.index = i + width * j + width * height * k;
66+
var selectIndex = selection.index = k + depth * j + depth * height * i;
6367

6468
selection.traceCoordinate = [
6569
this.data.x[selectIndex],
@@ -150,26 +154,14 @@ function generateIsosurfaceMesh(data) {
150154
var numVertices;
151155
var beginVertextLength;
152156

153-
var width = data.x.length;
154-
var height = data.y.length;
155-
var depth = data.z.length;
157+
var width = data.width;
158+
var height = data.height;
159+
var depth = data.depth;
156160

157161
function getIndex(i, j, k) {
158-
return i + width * j + width * height * k;
162+
return k + depth * j + depth * height * i;
159163
}
160164

161-
function copyElements(src) {
162-
var dst = [];
163-
for(var i = 0; i < src.length; i++) {
164-
dst[i] = src[i];
165-
}
166-
return dst;
167-
}
168-
169-
var Xs = copyElements(data.x);
170-
var Ys = copyElements(data.y);
171-
var Zs = copyElements(data.z);
172-
173165
var minValues = data._minValues;
174166
var maxValues = data._maxValues;
175167

@@ -384,16 +376,11 @@ function generateIsosurfaceMesh(data) {
384376
var xyzv = [];
385377
for(var q = 0; q < 4; q++) {
386378
var index = indecies[q];
387-
388-
var k = Math.floor(index / (width * height));
389-
var j = Math.floor((index - k * width * height) / width);
390-
var i = Math.floor(index - k * width * height - j * width);
391-
392379
xyzv.push(
393380
[
394-
Xs[i],
395-
Ys[j],
396-
Zs[k],
381+
data.x[index],
382+
data.y[index],
383+
data.z[index],
397384
data.value[index]
398385
]
399386
);
@@ -816,10 +803,16 @@ function generateIsosurfaceMesh(data) {
816803
}
817804

818805
function insertGridPoints() {
819-
for(var k = 0; k < depth; k++) {
806+
for(var i = 0; i < width; i++) {
820807
for(var j = 0; j < height; j++) {
821-
for(var i = 0; i < width; i++) {
822-
addVertex(Xs[i], Ys[j], Zs[k], data.value[getIndex(i, j, k)]);
808+
for(var k = 0; k < depth; k++) {
809+
var index = getIndex(i, j, k);
810+
addVertex(
811+
data.x[index],
812+
data.y[index],
813+
data.z[index],
814+
data.value[index]
815+
);
823816
}
824817
}
825818
}
@@ -883,13 +876,19 @@ function generateIsosurfaceMesh(data) {
883876
var ceilIndices = [];
884877
var distRatios = [];
885878
if(slice.locations.length) {
879+
886880
for(var q = 0; q < slice.locations.length; q++) {
887881

888-
var near = findNearestOnAxis(
889-
slice.locations[q],
890-
(e === 'x') ? Xs :
891-
(e === 'y') ? Ys : Zs
892-
);
882+
var location = slice.locations[q];
883+
884+
var near;
885+
if(e === 'x') {
886+
near = findNearestOnAxis(location, data.x, width * height * depth, width, 1 + depth * height);
887+
} else if(e === 'y') {
888+
near = findNearestOnAxis(location, data.y, width * height * depth, height, 1 + depth);
889+
} else {
890+
near = findNearestOnAxis(location, data.z, width * height * depth, depth, 1);
891+
}
893892

894893
if(near.distRatio === 0) {
895894
exactIndices.push(near.id);
@@ -955,10 +954,6 @@ function generateIsosurfaceMesh(data) {
955954
emptyVertices();
956955
}
957956

958-
data._Xs = Xs;
959-
data._Ys = Ys;
960-
data._Zs = Zs;
961-
962957
data.x = allXs;
963958
data.y = allYs;
964959
data.z = allZs;

src/traces/isosurface/defaults.js

+9-4
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,21 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
3030
traceOut.isomax = null;
3131
}
3232

33+
var width = coerce('width');
34+
var height = coerce('height');
35+
var depth = coerce('depth');
36+
var numVertices = width * height * depth;
37+
3338
var x = coerce('x');
3439
var y = coerce('y');
3540
var z = coerce('z');
3641
var value = coerce('value');
3742

3843
if(
39-
!x || !x.length ||
40-
!y || !y.length ||
41-
!z || !z.length ||
42-
!value || !value.length
44+
!x || !x.length || x.length !== numVertices ||
45+
!y || !y.length || y.length !== numVertices ||
46+
!z || !z.length || z.length !== numVertices ||
47+
!value || !value.length || value.length !== numVertices
4348
) {
4449
traceOut.visible = false;
4550
return;

0 commit comments

Comments
 (0)