Geant4-11
G4VScoreColorMap.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//
28
29#include "G4VScoreColorMap.hh"
30#include <string>
31#include <sstream>
32#include <iomanip>
33
34#include "G4VVisManager.hh"
35#include "G4VisAttributes.hh"
36#include "G4Text.hh"
37#include "G4Circle.hh"
38#include "G4Polyline.hh"
39#include "G4Colour.hh"
40#include "G4Polyhedron.hh"
41
43 : fName(mName)
44 , ifFloat(true)
45 , fMinVal(0.)
46 , fMaxVal(DBL_MAX)
47 , fVisManager(nullptr)
48{
49 ;
50}
51
53
55{
57 if(!fVisManager)
58 {
59 G4cerr << "G4VScoringMesh::DrawColorChart(): no visualization system"
60 << G4endl;
61 return;
62 }
63
64 DrawColorChartBar(_nPoint);
65 DrawColorChartText(_nPoint);
66}
67
69{
70 G4double min = this->GetMin();
71 G4double max = this->GetMax();
72 G4double smin = -0.89, smax = smin + 0.05 * (_nPoint) *0.83, step = 0.001;
73 G4double c[4];
74
76
77 for(G4double y = smin; y < smax; y += step)
78 {
79 G4double ra = (y - smin) / (smax - smin), rb = 1. - ra;
80 G4Polyline line;
81 line.push_back(G4Point3D(-0.96, y, 0.));
82 line.push_back(G4Point3D(-0.91, y, 0.));
83 this->GetMapColor((ra * max + rb * min) / (ra + rb), c);
84 G4Colour col(c[0], c[1], c[2]);
85 G4VisAttributes att(col);
86 line.SetVisAttributes(&att);
87 fVisManager->Draw2D(line);
88 }
89
91}
92
94{
95 G4double min = this->GetMin();
96 G4double max = this->GetMax();
97 G4double c[4];
98 G4Colour black(0.1, 0.1, 0.1, 0.8);
99
101
102 for(int n = 0; n < _nPoint; n++)
103 {
104 G4double a = n / (_nPoint - 1.), b = 1. - a;
105 G4double v = (a * max + b * min) / (a + b);
106 // background color
107
108 for(int l = 0; l < 21; l++)
109 {
110 G4Polyline line;
111 line.push_back(G4Point3D(-0.9, -0.905 + 0.05 * n + 0.002 * l, 0.));
112 line.push_back(G4Point3D(-0.75, -0.905 + 0.05 * n + 0.002 * l, 0.));
113 G4VisAttributes attblack(black);
114 line.SetVisAttributes(&attblack);
115 fVisManager->Draw2D(line);
116 }
117
118 // text
119 // char cstring[80];
120 // std::sprintf(cstring, "%8.2e", v);
121 // G4String value(cstring);
122 std::ostringstream oss;
123 oss << std::setw(8) << std::setprecision(1) << std::scientific << v;
124 std::string str = oss.str();
125 G4String value = str; //.c_str());
126
127 G4Text text(value, G4Point3D(-0.9, -0.9 + 0.05 * n, 0.4));
128 G4double size = 12.;
129 text.SetScreenSize(size);
130 this->GetMapColor(v, c);
131 G4Colour color(c[0], c[1], c[2], 1.);
132 G4VisAttributes att(color);
133 text.SetVisAttributes(&att);
134
135 fVisManager->Draw2D(text);
136 }
137
138 // draw ps name
139 // background
140 G4double lpsname = 2. + fPSName.size() * 0.95;
141 if(lpsname > 0)
142 {
143 for(int l = 0; l < 22; l++)
144 {
145 G4Polyline line;
146 line.push_back(G4Point3D(-0.92, -0.965 + 0.002 * l, 0.));
147 line.push_back(
148 G4Point3D(-0.92 + 0.025 * lpsname, -0.965 + 0.002 * l, 0.));
149 G4VisAttributes attblack(black);
150 // G4VisAttributes attblack(G4Colour(.5, .5, 1.));
151 line.SetVisAttributes(&attblack);
152 fVisManager->Draw2D(line);
153 }
154
155 // ps name
156 G4Text txtpsname(fPSName, G4Point3D(-0.9, -0.96, 0.1));
157 G4double size = 12.;
158 txtpsname.SetScreenSize(size);
159 G4Colour color(1., 1., 1.);
160 G4VisAttributes att(color);
161 txtpsname.SetVisAttributes(&att);
162 fVisManager->Draw2D(txtpsname);
163 }
164
165 // draw unit
166 // background
167 G4double len = 2. + fPSUnit.size();
168 if(len > 0)
169 {
170 for(int l = 0; l < 21; l++)
171 {
172 G4Polyline line;
173 line.push_back(G4Point3D(-0.7, -0.9 + 0.002 * l, 0.));
174 line.push_back(G4Point3D(-0.7 + 0.025 * len, -0.9 + 0.002 * l, 0.));
175 G4VisAttributes attblack(black);
176 // G4VisAttributes attblack(G4Colour(.5, .5, .5));
177 line.SetVisAttributes(&attblack);
178 fVisManager->Draw2D(line);
179 }
180
181 // unit
182 G4String psunit = "[" + fPSUnit + "]";
183 G4Text txtunit(psunit, G4Point3D(-0.69, -0.9, 0.1));
184 G4double size = 12.;
185 txtunit.SetScreenSize(size);
186 G4Colour color(1., 1., 1.);
187 G4VisAttributes att(color);
188 txtunit.SetVisAttributes(&att);
189 fVisManager->Draw2D(txtunit);
190 }
191
193}
HepGeom::Point3D< G4double > G4Point3D
Definition: G4Point3D.hh:34
double G4double
Definition: G4Types.hh:83
int G4int
Definition: G4Types.hh:85
G4GLOB_DLL std::ostream G4cerr
#define G4endl
Definition: G4ios.hh:57
Definition: G4Text.hh:72
void SetScreenSize(G4double)
virtual void DrawColorChart(G4int nPoint=5)
virtual void DrawColorChartText(G4int nPoint)
G4double GetMax() const
G4VScoreColorMap(G4String mName)
G4double GetMin() const
virtual ~G4VScoreColorMap()
G4VVisManager * fVisManager
virtual void GetMapColor(G4double val, G4double color[4])=0
virtual void DrawColorChartBar(G4int nPoint)
virtual void Draw2D(const G4Circle &, const G4Transform3D &objectTransformation=G4Transform3D())=0
virtual void EndDraw2D()=0
static G4VVisManager * GetConcreteInstance()
virtual void BeginDraw2D(const G4Transform3D &objectTransformation=G4Transform3D())=0
void SetVisAttributes(const G4VisAttributes *)
Definition: G4Visible.cc:96
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
#define DBL_MAX
Definition: templates.hh:62