Skip to main content

MneICP

Namespace: MNELIB  ·  Library: MNE Library

Module

This page documents a header-level module — a collection of free functions that share an algorithmic topic. There is no enclosing C++ class; the functions live directly in the library namespace.

Python equivalent

mne.coreg.Coregistration in MNE-Python.

#include <mne/mne_icp.h>

SPDX-License-Identifier: BSD-3-Clause Copyright (c) 2026 MNE-CPP Authors.

Free functions for the point-to-surface ICP used by mne-cpp's coregistration tools to refine an initial head <-> MRI transformation: MNELIB::fitMatchedPoints aligns matched point pairs (e.g. fiducials), MNELIB::discard3DPointOutliers drops points far from the surface, and MNELIB::performIcp projects each point onto the nearest triangle of an MNEBemSurface (via MNEProjectToSurface), solves a rigid-body least squares with SVD and iterates until convergence.

src/examples/ex_mne_api/main.cpp
// 1. Rough start from three matched points (e.g. the fiducials)
Matrix4f start;
MatrixXf mriPoints(3, 3);
mriPoints << innerSkull.rr.row(0), innerSkull.rr.row(20), innerSkull.rr.row(40);
fitMatchedPoints(headShape.topRows(3), mriPoints, start);
FiffCoordTrans headToMri(FIFFV_COORD_HEAD, FIFFV_COORD_MRI, start);
// 2. Drop head shape points further than 10 mm from the surface, then refine with ICP
auto surface = QSharedPointer<MNEProjectToSurface>::create(innerSkull);
VectorXi take;
MatrixXf kept;
discard3DPointOutliers(surface, headShape, headToMri, take, kept, 0.01f);
float rmse = 0.0f;
performIcp(surface, kept, headToMri, rmse, false, 50, 1e-6f);

Functions​

performIcp(mneSurfacePoints, matPointCloud, transFromTo, fRMSE, bScale, iMaxIter, fTol, vecWeights)​

bool performIcp(const QSharedPointer<[MNEProjectToSurface](/docs/api/mne/mne-project-to-surface)> mneSurfacePoints, const Eigen::MatrixXf & matPointCloud, [FiffCoordTrans](/docs/api/fiff/fiff-coord-trans) & transFromTo, float & fRMSE, bool bScale, int iMaxIter, float fTol, const Eigen::VectorXf & vecWeights);

The ICP algorithm to register a point cloud with a surface.

Parameters:

  • mneSurfacePoints : const QSharedPointer<MNEProjectToSurface> The MNEProjectToSurface object that contains the surface triangles etc. (To).

  • matPointCloud : const Eigen::MatrixXf & The point cloud to be registered (From).

  • transFromTo : FiffCoordTrans & The forward transformation matrix. It can contain an initial transformation (e.g. from fiducial alignment).

  • fRMSE : float & The resulting Root-Mean-Square-Error in m.

  • bScale : bool Whether to apply scaling or not. Should be false for matching data sets, defaults to false.

  • iMaxIter : int The maximum number of iterations for the ICP algorithm, defaults to 20.

  • fTol : float The convergence tolerance, defaults to 0.001.

  • vecWeights : const Eigen::VectorXf & The weights to apply, defaults to zeros.

Returns:

  • bool — Whether the registration was successful.

fitMatchedPoints(matSrcPoint, matDstPoint, matTrans, fScale, bScale, vecWeights)​

bool fitMatchedPoints(const Eigen::MatrixXf & matSrcPoint, const Eigen::MatrixXf & matDstPoint, Eigen::Matrix4f & matTrans, float fScale, bool bScale, const Eigen::VectorXf & vecWeights);

Corresponding point set registration using quaternions.

Parameters:

  • matSrcPoint : const Eigen::MatrixXf & The source point set.

  • matDstPoint : const Eigen::MatrixXf & The destination point set.

  • matTrans : Eigen::Matrix4f & The forward transformation matrix.

  • fScale : float The scaling parameter, defaults to 1.0.

  • bScale : bool Whether to apply scaling or not. Should be false for matching data sets, defaults to false.

  • vecWeights : const Eigen::VectorXf & The weights to apply, defaults to zeros.

Returns:

  • bool — Whether the matching was successful.

discard3DPointOutliers(mneSurfacePoints, matPointCloud, transFromTo, vecTake, matTakePoint, fMaxDist)​

bool discard3DPointOutliers(const QSharedPointer<[MNEProjectToSurface](/docs/api/mne/mne-project-to-surface)> mneSurfacePoints, const Eigen::MatrixXf & matPointCloud, const [FiffCoordTrans](/docs/api/fiff/fiff-coord-trans) & transFromTo, Eigen::VectorXi & vecTake, Eigen::MatrixXf & matTakePoint, float fMaxDist);

Discard outliers compared to a given 3D surface.

Parameters:

  • mneSurfacePoints : const QSharedPointer<MNEProjectToSurface> The MNEProjectToSurface object that contains the surface triangles etc. (To).

  • matPointCloud : const Eigen::MatrixXf & The point cloud to be registered (From).

  • transFromTo : const FiffCoordTrans & The forward transformation matrix.

  • vecTake : Eigen::VectorXi & The index of taken digitizers.

  • matTakePoint : Eigen::MatrixXf & The digitizer points to take.

  • fMaxDist : float The maximum distance to the surface in mm, defaults to 0 mm.

Returns:

  • bool — Whether the discarding was successful.

Example​

Authors of this file​