MNE-CPP  0.1.9
A Framework for Electrophysiology
rtconnectivity.cpp
Go to the documentation of this file.
1 //=============================================================================================================
35 //=============================================================================================================
36 // INCLUDES
37 //=============================================================================================================
38 
39 #include "rtconnectivity.h"
40 
43 
44 //=============================================================================================================
45 // EIGEN INCLUDES
46 //=============================================================================================================
47 
48 //=============================================================================================================
49 // QT INCLUDES
50 //=============================================================================================================
51 
52 #include <QElapsedTimer>
53 #include <QDebug>
54 
55 //=============================================================================================================
56 // USED NAMESPACES
57 //=============================================================================================================
58 
59 using namespace RTPROCESSINGLIB;
60 using namespace CONNECTIVITYLIB;
61 
62 //=============================================================================================================
63 // DEFINE MEMBER METHODS RtConnectivityWorker
64 //=============================================================================================================
65 
66 void RtConnectivityWorker::doWork(const ConnectivitySettings &connectivitySettings)
67 {
68  if(this->thread()->isInterruptionRequested()) {
69  return;
70  }
71 
72  if(connectivitySettings.getConnectivityMethods().isEmpty()) {
73  qDebug()<<"RtConnectivityWorker::doWork() - Network methods are empty";
74  return;
75  }
76 
77  ConnectivitySettings connectivitySettingsTemp = connectivitySettings;
78 
79  QElapsedTimer time;
80  qint64 iTime = 0;
81  time.start();
82 
83  QList<Network> finalNetworks = Connectivity::calculate(connectivitySettingsTemp);
84 
85 // iTime = time.elapsed();
86 
87 // qDebug()<<"----------------------------------------";
88 // qDebug()<<"----------------------------------------";
89 // qDebug()<<"------RtConnectivityWorker::doWork()";
90 // qDebug()<<"------Method:"<<connectivitySettings.getConnectivityMethods().first();
91 // qDebug()<<"------Data dim:"<<connectivitySettings.at(0).matData.rows() << "x" << connectivitySettings.at(0).matData.cols();
92 // qDebug()<<"------Number trials:"<< connectivitySettings.size();
93 // qDebug()<<"------Total time:"<<iTime << "ms";
94 // qDebug()<<"----------------------------------------";
95 // qDebug()<<"----------------------------------------";
96 
97  emit resultReady(finalNetworks, connectivitySettingsTemp);
98 }
99 
100 //=============================================================================================================
101 // DEFINE MEMBER METHODS RtConnectivity
102 //=============================================================================================================
103 
105 : QObject(parent)
106 {
108  worker->moveToThread(&m_workerThread);
109 
110  connect(&m_workerThread, &QThread::finished,
111  worker, &QObject::deleteLater);
112 
113  connect(this, &RtConnectivity::operate,
115 
116  connect(worker, &RtConnectivityWorker::resultReady,
117  this, &RtConnectivity::newConnectivityResultAvailable);
118 
119  m_workerThread.start();
120 }
121 
122 //=============================================================================================================
123 
125 {
126  stop();
127 }
128 
129 //=============================================================================================================
130 
131 void RtConnectivity::append(const ConnectivitySettings& connectivitySettings)
132 {
133  emit operate(connectivitySettings);
134 }
135 
136 //=============================================================================================================
137 
139 {
140  stop();
141 
143  worker->moveToThread(&m_workerThread);
144 
145  connect(&m_workerThread, &QThread::finished,
146  worker, &QObject::deleteLater);
147 
148  connect(this, &RtConnectivity::operate,
150 
151  connect(worker, &RtConnectivityWorker::resultReady,
152  this, &RtConnectivity::newConnectivityResultAvailable);
153 
154  m_workerThread.start();
155 }
156 
157 //=============================================================================================================
158 
160 {
161  m_workerThread.requestInterruption();
162  m_workerThread.quit();
163  m_workerThread.wait();
164 }
RTPROCESSINGLIB::RtConnectivity::append
void append(const CONNECTIVITYLIB::ConnectivitySettings &connectivitySettings)
Definition: rtconnectivity.cpp:131
RTPROCESSINGLIB::RtConnectivityWorker::doWork
void doWork(const CONNECTIVITYLIB::ConnectivitySettings &connectivitySettings)
Definition: rtconnectivity.cpp:66
RTPROCESSINGLIB::RtConnectivityWorker
Real-time connectivity worker.
Definition: rtconnectivity.h:85
RTPROCESSINGLIB::RtConnectivity::~RtConnectivity
~RtConnectivity()
Definition: rtconnectivity.cpp:124
rtconnectivity.h
RtConnectivity class declaration.
CONNECTIVITYLIB::ConnectivitySettings
This class is a container for connectivity settings.
Definition: connectivitysettings.h:91
RTPROCESSINGLIB::RtConnectivity::stop
void stop()
Definition: rtconnectivity.cpp:159
RTPROCESSINGLIB::RtConnectivity::restart
void restart()
Definition: rtconnectivity.cpp:138
RTPROCESSINGLIB::RtConnectivity::RtConnectivity
RtConnectivity(QObject *parent=0)
Definition: rtconnectivity.cpp:104
RTPROCESSINGLIB::RtConnectivity::m_workerThread
QThread m_workerThread
Definition: rtconnectivity.h:151
connectivitysettings.h
ConnectivitySettings class declaration.
connectivity.h
Connectivity class declaration.