Logo ROOT   6.10/09
Reference Guide
TEveRGBAPalette.h
Go to the documentation of this file.
1 // @(#)root/eve:$Id$
2 // Authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2007, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #ifndef ROOT_TEveRGBAPalette
13 #define ROOT_TEveRGBAPalette
14 
15 #include "TEveUtil.h"
16 
17 #include "TObject.h"
18 #include "TQObject.h"
19 
20 #include "TMath.h"
21 
22 class TEveRGBAPalette : public TObject,
23  public TQObject,
24  public TEveRefCnt
25 {
26  friend class TEveRGBAPaletteEditor;
28 
29  friend class TEveRGBAPaletteOverlay;
30 
31 public:
33 
34 private:
35  TEveRGBAPalette(const TEveRGBAPalette&); // Not implemented
36  TEveRGBAPalette& operator=(const TEveRGBAPalette&); // Not implemented
37 
38 protected:
39  Double_t fUIf; // UI representation calculated as: d = fUIf*i + fUIc
40  Double_t fUIc; // UI representation calculated as: d = fUIf*i + fUIc
41 
42  Int_t fLowLimit; // Low limit for Min/Max values (used by editor)
43  Int_t fHighLimit; // High limit for Min/Max values (used by editor)
46 
47  Bool_t fUIDoubleRep; // Represent UI parts with real values.
48  Bool_t fInterpolate; // Interpolate colors for signal values.
49  Bool_t fShowDefValue; // Flags whether signals with default value should be shown.
50  Bool_t fFixColorRange; // If true, map palette to low/high limit otherwise to min/max value.
53 
54  Color_t fDefaultColor; // Color for when value is not specified
56  Color_t fUnderColor; // Underflow color
58  Color_t fOverColor; // Overflow color
60 
61  mutable Int_t fNBins; // Number of signal-color entries.
62  mutable Int_t fCAMin; // Minimal signal in color-array.
63  mutable Int_t fCAMax; // Maximal signal in color-array.
64  mutable UChar_t* fColorArray; //[4*fNBins]
65 
66  void SetupColor(Int_t val, UChar_t* pix) const;
67 
68  Double_t IntToDouble(Int_t i) const { return fUIf*i + fUIc; }
69  Int_t DoubleToInt(Double_t d) const { return TMath::Nint((d - fUIc) / fUIf); }
70 
71  Double_t GetCAMinAsDouble() const { return IntToDouble(fCAMin); }
72  Double_t GetCAMaxAsDouble() const { return IntToDouble(fCAMax); }
73 
75 
76 public:
78  TEveRGBAPalette(Int_t min, Int_t max, Bool_t interp=kTRUE,
79  Bool_t showdef=kTRUE, Bool_t fixcolrng=kFALSE);
80  virtual ~TEveRGBAPalette();
81 
82  void SetupColorArray() const;
83  void ClearColorArray();
84 
85  Bool_t WithinVisibleRange(Int_t val) const;
86  const UChar_t* ColorFromValue(Int_t val) const;
87  void ColorFromValue(Int_t val, UChar_t* pix, Bool_t alpha=kTRUE) const;
88  Bool_t ColorFromValue(Int_t val, Int_t defVal, UChar_t* pix, Bool_t alpha=kTRUE) const;
89 
90  Int_t GetMinVal() const { return fMinVal; }
91  Int_t GetMaxVal() const { return fMaxVal; }
92 
93  void SetLimits(Int_t low, Int_t high);
94  void SetLimitsScaleMinMax(Int_t low, Int_t high);
95  void SetMinMax(Int_t min, Int_t max);
96  void SetMin(Int_t min);
97  void SetMax(Int_t max);
98 
99  Int_t GetLowLimit() const { return fLowLimit; }
100  Int_t GetHighLimit() const { return fHighLimit; }
101 
102  // ================================================================
103 
104  Bool_t GetUIDoubleRep() const { return fUIDoubleRep; }
105  void SetUIDoubleRep(Bool_t b, Double_t f=1, Double_t c=0);
106 
107  Bool_t GetInterpolate() const { return fInterpolate; }
108  void SetInterpolate(Bool_t b);
109 
111  void SetShowDefValue(Bool_t v) { fShowDefValue = v; }
112 
114  void SetFixColorRange(Bool_t v);
115 
118  void SetUnderflowAction(Int_t a) { fUnderflowAction = a; }
119  void SetOverflowAction(Int_t a) { fOverflowAction = a; }
120 
121  // ================================================================
122 
126  const UChar_t* GetDefaultRGBA() const { return fDefaultRGBA; }
127 
128  void SetDefaultColor(Color_t ci);
129  void SetDefaultColorPixel(Pixel_t pix);
131 
132  // ----------------------------------------------------------------
133 
134  Color_t GetUnderColor() const { return fUnderColor; }
137  const UChar_t* GetUnderRGBA() const { return fUnderRGBA; }
138 
139  void SetUnderColor(Color_t ci);
140  void SetUnderColorPixel(Pixel_t pix);
141  void SetUnderColorRGBA(UChar_t r, UChar_t g, UChar_t b, UChar_t a=255);
142 
143  // ----------------------------------------------------------------
144 
145  Color_t GetOverColor() const { return fOverColor; }
148  const UChar_t* GetOverRGBA() const { return fOverRGBA; }
149 
150  void SetOverColor(Color_t ci);
151  void SetOverColorPixel(Pixel_t pix);
152  void SetOverColorRGBA(UChar_t r, UChar_t g, UChar_t b, UChar_t a=255);
153 
154  // ================================================================
155 
156  void MinMaxValChanged(); // *SIGNAL*
157 
158  ClassDef(TEveRGBAPalette, 0); // A generic, speed-optimised mapping from value to RGBA color supporting different wrapping and range truncation modes.
159 };
160 
161 
162 /******************************************************************************/
163 // Inlines for TEveRGBAPalette
164 /******************************************************************************/
165 
166 //______________________________________________________________________________
168 {
169  if ((val < fMinVal && fUnderflowAction == kLA_Cut) ||
170  (val > fMaxVal && fOverflowAction == kLA_Cut))
171  return kFALSE;
172  else
173  return kTRUE;
174 }
175 
176 //______________________________________________________________________________
178 {
179  // Here we expect that kLA_Cut has been checked; we further check
180  // for kLA_Wrap and kLA_Clip otherwise we proceed as for kLA_Mark.
181 
183 
184  if (val < fMinVal)
185  {
186  if (fUnderflowAction == kLA_Wrap)
187  val = (val+1-fCAMin)%fNBins + fCAMax;
188  else if (fUnderflowAction == kLA_Clip)
189  val = fMinVal;
190  else
191  return fUnderRGBA;
192  }
193  else if(val > fMaxVal)
194  {
195  if (fOverflowAction == kLA_Wrap)
196  val = (val-1-fCAMax)%fNBins + fCAMin;
197  else if (fOverflowAction == kLA_Clip)
198  val = fMaxVal;
199  else
200  return fOverRGBA;
201  }
202 
203  return fColorArray + 4 * (val - fCAMin);
204 }
205 
206 //______________________________________________________________________________
207 inline void TEveRGBAPalette::ColorFromValue(Int_t val, UChar_t* pix, Bool_t alpha) const
208 {
209  const UChar_t* c = ColorFromValue(val);
210  pix[0] = c[0]; pix[1] = c[1]; pix[2] = c[2];
211  if (alpha) pix[3] = c[3];
212 }
213 
214 //______________________________________________________________________________
215 inline Bool_t TEveRGBAPalette::ColorFromValue(Int_t val, Int_t defVal, UChar_t* pix, Bool_t alpha) const
216 {
217  if (val == defVal) {
218  if (fShowDefValue) {
219  pix[0] = fDefaultRGBA[0];
220  pix[1] = fDefaultRGBA[1];
221  pix[2] = fDefaultRGBA[2];
222  if (alpha) pix[3] = fDefaultRGBA[3];
223  return kTRUE;
224  } else {
225  return kFALSE;
226  }
227  }
228 
229  if (WithinVisibleRange(val)) {
230  ColorFromValue(val, pix, alpha);
231  return kTRUE;
232  } else {
233  return kFALSE;
234  }
235 }
236 
237 #endif
void SetUnderColor(Color_t ci)
Set underflow color.
Int_t GetUnderflowAction() const
A generic, speed-optimised mapping from value to RGBA color supporting different wrapping and range t...
Bool_t GetInterpolate() const
void SetUnderColorRGBA(UChar_t r, UChar_t g, UChar_t b, UChar_t a=255)
Set underflow color.
Double_t IntToDouble(Int_t i) const
This is the ROOT implementation of the Qt object communication mechanism (see also http://www...
Definition: TQObject.h:49
Description of TEveRGBAPaletteOverlay.
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
TArc * a
Definition: textangle.C:12
Color_t * PtrOverColor()
UChar_t * GetOverRGBA()
void SetOverColorRGBA(UChar_t r, UChar_t g, UChar_t b, UChar_t a=255)
Set overflow color.
void SetOverflowAction(Int_t a)
Int_t GetMinVal() const
void ClearColorArray()
Clear internal color array.
#define ClassDef(name, id)
Definition: Rtypes.h:297
void SetFixColorRange(Bool_t v)
Set flag specifying how the palette is mapped to signal values: true - LowLimit -> HighLimit false - ...
ULong_t Pixel_t
Definition: GuiTypes.h:39
const UChar_t * GetUnderRGBA() const
Color_t * PtrUnderColor()
UChar_t fOverRGBA[4]
void SetLimitsScaleMinMax(Int_t low, Int_t high)
Set low/high limits and rescale current min/max values.
void SetDefaultColorPixel(Pixel_t pix)
Set default color.
const UChar_t * ColorFromValue(Int_t val) const
short Color_t
Definition: RtypesCore.h:79
void SetupColorArray() const
Construct internal color array that maps signal value to RGBA color.
Bool_t GetFixColorRange() const
void SetDefaultColor(Color_t ci)
Set default color.
Sub-editor for TEveRGBAPalette class.
void SetMin(Int_t min)
Set current min value.
TRandom2 r(17)
UChar_t * fColorArray
SVector< double, 2 > v
Definition: Dict.h:5
void SetShowDefValue(Bool_t v)
void SetMinMax(Int_t min, Int_t max)
Set current min/max values.
Color_t GetDefaultColor() const
Base-class for reference-counted objects.
Definition: TEveUtil.h:163
void SetMax(Int_t max)
Set current max value.
void SetOverColor(Color_t ci)
Set overflow color.
Int_t GetMaxVal() const
Color_t GetUnderColor() const
Int_t GetLowLimit() const
const Bool_t kFALSE
Definition: RtypesCore.h:92
double f(double x)
double Double_t
Definition: RtypesCore.h:55
Editor for TEveRGBAPalette class.
Int_t GetHighLimit() const
Color_t GetOverColor() const
TEveRGBAPalette & operator=(const TEveRGBAPalette &)
void SetUIDoubleRep(Bool_t b, Double_t f=1, Double_t c=0)
Set flag determining whether GUI editor and overlays should show limits and axis values as real value...
Int_t GetOverflowAction() const
Bool_t GetUIDoubleRep() const
Double_t GetCAMaxAsDouble() const
Mother of all ROOT objects.
Definition: TObject.h:37
const UChar_t * GetOverRGBA() const
void SetInterpolate(Bool_t b)
Set interpolation flag.
TEveRGBAPalette()
Constructor.
void SetDefaultColorRGBA(UChar_t r, UChar_t g, UChar_t b, UChar_t a=255)
Set default color.
void SetLimits(Int_t low, Int_t high)
Set low/high limits on signal value.
UChar_t fUnderRGBA[4]
void SetupColor(Int_t val, UChar_t *pix) const
Set RGBA color &#39;pixel&#39; for signal-value &#39;val&#39;.
void MinMaxValChanged()
Emit the "MinMaxValChanged()" signal.
you should not use this method at all Int_t Int_t Double_t Double_t Double_t Int_t Double_t Double_t Double_t Double_t b
Definition: TRolke.cxx:630
void SetUnderflowAction(Int_t a)
Int_t DoubleToInt(Double_t d) const
const UChar_t * GetDefaultRGBA() const
Color_t * PtrDefaultColor()
unsigned char UChar_t
Definition: RtypesCore.h:34
UChar_t fDefaultRGBA[4]
static TEveRGBAPalette * fgDefaultPalette
Double_t GetCAMinAsDouble() const
UChar_t * GetDefaultRGBA()
Bool_t WithinVisibleRange(Int_t val) const
void SetOverColorPixel(Pixel_t pix)
Set overflow color.
const Bool_t kTRUE
Definition: RtypesCore.h:91
Int_t Nint(T x)
Definition: TMath.h:607
virtual ~TEveRGBAPalette()
Destructor.
Bool_t GetShowDefValue() const
void SetUnderColorPixel(Pixel_t pix)
Set underflow color.
UChar_t * GetUnderRGBA()