Results 1 to 2 of 2

Thread: QwtSpectrogram, don't draw from scratch

  1. #1
    Join Date
    Jul 2017
    Posts
    7
    Thanks
    5
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default QwtSpectrogram, don't draw from scratch

    I want to draw a spectrogram periodically, which means that data come over time, and i just want to add columns to the previous graph (see photo).

    What i did is to declare a
    Qt Code:
    1. QwtPlotSpectrogram * spectrogram
    To copy to clipboard, switch view to plain text mode 
    instance, and i use the setData() function where i pass a SpectrogramData instance:

    Qt Code:
    1. class SpectrogramData : public QwtRasterData {
    2.  
    3. private:
    4. std::vector<std::vector<double>> data;
    5.  
    6. public:
    7. SpectrogramData(int height, int width);
    8.  
    9. ~SpectrogramData();
    10.  
    11. virtual double value(double x, double y) const;
    12. };
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. spectrogram->setData(spectrogram_data);
    To copy to clipboard, switch view to plain text mode 

    When new data come, i add them to the data structure, and call replot() in the QwtPlot instance that the QwtSpectrogram is attached to.

    Because the spectrogram will ultimately have about 700*22000 size, i don't know what replot() does. Is there a way to tell qwt to only plot a certain column of data or region or rectangular or something in the spectrogram?
    Attached Images Attached Images
    Last edited by kkaz; 31st July 2017 at 09:19.

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

    Default Re: QwtSpectrogram, don't draw from scratch

    Quote Originally Posted by kkaz View Post
    When new data come, i add them to the data structure, and call replot() in the QwtPlot instance that the QwtSpectrogram is attached to.
    In case you are changing your vector behind the back of the item ( = no setData ) you might also have to invalidate the paint cache of the item manually.

    Because the spectrogram will ultimately have about 700*22000 size, i don't know what replot() does.
    The spectrogram iterates over the pixels in a resolution, that corresponds to the minimum of screen/data. Assuming a situation, where the plot canvas has a size of 1000x1000 it would be 700x1000.

    It is the job of the value() method to do the resampling. The fastest but simplest algo is called nearest neighbour, what simply rounds the requested position to the closest existing one. But you could also use more advanced algos like bilinear interpolation, what is implemented in QwtPlotMatrixData. But be careful with your implementation - value() is called for each pixel and needs to be implemented quite performantly.
    Is there a way to tell qwt to only plot a certain column of data or region or rectangular or something in the spectrogram?
    This is one of the most relevant features, that are missing in Qwt. But it is usually only important, when you need high refresh rates ( several replots per second ). Often it is good enough to decouple the rate of the incoming data from the update rate using a timer.

    I recommend to play with the spectrogram example first to find out if full replots are fast enough for your situation. Only if not it is worth to spend some time with shifting columns in the paint cache and repainting only parts of it. If you really have to go this way you should consider to flip the x/y axes because a QImage internally is stored as a sequence of rows and you can shift by memcpy.

    Uwe

Similar Threads

  1. How to adddata for qwtspectrogram
    By centroid in forum Qwt
    Replies: 2
    Last Post: 2nd August 2010, 14:36
  2. Getting started from scratch
    By hyde in forum Newbie
    Replies: 1
    Last Post: 11th December 2008, 15:22
  3. Replies: 0
    Last Post: 28th August 2008, 15:49
  4. QwtSpectrogram example program
    By cgifford in forum Qwt
    Replies: 3
    Last Post: 2nd July 2008, 07:46

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.