Skip to main content

MNEMshDisplaySurface

Namespace: MNELIB  ·  Library: MNE Library

#include <mne/mne_msh_display_surface.h>

class MNELIB::MNEMshDisplaySurface

Replaces *mshDisplaySurface, mshDisplaySurfaceRec struct (analyze_types.c).

The MNE Msh Display FsSurface class holds information about a surface to be rendered.

src/examples/ex_mne_api/main.cpp
// Total solid angle seen from a point: 4 pi inside a closed surface, 0 outside
auto skull = MNESurface::read_bem_surface2(bemFile.fileName(), FIFFV_BEM_SURF_ID_BRAIN, true);
skull->compute_surface_cm();
const double inside = skull->sum_solids(Map<const Vector3f>(skull->cm)) / (4.0 * M_PI);
const double outside = skull->sum_solids(Vector3f(0.0f, 0.0f, 0.2f)) / (4.0 * M_PI);

// The same surface as an MNE-C viewer display surface
MNEMshDisplaySurfaceSet display;
display.add_bem_surface(bemFile.fileName(), FIFFV_BEM_SURF_ID_BRAIN, "inner skull", 1, 1); // checks closure
const MNEMshDisplaySurface& shown = *display.surfs[0];

Inheritance​


Public Methods​

MNEMshDisplaySurface()​

Constructs the MNEMshDisplaySurface.


~MNEMshDisplaySurface()​

Destroys the MNEMshDisplaySurface.


align_fiducials(head_dig, mri_dig, niter, scale_head, omit_dist, scales)​

Align MEG and MRI coordinate systems using fiducial points and ICP.

Parameters:

  • head_dig : FiffDigitizerData & MEG digitizer data (transformed in-place).

  • mri_dig : const FiffDigitizerData & MRI digitizer data with fiducial locations.

  • niter : int Number of ICP iterations.

  • scale_head : int If non-zero, scale the head surface to match digitizer.

  • omit_dist : float Discard digitizer points farther than this from the surface (m).

  • scales : Eigen::Vector3f & If non-null, receives the per-axis scale factors applied.

Returns:

  • int — OK on success, FAIL on error.

get_head_scale(dig, mri_fid, scales)​

Compute a uniform head scale factor by fitting spheres.

Parameters:

  • dig : FiffDigitizerData & Digitizer data; points with positive z are used for the sphere fit.

  • mri_fid : const Eigen::Matrix3f & MRI fiducial locations (LPA, nasion, RPA rows), in m.

  • scales : Eigen::Vector3f & Receives the per-axis scale factors (all set to 1 if a sphere fit fails).


discard_outlier_digitizer_points(d, maxdist)​

Mark digitizer points whose distance to the head surface exceeds maxdist.

Parameters:

  • d : FiffDigitizerData & Digitizer data; its discard flags and distances are updated.

  • maxdist : float Maximum allowed distance to the surface, in m; cardinal and HPI points are never discarded.

Returns:

  • int — Number of points discarded.

calculate_digitizer_distances(dig, do_all, do_approx)​

Compute the distance from each active digitizer point to the head surface.

Parameters:

  • dig : FiffDigitizerData & Digitizer data; dist, closest and closest_point are updated.

  • do_all : bool If true, include inactive and discarded points.

  • do_approx : bool If true, start the closest-point search from the previously found triangles.


iterate_alignment_once(dig, nasion_weight, nasion_mri, last_step)​

Perform one iteration of ICP-like alignment.

Parameters:

  • dig : FiffDigitizerData & Digitizer data; head_mri_t_adj and distances are updated.

  • nasion_weight : int Weight of the nasion point in the Procrustes fit.

  • nasion_mri : const std::optional< Eigen::Vector3f > & Optional fixed MRI location of the nasion, in m.

  • last_step : int Non-zero if this is the final iteration (enables exact distances).

Returns:

  • int — OK on success, FAIL if no adjustable transform exists, fewer than 3 points are active, or the fit fails.

rms_digitizer_distance(dig)​

Compute the RMS distance from active digitizer points to the head surface.

Parameters:

Returns:

  • float — RMS distance of the active, non-discarded points, in m.

scale(scales)​

Scale a display surface's bounding box and all vertex positions.

Parameters:

  • scales : const Eigen::Vector3f & Per-axis scale factors (x, y, z).

decide_surface_extent(tag)​

Compute and store the axis-aligned bounding box and field-of-view radius by iterating all vertex positions.

Parameters:

  • tag : const QString & FsSurface name tag (used for debug logging).

decide_curv_display(name)​

Set the curvature display mode based on a surface type name.

Inflated, sphere, and white surfaces use overlay mode; others use none.

Parameters:

  • name : const QString & FsSurface type name.

setup_curvature_colors()​

Allocate and fill per-vertex color arrays using positive/negative curvature colors (if curvature overlay mode is on) or uniform gray.


Example​

Used in examples​

ex_mne_api​

MNE library: BEM surfaces, surface projection, ICP, source spaces and epochs.

src/examples/ex_mne_api/main.cpp, line 469
// The same surface as an MNE-C viewer display surface
MNEMshDisplaySurfaceSet display;
display.add_bem_surface(bemFile.fileName(), FIFFV_BEM_SURF_ID_BRAIN, "inner skull", 1, 1); // checks closure
const MNEMshDisplaySurface& shown = *display.surfs[0];
// mne.surface._get_solids (which returns the solid angle / 2): 0.5 at the centroid, 0 at (0, 0, 200) mm;
// bounding box -66.7 ... 105.8 mm, centroid (0.67, -10.01, 44.26) mm
ok &= expect(near(inside, 1.0, 1e-6) && std::fabs(outside) < 1e-6 && (Map<const Vector3f>(skull->cm) - Vector3f(0.00067339f, -0.01001356f, 0.04426273f)).norm() < 1e-6f,
"MNESurface: solid angles show the inner skull is closed, like mne._get_solids");
ok &= expect(display.nsurf == 1 && shown.np == 2562 && shown.surf_name == "inner skull" && near(shown.fov, 0.10576099902391434, 1e-6) && (shown.minv - Vector3f(-0.0667366f, -0.0880172f, -0.0445037f)).norm() < 1e-6f,
"MNEMshDisplaySurfaceSet/MNEMshDisplaySurface: the BEM surface and its extent in the viewer");

Authors of this file​