Skip to content

Commit 82926ce

Browse files
committed
optimize
1 parent b802ab8 commit 82926ce

File tree

5 files changed

+35
-27
lines changed

5 files changed

+35
-27
lines changed

gui/include/gui/waterfallplotwidget.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#define WATERFALL_PLOT_WIDGET_H
2424

2525
#include "plotwidget.h"
26+
#include "toolcomponent.h"
2627
#include "scopy-gui_export.h"
2728

2829
#include <qwt_plot_spectrogram.h>
@@ -43,7 +44,7 @@ class SCOPY_GUI_EXPORT WaterfallData : public QwtRasterData
4344
explicit WaterfallData(int maxRows = 200);
4445
~WaterfallData() override;
4546

46-
void addFFTData(const double *data, size_t size);
47+
void addFFTData(const float *data, size_t size);
4748
void reset();
4849

4950
void setXInterval(double minFreq, double maxFreq);
@@ -57,7 +58,7 @@ class SCOPY_GUI_EXPORT WaterfallData : public QwtRasterData
5758
double value(double x, double y) const override;
5859

5960
private:
60-
std::deque<std::vector<double>> m_data;
61+
std::deque<std::vector<float>> m_data;
6162
int m_maxRows;
6263
size_t m_fftSize;
6364

@@ -98,16 +99,15 @@ class SCOPY_GUI_EXPORT WaterfallPlotWidget : public PlotWidget
9899
explicit WaterfallPlotWidget(QWidget *parent = nullptr);
99100
~WaterfallPlotWidget() override;
100101

101-
void addFFTData(const double *data, size_t size);
102+
void addFFTData(const float *data, size_t size);
102103
void clearData();
103104

105+
void setChannel(ChannelData *ch);
106+
104107
void setFrequencyRange(double startHz, double stopHz);
105108
void setIntensityRange(double minDb, double maxDb);
106109
void setNumRows(int rows);
107110

108-
Q_SIGNALS:
109-
void newData();
110-
111111
public Q_SLOTS:
112112
void updateYAxis();
113113

@@ -119,6 +119,8 @@ public Q_SLOTS:
119119
QElapsedTimer m_rowTimer;
120120
double m_secsPerRow;
121121
int m_rowCount;
122+
123+
ChannelData *m_channel = nullptr;
122124
};
123125

124126
} // namespace scopy

gui/src/cursorcontroller.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,12 +212,14 @@ void CursorController::syncXCursorControllers(CursorController *ctrl1, CursorCon
212212
ctrl1->x1Cursor->blockSignals(true);
213213
ctrl2->x1Cursor->setPosition(pos);
214214
ctrl1->x1Cursor->blockSignals(false);
215+
ctrl2->x1Cursor->repaint();
215216
ctrl2->m_plot->repaint();
216217
});
217218
connect(ctrl1->x2Cursor, &PlotAxisHandle::scalePosChanged, ctrl2->x2Cursor, [=](double pos) {
218219
ctrl1->x2Cursor->blockSignals(true);
219220
ctrl2->x2Cursor->setPosition(pos);
220221
ctrl1->x2Cursor->blockSignals(false);
222+
ctrl2->x2Cursor->repaint();
221223
ctrl2->m_plot->repaint();
222224
});
223225

@@ -226,12 +228,14 @@ void CursorController::syncXCursorControllers(CursorController *ctrl1, CursorCon
226228
ctrl2->x1Cursor->blockSignals(true);
227229
ctrl1->x1Cursor->setPosition(pos);
228230
ctrl2->x1Cursor->blockSignals(false);
231+
ctrl1->x1Cursor->repaint();
229232
ctrl1->m_plot->repaint();
230233
});
231234
connect(ctrl2->x2Cursor, &PlotAxisHandle::scalePosChanged, ctrl1->x2Cursor, [=](double pos) {
232235
ctrl2->x2Cursor->blockSignals(true);
233236
ctrl1->x2Cursor->setPosition(pos);
234237
ctrl2->x2Cursor->blockSignals(false);
238+
ctrl1->x2Cursor->repaint();
235239
ctrl1->m_plot->repaint();
236240
});
237241
}

gui/src/waterfallplotwidget.cpp

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
#include <qwt_scale_widget.h>
3131
#include <cfloat>
32+
#include <vector>
3233

3334
using namespace scopy;
3435

@@ -47,7 +48,7 @@ WaterfallData::WaterfallData(int maxRows)
4748

4849
WaterfallData::~WaterfallData() {}
4950

50-
void WaterfallData::addFFTData(const double *data, size_t size)
51+
void WaterfallData::addFFTData(const float *data, size_t size)
5152
{
5253
if(!data || size == 0)
5354
return;
@@ -60,7 +61,7 @@ void WaterfallData::addFFTData(const double *data, size_t size)
6061
m_fftSize = size;
6162
}
6263

63-
m_data.push_back(std::vector<double>(data, data + size));
64+
m_data.push_back(std::vector<float>(data, data + size));
6465

