001 #include "Palette.h"
002
003 #ifdef WIN32
004 #include <Riostream.h>
005 #else
006 #include <iostream.h>
007 #endif
008
009 #include <TApplication.h>
010 #include <TColor.h>
011 #include <TStyle.h>
012
013 using std::cerr;
014 using std::endl;
015 using std::cout;
016
017 Palette::Palette(double x, double y, double width, double heigth) {
018 this->initPalette(x, y, width, heigth, DEFAULT_NCOLORS);
019 }
020
021 Palette::Palette(double x, double y, double width, double heigth, int ncolors) {
022 if(ncolors<MAX_NCOLORS) {
023 this->initPalette(x, y, width, heigth, ncolors);
024 } else {
025 cerr<<"Palette::Palette(int ncolors) - requested ncolors above limit !"<<endl;
026 exit(EXIT_FAILURE);
027 }
028 }
029
030 Palette::~Palette(void)
031 {
032 std::vector<TBox*>::iterator it = m_vbox.begin();
033 for(;it!=m_vbox.end();++it) {
034 delete *it;
035 }
036 delete m_paxis;
037 }
038
039 void Palette::initPalette(double x, double y, double width, double heigth, int ncolors) {
040 m_paxis = 0;
041 m_nColors = ncolors-1;
042 m_vbox.reserve(m_nColors);
043
044 double m_paletteWidth = width;
045 double m_paletteHeigth = heigth;
046
047
048 for (int i=0;i<(m_nColors+1);i++) {
049 if(!gROOT->GetColor(230+i)) {
050 TColor *color = new TColor(230+i,(i/((m_nColors)*1.0)),0.,1-(i/((m_nColors)*1.0)),"");
051 } else {
052 TColor *color = gROOT->GetColor(230+i);
053 color->SetRGB((i/((m_nColors)*1.0)),0.,1-(i/((m_nColors)*1.0)));
054 }
055 m_palette[i]=230+i;
056 }
057 gStyle->SetPalette(m_nColors+1,m_palette);
058
059
060 double dy = m_paletteHeigth/((double)m_nColors+1);
061 for(int i=0;i<m_nColors+1;++i) {
062 TBox* box = new TBox(x,i*dy+y,x+m_paletteWidth,(i+1)*dy+y);
063 if(box) {
064 m_vbox.push_back(box);
065 box->SetFillColor(230+i);
066 } else cout<<"Palette::DrawPalette() Could not allocate a new TBox !"<<endl;
067 }
068
069 m_paxis = new TGaxis(x+m_paletteWidth,y,x+m_paletteWidth,y+m_paletteHeigth,0.,1.,510,"+S");
070 m_paxis->SetLabelOffset(0.035);
071 m_paxis->SetTickSize(0.01);
072
073 m_bIsDrawn = false;
074 m_pPad = 0;
075 }
076
077 void Palette::draw(void) {
078 if(!m_bIsDrawn) {
079 std::vector<TBox*>::iterator it = m_vbox.begin();
080 for(;it!=m_vbox.end();++it) {
081 (*it)->Draw();
082 }
083 m_paxis->Draw();
084 m_pPad = (TPad*) gPad;
085 m_bIsDrawn = true;
086 }
087 }
088
089 void Palette::remove() {
090 if(m_bIsDrawn) {
091 TList* li = m_pPad->GetListOfPrimitives();
092 std::vector<TBox*>::iterator it = m_vbox.begin();
093 for(;it!=m_vbox.end();++it) {
094 li->Remove(*it);
095 }
096
097 li->Remove(m_paxis);
098 m_pPad = 0;
099 m_bIsDrawn = false;
100 }
101 }
102
103 void Palette::update(const Scale& dataScale) {
104 m_min = dataScale.minimum();
105 m_max = dataScale.maximum();
106
107 if(m_max==m_min) {
108 m_min*=0.95;
109 m_max*=1.1;
110 }
111
112 if(m_paxis) {
113 m_paxis->SetWmax(m_max*1.);
114 m_paxis->SetWmin(m_min*1.);
115 }
116 }
117
118 int Palette::colorId(double value) {
119
120 if(value>m_max) return kGreen;
121 if(value<m_min) return kBlack;
122
123 int color;
124 if((m_max-m_min)!=0.) {
125 color = (int)((value-m_min)*m_nColors/(m_max-m_min)+230);
126 } else {
127 color = kGreen;
128 }
129 return color;
130 }
| Due to the LXR bug, the updates fail sometimes to remove references to deleted files. The Saturday's full rebuilds fix these problems |
|
This page was automatically generated by the
LXR engine.
|
|