source: Idarraga/mpxdataconverter/drawProperties.cpp

Last change on this file was 26, checked in by idarraga, 13 years ago
File size: 3.0 KB
Line 
1#include "drawProperties.h"
2
3HistoProperties::HistoProperties(){
4
5  histoPalette = new MPXPalette();
6
7}
8
9HistoProperties::~HistoProperties(){
10  delete histoPalette;
11}
12
13
14///////////////////////////////////////////////
15
16
17Bool_t HistoProperties::setMode(Int_t visMode, TCanvas * c1){
18
19
20  switch (visMode) {
21   
22  case VIS_MOD_GRAY:
23    histoPalette->Saturation = GRAY_SATURATION_VAL;
24    histoPalette->Maxlightness = GRAY_MAXLIGHTNESS_VAL;
25    histoPalette->Minlightness = GRAY_MINLIGHTNESS_VAL;
26    histoPalette->MaxHue = GRAY_MAXHUE_VAL;
27    histoPalette->MinHue = GRAY_MINHUE_VAL;
28    break;
29   
30  case VIS_MOD_JET:
31    std::cout << "  [INFO] change to mode Jet" << std::endl;
32    histoPalette->Saturation = JET_SATURATION_VAL;
33    histoPalette->Maxlightness = JET_MAXLIGHTNESS_VAL;
34    histoPalette->Minlightness = JET_MINLIGHTNESS_VAL;
35    histoPalette->MaxHue = JET_MAXHUE_VAL;
36    histoPalette->MinHue = JET_MINHUE_VAL;
37    break;
38   
39  case VIS_MOD_HOT:
40    histoPalette->Saturation = HOT_SATURATION_VAL;
41    histoPalette->Maxlightness = HOT_MAXLIGHTNESS_VAL;
42    histoPalette->Minlightness = HOT_MINLIGHTNESS_VAL;
43    histoPalette->MaxHue = HOT_MAXHUE_VAL;
44    histoPalette->MinHue = HOT_MINHUE_VAL;
45    break;
46   
47  case VIS_MOD_COOL:
48    histoPalette->Saturation = COOL_SATURATION_VAL;
49    histoPalette->Maxlightness = COOL_MAXLIGHTNESS_VAL;
50    histoPalette->Minlightness = COOL_MINLIGHTNESS_VAL;
51    histoPalette->MaxHue = COOL_MAXHUE_VAL;
52    histoPalette->MinHue = COOL_MINHUE_VAL;
53    break;
54   
55  default:
56
57    break;
58  }
59
60  Int_t * palette = histoPalette->generatePalette();
61  gStyle->SetPalette(256, palette);
62  gStyle->SetPalette(1, 0);
63  c1->SetFrameBorderMode(0);
64  c1->SetFrameFillColor(palette[0]);
65  //c1->SetFrameFillColor(1,0);
66  c1->SetBorderMode(0);
67  c1->ToggleEventStatus(); // see Event Status bar
68
69  return true;
70}
71
72
73MPXPalette::MPXPalette(){
74
75  Saturation = -1;
76  Maxlightness = -1;
77  Minlightness = -1;
78  MaxHue = -1;
79  MinHue = -1;
80  Lightness = -1;
81
82  MaxColors = 256;
83  palette = new Int_t[MaxColors];
84  index = -1;
85  lightness = -1.0; hue = -1.0; r = -1.0; 
86  g = -1.0; b = -1.0; rv = -1.0; gv = -1.0; 
87  bv = -1.0;
88  failures = 0;
89
90}
91
92MPXPalette::~MPXPalette(){
93  delete palette;
94  delete color;
95}
96
97
98Int_t * MPXPalette::generatePalette(){
99
100  for (int i = 0 ; i < MaxColors ; i++)
101    {
102      index = palette[i] = MaxColors+1+i;     
103      color = new TColor(index, 0, 0, 0);
104      lightness = Maxlightness-(i+1)*((Maxlightness-Minlightness)/MaxColors);
105      hue = MaxHue-(i+1)*((MaxHue-MinHue)/MaxColors);
106      color->HLStoRGB(hue, lightness, Saturation, r, g, b);
107      color->SetRGB(r, g, b);
108
109      // check if the color can be defined
110      //gVirtualX->GetRGB(index, rv, gv, bv);
111      //gGXW->GetRGB(index, rv, gv, bv);
112     
113      if (r != rv || g != gv || b != bv) {
114        failures++;
115        //palette[i] =  i ? palette[i-1] : 1;
116      }
117    } 
118
119  if (failures)
120    std::cout << "  [WARNING] palette(): couldn't allocate " 
121              << failures << " of " << MaxColors << " colors" << std::endl;
122
123  return palette;
124}
Note: See TracBrowser for help on using the repository browser.