|
136 | 136 | fig.suptitle("Dipole Fits Scaled by Amplitude and Colored by GOF") |
137 | 137 |
|
138 | 138 |
|
| 139 | +# %% |
| 140 | +# Update overlays via ``Brain.layered_meshes`` |
| 141 | +# -------------------------------------------- |
| 142 | +# |
| 143 | +# After :meth:`~mne.viz.Brain.add_data` is called, each hemisphere's surface |
| 144 | +# is backed by a :class:`~mne.viz.LayeredMesh` stored in |
| 145 | +# ``brain.layered_meshes``. Calling |
| 146 | +# :meth:`~mne.viz.LayeredMesh.update_overlay` pushes new scalar data without |
| 147 | +# rebuilding the full rendering pipeline — the key operation for packages that |
| 148 | +# stream source-space data onto the brain in real time, such as |
| 149 | +# `MNE-RT <https://payamsash.github.io/mne-rt/>`_. |
| 150 | +# |
| 151 | +# Here we add an initial bottom-to-top gradient as the first data frame. |
| 152 | + |
| 153 | +brain = mne.viz.Brain("sample", subjects_dir=subjects_dir, hemi="lh", **brain_kwargs) |
| 154 | +coords = brain.geo["lh"].coords |
| 155 | +data_t0 = coords[:, 2] |
| 156 | +data_t0 = (data_t0 - data_t0.min()) / (data_t0.max() - data_t0.min()) |
| 157 | +brain.add_data( |
| 158 | + data_t0, hemi="lh", fmin=0, fmax=1, colormap="viridis", smoothing_steps=5 |
| 159 | +) |
| 160 | +brain.show_view(azimuth=190, elevation=70, distance=350, focalpoint=(0, 0, 20)) |
| 161 | + |
| 162 | +# %% |
| 163 | +# Simulate a new data frame arriving: call |
| 164 | +# :meth:`~mne.viz.LayeredMesh.update_overlay` on the **same** brain to replace |
| 165 | +# the scalars in-place — no new mesh, no new actor, no pipeline rebuild. |
| 166 | + |
| 167 | +# we create a new brain here for comparison purposes |
| 168 | +brain_update = mne.viz.Brain( |
| 169 | + "sample", subjects_dir=subjects_dir, hemi="lh", **brain_kwargs |
| 170 | +) |
| 171 | +brain_update.add_data( |
| 172 | + data_t0, hemi="lh", fmin=0, fmax=1, colormap="viridis", smoothing_steps=5 |
| 173 | +) |
| 174 | +brain_update.show_view(azimuth=190, elevation=70, distance=350, focalpoint=(0, 0, 20)) |
| 175 | +data_t1 = coords[:, 1] |
| 176 | +data_t1 = (data_t1 - data_t1.min()) / (data_t1.max() - data_t1.min()) |
| 177 | +mesh = brain_update.layered_meshes["lh"] |
| 178 | +mesh.update_overlay(name="data", scalars=data_t1) |
| 179 | +mesh.update() |
| 180 | + |
139 | 181 | # %% |
140 | 182 | # Use per-vertex opacity for distributed data |
141 | 183 | # -------------------------------------------- |
|
0 commit comments