CMS 3D CMS Logo

FWColorManager.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Core
4 // Class : FWColorManager
5 //
6 // Implementation:
7 // <Notes on implementation>
8 //
9 // Original Author: Chris Jones
10 // Created: Tue Mar 24 10:10:01 CET 2009
11 //
12 
13 // system include files
14 #include <iostream>
15 #include <map>
16 #include <memory>
17 #include "TColor.h"
18 #include "TROOT.h"
19 #include "TMath.h"
20 #include "TEveUtil.h"
21 #include "TEveManager.h"
22 #include "TGLViewer.h"
23 
24 // user include files
27 #include "Fireworks/Core/src/fwPaletteClassic.icc"
29 
30 
31 //
32 // constants, enums and typedefs
33 //
34 
35 //
36 // static data member definitions
37 //
38 const Color_t FWColorManager::s_defaultStartColorIndex = 1000;
40 
41 static
42 void resetColors(const float(* iColors)[3], unsigned int iSize, unsigned int iStart, float gammaOff )
43 {
44  // std::cout << "reset colors " << iColors << " start " << iStart << " size " << iSize<< " gamma " << gammaOff << std::endl;
45  TSeqCollection* colorTable = gROOT->GetListOfColors();
46 
47  TColor* c = static_cast<TColor*>(colorTable->At(iStart));
48  unsigned int index = iStart;
49  if(nullptr==c || c->GetNumber() != static_cast<int>(iStart)) {
50  TIter next(colorTable);
51  while( (c=static_cast<TColor*>( next() )) ) {
52  if(c->GetNumber()==static_cast<int>(iStart)) {
53  index = iStart;
54  break;
55  }
56  }
57  }
58  assert(nullptr!=c);
59 
60  for(unsigned int i = index; i< index+iSize; ++i,++iColors) {
61  TColor* c = static_cast<TColor*> (colorTable->At(i));
62  float red = (*iColors)[0];
63  float green = (*iColors)[1];
64  float blue = (*iColors)[2];
65 
66  // apply brightness
67  red = TMath::Power(red, (2.5 + gammaOff)/2.5);
68  green = TMath::Power(green, (2.5 + gammaOff)/2.5);
69  blue = TMath::Power(blue, (2.5 + gammaOff)/2.5);
70 
71  // printf("--> [%d] (%.1f, %.1f, %.1f) => \n", i, red, green, blue);
72  c->SetRGB(red,green,blue);
73  }
74 }
75 //
76 // constructors and destructor
77 //
80  m_gammaOff(0),
81  m_background(kBlack),
82  m_foreground(kWhite),
83  m_changeManager(iManager),
88 {
90 }
91 
93 {
94 }
95 
96 //
97 //
98 // member functions
99 
101 {
104 
107 
110 
114 
115  switch (m_paletteId) {
116  case (kArctic):
117  // m_geomColor[kFWMuonBarrelLineColorIndex] = 1027;
118  //m_geomColor[kFWMuonEndcapLineColorIndex] = 1027;
119  break;
120  case (kFall):
122  break;
123  case (kSpring):
126  break;
127  case (kPurple):
128  m_geomColor[kFWMuonBarrelLineColorIndex] = 1027; //kBlue -1;
130  break;
131  default:
132  break;
133  }
134 }
135 
137 {
139  m_numColorIndices = fireworks::s_size;
140 
141  int index = m_startColorIndex;
142  //std::cout <<"start color index "<<m_startColorIndex<<std::endl;
143 
144  const float(* itEnd)[3] = fireworks::s_forBlack+fireworks::s_size;
145  for(const float(* it)[3] = fireworks::s_forBlack;
146  it != itEnd;
147  ++it) {
148  //NOTE: this constructor automatically places this color into the gROOT color list
149  //std::cout <<" color "<< index <<" "<<(*it)[0]<<" "<<(*it)[1]<<" "<<(*it)[2]<<std::endl;
150  if ( index <= gROOT->GetListOfColors()->GetLast())
151  gROOT->GetListOfColors()->RemoveAt(index);
152  new TColor(index++,(*it)[0],(*it)[1],(*it)[2]);
153  }
154 
155  // Save default ROOT colors.
156  TEveUtil::SetColorBrightness(0, kFALSE);
157 }
158 
160 {
162  m_paletteId = (EPalette)x;
164  initColorTable();
165 }
166 
167 
168 
169 
170 void
172 {
173  const float(* colValues)[3];
174  colValues = isColorSetLight() ? fireworks::s_forWhite : fireworks::s_forBlack;
175  if (m_paletteId == EPalette::kClassic)
176  {
177  // std::cout << "initColorTable classic \n";
178  resetColors(colValues, fireworks::s_size, m_startColorIndex, m_gammaOff);
179  }
180  else {
181  // std::cout << "initColorTable extra \n";
182  float (*ev)[3] = (float (*)[3])calloc(3*fireworks::s_size, sizeof (float));
183  for (int ci = 0; ci < 34; ++ci) {
184  for (int j = 0; j < 3; ++j)
185  ev[ci][j] = colValues[ci][j];
186 
187  }
189  resetColors(ev, fireworks::s_size, m_startColorIndex, m_gammaOff);
190  }
191 
192  // AMT: Commented out ... Why this is necessary ?
193  //float eveGamma = isColorSetLight() ? 1.666*m_gammaOff - 2.5 : 1.666*m_gammaOff;
194  //TEveUtil::SetColorBrightness(eveGamma);
195 }
196 
198 {
199  initColorTable();
201 }
202 
204 {
209 }
210 
211 void
213 {
214  // Called from CmsShowBrightnessPopup slider where range is set
215  // to: -15, 15.
216  m_gammaOff = -b*0.1f;
217  updateColors();
218 }
219 
220 int
222 {
223  return TMath::FloorNint(-m_gammaOff*10);
224 }
225 
226 void
228 {
229  m_gammaOff = 0;
230  updateColors();
231 }
232 
233 void
235 {
237 }
238 
239 void
241 {
242  if(backgroundColorIndex()!=iIndex) {
246  } else {
249  }
250  updateColors();
251  }
252 }
253 
254 void
256 {
257  m_gammaOff = -b*0.1f;
258  setBackgroundColorIndex(iIndex);
259 }
260 
261 Bool_t
262 FWColorManager::setColorSetViewer(TGLViewer* v, Color_t iColor)
263 {
264  if ( (iColor == kBlackIndex && !v->IsColorSetDark()) ||
265  (iColor == kWhiteIndex && v->IsColorSetDark()) )
266  {
267  v->SwitchColorSet();
268  return kTRUE;
269  }
270  return kFALSE;
271 }
272 
273 void
275 {
276  // printf("set geom color %d \n", iColor);
277  m_geomColor[idx] = iColor;
279  gEve->Redraw3D();
280 }
281 void
282 FWColorManager::setGeomTransparency(Color_t iTransp, bool projectedType)
283 {
284  if (projectedType)
285  m_geomTransparency2D = iTransp;
286  else
287  m_geomTransparency3D = iTransp;
288 
289  geomTransparencyHaveChanged_.emit(projectedType);
290 
291  gEve->Redraw3D();
292 }
293 
294 //
295 // const member functions
296 //
297 
298 
299 void
300 FWColorManager::fillLimitedColors(std::vector<Color_t>& cv) const
301 {
302  cv.reserve(cv.size() + m_numColorIndices);
303  for (Color_t i = m_startColorIndex; i < borderOfLimitedColors(); ++i)
304  {
305  cv.push_back(i);
306  }
307 }
308 
311 {
312  if(m_background==kBlack) {
313  return kBlackIndex;
314  }
315  return kWhiteIndex;
316 }
317 
318 bool
319 FWColorManager::colorHasIndex(Color_t iColor) const
320 {
321  return iColor > 0 && iColor < m_startColorIndex + m_numColorIndices;
322 }
323 
324 
325 Color_t
327 {
328  return m_geomColor[iIndex];
329 }
330 
331 
332 static std::shared_ptr<std::map<Color_t,Color_t> > m_oldColorToIndexMap;
333 
334 Color_t
335 FWColorManager::oldColorToIndex(Color_t iColor, int version) const
336 {
337  enum {
338  kFWRed = 1008,
339  kFWBlue = 1005,
340  kFWCyan = 1007,
341  kFWGreen = 1009,
342  kFWMagenta = 1001,
343  kFWOrange = 1004,
344  kFWYellow = 1000
345  };
346 
347  if (version < 3)
348  {
349  if(nullptr==m_oldColorToIndexMap.get()) {
350  m_oldColorToIndexMap = std::make_shared<std::map<Color_t,Color_t> >();
351  (*m_oldColorToIndexMap)[kRed]=kFWRed;
352  (*m_oldColorToIndexMap)[kBlue]=kFWBlue;
353  (*m_oldColorToIndexMap)[kYellow]=kFWYellow;
354  (*m_oldColorToIndexMap)[kGreen]=kFWGreen;
355  (*m_oldColorToIndexMap)[kCyan]=kFWCyan;
356  (*m_oldColorToIndexMap)[kTeal]=kFWCyan;
357  (*m_oldColorToIndexMap)[kMagenta]=kFWMagenta;
358  (*m_oldColorToIndexMap)[kViolet]=kFWMagenta;
359  (*m_oldColorToIndexMap)[kOrange]=kFWOrange;
360  (*m_oldColorToIndexMap)[3]=kFWGreen;
361 
362  }
363  return (*m_oldColorToIndexMap)[iColor];
364  }
365  else if (version == 3)
366  {
367  return iColor+ 1000;
368  }
369  else
370  {
371  const static unsigned int s_version45offset = 5;
372  return iColor < 1011 ? iColor : iColor + s_version45offset ;
373  }
374 }
Bool_t isColorSetLight() const
sigc::signal< void > geomColorsHaveChanged_
void setDefaultGeomColors()
static void resetColors(const float(*iColors)[3], unsigned int iSize, unsigned int iStart, float gammaOff)
static std::shared_ptr< std::map< Color_t, Color_t > > m_oldColorToIndexMap
FWGeomColorIndex
static Color_t getDefaultStartColorIndex()
void fillLimitedColors(std::vector< Color_t > &cv) const
bool ev
Color_t oldColorToIndex(Color_t, int version) const
cv
Definition: cuy.py:364
int borderOfLimitedColors() const
sigc::signal< void, bool > geomTransparencyHaveChanged_
Bool_t isColorSetDark() const
bool colorHasIndex(Color_t) const
void setGeomColor(FWGeomColorIndex, Color_t)
void setBackgroundColorIndex(BackgroundColorIndex)
virtual ~FWColorManager()
void setGeomTransparency(Color_t idx, bool projectedType)
EPalette m_paletteId
Char_t m_geomTransparency2D
FWModelChangeManager * m_changeManager
void setPalette(long long)
sigc::signal< void > colorsHaveChangedFinished_
Char_t m_geomTransparency3D
void defaultBrightness()
Color_t m_numColorIndices
Color_t m_foreground
BackgroundColorIndex backgroundColorIndex() const
void GetColorValuesForPaletteExtra(float(*iColors)[3], unsigned int iSize, FWColorManager::EPalette id, bool isWhiteBg)
Color_t m_geomColor[kFWGeomColorSize]
void setBrightness(int)
static const Color_t s_defaultStartColorIndex
def green(string)
double b
Definition: hdecay.h:120
void setBackgroundAndBrightness(BackgroundColorIndex, int)
void propagatePaletteChanges() const
static Bool_t setColorSetViewer(TGLViewer *, Color_t)
FWColorManager(FWModelChangeManager *)
Color_t m_startColorIndex
sigc::signal< void > colorsHaveChanged_
Color_t m_background
Color_t geomColor(FWGeomColorIndex) const