Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
G4TheMTRayTracer.cc
이 파일의 문서화 페이지로 가기
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: G4TheMTRayTracer.cc 66264 2012-12-14 10:17:44Z allison $
28 //
29 
30 #include "G4TheMTRayTracer.hh"
31 #include "G4SystemOfUnits.hh"
32 #include "G4RTMessenger.hh"
33 #include "G4VFigureFileMaker.hh"
34 #include "G4RTJpegMaker.hh"
35 #include "G4RTRun.hh"
36 #include "G4RTRunAction.hh"
38 #include "G4VRTScanner.hh"
39 
40 #include "G4MTRunManager.hh"
41 #include "G4SDManager.hh"
42 #include "G4StateManager.hh"
43 #include "G4Colour.hh"
44 #include "G4VisAttributes.hh"
45 #include "G4UImanager.hh"
46 #include "G4UIcommand.hh"
47 #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.");}
62  theUserRunAction = 0;
63  theRTRunAction = 0;
64 }
65 
67 {
69  {
72  }
73  if(theRTRunAction)
74  {
75  delete theRTRunAction;
76  theRTRunAction = 0;
77  }
78 }
79 
80 void G4TheMTRayTracer::Trace(const G4String& fileName)
81 {
83  G4ApplicationState currentState = theStateMan->GetCurrentState();
84  if(currentState!=G4State_Idle)
85  {
86  G4cerr << "Illegal application state <" << theStateMan->GetStateString(currentState)
87  << "> - Trace() ignored. " << G4endl;
88  return;
89  }
90 
91  if(!theFigMaker)
92  {
93  G4cerr << "Figure file maker class is not specified - Trace() ignored." << G4endl;
94  return;
95  }
96 
98  G4int storeTrajectory = UI->GetCurrentIntValue("/tracking/storeTrajectory");
99  UI->ApplyCommand("/tracking/storeTrajectory 1");
100 
102  eyeDirection = tmpVec.unit();
103  G4int nPixel = nColumn*nRow;
104  colorR = new unsigned char[nPixel];
105  colorG = new unsigned char[nPixel];
106  colorB = new unsigned char[nPixel];
107  unsigned char defR = (unsigned char)(int(255*backgroundColour.GetRed()));
108  unsigned char defG = (unsigned char)(int(255*backgroundColour.GetGreen()));
109  unsigned char defB = (unsigned char)(int(255*backgroundColour.GetBlue()));
110  for(G4int ii=0;ii<nPixel;ii++)
111  {
112  colorR[ii] = defR;
113  colorG[ii] = defG;
114  colorB[ii] = defB;
115  }
116 
117  G4bool succeeded = CreateBitMap();
118  if(succeeded)
119  { CreateFigureFile(fileName); }
120  else
121  { G4cerr << "Could not create figure file" << G4endl;
122  G4cerr << "You might set the eye position outside of the world volume" << G4endl; }
123 
124  G4String str = "/tracking/storeTrajectory " + G4UIcommand::ConvertToString(storeTrajectory);
125  UI->ApplyCommand(str);
126 
127  delete [] colorR;
128  delete [] colorG;
129  delete [] colorB;
130 }
131 
133 {
137 
140 
143 }
144 
146 {
148  mrm->SetUserInitialization(const_cast<G4UserWorkerInitialization*>(theUserWorkerInitialization));
149  mrm->SetUserAction(const_cast<G4UserRunAction*>(theUserRunAction));
150 }
151 
153 {
155  visMan->IgnoreStateChanges(true);
157 
158 // Event loop
160  G4int nEvent = nRow*nColumn;
163  G4String str = "/run/beamOn " + G4UIcommand::ConvertToString(nEvent);
165 
167  visMan->IgnoreStateChanges(false);
168 
169  const G4RTRun* theRun = static_cast<const G4RTRun*>(mrm->GetCurrentRun());
170  if(!theRun) return false;
171 
172  G4THitsMap<G4Colour>* colMap = theRun->GetMap();
173  std::map<G4int,G4Colour*>::iterator itr = colMap->GetMap()->begin();
174  for(;itr!=colMap->GetMap()->end();itr++)
175  {
176  G4int key = itr->first;
177  G4Colour* col = itr->second;
178  colorR[key] = (unsigned char)(int(255*col->GetRed()));
179  colorG[key] = (unsigned char)(int(255*col->GetGreen()));
180  colorB[key] = (unsigned char)(int(255*col->GetBlue()));
181  }
182 
183  theScanner->Initialize(nRow,nColumn);
184  G4int iRow, iColumn;
185  while (theScanner->Coords(iRow,iColumn))
186  {
187  G4int iCoord = iRow * nColumn + iColumn;
188  theScanner->Draw(colorR[iCoord],colorG[iCoord],colorB[iCoord]);
189  }
190 
191  return true;
192 }
193 
virtual void RestoreUserActions()
static G4MTRunManager * GetMasterRunManager()
const G4Run * GetCurrentRun() const
virtual void Initialize(G4int nRow, G4int nColumn)=0
G4ThreeVector targetPosition
const G4UserRunAction * GetUserRunAction() const
virtual G4bool Coords(G4int &iRow, G4int &iColumn)=0
G4ThreeVector eyePosition
G4THitsMap< G4Colour > * GetMap() const
Definition: G4RTRun.hh:64
G4int ApplyCommand(const char *aCommand)
Definition: G4UImanager.cc:466
#define G4endl
Definition: G4ios.hh:61
virtual G4bool CreateBitMap()
const G4UserWorkerInitialization * theUserWorkerInitialization
G4VFigureFileMaker * theFigMaker
void CreateFigureFile(const G4String &fileName)
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:73
static G4VVisManager * GetConcreteInstance()
virtual void StoreUserActions()
unsigned char * colorG
unsigned char * colorB
bool G4bool
Definition: G4Types.hh:79
G4VRTScanner * theScanner
G4Colour backgroundColour
Int_t col[ntarg]
Definition: Style.C:29
G4String GetStateString(G4ApplicationState aState) const
virtual void SetUserInitialization(G4VUserPhysicsList *userPL)
static G4TheMTRayTracer * theInstance
const G4UserWorkerInitialization * GetUserWorkerInitialization() const
virtual void IgnoreStateChanges(G4bool)
G4double GetRed() const
Definition: G4Colour.hh:151
const G4UserRunAction * theUserRunAction
unsigned char * colorR
virtual void Draw(unsigned char red, unsigned char green, unsigned char blue)
Definition: G4VRTScanner.hh:71
G4ThreeVector eyeDirection
G4GLOB_DLL std::ostream G4cerr
virtual void SetUserAction(G4UserRunAction *userAction)
Hep3Vector unit() const
virtual void Trace(const G4String &fileName)
virtual ~G4TheMTRayTracer()
static G4String ConvertToString(G4bool boolVal)
Definition: G4UIcommand.cc:374
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.hh:65
int G4int
Definition: G4Types.hh:78
G4ApplicationState GetCurrentState() const
G4int GetCurrentIntValue(const char *aCommand, G4int parameterNumber=1, G4bool reGet=true)
Definition: G4UImanager.cc:252
G4ApplicationState
G4double GetBlue() const
Definition: G4Colour.hh:153
G4double GetGreen() const
Definition: G4Colour.hh:152
G4RTRunAction * theRTRunAction
Map_t * GetMap() const
Definition: G4THitsMap.hh:117
G4TheMTRayTracer(G4VFigureFileMaker *figMaker=0, G4VRTScanner *scanner=0)
G4RTWorkerInitialization * theRTWorkerInitialization
static G4StateManager * GetStateManager()