Color Transfer Functions in Mayavi

93 views
Skip to first unread message

Williams, Darren

unread,
May 24, 2021, 4:13:58 PM5/24/21
to ets-...@googlegroups.com
Hi Prabhu (and others).

I found the following piece from you on the web from a few years 
ago regarding color transfer functions.

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 
instead of transparency. 

c['rgb'] something ?

Thanks in advance. 

Darren Williams
Penn State
Reply all
Reply to author
Forward
0 new messages