Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d417e6e

Browse files
committed
isosurface trace [xyz](min|max) bounds
1 parent 1c4ec62 commit d417e6e

File tree

3 files changed

+89
-17
lines changed

3 files changed

+89
-17
lines changed

src/traces/isosurface/attributes.js

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,32 +59,56 @@ var attrs = {
5959
description: 'Sets the maximum iso bound of the isosurface.'
6060
},
6161

62-
smoothnormals: {
63-
valType: 'boolean',
62+
xmin: {
63+
valType: 'number',
6464
editType: 'calc',
65-
description: ''
65+
description: 'Sets the minimum x bound of the isosurface.'
6666
},
6767

68-
singlemesh: {
69-
valType: 'boolean',
68+
xmax: {
69+
valType: 'number',
7070
editType: 'calc',
71-
description: ''
71+
description: 'Sets the maximum x bound of the isosurface.'
7272
},
7373

74-
isocaps: {
74+
ymin: {
75+
valType: 'number',
76+
editType: 'calc',
77+
description: 'Sets the minimum y bound of the isosurface.'
78+
},
79+
80+
ymax: {
81+
valType: 'number',
82+
editType: 'calc',
83+
description: 'Sets the maximum y bound of the isosurface.'
84+
},
85+
86+
zmin: {
87+
valType: 'number',
88+
editType: 'calc',
89+
description: 'Sets the minimum z bound of the isosurface.'
90+
},
91+
92+
zmax: {
93+
valType: 'number',
94+
editType: 'calc',
95+
description: 'Sets the maximum z bound of the isosurface.'
96+
},
97+
98+
smoothnormals: {
7599
valType: 'boolean',
76100
editType: 'calc',
77101
description: ''
78102
},
79103

80-
boundmin: {
81-
valType: 'data_array',
104+
singlemesh: {
105+
valType: 'boolean',
82106
editType: 'calc',
83107
description: ''
84108
},
85109

86-
boundmax: {
87-
valType: 'data_array',
110+
isocaps: {
111+
valType: 'boolean',
88112
editType: 'calc',
89113
description: ''
90114
},

src/traces/isosurface/convert.js

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,32 @@ function getSequence(src) {
118118
return xs;
119119
}
120120

121+
// This should find the bounding box min
122+
// edge index so that `value` lies at the edge or outside
123+
// the range starting from xs[edge index].
124+
// That is, xs[edge index] >= value.
125+
function findMinIndex(xs, value) {
126+
for(var i = 0; i < xs.length; i++) {
127+
if(xs[i] >= value) {
128+
return i;
129+
}
130+
}
131+
return xs.length;
132+
}
133+
134+
// This should find the bounding box max
135+
// edge index so that `value` lies at the edge or outside
136+
// the range ending at xs[edge index].
137+
// That is, xs[edge index] <= value.
138+
function findMaxIndex(xs, value) {
139+
for(var i = xs.length-1; i >= 0; i--) {
140+
if(xs[i] <= value) {
141+
return i;
142+
}
143+
}
144+
return -1;
145+
}
146+
121147
function convert(scene, trace) {
122148
var sceneLayout = scene.fullSceneLayout;
123149
var dataScale = scene.dataScale;
@@ -140,11 +166,6 @@ function convert(scene, trace) {
140166
toDataCoords(zs, 'zaxis')
141167
];
142168

143-
// var bounds = [
144-
// isosurfaceOpts.boundmin || [xs[0], ys[0], zs[0]],
145-
// isosurfaceOpts.boundmax || [xs[xs.length - 1], ys[ys.length - 1], zs[zs.length - 1]]
146-
// ];
147-
148169

149170
isosurfaceOpts.values = trace.value;
150171

@@ -156,7 +177,26 @@ function convert(scene, trace) {
156177
isosurfaceOpts.isoCaps = trace.isocaps;
157178
isosurfaceOpts.singleMesh = trace.singlemesh === undefined ? true : trace.singlemesh;
158179

159-
var bounds = [[0, 0, 0], isosurfaceOpts.dimensions];
180+
var bounds = [[0, 0, 0], isosurfaceOpts.dimensions.slice()];
181+
182+
if(trace.xmin !== undefined) {
183+
bounds[0][0] = findMinIndex(xs, trace.xmin);
184+
}
185+
if(trace.ymin !== undefined) {
186+
bounds[0][1] = findMinIndex(ys, trace.ymin);
187+
}
188+
if(trace.zmin !== undefined) {
189+
bounds[0][2] = findMinIndex(zs, trace.zmin);
190+
}
191+
if(trace.xmax !== undefined) {
192+
bounds[1][0] = findMaxIndex(xs, trace.xmax);
193+
}
194+
if(trace.ymax !== undefined) {
195+
bounds[1][1] = findMaxIndex(ys, trace.ymax);
196+
}
197+
if(trace.zmax !== undefined) {
198+
bounds[1][2] = findMaxIndex(zs, trace.zmax);
199+
}
160200

161201
var meshData = isosurfacePlot(isosurfaceOpts, bounds);
162202

src/traces/isosurface/defaults.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
3939
coerce('isocaps');
4040
// coerce('singlemesh');
4141

42+
coerce('xmin');
43+
coerce('ymin');
44+
coerce('zmin');
45+
46+
coerce('xmax');
47+
coerce('ymax');
48+
coerce('zmax');
49+
4250
coerce('lighting.ambient');
4351
coerce('lighting.diffuse');
4452
coerce('lighting.specular');

0 commit comments

Comments
 (0)