I implemented an example based on the 'spectrogram' example by exchanging the 'SpectrogramData' class with the build in 'QwtMatrixRasterData' class.
The problem is that the data is not shown and the plot remains empty. I would like to know what is missing in this code.
#include <qwt_plot.h>
#include <qwt_plot_spectrogram.h>
#include <qwt_matrix_raster_data.h>
{
Q_OBJECT
public:
QMatrixPlot
(QWidget *parent
= NULL);
virtual ~QMatrixPlot()
{
if (d_spectrogram)
delete d_spectrogram;
}
void setMatrixData(const QVector< double > &values, int numColumns);
private:
QwtMatrixRasterData * m_MatrixRasterData;
int d_alpha;
int d_mapType;
};
#include <qwt_plot.h>
#include <qwt_plot_spectrogram.h>
#include <qwt_matrix_raster_data.h>
class QMatrixPlot : public QwtPlot
{
Q_OBJECT
public:
QMatrixPlot(QWidget *parent = NULL);
virtual ~QMatrixPlot()
{
if (d_spectrogram)
delete d_spectrogram;
}
void setMatrixData(const QVector< double > &values, int numColumns);
private:
QwtPlotSpectrogram * d_spectrogram;
QwtMatrixRasterData * m_MatrixRasterData;
int d_alpha;
int d_mapType;
};
To copy to clipboard, switch view to plain text mode
#include "QMatrixPlot.h"
#include "qcolormap.h"
#include "qwt_plot_layout.h"
#include "qwt_scale_widget.h"
QMatrixPlot
::QMatrixPlot(QWidget *parent
): d_alpha(255)
{
d_spectrogram->setRenderThreadCount( 0 ); // use system specific thread count
m_MatrixRasterData = new QwtMatrixRasterData();
d_spectrogram->setData( m_MatrixRasterData );
d_spectrogram->attach( this );
}
void QMatrixPlot::setMatrixData(const QVector< double > &values, int numColumns)
{
m_MatrixRasterData->setValueMatrix (values, numColumns);
const QwtInterval zInterval = d_spectrogram->data()->interval( Qt::ZAxis );
setAxisScale
( QwtPlot::yRight, zInterval.
minValue(), zInterval.
maxValue() );
axis->setColorMap( zInterval, QColorMap::map(d_mapType) );
}
#include "QMatrixPlot.h"
#include "qcolormap.h"
#include "qwt_plot_layout.h"
#include "qwt_scale_widget.h"
QMatrixPlot::QMatrixPlot(QWidget *parent ):
QwtPlot( parent ),
d_alpha(255)
{
d_spectrogram = new QwtPlotSpectrogram();
d_spectrogram->setRenderThreadCount( 0 ); // use system specific thread count
d_spectrogram->setCachePolicy( QwtPlotRasterItem::PaintCache );
m_MatrixRasterData = new QwtMatrixRasterData();
d_spectrogram->setData( m_MatrixRasterData );
d_spectrogram->attach( this );
}
void QMatrixPlot::setMatrixData(const QVector< double > &values, int numColumns)
{
m_MatrixRasterData->setValueMatrix (values, numColumns);
const QwtInterval zInterval = d_spectrogram->data()->interval( Qt::ZAxis );
setAxisScale( QwtPlot::yRight, zInterval.minValue(), zInterval.maxValue() );
QwtScaleWidget *axis = axisWidget( QwtPlot::yRight );
axis->setColorMap( zInterval, QColorMap::map(d_mapType) );
}
To copy to clipboard, switch view to plain text mode
#include <QtWidgets/QApplication>
#include <QtWidgets/QMainWindow>
#include "qmatrixplot.h"
#include <vector>
using std::vector;
int main( int argc, char **argv )
{
QMatrixPlot * plot = new QMatrixPlot();
plot->setTitle( "2D Plot Demo" );
// create data
QVector<double> x(100);
QVector<double> y1(x.size());
for (size_t i = 0; i< x.size(); ++i) { x[i] = int(i)-50; }
for (size_t i = 0; i< y1.size(); ++i) { y1[i] = sin(double(x[i])/10.0); }
plot->setMatrixData(y1, 10);
plot->replot();
window.setCentralWidget(plot);
window.resize(800, 600);
window.show();
return a.exec();
}
#include <QtWidgets/QApplication>
#include <QtWidgets/QMainWindow>
#include "qmatrixplot.h"
#include <vector>
using std::vector;
int main( int argc, char **argv )
{
QApplication a( argc, argv );
QMatrixPlot * plot = new QMatrixPlot();
plot->setTitle( "2D Plot Demo" );
// create data
QVector<double> x(100);
QVector<double> y1(x.size());
for (size_t i = 0; i< x.size(); ++i) { x[i] = int(i)-50; }
for (size_t i = 0; i< y1.size(); ++i) { y1[i] = sin(double(x[i])/10.0); }
plot->setMatrixData(y1, 10);
plot->replot();
QMainWindow window;
window.setCentralWidget(plot);
window.resize(800, 600);
window.show();
return a.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks