G4ScoreLogColorMap Class Reference

#include <G4ScoreLogColorMap.hh>

Inheritance diagram for G4ScoreLogColorMap:

G4VScoreColorMap

Public Member Functions

 G4ScoreLogColorMap (G4String mName)
virtual ~G4ScoreLogColorMap ()
virtual void GetMapColor (G4double val, G4double color[4])
virtual void DrawColorChartBar (G4int nPoint)
virtual void DrawColorChartText (G4int nPoint)

Detailed Description

Definition at line 36 of file G4ScoreLogColorMap.hh.


Constructor & Destructor Documentation

G4ScoreLogColorMap::G4ScoreLogColorMap ( G4String  mName  ) 

Definition at line 44 of file G4ScoreLogColorMap.cc.

00045 :G4VScoreColorMap(mName)
00046 {;}

G4ScoreLogColorMap::~G4ScoreLogColorMap (  )  [virtual]

Definition at line 48 of file G4ScoreLogColorMap.cc.

00049 {;}


Member Function Documentation

void G4ScoreLogColorMap::DrawColorChartBar ( G4int  nPoint  )  [virtual]

Reimplemented from G4VScoreColorMap.

Definition at line 138 of file G4ScoreLogColorMap.cc.

References G4VVisManager::Draw2D(), G4VScoreColorMap::fMaxVal, G4VScoreColorMap::fMinVal, G4VScoreColorMap::fVisManager, GetMapColor(), and G4Visible::SetVisAttributes().

00138                                                         {
00139 
00140   //G4cout << "++++++ " << fMinVal << " - " << fMaxVal << G4endl;
00141   G4bool lmin = true, lmax = true;
00142   if(fMinVal <= 0.) lmin = false;
00143   if(fMaxVal <= 0.) lmax = false;
00144   G4double min = 0.;
00145   if(lmin) min = std::log10(fMinVal);
00146   G4double max = 0.;
00147   if(lmax) max = std::log10(fMaxVal);
00148 
00149   G4double smin = -0.89, smax = smin + 0.05*(_nPoint)*0.83, step=0.001;
00150   G4double c[4];
00151   for(G4double y = smin; y < smax; y+=step) {
00152     G4double ra = (y-smin)/(smax-smin), rb = 1.-ra;
00153     G4Polyline line;
00154     line.push_back(G4Point3D(-0.96, y, 0.));
00155     line.push_back(G4Point3D(-0.91, y, 0.));
00156     G4double val = std::pow(10., (ra*max+rb*min)/(ra+rb));
00157     this->GetMapColor(val, c);
00158     if(c[0] == 0 && c[1] == 0 && c[2] == 0 && c[3] == 0) return;
00159     if(c[0] == 0 && c[1] == 0 && c[2] == 0 && c[3] == -1.) continue;
00160     G4Colour col(c[0], c[1], c[2]);
00161     G4VisAttributes att(col);
00162     line.SetVisAttributes(&att);
00163     fVisManager->Draw2D(line);
00164   }
00165 
00166 }

void G4ScoreLogColorMap::DrawColorChartText ( G4int  nPoint  )  [virtual]

Reimplemented from G4VScoreColorMap.

Definition at line 167 of file G4ScoreLogColorMap.cc.

References G4VVisManager::Draw2D(), G4VScoreColorMap::fMaxVal, G4VScoreColorMap::fMinVal, G4VScoreColorMap::fPSName, G4VScoreColorMap::fPSUnit, G4VScoreColorMap::fVisManager, GetMapColor(), CLHEP::detail::n, G4VMarker::SetScreenSize(), and G4Visible::SetVisAttributes().

