PDA

View Full Version : transparency in colormap, still don't get it!



qt_gotcha
26th January 2013, 12:36
Sorry, I have asked this before but still don't get it! :o
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:


class colorMapWater: public QwtLinearColorMap
{
public:
colorMapWater():
QwtLinearColorMap( QColor(BGc), Qt::darkBlue )
{
addColorStop( 0.0, qRgba(0, 0, 0, 0));// or Qt::transparent);
addColorStop( 0.1, QColor("#FFFF55") );
addColorStop( 0.4, QColor("#8080FF") );
addColorStop( 0.9, Qt::blue );
}
};

the function to show the top (water) map is as follows.


// fill QwtMatrixRasterData RD with matrix data from Map and find the new max value
// also sets interval for x and y axis
double MaxV = fillDrawMapData(Map, RD);

// set the interval to the new max value
maxAxis2 = qMax(maxAxis2, MaxV);
RD->setInterval( Qt::ZAxis, QwtInterval( 0, maxAxis2));

//drawMap is a QwtPlotSpectrogram
drawMap->setData(RD);
drawMap->setColorMap(new colorMapWater());

// set the right axis legend to the new interval
rightAxis->setColorMap( drawMap->data()->interval( Qt::ZAxis ), new colorMapWater());
MPlot->setAxisScale( MPlot->yRight, 0, maxAxis2);
MPlot->setAxisScaleEngine( MPlot->yRight, new QwtLinearScaleEngine() );
MPlot->replot();

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!

Uwe
28th January 2013, 20:34
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

qt_gotcha
29th January 2013, 07:11
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...

Uwe
29th January 2013, 08:52
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:


class YourColorMap: public QwtLinearColorMap
{
virtual QRgb rgb( const QwtInterval &interval, double value ) const
{
if ( value == ... )
return qRgba( 0, 0, 0, 0 );

return QwtLinearColorMap::rgb( interval, value );
};

Uwe

jesse_mark
6th February 2013, 17:23
Where u able to get the transparency in colormap ???
please let us know how you did that.

Thank you so much.

Alekon
19th January 2015, 14:00
Hi all,

also interesting of spectrograms transparency. This solution (Uwe's idea above) works:

class QwtTransparentLinearColorMap : public QwtLinearColorMap
{
typedef QwtLinearColorMap Base;

public:
virtual QRgb rgb(const QwtInterval& interval, double value) const
{
QRgb result = Base::rgb(interval, value);
result = (result & 0x00FFFFFF) | 0x7F000000; // semi-transparent
return result;
}
};

Uwe
19th January 2015, 19:05
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