Results 1 to 5 of 5

Thread: How to implement an "adaptive" pixelHint for Spectrogram?

  1. #1
    Join Date
    Mar 2012
    Posts
    16
    Thanks
    15
    Qt products
    Qt4
    Platforms
    Windows

    Default How to implement an "adaptive" pixelHint for Spectrogram?

    Hi,

    Say I have 2D data array (x*y) = (2000*2000) in QwtMatrixRasterData with setInterval( Qt::XAxis, QwtInterval( 0, 2000, QwtInterval::ExcludeMaximum)) and same for YAxis.

    When the ResampleMode == NearestNeighbour (default) in QwtMatrixRasterData, then the default QwtMatrixRasterData:ixelHint is returning :

    rect = QRectF( intervalX.minValue(), intervalY.minValue(), d_data->dx, d_data->dy );

    #1. If I zoom in a lot and want to display in plot coordinate the part (X,Y,W,H)= (500,500,3,3), this will have the nice effect of calling QwtMatrixRasterData::value( double x, double y ) only 9 times (from what I understand) independently of the image size displayed on screen. Thus initRaster would return me area x=500 y=500 w=3 h=3 and imgSize w=3 h=3. Perfect.

    #2. Now if I zoom out a lot, to display the whole 2D array i.e in plot coordinate the part (X,Y,W,H)= (0,0,2000,2000), on a very small rendered screen area that is say only 20 pixels by 20 pixels, the rendering will happen in 2000x2000 instead of 20 by 20 pixels, because pixelHint is not set to render in target device ( f.e. screen ) resolution. This is normal. That means that initRaster would return area x=0 y=0 w=2000 h=2000 and imgSize w=2000 h=2000. The lag will be terrible.

    The question is, when I fall in case #2 when I zoom out a lot, (so when the screen resolution is smaller than the area resolution to be displayed) then I want to change pixelHint and set it to null so it renders in screen resolution. What would be a proper implementation of PixelHint in this case? Note that always configuring PixelHint in screen resolution (null QRectF) would have the exact opposite behavior of rendering only a few pixels when we zoom out a lot but rendering all the pixels if we zoom in a lot even to display an area of 1 by 1 in plot coordinate (which makes no sense if we are in NearestNeighbour mode). So this has to be an adaptive PixelHint.

    A partial answer to this issue is that I guess we'd need to know the size of the image in screen resolution in pixelHint and compare it against the area covered in plot coordinate, and then set pixelHint to null when the (area width in plot coordinate is > screen resolution width) && (area height in plot coordinate is > screen resolution height ) ?

    Thanks!

    M.Klein

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

    Default Re: How to implement an "adaptive" pixelHint for Spectrogram?

    Quote Originally Posted by MattK View Post
    #2. Now if I zoom out a lot, to display the whole 2D array i.e in plot coordinate the part (X,Y,W,H)= (0,0,2000,2000), on a very small rendered screen area that is say only 20 pixels by 20 pixels, the rendering will happen in 2000x2000 instead of 20 by 20 pixels, because pixelHint is not set to render in target device ( f.e. screen ) resolution. This is normal.
    No it isn't - rendering should be in target device resolution then !
    Check the code in QwtPlotRasterItem::draw, what goes wrong in your situation.

    Uwe

  3. #3
    Join Date
    Mar 2012
    Posts
    16
    Thanks
    15
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to implement an "adaptive" pixelHint for Spectrogram?

    Thanks for your previous answer! Interesting. I see why you say
    rendering should be in target device resolution then
    since QwtPlotRasterItem::draw is normally forcing the pixelHint to be NULL within this function when "the resolution of the data pixels is higher than the resolution of the target device we render in target device resolution."

    I don't see any flaw in your code, yet QwtPlotRasterItem::draw is not able to detect the following situation: from your spectrogram example, change
    Qt Code:
    1. in class SpectrogramData: public QwtRasterData
    2.  
    3. setInterval( Qt::XAxis, QwtInterval( -1.5, 1.5 ) );
    4. setInterval( Qt::YAxis, QwtInterval( -1.5, 1.5 ) );
    5.  
    6. to
    7.  
    8. setInterval( Qt::XAxis, QwtInterval( -1500, 1500 ) );
    9. setInterval( Qt::YAxis, QwtInterval( -1500, 1500 ) );
    10.  
    11. then add
    12.  
    13. QRectF pixelHint( const QRectF &) const
    14. {
    15. QRectF rect(0,0,1,1);
    16. return rect;
    17. }
    To copy to clipboard, switch view to plain text mode 

    This PixelHint is appropriate for a matrix of course... so it makes little sense in this example, but it doesn't matter. What's interesting here is that, once you run this example with the modifications, it's almost impossible to resize the window when you run it, because it rending a 3000 x 3000 matrix in a window that is much smaller. Even if you resize the window to a very small size of say 50x50 pixels, it will still lag a lot... Changing the pixelHint to NULL so that the rendering is done to the screen resolution does solve the issue. This shows that QwtPlotRasterItem::draw is not able to detect that the screen resolution is smaller than the "data"pixel resolution in this case.

    Maybe this is done purposely? This can have an interest for example when exporting to a printer or an tiff image. But in this case, how to keep a pixelHint such as QRectF rect(0,0,1,1); and keeping the resolution of the data pixel equal or lower than the target device (I mean without hacking the code source of Qwt)? :-)
    Last edited by MattK; 10th April 2012 at 05:53. Reason: made a much simpler post

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

    Default Re: How to implement an "adaptive" pixelHint for Spectrogram?

    I checked your code and indeed there is a bug in QwtPlotRasterItem: to compare the pixelHint with a pixel in target device resolution it translates a dummy rectangle ( 0, 0, 1, 1 ) into scale coordinates. But QwtScaleMap::invTransform() always subtracts 1 pixel ( this is how QRectF is defined ) so that the result is always an empty rectangle.

    Fixed in SVN ( trunk + 6.0 branch ).

    Uwe

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

    MattK (17th April 2012)

  6. #5
    Join Date
    Mar 2012
    Posts
    16
    Thanks
    15
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to implement an "adaptive" pixelHint for Spectrogram?

    I can see your fix at http://qwt.svn.sourceforge.net/viewv...66&sortby=date
    It's not trivial to the novice, I would have not been able to fix it myself properly in a reasonable amount of time. You're the King, thanks a lot - hence the 50 bucks donated a few weeks ago through Paypal from my company.

Similar Threads

  1. Reusing the same widget to implement "split-screen"
    By thomab in forum Qt Programming
    Replies: 3
    Last Post: 29th January 2011, 15:57
  2. How can i implement "Undo" action?
    By suseway in forum Qt Programming
    Replies: 1
    Last Post: 29th October 2010, 11:32
  3. Replies: 1
    Last Post: 15th June 2009, 17:28
  4. [QT3] Implement "Freeze Panes" features in QListView
    By Syphius in forum Qt Programming
    Replies: 7
    Last Post: 5th January 2009, 21:25
  5. Translation QFileDialog standart buttons ("Open"/"Save"/"Cancel")
    By victor.yacovlev in forum Qt Programming
    Replies: 4
    Last Post: 24th January 2008, 19:05

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.