6566
while(static_cast<int>(m_data.size()) > m_maxRows)
6667
m_data.pop_front();
@@ -116,7 +117,7 @@ double WaterfallData::value(double x, double y) const
116117
if(bin < 0 || static_cast<size_t>(bin) >= m_fftSize)
117118
return -DBL_MAX;
118119

119-
return m_data[static_cast<size_t>(dataRow)][static_cast<size_t>(bin)];
120+
return static_cast<double>(m_data[static_cast<size_t>(dataRow)][static_cast<size_t>(bin)]);
120121
}
121122

122123
// =============================================================================
@@ -182,7 +183,7 @@ WaterfallPlotWidget::WaterfallPlotWidget(QWidget *parent)
182183

183184
WaterfallPlotWidget::~WaterfallPlotWidget() {}
184185

185-
void WaterfallPlotWidget::addFFTData(const double *data, size_t size)
186+
void WaterfallPlotWidget::addFFTData(const float *data, size_t size)
186187
{
187188
if(m_rowTimer.isValid()) {
188189
const double elapsed = m_rowTimer.elapsed() / 1000.0;
@@ -245,4 +246,18 @@ void WaterfallPlotWidget::setNumRows(int rows)
245246
yAxis()->setInterval(rows, 0);
246247
}
247248

249+
void WaterfallPlotWidget::setChannel(ChannelData *ch)
250+
{
251+
disconnect(m_channel, &ChannelData::newData, this, nullptr);
252+
if(m_channel != ch)
253+
clearData();
254+
255+
m_channel = ch;
256+
if(ch)
257+
connect(m_channel, &ChannelData::newData, this, [this](const float *, const float *yData, size_t size, bool) {
258+
addFFTData(yData, size);
259+
replot();
260+
});
261+
}
262+
248263
#include "moc_waterfallplotwidget.cpp"

packages/generic-plugins/plugins/adc/src/freq/fftplotcomponent.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,9 @@ FFTPlotComponent::FFTPlotComponent(QString name, uint32_t uuid, QWidget *parent)
9494
m_waterfallCursor = new CursorController(m_waterfallPlot, this);
9595
m_waterfallCursor->getPlotCursors()->setXHandlePos((HandlePos)xCursorPos);
9696
m_waterfallCursor->getPlotCursors()->setYHandlePos((HandlePos)yCursorPos);
97-
CursorController::syncXCursorControllers(m_cursor, m_waterfallCursor);
9897

98+
CursorController::syncXCursorControllers(m_cursor, m_waterfallCursor);
9999
PlotNavigator::syncXNavigators(m_fftPlot->navigator(), m_waterfallPlot->navigator());
100-
101100
}
102101

103102
FFTPlotComponent::~FFTPlotComponent() {}
@@ -122,7 +121,7 @@ void FFTPlotComponent::selectChannel(ChannelComponent *ch)
122121
disconnect(m_activeChannel, &ChannelComponent::nameChanged, nullptr, nullptr);
123122

124123
m_activeChannel = ch;
125-
m_waterfallPlot->clearData();
124+
m_waterfallPlot->setChannel(ch ? ch->chData() : nullptr);
126125

127126
if(ch) {
128127
m_waterfallDockWrapper->setTitle("Waterfall Plot - " + ch->name());
@@ -139,6 +138,8 @@ void FFTPlotComponent::addChannel(ChannelComponent *c)
139138

140139
void FFTPlotComponent::removeChannel(ChannelComponent *c)
141140
{
141+
if(c == m_activeChannel)
142+
selectChannel(nullptr);
142143
PlotComponent::removeChannel(c);
143144
m_plotMenu->removeChannel(c);
144145
}

packages/generic-plugins/plugins/adc/src/freq/fftplotcomponentchannel.cpp

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,13 @@
2020
*/
2121

2222
#include "fftplotcomponentchannel.h"
23-
#include <gui/waterfallplotwidget.h>
2423
#include <minmaxholdcontroller.hpp>
2524
#include <pluginbase/preferences.h>
2625
#include <widgets/menucollapsesection.h>
2726
#include <widgets/menuplotaxisrangecontrol.h>
2827
#include <widgets/menuplotchannelcurvestylecontrol.h>
2928
#include <widgets/menusectionwidget.h>
3029

31-
#include <vector>
32-
3330
using namespace scopy;
3431
using namespace adc;
3532

@@ -139,17 +136,6 @@ void FFTPlotComponentChannel::onNewData(const float *xData_, const float *yData_
139136

140137
m_minMaxHoldController->update(xData_, yData_, size);
141138
m_markerController->computeMarkers();
142-
143-
// Feed waterfall if this channel is the active one
144-
if(m_plotComponent && m_plotComponent->activeChannel() == m_ch) {
145-
WaterfallPlotWidget *wf = m_plotComponent->waterfallPlot();
146-
std::vector<double> buf(size);
147-
for(size_t i = 0; i < size; ++i) {
148-
buf[i] = static_cast<double>(yData_[i]);
149-
}
150-
wf->addFFTData(buf.data(), size);
151-
wf->replot();
152-
}
153139
}
154140

155141
void FFTPlotComponentChannel::lockYAxis(bool b)

0 commit comments

Comments
 (0)