Skip to content
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 scalar bar #93

Open
teteraf opened this issue Dec 9, 2013 · 4 comments
Open

Volume scalar bar #93

teteraf opened this issue Dec 9, 2013 · 4 comments
Labels

Comments

@teteraf
Copy link

teteraf commented Dec 9, 2013

First of all congratulations for the great work you do with Mayavi!
I have been trying to visualise a volume using Maximum Intensity Projection and cannot get the scalar bar depicted properly unless I kind of "update" the source. In the example at the end, the scalar bar appears just black. A workaround I have found is to change the name of the dataset (see last code line).
I have seen this behaviour on Windows 7 (Enthought Canopy 1.1.0 64 bit) and on Ubuntu 12.04 64 bit (Mayavi 4.0.0, VTK 5.8.0, Python 2.7.3).
Do you know why does this happen and if there is any other way of solving it?
In addition, is it possible to create a colorbar that also displays the alpha channel?

Thanks in advance!

# Testing lut and transparency for a given Volume
import numpy as np
x, y, z = np.ogrid[-.5:.5:200j, -.5:.5:200j, -.5:.5:200j]
r = np.sqrt(x**2 + y**2 + z**2)
# Generalized Laguerre polynomial (3, 2)
L = -r**3/6 + 5./2*r**2 - 10*r + 6
# Spherical harmonic (3, 2)
Y = (x+y*1j)**2*z/r**3
Phi = L*Y*np.exp(-r)*r**2
# Defining array for ColorTransferFunction
clr=np.array([[0,0,0,0],
  [abs(Phi).max()*0.5,0.9,0,0],
  [abs(Phi).max(),1,0.9,0]])
# Defining opacity array
opct=np.array([[0,0],
  [abs(Phi).max()*0.5,0.5],
  [abs(Phi).max(),1]])
clr=clr.transpose()
opct=opct.transpose()
# Visualize it with mlab.volume
from mayavi import mlab
mlab.figure(1, fgcolor=(1, 1, 1), bgcolor=(0, 0, 0))
# We create a scalar field with the module of Phi as the scalar
src = mlab.pipeline.scalar_field(np.abs(Phi))
vuf = mlab.pipeline.volume(src)
vuf.volume_mapper.lock_sample_distance_to_input_spacing = True
vuf.volume_mapper.blend_mode = 'maximum_intensity'

# Changing the ctf: 
from tvtk.util.ctf import ColorTransferFunction
# ctf.add_rgb_point(value, r, g, b) # r, g, and b are float between 0 and 1
# ctf.add_hsv_point(value, h, s, v)
ctf = ColorTransferFunction()
for n in range(np.shape(clr)[1]):
    aux=np.squeeze(clr[:,n])
    ctf.add_rgb_point(aux[0],aux[1],aux[2],aux[3])

vuf._volume_property.set_color(ctf)
vuf._ctf = ctf
vuf.update_ctf = True

# Changing the otf:
from tvtk.util.ctf import PiecewiseFunction
# otf.add_point(value, opacity)
otf = PiecewiseFunction()
for n in range(np.shape(opct)[1]):
    aux=np.squeeze(opct[:,n])
    otf.add_point(aux[0],aux[1])
vuf._otf = otf
vuf._volume_property.set_scalar_opacity(otf)
ctf.range = [abs(Phi).min(), abs(Phi).max()]

vuf.lut_manager.show_scalar_bar = True
# src.scalar_name='Phi' # Uncomment to get it to work 
@stefanoborini
Copy link
Contributor

Confirmed. Investigating.

@stefanoborini
Copy link
Contributor

I am puzzled because the LUT is apparently keeping the default hue (red-blue gradient) even when the correct gradient is shown. it's not touched and yet it's the only source for the widget. There is some mechanism at work that I still haven't found.

@stefanoborini
Copy link
Contributor

The Volume Module appears to be installing a VolumeProperty to the LUT where all color values are zero. Probably uninitialized _volume_property?

@stefanoborini
Copy link
Contributor

After investigation, I don't think this is a bug. The main problem is that you are accessing members that are considered private, but in any case the issue is that you are replacing the CTF on the Volume. The VolumeProperty has an internal CTF that never gets updated. Internally, we keep this consistent, but manipulating it from the outside you obtain strange results.

@prabhuramachandran any comment?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants