TEveRGBAPalette.h

Go to the documentation of this file.
00001 // @(#)root/eve:$Id: TEveRGBAPalette.h 30823 2009-10-21 13:58:59Z matevz $
00002 // Authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2007, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
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&);            // Not implemented
00032    TEveRGBAPalette& operator=(const TEveRGBAPalette&); // Not implemented
00033 
00034 protected:
00035    Int_t     fLowLimit;  // Low  limit for Min/Max values (used by editor)
00036    Int_t     fHighLimit; // High limit for Min/Max values (used by editor)
00037    Int_t     fMinVal;
00038    Int_t     fMaxVal;
00039 
00040    Bool_t    fInterpolate;    // Interpolate colors for signal values.
00041    Bool_t    fShowDefValue;   // Flags whether signals with default value should be shown.
00042    Bool_t    fFixColorRange;  // If true, map palette to low/high limit otherwise to min/max value.
00043    Int_t     fUnderflowAction;
00044    Int_t     fOverflowAction;
00045 
00046    Color_t   fDefaultColor;   // Color for when value is not specified
00047    UChar_t   fDefaultRGBA[4];
00048    Color_t   fUnderColor;     // Underflow color
00049    UChar_t   fUnderRGBA[4];
00050    Color_t   fOverColor;      // Overflow color
00051    UChar_t   fOverRGBA[4];
00052 
00053    mutable Int_t    fNBins;      // Number of signal-color entries.
00054    mutable Int_t    fCAMin;      // Minimal signal in color-array.
00055    mutable Int_t    fCAMax;      // Maximal signal in color-array.
00056    mutable UChar_t* fColorArray; //[4*fNBins]
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(); // *SIGNAL*
00140 
00141    ClassDef(TEveRGBAPalette, 1); // A generic, speed-optimised mapping from value to RGBA color supporting different wrapping and range truncation modes.
00142 };
00143 
00144 
00145 /******************************************************************************/
00146 // Inlines for TEveRGBAPalette
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    // Here we expect that kLA_Cut has been checked; we further check
00163    // for kLA_Wrap and kLA_Clip otherwise we proceed as for kLA_Mark.
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

Generated on Tue Jul 5 14:14:59 2011 for ROOT_528-00b_version by  doxygen 1.5.1