nipy / PySurfer

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

Feature request: obtain vertex number by clicking on the brain #218

Closed wmvanvliet closed 6 years ago

wmvanvliet commented 6 years ago

I really wish I had the ability to click on the brain and get the vertex number and the corresponding index of the data matrix. Sometimes I see something interesting on the cortex and would like to quickly get to the corresponding row in the data matrix.

christianbrodbeck commented 6 years ago

In the mne-python coreg-GUI you can click on the head to set fiducials, you should be able to find all the necessary mayavi functions there.

mwaskom commented 6 years ago

This is already built into mayavi. I'm pretty sure you just need to click and then press "p".

mwaskom commented 6 years ago

Here's a very simple example to show how you can also define a mayavi callback to do this that you can extend to use the index directly in your code:

from mayavi import mlab
from surfer import Brain
b = Brain("fsaverage", "lh", "inflated")
f = mlab.figure("fsaverage")
f.on_mouse_pick(lambda p: print(p.point_id), button="Right")

After executing this, right-clicking on a vertex should result in its index being printed to stdout. I'm not sure if there's a simpler way to get the figure handle. It's buried in a private attribute in the Brain object (in the b._figures nested list), so going through mlab to get it seemed to make sense.

mwaskom commented 6 years ago

Closing as I don't see a need for any more functionality in pysurfer itself but others can comment/reopen if they want to add something.

wmvanvliet commented 6 years ago

I never knew! Thanks for the tips!