Skip to content

Commit aea5354

Browse files
committed
ENH: change storage of data in mne scan plugin
1 parent bd29616 commit aea5354

File tree

8 files changed

+124
-24
lines changed

8 files changed

+124
-24
lines changed

applications/mne_analyze/plugins/timefrequency/timefrequency.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ QDockWidget *TimeFrequency::getControl()
148148
connect(pSettings, &DISPLIB::TimeFrequencySettingsView::maxFreqChanged,
149149
m_pTFModel.data(), &DISPLIB::TimeFrequencyModel::setMaxFreq, Qt::UniqueConnection);
150150

151+
152+
151153
pDock->setWidget(pSettings);
152154

153155

@@ -230,6 +232,9 @@ void TimeFrequency::onModelChanged(QSharedPointer<ANSHAREDLIB::AbstractModel> pN
230232
m_pEvokedModel->setEvokedSet(m_pAvgModel->data(QModelIndex()).value<QSharedPointer<FIFFLIB::FiffEvokedSet>>());
231233
m_pTimeFreqView->setEvokedSetModel(m_pEvokedModel);
232234
}
235+
if(pNewModel->getType() == MODEL_TYPE::ANSHAREDLIB_FIFFRAW_MODEL) {
236+
m_pFiffRawModel = qSharedPointerCast<FiffRawViewModel>(pNewModel);
237+
}
233238
}
234239

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

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

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

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

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

285290

286291
m_pTFModel->setFiffInfo(m_pAvgModel->getEvokedSet()->evoked.first().info);

applications/mne_analyze/plugins/timefrequency/timefrequency.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,13 @@ class TIMEFREQUENCYSHARED_EXPORT TimeFrequency : public ANSHAREDLIB::AbstractPlu
158158

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

162164
QSharedPointer<DISPLIB::TimeFrequencyModel> m_pTFModel;
163165

166+
bool m_bComputeWithAverage;
167+
164168
};
165169

166170
//=============================================================================================================

applications/mne_scan/plugins/timefrequency/timefrequency.cpp

Lines changed: 56 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@
4545
#include <scMeas/realtimetimefrequency.h>
4646
#include <scMeas/realtimemultisamplearray.h>
4747

48+
#include <utils/spectrogram.h>
49+
4850
#include <iostream>
4951

5052
//=============================================================================================================
@@ -72,7 +74,7 @@ using namespace UTILSLIB;
7274

7375
TimeFrequency::TimeFrequency()
7476
: m_pCircularEvokedBuffer(CircularBuffer<FIFFLIB::FiffEvoked>::SPtr::create(40))
75-
, m_iDataQueueBlockSize(25)
77+
, m_iDataQueueBlockSize(15)
7678
{
7779
}
7880

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

217220
//=============================================================================================================
218-
221+
#include <disp/plots/tfplot.h>
219222
void TimeFrequency::run()
220223
{
221224
FIFFLIB::FiffEvoked evoked;
222225
QStringList lResponsibleTriggerTypes;
226+
Eigen::MatrixXd matData;
227+
223228

224229
while(!isInterruptionRequested()){
225-
if(m_DataQueue.size() > m_iDataQueueBlockSize){
226-
QMutexLocker locker(&m_qMutex);
230+
if(m_pCircularTimeSeriesBuffer->pop(matData)){
227231

228-
computeTimeFrequency();
232+
// int iCols = 0;
229233

230-
while(m_DataQueue.size() > m_iDataQueueBlockSize){
231-
m_DataQueue.pop_front();
232-
}
234+
// std::cout<< "First matrix r:" << m_DataQueue.front().rows() << " | c: " << m_DataQueue.front().cols() << std::endl;
235+
236+
// for (auto mat : m_DataQueue){
237+
// iCols += mat.cols();
238+
// }
239+
240+
// std::cout << "COLS: " << iCols << std::endl;
241+
242+
// Eigen::MatrixXd dataMat(m_DataQueue.front().rows(), iCols);
243+
244+
// for (auto mat : m_DataQueue){
245+
// Eigen::MatrixXd temp = mat;
246+
// dataMat << temp;
247+
// }
248+
249+
// std::cout << "New Matrix - r: " << dataMat.rows() << " | c: " << dataMat.cols() << std::endl;
250+
251+
// if((testing_counter % 20) == 0){
252+
// Eigen::VectorXd dataCol = dataMat.row(1).transpose();
253+
254+
// Eigen::MatrixXd Spectrum = UTILSLIB::Spectrogram::makeSpectrogram(dataCol, m_pFiffInfo->sfreq * 0.2);
255+
256+
//// DISPLIB::TFplot* tfplot2 = new DISPLIB::TFplot(Spectrum, m_pFiffInfo->sfreq, 0, 50, DISPLIB::ColorMaps::Jet);
257+
258+
//// tfplot2->show();
259+
// }
260+
261+
// while(m_DataQueue.size() > m_iDataQueueBlockSize){
262+
// m_DataQueue.pop_front();
263+
// }
264+
// testing_counter++;
233265
}
234266
// if(m_pCircularEvokedBuffer->pop(evoked)) {
235267
// m_qMutex.lock();
@@ -251,17 +283,25 @@ void TimeFrequency::computeTimeFrequency()
251283

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

286+
Eigen::MatrixXd dataMat(m_DataQueue.front().rows(), iCols);
287+
288+
{
289+
QMutexLocker locker(&m_qMutex);
254290
for (auto mat : m_DataQueue){
255291
iCols += mat.cols();
256292
}
257293

258294
std::cout << "COLS: " << iCols << std::endl;
259-
260-
Eigen::MatrixXd dataMat(m_DataQueue.front().rows(), iCols);
261-
262295
for (auto mat : m_DataQueue){
263296
dataMat << mat;
264297
}
265-
298+
}
266299
std::cout << "New Matrix - r: " << dataMat.rows() << " | c: " << dataMat.cols() << std::endl;
300+
301+
// for(int i = 0; i < dataMat.rows(); i++){
302+
// Eigen::VectorXd dataCol = dataMat.row(i).transpose();
303+
304+
// Eigen::MatrixXd Spectrum = UTILSLIB::Spectrogram::makeSpectrogram(dataCol, m_pFiffInfo->sfreq * 0.2);
305+
// }
306+
267307
}

libraries/disp/viewers/formfiles/timefrequencysettingsview.ui

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,44 @@
121121
</item>
122122
</layout>
123123
</item>
124+
<item>
125+
<widget class="QFrame" name="frame">
126+
<property name="sizePolicy">
127+
<sizepolicy hsizetype="Preferred" vsizetype="Minimum">
128+
<horstretch>0</horstretch>
129+
<verstretch>0</verstretch>
130+
</sizepolicy>
131+
</property>
132+
<property name="frameShape">
133+
<enum>QFrame::StyledPanel</enum>
134+
</property>
135+
<property name="frameShadow">
136+
<enum>QFrame::Raised</enum>
137+
</property>
138+
<layout class="QHBoxLayout" name="horizontalLayout_3">
139+
<item>
140+
<widget class="QRadioButton" name="radioButton_avg">
141+
<property name="text">
142+
<string>Use average</string>
143+
</property>
144+
<property name="checked">
145+
<bool>true</bool>
146+
</property>
147+
</widget>
148+
</item>
149+
<item>
150+
<widget class="QRadioButton" name="radioButton_rawdata">
151+
<property name="text">
152+
<string>Use raw data</string>
153+
</property>
154+
<property name="checked">
155+
<bool>false</bool>
156+
</property>
157+
</widget>
158+
</item>
159+
</layout>
160+
</widget>
161+
</item>
124162
</layout>
125163
</widget>
126164
</item>
@@ -138,7 +176,7 @@
138176
</spacer>
139177
</item>
140178
<item>
141-
<widget class="QCheckBox" name="checkBox">
179+
<widget class="QCheckBox" name="checkBox_auto">
142180
<property name="text">
143181
<string>Auto recompute for new averages.</string>
144182
</property>

libraries/disp/viewers/helpers/timefrequencymodel.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,13 +219,17 @@ float TimeFrequencyModel::getSamplingFrequency()
219219
void TimeFrequencyModel::setMinFreq(int iFreq)
220220
{
221221
m_iMinFreq = iFreq;
222+
223+
emit dataChanged(index(0,0), index(rowCount() - 1, columnCount() - 1));
222224
}
223225

224226
//=============================================================================================================
225227

226228
void TimeFrequencyModel::setMaxFreq(int iFreq)
227229
{
228230
m_iMaxFreq = iFreq;
231+
232+
emit dataChanged(index(0,0), index(rowCount() - 1, columnCount() - 1));
229233
}
230234

231235
//=============================================================================================================

libraries/disp/viewers/timefrequencysettingsview.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,4 +140,8 @@ void TimeFrequencySettingsView::initGUI()
140140

141141
connect(m_pUi->pushButton_ciompute, &QPushButton::released,
142142
this, &TimeFrequencySettingsView::computePushed, Qt::UniqueConnection);
143+
144+
145+
connect(m_pUi->radioButton_avg, &QRadioButton::toggled,
146+
this, &TimeFrequencySettingsView::computeWithAvg, Qt::UniqueConnection);
143147
}

libraries/disp/viewers/timefrequencysettingsview.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ class DISPSHARED_EXPORT TimeFrequencySettingsView : public AbstractView
112112

113113
void colorMapChanged(const QString &colormap);
114114

115+
void computeWithAvg(bool checked);
116+
115117
protected:
116118

117119
void initGUI();

libraries/rtprocessing/timefrequency.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ class RTPROCESINGSHARED_EXPORT TimeFrequencyData
8080
static std::vector<Eigen::MatrixXcd> computeComplexTimeFrequency(const FIFFLIB::FiffEvokedSet& evokedSet);
8181

8282
private:
83+
84+
Eigen::MatrixXcd m_TFData;
85+
8386
};
8487

8588

0 commit comments

Comments
 (0)