00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include "TEveRGBAPalette.h"
00013
00014 #include "TColor.h"
00015 #include "TStyle.h"
00016 #include "TMath.h"
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 ClassImp(TEveRGBAPalette);
00029
00030
00031 TEveRGBAPalette::TEveRGBAPalette() :
00032 TObject(), TQObject(),
00033 TEveRefCnt(),
00034
00035 fLowLimit(0), fHighLimit(0), fMinVal(0), fMaxVal(0),
00036
00037 fInterpolate (kTRUE),
00038 fShowDefValue (kTRUE),
00039 fFixColorRange (kFALSE),
00040 fUnderflowAction (kLA_Cut),
00041 fOverflowAction (kLA_Clip),
00042
00043 fDefaultColor(-1),
00044 fUnderColor (-1),
00045 fOverColor (-1),
00046
00047 fNBins(0), fCAMin(0), fCAMax(0), fColorArray(0)
00048 {
00049
00050
00051 SetLimits(0, 1024);
00052 SetMinMax(0, 512);
00053
00054 SetDefaultColor(0);
00055 SetUnderColor(1);
00056 SetOverColor(2);
00057 }
00058
00059
00060 TEveRGBAPalette::TEveRGBAPalette(Int_t min, Int_t max, Bool_t interp,
00061 Bool_t showdef, Bool_t fixcolrng) :
00062 TObject(), TQObject(),
00063 TEveRefCnt(),
00064
00065 fLowLimit(0), fHighLimit(0), fMinVal(0), fMaxVal(0),
00066
00067 fInterpolate (interp),
00068 fShowDefValue (showdef),
00069 fFixColorRange (fixcolrng),
00070 fUnderflowAction (kLA_Cut),
00071 fOverflowAction (kLA_Clip),
00072
00073 fDefaultColor(-1),
00074 fUnderColor (-1),
00075 fOverColor (-1),
00076
00077 fNBins(0), fCAMin(0), fCAMax(0), fColorArray(0)
00078 {
00079
00080
00081 SetLimits(min, max);
00082 SetMinMax(min, max);
00083
00084 SetDefaultColor(0);
00085 SetUnderColor(1);
00086 SetOverColor(2);
00087 }
00088
00089
00090 TEveRGBAPalette::~TEveRGBAPalette()
00091 {
00092
00093
00094 delete [] fColorArray;
00095 }
00096
00097
00098
00099
00100 void TEveRGBAPalette::SetupColor(Int_t val, UChar_t* pixel) const
00101 {
00102
00103
00104 using namespace TMath;
00105 Float_t div = Max(1, fCAMax - fCAMin);
00106 Int_t nCol = gStyle->GetNumberOfColors();
00107
00108 Float_t f;
00109 if (val >= fCAMax) f = nCol - 1;
00110 else if (val <= fCAMin) f = 0;
00111 else f = (val - fCAMin)/div*(nCol - 1);
00112
00113 if (fInterpolate) {
00114 Int_t bin = (Int_t) f;
00115 Float_t f1 = f - bin, f2 = 1.0f - f1;
00116 TEveUtil::ColorFromIdx(f1, gStyle->GetColorPalette(bin),
00117 f2, gStyle->GetColorPalette(Min(bin + 1, nCol - 1)),
00118 pixel);
00119 } else {
00120 TEveUtil::ColorFromIdx(gStyle->GetColorPalette((Int_t) Nint(f)), pixel);
00121 }
00122 }
00123
00124
00125 void TEveRGBAPalette::SetupColorArray() const
00126 {
00127
00128
00129 if (fColorArray)
00130 delete [] fColorArray;
00131
00132 if (fFixColorRange) {
00133 fCAMin = fLowLimit; fCAMax = fHighLimit;
00134 } else {
00135 fCAMin = fMinVal; fCAMax = fMaxVal;
00136 }
00137 fNBins = fCAMax - fCAMin + 1;
00138
00139 fColorArray = new UChar_t [4 * fNBins];
00140 UChar_t* p = fColorArray;
00141 for(Int_t v = fCAMin; v <= fCAMax; ++v, p+=4)
00142 SetupColor(v, p);
00143 }
00144
00145
00146 void TEveRGBAPalette::ClearColorArray()
00147 {
00148
00149
00150 if (fColorArray) {
00151 delete [] fColorArray;
00152 fColorArray = 0;
00153 fNBins = fCAMin = fCAMax = 0;
00154 }
00155 }
00156
00157
00158
00159
00160 void TEveRGBAPalette::SetLimits(Int_t low, Int_t high)
00161 {
00162
00163
00164
00165 fLowLimit = low;
00166 fHighLimit = high;
00167
00168 if (fMaxVal < fLowLimit) SetMax(fLowLimit);
00169 if (fMinVal < fLowLimit) SetMin(fLowLimit);
00170 if (fMinVal > fHighLimit) SetMin(fHighLimit);
00171 if (fMaxVal > fHighLimit) SetMax(fHighLimit);
00172
00173 ClearColorArray();
00174 }
00175
00176
00177 void TEveRGBAPalette::SetLimitsScaleMinMax(Int_t low, Int_t high)
00178 {
00179
00180
00181 Float_t rng_old = fHighLimit - fLowLimit;
00182 Float_t rng_new = high - low;
00183
00184 fMinVal = TMath::Nint(low + (fMinVal - fLowLimit)*rng_new/rng_old);
00185 fMaxVal = TMath::Nint(low + (fMaxVal - fLowLimit)*rng_new/rng_old);
00186 fLowLimit = low;
00187 fHighLimit = high;
00188
00189 ClearColorArray();
00190 }
00191
00192
00193 void TEveRGBAPalette::SetMin(Int_t min)
00194 {
00195
00196
00197 fMinVal = TMath::Min(min, fMaxVal);
00198 ClearColorArray();
00199 }
00200
00201
00202 void TEveRGBAPalette::SetMax(Int_t max)
00203 {
00204
00205
00206 fMaxVal = TMath::Max(max, fMinVal);
00207 ClearColorArray();
00208 }
00209
00210
00211 void TEveRGBAPalette::SetMinMax(Int_t min, Int_t max)
00212 {
00213
00214
00215 fMinVal = min;
00216 fMaxVal = max;
00217 ClearColorArray();
00218 }
00219
00220
00221
00222
00223 void TEveRGBAPalette::SetInterpolate(Bool_t b)
00224 {
00225
00226
00227
00228 fInterpolate = b;
00229 ClearColorArray();
00230 }
00231
00232
00233 void TEveRGBAPalette::SetFixColorRange(Bool_t v)
00234 {
00235
00236
00237
00238
00239 fFixColorRange = v;
00240 ClearColorArray();
00241 }
00242
00243
00244
00245
00246 void TEveRGBAPalette::SetDefaultColor(Color_t ci)
00247 {
00248
00249
00250 fDefaultColor = ci;
00251 TEveUtil::ColorFromIdx(ci, fDefaultRGBA, kTRUE);
00252 }
00253
00254
00255 void TEveRGBAPalette::SetDefaultColorPixel(Pixel_t pix)
00256 {
00257
00258
00259 SetDefaultColor(Color_t(TColor::GetColor(pix)));
00260 }
00261
00262
00263 void TEveRGBAPalette::SetDefaultColorRGBA(UChar_t r, UChar_t g, UChar_t b, UChar_t a)
00264 {
00265
00266
00267 fDefaultColor = Color_t(TColor::GetColor(r, g, b));
00268 fDefaultRGBA[0] = r;
00269 fDefaultRGBA[1] = g;
00270 fDefaultRGBA[2] = b;
00271 fDefaultRGBA[3] = a;
00272 }
00273
00274
00275
00276
00277 void TEveRGBAPalette::SetUnderColor(Color_t ci)
00278 {
00279
00280
00281 fUnderColor = ci;
00282 TEveUtil::ColorFromIdx(ci, fUnderRGBA, kTRUE);
00283 }
00284
00285
00286 void TEveRGBAPalette::SetUnderColorPixel(Pixel_t pix)
00287 {
00288
00289
00290 SetUnderColor(Color_t(TColor::GetColor(pix)));
00291 }
00292
00293
00294 void TEveRGBAPalette::SetUnderColorRGBA(UChar_t r, UChar_t g, UChar_t b, UChar_t a)
00295 {
00296
00297
00298 fUnderColor = Color_t(TColor::GetColor(r, g, b));
00299 fUnderRGBA[0] = r;
00300 fUnderRGBA[1] = g;
00301 fUnderRGBA[2] = b;
00302 fUnderRGBA[3] = a;
00303 }
00304
00305
00306
00307
00308 void TEveRGBAPalette::SetOverColor(Color_t ci)
00309 {
00310
00311
00312 fOverColor = ci;
00313 TEveUtil::ColorFromIdx(ci, fOverRGBA, kTRUE);
00314 }
00315
00316
00317 void TEveRGBAPalette::SetOverColorPixel(Pixel_t pix)
00318 {
00319
00320
00321 SetOverColor(Color_t(TColor::GetColor(pix)));
00322 }
00323
00324
00325 void TEveRGBAPalette::SetOverColorRGBA(UChar_t r, UChar_t g, UChar_t b, UChar_t a)
00326 {
00327
00328
00329 fOverColor = Color_t(TColor::GetColor(r, g, b));
00330 fOverRGBA[0] = r;
00331 fOverRGBA[1] = g;
00332 fOverRGBA[2] = b;
00333 fOverRGBA[3] = a;
00334 }
00335
00336
00337 void TEveRGBAPalette::MinMaxValChanged()
00338 {
00339
00340
00341
00342
00343
00344 Emit("MinMaxValChanged()");
00345 }