Results 1 to 3 of 3

Thread: How to implement QwtPlotSpectrogram with QwtMatrixRasterData

  1. #1
    Join Date
    Feb 2008
    Posts
    157
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default How to implement QwtPlotSpectrogram with QwtMatrixRasterData

    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.

    Qt Code:
    1. #include <qwt_plot.h>
    2.  
    3. #include <qwt_plot_spectrogram.h>
    4. #include <qwt_matrix_raster_data.h>
    5.  
    6.  
    7. class QMatrixPlot : public QwtPlot
    8. {
    9. Q_OBJECT
    10. public:
    11. QMatrixPlot(QWidget *parent = NULL);
    12. virtual ~QMatrixPlot()
    13. {
    14. if (d_spectrogram)
    15. delete d_spectrogram;
    16. }
    17.  
    18. void setMatrixData(const QVector< double > &values, int numColumns);
    19.  
    20. private:
    21. QwtPlotSpectrogram * d_spectrogram;
    22. QwtMatrixRasterData * m_MatrixRasterData;
    23.  
    24. int d_alpha;
    25. int d_mapType;
    26.  
    27. };
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #include "QMatrixPlot.h"
    2. #include "qcolormap.h"
    3. #include "qwt_plot_layout.h"
    4. #include "qwt_scale_widget.h"
    5.  
    6. QMatrixPlot::QMatrixPlot(QWidget *parent ):
    7. QwtPlot( parent ),
    8. d_alpha(255)
    9. {
    10.  
    11. d_spectrogram = new QwtPlotSpectrogram();
    12. d_spectrogram->setRenderThreadCount( 0 ); // use system specific thread count
    13. d_spectrogram->setCachePolicy( QwtPlotRasterItem::PaintCache );
    14.  
    15. m_MatrixRasterData = new QwtMatrixRasterData();
    16. d_spectrogram->setData( m_MatrixRasterData );
    17. d_spectrogram->attach( this );
    18.  
    19. }
    20.  
    21. void QMatrixPlot::setMatrixData(const QVector< double > &values, int numColumns)
    22. {
    23. m_MatrixRasterData->setValueMatrix (values, numColumns);
    24.  
    25. const QwtInterval zInterval = d_spectrogram->data()->interval( Qt::ZAxis );
    26. setAxisScale( QwtPlot::yRight, zInterval.minValue(), zInterval.maxValue() );
    27.  
    28. QwtScaleWidget *axis = axisWidget( QwtPlot::yRight );
    29. axis->setColorMap( zInterval, QColorMap::map(d_mapType) );
    30. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #include <QtWidgets/QApplication>
    2. #include <QtWidgets/QMainWindow>
    3.  
    4. #include "qmatrixplot.h"
    5.  
    6. #include <vector>
    7. using std::vector;
    8.  
    9. int main( int argc, char **argv )
    10. {
    11. QApplication a( argc, argv );
    12.  
    13. QMatrixPlot * plot = new QMatrixPlot();
    14. plot->setTitle( "2D Plot Demo" );
    15.  
    16. // create data
    17. QVector<double> x(100);
    18. QVector<double> y1(x.size());
    19.  
    20. for (size_t i = 0; i< x.size(); ++i) { x[i] = int(i)-50; }
    21. for (size_t i = 0; i< y1.size(); ++i) { y1[i] = sin(double(x[i])/10.0); }
    22.  
    23. plot->setMatrixData(y1, 10);
    24. plot->replot();
    25.  
    26. QMainWindow window;
    27. window.setCentralWidget(plot);
    28. window.resize(800, 600);
    29. window.show();
    30.  
    31. return a.exec();
    32. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Feb 2008
    Posts
    157
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to implement QwtPlotSpectrogram with QwtMatrixRasterData

    It seems as if the intervall for all axis (x, y, z) must be set:

    Qt Code:
    1. void QMatrixPlot::setMatrixData(const QVector< double > &values, int numColumns)
    2. {
    3. size_t rows = values.size()/numColumns;
    4. m_MatrixRasterData->setInterval( Qt::XAxis, QwtInterval( 0, numColumns ) );
    5. m_MatrixRasterData->setInterval( Qt::YAxis, QwtInterval( 0, rows ) );
    6.  
    7. double minValue = *std::min_element( std::begin(values), std::end(values) );
    8. double maxValue = *std::max_element( std::begin(values), std::end(values) );
    9. m_MatrixRasterData->setInterval( Qt::ZAxis, QwtInterval(minValue, maxValue) );
    10.  
    11. m_MatrixRasterData->setValueMatrix (values, numColumns);
    12. d_spectrogram->setData( m_MatrixRasterData );
    13.  
    14. const QwtInterval zInterval = d_spectrogram->data()->interval( Qt::ZAxis );
    15. setAxisScale( QwtPlot::yRight, zInterval.minValue(), zInterval.maxValue() );
    16.  
    17. QwtScaleWidget *axis = axisWidget( QwtPlot::yRight );
    18. axis->setColorMap( zInterval, QColorMap::map(d_mapType) );
    19. }
    To copy to clipboard, switch view to plain text mode 

    However since QwtMatrixRasterData is to my understanding supposed to be a complete class, I do not understand why this is not implemented within setData.
    The other thing I do not understand is why the QwtPlotSpectrogram needs a new QwtMatrixRasterData pointer for every new data. Why is this not attached
    and a signal used?

  3. #3
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,311
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to implement QwtPlotSpectrogram with QwtMatrixRasterData

    Quote Originally Posted by pospiech View Post
    However since QwtMatrixRasterData is to my understanding supposed to be a complete class, I do not understand why this is not implemented within setData.
    It is a convenience class, but in the majority of the use cases copying values into a matrix is not the best approach. In fact I would say in about 90% of my own use cases I implemented an individual type of bridge between the data and the plot ( = QwtRasterData ) tailored for the specific situation of the application.

    Always keep in mind, that we are talking about potentially tera bytes of data, or the other way round no data at all - like in the spectrogram example.

    Uwe

Similar Threads

  1. Replies: 5
    Last Post: 9th March 2013, 13:25
  2. Replies: 3
    Last Post: 11th July 2012, 06:56
  3. Replies: 8
    Last Post: 2nd November 2011, 16:31
  4. Replies: 13
    Last Post: 22nd August 2011, 20:12
  5. Bugs in QwtMatrixRasterData?
    By alex_sh in forum Qwt
    Replies: 13
    Last Post: 23rd January 2011, 11:59

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.