Add UI event support for Brain class#11891
Conversation
|
For the linking of camera's, here are my thoughts about it: While it is certainly something you may want to do in certain cases, it is also something you may not want to do. Calling There's a performance consideration. The straightforward implementation of |
I'm surprised by this. I'd expect most to be 4x4 and very fast to compute or combine, and VTK should do a lot of it in c++ or in the GPU. Can you give an example bit if code that shows the slowdown? But in the end even if it's a bit slow during interactive rotation it's perhaps not necessarily a deal breaker. |
|
This is ready for review now! |
|
I haven’t benchmarked show_view yet, I’ll give it a try. But it feels inefficient seeing how many events camera movement will spawn |
|
Even done in Python it seems quite fast to do some multiplies: And at the renderer level VTK should be smart enough not to render faster than 60 Hz (I think it is) and do all this stuff in C++ or (more likely) at the GPU level just at render time. So I'm still optimistic... |
mne/viz/ui_events.py
Outdated
| The first figure whose event channel will be linked to the second. | ||
| fig2 : matplotlib.figure.Figure | Figure3D | ||
| The second figure whose event channel will be linked to the first. | ||
| figs : matplotlib.figure.Figure | Figure3D |
There was a problem hiding this comment.
I think this should be something like
| figs : matplotlib.figure.Figure | Figure3D | |
| figs : tuple of matplotlib.figure.Figure, shape (n,) | tuple of Figure3D, shape (n,) |
|
I've looked into building a However, I've run into a problem: if I get the camera parameters from |
|
So for this PR, I'm going to leave it alone I think. |
|
Works beautifully @wmvanvliet, in it goes! |
Co-authored-by: Eric Larson <larson.eric.d@gmail.com>
Now that we have a UI event system, we can start work on implementing it in places where we want extra interop between figures. This PR tackles the
Brainobject.UI Events implemented:
CameraMove (when you move the camera)(difficult to implement, likely YAGNI)The idea is to completely replace the
Brain.callbacksdictionary,mne/viz/_brain/callback.py, andmne.viz._brain/_LInkViewerwith the UI events system.Along the way, two bugs are fixed:
int(time)conversion where it should have remained afloat.MNEsource estimate has values around 1E-10 and the sliders would effectively have a range of [0, 0]. This PR adds a scaling factor for the sliders to make them useful in these cases.The event-handing codepath for updating something about the plot goes as follows:
Brain.set_time) publishes a UI event (TimeChange)TimeChange), possibly by calling the public method, but could also publish the UI event directly if the public function has too much overhead.Brainsubscribes to its own UI events and calls a private function when receiving it (Brain._on_time_change)Brain._on_time_change) updates the plot and GUI elements to match the new value.