mayavi enthought volume rendering buggy gui

357 Views Asked by At

I think I have come across a genuine bug. It seems that something very strange and certainly unintuitive is happening with the colortransferfunction(CTF) interface.

I'll describe here what I've shown in the movie at the following link(5MB): https://drive.google.com/file/d/0B2DsQIFbCQmELTZzWVc1MDc1MGM/view?usp=sharing

Action: mlab.pipeline.volume(whatever). It doesn't matter how the volume rendering is created. Result: The volume source is displayed as red. Fine.

Action: The user just clicks on the volume transfer function without changing it much. You can even move it back to exactly where it was. Result: The volume source totally changes colors from red to green: suggesting the CTF in the "Mayavi pipeline" window is not the same as the one originally used in "Mayavi Scene 1"

Action: The user, having clicked on the opacity transfer function at least once, clicks away. Then the user clicks back. Result: The CTF totally changes to this blue-red fade instead of this nice three-color style before. If the user messes with the OTF once more, update CTF will change the volume again! from this green color to this red-purple-ish.

Note: It's not just "clicking away" and clicking back that causes this weird change in CTF. I originally ran into this problem while changing data sources. I had say 5 difference volumes. Whenever I would say "array_src.scalar_values=my_volumes.next()" the CTF would change from a rgb to a blue-red fade if and only if I had tried to alter the ctf manually in the GUI.

I really hope we can get this resolved.

Thanks, Chris Snyder

1

There are 1 best solutions below

0
On

I have a workaround. The point here is that when you switch your data to be volume rendered, the ctf and otf stay in place instead of doing strange re-scalings and color changing. The solution is two fold.

1) Make sure all your data volumes are scaled to exactly 0-255. You must make sure the smallest and largest values are exactly 0 and 255 respectively, not just merely in the range [0,255]. This is important because under the hood mayavi tries to rescale the ctf/otf ranges according to your data when you switch out array.scalar_data. However, it fails in strange ways.

2) Instead of working with the built in editor from SceneEditor(MayaviScene), expose directly the Volume.view trait associated with your data. Changes to this ctf/otf editor do not switch the volume from blue-green-red mode to this blue-red fade when the underlying data is changed. Here is how to do it: (The critical line is Item('vol_module',style='custom',show_label=False)

B=io.imread(bad)
G=io.imread(good)
B=B-B.min();B/=B.max();B*=255
G=G-G.min();G/=G.max();G*=255
class Vis(HasTraits):
    query=Str()
    scene     = Instance(MlabSceneModel,())    

    switch_data=Button()

    #You have to put vol_module here (or call add_trait later in init) for View() to see it
    vol_module=Instance(Volume(),())
    editor=SceneEditor(scene_class=MayaviScene)
    def __init__(self,G,B):
        self.G=G
        self.B=B
        HasTraits.__init__(self)
        self.array_src=ArraySource()
        self.array_src.scalar_data=G
        self.G_active=True
        self.scene.mayavi_scene.add_child(self.array_src)
        self.volume=self.array_src.add_module(self.vol_module)


    def _switch_data_fired(self):
        if self.G_active:
            self.array_src.scalar_data=self.B
            self.G_active=False
        else:
            self.array_src.scalar_data=self.G
            self.G_active=True

    traits_view = View( 
            HGroup(
                    Item('scene',editor=editor,height=250, width=300, show_label=False),

                    Item('vol_module',style='custom',show_label=False),#critical
                  )
                     )

vis=Vis(G,B)
#vis=Vis(B,G)
vis.configure_traits()