Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when setting colorbar in traits #86

Open
Tscheik opened this issue Oct 10, 2013 · 9 comments
Open

Error when setting colorbar in traits #86

Tscheik opened this issue Oct 10, 2013 · 9 comments
Labels

Comments

@Tscheik
Copy link

Tscheik commented Oct 10, 2013

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
Copy link
Member

dpinte commented Oct 10, 2013

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

@Tscheik
Copy link
Author

Tscheik commented Oct 10, 2013

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
Copy link
Member

dpinte commented Oct 10, 2013

I am on 1.1.0.371 on MacOSX 10.6 64bit.

@Tscheik
Copy link
Author

Tscheik commented Oct 10, 2013

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
Copy link

aokj4ck commented May 30, 2014

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
Copy link
Contributor

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

@stefanoborini
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

I leave this pending. @prabhuramachandran any comment?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants