Skip to content

Commit 1326afe

Browse files
payamsashlarsoner
andauthored
ENH: add overlay Brain GUI (#14031)
Co-authored-by: Eric Larson <larson.eric.d@gmail.com>
1 parent 979e9a7 commit 1326afe

9 files changed

Lines changed: 252 additions & 35 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
When multiple overlays are active (via ``remove_existing=False`` in :meth:`~mne.viz.Brain.add_data`), the interactive Brain viewer now shows an "Overlay" drop-down in the *Color Limits* dock panel that lets the user switch which overlay's color limits and smoothing the sliders control. By `Payam Sadeghi-Shabestari`_.

examples/visualization/brain.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,11 @@
219219
# alpha-composited by :class:`~mne.viz.LayeredMesh` so both datasets appear
220220
# at the same time.
221221
#
222-
# Here we simulate two focal patches of activity in different brain regions:
223-
# a temporal source (red/hot) and a frontal source (blue).
222+
# Here we simulate two focal patches of activity evolving over time in
223+
# different brain regions: a temporal source (red/hot) that peaks early and
224+
# a frontal source (blue) that peaks later. In the interactive viewer an
225+
# "Overlay" drop-down appears in the *Color Limits* panel — use it to switch
226+
# which overlay's limits and smoothing the sliders control.
224227

225228
brain = mne.viz.Brain(
226229
"sample",
@@ -246,6 +249,7 @@ def gaussian_patch(coords, center, sigma=15.0):
246249
fmin=0.1,
247250
fmax=1.5,
248251
colormap="hot",
252+
transparent=True,
249253
key="temporal",
250254
smoothing_steps=5,
251255
)
@@ -257,6 +261,7 @@ def gaussian_patch(coords, center, sigma=15.0):
257261
fmin=0.1,
258262
fmax=0.6,
259263
colormap="Blues",
264+
transparent=True,
260265
alpha=0.5,
261266
key="frontal",
262267
remove_existing=False,

mne/viz/_3d_overlay.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,9 @@ def _clean(self):
263263
self._polydata = None
264264
self._renderer = None
265265

266-
def update_overlay(self, name, scalars=None, colormap=None, opacity=None, rng=None):
266+
def update_overlay(
267+
self, name, scalars=None, colormap=None, opacity=None, rng=None, update=True
268+
):
267269
"""Update an existing overlay in-place.
268270
269271
Parameters
@@ -281,6 +283,11 @@ def update_overlay(self, name, scalars=None, colormap=None, opacity=None, rng=No
281283
New opacity in ``[0, 1]``. If ``None``, opacity is unchanged.
282284
rng : array-like, shape (2,) | None
283285
New ``[min, max]`` colormap range. If ``None``, range is unchanged.
286+
update : bool
287+
If ``True`` (default), recompose overlays and refresh the mesh
288+
immediately. Pass ``False`` to stage the change without
289+
triggering a recompose; the caller is then responsible for
290+
calling :meth:`update` once all overlays have been staged.
284291
"""
285292
overlay = self._overlays.get(name, None)
286293
if overlay is None:
@@ -304,6 +311,8 @@ def update_overlay(self, name, scalars=None, colormap=None, opacity=None, rng=No
304311
overlay._opacity = opacity
305312
if rng is not None:
306313
overlay._rng = rng
314+
if not update:
315+
return
307316
# partial update: use cache if possible
308317
if name == list(self._overlays.keys())[-1]:
309318
self.update(colors=overlay.to_colors())

0 commit comments

Comments
 (0)