enthought / mayavi

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

Error when setting colorbar in traits #86

Open Tscheik opened 11 years ago

Tscheik commented 11 years ago

Dear Mayavi developers, I've run into (another :) ) error... This time when trying to display a colorbar within the traits example:

#!/usr/bin/env python
"""A simple example of how to use mayavi.mlab inside a traits UI dialog.

This example uses traitsUI (
`traitsUI <http://code.enthought.com/projects/traits/>`_ ) to create a
the simplest possible dialog: a single Mayavi scene in a window.
"""

# Authors: Prabhu Ramachandran <prabhu [at] aero.iitb.ac.in>
#          Gael Varoquaux
# Copyright (c) 2007, Enthought, Inc.
# License: BSD Style.

# Standard imports.
from numpy import sqrt, sin, mgrid

# Enthought imports.
from traits.api import HasTraits, Instance
from traitsui.api import View, Item
from tvtk.pyface.scene_editor import SceneEditor

from mayavi.tools.mlab_scene_model import MlabSceneModel
from mayavi.core.ui.mayavi_scene import MayaviScene

######################################################################
class ActorViewer(HasTraits):

    # The scene model.
    scene = Instance(MlabSceneModel, ())

    ######################
    # Using 'scene_class=MayaviScene' adds a Mayavi icon to the toolbar,
    # to pop up a dialog editing the pipeline.
    view = View(Item(name='scene',
                     editor=SceneEditor(scene_class=MayaviScene),
                     show_label=False,
                     resizable=True,
                     height=500,
                     width=500),
                resizable=True
                )

    def __init__(self, **traits):
        HasTraits.__init__(self, **traits)
        self.generate_data()

    def generate_data(self):
        # Create some data
        X, Y = mgrid[-2:2:100j, -2:2:100j]
        R = 10*sqrt(X**2 + Y**2)
        Z = sin(R)/R

        self.scene.mlab.surf(X, Y, Z, colormap='gist_earth')
        self.scene.mlab.colorbar()

if __name__ == '__main__':
    a = ActorViewer()
    a.configure_traits()

throws an error:

ERROR: In /Users/builder/pisi-64bit/tmp/VTK-5.6.0-3/work/VTK/Widgets/vtkAbstractWidget.cxx, line 119
vtkScalarBarWidget (0x1186380c0): The interactor must be set prior to enabling the widget

I'm not sure whether this is an mayavi issue or a VTK bug (or I'm missing something and this is done otherwise...).

Best regards, Tscheik

dpinte commented 11 years ago

@Tscheik can you report what platform you use? and what EPD/Canopy version? This code runs fine on Canopy 1.1

Tscheik commented 11 years ago

Hi @dpinte, I'm using Canopy 1.1.1.1452 (64 bit) on a MacOSX 10.7.5. The error is also triggered with EPD 7.1-1 (32-bit) on the same machine.

dpinte commented 11 years ago

I am on 1.1.0.371 on MacOSX 10.6 64bit.

Tscheik commented 11 years ago

I also tested this with ubuntu 12.04 and 13.04 (mayavi2 should be version 4.0.0.3, respectively 4.1.0.1, see http://packages.ubuntu.com/precise/mayavi2 and http://packages.ubuntu.com/raring/mayavi2), same error:

ERROR: In /build/buildd/vtk-5.8.0/Widgets/vtkAbstractWidget.cxx, line 118
vtkScalarBarWidget (0x775ed20): The interactor must be set prior to enabling the widget
aokj4ck commented 10 years ago

I am also having this issue on OS X 10.9 with Canopy 1.4. Has there been a fix (for client or Enthought code)?

stefanoborini commented 8 years ago

Confirmed still present in 4.4.4 with vtk 6.2 and 7.1. Investigating.

stefanoborini commented 8 years ago

After investigation, I am not sure we can call it a bug, rather it's intended behavior. The problem, straightforward from the message, is that we are trying to install the scalarbarwidget before there's an interactor. This check is perform in the vtkAbstractWidget class. in generate_data we are not displaying anything yet, so there's no interactor setup, and the call to colorbar() ends up creating the vtkScalarBarWidget too early.

My point is that graphic setup should occur later, when the displaying environment is correctly setup.

stefanoborini commented 8 years ago

Specifically, maybe the example should be changed to something along these lines. This works as intended.

#!/usr/bin/env python
"""A simple example of how to use mayavi.mlab inside a traits UI dialog.

This example uses traitsUI (
`traitsUI <http://code.enthought.com/projects/traits/>`_ ) to create a
the simplest possible dialog: a single Mayavi scene in a window.
"""

# Authors: Prabhu Ramachandran <prabhu [at] aero.iitb.ac.in>
#          Gael Varoquaux
# Copyright (c) 2007, Enthought, Inc.
# License: BSD Style.

# Standard imports.
from numpy import sqrt, sin, mgrid

# Enthought imports.
from traits.api import HasTraits, Instance
from traitsui.api import View, Item, ModelView
from tvtk.pyface.scene_editor import SceneEditor

from mayavi.tools.mlab_scene_model import MlabSceneModel
from mayavi.core.ui.mayavi_scene import MayaviScene

class SceneView(ModelView):
    # The scene model.
    scene = Instance(MlabSceneModel, ())

    ######################
    # Using 'scene_class=MayaviScene' adds a Mayavi icon to the toolbar,
    # to pop up a dialog editing the pipeline.
    view = View(Item(name='scene',
                     editor=SceneEditor(scene_class=MayaviScene),
                     show_label=False,
                     resizable=True,
                     height=500,
                     width=500),
                resizable=True,
                )

    def init(self, arg):
        self.scene.mlab.surf(self.model.X, self.model.Y, self.model.Z, colormap='gist_earth')
        self.scene.mlab.colorbar()

class ActorViewer(HasTraits):
    def __init__(self, **traits):
        HasTraits.__init__(self, **traits)

        # Create some data
        self.X, self.Y = mgrid[-2:2:100j, -2:2:100j]
        self.R = 10*sqrt(self.X**2 + self.Y**2)
        self.Z = sin(self.R)/self.R

if True:
    a = ActorViewer()
    view = SceneView(model=a)
    view.configure_traits()

However, I must say that this message appears at every repaint. I don't know if it's unrelated or not.

ERROR: In /Users/vagrant/pisi-64bit/tmp/VTK-6.2.0-1/work/VTK-6.2.0/Rendering/OpenGL/vtkOpenGLTexture.cxx, line 200
vtkOpenGLTexture (0x11efbcce0): No scalar values found for texture input!

The alternative would be to postpone the enabling of the scalarbar if the interactor is None.

stefanoborini commented 8 years ago

I leave this pending. @prabhuramachandran any comment?