Skip to content

Commit

Permalink
ENH: change storage of data in mne scan plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielbmotta committed May 5, 2021
1 parent bd29616 commit aea5354
Show file tree
Hide file tree
Showing 8 changed files with 124 additions and 24 deletions.
19 changes: 12 additions & 7 deletions applications/mne_analyze/plugins/timefrequency/timefrequency.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ QDockWidget *TimeFrequency::getControl()
connect(pSettings, &DISPLIB::TimeFrequencySettingsView::maxFreqChanged,
m_pTFModel.data(), &DISPLIB::TimeFrequencyModel::setMaxFreq, Qt::UniqueConnection);



pDock->setWidget(pSettings);


Expand Down Expand Up @@ -230,6 +232,9 @@ void TimeFrequency::onModelChanged(QSharedPointer<ANSHAREDLIB::AbstractModel> pN
m_pEvokedModel->setEvokedSet(m_pAvgModel->data(QModelIndex()).value<QSharedPointer<FIFFLIB::FiffEvokedSet>>());
m_pTimeFreqView->setEvokedSetModel(m_pEvokedModel);
}
if(pNewModel->getType() == MODEL_TYPE::ANSHAREDLIB_FIFFRAW_MODEL) {
m_pFiffRawModel = qSharedPointerCast<FiffRawViewModel>(pNewModel);
}
}

//=============================================================================================================
Expand Down Expand Up @@ -271,16 +276,16 @@ void TimeFrequency::computeTimeFreqency()
// DISPLIB::TFplot* tfplot = new DISPLIB::TFplot(spectr.front(), m_pAvgModel->getEvokedSet()->evoked.first().info.sfreq, 0, 100, DISPLIB::ColorMaps::Jet);
// tfplot->show();

auto spectr2 = RTPROCESSINGLIB::TimeFrequencyData::computeTimeFrequency(*m_pAvgModel->getEvokedSet());
// auto spectr2 = RTPROCESSINGLIB::TimeFrequencyData::computeTimeFrequency(*m_pAvgModel->getEvokedSet());

DISPLIB::TFplot* tfplot2 = new DISPLIB::TFplot(spectr2.front(), m_pAvgModel->getEvokedSet()->evoked.first().info.sfreq, 0, 100, DISPLIB::ColorMaps::Jet);
tfplot2->show();
// DISPLIB::TFplot* tfplot2 = new DISPLIB::TFplot(spectr2.front(), m_pAvgModel->getEvokedSet()->evoked.first().info.sfreq, 0, 100, DISPLIB::ColorMaps::Jet);
// tfplot2->show();

DISPLIB::TFplot* tfplot3 = new DISPLIB::TFplot(spectr2.at(20), m_pAvgModel->getEvokedSet()->evoked.first().info.sfreq, 0, 100, DISPLIB::ColorMaps::Jet);
tfplot3->show();
// DISPLIB::TFplot* tfplot3 = new DISPLIB::TFplot(spectr2.at(20), m_pAvgModel->getEvokedSet()->evoked.first().info.sfreq, 0, 100, DISPLIB::ColorMaps::Jet);
// tfplot3->show();

DISPLIB::TFplot* tfplot4 = new DISPLIB::TFplot(spectr2.at(80), m_pAvgModel->getEvokedSet()->evoked.first().info.sfreq, 0, 100, DISPLIB::ColorMaps::Jet);
tfplot4->show();
// DISPLIB::TFplot* tfplot4 = new DISPLIB::TFplot(spectr2.at(80), m_pAvgModel->getEvokedSet()->evoked.first().info.sfreq, 0, 100, DISPLIB::ColorMaps::Jet);
// tfplot4->show();


m_pTFModel->setFiffInfo(m_pAvgModel->getEvokedSet()->evoked.first().info);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,13 @@ class TIMEFREQUENCYSHARED_EXPORT TimeFrequency : public ANSHAREDLIB::AbstractPlu

