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 
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 }
RTPROCESSINGLIB::RtInvOp::restart
void restart()
Definition: rtinvop.cpp:153
RTPROCESSINGLIB::RtInvOp::m_pFiffInfo
QSharedPointer< FIFFLIB::FiffInfo > m_pFiffInfo
Definition: rtinvop.h:180
RTPROCESSINGLIB::RtInvOpWorker::doWork
void doWork(const RtInvOpInput &inputData)
Definition: rtinvop.cpp:72
MNELIB::MNEForwardSolution::SPtr
QSharedPointer< MNEForwardSolution > SPtr
Definition: mne_forwardsolution.h:173
RTPROCESSINGLIB::RtInvOp::m_pFwd
QSharedPointer< MNELIB::MNEForwardSolution > m_pFwd
Definition: rtinvop.h:181
FIFFLIB::FiffInfo::SPtr
QSharedPointer< FiffInfo > SPtr
Definition: fiff_info.h:87
RTPROCESSINGLIB::RtInvOpWorker
Real-time inverse operator worker.
Definition: rtinvop.h:90
MNELIB::MNEForwardSolution
Forward operator.
Definition: mne_forwardsolution.h:170
RTPROCESSINGLIB::RtInvOp::m_workerThread
QThread m_workerThread
Definition: rtinvop.h:183
RTPROCESSINGLIB::RtInvOp::invOperatorCalculated
void invOperatorCalculated(const MNELIB::MNEInverseOperator &invOp)
mne_inverse_operator.h
MNEInverseOperator class declaration.
RTPROCESSINGLIB::RtInvOp::setFwdSolution
void setFwdSolution(QSharedPointer< MNELIB::MNEForwardSolution > pFwd)
Definition: rtinvop.cpp:139
fiff_info.h
FiffInfo class declaration.
FIFFLIB::FiffCov
covariance data
Definition: fiff_cov.h:77
MNELIB::MNEInverseOperator
Inverse operator.
Definition: mne_inverse_operator.h:141
RTPROCESSINGLIB::RtInvOp::operate
void operate(const RtInvOpInput &inputData)
mne_forwardsolution.h
MNEForwardSolution class declaration, which provides the forward solution including the source space ...
RTPROCESSINGLIB::RtInvOp::handleResults
void handleResults(const MNELIB::MNEInverseOperator &invOp)
Definition: rtinvop.cpp:146
rtinvop.h
RtInvOp class declaration.
RTPROCESSINGLIB::RtInvOp::stop
void stop()
Definition: rtinvop.cpp:174
RTPROCESSINGLIB::RtInvOp::RtInvOp
RtInvOp(QSharedPointer< FIFFLIB::FiffInfo > &p_pFiffInfo, QSharedPointer< MNELIB::MNEForwardSolution > &p_pFwd, QObject *parent=0)
Definition: rtinvop.cpp:94
RTPROCESSINGLIB::RtInvOp::~RtInvOp
~RtInvOp()
Definition: rtinvop.cpp:120
RTPROCESSINGLIB::RtInvOpWorker::resultReady
void resultReady(const MNELIB::MNEInverseOperator &invOp)
RTPROCESSINGLIB::RtInvOp::append
void append(const FIFFLIB::FiffCov &noiseCov)
Definition: rtinvop.cpp:127
RTPROCESSINGLIB::RtInvOpInput
Definition: rtinvop.h:78