Skip to content

Commit 70b0677

Browse files
committed
MAINT: convert other algorithm plugins
1 parent fd77c90 commit 70b0677

File tree

10 files changed

+82
-38
lines changed

10 files changed

+82
-38
lines changed

applications/mne_scan/plugins/neuronalconnectivity/neuronalconnectivity.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ NeuronalConnectivity::NeuronalConnectivity()
109109

110110
NeuronalConnectivity::~NeuronalConnectivity()
111111
{
112-
if(this->isRunning()) {
112+
if(m_bProcessOutput) {
113113
stop();
114114
}
115115
}
@@ -195,7 +195,8 @@ void NeuronalConnectivity::unload()
195195
bool NeuronalConnectivity::start()
196196
{
197197
//Start thread
198-
QThread::start();
198+
m_bProcessOutput = true;
199+
m_OutputProcessingThread = std::thread(&NeuronalConnectivity::run, this);
199200

200201
return true;
201202
}
@@ -206,8 +207,11 @@ bool NeuronalConnectivity::stop()
206207
{
207208
m_pRtConnectivity->restart();
208209

209-
requestInterruption();
210-
wait(500);
210+
m_bProcessOutput = false;
211+
212+
if(m_OutputProcessingThread.joinable()){
213+
m_OutputProcessingThread.join();
214+
}
211215

212216
m_bPluginControlWidgetsInit = false;
213217

@@ -510,13 +514,13 @@ void NeuronalConnectivity::run()
510514
break;
511515
}
512516
m_mutex.unlock();
513-
msleep(100);
517+
std::this_thread::sleep_for(std::chrono::milliseconds(100));
514518
}
515519

516520
int skip_count = 0;
517521
Network network;
518522

