nipy / PySurfer

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

Annotations/Labels invisible from certain angles #299

Open jshanna100 opened 3 years ago

jshanna100 commented 3 years ago

I recently upgraded from Ubuntu 18 to 20, and updated my NVIDIA drivers to 460.39, and now pysurfer is not displaying parcellations and labels correctly anymore. From certain angles, the parcellation borders are somehow not visible, though if one rotates the brain they are visible. It is as though there is an inverse spotlight shining on the brain from above (see picture).

Changing the cortex alpha to 0.99 fixes the problem, though it is not a long term solution for me. 0.99 is still somehow quite transparent, and for my purposes I need the cortex to be opaque.

image

mwaskom commented 3 years ago

I think this is the same issue described in this thread: https://github.com/nipy/PySurfer/issues/258

Unfortunately as I understand it this is fundamentally a bug in some of the lower-level graphics libraries and there's no one-size-fits-all solution that can be implemented in pysurfer. But that thread has some workarounds that people have reported as effective on their specific systems.

jshanna100 commented 3 years ago

Thanks. Unfortunately none of the workarounds solved the problem for me, but I did run across some odd properties of the Brain surface opacity.

If I set the alpha to 1 as a parameter during the initialisation of the Brain object, and then manually set it 0.99 in the Mayavi pipeline, the cortex is almost completely opaque, as it should be. If, however, I set it to 0.99 as a Brain initialisation parameter, it is fairly transparent, and even more strangely, if I attempt to further change it manually in the Mayavi pipeline, it cannot reach the needed level of opacity; i.e. at 0.99 the cortex is too transparent, but the parcellation is drawn correctly, and then at 1.0 the cortex is completely opaque, but the parcellations are buggy again.

larsoner commented 3 years ago

You could try enabling depth peeling with something like:

for ff in brain._figures:
    for f in ff:
        f.scene.renderer.use_depth_peeling = True

It's designed to help with depth-buffer resolution problems.

Alternatively, you might be able to use MNE-Python's implementation of a simialar Brain class. We basically started by trying to replicate the parts of PySurfer's viz using PyVista instead of Mayavi then moved toward volume viz, interactive viz, etc. according to what we needed in a new design along the lines of what has been discussed before. We recently refactored things so that all alpha blending of the overlays is done in the CPU so just a single mesh ends up being rendered per hemisphere.

jshanna100 commented 3 years ago

Enabling depth peeling had no effect except to significantly slow down redraw speed.

The MNE Brain class draws it perfectly well, but the problem is that I'm using this with some custom functionality I've made for visualising connectivity that makes heavy use of mlab's points3d and plot3d functions. It's not clear to me if/how these can be utilised within the mne.viz.Brain class...

mmagnuski commented 3 years ago

I had the same problem on one of my computers. A solution suggested in this issue by @solleo works well for me. For one hemisphere you can do:

n_children = len(brain.brain_matrix[0][0]._f.children)

for idx in range(1, n_children):
    (brain.brain_matrix[0][0]._f.children[idx].children[0].children[0]
     .children[0].actor.actor.force_opaque) = True