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

Skip to content

Commit e75e9d7

Browse files
committed
isosurface single-color surface
1 parent eb5221d commit e75e9d7

File tree

3 files changed

+41
-9
lines changed

3 files changed

+41
-9
lines changed

src/traces/isosurface/attributes.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,25 @@ var attrs = {
108108
valType: 'boolean',
109109
role: 'info',
110110
editType: 'calc',
111-
description: 'Smooth normals of the isosurface (default: true)'
111+
description: 'Smooth normals of the isosurface. By default this is set to true.'
112112
},
113113

114114
isocaps: {
115115
valType: 'boolean',
116116
role: 'info',
117117
editType: 'calc',
118-
description: 'Whether to generate isocaps for the isosurface (default: true)'
118+
description: 'Whether to generate isocaps for the isosurface. By default this is set to true.'
119+
},
120+
121+
color: {
122+
valType: 'color',
123+
role: 'style',
124+
editType: 'calc',
125+
description: [
126+
'Sets the color of the isosurface.',
127+
'By default the isosurface color is computed from the colorscale.',
128+
'Isocaps still use the colorscale colors even with this set.'
129+
].join(" ")
119130
},
120131

121132
text: {

src/traces/isosurface/convert.js

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,9 @@
4646
cmin: 1500,
4747
cmax: 2000,
4848
49-
smoothnormals: true,
49+
smoothnormals: true,
5050
isocaps: true,
5151
52-
singlemesh: true,
53-
5452
colorscale: 'Portland'
5553
}])
5654
@@ -61,6 +59,7 @@ var isosurfacePlot = require('gl-isosurface3d');
6159

6260
var simpleMap = require('../../lib').simpleMap;
6361
var parseColorScale = require('../../lib/gl_format_color').parseColorScale;
62+
var str2RgbaArray = require('../../lib/str2rgbarray');
6463

6564
function Isosurface(scene, uid) {
6665
this.scene = scene;
@@ -164,13 +163,24 @@ function convert(scene, trace) {
164163

165164
isosurfaceOpts.values = trace.value;
166165

167-
isosurfaceOpts.colormap = parseColorScale(trace.colorscale);
168-
// isosurfaceOpts.capsColormap = parseColorScale(trace.capscolorscale);
166+
if (trace.colorscale) {
167+
isosurfaceOpts.colormap = parseColorScale(trace.colorscale);
168+
}
169+
if (trace.color) {
170+
isosurfaceOpts.capsColormap = isosurfaceOpts.colormap;
171+
var color = str2RgbaArray(trace.color).map(function(c) { return c * 255; });
172+
isosurfaceOpts.colormap = [{index: 0, rgb: color}, {index: 1, rgb: color}];
173+
if (!isosurfaceOpts.capsColormap) {
174+
isosurfaceOpts.capsColormap = isosurfaceOpts.colormap;
175+
}
176+
}
169177
isosurfaceOpts.vertexIntensityBounds = [trace.cmin, trace.cmax];
170178
isosurfaceOpts.isoBounds = [trace.isomin, trace.isomax];
171179

172180
isosurfaceOpts.isoCaps = trace.isocaps;
173-
isosurfaceOpts.singleMesh = trace.singlemesh === undefined ? true : trace.singlemesh;
181+
isosurfaceOpts.singleMesh = false; //trace.singlemesh === undefined ? true : trace.singlemesh;
182+
183+
isosurfaceOpts.smoothNormals = trace.smoothnormals === undefined ? true : trace.smoothnormals;
174184

175185
var bounds = [[0, 0, 0], isosurfaceOpts.dimensions.slice()];
176186

@@ -225,6 +235,7 @@ function createIsosurfaceTrace(scene, data) {
225235

226236
var meshData = convert(scene, data);
227237
var mesh = isosurfacePlot.createTriMesh(gl, meshData);
238+
var capMesh = isosurfacePlot.createTriMesh(gl, meshData.caps);
228239
var trace = data;
229240
var xbnds = toDataCoords(scene, trace._xbnds, 'xaxis');
230241
var ybnds = toDataCoords(scene, trace._ybnds, 'yaxis');
@@ -240,7 +251,16 @@ function createIsosurfaceTrace(scene, data) {
240251
isosurface.meshData = meshData;
241252
mesh._trace = isosurface;
242253

254+
var caps = new Isosurface(scene, data.uid);
255+
caps.mesh = capMesh;
256+
caps.data = data;
257+
caps.meshData = meshData;
258+
capMesh._trace = caps;
259+
260+
isosurface.caps = caps;
261+
243262
scene.glplot.add(mesh);
263+
scene.glplot.add(capMesh);
244264

245265
return isosurface;
246266
}

src/traces/isosurface/defaults.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,12 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
3333
return;
3434
}
3535

36+
coerce('color');
37+
3638
coerce('isomin');
3739
coerce('isomax');
3840
coerce('smoothnormals');
3941
coerce('isocaps');
40-
// coerce('singlemesh');
4142

4243
coerce('xmin');
4344
coerce('ymin');

0 commit comments

Comments
 (0)