00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include <iostream>
00016 #include <map>
00017 #include <boost/shared_ptr.hpp>
00018 #include "TColor.h"
00019 #include "TROOT.h"
00020 #include "TMath.h"
00021 #include "TEveUtil.h"
00022 #include "TEveManager.h"
00023 #include "TGLViewer.h"
00024
00025
00026 #include "Fireworks/Core/interface/FWColorManager.h"
00027 #include "Fireworks/Core/interface/FWModelChangeManager.h"
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 const Color_t FWColorManager::s_defaultStartColorIndex = 1000;
00040 Color_t FWColorManager::getDefaultStartColorIndex() { return s_defaultStartColorIndex; }
00041
00042 enum {
00043 kFWRed = 1008,
00044 kFWBlue = 1005,
00045 kFWCyan = 1007,
00046 kFWGreen = 1009,
00047 kFWMagenta = 1001,
00048 kFWOrange = 1004,
00049 kFWYellow = 1000
00050 };
00051
00052 static const float s_forWhite[][3] ={
00053 { 0.79, 0.79, 0.12 },
00054 { 0.47, 0.00, 0.64 },
00055 { 0.98, 0.70, 0.00 },
00056 { 0.18, 0.00, 0.59 },
00057 { 0.98, 0.54, 0.00 },
00058 { 0.00, 0.11, 1.00 },
00059 { 0.99, 0.26, 0.01 },
00060 { 0.00, 0.80, 0.78 },
00061 { 1.00, 0.06, 0.00 },
00062 { 0.33, 0.64, 0.14 },
00063 { 0.60, 0.06, 0.23 },
00064 { 0.65, 0.92, 0.17 },
00065 { 0.00, 0.46, 1.00 },
00066 { 1.00, 0.00, 0.40 },
00067 { 0.02, 1.00, 0.40 },
00068 { 0.40, 0.40, 0.40 },
00069 { 0.00, 0.00, 0.00 },
00070
00071 { 0.85, 0.85, 0.58 },
00072 { 0.87, 0.72, 0.92 },
00073 { 0.99, 0.88, 0.59 },
00074 { 0.79, 0.72, 0.90 },
00075 { 1.00, 0.82, 0.59 },
00076 { 0.71, 0.75, 0.99 },
00077 { 1.00, 0.80, 0.72 },
00078 { 0.71, 0.98, 0.95 },
00079 { 0.99, 0.74, 0.70 },
00080 { 0.77, 0.86, 0.65 },
00081 { 0.90, 0.74, 0.79 },
00082 { 0.67, 0.95, 0.52 },
00083 { 0.57, 0.78, 1.00 },
00084 { 1.00, 0.57, 0.74 },
00085 { 0.73, 1.00, 0.83 },
00086 { 0.80, 0.80, 0.80 },
00087 { 0.60, 0.60, 0.60 }
00088 };
00089
00090 static const float s_forBlack[][3] ={
00091 { 1.00, 1.00, 0.20 },
00092 { 0.53, 0.00, 0.69 },
00093 { 0.98, 0.74, 0.01 },
00094 { 0.24, 0.00, 0.64 },
00095 { 0.98, 0.60, 0.01 },
00096 { 0.01, 0.14, 1.00 },
00097 { 0.99, 0.33, 0.03 },
00098 { 0.01, 0.83, 0.81 },
00099 { 1.00, 0.09, 0.00 },
00100 { 0.40, 0.69, 0.20 },
00101 { 0.65, 0.10, 0.29 },
00102 { 0.65, 0.92, 0.17 },
00103 { 0.00, 0.39, 0.79 },
00104 { 1.00, 0.00, 0.40 },
00105 { 0.02, 1.00, 0.40 },
00106 { 0.70, 0.70, 0.70 },
00107 { 1.00, 1.00, 1.00 },
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119 { 0.27, 0.27, 0.04 },
00120 { 0.19, 0.00, 0.24 },
00121 { 0.19, 0.15, 0.00 },
00122 { 0.14, 0.00, 0.38 },
00123 { 0.19, 0.11, 0.00 },
00124 { 0.01, 0.05, 0.33 },
00125 { 0.17, 0.05, 0.02 },
00126 { 0.00, 0.33, 0.29 },
00127 { 0.34, 0.03, 0.01 },
00128 { 0.15, 0.24, 0.06 },
00129 { 0.24, 0.02, 0.11 },
00130 { 0.22, 0.30, 0.07 },
00131 { 0.00, 0.20, 0.26 },
00132 { 0.35, 0.00, 0.14 },
00133 { 0.00, 0.35, 0.12 },
00134 { 0.22, 0.22, 0.22 },
00135 { 0.36, 0.36, 0.36 }
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146 };
00147
00148 static unsigned int s_size = sizeof(s_forBlack)/sizeof(s_forBlack[0]);
00149
00150
00151 static
00152 void resetColors(const float(* iColors)[3], unsigned int iSize, unsigned int iStart, float gammaOff )
00153 {
00154 TSeqCollection* colorTable = gROOT->GetListOfColors();
00155
00156 TColor* c = static_cast<TColor*>(colorTable->At(iStart));
00157 unsigned int index = iStart;
00158 if(0==c || c->GetNumber() != static_cast<int>(iStart)) {
00159 TIter next(colorTable);
00160 while( (c=static_cast<TColor*>( next() )) ) {
00161 if(c->GetNumber()==static_cast<int>(iStart)) {
00162 index = iStart;
00163 break;
00164 }
00165 }
00166 }
00167 assert(0!=c);
00168
00169 for(unsigned int i = index; i< index+iSize; ++i,++iColors) {
00170 TColor* c = static_cast<TColor*> (colorTable->At(i));
00171 float red = (*iColors)[0];
00172 float green = (*iColors)[1];
00173 float blue = (*iColors)[2];
00174
00175
00176 red = TMath::Power(red, (2.5 + gammaOff)/2.5);
00177 green = TMath::Power(green, (2.5 + gammaOff)/2.5);
00178 blue = TMath::Power(blue, (2.5 + gammaOff)/2.5);
00179
00180 c->SetRGB(red,green,blue);
00181 }
00182 }
00183
00184
00185
00186 FWColorManager::FWColorManager(FWModelChangeManager* iManager):
00187 m_gammaOff(0),
00188 m_background(kBlack),
00189 m_foreground(kWhite),
00190 m_changeManager(iManager),
00191 m_startColorIndex(0),
00192 m_numColorIndices(0),
00193 m_geomTransparency2D(50),
00194 m_geomTransparency3D(90)
00195 {
00196 m_geomColor[kFWPixelBarrelColorIndex ] = 1032;
00197 m_geomColor[kFWPixelEndcapColorIndex ] = 1033;
00198
00199 m_geomColor[kFWTrackerBarrelColorIndex ] = 1026;
00200 m_geomColor[kFWTrackerEndcapColorIndex ] = 1017;
00201
00202 m_geomColor[kFWMuonBarrelLineColorIndex] = 1025;
00203 m_geomColor[kFWMuonEndcapLineColorIndex] = 1022;
00204 }
00205
00206 FWColorManager::~FWColorManager()
00207 {
00208 }
00209
00210
00211
00212
00213
00214 void FWColorManager::initialize()
00215 {
00216
00217 TEveUtil::SetColorBrightness(0, kFALSE);
00218
00219 m_startColorIndex = s_defaultStartColorIndex;
00220 m_numColorIndices = s_size;
00221
00222 unsigned int index = m_startColorIndex;
00223
00224
00225 const float(* itEnd)[3] = s_forBlack+s_size;
00226 for(const float(* it)[3] = s_forBlack;
00227 it != itEnd;
00228 ++it) {
00229
00230
00231 new TColor(index++,(*it)[0],(*it)[1],(*it)[2]);
00232 }
00233 }
00234
00235 void FWColorManager::updateColors()
00236 {
00237 if (backgroundColorIndex() == kBlackIndex)
00238 {
00239 resetColors(s_forBlack,s_size,m_startColorIndex, m_gammaOff);
00240 TEveUtil::SetColorBrightness(1.666*m_gammaOff);
00241 }
00242 else
00243 {
00244 resetColors(s_forWhite,s_size,m_startColorIndex, m_gammaOff);
00245 TEveUtil::SetColorBrightness(1.666*m_gammaOff - 2.5);
00246 }
00247 FWChangeSentry sentry(*m_changeManager);
00248 colorsHaveChanged_();
00249 colorsHaveChangedFinished_();
00250 }
00251
00252
00253 void
00254 FWColorManager::setBrightness(int b)
00255 {
00256
00257
00258 m_gammaOff = -b*0.1f;
00259 updateColors();
00260 }
00261
00262 int
00263 FWColorManager::brightness()
00264 {
00265 return TMath::FloorNint(-m_gammaOff*10);
00266 }
00267
00268 void
00269 FWColorManager::defaultBrightness()
00270 {
00271 m_gammaOff = 0;
00272 updateColors();
00273 }
00274
00275 void
00276 FWColorManager::switchBackground()
00277 {
00278 setBackgroundColorIndex(isColorSetDark() ? kWhiteIndex : kBlackIndex);
00279 }
00280
00281 void
00282 FWColorManager::setBackgroundColorIndex(BackgroundColorIndex iIndex)
00283 {
00284 if(backgroundColorIndex()!=iIndex) {
00285 if(backgroundColorIndex()==kBlackIndex) {
00286 m_background=kWhiteIndex;
00287 m_foreground=kBlackIndex;
00288 } else {
00289 m_background=kBlackIndex;
00290 m_foreground=kWhiteIndex;
00291 }
00292 updateColors();
00293 }
00294 }
00295
00296 void
00297 FWColorManager::setBackgroundAndBrightness(BackgroundColorIndex iIndex, int b)
00298 {
00299 m_gammaOff = -b*0.1f;
00300 setBackgroundColorIndex(iIndex);
00301 }
00302
00303 Bool_t
00304 FWColorManager::setColorSetViewer(TGLViewer* v, Color_t iColor)
00305 {
00306 if ( (iColor == kBlackIndex && !v->IsColorSetDark()) ||
00307 (iColor == kWhiteIndex && v->IsColorSetDark()) )
00308 {
00309 v->SwitchColorSet();
00310 return kTRUE;
00311 }
00312 return kFALSE;
00313 }
00314
00315 void
00316 FWColorManager::setGeomColor(FWGeomColorIndex idx, Color_t iColor)
00317 {
00318
00319 m_geomColor[idx] = iColor;
00320 geomColorsHaveChanged_();
00321 gEve->Redraw3D();
00322 }
00323 void
00324 FWColorManager::setGeomTransparency(Color_t iTransp, bool projectedType)
00325 {
00326 if (projectedType)
00327 m_geomTransparency2D = iTransp;
00328 else
00329 m_geomTransparency3D = iTransp;
00330
00331 geomTransparencyHaveChanged_.emit(projectedType);
00332
00333 gEve->Redraw3D();
00334 }
00335
00336
00337
00338
00339
00340
00341 void
00342 FWColorManager::fillLimitedColors(std::vector<Color_t>& cv) const
00343 {
00344 cv.reserve(cv.size() + m_numColorIndices);
00345 for (Color_t i = m_startColorIndex; i < borderOfLimitedColors(); ++i)
00346 {
00347 cv.push_back(i);
00348 }
00349 }
00350
00351 FWColorManager::BackgroundColorIndex
00352 FWColorManager::backgroundColorIndex() const
00353 {
00354 if(m_background==kBlack) {
00355 return kBlackIndex;
00356 }
00357 return kWhiteIndex;
00358 }
00359
00360 bool
00361 FWColorManager::colorHasIndex(Color_t iColor) const
00362 {
00363 return iColor > 0 && iColor < m_startColorIndex + m_numColorIndices;
00364 }
00365
00366
00367 Color_t
00368 FWColorManager::geomColor(FWGeomColorIndex iIndex) const
00369 {
00370 return m_geomColor[iIndex];
00371 }
00372
00373
00374 static boost::shared_ptr<std::map<Color_t,Color_t> > m_oldColorToIndexMap;
00375
00376 Color_t
00377 FWColorManager::oldColorToIndex(Color_t iColor, int version) const
00378 {
00379 if (version < 3)
00380 {
00381 if(0==m_oldColorToIndexMap.get()) {
00382 m_oldColorToIndexMap = boost::shared_ptr<std::map<Color_t,Color_t> >(new std::map<Color_t,Color_t>());
00383 (*m_oldColorToIndexMap)[kRed]=kFWRed;
00384 (*m_oldColorToIndexMap)[kBlue]=kFWBlue;
00385 (*m_oldColorToIndexMap)[kYellow]=kFWYellow;
00386 (*m_oldColorToIndexMap)[kGreen]=kFWGreen;
00387 (*m_oldColorToIndexMap)[kCyan]=kFWCyan;
00388 (*m_oldColorToIndexMap)[kTeal]=kFWCyan;
00389 (*m_oldColorToIndexMap)[kMagenta]=kFWMagenta;
00390 (*m_oldColorToIndexMap)[kViolet]=kFWMagenta;
00391 (*m_oldColorToIndexMap)[kOrange]=kFWOrange;
00392 (*m_oldColorToIndexMap)[3]=kFWGreen;
00393
00394 }
00395 return (*m_oldColorToIndexMap)[iColor];
00396 }
00397 else if (version == 3)
00398 {
00399 return iColor+ 1000;
00400 }
00401 else
00402 {
00403 static unsigned int s_version45offset = 5;
00404 return iColor < 1011 ? iColor : iColor + s_version45offset ;
00405 }
00406 }