nipy / PySurfer

Cortical neuroimaging visualization in Python
https://pysurfer.github.io/
BSD 3-Clause "New" or "Revised" License
239 stars 98 forks source link

Problem with overlay rendering when visualizing the inverse problem #284

Closed filip-halemba closed 4 years ago

filip-halemba commented 4 years ago

During visualization of inverse problem with mne-python I produced "leaky" picture like in picture below.

Screenshot from 2020-01-19 22-19-31

I started to asking question on gitter where @larsoner put some advice for me. After few days I resolved my problem by enabling backface culling for the overlay.

Screenshot from 2020-02-03 22-34-32 Screenshot from 2020-02-03 22-34-39

This task was created at the request of @larsoner - https://gitter.im/mne-tools/mne-python?at=5e3899b1e8a838355913a83a

wmvanvliet commented 4 years ago

Is there any downside to enabling backface culling by default?

larsoner commented 4 years ago

I thought that there were some cases when the brain was partially transparent where it seemed better to have it off. So one option is to enable backface culling when the brain alpha is 1. and disable it otherwise. @wmvanvliet since you can replicate do you want to try?

wmvanvliet commented 4 years ago

I've done some digging around. Unfortunately, the problem goes deeper than backface culling. There is a bug in Qt5 regarding obtaining an OpenGL rendering context with a depth buffer. Somehow, for some non-nvidia chipsets, Qt5 creates a context without depth buffering. Hence vertices are rendered in the wrong order. Hence bad rendering bugs like we see in this issue. Here is a clue:

http://vtk.1045678.n5.nabble.com/VTK-master-Qt-5-and-Intel-i915-driver-on-Ubuntu-Linux-tt5727112.html

Temporary fix is to switch Mayavi over to the wx rendering engine. But that has problems of its own.

wmvanvliet commented 4 years ago

Backface culling removes a lot of vertices from the render queue and hence alleviates the problems a bit.

larsoner commented 4 years ago

The only other idea I have is trying to tweak the OpenGL rendering to set the polygon offset (negative values for the ones we want on top) and enabling polygon offset for fill mode. Not sure if this requires a functional depth buffer but it might.

wmvanvliet commented 4 years ago

Here's how things look with a non-nvidia card. It's not limited to just the overlay:

fig

larsoner commented 4 years ago

No offset fill is going to save you from that :(

If a usable workaround is actually to use a QVTKWidget2 instead of QVTKWidget, then we could try updating mayavi to use this newer widget. We could also see if PyVista could make a corresponding change. There have been depth problems in mne coreg that would might also be fixed by such a change.

wmvanvliet commented 4 years ago

Way ahead of you :) Mayavi, well pyface, doesn't use QVTKWidget directly, but does it's own thing on top of QGLWidget: https://github.com/enthought/mayavi/blob/master/tvtk/pyface/ui/qt4/QVTKRenderWindowInteractor.py

larsoner commented 4 years ago

Cross-ref to https://github.com/pyvista/pyvista/issues/473. Maybe the fix there combined with using VTK 8.2+ would fix things.

larsoner commented 4 years ago

(on my VTK 8.1.2 and NVIDIA hardware my QVTKRWIBase is 'QWidget')

wmvanvliet commented 4 years ago

It would be awesome if we could solve this!

larsoner commented 4 years ago

@wmvanvliet you can try conda-forge to see if the 8.2 they have up there can be used:

https://anaconda.org/conda-forge/vtk/files

It might automatically work, and if not, maybe look into what they did in pyvista/pyvista#473 to fix things...