Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

evd::ColorScale Class Reference

Build an association between a numerical range and a ROOT color index for use in, eg., the event display. More...

#include <ColorScale.h>

List of all members.

Public Member Functions

 ColorScale (double xlo, double xhi, int which=kRainbow, int scale=kLinear, int n=40, double h1=0, double h1=0, double v1=0, double v2=0)
int operator() (double x) const
int GetColor (double x) const
void SetPalette ()

Private Member Functions

void HSVtoRGB (double h, double s, double v, double *r, double *g, double *b) const
void MakeHSVScale (int n, double h1, double h2, double vs1, double vs2)
 Make a color scale of n colors ranging between two points in an HSV color space.

Private Attributes

double fXlo
double fXhi
 Numeric value at low end of scale.
int fScale
 Numeric value at high end of scale.
int fNcolor
 Linear? Log? Sqrt?
int fColors [128]
 How many colors in scale?


Detailed Description

Build an association between a numerical range and a ROOT color index for use in, eg., the event display.

Definition at line 34 of file ColorScale.h.


Constructor & Destructor Documentation

ColorScale::ColorScale double  xlo,
double  xhi,
int  which = kRainbow,
int  scale = kLinear,
int  n = 40,
double  h1 = 0,
double  h2 = 0,
double  v1 = 0,
double  v2 = 0
 

Construct a color scale

Parameters:
xlo - The value at the low end of the scale
xhi - The value at the high end of the scale
which - Which color map to use (see enum's in ColorScale.h)
scale - How to scale range (see enum's in ColorScale.h)
n - How many colors to use
h1 - First H value in range
h2 - Last H value in range
v1 - First V value in range
v2 - Last V value in range

Definition at line 28 of file ColorScale.cxx.

References evd::kBlues, evd::kColdToHot, evd::kCustom, evd::kGeographic, evd::kGreens, evd::kHeatedObject, evd::kRainbow, evd::kReds, and MakeHSVScale().

00030                                                                    :
00031   fXlo(xlo),
00032   fXhi(xhi),
00033   fScale(scale)
00034 {
00035   switch(which) {
00036   case kColdToHot:    this->MakeHSVScale(n, 150.0, 0.0,   0.2, 0.5);  break;
00037   case kHeatedObject: this->MakeHSVScale(n, 60.0,  0.0,   0.1, 0.9);  break;
00038   case kReds:         this->MakeHSVScale(n, 30.0,  0.0,   0.1, 0.9);  break;
00039   case kBlues:        this->MakeHSVScale(n, 180.0, 270.0, 0.1, 0.9);  break;
00040   case kGreens:       this->MakeHSVScale(n, 90.0,  120.0, 0.1, 0.9);  break;
00041   case kGeographic:   this->MakeHSVScale(n, 270.0, 30.0,  0.9, 0.05); break;
00042   case kCustom:       this->MakeHSVScale(n, h1, h2, v1, v2);          break;
00043   case kRainbow:
00044     // Default to a rainbow.
00045   default:
00046     this->MakeHSVScale(16,270,0,0.1,0.6);
00047     break;
00048   }
00049 }


Member Function Documentation

int ColorScale::GetColor double  x  )  const
 

Assign a ROOT color index to the value x

Parameters:
x - the value on the scale
Returns:
A ROOT color number

Definition at line 58 of file ColorScale.cxx.

References fColors, fNcolor, fScale, fXhi, and fXlo.

Referenced by evd::TQPad::Draw(), operator()(), and evd::RawDataDrawer::RawDigit2D().

00059 {
00060   double f=0.0;
00061   if (fScale == kLinear) {
00062     f = (x-fXlo)/(fXhi-fXlo);
00063   }
00064   else if (fScale == kLog) {
00065     f = (log(x)-log(fXlo))/(log(fXhi)-log(fXlo));
00066   }
00067   else if (fScale == kSqrt) {
00068     f = (sqrt(x)-sqrt(fXlo))/(sqrt(fXhi)-sqrt(fXlo));
00069   }
00070 
00071   int indx = (int)floor(f*(float)fNcolor);
00072   if (indx<0)        indx = 0;
00073   if (indx>=fNcolor) indx = fNcolor-1;
00074   return fColors[indx];
00075 }

void ColorScale::HSVtoRGB double  h,
double  s,
double  v,
double *  r,
double *  g,
double *  b
const [private]
 

Convert hue, saturation and value numbers to red, green, blue

Parameters:
h - hue (in range from 0 to 360)
s - saturation
v - value
r - returned r value
g - returned g value
b - returned b value

Definition at line 91 of file ColorScale.cxx.

Referenced by MakeHSVScale().

00093 {
00094   // A-chromatic, return grey scale values
00095   if (s==0.0) { *r = *g = *b = v; return; }
00096 
00097   int i;
00098   double f, p, q, t;
00099   double hh = h;
00100   while (hh<  0.0) hh += 360.0;
00101   while (hh>360.0) hh -= 360.0;
00102   hh /= 60;
00103   i = (int)floor(hh);
00104   f = hh - i;
00105   p = v * (1 - s);
00106   q = v * (1 - s*f);
00107   t = v * (1 - s*(1-f) );
00108   switch( i ) {
00109   case 0:  *r = v; *g = t; *b = p; break;
00110   case 1:  *r = q; *g = v; *b = p; break;
00111   case 2:  *r = p; *g = v; *b = t; break;
00112   case 3:  *r = p; *g = q; *b = v; break;
00113   case 4:  *r = t; *g = p; *b = v; break;
00114   default: *r = v; *g = p; *b = q; break;
00115   }
00116 }

void ColorScale::MakeHSVScale int  n,
double  h1,
double  h2,
double  vs1,
double  vs2
[private]
 

Make a color scale of n colors ranging between two points in an HSV color space.

Choose points so that the value of the colors changes uniformly. This ensures good viewing event in black and white.

Parameters:
n - number of colors in the scale
h1 - first H value in color scale
h2 - second H value in color scale
vs1 - first V value in color scale
vs2 - second V value in color scale

Definition at line 132 of file ColorScale.cxx.

References fColors, fNcolor, and HSVtoRGB().

Referenced by ColorScale().

00135 {
00136   int i;
00137   double r, g, b;
00138   double h;
00139   double vs, v, s;
00140   
00141   if (n>128) n = 128;
00142   fNcolor = n;
00143 
00144   for (i=0; i<fNcolor; ++i) {
00145     h  = h1  + (h2-h1)*(float)i/(float)(fNcolor-1);
00146     vs = vs1 + (vs2-vs1)*(float)i/(float)(fNcolor-1);
00147     vs = -1.0 + 2.0*vs;
00148     if (vs<0.0) { v = 1.0; s = 1.0+vs; }
00149     else { v = 1.0-vs; s = 1.0; }
00150     this->HSVtoRGB(h, s, v, &r, &g, &b);
00151     r *= 255;
00152     g *= 255;
00153     b *= 255;
00154     fColors[i] = TColor::GetColor((int)r,(int)g,(int)b);
00155   }
00156 }

int ColorScale::operator() double  x  )  const
 

