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#include <Eigen/Core>
48
49//=============================================================================================================
50// QT INCLUDES
51//=============================================================================================================
52
53#include <QFile>
54#include <QTextStream>
55#include <QDebug>
56
57//=============================================================================================================
58// USED NAMESPACES
59//=============================================================================================================
60
61using namespace Eigen;
62using namespace MNELIB;
63using namespace FIFFLIB;
64
65//=============================================================================================================
66// DEFINE MEMBER METHODS
67//=============================================================================================================
68
72, nchan(0)
73, out_order(0)
74, in_order(0)
75, in_nuse(0)
76, out_nuse(0)
77{
78 origin[0] = 0;
79 origin[1] = 0;
80 origin[2] = 0;
81}
82
83//=============================================================================================================
84
86: job(p_MneSssData.job)
87, coord_frame(p_MneSssData.coord_frame)
88, nchan(p_MneSssData.nchan)
89, out_order(p_MneSssData.out_order)
90, in_order(p_MneSssData.in_order)
91, comp_info(p_MneSssData.comp_info)
92, in_nuse(p_MneSssData.in_nuse)
93, out_nuse(p_MneSssData.out_nuse)
94{
95 origin[0] = p_MneSssData.origin[0];
96 origin[1] = p_MneSssData.origin[1];
97 origin[2] = p_MneSssData.origin[2];
98}
99
100//=============================================================================================================
101
102MNESssData::~MNESssData() = default;
103
104//=============================================================================================================
105
106std::unique_ptr<MNESssData> MNESssData::read(const QString &name)
107{
108 QFile file(name);
109 FiffStream::SPtr stream(new FiffStream(&file));
110
111 std::unique_ptr<MNESssData> s;
112
113 if(stream->open())
114 s = read_from_node(stream,stream->dirtree());
115
116 stream->close();
117 return s;
118}
119
120//=============================================================================================================
121
122std::unique_ptr<MNESssData> MNESssData::read_from_node(QSharedPointer<FiffStream> &stream, const QSharedPointer<FiffDirNode> &start)
123{
124 auto s = std::make_unique<MNESssData>();
125 QList<FiffDirNode::SPtr> sss;
127 FiffTag::UPtr t_pTag;
128 const float *r0;
129 int j,p,q,n;
130 /*
131 * Locate the SSS information
132 */
133 sss = start->dir_tree_find(FIFFB_SSS_INFO);
134 if (sss.size() > 0) {
135 node = sss[0];
136 /*
137 * Read the SSS information, require all tags to be present
138 */
139 if (!node->find_tag(stream, FIFF_SSS_JOB, t_pTag)) {
140 return nullptr;
141 }
142 s->job = *t_pTag->toInt();
143
144 if (!node->find_tag(stream, FIFF_SSS_FRAME, t_pTag)) {
145 return nullptr;
146 }
147 s->coord_frame = *t_pTag->toInt();
148
149 if (!node->find_tag(stream, FIFF_SSS_ORIGIN, t_pTag)) {
150 return nullptr;
151 }
152 r0 = t_pTag->toFloat();
153 Eigen::Map<Eigen::Vector3f>(s->origin) = Eigen::Map<const Eigen::Vector3f>(r0);
154
155 if (!node->find_tag(stream, FIFF_SSS_ORD_IN, t_pTag)) {
156 return nullptr;
157 }
158 s->in_order = *t_pTag->toInt();
159
160 if (!node->find_tag(stream, FIFF_SSS_ORD_OUT, t_pTag)) {
161 return nullptr;
162 }
163 s->out_order = *t_pTag->toInt();
164
165 if (!node->find_tag(stream, FIFF_SSS_NMAG, t_pTag)) {
166 return nullptr;
167 }
168 s->nchan = *t_pTag->toInt();
169
170 if (!node->find_tag(stream, FIFF_SSS_COMPONENTS, t_pTag)) {
171 return nullptr;
172 }
173 {
174 int ncomp = t_pTag->size()/sizeof(fiff_int_t);
175 int *raw = t_pTag->toInt();
176 s->comp_info = Eigen::VectorXi::Map(raw, ncomp);
177
178 if (ncomp != (s->in_order*(2+s->in_order) + s->out_order*(2+s->out_order))) {
179 qCritical("Number of SSS components does not match the expansion orders listed in the file");
180 return nullptr;
181 }
182 }
183 /*
184 * Count the components in use
185 */
186 for (j = 0, n = 3, p = 0; j < s->in_order; j++, n = n + 2) {
187 for (q = 0; q < n; q++, p++)
188 if (s->comp_info[p])
189 s->in_nuse++;
190 }
191 for (j = 0, n = 3; j < s->out_order; j++, n = n + 2) {
192 for (q = 0; q < n; q++, p++)
193 s->out_nuse++;
194 }
195 }
196 /*
197 * There it is!
198 */
199 return s;
200}
201
202//=============================================================================================================
203namespace MNELIB
204{
205
208 int frame;
209 const char *name;
210};
211
212}
213
214//=============================================================================================================
215
216const char *mne_coord_frame_name_1(int frame)
217{
218 static frameNameRec_1 frames[] = {
219 {FIFFV_COORD_UNKNOWN,"unknown"},
220 {FIFFV_COORD_DEVICE,"MEG device"},
221 {FIFFV_COORD_ISOTRAK,"isotrak"},
222 {FIFFV_COORD_HPI,"hpi"},
223 {FIFFV_COORD_HEAD,"head"},
224 {FIFFV_COORD_MRI,"MRI (surface RAS)"},
225 {FIFFV_MNE_COORD_MRI_VOXEL, "MRI voxel"},
226 {FIFFV_COORD_MRI_SLICE,"MRI slice"},
227 {FIFFV_COORD_MRI_DISPLAY,"MRI display"},
228 {FIFFV_MNE_COORD_CTF_DEVICE,"CTF MEG device"},
229 {FIFFV_MNE_COORD_CTF_HEAD,"CTF/4D/KIT head"},
230 {FIFFV_MNE_COORD_RAS,"RAS (non-zero origin)"},
231 {FIFFV_MNE_COORD_MNI_TAL,"MNI Talairach"},
232 {FIFFV_MNE_COORD_FS_TAL_GTZ,"Talairach (MNI z > 0)"},
233 {FIFFV_MNE_COORD_FS_TAL_LTZ,"Talairach (MNI z < 0)"},
234 {-1,"unknown"}
235 };
236 int k;
237 for (k = 0; frames[k].frame != -1; k++) {
238 if (frame == frames[k].frame)
239 return frames[k].name;
240 }
241 return frames[k].name;
242}
243
244//=============================================================================================================
245
246void MNESssData::print(QTextStream &out) const
247{
248 int j,p,q,n;
249
250 out << "job : " << this->job << "\n";
251 out << "coord frame : " << mne_coord_frame_name_1(this->coord_frame) << "\n";
252 out << "origin : " << qSetFieldWidth(6) << qSetRealNumberPrecision(1) << Qt::fixed
253 << 1000*this->origin[0] << " " << 1000*this->origin[1] << " " << 1000*this->origin[2] << qSetFieldWidth(0) << " mm\n";
254 out << "in order : " << this->in_order << "\n";
255 out << "out order : " << this->out_order << "\n";
256 out << "nchan : " << this->nchan << "\n";
257 out << "ncomp : " << this->comp_info.size() << "\n";
258 out << "in nuse : " << this->in_nuse << "\n";
259 out << "out nuse : " << this->out_nuse << "\n";
260 out << "comps : ";
261 /*
262 * This produces the same output as maxfilter
263 */
264 for (j = 0, n = 3, p = 0; j < this->in_order; j++, n = n + 2) {
265 if (j > 0)
266 out << ";";
267 for (q = 0; q < n; q++, p++)
268 out << this->comp_info[p];
269 }
270 out << "//";
271 for (j = 0, n = 3; j < this->out_order; j++, n = n + 2) {
272 if (j > 0)
273 out << ";";
274 for (q = 0; q < n; q++, p++)
275 out << this->comp_info[p];
276 }
277 out << "\n";
278 return;
279}
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
FiffStream class declaration.
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
MNE SSS Data (MNESssData) class declaration.
const char * mne_coord_frame_name_1(int frame)
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
std::unique_ptr< FiffTag > UPtr
Definition fiff_tag.h:158
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)