Mayavi Colorbar Woes

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Mayavi Colorbar Woes

Lorenzo Dimagiba
Hello all,

I seem to be having a bit of an issue displaying the colorbar for my mayavi scene. Here is the code that appears to need some tinkering:



self.basket0 = mlab.mesh(datax, datay, dataz, figure=self.scene1.mayavi_scene,
scalars=self.basket_CI[i], vmin  = vmin,vmax= vmax, colormap='jet')
self.basket0.actor.mapper.interpolate_scalars_before_mapping = True
mlab.colorbar(title = 'ms')


Using this code, my model generates perfectly, however the colorbar does not appear, and the following error is received:

vtkScalarBarWidget (08923810): The interactor must be set prior to enabling the widget


Does anybody have any idea what might be the issue here? If it is of any value, I am displaying my mayavi content in a traits dialog box. Thanks for any help!

Lorenzo

_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: Mayavi Colorbar Woes

Roan LaPlante
You might have noticed that your example fails when using an embedded UI but works fine if making standalone calls to mlab.  The problem is timing; the scene is not yet fully initialized by the time you do the processing which is probably in __init__.  Doing stuff in __init__ happens before traits are initialized.  The solution is to listen to 'scene.activated' and do all of your image processing after that.


from mayavi.core.ui.api import MlabSceneModel,MayaviScene,SceneEditor

class App(HasTraits):
    scene=Instance(MlabSceneModel,())

    traits_view=View(Item(name='scene',editor=SceneEditor(scene_class=MayaviScene),height=500,width=500))

    @on_trait_change('scene.activated')
    def setup(self):
        datax,datay,dataz=np.random.random((3,100,100))

        basket0=mlab.mesh(datax,datay,dataz,colormap='cool',figure=self.scene.mayavi_scene)
        basket0.actor.mapper.interpolate_scalars_before_mapping=True
        mlab.colorbar(title='ms')

App().configure_traits()



R


On Wed, Aug 14, 2013 at 9:32 AM, Lorenzo Dimagiba <[hidden email]> wrote:
Hello all,

I seem to be having a bit of an issue displaying the colorbar for my mayavi scene. Here is the code that appears to need some tinkering:



self.basket0 = mlab.mesh(datax, datay, dataz, figure=self.scene1.mayavi_scene,
scalars=self.basket_CI[i], vmin  = vmin,vmax= vmax, colormap='jet')
self.basket0.actor.mapper.interpolate_scalars_before_mapping = True
mlab.colorbar(title = 'ms')


Using this code, my model generates perfectly, however the colorbar does not appear, and the following error is received:

vtkScalarBarWidget (08923810): The interactor must be set prior to enabling the widget


Does anybody have any idea what might be the issue here? If it is of any value, I am displaying my mayavi content in a traits dialog box. Thanks for any help!

Lorenzo

_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev


The information in this e-mail is intended only for the person to whom it is
addressed. If you believe this e-mail was sent to you in error and the e-mail
contains patient information, please contact the Partners Compliance HelpLine at
http://www.partners.org/complianceline . If the e-mail was sent to you in error
but does not contain patient information, please contact the sender and properly
dispose of the e-mail.




--
Roan LaPlante
Athinoula A. Martinos Center for Biomedical Imaging


_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: Mayavi Colorbar Woes

Lorenzo Dimagiba
In reply to this post by Lorenzo Dimagiba
Your method of of utilizing 'scene.activated' definitely worked. What puzzles me however is the fact that I am able to use the exact same code (as I had provided) in a situation where it does work. I wonder if you/someone might be able to explain this phenomenon.

To get the code to work as is, I go about the following steps:

1. I create my dialog instance from my main program
2. I make the dialog appear as a page in my overall GUI.
3. I invoke the method in my dialog instance that plots my model and puts the colorbar.

self.decrement_view = Basket_Decrement()
self.control3 = self.decrement_view.edit_traits(
                parent=self,
                kind='subpanel').control
self.notebook.AddPage(page=self.control3, caption='Decrement Maps')
self.notebook.AdvanceSelection(forward=True)
self.decrement_view.draw_decrement_basket(path) ##this is the method which plots and puts the  colorbar and such##

Running my code like this allows me to add the colorbar as I had it.

However, trying to run my code in a more simple way, on its own:
test = Basket_Decrement()
test.draw_decrement_basket(path)

Does not allow me to keep my code as is, and display a colorbar.

_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: Mayavi Colorbar Woes

Roan LaPlante
I'm not 100% sure of the order in which things happen if your GUI is composed of these notebook pages, but the basic principle is still the same.

The scene is initialized as soon as it needs to be.  If you call configure_traits(), before setting up the GUI, traitsui/enaml will make sure that all of the traits exposed are initialized, and then build the GUI for you.  Absent something actually asking for the scene to be displayed (I think in your example it is edit_traits() ), it won't ever be initialized, and some things (specifically anything depending on interactive features) won't work, because it hasn't finished being built yet.


R


On Wed, Aug 14, 2013 at 3:38 PM, Lorenzo Dimagiba <[hidden email]> wrote:
Your method of of utilizing 'scene.activated' definitely worked. What puzzles me however is the fact that I am able to use the exact same code (as I had provided) in a situation where it does work. I wonder if you/someone might be able to explain this phenomenon.

To get the code to work as is, I go about the following steps:

1. I create my dialog instance from my main program
2. I make the dialog appear as a page in my overall GUI.
3. I invoke the method in my dialog instance that plots my model and puts the colorbar.

self.decrement_view = Basket_Decrement()
self.control3 = self.decrement_view.edit_traits(
                parent=self,
                kind='subpanel').control
self.notebook.AddPage(page=self.control3, caption='Decrement Maps')
self.notebook.AdvanceSelection(forward=True)
self.decrement_view.draw_decrement_basket(path) ##this is the method which plots and puts the  colorbar and such##

Running my code like this allows me to add the colorbar as I had it.

However, trying to run my code in a more simple way, on its own:
test = Basket_Decrement()
test.draw_decrement_basket(path)

Does not allow me to keep my code as is, and display a colorbar.

_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev


The information in this e-mail is intended only for the person to whom it is
addressed. If you believe this e-mail was sent to you in error and the e-mail
contains patient information, please contact the Partners Compliance HelpLine at
http://www.partners.org/complianceline . If the e-mail was sent to you in error
but does not contain patient information, please contact the sender and properly
dispose of the e-mail.




--
Roan LaPlante
Athinoula A. Martinos Center for Biomedical Imaging


_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev