transparency in colormap, still don't get it!
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:
Code:
{
public:
colorMapWater():
{
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.
Code:
// 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->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!
Re: transparency in colormap, still don't get it!
Quote:
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
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...
Re: transparency in colormap, still don't get it!
Quote:
Originally Posted by
qt_gotcha
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:
Code:
{
virtual QRgb rgb( const QwtInterval &interval, double value ) const
{
if ( value == ... )
return qRgba( 0, 0, 0, 0 );
};
Uwe
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.
Re: transparency in colormap, still don't get it!
Hi all,
also interesting of spectrograms transparency. This solution (Uwe's idea above) works:
Code:
{
public:
virtual QRgb rgb(const QwtInterval& interval, double value) const
{
QRgb result = Base::rgb(interval, value);
result = (result & 0x00FFFFFF) | 0x7F000000; // semi-transparent
return result;
}
};
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