Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:11:42

0001 // @(#)root/eve:$Id$
0002 // Authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007
0003 
0004 /*************************************************************************
0005  * Copyright (C) 1995-2007, Rene Brun and Fons Rademakers.               *
0006  * All rights reserved.                                                  *
0007  *                                                                       *
0008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
0009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
0010  *************************************************************************/
0011 
0012 #ifndef ROOT_TEveRGBAPalette
0013 #define ROOT_TEveRGBAPalette
0014 
0015 #include "TEveUtil.h"
0016 
0017 #include "TObject.h"
0018 #include "TQObject.h"
0019 
0020 #include "TMath.h"
0021 
0022 class TEveRGBAPalette : public TObject,
0023                         public TQObject,
0024                         public TEveRefCnt
0025 {
0026    friend class TEveRGBAPaletteEditor;
0027    friend class TEveRGBAPaletteSubEditor;
0028 
0029    friend class TEveRGBAPaletteOverlay;
0030 
0031 public:
0032    enum ELimitAction_e { kLA_Cut, kLA_Mark, kLA_Clip, kLA_Wrap };
0033 
0034 private:
0035    TEveRGBAPalette(const TEveRGBAPalette&);            // Not implemented
0036    TEveRGBAPalette& operator=(const TEveRGBAPalette&); // Not implemented
0037 
0038 protected:
0039    Double_t  fUIf;       // UI representation calculated as: d = fUIf*i + fUIc
0040    Double_t  fUIc;       // UI representation calculated as: d = fUIf*i + fUIc
0041 
0042    Int_t     fLowLimit;  // Low  limit for Min/Max values (used by editor)
0043    Int_t     fHighLimit; // High limit for Min/Max values (used by editor)
0044    Int_t     fMinVal;
0045    Int_t     fMaxVal;
0046 
0047    Bool_t    fUIDoubleRep;    // Represent UI parts with real values.
0048    Bool_t    fInterpolate;    // Interpolate colors for signal values.
0049    Bool_t    fShowDefValue;   // Flags whether signals with default value should be shown.
0050    Bool_t    fFixColorRange;  // If true, map palette to low/high limit otherwise to min/max value.
0051    Int_t     fUnderflowAction;
0052    Int_t     fOverflowAction;
0053 
0054    Color_t   fDefaultColor;   // Color for when value is not specified
0055    UChar_t   fDefaultRGBA[4];
0056    Color_t   fUnderColor;     // Underflow color
0057    UChar_t   fUnderRGBA[4];
0058    Color_t   fOverColor;      // Overflow color
0059    UChar_t   fOverRGBA[4];
0060 
0061    mutable Int_t    fNBins;      // Number of signal-color entries.
0062    mutable Int_t    fCAMin;      // Minimal signal in color-array.
0063    mutable Int_t    fCAMax;      // Maximal signal in color-array.
0064    mutable UChar_t* fColorArray; //[4*fNBins]
0065 
0066    void SetupColor(Int_t val, UChar_t* pix) const;
0067 
0068    Double_t IntToDouble(Int_t i)    const { return fUIf*i + fUIc; }
0069    Int_t    DoubleToInt(Double_t d) const { return TMath::Nint((d - fUIc) / fUIf); }
0070 
0071    Double_t GetCAMinAsDouble() const { return IntToDouble(fCAMin); }
0072    Double_t GetCAMaxAsDouble() const { return IntToDouble(fCAMax); }
0073 
0074    static TEveRGBAPalette* fgDefaultPalette;
0075 
0076 public:
0077    TEveRGBAPalette();
0078    TEveRGBAPalette(Int_t min, Int_t max, Bool_t interp=kTRUE,
0079                    Bool_t showdef=kTRUE, Bool_t fixcolrng=kFALSE);
0080    ~TEveRGBAPalette() override;
0081 
0082    void SetupColorArray() const;
0083    void ClearColorArray();
0084 
0085    Bool_t   WithinVisibleRange(Int_t val) const;
0086    const UChar_t* ColorFromValue(Int_t val) const;
0087    void     ColorFromValue(Int_t val, UChar_t* pix, Bool_t alpha=kTRUE) const;
0088    Bool_t   ColorFromValue(Int_t val, Int_t defVal, UChar_t* pix, Bool_t alpha=kTRUE) const;
0089 
0090    Int_t  GetMinVal() const { return fMinVal; }
0091    Int_t  GetMaxVal() const { return fMaxVal; }
0092 
0093    void   SetLimits(Int_t low, Int_t high);
0094    void   SetLimitsScaleMinMax(Int_t low, Int_t high);
0095    void   SetMinMax(Int_t min, Int_t max);
0096    void   SetMin(Int_t min);
0097    void   SetMax(Int_t max);
0098 
0099    Int_t  GetLowLimit()  const { return fLowLimit;  }
0100    Int_t  GetHighLimit() const { return fHighLimit; }
0101 
0102    // ================================================================
0103 
0104    Bool_t GetUIDoubleRep() const { return fUIDoubleRep; }
0105    void   SetUIDoubleRep(Bool_t b, Double_t f=1, Double_t c=0);
0106 
0107    Bool_t GetInterpolate() const { return fInterpolate; }
0108    void   SetInterpolate(Bool_t b);
0109 
0110    Bool_t GetShowDefValue() const { return fShowDefValue; }
0111    void   SetShowDefValue(Bool_t v) { fShowDefValue = v; }
0112 
0113    Bool_t GetFixColorRange() const { return fFixColorRange; }
0114    void   SetFixColorRange(Bool_t v);
0115 
0116    Int_t GetUnderflowAction() const  { return fUnderflowAction; }
0117    Int_t GetOverflowAction()  const  { return fOverflowAction;  }
0118    void  SetUnderflowAction(Int_t a) { fUnderflowAction = a;    }
0119    void  SetOverflowAction(Int_t a)  { fOverflowAction  = a;    }
0120 
0121    // ================================================================
0122 
0123    Color_t  GetDefaultColor() const { return fDefaultColor; }
0124    Color_t* PtrDefaultColor() { return &fDefaultColor; }
0125    UChar_t* GetDefaultRGBA()  { return fDefaultRGBA;  }
0126    const UChar_t* GetDefaultRGBA() const { return fDefaultRGBA;  }
0127 
0128    void   SetDefaultColor(Color_t ci);
0129    void   SetDefaultColorPixel(Pixel_t pix);
0130    void   SetDefaultColorRGBA(UChar_t r, UChar_t g, UChar_t b, UChar_t a=255);
0131 
0132    // ----------------------------------------------------------------
0133 
0134    Color_t  GetUnderColor() const { return fUnderColor; }
0135    Color_t* PtrUnderColor() { return &fUnderColor; }
0136    UChar_t* GetUnderRGBA()  { return fUnderRGBA;  }
0137    const UChar_t* GetUnderRGBA() const { return fUnderRGBA;  }
0138 
0139    void   SetUnderColor(Color_t ci);
0140    void   SetUnderColorPixel(Pixel_t pix);
0141    void   SetUnderColorRGBA(UChar_t r, UChar_t g, UChar_t b, UChar_t a=255);
0142 
0143    // ----------------------------------------------------------------
0144 
0145    Color_t  GetOverColor() const { return fOverColor; }
0146    Color_t* PtrOverColor() { return &fOverColor; }
0147    UChar_t* GetOverRGBA()  { return fOverRGBA;  }
0148    const UChar_t* GetOverRGBA() const { return fOverRGBA;  }
0149 
0150    void   SetOverColor(Color_t ci);
0151    void   SetOverColorPixel(Pixel_t pix);
0152    void   SetOverColorRGBA(UChar_t r, UChar_t g, UChar_t b, UChar_t a=255);
0153 
0154    void OnZeroRefCount() override { delete this; }
0155 
0156    // ================================================================
0157 
0158    void MinMaxValChanged(); // *SIGNAL*
0159 
0160    ClassDefOverride(TEveRGBAPalette, 0); // A generic, speed-optimised mapping from value to RGBA color supporting different wrapping and range truncation modes.
0161 };
0162 
0163 
0164 /******************************************************************************/
0165 // Inlines for TEveRGBAPalette
0166 /******************************************************************************/
0167 
0168 //______________________________________________________________________________
0169 inline Bool_t TEveRGBAPalette::WithinVisibleRange(Int_t val) const
0170 {
0171    if ((val < fMinVal && fUnderflowAction == kLA_Cut) ||
0172        (val > fMaxVal && fOverflowAction  == kLA_Cut))
0173       return kFALSE;
0174    else
0175       return kTRUE;
0176 }
0177 
0178 //______________________________________________________________________________
0179 inline const UChar_t* TEveRGBAPalette::ColorFromValue(Int_t val) const
0180 {
0181    // Here we expect that kLA_Cut has been checked; we further check
0182    // for kLA_Wrap and kLA_Clip otherwise we proceed as for kLA_Mark.
0183 
0184    if (!fColorArray)  SetupColorArray();
0185 
0186    if (val < fMinVal)
0187    {
0188       if (fUnderflowAction == kLA_Wrap)
0189          val = (val+1-fCAMin)%fNBins + fCAMax;
0190       else if (fUnderflowAction == kLA_Clip)
0191          val = fMinVal;
0192       else
0193          return fUnderRGBA;
0194    }
0195    else if(val > fMaxVal)
0196    {
0197       if (fOverflowAction == kLA_Wrap)
0198          val = (val-1-fCAMax)%fNBins + fCAMin;
0199       else if (fOverflowAction == kLA_Clip)
0200          val = fMaxVal;
0201       else
0202          return fOverRGBA;
0203    }
0204 
0205    return fColorArray + 4 * (val - fCAMin);
0206 }
0207 
0208 //______________________________________________________________________________
0209 inline void TEveRGBAPalette::ColorFromValue(Int_t val, UChar_t* pix, Bool_t alpha) const
0210 {
0211    const UChar_t* c = ColorFromValue(val);
0212    pix[0] = c[0]; pix[1] = c[1]; pix[2] = c[2];
0213    if (alpha) pix[3] = c[3];
0214 }
0215 
0216 //______________________________________________________________________________
0217 inline Bool_t TEveRGBAPalette::ColorFromValue(Int_t val, Int_t defVal, UChar_t* pix, Bool_t alpha) const
0218 {
0219    if (val == defVal) {
0220       if (fShowDefValue) {
0221          pix[0] = fDefaultRGBA[0];
0222          pix[1] = fDefaultRGBA[1];
0223          pix[2] = fDefaultRGBA[2];
0224          if (alpha) pix[3] = fDefaultRGBA[3];
0225          return kTRUE;
0226       } else {
0227          return kFALSE;
0228       }
0229    }
0230 
0231    if (WithinVisibleRange(val)) {
0232       ColorFromValue(val, pix, alpha);
0233       return kTRUE;
0234    } else {
0235       return kFALSE;
0236    }
0237 }
0238 
0239 #endif