import numpy as np
from mayavi import mlab
mlab.figure(bgcolor=(1, 1, 1))
x, y, z = np.ogrid[-10:10:20j, -10:10:20j, -10:10:20j]
s = np.sin(x*y*z)/(x*y*z)
src = mlab.pipeline.scalar_field(s)
vol = mlab.pipeline.volume(src)
# Change the color transfer function
from tvtk.util import ctf
c = ctf.save_ctfs(vol._volume_property)
print c
c['alpha'][1][1] = 1.0
ctf.load_ctfs(c, vol._volume_property)
# Update the shadow LUT of the volume module.
vol.update_ctf = True
mlab.show()
The key here is the save_ctfs
and load_ctfs
.
You can look at https://github.com/enthought/mayavi/blob/master/tvtk/util/ctf.py if
you want to understand this a bit better. All the example above does is to manipulate the opacity transfer function and set it back on the volume property.
Can you please explain what the two [1] numbers in the line
c['alpha'][1][1] = 1.0
do? Also how would this line change if I wanted to edit colors