enthought / enthought/mayavi

Volume scalar bar

Open
#93 4 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Python
Stars
1.4k
Forks
316
Avg merge
7h 44m
Merged PRs (30d)
5

Description

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!

``` python
# 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
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.