00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include "G4VScoreColorMap.hh"
00031 #include <string>
00032 #include <sstream>
00033 #include <iomanip>
00034
00035 #include "G4VVisManager.hh"
00036 #include "G4VisAttributes.hh"
00037 #include "G4Text.hh"
00038 #include "G4Circle.hh"
00039 #include "G4Polyline.hh"
00040 #include "G4Colour.hh"
00041
00042 G4VScoreColorMap::G4VScoreColorMap(G4String mName)
00043 :fName(mName),ifFloat(true),fMinVal(0.),fMaxVal(DBL_MAX),fVisManager(0)
00044 {;}
00045
00046 G4VScoreColorMap::~G4VScoreColorMap()
00047 {;}
00048
00049 void G4VScoreColorMap::DrawColorChart(G4int _nPoint) {
00050
00051 fVisManager = G4VVisManager::GetConcreteInstance();
00052 if(!fVisManager) {
00053 G4cerr << "G4VScoringMesh::DrawColorChart(): no visualization system" << G4endl;
00054 return;
00055 }
00056
00057 DrawColorChartBar(_nPoint);
00058 DrawColorChartText(_nPoint);
00059 }
00060
00061 void G4VScoreColorMap::DrawColorChartBar(G4int _nPoint) {
00062
00063 G4double min = this->GetMin();
00064 G4double max = this->GetMax();
00065 G4double smin = -0.89, smax = smin + 0.05*(_nPoint)*0.83, step=0.001;
00066 G4double c[4];
00067 for(G4double y = smin; y < smax; y+=step) {
00068 G4double ra = (y-smin)/(smax-smin), rb = 1.-ra;
00069 G4Polyline line;
00070 line.push_back(G4Point3D(-0.96, y, 0.));
00071 line.push_back(G4Point3D(-0.91, y, 0.));
00072 this->GetMapColor((ra*max+rb*min)/(ra+rb), c);
00073 G4Colour col(c[0], c[1], c[2]);
00074 G4VisAttributes att(col);
00075 line.SetVisAttributes(&att);
00076 fVisManager->Draw2D(line);
00077 }
00078
00079 }
00080 void G4VScoreColorMap::DrawColorChartText(G4int _nPoint) {
00081
00082 G4double min = this->GetMin();
00083 G4double max = this->GetMax();
00084 G4double c[4];
00085 G4Colour black(0., 0., 0.);
00086 for(int n = 0; n < _nPoint; n++) {
00087 G4double a = n/(_nPoint-1.), b = 1.-a;
00088 G4double v = (a*max + b*min)/(a+b);
00089
00090 for(int l = 0; l < 21; l++) {
00091 G4Polyline line;
00092 line.push_back(G4Point3D(-0.908, -0.905+0.05*n+0.002*l, 0.));
00093 line.push_back(G4Point3D(-0.705, -0.905+0.05*n+0.002*l, 0.));
00094 G4VisAttributes attblack(black);
00095 line.SetVisAttributes(&attblack);
00096 fVisManager->Draw2D(line);
00097 }
00098
00099
00100
00101
00102 std::ostringstream oss;
00103 oss << std::setw(8) << std::setprecision(1) << std::scientific << v;
00104 std::string str = oss.str();
00105 G4String value(str.c_str());
00106
00107 G4Text text(value, G4Point3D(-0.9, -0.9+0.05*n, 0));
00108 G4double size = 12.;
00109 text.SetScreenSize(size);
00110 this->GetMapColor(v, c);
00111 G4Colour color(c[0], c[1], c[2]);
00112 G4VisAttributes att(color);
00113 text.SetVisAttributes(&att);
00114
00115 fVisManager->Draw2D(text);
00116 }
00117
00118
00119
00120 G4int lpsname = 20;
00121 if(lpsname > 0) {
00122 for(int l = 0; l < 22; l++) {
00123 G4Polyline line;
00124 line.push_back(G4Point3D(-0.9, -0.965+0.002*l, 0.));
00125 line.push_back(G4Point3D(-0.9+0.025*lpsname, -0.965+0.002*l, 0.));
00126 G4VisAttributes attblack(black);
00127
00128 line.SetVisAttributes(&attblack);
00129 fVisManager->Draw2D(line);
00130 }
00131
00132 G4Text txtpsname(fPSName, G4Point3D(-0.9, -0.96, 0.));
00133 G4double size = 12.;
00134 txtpsname.SetScreenSize(size);
00135 G4Colour color(1., 1., 1.);
00136 G4VisAttributes att(color);
00137 txtpsname.SetVisAttributes(&att);
00138 fVisManager->Draw2D(txtpsname);
00139 }
00140
00141
00142
00143 G4int len = fPSUnit.size();
00144 if(len > 0) {
00145 for(int l = 0; l < 21; l++) {
00146 G4Polyline line;
00147 line.push_back(G4Point3D(-0.7, -0.9+0.002*l, 0.));
00148 line.push_back(G4Point3D(-0.7+0.3, -0.9+0.002*l, 0.));
00149 G4VisAttributes attblack(black);
00150
00151 line.SetVisAttributes(&attblack);
00152 fVisManager->Draw2D(line);
00153 }
00154
00155 G4String psunit = "[" + fPSUnit + "]";
00156 G4Text txtunit(psunit, G4Point3D(-0.69, -0.9, 0.));
00157 G4double size = 12.;
00158 txtunit.SetScreenSize(size);
00159 G4Colour color(1., 1., 1.);
00160 G4VisAttributes att(color);
00161 txtunit.SetVisAttributes(&att);
00162 fVisManager->Draw2D(txtunit);
00163 }
00164
00165 }