QSharedPointer<DISPLIB::EvokedSetModel> m_pEvokedModel; /**< Pointer to model used to display averaging data from m_pFiffEvokedSet and m_pFiffEvoked */
QSharedPointer<ANSHAREDLIB::AveragingDataModel> m_pAvgModel; /**< Pointer to currently loaded FiffRawView Model */
QSharedPointer<ANSHAREDLIB::FiffRawViewModel> m_pFiffRawModel; /**< Pointer to currently loaded FiffRawView Model. */


QSharedPointer<DISPLIB::TimeFrequencyModel> m_pTFModel;

bool m_bComputeWithAverage;

};

//=============================================================================================================
Expand Down
72 changes: 56 additions & 16 deletions applications/mne_scan/plugins/timefrequency/timefrequency.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
#include <scMeas/realtimetimefrequency.h>
#include <scMeas/realtimemultisamplearray.h>

#include <utils/spectrogram.h>

#include <iostream>

//=============================================================================================================
Expand Down Expand Up @@ -72,7 +74,7 @@ using namespace UTILSLIB;

TimeFrequency::TimeFrequency()
: m_pCircularEvokedBuffer(CircularBuffer<FIFFLIB::FiffEvoked>::SPtr::create(40))
, m_iDataQueueBlockSize(25)
, m_iDataQueueBlockSize(15)
{
}

Expand Down Expand Up @@ -172,13 +174,14 @@ void TimeFrequency::update(SCMEASLIB::Measurement::SPtr pMeasurement)
if (m_pFiffInfo){
QMutexLocker locker(&m_qMutex);
for(unsigned char i = 0; i < pRTMSA->getMultiSampleArray().size(); ++i) {
std::cout << "pRTMSA->getMultiSampleArray().size() " << pRTMSA->getMultiSampleArray().size();
// Please note that we do not need a copy here since this function will block until
// the buffer accepts new data again. Hence, the data is not deleted in the actual
// Measurement function after it emitted the notify signal.
m_DataQueue.push_back(pRTMSA->getMultiSampleArray()[i]);
// while(!m_pCircularTimeSeriesBuffer->push(pRTMSA->getMultiSampleArray()[i])) {
// //Do nothing until the circular buffer is ready to accept new data again
// }
// m_DataQueue.push_back(pRTMSA->getMultiSampleArray()[i]);
while(!m_pCircularTimeSeriesBuffer->push(pRTMSA->getMultiSampleArray()[i])) {
//Do nothing until the circular buffer is ready to accept new data again
}
}
}
}
Expand Down Expand Up @@ -215,21 +218,50 @@ void TimeFrequency::initPluginControlWidgets()
}

//=============================================================================================================