00167                                                          {
00168   G4bool lmin = true, lmax = true;
00169   if(fMinVal <= 0.) lmin = false;
00170   if(fMaxVal <= 0.) lmax = false;
00171 
00172   G4double min = 0.;
00173   if(lmin) min = std::log10(fMinVal);
00174   //if(min > 0.) min = std::floor(min);
00175   //else min = std::ceil(min);
00176 
00177   G4double max = 0.;
00178   if(lmax) max = std::log10(fMaxVal);
00179   //if(max > 0.) max = std::ceil(max);
00180   //else max = std::floor(max);
00181 
00182   G4double c[4];
00183   G4Colour black(0., 0., 0.);
00184   for(int n = 0; n < _nPoint; n++) {
00185     G4double a = n/(_nPoint-1.), b = 1.-a;
00186     G4double v = (a*max + b*min)/(a+b);
00187 
00188     this->GetMapColor(std::pow(10., v), c);
00189     if(c[0] == 0 && c[1] == 0 && c[2] == 0 && c[3] == 0) return;
00190     if(c[0] == 0 && c[1] == 0 && c[2] == 0 && c[3] == -1.) continue;
00191 
00192     // background color
00193     for(int l = 0; l < 21; l++) {
00194       G4Polyline line;
00195       line.push_back(G4Point3D(-0.908, -0.905+0.05*n+0.002*l, 0.));
00196       line.push_back(G4Point3D(-0.705, -0.905+0.05*n+0.002*l, 0.));
00197       G4VisAttributes attblack(black);
00198       line.SetVisAttributes(&attblack);
00199       fVisManager->Draw2D(line);
00200     }
00201     // text
00202     //char cstring[80]; 
00203     //std::sprintf(cstring, "%8.1e", std::pow(10., v));
00204     //G4String value(cstring);
00205     std::ostringstream oss;
00206     oss << std::setw(8) << std::setprecision(1) << std::scientific << std::pow(10., v);
00207     std::string str = oss.str();
00208     G4String value(str.c_str());
00209     G4Text text(value, G4Point3D(-0.9, -0.9+0.05*n, 0));
00210     G4double size = 12.;
00211     text.SetScreenSize(size);
00212     //this->GetMapColor(std::pow(10., v), c);
00213     G4Colour color(c[0], c[1], c[2]);
00214     G4VisAttributes att(color);
00215     text.SetVisAttributes(&att);
00216 
00217     fVisManager->Draw2D(text);
00218   }
00219 
00220 
00221   // draw ps name
00222   // background
00223   G4int lpsname = 20;// fPSName.size();
00224   if(lpsname > 0) {
00225     for(int l = 0; l < 22; l++) {
00226       G4Polyline line;
00227       line.push_back(G4Point3D(-0.9, -0.965+0.002*l, 0.));
00228       line.push_back(G4Point3D(-0.9+0.025*lpsname, -0.965+0.002*l, 0.));
00229       G4VisAttributes attblack(black);
00230       //G4VisAttributes attblack(G4Colour(.0, .5, .0));
00231       line.SetVisAttributes(&attblack);
00232       fVisManager->Draw2D(line);
00233     }
00234     // ps name
00235     G4Text txtpsname(fPSName, G4Point3D(-0.9, -0.96, 0.));
00236     G4double size = 12.;
00237     txtpsname.SetScreenSize(size);
00238     G4Colour color(1., 1., 1.);
00239     G4VisAttributes att(color);
00240     txtpsname.SetVisAttributes(&att);
00241     fVisManager->Draw2D(txtpsname);
00242   }
00243 
00244 
00245 
00246   // draw unit
00247   // background
00248   G4int len = fPSUnit.size();
00249   if(len > 0) {
00250     for(int l = 0; l < 21; l++) {
00251       G4Polyline line;
00252       line.push_back(G4Point3D(-0.7, -0.9+0.002*l, 0.));
00253       line.push_back(G4Point3D(-0.7+0.3, -0.9+0.002*l, 0.));
00254       G4VisAttributes attblack(black);
00255       //G4VisAttributes attblack(G4Colour(.5, .0, .0));
00256       line.SetVisAttributes(&attblack);
00257       fVisManager->Draw2D(line);
00258     }
00259     // unit
00260     G4String psunit = "[" + fPSUnit + "]";
00261     G4Text txtunit(psunit, G4Point3D(-0.69, -0.9, 0.));
00262     G4double size = 12.;
00263     txtunit.SetScreenSize(size);
00264     G4Colour color(1., 1., 1.);
00265     G4VisAttributes att(color);
00266     txtunit.SetVisAttributes(&att);
00267     fVisManager->Draw2D(txtunit);
00268   }
00269 
00270 }

