v2.0.0
Loading...
Searching...
No Matches
mne_sss_data.cpp
Go to the documentation of this file.
1//=============================================================================================================
36
37//=============================================================================================================
38// INCLUDES
39//=============================================================================================================
40
41#include "mne_sss_data.h"
42#include <fiff/fiff_file.h>
43#include <fiff/fiff_constants.h>
44#include <fiff/fiff_stream.h>
45#include <fiff/fiff_tag.h>
46
47//============================= dot.h =============================
48
49#define X 0
50#define Y 1
51#define Z 2
52
53#define VEC_COPY(to,from) {\
54 (to)[X] = (from)[X];\
55 (to)[Y] = (from)[Y];\
56 (to)[Z] = (from)[Z];\
57 }
58
59//=============================================================================================================
60// QT INCLUDES
61//=============================================================================================================
62
63#include <QFile>
64#include <QTextStream>
65
66//=============================================================================================================
67// USED NAMESPACES
68//=============================================================================================================
69
70using namespace Eigen;
71using namespace MNELIB;
72using namespace FIFFLIB;
73
74//=============================================================================================================
75// DEFINE MEMBER METHODS
76//=============================================================================================================
77
81, nchan(0)
82, out_order(0)
83, in_order(0)
84, in_nuse(0)
85, out_nuse(0)
86{
87 origin[0] = 0;
88 origin[1] = 0;
89 origin[2] = 0;
90}
91
92//=============================================================================================================
93
95: job(p_MneSssData.job)
96, coord_frame(p_MneSssData.coord_frame)
97, nchan(p_MneSssData.nchan)
98, out_order(p_MneSssData.out_order)
99, in_order(p_MneSssData.in_order)
100, comp_info(p_MneSssData.comp_info)
101, in_nuse(p_MneSssData.in_nuse)
102, out_nuse(p_MneSssData.out_nuse)
103{
104 origin[0] = p_MneSssData.origin[0];
105 origin[1] = p_MneSssData.origin[1];
106 origin[2] = p_MneSssData.origin[2];
107}
108
109//=============================================================================================================
110
111MNESssData::~MNESssData() = default;
112
113//=============================================================================================================
114
115MNESssData *MNESssData::read(const QString &name)
116{
117 QFile file(name);
118 FiffStream::SPtr stream(new FiffStream(&file));
119
120 MNESssData* s = NULL;
121
122 if(stream->open())
123 s = read_from_node(stream,stream->dirtree());
124
125 stream->close();
126 return s;
127}
128
129//=============================================================================================================
130
131MNESssData *MNESssData::read_from_node(QSharedPointer<FiffStream> &stream, const QSharedPointer<FiffDirNode> &start)
132{
133 MNESssData* s = new MNESssData();
134 QList<FiffDirNode::SPtr> sss;
136 FiffTag::SPtr t_pTag;
137 float *r0;
138 int j,p,q,n;
139 /*
140 * Locate the SSS information
141 */
142 sss = start->dir_tree_find(FIFFB_SSS_INFO);
143 if (sss.size() > 0) {
144 node = sss[0];
145 /*
146 * Read the SSS information, require all tags to be present
147 */
148 if (!node->find_tag(stream, FIFF_SSS_JOB, t_pTag))
149 goto bad;
150 s->job = *t_pTag->toInt();
151
152 if (!node->find_tag(stream, FIFF_SSS_FRAME, t_pTag))
153 goto bad;
154 s->coord_frame = *t_pTag->toInt();
155
156 if (!node->find_tag(stream, FIFF_SSS_ORIGIN, t_pTag))
157 goto bad;
158 r0 = t_pTag->toFloat();
159 VEC_COPY(s->origin,r0);
160
161 if (!node->find_tag(stream, FIFF_SSS_ORD_IN, t_pTag))
162 goto bad;
163 s->in_order = *t_pTag->toInt();
164
165 if (!node->find_tag(stream, FIFF_SSS_ORD_OUT, t_pTag))
166 goto bad;
167 s->out_order = *t_pTag->toInt();
168
169 if (!node->find_tag(stream, FIFF_SSS_NMAG, t_pTag))
170 goto bad;
171 s->nchan = *t_pTag->toInt();
172
173 if (!node->find_tag(stream, FIFF_SSS_COMPONENTS, t_pTag))
174 goto bad;
175 {
176 int ncomp = t_pTag->size()/sizeof(fiff_int_t);
177 int *raw = t_pTag->toInt();
178 s->comp_info = Eigen::VectorXi::Map(raw, ncomp);
179
180 if (ncomp != (s->in_order*(2+s->in_order) + s->out_order*(2+s->out_order))) {
181 printf("Number of SSS components does not match the expansion orders listed in the file");
182 goto bad;
183 }
184 }
185 /*
186 * Count the components in use
187 */
188 for (j = 0, n = 3, p = 0; j < s->in_order; j++, n = n + 2) {
189 for (q = 0; q < n; q++, p++)
190 if (s->comp_info[p])
191 s->in_nuse++;
192 }
193 for (j = 0, n = 3; j < s->out_order; j++, n = n + 2) {
194 for (q = 0; q < n; q++, p++)
195 s->out_nuse++;
196 }
197 }
198 /*
199 * There it is!
200 */
201 return s;
202
203bad : {
204 /*
205 * Not entirely happy
206 */
207 if (s)
208 delete s;
209 return NULL;
210 }
211}
212
213//=============================================================================================================
214namespace MNELIB
215{
216
218typedef struct {
219 int frame;
220 const char *name;
222
223}
224
225//=============================================================================================================
226
227const char *mne_coord_frame_name_1(int frame)
228{
229 static frameNameRec_1 frames[] = {
230 {FIFFV_COORD_UNKNOWN,"unknown"},
231 {FIFFV_COORD_DEVICE,"MEG device"},
232 {FIFFV_COORD_ISOTRAK,"isotrak"},
233 {FIFFV_COORD_HPI,"hpi"},
234 {FIFFV_COORD_HEAD,"head"},
235 {FIFFV_COORD_MRI,"MRI (surface RAS)"},
236 {FIFFV_MNE_COORD_MRI_VOXEL, "MRI voxel"},
237 {FIFFV_COORD_MRI_SLICE,"MRI slice"},
238 {FIFFV_COORD_MRI_DISPLAY,"MRI display"},
239 {FIFFV_MNE_COORD_CTF_DEVICE,"CTF MEG device"},
240 {FIFFV_MNE_COORD_CTF_HEAD,"CTF/4D/KIT head"},
241 {FIFFV_MNE_COORD_RAS,"RAS (non-zero origin)"},
242 {FIFFV_MNE_COORD_MNI_TAL,"MNI Talairach"},
243 {FIFFV_MNE_COORD_FS_TAL_GTZ,"Talairach (MNI z > 0)"},
244 {FIFFV_MNE_COORD_FS_TAL_LTZ,"Talairach (MNI z < 0)"},
245 {-1,"unknown"}
246 };
247 int k;
248 for (k = 0; frames[k].frame != -1; k++) {
249 if (frame == frames[k].frame)
250 return frames[k].name;
251 }
252 return frames[k].name;
253}
254
255//=============================================================================================================
256
257void MNESssData::print(QTextStream &out) const
258{
259 int j,p,q,n;
260
261 out << "job : " << this->job << "\n";
262 out << "coord frame : " << mne_coord_frame_name_1(this->coord_frame) << "\n";
263 out << "origin : " << qSetFieldWidth(6) << qSetRealNumberPrecision(1) << Qt::fixed
264 << 1000*this->origin[0] << " " << 1000*this->origin[1] << " " << 1000*this->origin[2] << qSetFieldWidth(0) << " mm\n";
265 out << "in order : " << this->in_order << "\n";
266 out << "out order : " << this->out_order << "\n";
267 out << "nchan : " << this->nchan << "\n";
268 out << "ncomp : " << this->comp_info.size() << "\n";
269 out << "in nuse : " << this->in_nuse << "\n";
270 out << "out nuse : " << this->out_nuse << "\n";
271 out << "comps : ";
272 /*
273 * This produces the same output as maxfilter
274 */
275 for (j = 0, n = 3, p = 0; j < this->in_order; j++, n = n + 2) {
276 if (j > 0)
277 out << ";";
278 for (q = 0; q < n; q++, p++)
279 out << this->comp_info[p];
280 }
281 out << "//";
282 for (j = 0, n = 3; j < this->out_order; j++, n = n + 2) {
283 if (j > 0)
284 out << ";";
285 for (q = 0; q < n; q++, p++)
286 out << this->comp_info[p];
287 }
288 out << "\n";
289 return;
290}
FiffTag class declaration, which provides fiff tag I/O and processing methods.
Fiff constants.
#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
FiffStream class declaration.
Header file describing the numerical values used in fif files.
#define FIFF_SSS_COMPONENTS
Definition fiff_file.h:533
#define FIFF_SSS_ORD_OUT
Definition fiff_file.h:531
#define FIFF_SSS_JOB
Definition fiff_file.h:528
#define FIFF_SSS_ORIGIN
Definition fiff_file.h:529
#define FIFFB_SSS_INFO
Definition fiff_file.h:427
#define FIFF_SSS_NMAG
Definition fiff_file.h:532
#define FIFF_SSS_FRAME
Definition fiff_file.h:527
#define FIFFV_SSS_JOB_NOTHING
Definition fiff_file.h:538
#define FIFF_SSS_ORD_IN
Definition fiff_file.h:530
#define VEC_COPY(to, from)
const char * mne_coord_frame_name_1(int frame)
MNE SSS Data (MNESssData) class declaration.
Core MNE data structures (source spaces, source estimates, hemispheres).
FIFF file I/O and data structures (raw, epochs, evoked, covariance, forward).
qint32 fiff_int_t
Definition fiff_types.h:89
QSharedPointer< FiffDirNode > SPtr
FIFF File I/O routines.
QSharedPointer< FiffStream > SPtr
QSharedPointer< FiffTag > SPtr
Definition fiff_tag.h:155
Lookup record mapping a FIFF coordinate frame integer code to its human-readable name.
Eigen::VectorXi comp_info
static MNESssData * read(const QString &name)
void print(QTextStream &out) const
static MNESssData * read_from_node(QSharedPointer< FIFFLIB::FiffStream > &stream, const QSharedPointer< FIFFLIB::FiffDirNode > &start)