MNE-CPP  beta 1.0
main.cpp
1 //=============================================================================================================
36 //*************************************************************************************************************
37 //=============================================================================================================
38 // INCLUDES
39 //=============================================================================================================
40 
41 #include <fs/label.h>
42 #include <fs/surface.h>
43 #include <fs/annotationset.h>
44 
45 #include <fiff/fiff_evoked.h>
46 #include <fiff/fiff.h>
47 #include <mne/mne.h>
48 
49 #include <mne/mne_sourceestimate.h>
51 
52 #include <disp3D/inverseview.h>
53 
54 #include <utils/mnemath.h>
55 
56 #include <iostream>
57 
58 
59 //*************************************************************************************************************
60 //=============================================================================================================
61 // QT INCLUDES
62 //=============================================================================================================
63 
64 #include <QGuiApplication>
65 
66 
67 //*************************************************************************************************************
68 //=============================================================================================================
69 // USED NAMESPACES
70 //=============================================================================================================
71 
72 using namespace MNELIB;
73 using namespace FSLIB;
74 using namespace FIFFLIB;
75 using namespace INVERSELIB;
76 using namespace UTILSLIB;
77 using namespace DISP3DLIB;
78 
79 
80 //*************************************************************************************************************
81 //=============================================================================================================
82 // MAIN
83 //=============================================================================================================
84 
85 //=============================================================================================================
94 int main(int argc, char *argv[])
95 {
96  QGuiApplication a(argc, argv);
97 
98  //########################################################################################
99  // Source Estimate
100 
101  QFile t_fileFwd("./MNE-sample-data/MEG/sample/sample_audvis-meg-eeg-oct-6-fwd.fif");
102  QFile t_fileEvoked("./MNE-sample-data/MEG/sample/sample_audvis-ave.fif");
103  AnnotationSet t_annotationSet("sample", 2, "aparc.a2009s", "./MNE-sample-data/subjects");
104  SurfaceSet t_surfSet("sample", 2, "white", "./MNE-sample-data/subjects");
105 
106  QString t_sFileNameStc("");//"RapMusic.stc");
107 
108  qint32 numDipolePairs = 7;
109 
110  bool doMovie = true;//false;
111 
112  // Parse command line parameters
113  for(qint32 i = 0; i < argc; ++i)
114  {
115  if(strcmp(argv[i], "-stc") == 0 || strcmp(argv[i], "--stc") == 0)
116  {
117  if(i + 1 < argc)
118  t_sFileNameStc = QString::fromUtf8(argv[i+1]);
119  }else if(strcmp(argv[i], "-num") == 0 || strcmp(argv[i], "--num") == 0)
120  {
121  if(i + 1 < argc)
122  numDipolePairs = atof(argv[i+1]);
123  }
124  }
125 
126  qDebug() << "Start calculation with stc:" << t_sFileNameStc;
127 
128  // Load data
129  fiff_int_t setno = 0;
130  QPair<QVariant, QVariant> baseline(QVariant(), 0);
131  FiffEvoked evoked(t_fileEvoked, setno, baseline);
132  if(evoked.isEmpty())
133  return 1;
134 
135  std::cout << "evoked first " << evoked.first << "; last " << evoked.last << std::endl;
136 
137  MNEForwardSolution t_Fwd(t_fileFwd);
138  if(t_Fwd.isEmpty())
139  return 1;
140 
141  QStringList ch_sel_names = t_Fwd.info.ch_names;
142  FiffEvoked pickedEvoked = evoked.pick_channels(ch_sel_names);
143 
144  //
145  // Cluster forward solution;
146  //
147  MNEForwardSolution t_clusteredFwd = t_Fwd.cluster_forward_solution(t_annotationSet, 20);//40);
148 
149 // std::cout << "Size " << t_clusteredFwd.sol->data.rows() << " x " << t_clusteredFwd.sol->data.cols() << std::endl;
150 // std::cout << "Clustered Fwd:\n" << t_clusteredFwd.sol->data.row(0) << std::endl;
151 
152 
153  PwlRapMusic t_pwlRapMusic(t_clusteredFwd, false, numDipolePairs);
154 
155  if(doMovie)
156  t_pwlRapMusic.setStcAttr(200,0.5);
157 
158 
159  MNESourceEstimate sourceEstimate = t_pwlRapMusic.calculateInverse(pickedEvoked);
160 
161  std::cout << "source estimated" << std::endl;
162 
163  if(sourceEstimate.isEmpty())
164  return 1;
165 
166  QList<Label> t_qListLabels;
167  QList<RowVector4i> t_qListRGBAs;
168 
169  //ToDo overload toLabels using instead of t_surfSet rr of MNESourceSpace
170  t_annotationSet.toLabels(t_surfSet, t_qListLabels, t_qListRGBAs);
171 
172  InverseView view(t_pwlRapMusic.getSourceSpace(), t_qListLabels, t_qListRGBAs, 24, true, false, false);//true);
173 
174 
175  if (view.stereoType() != QGLView::RedCyanAnaglyph)
176  view.camera()->setEyeSeparation(0.3f);
177  QStringList args = QCoreApplication::arguments();
178  int w_pos = args.indexOf("-width");
179  int h_pos = args.indexOf("-height");
180  if (w_pos >= 0 && h_pos >= 0)
181  {
182  bool ok = true;
183  int w = args.at(w_pos + 1).toInt(&ok);
184  if (!ok)
185  {
186  qWarning() << "Could not parse width argument:" << args;
187  return 1;
188  }
189  int h = args.at(h_pos + 1).toInt(&ok);
190  if (!ok)
191  {
192  qWarning() << "Could not parse height argument:" << args;
193  return 1;
194  }
195  view.resize(w, h);
196  }
197  else
198  {
199  view.resize(800, 600);
200  }
201  view.show();
202 
203  //Push Estimate
204  view.pushSourceEstimate(sourceEstimate);
205 
206  if(!t_sFileNameStc.isEmpty())
207  {
208  QFile t_fileClusteredStc(t_sFileNameStc);
209  sourceEstimate.write(t_fileClusteredStc);
210  }
211 
212  return a.exec();
213 }
MNEForwardSolution cluster_forward_solution(const AnnotationSet &p_AnnotationSet, qint32 p_iClusterSize, MatrixXd &p_D=defaultD, const FiffCov &p_pNoise_cov=defaultCov, const FiffInfo &p_pInfo=defaultInfo, QString p_sMethod="cityblock") const
3D stereoscopic labels
Definition: inverseview.h:118
evoked data
Definition: fiff_evoked.h:91
PwlRapMusic algorithm class declaration.
Annotation set.
Definition: annotationset.h:96
bool write(QIODevice &p_IODevice)
Definition: fiff.h:98
FiffEvoked pick_channels(const QStringList &include=defaultQStringList, const QStringList &exclude=defaultQStringList) const
Surface class declaration.
MNESourceEstimate class declaration.
AnnotationSet class declaration.
InverseView class declaration.
Label class declaration.
The PwlRapMusic class provides the POWELL RAP MUSIC Algorithm CPU implementation. ToDo: Paper referen...
Definition: pwlrapmusic.h:96
MNEMath class declaration.
FIFF class declaration, which provides static wrapper functions to stay consistent with mne matlab to...
A hemisphere set of surfaces.
Definition: surfaceset.h:83