Brief description of class still missing. More...
#include <ColorPaletteData.h>
Public Member Functions | |
| void | allocate (int n) |
| QColor & | color (int i) const |
| QColor & | color (double val) const |
| void | colorHSVInterpole (int imin, int imax) |
| ColorPaletteData () | |
| ColorPaletteData (const ColorPaletteData &o) | |
| void | colorRGBInterpole (int imin, int imax) |
| int | count () const |
| void | defaultBW (int n, int transparency) |
| void | defaultHSVColors (int sat, int value, int n, int transparency) |
| void | defaultRGBColors (int n, int transparency) |
| int | index (double val) const |
| double | lowerValue (int i) const |
| bool | operator!= (const ColorPaletteData &o) const |
| bool | operator== (const ColorPaletteData &o) const |
| void | setColor (int i, const QColor &c) const |
| void | setUpperValue (int i, double v) |
| void | setVLinear (double min, double max) |
| void | setVLinear (int imin, int imax, double min, double max) |
| void | setVLog (double min, double max) |
| void | setVLog (int imin, int imax, double min, double max) |
| double | upperValue (int i) const |
| ~ColorPaletteData () | |
Brief description of class still missing.
Full description of class still missing
| void QGpGuiTools::ColorPaletteData::allocate | ( | int | n | ) |
References TRACE.
Referenced by defaultBW(), defaultHSVColors(), and defaultRGBColors().
{
TRACE;
if(n < 2) n=2;
if( !_colors || n!=_n) {
if(_colors) delete [] _colors;
_colors=new QColor[ n ];
if(_upperValues) delete [] _upperValues;
_upperValues=new double[ n - 1 ];
_n=n;
_n2=1;
while(_n2 < _n - 1) _n2=_n2 << 1; // multiply by 2
_n2=_n2 >> 1;
}
}
| QColor& QGpGuiTools::ColorPaletteData::color | ( | int | i | ) | const [inline] |
{return _colors[i];}
| QColor& QGpGuiTools::ColorPaletteData::color | ( | double | val | ) | const [inline] |
{return _colors[index(val)];}
| void QGpGuiTools::ColorPaletteData::colorHSVInterpole | ( | int | imin, |
| int | imax | ||
| ) |
References TRACE.
{
TRACE;
double h, h2, dh, s, s2, ds, v, v2, dv, a, a2, da;
if(_n <= 2) return ;
if(imin < 0) imin=0;
if(imax > _n - 1) imax=_n - 1;
QColor& c1=_colors[ imin ];
h=c1.hue();
s=c1.saturation();
v=c1.value();
a=c1.alpha();
QColor& c2=_colors[ imax ];
h2=c2.hue();
s2=c2.saturation();
v2=c2.value();
a2=c2.alpha();
dh=(h2 - h)/(double) (imax - imin + 1);
ds=(s2 - s)/(double) (imax - imin + 1);
dv=(v2 - v)/(double) (imax - imin + 1);
da=(a2 - a)/(double) (imax - imin + 1);
for(int i=imin + 1; i < imax; i++ ) {
h += dh;
s += ds;
v += dv;
a += da;
_colors[ i ].setHsv(( int) h, (int) s, (int) v, (int) a);
}
}
| void QGpGuiTools::ColorPaletteData::colorRGBInterpole | ( | int | imin, |
| int | imax | ||
| ) |
References TRACE.
{
TRACE;
double r, r2, dr, g, g2, dg, b, b2, db, a, a2, da;
if(_n <= 2) return ;
if(imin < 0) imin=0;
if(imax > _n - 1) imax=_n - 1;
QColor& c1=_colors[ imin ];
r=c1.red();
g=c1.green();
b=c1.blue();
a=c1.alpha();
QColor& c2=_colors[ imax ];
r2=c2.red();
g2=c2.green();
b2=c2.blue();
a2=c2.alpha();
dr=(r2 - r)/(double) (imax - imin + 1);
dg=(g2 - g)/(double) (imax - imin + 1);
db=(b2 - b)/(double) (imax - imin + 1);
da=(a2 - a)/(double) (imax - imin + 1);
for(int i=imin + 1; i < imax; i++ ) {
r += dr;
g += dg;
b += db;
a += da;
_colors[ i ]=QColor(( int) r, (int) g, (int) b, (int) a);
}
}
| int QGpGuiTools::ColorPaletteData::count | ( | ) | const [inline] |
{return _n;}
| void QGpGuiTools::ColorPaletteData::defaultBW | ( | int | n, |
| int | transparency | ||
| ) |
References allocate(), and TRACE.
| void QGpGuiTools::ColorPaletteData::defaultHSVColors | ( | int | sat, |
| int | value, | ||
| int | n, | ||
| int | transparency | ||
| ) |
References allocate(), and TRACE.
| void QGpGuiTools::ColorPaletteData::defaultRGBColors | ( | int | n, |
| int | transparency | ||
| ) |
References allocate(), and TRACE.
{
TRACE;
allocate(n);
int i;
if(_n==2) {
_colors[ 0 ]=QColor(0, 0, 255, transparency);
_colors[ 1 ]=QColor(255, 0, 0, transparency);
} else if(_n==3) {
_colors[ 0 ]=QColor(0, 0, 255, transparency);
_colors[ 1 ]=QColor(0, 255, 0, transparency);
_colors[ 2 ]=QColor(255, 0, 0, transparency);
} else {
double truc, r, g, b;
int n1=_n/3;
int n2=n1 + (_n - n1)/2;
for(i=0; i < n1; i++ ) {
truc=(double) i/(double) n1;
r=0.;
g=pow(truc, 0.3);
b=1. - truc * truc;
_colors[ i ]=QColor(( int) (r * 255), (int) (g * 255), (int) (b * 255), transparency);
}
for(i=n1; i < n2; i++ ) {
truc=(double) (i - n1)/(double) (n2 - n1);
r=pow(truc, 0.3);
g=1.;
b=0.;
_colors[ i ]=QColor(( int) (r * 255), (int) (g * 255), (int) (b * 255), transparency);
}
for(i=n2; i < _n; i++ ) {
truc=(double) (i - n2)/(double) (n - n2 - 1);
r=1.;
g=1. - truc * truc;
b=0.;
_colors[ i ]=QColor(( int) (r * 255), (int) (g * 255), (int) (b * 255), transparency);
}
}
}
| int QGpGuiTools::ColorPaletteData::index | ( | double | val | ) | const |
Returns the color index of value val. The palette must at least contain two items.
References TRACE.
{
TRACE;
if(val <= _upperValues[ 0 ] ) return 0;
int lasti=_n - 2;
if(val > _upperValues[ lasti ] ) return lasti + 1;
int i=_n2;
int step2=i >> 1;
while(step2 > 0) {
if(i > lasti) i -= step2;
else if(val <= _upperValues[ i ] ) {
if(val > _upperValues[ i - 1 ] ) break;
i -= step2;
} else
i += step2;
step2=step2 >> 1;
}
return i;
}
| double QGpGuiTools::ColorPaletteData::lowerValue | ( | int | i | ) | const [inline] |
{return i>0 ? _upperValues[i-1] : -1e99;}
| bool QGpGuiTools::ColorPaletteData::operator!= | ( | const ColorPaletteData & | o | ) | const [inline] |
{return ! operator==(o);}
| bool QGpGuiTools::ColorPaletteData::operator== | ( | const ColorPaletteData & | o | ) | const |
| void QGpGuiTools::ColorPaletteData::setColor | ( | int | i, |
| const QColor & | c | ||
| ) | const [inline] |
{_colors[i]=c;}
| void QGpGuiTools::ColorPaletteData::setUpperValue | ( | int | i, |
| double | v | ||
| ) | [inline] |
{_upperValues[i]=v;}
| void QGpGuiTools::ColorPaletteData::setVLinear | ( | double | min, |
| double | max | ||
| ) | [inline] |
| void QGpGuiTools::ColorPaletteData::setVLinear | ( | int | imin, |
| int | imax, | ||
| double | min, | ||
| double | max | ||
| ) |
References TRACE.
{
TRACE;
if(_n==2)
_upperValues[ 0 ]=(min + max) * 0.5;
else if(_n < 2) return ;
else {
if(imin<0) imin=0;
else if(imin>=_n-1) imin=_n-2;
if(imax<0) imax=0;
else if(imax>=_n-1) imax=_n-2;
double inc=(max - min)/(double) (imax -imin);
_upperValues[ imin ]=min;
for(int i=imin+1;i <= imax; i++ ) _upperValues[ i ]=_upperValues[ i - 1 ] + inc;
}
}
| void QGpGuiTools::ColorPaletteData::setVLog | ( | double | min, |
| double | max | ||
| ) | [inline] |
| void QGpGuiTools::ColorPaletteData::setVLog | ( | int | imin, |
| int | imax, | ||
| double | min, | ||
| double | max | ||
| ) |
References TRACE.
{
TRACE;
if(_n==2)
_upperValues[ 0 ]=(min + max) * 0.5;
else if(_n < 2) return ;
else {
if(imin<0) imin=0;
else if(imin>=_n-1) imin=_n-2;
if(imax<0) imax=0;
else if(imax>=_n-1) imax=_n-2;
double inc=pow(max/min, 1/(double) (imax - imin) );
_upperValues[ imin ]=min;
for(int i=imin+1;i <= imax; i++ ) _upperValues[ i ]=_upperValues[ i - 1 ] * inc;
}
}
| double QGpGuiTools::ColorPaletteData::upperValue | ( | int | i | ) | const [inline] |
{return i<_n-1 ? _upperValues[i] : 1e99;}