ROOT  6.06/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:
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);
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);
153 
154  // ================================================================
155 
156  void MinMaxValChanged(); // *SIGNAL*
157 
158  ClassDef(TEveRGBAPalette, 1); // 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.
Bool_t GetInterpolate() const
A generic, speed-optimised mapping from value to RGBA color supporting different wrapping and range t...
static Vc_ALWAYS_INLINE int_v min(const int_v &x, const int_v &y)
Definition: vector.h:433
void SetUnderColorRGBA(UChar_t r, UChar_t g, UChar_t b, UChar_t a=255)
Set underflow color.
ClassDef(TEveRGBAPalette, 1)
void SetupColor(Int_t val, UChar_t *pix) const
Set RGBA color 'pixel' for signal-value 'val'.
This is the ROOT implementation of the Qt object communication mechanism (see also http://www...
Definition: TQObject.h:53
Int_t DoubleToInt(Double_t d) const
Bool_t GetUIDoubleRep() const
Description of TEveRGBAPaletteOverlay.
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
Color_t GetUnderColor() const
TArc * a
Definition: textangle.C:12
const Bool_t kFALSE
Definition: Rtypes.h:92
Color_t * PtrOverColor()
Bool_t GetShowDefValue() const
Double_t IntToDouble(Int_t i) const
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)
void ClearColorArray()
Clear internal color array.
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:41
Color_t * PtrUnderColor()
Bool_t WithinVisibleRange(Int_t val) const
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.
short Color_t
Definition: RtypesCore.h:79
void SetDefaultColor(Color_t ci)
Set default color.
Sub-editor for TEveRGBAPalette class.
const UChar_t * ColorFromValue(Int_t val) const
void SetMin(Int_t min)
Set current min value.
ROOT::R::TRInterface & r
Definition: Object.C:4
UChar_t * fColorArray
SVector< double, 2 > v
Definition: Dict.h:5
Int_t GetMaxVal() const
Color_t GetDefaultColor() const
void SetShowDefValue(Bool_t v)
void SetMinMax(Int_t min, Int_t max)
Set current min/max values.
Int_t GetMinVal() const
const UChar_t * GetOverRGBA() const
Int_t GetLowLimit() const
Base-class for reference-counted objects.
Definition: TEveUtil.h:163
void SetupColorArray() const
Construct internal color array that maps signal value to RGBA color.
void SetMax(Int_t max)
Set current max value.
void SetOverColor(Color_t ci)
Set overflow color.
const UChar_t * GetUnderRGBA() const
Int_t GetUnderflowAction() const
Color_t GetOverColor() const
Int_t GetOverflowAction() const
double f(double x)
double Double_t
Definition: RtypesCore.h:55
Editor for TEveRGBAPalette class.
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...
static Vc_ALWAYS_INLINE int_v max(const int_v &x, const int_v &y)
Definition: vector.h:440
Mother of all ROOT objects.
Definition: TObject.h:58
void SetInterpolate(Bool_t b)
Set interpolation flag.
TEveRGBAPalette()
Constructor.
const UChar_t * GetDefaultRGBA() const
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]
Double_t GetCAMaxAsDouble() const
Int_t GetHighLimit() const
void MinMaxValChanged()
Emit the "MinMaxValChanged()" signal.
void SetUnderflowAction(Int_t a)
Color_t * PtrDefaultColor()
unsigned char UChar_t
Definition: RtypesCore.h:34
Double_t GetCAMinAsDouble() const
UChar_t fDefaultRGBA[4]
static TEveRGBAPalette * fgDefaultPalette
const Bool_t kTRUE
Definition: Rtypes.h:91
UChar_t * GetDefaultRGBA()
void SetOverColorPixel(Pixel_t pix)
Set overflow color.
Int_t Nint(T x)
Definition: TMath.h:480
Bool_t GetFixColorRange() const
virtual ~TEveRGBAPalette()
Destructor.
void SetUnderColorPixel(Pixel_t pix)
Set underflow color.
UChar_t * GetUnderRGBA()