00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef ROOT_TEveRGBAPalette
00013 #define ROOT_TEveRGBAPalette
00014
00015 #include "TEveUtil.h"
00016
00017 #include "TObject.h"
00018 #include "TQObject.h"
00019
00020 class TEveRGBAPalette : public TObject,
00021 public TQObject,
00022 public TEveRefCnt
00023 {
00024 friend class TEveRGBAPaletteEditor;
00025 friend class TEveRGBAPaletteSubEditor;
00026
00027 public:
00028 enum ELimitAction_e { kLA_Cut, kLA_Mark, kLA_Clip, kLA_Wrap };
00029
00030 private:
00031 TEveRGBAPalette(const TEveRGBAPalette&);
00032 TEveRGBAPalette& operator=(const TEveRGBAPalette&);
00033
00034 protected:
00035 Int_t fLowLimit;
00036 Int_t fHighLimit;
00037 Int_t fMinVal;
00038 Int_t fMaxVal;
00039
00040 Bool_t fInterpolate;
00041 Bool_t fShowDefValue;
00042 Bool_t fFixColorRange;
00043 Int_t fUnderflowAction;
00044 Int_t fOverflowAction;
00045
00046 Color_t fDefaultColor;
00047 UChar_t fDefaultRGBA[4];
00048 Color_t fUnderColor;
00049 UChar_t fUnderRGBA[4];
00050 Color_t fOverColor;
00051 UChar_t fOverRGBA[4];
00052
00053 mutable Int_t fNBins;
00054 mutable Int_t fCAMin;
00055 mutable Int_t fCAMax;
00056 mutable UChar_t* fColorArray;
00057
00058 void SetupColor(Int_t val, UChar_t* pix) const;
00059
00060 static TEveRGBAPalette* fgDefaultPalette;
00061
00062 public:
00063 TEveRGBAPalette();
00064 TEveRGBAPalette(Int_t min, Int_t max, Bool_t interp=kTRUE,
00065 Bool_t showdef=kTRUE, Bool_t fixcolrng=kFALSE);
00066 virtual ~TEveRGBAPalette();
00067
00068 void SetupColorArray() const;
00069 void ClearColorArray();
00070
00071 Bool_t WithinVisibleRange(Int_t val) const;
00072 const UChar_t* ColorFromValue(Int_t val) const;
00073 void ColorFromValue(Int_t val, UChar_t* pix, Bool_t alpha=kTRUE) const;
00074 Bool_t ColorFromValue(Int_t val, Int_t defVal, UChar_t* pix, Bool_t alpha=kTRUE) const;
00075
00076 Int_t GetMinVal() const { return fMinVal; }
00077 Int_t GetMaxVal() const { return fMaxVal; }
00078
00079 void SetLimits(Int_t low, Int_t high);
00080 void SetLimitsScaleMinMax(Int_t low, Int_t high);
00081 void SetMinMax(Int_t min, Int_t max);
00082 void SetMin(Int_t min);
00083 void SetMax(Int_t max);
00084
00085 Int_t GetLowLimit() const { return fLowLimit; }
00086 Int_t GetHighLimit() const { return fHighLimit; }
00087
00088
00089
00090 Bool_t GetInterpolate() const { return fInterpolate; }
00091 void SetInterpolate(Bool_t b);
00092
00093 Bool_t GetShowDefValue() const { return fShowDefValue; }
00094 void SetShowDefValue(Bool_t v) { fShowDefValue = v; }
00095
00096 Bool_t GetFixColorRange() const { return fFixColorRange; }
00097 void SetFixColorRange(Bool_t v);
00098
00099 Int_t GetUnderflowAction() const { return fUnderflowAction; }
00100 Int_t GetOverflowAction() const { return fOverflowAction; }
00101 void SetUnderflowAction(Int_t a) { fUnderflowAction = a; }
00102 void SetOverflowAction(Int_t a) { fOverflowAction = a; }
00103
00104
00105
00106 Color_t GetDefaultColor() const { return fDefaultColor; }
00107 Color_t* PtrDefaultColor() { return &fDefaultColor; }
00108 UChar_t* GetDefaultRGBA() { return fDefaultRGBA; }
00109 const UChar_t* GetDefaultRGBA() const { return fDefaultRGBA; }
00110
00111 void SetDefaultColor(Color_t ci);
00112 void SetDefaultColorPixel(Pixel_t pix);
00113 void SetDefaultColorRGBA(UChar_t r, UChar_t g, UChar_t b, UChar_t a=255);
00114
00115
00116
00117 Color_t GetUnderColor() const { return fUnderColor; }
00118 Color_t* PtrUnderColor() { return &fUnderColor; }
00119 UChar_t* GetUnderRGBA() { return fUnderRGBA; }
00120 const UChar_t* GetUnderRGBA() const { return fUnderRGBA; }
00121
00122 void SetUnderColor(Color_t ci);
00123 void SetUnderColorPixel(Pixel_t pix);
00124 void SetUnderColorRGBA(UChar_t r, UChar_t g, UChar_t b, UChar_t a=255);
00125
00126
00127
00128 Color_t GetOverColor() const { return fOverColor; }
00129 Color_t* PtrOverColor() { return &fOverColor; }
00130 UChar_t* GetOverRGBA() { return fOverRGBA; }
00131 const UChar_t* GetOverRGBA() const { return fOverRGBA; }
00132
00133 void SetOverColor(Color_t ci);
00134 void SetOverColorPixel(Pixel_t pix);
00135 void SetOverColorRGBA(UChar_t r, UChar_t g, UChar_t b, UChar_t a=255);
00136
00137
00138
00139 void MinMaxValChanged();
00140
00141 ClassDef(TEveRGBAPalette, 1);
00142 };
00143
00144
00145
00146
00147
00148
00149
00150 inline Bool_t TEveRGBAPalette::WithinVisibleRange(Int_t val) const
00151 {
00152 if ((val < fMinVal && fUnderflowAction == kLA_Cut) ||
00153 (val > fMaxVal && fOverflowAction == kLA_Cut))
00154 return kFALSE;
00155 else
00156 return kTRUE;
00157 }
00158
00159
00160 inline const UChar_t* TEveRGBAPalette::ColorFromValue(Int_t val) const
00161 {
00162
00163
00164
00165 if (!fColorArray) SetupColorArray();
00166
00167 if (val < fMinVal)
00168 {
00169 if (fUnderflowAction == kLA_Wrap)
00170 val = (val+1-fCAMin)%fNBins + fCAMax;
00171 else if (fUnderflowAction == kLA_Clip)
00172 val = fMinVal;
00173 else
00174 return fUnderRGBA;
00175 }
00176 else if(val > fMaxVal)
00177 {
00178 if (fOverflowAction == kLA_Wrap)
00179 val = (val-1-fCAMax)%fNBins + fCAMin;
00180 else if (fOverflowAction == kLA_Clip)
00181 val = fMaxVal;
00182 else
00183 return fOverRGBA;
00184 }
00185
00186 return fColorArray + 4 * (val - fCAMin);
00187 }
00188
00189
00190 inline void TEveRGBAPalette::ColorFromValue(Int_t val, UChar_t* pix, Bool_t alpha) const
00191 {
00192 const UChar_t* c = ColorFromValue(val);
00193 pix[0] = c[0]; pix[1] = c[1]; pix[2] = c[2];
00194 if (alpha) pix[3] = c[3];
00195 }
00196
00197
00198 inline Bool_t TEveRGBAPalette::ColorFromValue(Int_t val, Int_t defVal, UChar_t* pix, Bool_t alpha) const
00199 {
00200 if (val == defVal) {
00201 if (fShowDefValue) {
00202 pix[0] = fDefaultRGBA[0];
00203 pix[1] = fDefaultRGBA[1];
00204 pix[2] = fDefaultRGBA[2];
00205 if (alpha) pix[3] = fDefaultRGBA[3];
00206 return kTRUE;
00207 } else {
00208 return kFALSE;
00209 }
00210 }
00211
00212 if (WithinVisibleRange(val)) {
00213 ColorFromValue(val, pix, alpha);
00214 return kTRUE;
00215 } else {
00216 return kFALSE;
00217 }
00218 }
00219
00220 #endif