-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Volume traces #2753
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
Volume traces #2753
Changes from 1 commit
6a9c27b
31fbc97
d3fc93f
9e8378d
0691672
a48ee0e
27e6334
e0d7fa1
bbaaebb
c392a7d
d7ae2fd
ce212cb
6866c18
379efe6
61b9f60
34a1aa7
4f11e35
0b06423
34b40f0
4c6f59c
d788250
7107b68
8f93b02
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,7 +52,12 @@ var attrs = { | |
valType: 'data_array', | ||
role: 'info', | ||
editType: 'calc', | ||
description: 'Sets the opacity scale of the volume, which opacity to use for which intensity. Array of 256 values in 0..1 range.' | ||
description: [ | ||
'Sets the opacity scale of the volume.', | ||
'Defines which opacity to use for which intensity.', | ||
'Multiplied with trace.opacity to obtain the final opacity.', | ||
'Colorscale-like array of [[0, opacity0], [v1, opacity1], ..., [1, opacityN]].' | ||
].join(' ') | ||
}, | ||
|
||
imin: { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I forget. Did we settle on We should also explain how this pair of attributes is related to volumeOpts.isoBounds = [trace.cmin, trace.cmax];
volumeOpts.intensityBounds = [
trace.imin === undefined ? trace.cmin : trace.imin,
trace.imax === undefined ? trace.cmax : trace.imax
]; in the attribute |
||
|
@@ -69,27 +74,6 @@ var attrs = { | |
description: 'Sets the maximum intensity bound of the volume.' | ||
}, | ||
|
||
opacity: { | ||
valType: 'number', | ||
role: 'info', | ||
editType: 'calc', | ||
description: 'Sets the opacity of the volume.' | ||
}, | ||
|
||
boundmin: { | ||
valType: 'data_array', | ||
role: 'info', | ||
editType: 'calc', | ||
description: '' | ||
}, | ||
|
||
boundmax: { | ||
valType: 'data_array', | ||
role: 'info', | ||
editType: 'calc', | ||
description: '' | ||
}, | ||
|
||
text: { | ||
valType: 'string', | ||
role: 'info', | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,8 +33,8 @@ | |
} | ||
|
||
var opacityscale = [] | ||
for (var i=0; i<256; i++) { | ||
opacityscale[i] = Math.pow(i/256, 1.2) | ||
for (var i=0; i<16; i++) { | ||
opacityscale[i] = [i/15, Math.pow(i/15, 1.2)] | ||
} | ||
|
||
Plotly.newPlot(gd, [{ | ||
|
@@ -101,6 +101,33 @@ proto.handlePick = function(selection) { | |
} | ||
}; | ||
|
||
function parseOpacityScale(opacityScale) { | ||
var alphaMapLength = 256; | ||
var alphaMap = new Float32Array(alphaMapLength); | ||
var alphaMapIndex = 0; | ||
var previousEntry = [0, 1]; | ||
for(var i = 0; i < opacityScale.length; i++) { | ||
var entry = opacityScale[i]; | ||
var startIndex = alphaMapIndex; | ||
var startValue = previousEntry[1]; | ||
var endIndex = Math.max(0, Math.min(Math.floor(entry[0] * alphaMapLength), alphaMapLength-1)); | ||
var endValue = entry[1]; | ||
var indexDelta = endIndex - startIndex; | ||
while(alphaMapIndex < endIndex) { | ||
var t = (alphaMapIndex - startIndex) / indexDelta; | ||
alphaMap[alphaMapIndex] = (1 - t) * startValue + t * endValue; | ||
alphaMapIndex++; | ||
} | ||
alphaMap[alphaMapIndex] = endValue; | ||
previousEntry = entry; | ||
} | ||
var lastAlpha = alphaMap[alphaMapIndex]; | ||
while(alphaMapIndex < alphaMapLength) { | ||
alphaMap[alphaMapIndex++] = lastAlpha; | ||
} | ||
return alphaMap; | ||
} | ||
|
||
var axisName2scaleIndex = {xaxis: 0, yaxis: 1, zaxis: 2}; | ||
|
||
function getSequence(src) { | ||
|
@@ -141,18 +168,12 @@ function convert(gl, scene, trace) { | |
toDataCoords(zs, 'zaxis') | ||
]; | ||
|
||
// var bounds = [ | ||
// volumeOpts.boundmin || [xs[0], ys[0], zs[0]], | ||
// volumeOpts.boundmax || [xs[xs.length - 1], ys[ys.length - 1], zs[zs.length - 1]] | ||
// ]; | ||
|
||
|
||
volumeOpts.values = trace.value; | ||
|
||
volumeOpts.colormap = parseColorScale(trace.colorscale); | ||
|
||
if(trace.opacityscale) { | ||
volumeOpts.alphamap = trace.opacityscale; | ||
volumeOpts.alphamap = parseOpacityScale(trace.opacityscale); | ||
} | ||
|
||
volumeOpts.isoBounds = [trace.cmin, trace.cmax]; | ||
|
@@ -161,8 +182,6 @@ function convert(gl, scene, trace) { | |
trace.imax === undefined ? trace.cmax : trace.imax | ||
]; | ||
|
||
volumeOpts.opacity = trace.opacity === undefined ? 1 : trace.opacity; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can still set this, if it'll get used downstream - which it looks like it will based on your amended description for My point was just that you don't need to handle the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ohh, right, thanks for catching this. |
||
|
||
var bounds = [[0, 0, 0], volumeOpts.dimensions]; | ||
|
||
var volume = volumePlot(gl, volumeOpts, bounds); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this mapping over the same range as
colorscale
? If so, can we specify it similarly, as a piecewise-linear list of pairs[[0, opacity0], [v1, opacity1], ..., [1, opacityN]]
?Is this used along with
trace.opacity
? Like the two are multiplied together perhaps? However that works it should be in the description.