Results 1 to 9 of 9

Thread: Nonuniform raster data resampler for QwtPlotSpectrogram (Qwt 5.2)

  1. #1
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,346
    Qt products
    Qt5
    Platforms
    Windows
    Thanks
    318
    Thanked 872 Times in 859 Posts

    Default Re: Nonuniform raster data resampler for QwtPlotSpectrogram (Qwt 5.2)

    I have developed a set of classes for use with QwtPlotSpectrogram that permits the ability to display an x, y array of data that has nonuniform spacing. QwtRasterData expects a uniformly-spaced array, whereas often real-world x,y data is sampled at varying intervals.

    This code uses a technique called "Gaussian splatting" to resample the non-uniform point array onto a uniformly-spaced grid. The technique can be thought of like throwing a snowball against a hard wall. The harder you throw it, the wider the "splat" it makes. In the Gaussian splatting method, the points are thrown against the uniform grid, and the intensity (z value) is sampled in a circular region around each point. There are two parameters: sigma, which is a measure of how hard the point is "thrown" onto the grid; and threshold, which controls how low the z-value is sampled before the algorithm stops expanding the circle. Small sigma means the image remains point-like, larger sigma smears the points out and sums up any overlap among the circles. The GaussianResampler class does this.

    The NonuniformRasterData class is derived from QwtRasterData, and uses the Gaussian resampler. It sets a default grid size of 1000 x 1000 pixels, but this can be adjusted. It uses bilinear interpolation to return interpolated z values from the uniform grid.

    I have developed and tested the code in the attached zip file against Qwt 5.2. It is not yet working with Qwt 6.x - for some reason the image does not appear, so I will have to investigate that and repost the code once I have it fixed.

    The attached ZIP file contains the source code along with .pro and .pri files. Please note that I use Qwt as a static library and I rename it to qwt5.lib, so you will probably have to edit the .pro file to get it working for you.

    The attached images show some of the plots it generates. The "+" symbols in some plots mark the locations of the original data points. Constructive feedback is always appreciated.

    This code is released under the terms of the Qwt License, Version 1.0.

    GaussianSplatter.zip

    Image1.jpg

    Image2.jpg

    Image3.jpg

    Image4.jpg


    Added after 38 minutes:


    I now have this working with Qwt 6.0. Please use the code in the attached zip file, which should be compatible with both Qwt 5.2 and Qwt 6.0.

    GaussianSplatter_6_0_Update.zip
    Last edited by d_stranz; 31st March 2012 at 22:37.

  2. The following 2 users say thank you to d_stranz for this useful post:

    Foul Ole Ron (23rd February 2016), pabose (7th January 2013)

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

    Default Re: Nonuniform raster data resampler for QwtPlotSpectrogram (Qwt 5.2)

    Quote Originally Posted by d_stranz View Post
    The NonuniformRasterData class is derived from QwtRasterData, and uses the Gaussian resampler. It sets a default grid size of 1000 x 1000 pixels, but this can be adjusted. It uses bilinear interpolation to return interpolated z values from the uniform grid.
    I'm not sure if resampling from non uniform raster data to a matrix has to be done more than once ?


    • If not you could convert your data into a matrix and use QwtPlotMatrixData then.
    • If true you could calculate the matrix by your resampler in YourRasterData::initRaster() and then use one of the implemented resampling algos ( well, there are no so many today ). In such an implementation resampling would be done twice for each image, but the expensive one in your resampler would be much faster as you could process all your values in one loop instead of the overhead you have from the point by point resampling of the spectrogram framework.


    Uwe

  4. #3
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,346
    Qt products
    Qt5
    Platforms
    Windows
    Thanks
    318
    Thanked 872 Times in 859 Posts

    Default Re: Nonuniform raster data resampler for QwtPlotSpectrogram (Qwt 5.2)

    I'm not sure if resampling from non uniform raster data to a matrix has to be done more than once ?
    The resampling from the point cloud (the non-uniform raster data) is done only once, in the "splatting" operation. This is dependent only on the size of the resampling grid held by the NonuniformRasterData class, not the screen pixel dimensions.

    Imagine the resampling grid as a window screen attached to a flat board (so nothing can go through it). Each original data point is a rotten tomato, and each one has a different size. Throw each tomato at the screen with the same force. Depending on the size of the tomato, it makes a bigger or smaller "splat". When you have thrown all of the tomatoes, examine the screen. At each grid crossing in the screen, measure the thickness of the tomato mush. These are the new z-values for the screen grid (x,y) positions used in the NonuniformRasterData (derived from QwtRasterData) class.

    The second step is what now happens in Qwt 6's QwtMatrixRasterData, the bilinear interpolation from resampling grid point to screen pixel. In Qwt 5.2, this class does not exist, so that is what my NonuniformRasterData class does. It just combines the two operations of resampling and interpolation. As you suggest, in Qwt 6, I could separate the GaussianResampler and replace the NonuniformRasterData class with QwtMatrixRasterData, using the resampled grid as its input. Good idea, and I will implement that.

    David

  5. #4
    Join Date
    Jul 2020
    Posts
    6
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Nonuniform raster data resampler for QwtPlotSpectrogram (Qwt 5.2)

    I know this probably counts as "necro posting", but nonetheless:

    I downloaded the zip file targetted to Qwt6. I am trying to use it with Qwt 6.3 and it doesn't seem to want to play.

    Is there a newer version that will work with Qwt 6.3.0?

    Is there any other code that allows sparse data to be used with QwtPlotSpectrogram?

    Thanks
    David

  6. #5
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,346
    Qt products
    Qt5
    Platforms
    Windows
    Thanks
    318
    Thanked 872 Times in 859 Posts

    Default Re: Nonuniform raster data resampler for QwtPlotSpectrogram (Qwt 5.2)

    Unfortunately, I stopped using Qwt nearly 10 years ago and have not touched this code since then. I switched over to QCustomPlot, which I find to be easily customized and extended.

    I am trying to use it with Qwt 6.3 and it doesn't seem to want to play.
    In what way? Doesn't compile and link? Doesn't work when executed? I have forgotten most of what I knew about Qwt, so I am afraid I won't be of much help.

    As an alternative to the Gaussian splatting, you might look into bilinear interpolation. Those algorithms are pretty easy to implement. Like this code, you could optimize it so that the interpolation is done only once each time the window is resized, into a fixed size array suitable for use with QwtPlotSpectrogram. If the data are really sparse, this can generate some weird gradient effects due to the interpolation, so like the Gaussian splatting, you could impose a "gravity" field around each point so that point's color (or opacity) gradually fades away into background at a certain distance.
    Last edited by d_stranz; 14th November 2025 at 17:45.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  7. #6
    Join Date
    Jul 2020
    Posts
    6
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Nonuniform raster data resampler for QwtPlotSpectrogram (Qwt 5.2)

    I'd happily use QCustomPlot!

    The problem is that your old code won't even compile with Qwt 6.3! Ho-hum. Let me be clear I'm dealing with very sparse data so I have perhaps only 100 to 150 data points in a 5202x3464 array.

    If you have something that I can use with QCustomPlot that will do what this did with Qwt ...

    Thanks David

  8. #7
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,346
    Qt products
    Qt5
    Platforms
    Windows
    Thanks
    318
    Thanked 872 Times in 859 Posts

    Default Re: Nonuniform raster data resampler for QwtPlotSpectrogram (Qwt 5.2)

    If I can find time, I will look at the original code to see if it can be ported to QCustomPlot. Quite honestly, I don't remember much about it
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  9. #8
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,326
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows
    Thanked 880 Times in 828 Posts

    Default Re: Nonuniform raster data resampler for QwtPlotSpectrogram (Qwt 5.2)

    QwtMatrixRasterData is a convenience API for uniform data - if your data is non uniform use QwtRasterData ( its base class ).

    Qt Code:
    1. class YourRasterData : public QwtRasterData
    2. {
    3. public:
    4. QwtInterval interval( Qt::Axis ) const override
    5. {
    6. // return x/y/z boundaries of your data
    7. }
    8.  
    9. double value( double x, double y ) const override
    10. {
    11. // return the value at a specific plot coordinate
    12. }
    13. };
    To copy to clipboard, switch view to plain text mode 

    There are a few more methods you can overload that might improve the performance of renderering - but the 2 above are mandatory.


    Added after 53 minutes:


    For what its worth: attached is Davids code adopted for Qwt 6.3 ( tested with Qt 6.10 ).

    HTH,
    Uwe
    Attached Files Attached Files
    Last edited by Uwe; 17th November 2025 at 08:06.

  10. The following user says thank you to Uwe for this useful post:

    d_stranz (17th November 2025)

  11. #9
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,346
    Qt products
    Qt5
    Platforms
    Windows
    Thanks
    318
    Thanked 872 Times in 859 Posts

    Default Re: Nonuniform raster data resampler for QwtPlotSpectrogram (Qwt 5.2)

    Thanks, Uwe. If @perdrix can use this, I'll defer looking into it.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Replies: 0
    Last Post: 17th November 2011, 17:44
  2. Replies: 1
    Last Post: 15th November 2010, 23:46
  3. Plot Raster chart background
    By jmsbc in forum Qwt
    Replies: 3
    Last Post: 8th August 2010, 20:56
  4. Native vs Raster
    By ArlexBee-871RBO in forum Qt Programming
    Replies: 7
    Last Post: 15th February 2010, 23:22
  5. Irregular data and QwtPlotSpectrogram
    By seveninches in forum Qwt
    Replies: 1
    Last Post: 27th January 2008, 11:52

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
  •  
Qt is a trademark of The Qt Company.