source: trunk/source/digits_hits/utils/src/G4VScoreColorMap.cc @ 1340

Last change on this file since 1340 was 1340, checked in by garnier, 14 years ago

update ti head

File size: 5.6 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: G4VScoreColorMap.cc,v 1.8 2010/07/26 03:52:33 akimura Exp $
28// GEANT4 tag $Name:  $
29//
30
31#include "G4VScoreColorMap.hh"
32#include <string>
33#include <sstream>
34#include <iomanip>
35
36#include "G4VVisManager.hh"
37#include "G4VisAttributes.hh"
38#include "G4Text.hh"
39#include "G4Circle.hh"
40#include "G4Polyline.hh"
41#include "G4Colour.hh"
42
43G4VScoreColorMap::G4VScoreColorMap(G4String mName)
44:fName(mName),ifFloat(true),fMinVal(0.),fMaxVal(DBL_MAX)
45{;}
46
47G4VScoreColorMap::~G4VScoreColorMap()
48{;}
49
50void G4VScoreColorMap::DrawColorChart(G4int _nPoint) {
51
52  fVisManager = G4VVisManager::GetConcreteInstance();
53  if(!fVisManager) {
54    G4cerr << "G4VScoringMesh::DrawColorChart(): no visualization system" << G4endl;
55    return;
56  }
57
58  DrawColorChartBar(_nPoint);
59  DrawColorChartText(_nPoint);
60}
61
62void G4VScoreColorMap::DrawColorChartBar(G4int _nPoint) {
63
64  G4double min = this->GetMin();
65  G4double max = this->GetMax();
66  G4double smin = -0.89, smax = smin + 0.05*(_nPoint)*0.83, step=0.001;
67  G4double c[4];
68  for(G4double y = smin; y < smax; y+=step) {
69    G4double ra = (y-smin)/(smax-smin), rb = 1.-ra;
70    G4Polyline line;
71    line.push_back(G4Point3D(-0.96, y, 0.));
72    line.push_back(G4Point3D(-0.91, y, 0.));
73    this->GetMapColor((ra*max+rb*min)/(ra+rb), c);
74    G4Colour col(c[0], c[1], c[2]);
75    G4VisAttributes att(col);
76    line.SetVisAttributes(&att);
77    fVisManager->Draw2D(line);
78  }
79
80}
81void G4VScoreColorMap::DrawColorChartText(G4int _nPoint) {
82
83  G4double min = this->GetMin();
84  G4double max = this->GetMax();
85  G4double c[4];
86  G4Colour black(0., 0., 0.);
87  for(int n = 0; n < _nPoint; n++) {
88    G4double a = n/(_nPoint-1.), b = 1.-a;
89    G4double v = (a*max + b*min)/(a+b);
90    // background color
91    for(int l = 0; l < 21; l++) {
92      G4Polyline line;
93      line.push_back(G4Point3D(-0.908, -0.905+0.05*n+0.002*l, 0.));
94      line.push_back(G4Point3D(-0.705, -0.905+0.05*n+0.002*l, 0.));
95      G4VisAttributes attblack(black);
96      line.SetVisAttributes(&attblack);
97      fVisManager->Draw2D(line);
98    }
99    // text
100    //char cstring[80];
101    //std::sprintf(cstring, "%8.2e", v);
102    //G4String value(cstring);
103    std::ostringstream oss;
104    oss << std::setw(8) << std::setprecision(1) << std::scientific << v;
105    std::string str = oss.str();
106    G4String value(str.c_str());
107
108    G4Text text(value, G4Point3D(-0.9, -0.9+0.05*n, 0));
109    G4double size = 12.;
110    text.SetScreenSize(size);
111    this->GetMapColor(v, c);
112    G4Colour color(c[0], c[1], c[2]);
113    G4VisAttributes att(color);
114    text.SetVisAttributes(&att);
115
116    fVisManager->Draw2D(text);
117  }
118
119  // draw ps name
120  // background
121  G4int lpsname = 20;//fPSName.size();
122  if(lpsname > 0) {
123    for(int l = 0; l < 22; l++) {
124      G4Polyline line;
125      line.push_back(G4Point3D(-0.9, -0.965+0.002*l, 0.));
126      line.push_back(G4Point3D(-0.9+0.025*lpsname, -0.965+0.002*l, 0.));
127      G4VisAttributes attblack(black);
128      //G4VisAttributes attblack(G4Colour(.5, .5, 1.));
129      line.SetVisAttributes(&attblack);
130      fVisManager->Draw2D(line);
131    }
132    // ps name
133    G4Text txtpsname(fPSName, G4Point3D(-0.9, -0.96, 0.));
134    G4double size = 12.;
135    txtpsname.SetScreenSize(size);
136    G4Colour color(1., 1., 1.);
137    G4VisAttributes att(color);
138    txtpsname.SetVisAttributes(&att);
139    fVisManager->Draw2D(txtpsname);
140  }
141
142  // draw unit
143  // background
144  G4int len = fPSUnit.size();
145  if(len > 0) {
146    for(int l = 0; l < 21; l++) {
147      G4Polyline line;
148      line.push_back(G4Point3D(-0.7, -0.9+0.002*l, 0.));
149      line.push_back(G4Point3D(-0.7+0.3, -0.9+0.002*l, 0.));
150      G4VisAttributes attblack(black);
151      //G4VisAttributes attblack(G4Colour(.5, .5, .5));
152      line.SetVisAttributes(&attblack);
153      fVisManager->Draw2D(line);
154    }
155    // unit
156    G4String psunit = "[" + fPSUnit + "]";
157    G4Text txtunit(psunit, G4Point3D(-0.69, -0.9, 0.));
158    G4double size = 12.;
159    txtunit.SetScreenSize(size);
160    G4Colour color(1., 1., 1.);
161    G4VisAttributes att(color);
162    txtunit.SetVisAttributes(&att);
163    fVisManager->Draw2D(txtunit);
164  }
165
166}
Note: See TracBrowser for help on using the repository browser.