MNE-CPP  beta 1.0
main.cpp
1 //=============================================================================================================
37 //*************************************************************************************************************
38 //=============================================================================================================
39 // INCLUDES
40 //=============================================================================================================
41 
42 #include <iostream>
43 #include <vector>
44 #include <math.h>
45 
46 
47 #include <fiff/fiff.h>
48 #include <mne/mne.h>
49 
50 
51 //*************************************************************************************************************
52 //=============================================================================================================
53 // QT INCLUDES
54 //=============================================================================================================
55 
56 #include <QtCore/QCoreApplication>
57 
58 
59 //*************************************************************************************************************
60 //=============================================================================================================
61 // USED NAMESPACES
62 //=============================================================================================================
63 
64 using namespace FIFFLIB;
65 using namespace MNELIB;
66 
67 
68 //*************************************************************************************************************
69 //=============================================================================================================
70 // MAIN
71 //=============================================================================================================
72 
73 //=============================================================================================================
82 int main(int argc, char *argv[])
83 {
84  QCoreApplication a(argc, argv);
85 
86  QFile t_fileRaw("./MNE-sample-data/MEG/sample/sample_audvis_raw.fif");
87 
88  float from = 42.956f;
89  float to = 320.670f;
90 
91  bool in_samples = false;
92 
93  bool keep_comp = true;
94 
95  //
96  // Setup for reading the raw data
97  //
98  FiffRawData raw(t_fileRaw);
99 
100  //
101  // Set up pick list: MEG + STI 014 - bad channels
102  //
103  //
104  QStringList include;
105  include << "STI 014";
106  bool want_meg = true;
107  bool want_eeg = false;
108  bool want_stim = false;
109 
110  RowVectorXi picks = raw.info.pick_types(want_meg, want_eeg, want_stim, include, raw.info.bads);
111 
112  //
113  // Set up projection
114  //
115  qint32 k = 0;
116  if (raw.info.projs.size() == 0)
117  printf("No projector specified for these data\n");
118  else
119  {
120  //
121  // Activate the projection items
122  //
123  for (k = 0; k < raw.info.projs.size(); ++k)
124  raw.info.projs[k].active = true;
125 
126  printf("%d projection items activated\n",raw.info.projs.size());
127  //
128  // Create the projector
129  //
130  fiff_int_t nproj = raw.info.make_projector(raw.proj);
131 
132  if (nproj == 0)
133  printf("The projection vectors do not apply to these channels\n");
134  else
135  printf("Created an SSP operator (subspace dimension = %d)\n",nproj);
136  }
137 
138  //
139  // Set up the CTF compensator
140  //
141  qint32 current_comp = raw.info.get_current_comp();
142  qint32 dest_comp = -1;
143 
144  if (current_comp > 0)
145  printf("Current compensation grade : %d\n",current_comp);
146 
147  if (keep_comp)
148  dest_comp = current_comp;
149 
150  if (current_comp != dest_comp)
151  {
152  qDebug() << "This part needs to be debugged";
153  if(MNE::make_compensator(raw.info, current_comp, dest_comp, raw.comp))
154  {
155  raw.info.set_current_comp(dest_comp);
156  printf("Appropriate compensator added to change to grade %d.\n",dest_comp);
157  }
158  else
159  {
160  printf("Could not make the compensator\n");
161  return -1;
162  }
163  }
164  //
165  // Read a data segment
166  // times output argument is optional
167  //
168  bool readSuccessful = false;
169  MatrixXd data;
170  MatrixXd times;
171  if (in_samples)
172  readSuccessful = raw.read_raw_segment(data, times, (qint32)from, (qint32)to, picks);
173  else
174  readSuccessful = raw.read_raw_segment_times(data, times, from, to, picks);
175 
176  if (!readSuccessful)
177  {
178  printf("Could not read raw segment.\n");
179  return -1;
180  }
181 
182  printf("Read %d samples.\n",(qint32)data.cols());
183 
184 
185  std::cout << data.block(0,0,10,10) << std::endl;
186 
187 
188  return a.exec();
189 }
190 
191 //*************************************************************************************************************
192 //=============================================================================================================
193 // STATIC DEFINITIONS
194 //=============================================================================================================
FIFF raw measurement data.
Definition: fiff_raw_data.h:94
Definition: fiff.h:98
FIFF class declaration, which provides static wrapper functions to stay consistent with mne matlab to...