enthought / mayavi

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

Mayavi window stop showing up #467

Open martinakos opened 7 years ago

martinakos commented 7 years ago

I've been using mayavi in python 3.5 and on a windows 10 machine. Today I was working on some script using mayavi and for no reason (that I know) the mayavi visualization window stopped showing up. In fact any mayavi example doesn't show the visualization window anymore. The scripts do wait on the mlab.show() but they won't show anything.

I've tried all the following but it still doesn't show the visualization window (each time just waiting at the mlab.show() command):

Probably unrelated, but the last thing I was doing before the window stop showing up was recording a script from the mayavi properties window, I wanted to see what commands correspond to moving the viewpoint to a certain place. Once I saw the commands being recorded, I copied them and close the mayavi visualization window without stopping the recording. From that moment onwards I experienced the described problem.

Any idea what's going on?

martinakos commented 7 years ago

I've been debugging the boy.py example on the machine that works and on the one that doesn't (both machines have the same software configuration) and I've found the first point in which their execution deviates.

When creating a figure:

mlab.figure(fgcolor=(0, 0, 0), bgcolor=(1, 1, 1)) the machine that works opens an empty vtk/mayavi window, the machine that doesn't work doesn't open anything.

I step through the figure function (in the machine that doesn't work) and I found that at this point in the execution stack it starts to deviate:

boy.py,  line 23
  mlab.figure(fgcolor=(0, 0, 0), bgcolor=(1, 1, 1))
figure.py,  line 68, in figure
  engine.new_scene(name=name, size=size)
recordable.py,  line 45, in _wrapper
  result = func(*args, **kw)
engine.py,  line 452, in new_scene
  viewer = self.scene_factory(**factory_kwargs)

viewer is a mayavi.core.null_engine.DummyViewer object, where as in the machine it works viewer is a mayavi.core.ui.mayavi_scene.MayaviViewer object

I also find that the factory_kwargs passed to self.scene_factory is {} in the machine it doesn't work, and it's {'size': (400,350)} in the machine it works.

I'm trying to understand how the scene_factory works but it's a bit daunting task.

martinakos commented 7 years ago

I found a solution!

Stepping through the code for mlab.figure() I found that at this point in the execution stack:

boy.py,  line 23
  mlab.figure(fgcolor=(0, 0, 0), bgcolor=(1, 1, 1))
figure.py,  line 63, in figure
  engine = get_engine()
engine_manager.py,  line 101, in get_engine
  return self.new_engine()
engine_manager.py,  line 154, in new_engine
  elif options.backend == 'test':

the backend was 'test' which instantiates a

engine = NullEngine(name='Null Mlab Engine')

in the machine that works the backend was 'auto' and it instantiates a

engine = Engine(name='Mlab Engine')

So I searched for how this backend is set, something related with the mayavi.preferences.prefence_manager.py I saw that in the same folder there is a preferences.ini . However, it already had a variable set as backend ='auto' .

Then I found that the script mayavi.scripts.mayavi2.py shows a data visualizer. If we select the menu option Tools/Preferences/Mayavi/Mlab the field backend was set to 'test'. I changed it to 'auto' and then the mayavi boy.py example started to work again!

One confusing thing is that then I went back to my original Python 3.5 installation and my original virtualenv. I run the boy.py example and it worked without having to do anything on that installation. So I suspect that these settings are being stored somewhere else outside the python or virtualenv folders, maybe in the windows registry? That is why re-installing mayavi, even in a new virtualenv and with a new python installation didn't solve the problem!

I'm not sure how the backend changed, probably I changed it myself while experimenting with mayavi. However, I think these preferences shouldn't be persistent outside the virtualenv or the python installation in use.