519-
while(!isInterruptionRequested()) {
523+
while(m_bProcessOutput) {
520524
//Do processing after skip count has reached limit
521525
if((skip_count % m_iDownSample) == 0) {
522526
if(m_pCircularBuffer->pop(network)) {
@@ -562,7 +566,7 @@ void NeuronalConnectivity::onMetricChanged(const QString& sMetric)
562566

563567
m_sConnectivityMethods = QStringList() << sMetric;
564568
m_connectivitySettings.setConnectivityMethods(m_sConnectivityMethods);
565-
if(m_pRtConnectivity && this->isRunning()) {
569+
if(m_pRtConnectivity && m_bProcessOutput) {
566570
m_pRtConnectivity->restart();
567571
m_pRtConnectivity->append(m_connectivitySettings);
568572
}

applications/mne_scan/plugins/neuronalconnectivity/neuronalconnectivity.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@
4949
#include <connectivity/connectivitysettings.h>
5050
#include <connectivity/network/network.h>
5151

52+
#include <thread>
53+
5254
//=============================================================================================================
5355
// QT INCLUDES
5456
//=============================================================================================================
@@ -272,6 +274,9 @@ class NEURONALCONNECTIVITYSHARED_EXPORT NeuronalConnectivity : public SCSHAREDLI
272274
Eigen::RowVectorXi m_vecPicks; /**< The picked data channels. */
273275

274276
CONNECTIVITYLIB::Network m_currentConnectivityResult; /**< The current connectivity result.*/
277+
278+
std::thread m_OutputProcessingThread;
279+
std::atomic_bool m_bProcessOutput;
275280
};
276281
} // NAMESPACE
277282

applications/mne_scan/plugins/noisereduction/noisereduction.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ NoiseReduction::NoiseReduction()
111111

112112
NoiseReduction::~NoiseReduction()
113113
{
114-
if(this->isRunning()) {
114+
if(m_bProcessOutput) {
115115
stop();
116116
}
117117
}
@@ -159,8 +159,11 @@ bool NoiseReduction::start()
159159

160160
bool NoiseReduction::stop()
161161
{
162-
requestInterruption();
163-
wait(500);
162+
m_bProcessOutput = false;
163+
164+
if(m_OutputProcessingThread.joinable()){
165+
m_OutputProcessingThread.join();
166+
}
164167

165168
m_iMaxFilterTapSize = -1;
166169

@@ -224,7 +227,8 @@ void NoiseReduction::update(SCMEASLIB::Measurement::SPtr pMeasurement)
224227
if(m_iMaxFilterTapSize == -1) {
225228
m_iMaxFilterTapSize = pRTMSA->getMultiSampleArray().first().cols();
226229
initPluginControlWidgets();
227-
QThread::start();
230+
m_bProcessOutput = true;
231+
m_OutputProcessingThread = std::thread(&NoiseReduction::run, this);
228232
}
229233

230234
for(unsigned char i = 0; i < pRTMSA->getMultiSampleArray().size(); ++i) {
@@ -345,7 +349,7 @@ void NoiseReduction::run()
345349
MatrixXd matData;
346350
QScopedPointer<RTPROCESSINGLIB::FilterOverlapAdd> pRtFilter(new RTPROCESSINGLIB::FilterOverlapAdd());
347351

348-
while(!isInterruptionRequested()) {
352+
while(m_bProcessOutput) {
349353
// Get the current data
350354
if(m_pCircularBuffer->pop(matData)) {
351355
m_mutex.lock();
@@ -409,7 +413,7 @@ void NoiseReduction::run()
409413
m_mutex.unlock();
410414

411415
//Send the data to the connected plugins and the display
412-
if(!isInterruptionRequested()) {
416+
if(m_bProcessOutput) {
413417
m_pNoiseReductionOutput->measurementData()->setValue(matData);
414418
}
415419
}

applications/mne_scan/plugins/noisereduction/noisereduction.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@
5050

5151
#include <scShared/Plugins/abstractalgorithm.h>
5252

53+
#include <thread>
54+
5355
//=============================================================================================================
5456
// QT INCLUDES
5557
//=============================================================================================================
@@ -263,6 +265,8 @@ class NOISEREDUCTIONSHARED_EXPORT NoiseReduction : public SCSHAREDLIB::AbstractA
263265
SCSHAREDLIB::PluginInputData<SCMEASLIB::RealTimeMultiSampleArray>::SPtr m_pNoiseReductionInput; /**< The RealTimeMultiSampleArray of the NoiseReduction input.*/
264266
SCSHAREDLIB::PluginOutputData<SCMEASLIB::RealTimeMultiSampleArray>::SPtr m_pNoiseReductionOutput; /**< The RealTimeMultiSampleArray of the NoiseReduction output.*/
265267

268+
std::thread m_OutputProcessingThread;
269+
std::atomic_bool m_bProcessOutput;
266270
signals:
267271
};
268272
} // NAMESPACE

applications/mne_scan/plugins/rtcmne/rtcmne.cpp

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ RtcMne::~RtcMne()
115115
{
116116
m_future.waitForFinished();
117117

118-
if(this->isRunning()) {
118+
if(m_bProcessOutput) {
119119
stop();
120120
}
121121
}
@@ -313,16 +313,20 @@ bool RtcMne::calcFiffInfo()
313313

314314
bool RtcMne::start()
315315
{
316-
QThread::start();
316+
m_bProcessOutput = true;
317+
m_OutputProcessingThread = std::thread(&RtcMne::run, this);
317318
return true;
318319
}
319320

320321
//=============================================================================================================
321322

322323
bool RtcMne::stop()
323324
{
324-
requestInterruption();
325-
wait(500);
325+
m_bProcessOutput = false;
326+
327+
if(m_OutputProcessingThread.joinable()){
328+
m_OutputProcessingThread.join();
329+
}
326330

327331
m_qListCovChNames.clear();
328332
m_bEvokedInput = false;
@@ -369,7 +373,7 @@ void RtcMne::updateRTFS(SCMEASLIB::Measurement::SPtr pMeasurement)
369373
m_qMutex.unlock();
370374

371375
// update inverse operator
372-
if(this->isRunning() && m_pRtInvOp) {
376+
if(m_bProcessOutput && m_pRtInvOp) {
373377
m_pRtInvOp->setFwdSolution(m_pFwd);
374378
m_pRtInvOp->append(*m_pNoiseCov);
375379
}
@@ -386,7 +390,7 @@ void RtcMne::updateRTMSA(SCMEASLIB::Measurement::SPtr pMeasurement)
386390
if(m_pFwd) {
387391
QSharedPointer<RealTimeMultiSampleArray> pRTMSA = pMeasurement.dynamicCast<RealTimeMultiSampleArray>();
388392

389-
if(pRTMSA && this->isRunning()) {
393+
if(pRTMSA && m_bProcessOutput) {
390394
//Fiff Information of the RTMSA
391395
m_qMutex.lock();
392396
if(!m_pFiffInfoInput) {
@@ -400,7 +404,7 @@ void RtcMne::updateRTMSA(SCMEASLIB::Measurement::SPtr pMeasurement)
400404
initPluginControlWidgets();
401405
}
402406

403-
if(this->isRunning()) {
407+
if(m_bProcessOutput) {
404408
// Check for artifacts
405409
QMap<QString,double> mapReject;
406410
mapReject.insert("eog", 150e-06);
@@ -433,7 +437,7 @@ void RtcMne::updateRTC(SCMEASLIB::Measurement::SPtr pMeasurement)
433437
if(m_pFwd) {
434438
QSharedPointer<RealTimeCov> pRTC = pMeasurement.dynamicCast<RealTimeCov>();
435439

436-
if(pRTC && this->isRunning()) {
440+
if(pRTC && m_bProcessOutput) {
437441
// Init Real-Time inverse estimator
438442
if(!m_pRtInvOp && m_pFiffInfo && m_pFwd) {
439443
m_pRtInvOp = RtInvOp::SPtr(new RtInvOp(m_pFiffInfo, m_pFwd));
@@ -446,7 +450,7 @@ void RtcMne::updateRTC(SCMEASLIB::Measurement::SPtr pMeasurement)
446450
m_qListCovChNames = pRTC->getValue()->names;
447451
}
448452

449-
if(this->isRunning() && m_pRtInvOp){
453+
if(m_bProcessOutput && m_pRtInvOp){
450454
m_pNoiseCov = pRTC->getValue();
451455
m_pRtInvOp->append(*m_pNoiseCov);
452456
}
@@ -467,7 +471,7 @@ void RtcMne::updateRTE(SCMEASLIB::Measurement::SPtr pMeasurement)
467471
initPluginControlWidgets();
468472
}
469473

470-
if(!this->isRunning() || !lResponsibleTriggerTypes.contains(m_sAvrType)) {
474+
if(!m_bProcessOutput || !lResponsibleTriggerTypes.contains(m_sAvrType)) {
471475
return;
472476
}
473477

@@ -491,7 +495,7 @@ void RtcMne::updateRTE(SCMEASLIB::Measurement::SPtr pMeasurement)
491495
initPluginControlWidgets();
492496
}
493497

494-
if(this->isRunning()) {
498+
if(m_bProcessOutput) {
495499
for(int i = 0; i < pFiffEvokedSet->evoked.size(); ++i) {
496500
if(pFiffEvokedSet->evoked.at(i).comment == m_sAvrType) {
497501
// Store current evoked as member so we can dispatch it if the time pick by the user changed
@@ -551,7 +555,7 @@ void RtcMne::onTimePointValueChanged(int iTimePointMs)
551555
m_iTimePointSps = m_pFiffInfoInput->sfreq * (float)iTimePointMs * 0.001f;
552556
m_qMutex.unlock();
553557

554-
if(this->isRunning()) {
558+
if(m_bProcessOutput) {
555559
while(!m_pCircularEvokedBuffer->push(m_currentEvoked)) {
556560
//Do nothing until the circular buffer is ready to accept new data again
557561
}
@@ -565,7 +569,7 @@ void RtcMne::run()
565569
{
566570
// Wait for fiff info to arrive
567571
while(!calcFiffInfo()) {
568-
msleep(200);
572+
std::this_thread::sleep_for(std::chrono::milliseconds(200));
569573
}
570574

571575
// Init parameters
@@ -588,7 +592,7 @@ void RtcMne::run()
588592
QStringList lChNamesInvOp;
589593

590594
// Start processing data
591-
while(!isInterruptionRequested()) {
595+
while(m_bProcessOutput) {
592596
m_qMutex.lock();
593597
iTimePointSps = m_iTimePointSps;
594598
bEvokedInput = m_bEvokedInput;

applications/mne_scan/plugins/rtcmne/rtcmne.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@
5050

5151
#include <mne/mne_inverse_operator.h>
5252

53+
#include <thread>
54+
5355
//=============================================================================================================
5456
// QT INCLUDES
5557
//=============================================================================================================
@@ -265,6 +267,9 @@ class RTCMNESHARED_EXPORT RtcMne : public SCSHAREDLIB::AbstractAlgorithm
265267

266268
MNELIB::MNEInverseOperator m_invOp; /**< The inverse operator. */
267269

270+
std::thread m_OutputProcessingThread;
271+
std::atomic_bool m_bProcessOutput;
272+
268273
signals:
269274
void responsibleTriggerTypesChanged(const QStringList& lResponsibleTriggerTypes);
270275

applications/mne_scan/plugins/rtfwd/rtfwd.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ RtFwd::~RtFwd()
115115
{
116116
m_future.waitForFinished();
117117

118-
if(this->isRunning()) {
118+
if(m_bProcessOutput) {
119119
stop();
120120
}
121121
}
@@ -222,7 +222,8 @@ bool RtFwd::start()
222222
stream->close();
223223

224224
//Start thread
225-
QThread::start();
225+
m_bProcessOutput = true;
226+
m_OutputProcessingThread = std::thread(&RtFwd::run, this);
226227

227228
return true;
228229
}
@@ -231,8 +232,11 @@ bool RtFwd::start()
231232

232233
bool RtFwd::stop()
233234
{
234-
requestInterruption();
235-
wait(500);
235+
m_bProcessOutput = false;
236+
237+
if(m_OutputProcessingThread.joinable()){
238+
m_OutputProcessingThread.join();
239+
}
236240

237241
m_bPluginControlWidgetsInit = false;
238242

@@ -400,7 +404,7 @@ void RtFwd::run()
400404
break;
401405
}
402406
m_mutex.unlock();
403-
msleep(200);
407+
std::this_thread::sleep_for(std::chrono::milliseconds(200));
404408
}
405409

406410
m_mutex.lock();
@@ -429,7 +433,7 @@ void RtFwd::run()
429433
bool bDoFwdComputation = false; // compute forward if requested
430434
bool bIsInit = false; // only recompute if initial fwd solulion is calculated
431435

432-
while(!isInterruptionRequested()) {
436+
while(m_bProcessOutput) {
433437
m_mutex.lock();
434438
bDoFwdComputation = m_bDoFwdComputation;
435439
m_mutex.unlock();

applications/mne_scan/plugins/rtfwd/rtfwd.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@
4949

5050
#include <fiff/fiff_coord_trans.h>
5151

52+
#include <thread>
53+
5254
//=============================================================================================================
5355
// QT INCLUDES
5456
//=============================================================================================================
@@ -225,6 +227,9 @@ class RTFWDSHARED_EXPORT RtFwd : public SCSHAREDLIB::AbstractAlgorithm
225227

226228
SCSHAREDLIB::PluginOutputData<SCMEASLIB::RealTimeFwdSolution>::SPtr m_pRTFSOutput; /**< The fwd solution.*/
227229

230+
std::thread m_OutputProcessingThread;
231+
std::atomic_bool m_bProcessOutput;
232+
228233
signals:
229234
//=========================================================================================================
230235
/**

applications/mne_scan/plugins/writetofile/writetofile.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ WriteToFile::WriteToFile()
111111

112112
WriteToFile::~WriteToFile()
113113
{
114-
if(this->isRunning()) {
114+
if(m_bProcessOutput) {
115115
stop();
116116
}
117117
}
@@ -145,7 +145,8 @@ void WriteToFile::unload()
145145

146146
bool WriteToFile::start()
147147
{
148-
QThread::start();
148+
m_bProcessOutput = true;
149+
m_OutputProcessingThread = std::thread(&WriteToFile::run, this);
149150

150151
return true;
151152
}
@@ -154,8 +155,11 @@ bool WriteToFile::start()
154155

155156
bool WriteToFile::stop()
156157
{
157-
requestInterruption();
158-
wait();
158+
m_bProcessOutput = false;
159+
160+
if(m_OutputProcessingThread.joinable()){
161+
m_OutputProcessingThread.join();
162+
}
159163

160164
m_bPluginControlWidgetsInit = false;
161165

@@ -293,7 +297,7 @@ void WriteToFile::run()
293297
MatrixXd matData;
294298
qint32 size = 0;
295299

296-
while(!isInterruptionRequested()) {
300+
while(m_bProcessOutput) {
297301
if(m_pCircularBuffer) {
298302
//pop matrix
299303

0 commit comments

Comments
 (0)