#include <disp/plots/tfplot.h>
void TimeFrequency::run()
{
FIFFLIB::FiffEvoked evoked;
QStringList lResponsibleTriggerTypes;
Eigen::MatrixXd matData;


while(!isInterruptionRequested()){
if(m_DataQueue.size() > m_iDataQueueBlockSize){
QMutexLocker locker(&m_qMutex);
if(m_pCircularTimeSeriesBuffer->pop(matData)){

computeTimeFrequency();
// int iCols = 0;

while(m_DataQueue.size() > m_iDataQueueBlockSize){
m_DataQueue.pop_front();
}
// std::cout<< "First matrix r:" << m_DataQueue.front().rows() << " | c: " << m_DataQueue.front().cols() << std::endl;

// for (auto mat : m_DataQueue){
// iCols += mat.cols();
// }

// std::cout << "COLS: " << iCols << std::endl;

// Eigen::MatrixXd dataMat(m_DataQueue.front().rows(), iCols);

// for (auto mat : m_DataQueue){
// Eigen::MatrixXd temp = mat;
// dataMat << temp;
// }

// std::cout << "New Matrix - r: " << dataMat.rows() << " | c: " << dataMat.cols() << std::endl;

// if((testing_counter % 20) == 0){
// Eigen::VectorXd dataCol = dataMat.row(1).transpose();

// Eigen::MatrixXd Spectrum = UTILSLIB::Spectrogram::makeSpectrogram(dataCol, m_pFiffInfo->sfreq * 0.2);

//// DISPLIB::TFplot* tfplot2 = new DISPLIB::TFplot(Spectrum, m_pFiffInfo->sfreq, 0, 50, DISPLIB::ColorMaps::Jet);

//// tfplot2->show();
// }

// while(m_DataQueue.size() > m_iDataQueueBlockSize){
// m_DataQueue.pop_front();
// }
// testing_counter++;
}
// if(m_pCircularEvokedBuffer->pop(evoked)) {
// m_qMutex.lock();
Expand All @@ -251,17 +283,25 @@ void TimeFrequency::computeTimeFrequency()

std::cout<< "First matrix r:" << m_DataQueue.front().rows() << " | c: " << m_DataQueue.front().cols() << std::endl;

Eigen::MatrixXd dataMat(m_DataQueue.front().rows(), iCols);

{
QMutexLocker locker(&m_qMutex);
for (auto mat : m_DataQueue){
iCols += mat.cols();
}

std::cout << "COLS: " << iCols << std::endl;

Eigen::MatrixXd dataMat(m_DataQueue.front().rows(), iCols);

for (auto mat : m_DataQueue){
dataMat << mat;
}

}
std::cout << "New Matrix - r: " << dataMat.rows() << " | c: " << dataMat.cols() << std::endl;

// for(int i = 0; i < dataMat.rows(); i++){
// Eigen::VectorXd dataCol = dataMat.row(i).transpose();

// Eigen::MatrixXd Spectrum = UTILSLIB::Spectrogram::makeSpectrogram(dataCol, m_pFiffInfo->sfreq * 0.2);
// }

}
40 changes: 39 additions & 1 deletion libraries/disp/viewers/formfiles/timefrequencysettingsview.ui
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,44 @@
</item>
</layout>
</item>
<item>
<widget class="QFrame" name="frame">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QRadioButton" name="radioButton_avg">
<property name="text">
<string>Use average</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="radioButton_rawdata">
<property name="text">
<string>Use raw data</string>
</property>
<property name="checked">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</item>
Expand All @@ -138,7 +176,7 @@
</spacer>
</item>
<item>
<widget class="QCheckBox" name="checkBox">
<widget class="QCheckBox" name="checkBox_auto">
<property name="text">
<string>Auto recompute for new averages.</string>
</property>
Expand Down
4 changes: 4 additions & 0 deletions libraries/disp/viewers/helpers/timefrequencymodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,13 +219,17 @@ float TimeFrequencyModel::getSamplingFrequency()
void TimeFrequencyModel::setMinFreq(int iFreq)
{
m_iMinFreq = iFreq;

emit dataChanged(index(0,0), index(rowCount() - 1, columnCount() - 1));
}

//=============================================================================================================

void TimeFrequencyModel::setMaxFreq(int iFreq)
{
m_iMaxFreq = iFreq;

emit dataChanged(index(0,0), index(rowCount() - 1, columnCount() - 1));
}

//=============================================================================================================
Expand Down
4 changes: 4 additions & 0 deletions libraries/disp/viewers/timefrequencysettingsview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,8 @@ void TimeFrequencySettingsView::initGUI()

connect(m_pUi->pushButton_ciompute, &QPushButton::released,
this, &TimeFrequencySettingsView::computePushed, Qt::UniqueConnection);


connect(m_pUi->radioButton_avg, &QRadioButton::toggled,
this, &TimeFrequencySettingsView::computeWithAvg, Qt::UniqueConnection);
}
2 changes: 2 additions & 0 deletions libraries/disp/viewers/timefrequencysettingsview.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ class DISPSHARED_EXPORT TimeFrequencySettingsView : public AbstractView

void colorMapChanged(const QString &colormap);

void computeWithAvg(bool checked);

protected:

void initGUI();
Expand Down
3 changes: 3 additions & 0 deletions libraries/rtprocessing/timefrequency.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ class RTPROCESINGSHARED_EXPORT TimeFrequencyData
static std::vector<Eigen::MatrixXcd> computeComplexTimeFrequency(const FIFFLIB::FiffEvokedSet& evokedSet);

private:

Eigen::MatrixXcd m_TFData;

};


Expand Down

0 comments on commit aea5354

Please sign in to comment.