]>
Commit | Line | Data |
---|---|---|
8373e543 | 1 | // $Header$ |
2 | ||
3 | #include "RGBAPalette.h" | |
4 | ||
5 | #include <TColor.h> | |
6 | #include <TStyle.h> | |
7 | ||
8 | using namespace Reve; | |
9 | ||
10 | //______________________________________________________________________ | |
11 | // RGBAPalette | |
12 | // | |
13 | ||
14 | ClassImp(RGBAPalette) | |
15 | ||
16 | RGBAPalette::RGBAPalette() : | |
17 | TObject(), | |
18 | Reve::ReferenceCount(), | |
19 | fCutLow (kTRUE), | |
20 | fCutHigh (kFALSE), | |
21 | fInterpolate (kFALSE), | |
22 | fWrap (kFALSE), | |
23 | fColorArray (0) | |
24 | { | |
25 | SetLimits(0, 1000); | |
26 | SetMinMax(0, 100); | |
27 | } | |
28 | ||
29 | RGBAPalette::RGBAPalette(Int_t min, Int_t max) : | |
30 | TObject(), | |
31 | Reve::ReferenceCount(), | |
32 | fCutLow (kTRUE), | |
33 | fCutHigh (kFALSE), | |
34 | fInterpolate (kFALSE), | |
35 | fWrap (kFALSE), | |
36 | fColorArray (0) | |
37 | { | |
38 | SetLimits(0, 1000); | |
39 | SetMinMax(min, max); | |
40 | } | |
41 | ||
42 | RGBAPalette::RGBAPalette(Int_t min, Int_t max, Bool_t interp, Bool_t wrap) : | |
43 | TObject(), | |
44 | Reve::ReferenceCount(), | |
45 | fInterpolate (interp), | |
46 | fWrap (wrap), | |
47 | fColorArray (0) | |
48 | { | |
49 | SetLimits(0, 1023); | |
50 | SetMinMax(min, max); | |
51 | } | |
52 | ||
53 | RGBAPalette::~RGBAPalette() | |
54 | { | |
55 | delete [] fColorArray; | |
56 | } | |
57 | ||
58 | /**************************************************************************/ | |
59 | ||
60 | void RGBAPalette::SetupColor(Int_t val, UChar_t* pixel) const | |
61 | { | |
62 | using namespace TMath; | |
63 | Float_t div = Max(1, fMaxVal - fMinVal); | |
64 | Int_t nCol = gStyle->GetNumberOfColors(); | |
65 | ||
66 | Float_t f; | |
67 | if (val >= fMaxVal) f = nCol - 1; | |
68 | else if (val <= fMinVal) f = 0; | |
69 | else f = (val - fMinVal)/div*(nCol - 1); | |
70 | ||
71 | if (fInterpolate) { | |
72 | Int_t bin = (Int_t) f; | |
73 | Float_t f1 = f - bin, f2 = 1.0f - f1; | |
74 | ColorFromIdx(f1, gStyle->GetColorPalette(bin), | |
75 | f2, gStyle->GetColorPalette(Min(bin + 1, nCol - 1)), | |
76 | pixel); | |
77 | } else { | |
78 | ColorFromIdx(gStyle->GetColorPalette((Int_t) Nint(f)), pixel); | |
79 | } | |
80 | } | |
81 | ||
82 | void RGBAPalette::SetupColorArray() const | |
83 | { | |
84 | if(fColorArray) // !!!! should reinit anyway, maybe palette in gstyle changed | |
85 | return; | |
86 | ||
87 | // !!!! probably should store original palette for editing ... | |
88 | ||
89 | fColorArray = new UChar_t [4 * fNBins]; | |
90 | UChar_t* p = fColorArray; | |
91 | for(Int_t v=fMinVal; v<=fMaxVal; ++v, p+=4) | |
92 | SetupColor(v, p); | |
93 | } | |
94 | ||
95 | void RGBAPalette::ClearColorArray() | |
96 | { | |
97 | if(fColorArray) { | |
98 | delete [] fColorArray; | |
99 | fColorArray = 0; | |
100 | } | |
101 | } | |
102 | ||
103 | /**************************************************************************/ | |
104 | ||
105 | void RGBAPalette::SetLimits(Int_t low, Int_t high) | |
106 | { | |
107 | fLowLimit = low; | |
108 | fHighLimit = high; | |
109 | if (fMaxVal < fLowLimit) SetMax(fLowLimit); | |
110 | if (fMinVal < fLowLimit) SetMin(fLowLimit); | |
111 | if (fMinVal > fHighLimit) SetMin(fHighLimit); | |
112 | if (fMaxVal > fHighLimit) SetMax(fHighLimit); | |
113 | ||
114 | } | |
115 | ||
116 | void RGBAPalette::SetMin(Int_t min) | |
117 | { | |
118 | fMinVal = TMath::Min(min, fMaxVal); | |
119 | fNBins = fMaxVal - fMinVal + 1; | |
120 | ClearColorArray(); | |
121 | } | |
122 | ||
123 | void RGBAPalette::SetMax(Int_t max) | |
124 | { | |
125 | fMaxVal = TMath::Max(max, fMinVal); | |
126 | fNBins = fMaxVal - fMinVal + 1; | |
127 | ClearColorArray(); | |
128 | } | |
129 | ||
130 | void RGBAPalette::SetMinMax(Int_t min, Int_t max) | |
131 | { | |
132 | fMinVal = min; | |
133 | fMaxVal = max; | |
134 | fNBins = fMaxVal - fMinVal + 1; | |
135 | ClearColorArray(); | |
136 | } | |
137 | ||
138 | void RGBAPalette::SetInterpolate(Bool_t b) | |
139 | { | |
140 | fInterpolate = b; | |
141 | ClearColorArray(); | |
142 | } | |
143 | ||
144 | void RGBAPalette::SetWrap(Bool_t b) | |
145 | { | |
146 | fWrap = b; | |
147 | } | |
148 | ||
149 | /**************************************************************************/ | |
150 | ||
151 | void RGBAPalette::SetDefaultColor(Color_t ci) | |
152 | { | |
153 | fDefaultColor = ci; | |
154 | ColorFromIdx(ci, fDefaultRGBA, kTRUE); | |
155 | } | |
156 | ||
157 | void RGBAPalette::SetDefaultColor(Pixel_t pix) | |
158 | { | |
159 | SetDefaultColor(Color_t(TColor::GetColor(pix))); | |
160 | } | |
161 | ||
162 | void RGBAPalette::SetDefaultColor(UChar_t r, UChar_t g, UChar_t b, UChar_t a) | |
163 | { | |
164 | fDefaultColor = Color_t(TColor::GetColor(r, g, b)); | |
165 | fDefaultRGBA[0] = r; | |
166 | fDefaultRGBA[1] = g; | |
167 | fDefaultRGBA[2] = b; | |
168 | fDefaultRGBA[3] = a; | |
169 | } |