v2.0.0
Loading...
Searching...
No Matches
mne_sss_data.cpp
Go to the documentation of this file.
1//=============================================================================================================
16
17//=============================================================================================================
18// INCLUDES
19//=============================================================================================================
20
21#include "mne_sss_data.h"
22#include <fiff/fiff_file.h>
23#include <fiff/fiff_constants.h>
24#include <fiff/fiff_stream.h>
25#include <fiff/fiff_tag.h>
26
27#include <Eigen/Core>
28
29//=============================================================================================================
30// QT INCLUDES
31//=============================================================================================================
32
33#include <QFile>
34#include <QTextStream>
35#include <QDebug>
36
37//=============================================================================================================
38// USED NAMESPACES
39//=============================================================================================================
40
41using namespace Eigen;
42using namespace MNELIB;
43using namespace FIFFLIB;
44
45//=============================================================================================================
46// DEFINE MEMBER METHODS
47//=============================================================================================================
48
52, nchan(0)
53, out_order(0)
54, in_order(0)
55, in_nuse(0)
56, out_nuse(0)
57{
58 origin[0] = 0;
59 origin[1] = 0;
60 origin[2] = 0;
61}
62
63//=============================================================================================================
64
66: job(p_MneSssData.job)
67, coord_frame(p_MneSssData.coord_frame)
68, nchan(p_MneSssData.nchan)
69, out_order(p_MneSssData.out_order)
70, in_order(p_MneSssData.in_order)
71, comp_info(p_MneSssData.comp_info)
72, in_nuse(p_MneSssData.in_nuse)
73, out_nuse(p_MneSssData.out_nuse)
74{
75 origin[0] = p_MneSssData.origin[0];
76 origin[1] = p_MneSssData.origin[1];
77 origin[2] = p_MneSssData.origin[2];
78}
79
80//=============================================================================================================
81
82MNESssData::~MNESssData() = default;
83
84//=============================================================================================================
85
86std::unique_ptr<MNESssData> MNESssData::read(const QString &name)
87{
88 QFile file(name);
89 FiffStream::SPtr stream(new FiffStream(&file));
90
91 std::unique_ptr<MNESssData> s;
92
93 if(stream->open())
94 s = read_from_node(stream,stream->dirtree());
95
96 stream->close();
97 return s;
98}
99
100//=============================================================================================================
101
102std::unique_ptr<MNESssData> MNESssData::read_from_node(QSharedPointer<FiffStream> &stream, const QSharedPointer<FiffDirNode> &start)
103{
104 auto s = std::make_unique<MNESssData>();
105 QList<FiffDirNode::SPtr> sss;
107 FiffTag::UPtr t_pTag;
108 const float *r0;
109 int j,p,q,n;
110 /*
111 * Locate the SSS information
112 */
113 sss = start->dir_tree_find(FIFFB_SSS_INFO);
114 if (sss.size() > 0) {
115 node = sss[0];
116 /*
117 * Read the SSS information, require all tags to be present
118 */
119 if (!node->find_tag(stream, FIFF_SSS_JOB, t_pTag)) {
120 return nullptr;
121 }
122 s->job = *t_pTag->toInt();
123
124 if (!node->find_tag(stream, FIFF_SSS_FRAME, t_pTag)) {
125 return nullptr;
126 }
127 s->coord_frame = *t_pTag->toInt();
128
129 if (!node->find_tag(stream, FIFF_SSS_ORIGIN, t_pTag)) {
130 return nullptr;
131 }
132 r0 = t_pTag->toFloat();
133 Eigen::Map<Eigen::Vector3f>(s->origin) = Eigen::Map<const Eigen::Vector3f>(r0);
134
135 if (!node->find_tag(stream, FIFF_SSS_ORD_IN, t_pTag)) {
136 return nullptr;
137 }
138 s->in_order = *t_pTag->toInt();
139
140 if (!node->find_tag(stream, FIFF_SSS_ORD_OUT, t_pTag)) {
141 return nullptr;
142 }
143 s->out_order = *t_pTag->toInt();
144
145 if (!node->find_tag(stream, FIFF_SSS_NMAG, t_pTag)) {
146 return nullptr;
147 }
148 s->nchan = *t_pTag->toInt();
149
150 if (!node->find_tag(stream, FIFF_SSS_COMPONENTS, t_pTag)) {
151 return nullptr;
152 }
153 {
154 int ncomp = t_pTag->size()/sizeof(fiff_int_t);
155 int *raw = t_pTag->toInt();
156 s->comp_info = Eigen::VectorXi::Map(raw, ncomp);
157
158 if (ncomp != (s->in_order*(2+s->in_order) + s->out_order*(2+s->out_order))) {
159 qCritical("Number of SSS components does not match the expansion orders listed in the file");
160 return nullptr;
161 }
162 }
163 /*
164 * Count the components in use
165 */
166 for (j = 0, n = 3, p = 0; j < s->in_order; j++, n = n + 2) {
167 for (q = 0; q < n; q++, p++)
168 if (s->comp_info[p])
169 s->in_nuse++;
170 }
171 for (j = 0, n = 3; j < s->out_order; j++, n = n + 2) {
172 for (q = 0; q < n; q++, p++)
173 s->out_nuse++;
174 }
175 }
176 /*
177 * There it is!
178 */
179 return s;
180}
181
182//=============================================================================================================
183namespace MNELIB
184{
185
188 int frame;
189 const char *name;
190};
191
192}
193
194//=============================================================================================================
195
196const char *mne_coord_frame_name_1(int frame)
197{
198 static frameNameRec_1 frames[] = {
199 {FIFFV_COORD_UNKNOWN,"unknown"},
200 {FIFFV_COORD_DEVICE,"MEG device"},
201 {FIFFV_COORD_ISOTRAK,"isotrak"},
202 {FIFFV_COORD_HPI,"hpi"},
203 {FIFFV_COORD_HEAD,"head"},
204 {FIFFV_COORD_MRI,"MRI (surface RAS)"},
205 {FIFFV_MNE_COORD_MRI_VOXEL, "MRI voxel"},
206 {FIFFV_COORD_MRI_SLICE,"MRI slice"},
207 {FIFFV_COORD_MRI_DISPLAY,"MRI display"},
208 {FIFFV_MNE_COORD_CTF_DEVICE,"CTF MEG device"},
209 {FIFFV_MNE_COORD_CTF_HEAD,"CTF/4D/KIT head"},
210 {FIFFV_MNE_COORD_RAS,"RAS (non-zero origin)"},
211 {FIFFV_MNE_COORD_MNI_TAL,"MNI Talairach"},
212 {FIFFV_MNE_COORD_FS_TAL_GTZ,"Talairach (MNI z > 0)"},
213 {FIFFV_MNE_COORD_FS_TAL_LTZ,"Talairach (MNI z < 0)"},
214 {-1,"unknown"}
215 };
216 int k;
217 for (k = 0; frames[k].frame != -1; k++) {
218 if (frame == frames[k].frame)
219 return frames[k].name;
220 }
221 return frames[k].name;
222}
223
224//=============================================================================================================
225
226void MNESssData::print(QTextStream &out) const
227{
228 int j,p,q,n;
229
230 out << "job : " << this->job << "\n";
231 out << "coord frame : " << mne_coord_frame_name_1(this->coord_frame) << "\n";
232 out << "origin : " << qSetFieldWidth(6) << qSetRealNumberPrecision(1) << Qt::fixed
233 << 1000*this->origin[0] << " " << 1000*this->origin[1] << " " << 1000*this->origin[2] << qSetFieldWidth(0) << " mm\n";
234 out << "in order : " << this->in_order << "\n";
235 out << "out order : " << this->out_order << "\n";
236 out << "nchan : " << this->nchan << "\n";
237 out << "ncomp : " << this->comp_info.size() << "\n";
238 out << "in nuse : " << this->in_nuse << "\n";
239 out << "out nuse : " << this->out_nuse << "\n";
240 out << "comps : ";
241 /*
242 * This produces the same output as maxfilter
243 */
244 for (j = 0, n = 3, p = 0; j < this->in_order; j++, n = n + 2) {
245 if (j > 0)
246 out << ";";
247 for (q = 0; q < n; q++, p++)
248 out << this->comp_info[p];
249 }
250 out << "//";
251 for (j = 0, n = 3; j < this->out_order; j++, n = n + 2) {
252 if (j > 0)
253 out << ";";
254 for (q = 0; q < n; q++, p++)
255 out << this->comp_info[p];
256 }
257 out << "\n";
258 return;
259}
const char * mne_coord_frame_name_1(int frame)
Signal Space Separation (Maxwell filter) basis metadata stored alongside MEG raw data.
Symbolic FIFF tag, block, value, unit and channel-type constants shared across FIFFLIB.
#define FIFFV_MNE_COORD_MNI_TAL
#define FIFFV_MNE_COORD_FS_TAL_LTZ
#define FIFFV_COORD_MRI_SLICE
#define FIFFV_MNE_COORD_CTF_DEVICE
#define FIFFV_COORD_DEVICE
#define FIFFV_COORD_MRI_DISPLAY
#define FIFFV_MNE_COORD_MRI_VOXEL
#define FIFFV_MNE_COORD_CTF_HEAD
#define FIFFV_COORD_HPI
#define FIFFV_COORD_HEAD
#define FIFFV_COORD_MRI
#define FIFFV_COORD_ISOTRAK
#define FIFFV_COORD_UNKNOWN
#define FIFFV_MNE_COORD_FS_TAL_GTZ
#define FIFFV_MNE_COORD_RAS
FIFF tag-kind, block-kind and type-code numerical definitions, authoritative for FIFFLIB.
#define FIFF_SSS_COMPONENTS
Definition fiff_file.h:526
#define FIFF_SSS_ORD_OUT
Definition fiff_file.h:524
#define FIFF_SSS_JOB
Definition fiff_file.h:521
#define FIFF_SSS_ORIGIN
Definition fiff_file.h:522
#define FIFFB_SSS_INFO
Definition fiff_file.h:420
#define FIFF_SSS_NMAG
Definition fiff_file.h:525
#define FIFF_SSS_FRAME
Definition fiff_file.h:520
#define FIFFV_SSS_JOB_NOTHING
Definition fiff_file.h:531
#define FIFF_SSS_ORD_IN
Definition fiff_file.h:523
FIFF tag: the 16-byte tag header (kind, type, size, next) plus its decoded payload.
FIFF binary tag-stream layer: wraps a QIODevice to read and write FIFF tags, directories,...
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
FIFF tag-stream reader/writer: wraps a QIODevice and exposes typed read_* / write_* methods for every...
QSharedPointer< FiffStream > SPtr
std::unique_ptr< FiffTag > UPtr
Definition fiff_tag.h:164
Lookup record mapping a FIFF coordinate frame integer code to its human-readable name.
Eigen::VectorXi comp_info
static std::unique_ptr< MNESssData > read_from_node(QSharedPointer< FIFFLIB::FiffStream > &stream, const QSharedPointer< FIFFLIB::FiffDirNode > &start)
void print(QTextStream &out) const
static std::unique_ptr< MNESssData > read(const QString &name)