IOUtils
Namespace: UTILSLIB · Library: Utilities Library
#include <utils/ioutils.h>
class UTILSLIB::IOUtils
IO utility routines for reading/writing Eigen matrices to text files.
Eigen matrix I/O utilities.
MatrixXd matrix(2, 3);
matrix << 1.5, -2.0, 3.25, 0.0, 1e-6, 42.0;
const QString matrixPath = dir.filePath("matrix.txt");
IOUtils::write_eigen_matrix(matrix, matrixPath, "example matrix");
MatrixXd readBack;
IOUtils::read_eigen_matrix(readBack, matrixPath);
Public Methods
~IOUtils()
Static Methods
write_eigen_matrix(in, sPath, sDescription)
Write Eigen Matrix to file (QString path).
Parameters:
-
in : const Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > & Matrix to write as whitespace-separated text, one row per line.
-
sPath : const QString & Path of the output file; an existing file is overwritten.
-
sDescription : const QString & Optional description; if non-empty, a dimensions and description header is written.
Returns:
- bool — True on success, false if the file could not be opened for writing.
write_eigen_matrix(in, sPath, sDescription)
write_eigen_matrix(in, sPath, sDescription)
write_eigen_matrix(in, sPath, sDescription)
Write Eigen Matrix to file (std::string path).
Parameters:
-
in : const Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > & Matrix to write as whitespace-separated text, one row per line.
-
sPath : const std::string & Path of the output file; an existing file is overwritten.
-
sDescription : const std::string & Optional description; if non-empty, a dimensions and description header is written.
Returns:
- bool — True on success, false if the file could not be opened for writing.
write_eigen_matrix(in, sPath, sDescription)
write_eigen_matrix(in, sPath, sDescription)
read_eigen_matrix(out, path)
Read Eigen Matrix from file (QString path).
Parameters:
-
out : Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > & Matrix resized and filled with the values read; lines containing '#' are skipped.
-
path : const QString & Path of the whitespace-separated text file to read.
Returns:
- bool — True on success, false if the file could not be opened.
read_eigen_matrix(out, path)
read_eigen_matrix(out, path)
read_eigen_matrix(out, path)
Read Eigen Matrix from file (std::string path).
Parameters:
-
out : Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > & Matrix resized and filled with the values read; lines containing '#' are skipped.
-
path : const std::string & Path of the whitespace-separated text file to read.
Returns:
- bool — True on success, false if the file could not be opened.
read_eigen_matrix(out, path)
read_eigen_matrix(out, path)
Example
- Full source:
src/examples/ex_utils/main.cpp - Build target:
ex_utils(runs under CTest)
Used in examples
ex_utils
Utilities library: buffers, observers, logging, file formats, montages, layouts and reports.
MatrixXd matrix(2, 3);
matrix << 1.5, -2.0, 3.25, 0.0, 1e-6, 42.0;
const QString matrixPath = dir.filePath("matrix.txt");
IOUtils::write_eigen_matrix(matrix, matrixPath, "example matrix");
MatrixXd readBack;
IOUtils::read_eigen_matrix(readBack, matrixPath);
ok &= expect(readBack.rows() == 2 && readBack.cols() == 3 && (readBack - matrix).cwiseAbs().maxCoeff() < 1e-12,
"IOUtils text matrix round trip");
ex_hpiFit
Example for cHPI fitting on raw data with SSP. The result is written to a .txt file for comparison with MaxFilter's .pos file.
IOUtils::write_eigen_matrix(matPosition, QString(QCoreApplication::applicationDirPath() + "/MNE-sample-data/" + sNameOut));
}
}
ex_inv_hpi
Inverse library: continuous head position (HPI) fitting.
// MaxFilter head position at t = 0: translation (-0.814, -11.046, 53.572) mm. One 200 ms window, so allow 1 mm
// (test_hpiFit_integration holds the mean over the whole recording to 0.3 mm).
MatrixXd maxfilter;
IOUtils::read_eigen_matrix(maxfilter, data + "/Result/ref_hpiFit_pos.txt");
const Vector3d translation = fit.devHeadTrans.trans.block<3, 1>(0, 3).cast<double>();
const Vector3d reference = maxfilter.block<1, 3>(0, 4).transpose();
ok &= expect(fit.hpiFreqs == QVector<int>({166, 154, 161, 158}) && fit.GoF.minCoeff() > 0.98 && (translation - reference).norm() < 0.001,
QString("InvHpiDataUpdater/InvHpiModelParameters/InvHpiFit: coils ordered 166/154/161/158 Hz, head position within %1 mm of MaxFilter")
.arg(1e3 * (translation - reference).norm(), 0, 'f', 3));
Also used in ex_read_fwd.
Authors of this file
- Christoph Dinh <christoph.dinh@mne-cpp.org>
- Lorenz Esch <lorenz.esch@tu-ilmenau.de>
- Ricky <rickytjen@yahoo.com>
- Juan GPC <jgarciaprieto@mgh.harvard.edu>
- Gabriel Motta <gabrielbenmotta@gmail.com>
- Andreas Griesshammer <ag@fieldlineinc.com>