v2.0.0
Loading...
Searching...
No Matches
compute_fwd_settings.cpp
Go to the documentation of this file.
1
2
4
5#include <stdio.h>
6
7using namespace Eigen;
8using namespace FIFFLIB;
9using namespace FWDLIB;
10
11#define X 0
12#define Y 1
13#define Z 2
14
15#ifndef PROGRAM_VERSION
16#define PROGRAM_VERSION "2.10"
17#endif
18
19//=============================================================================================================
20// STATIC DEFINITIONS
21//=============================================================================================================
22
23//=============================================================================================================
24// DEFINE MEMBER METHODS
25//=============================================================================================================
26
28{
29 initMembers();
30}
31
32//=============================================================================================================
33
35{
36 initMembers();
37
38 if (!check_args(argc,argv))
39 return;
40
41// mne_print_version_info(stderr,argv[0],PROGRAM_VERSION,__DATE__,__TIME__);
42 printf("%s version %s compiled at %s %s\n",argv[0],PROGRAM_VERSION,__DATE__,__TIME__);
43
45}
46
47//=============================================================================================================
48
50{
51 //ToDo Garbage collection
52}
53
54//=============================================================================================================
55
57{
58 if (srcname.isEmpty()) {
59 qCritical("Source space name is missing. Use the --src option to specify it.");
60 return;
61 }
62 if (!mri_head_ident) {
63 if (mriname.isEmpty() && transname.isEmpty()) {
64 qCritical("MRI <-> head coordinate transformation is missing. Use the --mri or --trans option to specify it.");
65 return;
66 }
67 }
68 if (measname.isEmpty()) {
69 qCritical("Source of coil and electrode locations is missing. Use the --meas option to specify it.");
70 return;
71 }
72 if (solname.isEmpty()) {
73 qCritical("Solution name is missing. Use the --fwd option to specify it.");
74 return;
75 }
76 if (! (include_meg || include_eeg)) {
77 qCritical("Employ the --meg and --eeg options to select MEG and/or EEG");
78 return;
79 }
80}
81
82//=============================================================================================================
83
84void ComputeFwdSettings::initMembers()
85{
86 // Init origin
87 r0 << 0.0f,0.0f,0.04f;
88
89 filter_spaces = true;
90 accurate = false;
91 fixed_ori = false;
92 include_meg = false;
93 include_eeg = false;
94 compute_grad = false;
95 mindist = 0.0f;
97 do_all = false;
98 nlabel = 0;
99
100 eeg_sphere_rad = 0.09f;
101 scale_eeg_pos = false;
102 use_equiv_eeg = true;
103 use_threads = true;
104
105 pFiffInfo = Q_NULLPTR;
107}
108
109//=============================================================================================================
110
111void ComputeFwdSettings::usage(char *name)
112{
113 printf("usage : %s [options]\n",name);
114 printf("\t--meg to compute the MEG forward solution\n");
115 printf("\t--eeg to compute the EEG forward solution\n");
116 printf("\t--grad compute the gradient of the field with respect to the dipole coordinates as well\n");
117 printf("\t--fixed to calculate only for the source orientation given by the surface normals\n");
118 printf("\t--mricoord do calculations in MRI coordinates instead of head coordinates\n");
119 printf("\t--accurate use more accurate coil definitions in MEG forward computation\n");
120 printf("\t--src name specify the source space\n");
121 printf("\t--label name label file to select the sources (can have multiple of these)\n");
122 printf("\t--mri name take head/MRI coordinate transform from here (Neuromag MRI description file)\n");
123 printf("\t--trans name take head/MRI coordinate transform from here (text file)\n");
124 printf("\t--notrans head and MRI coordinate systems are identical.\n");
125 printf("\t--meas name take MEG sensor and EEG electrode locations from here\n");
126 printf("\t--bem name BEM model name\n");
127 printf("\t--origin x:y:z/mm use a sphere model with this origin (head coordinates/mm)\n");
128 printf("\t--eegscalp scale the electrode locations to the surface of the scalp when using a sphere model\n");
129 printf("\t--eegmodels name read EEG sphere model specifications from here.\n");
130 printf("\t--eegmodel name name of the EEG sphere model to use (default : Default)\n");
131 printf("\t--eegrad rad/mm radius of the scalp surface to use in EEG sphere model (default : %7.1f mm)\n",1000*eeg_sphere_rad);
132 printf("\t--mindist dist/mm minimum allowable distance of the sources from the inner skull surface.\n");
133 printf("\t--mindistout name Output the omitted source space points here.\n");
134 printf("\t--includeall Omit all source space checks\n");
135 printf("\t--all calculate forward solution in all nodes instead the selected ones only.\n");
136 printf("\t--fwd name save the solution here\n");
137 printf("\t--help print this info.\n");
138 printf("\t--version print version info.\n\n");
139 exit(1);
140}
141
142//=============================================================================================================
143
144QString ComputeFwdSettings::build_command_line(QString old, QString new_item)
145{
146 if (!new_item.isEmpty() && new_item.size() > 0) {
147 if (!old.isEmpty()) {
148 old += " ";
149 }
150 old += new_item;
151 }
152 return old;
153}
154
155//=============================================================================================================
156
157bool ComputeFwdSettings::check_unrecognized_args(int argc, char **argv)
158{
159 int k;
160
161 if (argc > 1) {
162 printf("Unrecognized arguments : ");
163 for (k = 1; k < argc; k++)
164 printf("%s ",argv[k]);
165 printf("\n");
166 qCritical("Check the command line.");
167 return false;
168 }
169 return true;
170}
171
172//=============================================================================================================
173
174bool ComputeFwdSettings::check_args (int *argc,char **argv)
175{
176 int found;
177 char *last;
178
179 if ((last = strrchr(argv[0],'/')) == NULL)
180 last = argv[0];
181 else
182 last++;
183 command = build_command_line(command,last);
184 for (int k = 0; k < *argc; k++) {
185 found = 0;
186 if (strcmp(argv[k],"--version") == 0) {
187 printf("%s version %s compiled at %s %s\n", argv[0],PROGRAM_VERSION,__DATE__,__TIME__);
188 exit(0);
189 }
190 else if (strcmp(argv[k],"--help") == 0) {
191 usage(argv[0]);
192 exit(1);
193 }
194 else if (strcmp(argv[k],"--meg") == 0) {
195 found = 1;
196 include_meg = true;
197 }
198 else if (strcmp(argv[k],"--eeg") == 0) {
199 found = 1;
200 include_eeg = true;
201 }
202 else if (strcmp(argv[k],"--grad") == 0) {
203 found = 1;
204 compute_grad = true;
205 }
206 else if (strcmp(argv[k],"--all") == 0) {
207 found = 1;
208 do_all = true;
209 }
210 else if (strcmp(argv[k],"--accurate") == 0) {
211 found = 1;
212 accurate = true;
213 }
214 else if (strcmp(argv[k],"--fixed") == 0) {
215 found = 1;
216 fixed_ori = true;
217 }
218 else if (strcmp(argv[k],"--src") == 0) {
219 found = 2;
220 if (k == *argc - 1) {
221 qCritical("--src: argument required.");
222 return false;
223 }
224 srcname = QString(argv[k+1]);
225 }
226 else if (strcmp(argv[k],"--mri") == 0) {
227 found = 2;
228 if (k == *argc - 1) {
229 qCritical("--mri: argument required.");
230 return false;
231 }
232 mri_head_ident = false;
233 mriname = QString(argv[k+1]);
234 transname.clear();
235 }
236 else if (strcmp(argv[k],"--trans") == 0) {
237 found = 2;
238 if (k == *argc - 1) {
239 qCritical("--trans: argument required.");
240 return false;
241 }
242 mri_head_ident = false;
243 transname = QString(argv[k+1]);
244 mriname.clear();
245 }
246 else if (strcmp(argv[k],"--notrans") == 0) {
247 found = 1;
248 mri_head_ident = true;
249 mriname.clear();
250 transname.clear();
251 }
252 else if (strcmp(argv[k],"--meas") == 0) {
253 found = 2;
254 if (k == *argc - 1) {
255 qCritical("--meas: argument required.");
256 return false;
257 }
258 measname = QString(argv[k+1]);
259 }
260 else if (strcmp(argv[k],"--bem") == 0) {
261 found = 2;
262 if (k == *argc - 1) {
263 qCritical("--bem: argument required.");
264 return false;
265 }
266 bemname = QString(argv[k+1]);
267 }
268 else if (strcmp(argv[k],"--origin") == 0) {
269 found = 2;
270 if (k == *argc - 1) {
271 qCritical("--origin: argument required.");
272 return false;
273 }
274 if (sscanf(argv[k+1],"%f:%f:%f",r0[X],r0[Y],r0[Z]) != 3) {
275 qCritical("Could not interpret the origin.");
276 return false;
277 }
278 r0[X] = r0[X]/1000.0f;
279 r0[Y] = r0[Y]/1000.0f;
280 r0[Z] = r0[Z]/1000.0f;
281 }
282 else if (strcmp(argv[k],"--eegrad") == 0) {
283 found = 2;
284 if (k == *argc - 1) {
285 qCritical("--eegrad: argument required.");
286 return false;
287 }
288 if (sscanf(argv[k+1],"%g",&eeg_sphere_rad) != 1) {
289 qCritical("Incomprehensible radius : %s",argv[k+1]);
290 return false;
291 }
292 if (eeg_sphere_rad <= 0) {
293 qCritical("Radius must be positive");
294 return false;
295 }
297 }
298 else if (strcmp(argv[k],"--eegmodels") == 0) {
299 found = 2;
300 if (k == *argc - 1) {
301 qCritical("--eegmodels: argument required.");
302 return false;
303 }
304 eeg_model_file = QString(argv[k+1]);
305 }
306 else if (strcmp(argv[k],"--eegmodel") == 0) {
307 found = 2;
308 if (k == *argc - 1) {
309 qCritical("--eegmodel: argument required.");
310 return false;
311 }
312 eeg_model_name = QString(argv[k+1]);
313 }
314 else if (strcmp(argv[k],"--eegscalp") == 0) {
315 found = 1;
316 scale_eeg_pos = true;
317 }
318 else if (strcmp(argv[k],"--mindist") == 0) {
319 found = 2;
320 if (k == *argc - 1) {
321 qCritical("--mindist: argument required.");
322 return false;
323 }
324 if (sscanf(argv[k+1],"%f",&mindist) != 1) {
325 qCritical("Could not interpret the distance.");
326 return false;
327 }
328 if (mindist <= 0.0)
329 mindist = 0.0f;
330 mindist = mindist/1000.0f;
331 }
332 else if (strcmp(argv[k],"--includeall") == 0) {
333 found = 1;
334 filter_spaces = false;
335 }
336 else if (strcmp(argv[k],"--mindistout") == 0) {
337 found = 2;
338 if (k == *argc - 1) {
339 qCritical("--mindistout: argument required.");
340 return false;
341 }
342 mindistoutname = QString(argv[k+1]);
343 }
344 else if (strcmp(argv[k],"--mricoord") == 0) {
345 found = 1;
347 }
348 else if (strcmp(argv[k],"--fwd") == 0) {
349 found = 2;
350 if (k == *argc - 1) {
351 qCritical("--fwd: argument required.");
352 return false;
353 }
354 solname = QString(argv[k+1]);
355 }
356 else if (strcmp(argv[k],"--label") == 0) {
357 found = 2;
358 if (k == *argc - 1) {
359 qCritical("--label: argument required.");
360 return false;
361 }
362 labels.append(QString(argv[k+1]));
363 nlabel++;
364 }
365 if (found) {
366 for (int p = k; p < k + found; p++)
367 command = build_command_line(command,argv[p]);
368 for (int p = k; p < *argc-found; p++)
369 argv[p] = argv[p+found];
370 *argc = *argc - found;
371 k = k - found;
372 }
373 }
374 return check_unrecognized_args(*argc,argv);
375}
#define FIFFV_COORD_HEAD
#define FIFFV_COORD_MRI
#define X
#define PROGRAM_VERSION
#define Z
#define Y
Compute Forward Setting class declaration.
FIFF file I/O and data structures (raw, epochs, evoked, covariance, forward).
Forward modelling (BEM, MEG/EEG lead fields).
Definition compute_fwd.h:95
const QString name
Coordinate transformation description.
FIFFLIB::FiffCoordTrans meg_head_t
QSharedPointer< FIFFLIB::FiffInfo > pFiffInfo