Created
July 3, 2020 17:04
-
-
Save wspeirs/c2c5e6832df1e6bb1186384f8d660c2b to your computer and use it in GitHub Desktop.
Waterfall from QwtPlotSpectrogram
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <qwt_color_map.h> | |
#include <qwt_matrix_raster_data.h> | |
#include <boost/circular_buffer.hpp> | |
#include <QtCore/QMutex> | |
#include "waterfall.h" | |
using boost::circular_buffer; | |
using std::make_shared; | |
class SpectrogramData: public QwtRasterData | |
{ | |
public: | |
SpectrogramData() | |
{ | |
auto blank_row = make_shared<vector<double>>(2205); | |
rows = circular_buffer<shared_ptr<vector<double>>>(1000, blank_row); | |
} | |
double value(double x, double y) const override { | |
// qDebug(GUI) << x << ", " << y; | |
auto ret = rows.at(y)->at(x); | |
return ret; | |
} | |
void add_row(shared_ptr<vector<double>> row) { | |
qDebug(GUI) << "ADD ROW"; | |
rows.pop_front(); // remove the last row | |
rows.push_back(row); // insert the new row | |
} | |
private: | |
circular_buffer<shared_ptr<vector<double>>> rows; | |
}; | |
class LinearColorMapRGB: public QwtLinearColorMap | |
{ | |
public: | |
LinearColorMapRGB() : QwtLinearColorMap( Qt::darkBlue, Qt::red, QwtColorMap::RGB ) | |
{ | |
// set colors on gradient from darkBlue -> red | |
addColorStop( 0.05, Qt::blue ); | |
addColorStop( 0.25, Qt::green ); | |
addColorStop( 0.50, Qt::yellow ); | |
} | |
}; | |
Waterfall::Waterfall(QWidget *parent) : | |
QwtPlot(parent), | |
spectrogram(new QwtPlotSpectrogram()) | |
{ | |
spectrogram->setRenderThreadCount( 0 ); // use system specific thread count | |
spectrogram->setCachePolicy(QwtPlotRasterItem::NoCache); // won't update the display if we have a cache | |
auto data = new SpectrogramData(); | |
data->setInterval(Qt::XAxis, QwtInterval( 0.0, 2204.0 )); // frequency | |
data->setInterval( Qt::YAxis, QwtInterval( 0.0, 999.0 ) ); // time | |
data->setInterval( Qt::ZAxis, QwtInterval( 0.0, 100.0 ) ); // intensity | |
this->setAxisScale(QwtPlot::yLeft, 0.0, 999.0); | |
this->setAxisScale(QwtPlot::xBottom, 0.0, 2204.0); | |
spectrogram->setData(data); | |
spectrogram->attach(this); | |
spectrogram->setColorMap(new LinearColorMapRGB()); | |
} | |
void Waterfall::add_row(shared_ptr<vector<double>> row) { | |
reinterpret_cast<SpectrogramData*>(spectrogram->data())->add_row(row); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment