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 = false;//true;
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  RapMusic t_rapMusic(t_clusteredFwd, false, numDipolePairs);
154 
155  if(doMovie)
156  t_rapMusic.setStcAttr(200,0.5);
157 
158 
159  MNESourceEstimate sourceEstimate = t_rapMusic.calculateInverse(pickedEvoked);
160  if(sourceEstimate.isEmpty())
161  return 1;
162 
163 
164  QList<Label> t_qListLabels;
165  QList<RowVector4i> t_qListRGBAs;
166 
167  //ToDo overload toLabels using instead of t_surfSet rr of MNESourceSpace
168  t_annotationSet.toLabels(t_surfSet, t_qListLabels, t_qListRGBAs);
169 
170  InverseView view(t_rapMusic.getSourceSpace(), t_qListLabels, t_qListRGBAs, 24, true, false, false);//true);
171 
172 
173  if (view.stereoType() != QGLView::RedCyanAnaglyph)
174  view.camera()->setEyeSeparation(0.3f);
175  QStringList args = QCoreApplication::arguments();
176  int w_pos = args.indexOf("-width");
177  int h_pos = args.indexOf("-height");
178  if (w_pos >= 0 && h_pos >= 0)
179  {
180  bool ok = true;
181  int w = args.at(w_pos + 1).toInt(&ok);
182  if (!ok)
183  {
184  qWarning() << "Could not parse width argument:" << args;
185  return 1;
186  }
187  int h = args.at(h_pos + 1).toInt(&ok);
188  if (!ok)
189  {
190  qWarning() << "Could not parse height argument:" << args;
191  return 1;
192  }
193  view.resize(w, h);
194  }
195  else
196  {
197  view.resize(800, 600);
198  }
199  view.show();
200 
201  //Push Estimate
202  view.pushSourceEstimate(sourceEstimate);
203 
204  if(!t_sFileNameStc.isEmpty())
205  {
206  QFile t_fileClusteredStc(t_sFileNameStc);
207  sourceEstimate.write(t_fileClusteredStc);
208  }
209 
210  return a.exec();
211 }
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
Annotation set.
Definition: annotationset.h:96
bool write(QIODevice &p_IODevice)
Definition: fiff.h:98
RapMusic algorithm class declaration.
FiffEvoked pick_channels(const QStringList &include=defaultQStringList, const QStringList &exclude=defaultQStringList) const
Surface class declaration.
MNESourceEstimate class declaration.
The RapMusic class provides the RAP MUSIC Algorithm CPU implementation. ToDo: Paper references...
Definition: rapmusic.h:109
AnnotationSet class declaration.
InverseView class declaration.
Label class declaration.
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