6 Attachment(s)
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.
Attachment 7545
Attachment 7546
Attachment 7547
Attachment 7548
Attachment 7549
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.
Attachment 7550
Re: Nonuniform raster data resampler for QwtPlotSpectrogram (Qwt 5.2)
Quote:
Originally Posted by
d_stranz
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
Re: Nonuniform raster data resampler for QwtPlotSpectrogram (Qwt 5.2)
Quote:
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