void G4ScoreLogColorMap::GetMapColor ( G4double  val,
G4double  color[4] 
) [virtual]

Implements G4VScoreColorMap.

Definition at line 52 of file G4ScoreLogColorMap.cc.

References G4UIcommand::ConvertToString(), G4VScoreColorMap::fMaxVal, G4VScoreColorMap::fMinVal, G4Exception(), and JustWarning.

Referenced by DrawColorChartBar(), and DrawColorChartText().

00053 {
00054   G4bool lmin = true, lmax = true, lval = true;
00055   if(fMinVal < 0.) {
00056     lmin = false;
00057     G4String message = "    The min. value (fMinVal) is negative. : ";
00058     message += G4UIcommand::ConvertToString(fMinVal);
00059     G4Exception("G4ScoreLogColorMap::GetMapColor()",
00060                 "DigiHitsUtilsScoreLogColorMap000", JustWarning,
00061                 message);
00062   }
00063   if(fMaxVal < 0.) {
00064     lmax = false;
00065     G4String message = "    The max. value (fMaxVal) is negative. : ";
00066     message += G4UIcommand::ConvertToString(fMaxVal);
00067     G4Exception("G4ScoreLogColorMap::GetMapColor()",
00068                 "DigiHitsUtilsScoreLogColorMap001", JustWarning,
00069                 message);
00070   }
00071   if(!lmin || !lmax) {
00072     color[0] = 0.;
00073     color[1] = 0.;
00074     color[2] = 0.;
00075     color[3] = 0.;
00076     return;
00077   }
00078 
00079   if(val < 0.) {
00080     lval = false;
00081     G4String message = "     'val' (first argument) is negative : ";
00082     message += G4UIcommand::ConvertToString(fMaxVal);
00083     G4Exception("G4ScoreLogColorMap::GetMapColor()",
00084                 "DigiHitsUtilsScoreLogColorMap002", JustWarning,
00085                 message);
00086   }
00087   if(!lval) {
00088     color[0] = 0.;
00089     color[1] = 0.;
00090     color[2] = 0.;
00091     color[3] = -1.;
00092     return;
00093   }
00094 
00095   G4double logmin = 0., logmax = 0., logval = 0.;
00096   if(lmin) logmin = std::log10(fMinVal);
00097   if(lmax) logmax = std::log10(fMaxVal);
00098   if(lval) logval = std::log10(val);
00099   G4double value = 0.;
00100   if(lmax) value = (logval-logmin)/(logmax-logmin);
00101 
00102   if(value > 1.) {value=1.;}
00103   if(value < 0.) {value=0.;}
00104 
00105   // color map
00106   const int NCOLOR = 6;
00107   struct ColorMap {
00108     G4double val;
00109     G4double rgb[4];
00110   } colormap[NCOLOR] = {{0.0, {1., 1., 1., 1.}}, // value, r, g, b, alpha
00111                         {0.2, {0., 0., 1., 1.}},
00112                         {0.4, {0., 1., 1., 1.}},
00113                         {0.6, {0., 1., 0., 1.}},
00114                         {0.8, {1., 1., 0., 1.}},
00115                         {1.0, {1., 0., 0., 1.}}};
00116   
00117   // search
00118   G4int during[2] = {0, 0};
00119   for(int i = 1; i < NCOLOR; i++) {
00120     if(colormap[i].val >= value) {
00121       during[0] = i-1;
00122       during[1] = i;
00123       break;
00124     }
00125   }
00126 
00127   // interpolate
00128   G4double a = std::fabs(value - colormap[during[0]].val);
00129   G4double b = std::fabs(value - colormap[during[1]].val);
00130   for(int i = 0; i < 4; i++) {
00131     color[i] = (b*colormap[during[0]].rgb[i] + a*colormap[during[1]].rgb[i])
00132       /(colormap[during[1]].val - colormap[during[0]].val);
00133   } 
00134 
00135 }


The documentation for this class was generated from the following files:
Generated on Mon May 27 17:53:20 2013 for Geant4 by  doxygen 1.4.7