enthought / mayavi

3D visualization of scientific data in Python
http://docs.enthought.com/mayavi/mayavi/
Other
1.3k stars 284 forks source link

imshow ignores transparency and LUT changes of alpha values #611

Open raphael-attie opened 6 years ago

raphael-attie commented 6 years ago

I failed to make scalar-field-based transparency work with imshow(). I first tried setting transparent=True but this had no effect when done programmatically. It is only taken into account when I use the GUI to change to the "black-white" colormap (and only this one). I tried also changing the lookup table in the module_manager. No effect. If I directly use "black-white" colormap, I still need to go to the GUI, change the colormap, and go back to "black-white" for the transparency to work.

Here's a code to replicate:

data = np.repeat(np.linspace(0,1,512)[:,np.newaxis], 512, axis=1 )
mlab.figure(bgcolor=(1,1,1))
# Use transparency
im = mlab.imshow(data, colormap='cool', transparent=True)

# Tried changing the lookup table below. No effect. 
cmap = im.module_manager.scalar_lut_manager.lut.table.to_array()
cmap[:, -1] = np.linspace(0, 255, 256)
im.module_manager.scalar_lut_manager.lut.table = cmap
mlab.draw()
mlab.view(0, 0)
mlab.show()

This is under macOS Sierra 10.12.6.
Python 3.5 with qt 4.8.7. Graphics: Radeon Pro 460 & Intel HD Graphics 530 Mayavi 4.5

raphael-attie commented 6 years ago

I found a programmatic workaround by using the update_pipeline() method of the ImageActor returned byimshow() after changing the LUT.

data = np.repeat(np.linspace(0,1,512)[:,np.newaxis], 512, axis=1 )
mlab.figure(bgcolor=(1,1,1))
# Use transparency
im = mlab.imshow(data, colormap='cool', transparent=True)

# **WORKING** 
cmap = im.module_manager.scalar_lut_manager.lut.table.to_array()
cmap[:, -1] = np.linspace(0, 255, 256)
im.module_manager.scalar_lut_manager.lut.table = cmap
**im.update_pipeline()**
mlab.view(0, 0)

The use of the method 'update_pipeline()' does not seem to be documented. I found it by chance, by looking at all functions containing the expression "update*" in ImageActor.

Nonetheless, this workaround works whether the keyword transparent is True or False. Which makes the latter still inoperative.

prabhuramachandran commented 6 years ago

I am not surprised at this as changing the table directly may not signal to VTK underneath that anything has changed. Firing an update_pipeline explicitly flushes the pipeline and re-hooks up everything. I am not sure there is much that can be done about this. Do you that if the documentation is updated this would be a bit easier?

raphael-attie commented 6 years ago

Sure, as far as I'm concerned an update in the documentation would suffice.

On Mar 5, 2018 8:16 AM, "Prabhu Ramachandran" notifications@github.com wrote:

I am not surprised at this as changing the table directly may not signal to VTK underneath that anything has changed. Firing an update_pipeline explicitly flushes the pipeline and re-hooks up everything. I am not sure there is much that can be done about this. Do you that if the documentation is updated this would be a bit easier?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/enthought/mayavi/issues/611#issuecomment-370415602, or mute the thread https://github.com/notifications/unsubscribe-auth/AGOxw3wswSJPVcb4i1FE74x--xDimvoVks5tbTrEgaJpZM4SY2uc .