mne.viz.LayeredMesh#

class mne.viz.LayeredMesh(renderer, vertices, triangles, normals)[source]#

A mesh with support for layered RGBA overlays and optional smoothing.

This class manages a single brain-surface mesh and composites multiple named overlays (e.g., curvature, data, labels) on top of each other using alpha blending. It is the object stored in Brain.layered_meshes.

Warning

This class is not meant to be instantiated directly, and the initialization API could change at any time! Use mne.viz.Brain.add_data() to create instances.

Parameters:
rendererinstance of _Renderer

The renderer used to create the underlying mesh polydata.

verticesarray, shape (n_vertices, 3)

Vertex coordinates in metres.

trianglesarray, shape (n_triangles, 3)

Triangle indices into vertices.

normalsarray, shape (n_vertices, 3)

Vertex normals.

Attributes:
smooth_matscipy.sparse.csr_array or None

Optional spatial smoother / upsampler applied to scalar data before rendering. When set (e.g., by set_data_smoothing()), every call to update_overlay() will multiply the incoming scalars by this matrix before storing them. Shape must be (n_surface_vertices, n_source_vertices).

Methods

add_overlay(scalars, colormap, rng, opacity, ...)

Add a named overlay to the mesh.

remove_overlay(names)

Remove one or more overlays by name.

update([colors])

Recompose all overlays and refresh the mesh texture.

update_overlay(name[, scalars, colormap, ...])

Update an existing overlay in-place.

Notes

New in v1.13.

add_overlay(scalars, colormap, rng, opacity, name, smooth=False)[source]#

Add a named overlay to the mesh.

Parameters:
scalarsarray, shape (n_vertices,)

Scalar values to display. If smooth=True and smooth_mat is set, shape must be (n_src_vertices,).

colormaparray, shape (n_colors, 4)

RGBA colormap table (values in [0, 255]).

rngarray_like, shape (2,)

[min, max] range for colormap mapping.

opacityfloat | None

Overlay opacity in [0, 1]. None keeps the existing value.

namestr

Unique key identifying this overlay.

smoothbool

If True and smooth_mat is set, multiply scalars by smooth_mat before rendering. Use True only for source-space data; surface-space overlays (curvature, labels, annotations) should use the default False.

remove_overlay(names)[source]#

Remove one or more overlays by name.

Parameters:
namesstr | list of str

Name(s) of the overlay(s) to remove.

update(colors=None)[source]#

Recompose all overlays and refresh the mesh texture.

Parameters:
colorsarray_like of shape (n_triangles, 4) | None

Pre-composited RGBA colors to blend over the cached layer stack. If None, all overlays are recomposed from scratch.

Examples using update:

Plotting with mne.viz.Brain

Plotting with mne.viz.Brain
update_overlay(name, scalars=None, colormap=None, opacity=None, rng=None)[source]#

Update an existing overlay in-place.

Parameters:
namestr

Key of the overlay to update (must already exist).

scalarsarray, shape (n_vertices,) | None

New scalar values. If None, scalars are unchanged. If smooth_mat is set, smoothing is applied automatically (matching the behaviour of the original add_data() call that created the overlay).

colormaparray, shape (n_colors, 4) | None

New RGBA colormap table. If None, colormap is unchanged.

opacityfloat | None

New opacity in [0, 1]. If None, opacity is unchanged.

rngarray_like, shape (2,) | None

New [min, max] colormap range. If None, range is unchanged.

Examples using update_overlay:

Plotting with mne.viz.Brain

Plotting with mne.viz.Brain

Examples using mne.viz.LayeredMesh#

Plotting with mne.viz.Brain

Plotting with mne.viz.Brain