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

Last change on this file since 1093 was 998, checked in by garnier, 15 years ago

fichiers oublies

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