Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4ScoreLogColorMap.cc
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 //
27 // $Id: G4ScoreLogColorMap.cc 67992 2013-03-13 10:59:57Z gcosmo $
28 //
29 
30 #include "G4ScoreLogColorMap.hh"
31 #include <cmath>
32 #include <string>
33 #include <sstream>
34 #include <iomanip>
35 
36 
37 #include "G4VVisManager.hh"
38 #include "G4VisAttributes.hh"
39 #include "G4Text.hh"
40 #include "G4Circle.hh"
41 #include "G4Polyline.hh"
42 #include "G4Colour.hh"
43 
45 :G4VScoreColorMap(mName)
46 {;}
47 
49 {;}
50 
51 #include "G4UIcommand.hh"
53 {
54  G4bool lmin = true, lmax = true, lval = true;
55  if(fMinVal < 0.) {
56  lmin = false;
57  G4String message = " The min. value (fMinVal) is negative. : ";
59  G4Exception("G4ScoreLogColorMap::GetMapColor()",
60  "DigiHitsUtilsScoreLogColorMap000", JustWarning,
61  message);
62  }
63  if(fMaxVal < 0.) {
64  lmax = false;
65  G4String message = " The max. value (fMaxVal) is negative. : ";
67  G4Exception("G4ScoreLogColorMap::GetMapColor()",
68  "DigiHitsUtilsScoreLogColorMap001", JustWarning,
69  message);
70  }
71  if(!lmin || !lmax) {
72  color[0] = 0.;
73  color[1] = 0.;
74  color[2] = 0.;
75  color[3] = 0.;
76  return;
77  }
78 
79  if(val < 0.) {
80  lval = false;
81  G4String message = " 'val' (first argument) is negative : ";
83  G4Exception("G4ScoreLogColorMap::GetMapColor()",
84  "DigiHitsUtilsScoreLogColorMap002", JustWarning,
85  message);
86  }
87  if(!lval) {
88  color[0] = 0.;
89  color[1] = 0.;
90  color[2] = 0.;
91  color[3] = -1.;
92  return;
93  }
94 
95  G4double logmin = 0., logmax = 0., logval = 0.;
96  if(lmin) logmin = std::log10(fMinVal);
97  if(lmax) logmax = std::log10(fMaxVal);
98  if(lval) logval = std::log10(val);
99  G4double value = 0.;
100  if(lmax) value = (logval-logmin)/(logmax-logmin);
101 
102  if(value > 1.) {value=1.;}
103  if(value < 0.) {value=0.;}
104 
105  // color map
106  const int NCOLOR = 6;
107  struct ColorMap {
108  G4double val;
109  G4double rgb[4];
110  } colormap[NCOLOR] = {{0.0, {1., 1., 1., 1.}}, // value, r, g, b, alpha
111  {0.2, {0., 0., 1., 1.}},
112  {0.4, {0., 1., 1., 1.}},
113  {0.6, {0., 1., 0., 1.}},
114  {0.8, {1., 1., 0., 1.}},
115  {1.0, {1., 0., 0., 1.}}};
116 
117  // search
118  G4int during[2] = {0, 0};
119  for(int i = 1; i < NCOLOR; i++) {
120  if(colormap[i].val >= value) {
121  during[0] = i-1;
122  during[1] = i;
123  break;
124  }
125  }
126 
127  // interpolate
128  G4double a = std::fabs(value - colormap[during[0]].val);
129  G4double b = std::fabs(value - colormap[during[1]].val);
130  for(int i = 0; i < 4; i++) {
131  color[i] = (b*colormap[during[0]].rgb[i] + a*colormap[during[1]].rgb[i])
132  /(colormap[during[1]].val - colormap[during[0]].val);
133  }
134 
135 }
136 
137 
139 
140  //G4cout << "++++++ " << fMinVal << " - " << fMaxVal << G4endl;
141  G4bool lmin = true, lmax = true;
142  if(fMinVal <= 0.) lmin = false;
143  if(fMaxVal <= 0.) lmax = false;
144  G4double min = 0.;
145  if(lmin) min = std::log10(fMinVal);
146  G4double max = 0.;
147  if(lmax) max = std::log10(fMaxVal);
148 
149  G4double smin = -0.89, smax = smin + 0.05*(_nPoint)*0.83, step=0.001;
150  G4double c[4];
151  for(G4double y = smin; y < smax; y+=step) {
152  G4double ra = (y-smin)/(smax-smin), rb = 1.-ra;
153  G4Polyline line;
154  line.push_back(G4Point3D(-0.96, y, 0.));
155  line.push_back(G4Point3D(-0.91, y, 0.));
156  G4double val = std::pow(10., (ra*max+rb*min)/(ra+rb));
157  this->GetMapColor(val, c);
158  if(c[0] == 0 && c[1] == 0 && c[2] == 0 && c[3] == 0) return;
159  if(c[0] == 0 && c[1] == 0 && c[2] == 0 && c[3] == -1.) continue;
160  G4Colour col(c[0], c[1], c[2]);
161  G4VisAttributes att(col);
162  line.SetVisAttributes(&att);
163  fVisManager->Draw2D(line);
164  }
165 
166 }
168  G4bool lmin = true, lmax = true;
169  if(fMinVal <= 0.) lmin = false;
170  if(fMaxVal <= 0.) lmax = false;
171 
172  G4double min = 0.;
173  if(lmin) min = std::log10(fMinVal);
174  //if(min > 0.) min = std::floor(min);
175  //else min = std::ceil(min);
176 
177  G4double max = 0.;
178  if(lmax) max = std::log10(fMaxVal);
179  //if(max > 0.) max = std::ceil(max);
180  //else max = std::floor(max);
181 
182  G4double c[4];
183  G4Colour black(0., 0., 0.);
184  for(int n = 0; n < _nPoint; n++) {
185  G4double a = n/(_nPoint-1.), b = 1.-a;
186  G4double v = (a*max + b*min)/(a+b);
187 
188  this->GetMapColor(std::pow(10., v), c);
189  if(c[0] == 0 && c[1] == 0 && c[2] == 0 && c[3] == 0) return;
190  if(c[0] == 0 && c[1] == 0 && c[2] == 0 && c[3] == -1.) continue;
191 
192  // background color
193  for(int l = 0; l < 21; l++) {
194  G4Polyline line;
195  line.push_back(G4Point3D(-0.908, -0.905+0.05*n+0.002*l, 0.));
196  line.push_back(G4Point3D(-0.705, -0.905+0.05*n+0.002*l, 0.));
197  G4VisAttributes attblack(black);
198  line.SetVisAttributes(&attblack);
199  fVisManager->Draw2D(line);
200  }
201  // text
202  //char cstring[80];
203  //std::sprintf(cstring, "%8.1e", std::pow(10., v));
204  //G4String value(cstring);
205  std::ostringstream oss;
206  oss << std::setw(8) << std::setprecision(1) << std::scientific << std::pow(10., v);
207  std::string str = oss.str();
208  G4String value(str.c_str());
209  G4Text text(value, G4Point3D(-0.9, -0.9+0.05*n, 0));
210  G4double size = 12.;
211  text.SetScreenSize(size);
212  //this->GetMapColor(std::pow(10., v), c);
213  G4Colour color(c[0], c[1], c[2]);
214  G4VisAttributes att(color);
215  text.SetVisAttributes(&att);
216 
217  fVisManager->Draw2D(text);
218  }
219 
220 
221  // draw ps name
222  // background
223  G4int lpsname = 20;// fPSName.size();
224  if(lpsname > 0) {
225  for(int l = 0; l < 22; l++) {
226  G4Polyline line;
227  line.push_back(G4Point3D(-0.9, -0.965+0.002*l, 0.));
228  line.push_back(G4Point3D(-0.9+0.025*lpsname, -0.965+0.002*l, 0.));
229  G4VisAttributes attblack(black);
230  //G4VisAttributes attblack(G4Colour(.0, .5, .0));
231  line.SetVisAttributes(&attblack);
232  fVisManager->Draw2D(line);
233  }
234  // ps name
235  G4Text txtpsname(fPSName, G4Point3D(-0.9, -0.96, 0.));
236  G4double size = 12.;
237  txtpsname.SetScreenSize(size);
238  G4Colour color(1., 1., 1.);
239  G4VisAttributes att(color);
240  txtpsname.SetVisAttributes(&att);
241  fVisManager->Draw2D(txtpsname);
242  }
243 
244 
245 
246  // draw unit
247  // background
248  G4int len = fPSUnit.size();
249  if(len > 0) {
250  for(int l = 0; l < 21; l++) {
251  G4Polyline line;
252  line.push_back(G4Point3D(-0.7, -0.9+0.002*l, 0.));
253  line.push_back(G4Point3D(-0.7+0.3, -0.9+0.002*l, 0.));
254  G4VisAttributes attblack(black);
255  //G4VisAttributes attblack(G4Colour(.5, .0, .0));
256  line.SetVisAttributes(&attblack);
257  fVisManager->Draw2D(line);
258  }
259  // unit
260  G4String psunit = "[" + fPSUnit + "]";
261  G4Text txtunit(psunit, G4Point3D(-0.69, -0.9, 0.));
262  G4double size = 12.;
263  txtunit.SetScreenSize(size);
264  G4Colour color(1., 1., 1.);
265  G4VisAttributes att(color);
266  txtunit.SetVisAttributes(&att);
267  fVisManager->Draw2D(txtunit);
268  }
269 
270 }
Definition: G4Text.hh:73
G4VVisManager * fVisManager
static G4String ConvertToString(G4bool boolVal)
Definition: G4UIcommand.cc:357
HepGeom::Point3D< G4double > G4Point3D
Definition: G4Point3D.hh:35
virtual void GetMapColor(G4double val, G4double color[4])
int G4int
Definition: G4Types.hh:78
const G4int smax
bool G4bool
Definition: G4Types.hh:79
const G4int n
virtual void DrawColorChartBar(G4int nPoint)
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
void SetVisAttributes(const G4VisAttributes *)
Definition: G4Visible.cc:80
T max(const T t1, const T t2)
brief Return the largest of the two arguments
T min(const T t1, const T t2)
brief Return the smallest of the two arguments
const XML_Char int const XML_Char * value
const XML_Char int len
double G4double
Definition: G4Types.hh:76
virtual void DrawColorChartText(G4int nPoint)
virtual void Draw2D(const G4Circle &, const G4Transform3D &objectTransformation=G4Transform3D())=0
G4ScoreLogColorMap(G4String mName)
void SetScreenSize(G4double)