MNE-CPP  0.1.9
A Framework for Electrophysiology
rtinvop.cpp
Go to the documentation of this file.
1 //=============================================================================================================
36 //=============================================================================================================
37 // INCLUDES
38 //=============================================================================================================
39 
40 #include "rtinvop.h"
41 
42 #include <fiff/fiff_info.h>
43 
45 #include <mne/mne_inverse_operator.h>
46 
47 //=============================================================================================================
48 // QT INCLUDES
49 //=============================================================================================================
50 
51 #include <QDebug>
52 
53 //=============================================================================================================
54 // EIGEN INCLUDES
55 //=============================================================================================================
56 
57 #include <Eigen/Core>
58 
59 //=============================================================================================================
60 // USED NAMESPACES
61 //=============================================================================================================
62 
63 using namespace RTPROCESSINGLIB;
64 using namespace Eigen;
65 using namespace MNELIB;
66 using namespace FIFFLIB;
67 
68 //=============================================================================================================
69 // DEFINE MEMBER METHODS RtInvOpWorker
70 //=============================================================================================================
71 
72 void RtInvOpWorker::doWork(const RtInvOpInput &inputData)
73 {
74  if(this->thread()->isInterruptionRequested()) {
75  return;
76  }
77 
78  // Restrict forward solution as necessary for MEG
79  MNEForwardSolution forwardMeg = inputData.pFwd->pick_types(true, false);
80 
81  MNEInverseOperator invOpMeg(*inputData.pFiffInfo.data(),
82  forwardMeg,
83  inputData.noiseCov,
84  0.2f,
85  0.8f);
86 
87  emit resultReady(invOpMeg);
88 }
89 
90 //=============================================================================================================
91 // DEFINE MEMBER METHODS RtInvOp
92 //=============================================================================================================
93 
96  QObject *parent)
97 : QObject(parent)
98 , m_pFiffInfo(p_pFiffInfo)
99 , m_pFwd(p_pFwd)
100 {
101  RtInvOpWorker *worker = new RtInvOpWorker;
102  worker->moveToThread(&m_workerThread);
103 
104  connect(&m_workerThread, &QThread::finished,
105  worker, &QObject::deleteLater);
106 
107  connect(this, &RtInvOp::operate,
108  worker, &RtInvOpWorker::doWork);
109 
110  connect(worker, &RtInvOpWorker::resultReady,
111  this, &RtInvOp::handleResults);
112 
113  m_workerThread.start();
114 
115  qRegisterMetaType<RtInvOpInput>("RtInvOpInput");
116 }
117 
118 //=============================================================================================================
119 
121 {
122  stop();
123 }
124 
125 //=============================================================================================================
126 
127 void RtInvOp::append(const FIFFLIB::FiffCov &noiseCov)
128 {
129  RtInvOpInput inputData;
130  inputData.noiseCov = noiseCov;
131  inputData.pFiffInfo = m_pFiffInfo;
132  inputData.pFwd = m_pFwd;
133 
134  emit operate(inputData);
135 }
136 
137 //=============================================================================================================
138 
139 void RtInvOp::setFwdSolution(QSharedPointer<MNELIB::MNEForwardSolution> pFwd)
140 {
141  m_pFwd = pFwd;
142 }
143 
144 //=============================================================================================================
145 
147 {
148  emit invOperatorCalculated(invOp);
149 }
150 
151 //=============================================================================================================
152 
154 {
155  stop();
156 
157  RtInvOpWorker *worker = new RtInvOpWorker;
158  worker->moveToThread(&m_workerThread);
159 
160  connect(&m_workerThread, &QThread::finished,
161  worker, &QObject::deleteLater);
162 
163  connect(this, &RtInvOp::operate,
164  worker, &RtInvOpWorker::doWork);
165 
166  connect(worker, &RtInvOpWorker::resultReady,
167  this, &RtInvOp::handleResults);
168 
169  m_workerThread.start();
170 }
171 
172 //=============================================================================================================
173 
175 {
176  m_workerThread.requestInterruption();
177  m_workerThread.quit();
178  m_workerThread.wait();
179 }
void resultReady(const MNELIB::MNEInverseOperator &invOp)
void append(const FIFFLIB::FiffCov &noiseCov)
Definition: rtinvop.cpp:127
void operate(const RtInvOpInput &inputData)
QSharedPointer< MNELIB::MNEForwardSolution > m_pFwd
Definition: rtinvop.h:181
QSharedPointer< MNEForwardSolution > SPtr
QSharedPointer< FIFFLIB::FiffInfo > m_pFiffInfo
Definition: rtinvop.h:180
Real-time inverse operator worker.
Definition: rtinvop.h:90
void setFwdSolution(QSharedPointer< MNELIB::MNEForwardSolution > pFwd)
Definition: rtinvop.cpp:139
void doWork(const RtInvOpInput &inputData)
Definition: rtinvop.cpp:72
RtInvOp(QSharedPointer< FIFFLIB::FiffInfo > &p_pFiffInfo, QSharedPointer< MNELIB::MNEForwardSolution > &p_pFwd, QObject *parent=0)
Definition: rtinvop.cpp:94
void handleResults(const MNELIB::MNEInverseOperator &invOp)
Definition: rtinvop.cpp:146
RtInvOp class declaration.
MNEForwardSolution class declaration, which provides the forward solution including the source space ...
void invOperatorCalculated(const MNELIB::MNEInverseOperator &invOp)
FiffInfo class declaration.
covariance data
Definition: fiff_cov.h:77
QSharedPointer< FiffInfo > SPtr
Definition: fiff_info.h:87