Skip to content

Commit 8098c71

Browse files
authored
Merge pull request #3521 from plotly/speedup-isosurface
Increase the speed of isosurface creation
2 parents 884d2fa + 03aed83 commit 8098c71

11 files changed

+36
-58
lines changed

src/traces/isosurface/attributes.js

+7-29
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
var colorscaleAttrs = require('../../components/colorscale/attributes');
1212
var colorbarAttrs = require('../../components/colorbar/attributes');
13-
var surfaceAtts = require('../surface/attributes');
1413
var meshAttrs = require('../mesh3d/attributes');
1514
var baseAttrs = require('../../plots/attributes');
1615

@@ -225,7 +224,7 @@ var attrs = module.exports = overrideAll(extendFlat({
225224
'If trace `hoverinfo` contains a *text* flag and *hovertext* is not set,',
226225
'these elements will be seen in the hover labels.'
227226
].join(' ')
228-
},
227+
}
229228
},
230229

231230
colorscaleAttrs('', {
@@ -236,37 +235,16 @@ colorscaleAttrs('', {
236235

237236
colorbar: colorbarAttrs,
238237

239-
// Flat shaded mode
240-
flatshading: {
241-
valType: 'boolean',
242-
role: 'style',
243-
dflt: false,
244-
description: [
245-
'Determines whether or not normal smoothing is applied to the isosurfaces,',
246-
'creating isosurfaces with an angular, low-poly look via flat reflections.'
247-
].join(' ')
248-
},
249-
250-
contour: {
251-
show: extendFlat({}, surfaceAtts.contours.x.show, {
252-
description: [
253-
'Sets whether or not dynamic contours are shown on hover.',
254-
'Contours are more useful when hovering on caps and slices.'
255-
].join(' ')
256-
}),
257-
color: surfaceAtts.contours.x.color,
258-
width: surfaceAtts.contours.x.width
259-
},
260-
261-
lightposition: {
262-
x: extendFlat({}, surfaceAtts.lightposition.x, {dflt: 1e5}),
263-
y: extendFlat({}, surfaceAtts.lightposition.y, {dflt: 1e5}),
264-
z: extendFlat({}, surfaceAtts.lightposition.z, {dflt: 0})
265-
},
238+
contour: meshAttrs.contour,
239+
lightposition: meshAttrs.lightposition,
266240
lighting: meshAttrs.lighting,
241+
flatshading: meshAttrs.flatshading,
267242

268243
hoverinfo: extendFlat({}, baseAttrs.hoverinfo)
269244
}), 'calc', 'nested');
270245

246+
// required defaults to speed up surface normal calculations
247+
attrs.flatshading.dflt = true; attrs.lighting.facenormalsepsilon.dflt = 0;
248+
271249
attrs.x.editType = attrs.y.editType = attrs.z.editType = attrs.value.editType = 'calc+clearAxisTypes';
272250
attrs.transforms = undefined;

src/traces/isosurface/convert.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -396,9 +396,9 @@ function generateIsosurfaceMesh(data) {
396396

397397
function tryCreateTri(style, xyzv, abc, min, max, isSecondPass) {
398398

399-
abc = [-1, -1, -1]; // Note: for the moment we had to override indices
400-
// for planar surfaces (i.e. caps and slices) due to group shading
401-
// bug of gl-mesh3d. But don't worry this would run faster!
399+
abc = [-1, -1, -1]; // Note: for the moment we override indices
400+
// to run faster! But it is possible to comment this line
401+
// to reduce the number of vertices.
402402

403403
var tryDrawTri = function(style, xyzv, abc) {
404404
if( // we check here if the points are in `real` iso-min/max range

src/traces/isosurface/defaults.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
9595
'lightposition.x',
9696
'lightposition.y',
9797
'lightposition.z',
98-
'flatshading',
98+
'flatshading'
9999
].forEach(function(x) { coerce(x); });
100100

101101
colorscaleDefaults(traceIn, traceOut, layout, coerce, {prefix: '', cLetter: 'c'});
Loading
6.18 KB
Loading
Loading

test/image/mocks/gl3d_isosurface_log-axis_slices_surface-fill.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -1878,11 +1878,11 @@
18781878
1.000, 1.450, 1.900, 2.350, 2.800, 3.250, 3.700, 4.150, 4.600, 5.050, 5.500, 5.950, 6.400, 6.850, 7.300, 7.750, 8.200, 8.650, 9.100, 9.550, 10.000
18791879
],
18801880
"lighting": {
1881-
"ambient": 0.5,
1882-
"diffuse": 1.0,
1883-
"specular": 0.75,
1884-
"roughness": 1.0,
1885-
"fresnel": 0.25
1881+
"ambient": 0.5,
1882+
"diffuse": 1.0,
1883+
"specular": 0.75,
1884+
"roughness": 1.0,
1885+
"fresnel": 0.25
18861886
},
18871887
"lightposition": {
18881888
"x": 10000,

test/image/mocks/gl3d_isosurface_thin_caps_different_dims.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -3638,11 +3638,11 @@
36383638
-10, -8, -6, -4, -2, 0, 2, 4, 6, 8, 10
36393639
],
36403640
"lighting": {
3641-
"ambient": 0.5,
3642-
"diffuse": 1.0,
3643-
"specular": 0.75,
3644-
"roughness": 1.0,
3645-
"fresnel": 0.25
3641+
"ambient": 0.5,
3642+
"diffuse": 1.0,
3643+
"specular": 0.75,
3644+
"roughness": 1.0,
3645+
"fresnel": 0.25
36463646
},
36473647
"lightposition": {
36483648
"x": 10000,

test/image/mocks/gl3d_isosurface_uneven-scales_ranges_iso-null.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -1878,11 +1878,11 @@
18781878
0.000, 0.015, 0.120, 0.405, 0.960, 1.875, 3.240, 5.145, 7.680, 10.935, 15.000, 19.965, 25.920, 32.955, 41.160, 50.625, 61.440, 73.695, 87.480, 102.885, 120.000
18791879
],
18801880
"lighting": {
1881-
"ambient": 0.5,
1882-
"diffuse": 1.0,
1883-
"specular": 0.75,
1884-
"roughness": 1.0,
1885-
"fresnel": 0.25
1881+
"ambient": 0.5,
1882+
"diffuse": 1.0,
1883+
"specular": 0.75,
1884+
"roughness": 1.0,
1885+
"fresnel": 0.25
18861886
},
18871887
"lightposition": {
18881888
"x": 10000,

test/image/mocks/gl3d_isosurface_with_surface-pattern.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -1878,11 +1878,11 @@
18781878
-10.000, -9.998, -9.980, -9.932, -9.840, -9.688, -9.460, -9.143, -8.720, -8.178, -7.500, -6.672, -5.680, -4.507, -3.140, -1.563, 0.240, 2.282, 4.580, 7.147, 10.000
18791879
],
18801880
"lighting": {
1881-
"ambient": 0.5,
1882-
"diffuse": 1.0,
1883-
"specular": 0.75,
1884-
"roughness": 1.0,
1885-
"fresnel": 0.25
1881+
"ambient": 0.5,
1882+
"diffuse": 1.0,
1883+
"specular": 0.75,
1884+
"roughness": 1.0,
1885+
"fresnel": 0.25
18861886
},
18871887
"lightposition": {
18881888
"x": 10000,

test/image/mocks/gl3d_isosurface_xycaps_volume_slices.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -2838,11 +2838,11 @@
28382838
0, 0.008, 0.061, 0.207, 0.492, 0.960, 1.659, 2.634, 3.932, 5.599, 7.680, 10.222, 13.271, 16.873, 21.074, 25.920, 31.457, 37.732, 44.790, 52.677, 61.440, 71.124, 81.777, 93.443, 106.168, 120
28392839
],
28402840
"lighting": {
2841-
"ambient": 0.5,
2842-
"diffuse": 1.0,
2843-
"specular": 0.75,
2844-
"roughness": 1.0,
2845-
"fresnel": 0.25
2841+
"ambient": 0.5,
2842+
"diffuse": 1.0,
2843+
"specular": 0.75,
2844+
"roughness": 1.0,
2845+
"fresnel": 0.25
28462846
},
28472847
"lightposition": {
28482848
"x": 10000,

0 commit comments

Comments
 (0)