Geant4-11
G4TheMTRayTracer.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 "G4TheMTRayTracer.hh"
30#include "G4SystemOfUnits.hh"
31#include "G4RTMessenger.hh"
32#include "G4VFigureFileMaker.hh"
33#include "G4RTJpegMaker.hh"
34#include "G4RTRun.hh"
35#include "G4RTRunAction.hh"
37#include "G4VRTScanner.hh"
38
39#include "G4MTRunManager.hh"
40#include "G4SDManager.hh"
41#include "G4StateManager.hh"
42#include "G4Colour.hh"
43#include "G4VisAttributes.hh"
44#include "G4UImanager.hh"
45#include "G4UIcommand.hh"
46#include "G4VVisManager.hh"
48
50
52 G4VRTScanner* scanner)
53: G4TheRayTracer(figMaker,scanner)
54{
55 if(!theInstance)
56 { theInstance = this; }
57 else
58 { G4Exception("G4TheMTRayTracer::G4TheMTRayTracer","VisRayTracer00100",
59 FatalException,"G4TheMTRayTracer has to be a singleton.");}
64}
65
67{
68 if (theInstance) return theInstance;
69 else return new G4TheMTRayTracer;
70}
71
73(G4VFigureFileMaker* figMaker,G4VRTScanner* scanner)
74{
75 if (theInstance) {
76 theFigMaker=figMaker;
77 theScanner=scanner;
78 return theInstance;
79 }
80 else return new G4TheMTRayTracer(figMaker,scanner);
81}
82
84{
86 {
89 }
91 {
92 delete theRTRunAction;
94 }
95}
96
97void G4TheMTRayTracer::Trace(const G4String& fileName)
98{
100 G4ApplicationState currentState = theStateMan->GetCurrentState();
101 if(currentState!=G4State_Idle)
102 {
103 G4cerr << "Illegal application state <" << theStateMan->GetStateString(currentState)
104 << "> - Trace() ignored. " << G4endl;
105 return;
106 }
107
108 if(!theFigMaker)
109 {
110 G4cerr << "Figure file maker class is not specified - Trace() ignored." << G4endl;
111 return;
112 }
113
115 G4int storeTrajectory = UI->GetCurrentIntValue("/tracking/storeTrajectory");
116 UI->ApplyCommand("/tracking/storeTrajectory 1");
117
119 eyeDirection = tmpVec.unit();
120 G4int nPixel = nColumn*nRow;
121 colorR = new unsigned char[nPixel];
122 colorG = new unsigned char[nPixel];
123 colorB = new unsigned char[nPixel];
124 unsigned char defR = (unsigned char)(G4int(255*backgroundColour.GetRed()));
125 unsigned char defG = (unsigned char)(G4int(255*backgroundColour.GetGreen()));
126 unsigned char defB = (unsigned char)(G4int(255*backgroundColour.GetBlue()));
127 for(G4int ii=0;ii<nPixel;++ii)
128 {
129 colorR[ii] = defR;
130 colorG[ii] = defG;
131 colorB[ii] = defB;
132 }
133
134 G4bool succeeded = CreateBitMap();
135 if(succeeded)
136 { CreateFigureFile(fileName); }
137 else
138 { G4cerr << "Could not create figure file" << G4endl;
139 G4cerr << "You might set the eye position outside of the world volume" << G4endl; }
140
141 G4String str = "/tracking/storeTrajectory " + G4UIcommand::ConvertToString(storeTrajectory);
142 UI->ApplyCommand(str);
143
144 delete [] colorR;
145 delete [] colorG;
146 delete [] colorB;
147}
148
150{
154
157
160}
161
163{
168}
169
171{
173 visMan->IgnoreStateChanges(true);
175
177
178 // Keep, then switch off any printing requests
179 auto runVerbosity = mrm->GetVerboseLevel();
180 auto runPrintProgress = mrm->GetPrintProgress();
181 G4UImanager::GetUIpointer()->ApplyCommand("/run/verbose 0");
182 G4UImanager::GetUIpointer()->ApplyCommand("/run/printProgress 0");
183
184 // Event loop
185 G4int nEvent = nRow*nColumn;
188 G4String str = "/run/beamOn " + G4UIcommand::ConvertToString(nEvent);
190
191 // Restore printing requests
192 str = "/run/verbose " + G4UIcommand::ConvertToString(runVerbosity);
194 str = "/run/printProgress " + G4UIcommand::ConvertToString(runPrintProgress);
196
198 visMan->IgnoreStateChanges(false);
199
200 const G4RTRun* theRun = static_cast<const G4RTRun*>(mrm->GetCurrentRun());
201 if(!theRun) return false;
202
203 G4THitsMap<G4Colour>* colMap = theRun->GetMap();
204 auto itr = colMap->GetMap()->cbegin();
205 for(;itr!=colMap->GetMap()->cend();++itr)
206 {
207 G4int key = itr->first;
208 G4Colour* col = itr->second;
209 colorR[key] = (unsigned char)(G4int(255*col->GetRed()));
210 colorG[key] = (unsigned char)(G4int(255*col->GetGreen()));
211 colorB[key] = (unsigned char)(G4int(255*col->GetBlue()));
212 }
213
215 G4int iRow, iColumn;
216 while (theScanner->Coords(iRow,iColumn))
217 {
218 G4int iCoord = iRow * nColumn + iColumn;
219 theScanner->Draw(colorR[iCoord],colorG[iCoord],colorB[iCoord]);
220 }
221
222 return true;
223}
224
G4ApplicationState
@ G4State_Idle
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:35
bool G4bool
Definition: G4Types.hh:86
int G4int
Definition: G4Types.hh:85
G4GLOB_DLL std::ostream G4cerr
#define G4endl
Definition: G4ios.hh:57
Hep3Vector unit() const
G4double GetBlue() const
Definition: G4Colour.hh:154
G4double GetRed() const
Definition: G4Colour.hh:152
G4double GetGreen() const
Definition: G4Colour.hh:153
virtual void SetUserAction(G4UserRunAction *userAction)
virtual void SetUserInitialization(G4VUserPhysicsList *userPL)
G4THitsMap< G4Colour > * GetMap() const
Definition: G4RTRun.hh:63
static G4MTRunManager * GetMTMasterRunManager()
const G4UserWorkerInitialization * GetUserWorkerInitialization() const
const G4Run * GetCurrentRun() const
const G4UserRunAction * GetUserRunAction() const
G4int GetPrintProgress()
G4int GetVerboseLevel() const
const G4ApplicationState & GetCurrentState() const
G4String GetStateString(const G4ApplicationState &aState) const
static G4StateManager * GetStateManager()
G4RTWorkerInitialization * theRTWorkerInitialization
virtual void StoreUserActions()
virtual void Trace(const G4String &fileName)
const G4UserWorkerInitialization * theUserWorkerInitialization
const G4UserRunAction * theUserRunAction
virtual G4bool CreateBitMap()
virtual void RestoreUserActions()
static G4TheMTRayTracer * Instance()
G4RTRunAction * theRTRunAction
virtual ~G4TheMTRayTracer()
G4TheMTRayTracer(G4VFigureFileMaker *figMaker=0, G4VRTScanner *scanner=0)
static G4TheMTRayTracer * theInstance
G4ThreeVector eyeDirection
static G4VRTScanner * theScanner
static G4VFigureFileMaker * theFigMaker
unsigned char * colorG
G4Colour backgroundColour
unsigned char * colorR
G4ThreeVector targetPosition
void CreateFigureFile(const G4String &fileName)
G4ThreeVector eyePosition
unsigned char * colorB
static G4String ConvertToString(G4bool boolVal)
Definition: G4UIcommand.cc:445
G4int ApplyCommand(const char *aCommand)
Definition: G4UImanager.cc:485
G4int GetCurrentIntValue(const char *aCommand, G4int parameterNumber=1, G4bool reGet=true)
Definition: G4UImanager.cc:231
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:77
virtual void Initialize(G4int nRow, G4int nColumn)=0
virtual void Draw(unsigned char red, unsigned char green, unsigned char blue)
Definition: G4VRTScanner.hh:70
virtual G4bool Coords(G4int &iRow, G4int &iColumn)=0
Map_t * GetMap() const
Definition: G4THitsMap.hh:155
virtual void IgnoreStateChanges(G4bool)
static G4VVisManager * GetConcreteInstance()