File indexing completed on 2025-01-18 10:10:40
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #ifndef ROOT_REveRGBAPalette
0013 #define ROOT_REveRGBAPalette
0014
0015 #include "ROOT/REveElement.hxx"
0016 #include "ROOT/REveUtil.hxx"
0017
0018 #include "TMath.h"
0019
0020 namespace ROOT {
0021 namespace Experimental {
0022
0023 class REveRGBAPalette : public REveElement,
0024 public REveAuntAsList,
0025 public REveRefCnt
0026 {
0027 friend class REveRGBAPaletteEditor;
0028 friend class REveRGBAPaletteSubEditor;
0029
0030 friend class REveRGBAPaletteOverlay;
0031
0032 public:
0033 enum ELimitAction_e { kLA_Cut, kLA_Mark, kLA_Clip, kLA_Wrap };
0034
0035 private:
0036 REveRGBAPalette(const REveRGBAPalette&) = delete;
0037 REveRGBAPalette& operator=(const REveRGBAPalette&) = delete;
0038
0039 protected:
0040 Double_t fUIf;
0041 Double_t fUIc;
0042
0043 Int_t fLowLimit;
0044 Int_t fHighLimit;
0045 Int_t fMinVal;
0046 Int_t fMaxVal;
0047
0048 Bool_t fUIDoubleRep;
0049 Bool_t fInterpolate;
0050 Bool_t fShowDefValue;
0051 Bool_t fFixColorRange;
0052 Int_t fUnderflowAction;
0053 Int_t fOverflowAction;
0054
0055 Color_t fDefaultColor;
0056 UChar_t fDefaultRGBA[4];
0057 Color_t fUnderColor;
0058 UChar_t fUnderRGBA[4];
0059 Color_t fOverColor;
0060 UChar_t fOverRGBA[4];
0061
0062 mutable Int_t fNBins;
0063 mutable Int_t fCAMin;
0064 mutable Int_t fCAMax;
0065 mutable UChar_t* fColorArray;
0066
0067 void SetupColor(Int_t val, UChar_t* pix) const;
0068
0069 Double_t IntToDouble(Int_t i) const { return fUIf*i + fUIc; }
0070 Int_t DoubleToInt(Double_t d) const { return TMath::Nint((d - fUIc) / fUIf); }
0071
0072 Double_t GetCAMinAsDouble() const { return IntToDouble(fCAMin); }
0073 Double_t GetCAMaxAsDouble() const { return IntToDouble(fCAMax); }
0074
0075 static REveRGBAPalette* fgDefaultPalette;
0076
0077 void StampNieces();
0078 public:
0079 REveRGBAPalette();
0080 REveRGBAPalette(Int_t min, Int_t max, Bool_t interp=kTRUE,
0081 Bool_t showdef=kTRUE, Bool_t fixcolrng=kFALSE);
0082 ~REveRGBAPalette() override;
0083
0084 void SetupColorArray() const;
0085 void ClearColorArray();
0086
0087 Bool_t WithinVisibleRange(Int_t val) const;
0088 const UChar_t* ColorFromValue(Int_t val) const;
0089 void ColorFromValue(Int_t val, UChar_t* pix, Bool_t alpha=kTRUE) const;
0090 Bool_t ColorFromValue(Int_t val, Int_t defVal, UChar_t* pix, Bool_t alpha=kTRUE) const;
0091
0092 Int_t GetMinVal() const { return fMinVal; }
0093 Int_t GetMaxVal() const { return fMaxVal; }
0094
0095 void SetLimits(Int_t low, Int_t high);
0096 void SetLimitsScaleMinMax(Int_t low, Int_t high);
0097 void SetMinMax(Int_t min, Int_t max);
0098 void SetMin(Int_t min);
0099 void SetMax(Int_t max);
0100
0101 Int_t GetLowLimit() const { return fLowLimit; }
0102 Int_t GetHighLimit() const { return fHighLimit; }
0103
0104
0105
0106 Bool_t GetUIDoubleRep() const { return fUIDoubleRep; }
0107 void SetUIDoubleRep(Bool_t b, Double_t f=1, Double_t c=0);
0108
0109 Bool_t GetInterpolate() const { return fInterpolate; }
0110 void SetInterpolate(Bool_t b);
0111
0112 Bool_t GetShowDefValue() const { return fShowDefValue; }
0113 void SetShowDefValue(Bool_t v) { fShowDefValue = v; }
0114
0115 Bool_t GetFixColorRange() const { return fFixColorRange; }
0116 void SetFixColorRange(Bool_t v);
0117
0118 Int_t GetUnderflowAction() const { return fUnderflowAction; }
0119 Int_t GetOverflowAction() const { return fOverflowAction; }
0120 void SetUnderflowAction(Int_t a) { fUnderflowAction = a; StampNieces(); }
0121 void SetOverflowAction(Int_t a) { fOverflowAction = a; StampNieces(); }
0122
0123
0124
0125 Color_t GetDefaultColor() const { return fDefaultColor; }
0126 Color_t* PtrDefaultColor() { return &fDefaultColor; }
0127 UChar_t* GetDefaultRGBA() { return fDefaultRGBA; }
0128 const UChar_t* GetDefaultRGBA() const { return fDefaultRGBA; }
0129
0130 void SetDefaultColor(Color_t ci);
0131 void SetDefaultColorPixel(Pixel_t pix);
0132 void SetDefaultColorRGBA(UChar_t r, UChar_t g, UChar_t b, UChar_t a=255);
0133
0134
0135
0136 Color_t GetUnderColor() const { return fUnderColor; }
0137 Color_t* PtrUnderColor() { return &fUnderColor; }
0138 UChar_t* GetUnderRGBA() { return fUnderRGBA; }
0139 const UChar_t* GetUnderRGBA() const { return fUnderRGBA; }
0140
0141 void SetUnderColor(Color_t ci);
0142 void SetUnderColorPixel(Pixel_t pix);
0143 void SetUnderColorRGBA(UChar_t r, UChar_t g, UChar_t b, UChar_t a=255);
0144
0145
0146
0147 Color_t GetOverColor() const { return fOverColor; }
0148 Color_t* PtrOverColor() { return &fOverColor; }
0149 UChar_t* GetOverRGBA() { return fOverRGBA; }
0150 const UChar_t* GetOverRGBA() const { return fOverRGBA; }
0151
0152 void SetOverColor(Color_t ci);
0153 void SetOverColorPixel(Pixel_t pix);
0154 void SetOverColorRGBA(UChar_t r, UChar_t g, UChar_t b, UChar_t a=255);
0155
0156 void OnZeroRefCount() override { delete this; }
0157 Int_t WriteCoreJson(nlohmann::json &j, Int_t rnr_offset) override;
0158 };
0159
0160
0161
0162
0163
0164
0165 inline Bool_t REveRGBAPalette::WithinVisibleRange(Int_t val) const
0166 {
0167 if ((val < fMinVal && fUnderflowAction == kLA_Cut) ||
0168 (val > fMaxVal && fOverflowAction == kLA_Cut))
0169 return kFALSE;
0170 else
0171 return kTRUE;
0172 }
0173
0174
0175 inline const UChar_t* REveRGBAPalette::ColorFromValue(Int_t val) const
0176 {
0177
0178
0179
0180 if (!fColorArray) SetupColorArray();
0181
0182 if (val < fMinVal)
0183 {
0184 if (fUnderflowAction == kLA_Wrap)
0185 val = (val+1-fCAMin)%fNBins + fCAMax;
0186 else if (fUnderflowAction == kLA_Clip)
0187 val = fMinVal;
0188 else
0189 return fUnderRGBA;
0190 }
0191 else if(val > fMaxVal)
0192 {
0193 if (fOverflowAction == kLA_Wrap)
0194 val = (val-1-fCAMax)%fNBins + fCAMin;
0195 else if (fOverflowAction == kLA_Clip)
0196 val = fMaxVal;
0197 else
0198 return fOverRGBA;
0199 }
0200
0201 return fColorArray + 4 * (val - fCAMin);
0202 }
0203
0204
0205 inline void REveRGBAPalette::ColorFromValue(Int_t val, UChar_t* pix, Bool_t alpha) const
0206 {
0207 const UChar_t* c = ColorFromValue(val);
0208 pix[0] = c[0]; pix[1] = c[1]; pix[2] = c[2];
0209 if (alpha) pix[3] = c[3];
0210 }
0211
0212
0213 inline Bool_t REveRGBAPalette::ColorFromValue(Int_t val, Int_t defVal, UChar_t* pix, Bool_t alpha) const
0214 {
0215 if (val == defVal) {
0216 if (fShowDefValue) {
0217 pix[0] = fDefaultRGBA[0];
0218 pix[1] = fDefaultRGBA[1];
0219 pix[2] = fDefaultRGBA[2];
0220 if (alpha) pix[3] = fDefaultRGBA[3];
0221 return kTRUE;
0222 } else {
0223 return kFALSE;
0224 }
0225 }
0226
0227 if (WithinVisibleRange(val)) {
0228 ColorFromValue(val, pix, alpha);
0229 return kTRUE;
0230 } else {
0231 return kFALSE;
0232 }
0233 }
0234
0235 }
0236 }
0237
0238 #endif