Definition at line 76 of file ColorScale.cxx.

References GetColor().

00076                                          { 
00077   return this->GetColor(x); 
00078 }

void ColorScale::SetPalette  ) 
 

Set the ROOT color palette to use this color scale

Definition at line 162 of file ColorScale.cxx.

References fColors, and fNcolor.

00163 {
00164   gStyle->SetPalette(fNcolor, fColors);
00165 }


Member Data Documentation

int evd::ColorScale::fColors[128] [private]
 

How many colors in scale?

Definition at line 57 of file ColorScale.h.

Referenced by GetColor(), MakeHSVScale(), and SetPalette().

int evd::ColorScale::fNcolor [private]
 

Linear? Log? Sqrt?

Definition at line 56 of file ColorScale.h.

Referenced by GetColor(), MakeHSVScale(), and SetPalette().

int evd::ColorScale::fScale [private]
 

Numeric value at high end of scale.

Definition at line 55 of file ColorScale.h.

Referenced by GetColor().

double evd::ColorScale::fXhi [private]
 

Numeric value at low end of scale.

Definition at line 54 of file ColorScale.h.

Referenced by GetColor().

double evd::ColorScale::fXlo [private]
 

Definition at line 53 of file ColorScale.h.

Referenced by GetColor().


The documentation for this class was generated from the following files:
Generated on Sun Nov 22 04:45:30 2009 for NOvA Offline by  doxygen 1.3.9.1