Results 1 to 4 of 4

Thread: QwtRasterData and non-linearly sampled data

  1. #1

    Default QwtRasterData and non-linearly sampled data

    Hello. I want some suggestions on how to my code a bit more versatile. I altered the SpectrogramData example for a discrete series of XYZ data simply by coupling the x and y to the discrete values of my Data->ZData vector.
    Qt Code:
    1. class SpectrogramData: public QwtRasterData
    2. {
    3. public:
    4. ...
    5. virtual double value(double x, double y) const
    6. {
    7. double dx, dy;
    8. dx = (Data->Xdata.last()-Data->Xdata.first())/(Data->Xdata.size()-1);
    9. dy = (Data->Ydata.last()-Data->Ydata.first())/(Data->Ydata.size()-1);
    10. int i = (x-Data->Xdata.first())/dx, j = (y-Data->Ydata.first())/dy;
    11. return Data->Zdata[j][i];
    12. }
    13. ...
    14. }
    To copy to clipboard, switch view to plain text mode 
    This type of resampling works well if I am operating with linearly sampled data (XData and YData are equidistant). How can I improve this algorithm for a series of non-linearly scaled data (i.e. XData = [1 10 20 50 70 100 1000])?

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

    Default Re: QwtRasterData and non-linearly sampled data

    Quote Originally Posted by DizzyMoods View Post
    This type of resampling works well if I am operating with linearly sampled data (XData and YData are equidistant.
    One comment on your code: Spectrogram::value is called very often ( for each pixel ! ) and you should try to implement it as fast as possible. Better calculate dx and dy once instead of recalculating it again and again.

    Quote Originally Posted by DizzyMoods View Post
    How can I improve this algorithm for a series of non-linearly scaled data (i.e. XData = [1 10 20 50 70 100 1000])?
    Your code implements a nearest neighbor resampling. You can do the same for XData - beside the algorithm how to identify the next neighbor is different.

    Again you should be aware of the fact, that Spectrogram::value is called very often and heavy calculations shouldn't be avoided if possible. F.e. you could overload QwtRasterData::initRaster() and QwtRasterData::discardRaster() to initialize some values, that are constant for the situation - or build a temporary linear value matrix.

    Uwe

  3. #3

    Default Re: QwtRasterData and non-linearly sampled data

    Thanks, Uwe.
    Now I have some question about the initraster() function. Should I reimplement the whole function (similar to value) or should I just call it with particular QRectF and QSize values? This is my rendition SpectrogramData:
    Qt Code:
    1. class SpectrogramData: public QwtRasterData
    2. {
    3. public:
    4. SpectrumData *Data;
    5. double dx, dy;
    6. SpectrogramData(SpectrumData *InputData)
    7. {
    8. Data = InputData;
    9. setInterval( Qt::XAxis, QwtInterval( Data->.first(), Data->XData.last() ) );
    10. setInterval( Qt::YAxis, QwtInterval( Data->YData.first(), Data->YData.last() ) );
    11. setInterval( Qt::ZAxis, QwtInterval( Data->MinZ, Data->MaxZ ) );
    12. dx = (Data->XData.last()-Data->XData.first())/(Data->XData.size()-1);
    13. dy = (Data->YData.last()-Data->YData.first())/(Data->YData.size()-1);
    14. }
    15.  
    16. virtual double value(double x, double y) const
    17. {
    18. int i = (x-Data->XData.first())/dx, j = (y-Data->YData.first())/dy;
    19. return Data->ZData[j][i];
    20. }
    21. }
    To copy to clipboard, switch view to plain text mode 
    I tried to experiment with your suggestion and added these lines to the end of the constructor (lines 14+):
    Qt Code:
    1. QSize QS(Data->LengthOfX,Data->LengthOfY);
    2. QRectF QR(0,0,500,500); // Some random numbers to initialize QRectF
    3. initRaster(QR,QS);
    To copy to clipboard, switch view to plain text mode 
    but this implementation doesn't seem to yield any difference. Could you elaborate a bit more on initraster()? I searched this forum, but I can't find a good example of its usage.
    Thanks in advance.

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

    Default Re: QwtRasterData and non-linearly sampled data

    No you don't have to call initRaster - you have to implement it ( like the value method ) !

    The raster data object gets initialized by the spectrogram item each time before the image composition gets started. F.e. when you have a huge amount of data ( think of GIS data like the elevation for Canada every 10x10m ) you simply can't have the complete raster in memory. Here an implementation of ElevationData::initRaster would load the values for the requested tile from disk into a 2D matrix.

    Your implemention of SpectrogramData::initRaster knows about the raster ( bounding rectangle and the size of the data pixels ) in advance and you could build a matrix ( resample your ~logarithmic matrix ) so, that you can have fast lookups in SpectrogramData::value().

    But this all doesn't change the fact that you have to implement the resampling in your code.

    Uwe

Similar Threads

  1. Replies: 8
    Last Post: 2nd November 2011, 16:31
  2. Replies: 0
    Last Post: 10th September 2011, 13:38
  3. QwtRasterData and values
    By DKL1972 in forum Qwt
    Replies: 12
    Last Post: 10th March 2010, 09:53
  4. Convert QwtRasterData to QwtSeriesData
    By bigjoeystud in forum Qwt
    Replies: 3
    Last Post: 25th August 2009, 15:06
  5. Corrupt JPEG data: premature end of data segment
    By node_ex in forum Qt Programming
    Replies: 1
    Last Post: 19th August 2008, 08:57

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.