G4VScoreColorMap.cc

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 //
00027 // $Id$
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     // background color
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     // text
00099     //char cstring[80]; 
00100     //std::sprintf(cstring, "%8.2e", v);
00101     //G4String value(cstring);
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   // draw ps name
00119   // background
00120   G4int lpsname = 20;//fPSName.size();
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       //G4VisAttributes attblack(G4Colour(.5, .5, 1.));
00128       line.SetVisAttributes(&attblack);
00129       fVisManager->Draw2D(line);
00130     }
00131     // ps name
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   // draw unit
00142   // background
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       //G4VisAttributes attblack(G4Colour(.5, .5, .5));
00151       line.SetVisAttributes(&attblack);
00152       fVisManager->Draw2D(line);
00153     }
00154     // unit
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 }

Generated on Mon May 27 17:50:22 2013 for Geant4 by  doxygen 1.4.7