source: trunk/source/digits_hits/utils/src/G4ScoreLogColorMap.cc @ 1202

Last change on this file since 1202 was 1140, checked in by garnier, 15 years ago

update to CVS

File size: 5.7 KB
Line 
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,v 1.3 2009/05/04 15:57:33 akimura Exp $
28// GEANT4 tag $Name:  $
29//
30
31#include "G4ScoreLogColorMap.hh"
32#include <cmath>
33#include <string>
34#include <sstream>
35#include <iomanip>
36
37
38#include "G4VVisManager.hh"
39#include "G4VisAttributes.hh"
40#include "G4Text.hh"
41#include "G4Circle.hh"
42#include "G4Polyline.hh"
43#include "G4Colour.hh"
44
45G4ScoreLogColorMap::G4ScoreLogColorMap(G4String mName)
46:G4VScoreColorMap(mName)
47{;}
48
49G4ScoreLogColorMap::~G4ScoreLogColorMap()
50{;}
51
52void G4ScoreLogColorMap::GetMapColor(G4double val, G4double color[4])
53{
54  G4bool lmin = true, lmax = true, lval = true;
55  if(fMinVal <= 0.) lmin = false;
56  if(fMaxVal <= 0.) lmax = false;
57  if(val <= 0.) lval = false;
58  G4double logmin = 0., logmax = 0., logval = 0.;
59  if(lmin) logmin = std::log10(fMinVal);
60  if(lmax) logmax = std::log10(fMaxVal);
61  if(lval) logval = std::log10(val);
62  G4double value = 0.;
63  if(lmax) value = (logval-logmin)/(logmax-logmin);
64
65  if(value > 1.) {value=1.;}
66  if(value < 0.) {value=0.;}
67
68  // color map
69  const int NCOLOR = 6;
70  struct ColorMap {
71    G4double val;
72    G4double rgb[4];
73  } colormap[NCOLOR] = {{0.0, {1., 1., 1., 1.}}, // value, r, g, b, alpha
74                        {0.2, {0., 0., 1., 1.}},
75                        {0.4, {0., 1., 1., 1.}},
76                        {0.6, {0., 1., 0., 1.}},
77                        {0.8, {1., 1., 0., 1.}},
78                        {1.0, {1., 0., 0., 1.}}};
79 
80  // search
81  G4int during[2] = {0, 0};
82  for(int i = 1; i < NCOLOR; i++) {
83    if(colormap[i].val >= value) {
84      during[0] = i-1;
85      during[1] = i;
86      break;
87    }
88  }
89
90  // interpolate
91  G4double a = std::fabs(value - colormap[during[0]].val);
92  G4double b = std::fabs(value - colormap[during[1]].val);
93  for(int i = 0; i < 4; i++) {
94    color[i] = (b*colormap[during[0]].rgb[i] + a*colormap[during[1]].rgb[i])
95      /(colormap[during[1]].val - colormap[during[0]].val);
96  } 
97
98}
99
100
101void G4ScoreLogColorMap::DrawColorChartBar(G4int _nPoint) {
102
103  G4bool lmin = true, lmax = true;
104  if(fMinVal <= 0.) lmin = false;
105  if(fMaxVal <= 0.) lmax = false;
106  G4double min = 0.;
107  if(lmin) min = std::log10(fMinVal);
108  G4double max = 0.;
109  if(lmax) max = std::log10(fMaxVal);
110
111  G4double smin = -0.89, smax = smin + 0.05*(_nPoint)*0.83, step=0.001;
112  G4double c[4];
113  for(G4double y = smin; y < smax; y+=step) {
114    G4double ra = (y-smin)/(smax-smin), rb = 1.-ra;
115    G4Polyline line;
116    line.push_back(G4Point3D(-0.96, y, 0.));
117    line.push_back(G4Point3D(-0.91, y, 0.));
118    G4double val = std::pow(10., (ra*max+rb*min)/(ra+rb));
119    this->GetMapColor(val, c);
120    G4Colour col(c[0], c[1], c[2]);
121    G4VisAttributes att(col);
122    line.SetVisAttributes(&att);
123    fVisManager->Draw2D(line);
124  }
125
126}
127void G4ScoreLogColorMap::DrawColorChartText(G4int _nPoint) {
128  G4bool lmin = true, lmax = true;
129  if(fMinVal <= 0.) lmin = false;
130  if(fMaxVal <= 0.) lmax = false;
131
132  G4double min = 0.;
133  if(lmin) min = std::log10(fMinVal);
134  if(min > 0.) min = std::floor(min);
135  else min = std::ceil(min);
136
137  G4double max = 0.;
138  if(lmax) max = std::log10(fMaxVal);
139  if(max > 0.) max = std::floor(max);
140  else max = std::ceil(max);
141
142  G4double c[4];
143  G4Colour black(0., 0., 0.);
144  for(int n = 0; n < _nPoint; n++) {
145    G4double a = n/(_nPoint-1.), b = 1.-a;
146    G4double v = (a*max + b*min)/(a+b);
147    // background color
148    for(int l = 0; l < 21; l++) {
149      G4Polyline line;
150      line.push_back(G4Point3D(-0.908, -0.905+0.05*n+0.002*l, 0.));
151      line.push_back(G4Point3D(-0.705, -0.905+0.05*n+0.002*l, 0.));
152      G4VisAttributes attblack(black);
153      line.SetVisAttributes(&attblack);
154      fVisManager->Draw2D(line);
155    }
156    // text
157    //char cstring[80];
158    //std::sprintf(cstring, "%8.1e", std::pow(10., v));
159    //G4String value(cstring);
160    std::ostringstream oss;
161    oss << std::setw(8) << std::setprecision(1) << std::scientific << std::pow(10., v);
162    std::string str = oss.str();
163    G4String value(str.c_str());
164    G4Text text(value, G4Point3D(-0.9, -0.9+0.05*n, 0));
165    G4double size = 12.;
166    text.SetScreenSize(size);
167    this->GetMapColor(std::pow(10., v), c);
168    G4Colour color(c[0], c[1], c[2]);
169    G4VisAttributes att(color);
170    text.SetVisAttributes(&att);
171
172    fVisManager->Draw2D(text);
173  }
174}
Note: See TracBrowser for help on using the repository browser.