Results 1 to 7 of 7

Thread: transparency in colormap, still don't get it!

  1. #1
    Join Date
    Jul 2009
    Posts
    92
    Thanks
    7
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default transparency in colormap, still don't get it!

    Sorry, I have asked this before but still don't get it!
    I have a two layer GIS type application, with a QwtPlot and 2 Spectrograms:
    the bottom one is a grey scale shaded relief map, opaque, the top shows water flow. In the top spectrogram the value 0 needs to be transparent, anything > 0 needs to get a blue color. The color map is:
    Qt Code:
    1. class colorMapWater: public QwtLinearColorMap
    2. {
    3. public:
    4. colorMapWater():
    5. QwtLinearColorMap( QColor(BGc), Qt::darkBlue )
    6. {
    7. addColorStop( 0.0, qRgba(0, 0, 0, 0));// or Qt::transparent);
    8. addColorStop( 0.1, QColor("#FFFF55") );
    9. addColorStop( 0.4, QColor("#8080FF") );
    10. addColorStop( 0.9, Qt::blue );
    11. }
    12. };
    To copy to clipboard, switch view to plain text mode 
    the function to show the top (water) map is as follows.
    Qt Code:
    1. // fill QwtMatrixRasterData RD with matrix data from Map and find the new max value
    2. // also sets interval for x and y axis
    3. double MaxV = fillDrawMapData(Map, RD);
    4.  
    5. // set the interval to the new max value
    6. maxAxis2 = qMax(maxAxis2, MaxV);
    7. RD->setInterval( Qt::ZAxis, QwtInterval( 0, maxAxis2));
    8.  
    9. //drawMap is a QwtPlotSpectrogram
    10. drawMap->setData(RD);
    11. drawMap->setColorMap(new colorMapWater());
    12.  
    13. // set the right axis legend to the new interval
    14. rightAxis->setColorMap( drawMap->data()->interval( Qt::ZAxis ), new colorMapWater());
    15. MPlot->setAxisScale( MPlot->yRight, 0, maxAxis2);
    16. MPlot->setAxisScaleEngine( MPlot->yRight, new QwtLinearScaleEngine() );
    17. MPlot->replot();
    To copy to clipboard, switch view to plain text mode 
    In my thinking this should produce a plot where all values in RD that are zero should be transparent. I can also setAlpha and that works, the bottom layers is visible. However this producs differences in hue of the water layer that are interpreted wrongly (e.g. darker blue can be a dark bottom layer or deeper water) which is not what I want.
    Thanks!
    Last edited by qt_gotcha; 26th January 2013 at 13:16.

  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: transparency in colormap, still don't get it!

    addColorStop( 0.0, qRgba(0, 0, 0, 0));// or Qt::transparent);
    addColorStop( 0.1, QColor("#FFFF55") );
    Have a look at the implementation of QwtLinearColorMap::ColorStops::rgb() in qwt_color_map.cpp to see if this explains the effects you see on your plot.

    Uwe

  3. #3
    Join Date
    Jul 2009
    Posts
    92
    Thanks
    7
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: transparency in colormap, still don't get it!

    well, as far as I can see the code does not deal with alpha levels in those functions. Everything is done for RGB values only (using the dev trunc code), adding of color stops, interpolating between stops etc. The effect I see is that what should be transparent is black. I'll see if I can experiments with the code a bit.
    But if I add some alpha provision, then also the rendering should do that and that is a bit deeper in the code...

  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: transparency in colormap, still don't get it!

    Quote Originally Posted by qt_gotcha View Post
    well, as far as I can see the code does not deal with alpha levels in those functions.
    Yes, so the first interpolated value will be an opaque value close to ( 0, 0, 0 ). This is probably not what you want, but does it explain what you see ?

    What about overloading QwtLinearColorMap instead of using transparency for the stops:

    Qt Code:
    1. class YourColorMap: public QwtLinearColorMap
    2. {
    3. virtual QRgb rgb( const QwtInterval &interval, double value ) const
    4. {
    5. if ( value == ... )
    6. return qRgba( 0, 0, 0, 0 );
    7.  
    8. return QwtLinearColorMap::rgb( interval, value );
    9. };
    To copy to clipboard, switch view to plain text mode 

    Uwe

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

    qt_gotcha (29th January 2013)

  6. #5
    Join Date
    Jun 2012
    Posts
    173
    Thanks
    48
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: transparency in colormap, still don't get it!

    Where u able to get the transparency in colormap ???
    please let us know how you did that.

    Thank you so much.

  7. #6
    Join Date
    Jun 2014
    Posts
    17
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: transparency in colormap, still don't get it!

    Hi all,

    also interesting of spectrograms transparency. This solution (Uwe's idea above) works:
    Qt Code:
    1. class QwtTransparentLinearColorMap : public QwtLinearColorMap
    2. {
    3. typedef QwtLinearColorMap Base;
    4.  
    5. public:
    6. virtual QRgb rgb(const QwtInterval& interval, double value) const
    7. {
    8. QRgb result = Base::rgb(interval, value);
    9. result = (result & 0x00FFFFFF) | 0x7F000000; // semi-transparent
    10. return result;
    11. }
    12. };
    To copy to clipboard, switch view to plain text mode 

  8. #7
    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: transparency in colormap, still don't get it!

    Note that there is also: QwtPlotRasterItem::setAlpha(). The advantage of using this is that you can modify the alpha value without having to re-render the image. Advantage of your code is, that the alpha value is part of the cached image and when drawing the image from the cache the cycle for updating the alpha value can be avoided.

    So when you need to do something like with the slider of the spectrogram example QwtPlotRasterItem::setAlpha(), might be better. Otherwise your code might be faster ( if this matters ).

    Uwe

Similar Threads

  1. Transparency with QWinWidget
    By martian in forum Qt Programming
    Replies: 7
    Last Post: 28th February 2015, 06:13
  2. How to add colormap from files?
    By centroid in forum Qwt
    Replies: 3
    Last Post: 3rd August 2010, 08:02
  3. Replies: 1
    Last Post: 26th October 2008, 18:39
  4. Transparency ... Again
    By EricF in forum Qt Programming
    Replies: 4
    Last Post: 1st December 2007, 19:52
  5. transparency
    By roms18 in forum Qt Programming
    Replies: 2
    Last Post: 16th February 2006, 19:38

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.