v2.0.0
Loading...
Searching...
No Matches
mne_sparse_named_matrix.cpp
Go to the documentation of this file.
1//=============================================================================================================
12
13//=============================================================================================================
14// INCLUDES
15//=============================================================================================================
16
18
19#include <fiff/fiff_constants.h>
20#include <fiff/fiff_tag.h>
21
22//=============================================================================================================
23// USED NAMESPACES
24//=============================================================================================================
25
26using namespace MNELIB;
27using namespace FIFFLIB;
28
29//=============================================================================================================
30// DEFINE MEMBER METHODS
31//=============================================================================================================
32
33std::unique_ptr<MNESparseNamedMatrix> MNESparseNamedMatrix::read(FiffStream::SPtr& stream,
34 const FiffDirNode::SPtr& node,
35 int kind)
36{
38 FiffTag::UPtr tag;
39 if (node->type == FIFFB_MNE_NAMED_MATRIX) {
40 if (node->find_tag(stream, kind, tag)) {
41 block = node;
42 }
43 } else {
44 for (const FiffDirNode::SPtr& child : node->children) {
45 if (child->type == FIFFB_MNE_NAMED_MATRIX && child->find_tag(stream, kind, tag)) {
46 block = child;
47 break;
48 }
49 }
50 }
51 if (!block) {
52 return nullptr;
53 }
55 if (!data) {
56 return nullptr;
57 }
58 auto matrix = std::make_unique<MNESparseNamedMatrix>();
59 matrix->nrow = data->rows();
60 matrix->ncol = data->cols();
61 if (block->find_tag(stream, FIFF_MNE_NROW, tag) && *tag->toInt() != matrix->nrow) {
62 qCritical("MNESparseNamedMatrix::read - FIFF_MNE_NROW conflicts with the matrix data.");
63 return nullptr;
64 }
65 if (block->find_tag(stream, FIFF_MNE_NCOL, tag) && *tag->toInt() != matrix->ncol) {
66 qCritical("MNESparseNamedMatrix::read - FIFF_MNE_NCOL conflicts with the matrix data.");
67 return nullptr;
68 }
69 if (block->find_tag(stream, FIFF_MNE_ROW_NAMES, tag)) {
70 matrix->rowlist = FiffStream::split_name_list(tag->toString());
71 if (matrix->rowlist.size() != matrix->nrow) {
72 qCritical("MNESparseNamedMatrix::read - Incorrect number of entries in the row name list.");
73 return nullptr;
74 }
75 }
76 if (block->find_tag(stream, FIFF_MNE_COL_NAMES, tag)) {
77 matrix->collist = FiffStream::split_name_list(tag->toString());
78 if (matrix->collist.size() != matrix->ncol) {
79 qCritical("MNESparseNamedMatrix::read - Incorrect number of entries in the column name list.");
80 return nullptr;
81 }
82 }
83 matrix->data = std::move(data);
84 return matrix;
85}
86
87//=============================================================================================================
88
89void MNESparseNamedMatrix::write(FiffStream& stream, int kind) const
90{
94 if (!rowlist.isEmpty()) {
96 }
97 if (!collist.isEmpty()) {
99 }
100 stream.write_float_sparse_rcs(kind, data->eigen());
102}
Symbolic FIFF tag, block, value, unit and channel-type constants shared across FIFFLIB.
#define FIFF_MNE_ROW_NAMES
#define FIFF_MNE_COL_NAMES
#define FIFF_MNE_NCOL
#define FIFF_MNE_NROW
#define FIFFB_MNE_NAMED_MATRIX
FIFF tag: the 16-byte tag header (kind, type, size, next) plus its decoded payload.
Sparse variant of MNELIB::MNENamedMatrix, i.e. a sparse matrix with row and column name lists.
Core MNE data structures (source spaces, source estimates, hemispheres).
FIFF file I/O, in-memory data structures and high-level readers/writers.
QSharedPointer< FiffDirNode > SPtr
static FiffSparseMatrix::UPtr fiff_get_float_sparse_matrix(const FIFFLIB::FiffTag::UPtr &tag)
std::unique_ptr< FiffSparseMatrix > UPtr
FIFF tag-stream reader/writer: wraps a QIODevice and exposes typed read_* / write_* methods for every...
fiff_long_t start_block(fiff_int_t kind)
QSharedPointer< FiffStream > SPtr
fiff_long_t write_int(fiff_int_t kind, const fiff_int_t *data, fiff_int_t nel=1, fiff_int_t next=FIFFV_NEXT_SEQ)
fiff_long_t write_float_sparse_rcs(fiff_int_t kind, const Eigen::SparseMatrix< float > &mat)
fiff_long_t write_name_list(fiff_int_t kind, const QStringList &data)
static QStringList split_name_list(QString p_sNameList)
fiff_long_t end_block(fiff_int_t kind, fiff_int_t next=FIFFV_NEXT_SEQ)
std::unique_ptr< FiffTag > UPtr
Definition fiff_tag.h:165
std::unique_ptr< FIFFLIB::FiffSparseMatrix > data
void write(FIFFLIB::FiffStream &stream, int kind) const
static std::unique_ptr< MNESparseNamedMatrix > read(FIFFLIB::FiffStream::SPtr &stream, const FIFFLIB::FiffDirNode::SPtr &node, int kind)