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10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /visualization/RayTracer/src/G4TheMTRayTracer.cc (Version 11.3.0) and /visualization/RayTracer/src/G4TheMTRayTracer.cc (Version 10.7.p1)


  1 //                                                  1 //
  2 // *******************************************      2 // ********************************************************************
  3 // * License and Disclaimer                         3 // * License and Disclaimer                                           *
  4 // *                                                4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of th      5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
  6 // * the Geant4 Collaboration.  It is provided      6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
  7 // * conditions of the Geant4 Software License      7 // * conditions of the Geant4 Software License,  included in the file *
  8 // * LICENSE and available at  http://cern.ch/      8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
  9 // * include a list of copyright holders.           9 // * include a list of copyright holders.                             *
 10 // *                                               10 // *                                                                  *
 11 // * Neither the authors of this software syst     11 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing fin     12 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warran     13 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assum     14 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file      15 // * use.  Please see the license in the file  LICENSE  and URL above *
 16 // * for the full disclaimer and the limitatio     16 // * for the full disclaimer and the limitation of liability.         *
 17 // *                                               17 // *                                                                  *
 18 // * This  code  implementation is the result      18 // * This  code  implementation is the result of  the  scientific and *
 19 // * technical work of the GEANT4 collaboratio     19 // * technical work of the GEANT4 collaboration.                      *
 20 // * By using,  copying,  modifying or  distri     20 // * By using,  copying,  modifying or  distributing the software (or *
 21 // * any work based  on the software)  you  ag     21 // * any work based  on the software)  you  agree  to acknowledge its *
 22 // * use  in  resulting  scientific  publicati     22 // * use  in  resulting  scientific  publications,  and indicate your *
 23 // * acceptance of all terms of the Geant4 Sof     23 // * acceptance of all terms of the Geant4 Software license.          *
 24 // *******************************************     24 // ********************************************************************
 25 //                                                 25 //
 26 //                                                 26 //
 27 //                                                 27 //
 28                                                    28 
 29 #include "G4TheMTRayTracer.hh"                     29 #include "G4TheMTRayTracer.hh"
 30 #include "G4SystemOfUnits.hh"                      30 #include "G4SystemOfUnits.hh"
 31 #include "G4RTMessenger.hh"                        31 #include "G4RTMessenger.hh"
 32 #include "G4VFigureFileMaker.hh"                   32 #include "G4VFigureFileMaker.hh"
 33 #include "G4RTJpegMaker.hh"                        33 #include "G4RTJpegMaker.hh"
 34 #include "G4RTRun.hh"                              34 #include "G4RTRun.hh"
 35 #include "G4RTRunAction.hh"                        35 #include "G4RTRunAction.hh"
 36 #include "G4RTWorkerInitialization.hh"             36 #include "G4RTWorkerInitialization.hh"
 37 #include "G4VRTScanner.hh"                         37 #include "G4VRTScanner.hh"
 38                                                    38 
 39 #include "G4MTRunManager.hh"                       39 #include "G4MTRunManager.hh"
 40 #include "G4SDManager.hh"                          40 #include "G4SDManager.hh"
 41 #include "G4StateManager.hh"                       41 #include "G4StateManager.hh"
 42 #include "G4Colour.hh"                             42 #include "G4Colour.hh"
 43 #include "G4VisAttributes.hh"                      43 #include "G4VisAttributes.hh"
 44 #include "G4UImanager.hh"                          44 #include "G4UImanager.hh"
 45 #include "G4UIcommand.hh"                          45 #include "G4UIcommand.hh"
 46 #include "G4VVisManager.hh"                        46 #include "G4VVisManager.hh"
 47 #include "G4RunManagerFactory.hh"                  47 #include "G4RunManagerFactory.hh"
 48                                                    48 
 49 #define G4warn G4cout                          << 
 50                                                << 
 51 G4TheMTRayTracer* G4TheMTRayTracer::theInstanc     49 G4TheMTRayTracer* G4TheMTRayTracer::theInstance = nullptr;
 52                                                    50 
 53 G4TheMTRayTracer::G4TheMTRayTracer(G4VFigureFi     51 G4TheMTRayTracer::G4TheMTRayTracer(G4VFigureFileMaker* figMaker,
 54              G4VRTScanner* scanner)                52              G4VRTScanner* scanner)
 55 : G4TheRayTracer(figMaker,scanner)                 53 : G4TheRayTracer(figMaker,scanner)
 56 {                                                  54 {
 57   if(!theInstance)                                 55   if(!theInstance) 
 58   { theInstance = this; }                          56   { theInstance = this; }
 59   else                                             57   else
 60   { G4Exception("G4TheMTRayTracer::G4TheMTRayT     58   { G4Exception("G4TheMTRayTracer::G4TheMTRayTracer","VisRayTracer00100",
 61          FatalException,"G4TheMTRayTracer has      59          FatalException,"G4TheMTRayTracer has to be a singleton.");}
 62   theUserWorkerInitialization = 0;                 60   theUserWorkerInitialization = 0;
 63   theRTWorkerInitialization = 0;                   61   theRTWorkerInitialization = 0;
 64   theUserRunAction = 0;                            62   theUserRunAction = 0;
 65   theRTRunAction = 0;                              63   theRTRunAction = 0;
 66 }                                                  64 }
 67                                                    65 
 68 G4TheMTRayTracer* G4TheMTRayTracer::Instance() << 
 69 {                                              << 
 70   if (theInstance) return theInstance;         << 
 71   else return new G4TheMTRayTracer;            << 
 72 }                                              << 
 73                                                << 
 74 G4TheMTRayTracer* G4TheMTRayTracer::Instance   << 
 75 (G4VFigureFileMaker* figMaker,G4VRTScanner* sc << 
 76 {                                              << 
 77   if (theInstance) {                           << 
 78     theFigMaker=figMaker;                      << 
 79     theScanner=scanner;                        << 
 80     return theInstance;                        << 
 81   }                                            << 
 82   else return new G4TheMTRayTracer(figMaker,sc << 
 83 }                                              << 
 84                                                << 
 85 G4TheMTRayTracer::~G4TheMTRayTracer()              66 G4TheMTRayTracer::~G4TheMTRayTracer()
 86 {                                                  67 {
 87   if(theRTWorkerInitialization)                    68   if(theRTWorkerInitialization)
 88   {                                                69   {
 89     delete theRTWorkerInitialization;              70     delete theRTWorkerInitialization;
 90     theRTWorkerInitialization = 0;                 71     theRTWorkerInitialization = 0;
 91   }                                                72   }
 92   if(theRTRunAction)                               73   if(theRTRunAction)
 93   {                                                74   {
 94     delete theRTRunAction;                         75     delete theRTRunAction;
 95     theRTRunAction = 0;                            76     theRTRunAction = 0;
 96   }                                                77   }
 97 }                                                  78 }
 98                                                    79 
 99 void G4TheMTRayTracer::Trace(const G4String& f     80 void G4TheMTRayTracer::Trace(const G4String& fileName)
100 {                                                  81 {
101   G4StateManager* theStateMan = G4StateManager     82   G4StateManager* theStateMan = G4StateManager::GetStateManager();
102   G4ApplicationState currentState = theStateMa     83   G4ApplicationState currentState = theStateMan->GetCurrentState();
103   if(currentState!=G4State_Idle)                   84   if(currentState!=G4State_Idle)
104   {                                                85   {
105     G4warn << "Illegal application state <" << <<  86     G4cerr << "Illegal application state <" << theStateMan->GetStateString(currentState)
106            << "> - Trace() ignored. " << G4end     87            << "> - Trace() ignored. " << G4endl;
107     return;                                        88     return;
108   }                                                89   }
109                                                    90 
110   if(!theFigMaker)                                 91   if(!theFigMaker)
111   {                                                92   {
112     G4warn << "Figure file maker class is not  <<  93     G4cerr << "Figure file maker class is not specified - Trace() ignored." << G4endl;
113     return;                                        94     return;
114   }                                                95   }
115                                                    96 
116   G4UImanager* UI = G4UImanager::GetUIpointer(     97   G4UImanager* UI = G4UImanager::GetUIpointer();
117   G4int storeTrajectory = UI->GetCurrentIntVal     98   G4int storeTrajectory = UI->GetCurrentIntValue("/tracking/storeTrajectory");
118   UI->ApplyCommand("/tracking/storeTrajectory      99   UI->ApplyCommand("/tracking/storeTrajectory 1");
119                                                   100 
120   G4ThreeVector tmpVec = targetPosition - eyeP    101   G4ThreeVector tmpVec = targetPosition - eyePosition;
121   eyeDirection = tmpVec.unit();                   102   eyeDirection = tmpVec.unit();
122   G4int nPixel = nColumn*nRow;                    103   G4int nPixel = nColumn*nRow;
123   colorR = new unsigned char[nPixel];             104   colorR = new unsigned char[nPixel];
124   colorG = new unsigned char[nPixel];             105   colorG = new unsigned char[nPixel];
125   colorB = new unsigned char[nPixel];             106   colorB = new unsigned char[nPixel];
126   unsigned char defR = (unsigned char)(G4int(2    107   unsigned char defR = (unsigned char)(G4int(255*backgroundColour.GetRed()));
127   unsigned char defG = (unsigned char)(G4int(2    108   unsigned char defG = (unsigned char)(G4int(255*backgroundColour.GetGreen()));
128   unsigned char defB = (unsigned char)(G4int(2    109   unsigned char defB = (unsigned char)(G4int(255*backgroundColour.GetBlue()));
129   for(G4int ii=0;ii<nPixel;++ii)                  110   for(G4int ii=0;ii<nPixel;++ii)
130   {                                               111   {
131     colorR[ii] = defR;                            112     colorR[ii] = defR;
132     colorG[ii] = defG;                            113     colorG[ii] = defG;
133     colorB[ii] = defB;                            114     colorB[ii] = defB;
134   }                                               115   }
135                                                   116 
136   G4bool succeeded = CreateBitMap();              117   G4bool succeeded = CreateBitMap();
137   if(succeeded)                                   118   if(succeeded)
138   { CreateFigureFile(fileName); }                 119   { CreateFigureFile(fileName); }
139   else                                            120   else
140   { G4warn << "Could not create figure file" < << 121   { G4cerr << "Could not create figure file" << G4endl;
141     G4warn << "You might set the eye position  << 122     G4cerr << "You might set the eye position outside of the world volume" << G4endl; }
142                                                   123 
143   G4String str = "/tracking/storeTrajectory "     124   G4String str = "/tracking/storeTrajectory " + G4UIcommand::ConvertToString(storeTrajectory);
144   UI->ApplyCommand(str);                          125   UI->ApplyCommand(str);
145                                                   126 
146   delete [] colorR;                               127   delete [] colorR;
147   delete [] colorG;                               128   delete [] colorG;
148   delete [] colorB;                               129   delete [] colorB;
149 }                                                 130 }
150                                                   131 
151 void G4TheMTRayTracer::StoreUserActions()         132 void G4TheMTRayTracer::StoreUserActions()
152 {                                                 133 {
153   G4MTRunManager* mrm         = G4RunManagerFa    134   G4MTRunManager* mrm         = G4RunManagerFactory::GetMTMasterRunManager();
154   theUserWorkerInitialization = mrm->GetUserWo    135   theUserWorkerInitialization = mrm->GetUserWorkerInitialization();
155   theUserRunAction = mrm->GetUserRunAction();     136   theUserRunAction = mrm->GetUserRunAction();
156                                                   137 
157   if(!theRTWorkerInitialization) theRTWorkerIn    138   if(!theRTWorkerInitialization) theRTWorkerInitialization = new G4RTWorkerInitialization();
158   if(!theRTRunAction) theRTRunAction = new G4R    139   if(!theRTRunAction) theRTRunAction = new G4RTRunAction();
159                                                   140 
160   mrm->SetUserInitialization(theRTWorkerInitia    141   mrm->SetUserInitialization(theRTWorkerInitialization);
161   mrm->SetUserAction(theRTRunAction);             142   mrm->SetUserAction(theRTRunAction);
162 }                                                 143 }
163                                                   144 
164 void G4TheMTRayTracer::RestoreUserActions()       145 void G4TheMTRayTracer::RestoreUserActions()
165 {                                                 146 {
166   G4MTRunManager* mrm = G4RunManagerFactory::G    147   G4MTRunManager* mrm = G4RunManagerFactory::GetMTMasterRunManager();
167   mrm->SetUserInitialization(                     148   mrm->SetUserInitialization(
168     const_cast<G4UserWorkerInitialization*>(th    149     const_cast<G4UserWorkerInitialization*>(theUserWorkerInitialization));
169   mrm->SetUserAction(const_cast<G4UserRunActio    150   mrm->SetUserAction(const_cast<G4UserRunAction*>(theUserRunAction));
170 }                                                 151 }
171                                                   152 
172 G4bool G4TheMTRayTracer::CreateBitMap()           153 G4bool G4TheMTRayTracer::CreateBitMap()
173 {                                                 154 {
174   G4VVisManager* visMan = G4VVisManager::GetCo    155   G4VVisManager* visMan = G4VVisManager::GetConcreteInstance();
175   visMan->IgnoreStateChanges(true);               156   visMan->IgnoreStateChanges(true);
176   StoreUserActions();                             157   StoreUserActions();
177                                                   158 
178   G4MTRunManager* mrm = G4RunManagerFactory::G    159   G4MTRunManager* mrm = G4RunManagerFactory::GetMTMasterRunManager();
179                                                   160 
180   // Keep, then switch off any printing reques    161   // Keep, then switch off any printing requests
181   auto runVerbosity      = mrm->GetVerboseLeve    162   auto runVerbosity      = mrm->GetVerboseLevel();
182   auto runPrintProgress  = mrm->GetPrintProgre    163   auto runPrintProgress  = mrm->GetPrintProgress();
183   G4UImanager::GetUIpointer()->ApplyCommand("/    164   G4UImanager::GetUIpointer()->ApplyCommand("/run/verbose 0");
184   G4UImanager::GetUIpointer()->ApplyCommand("/    165   G4UImanager::GetUIpointer()->ApplyCommand("/run/printProgress 0");
185                                                   166 
186   // Event loop                                   167   // Event loop
187   G4int nEvent = nRow*nColumn;                    168   G4int nEvent = nRow*nColumn;
188 ////  mrm->BeamOn(nEvent);                        169 ////  mrm->BeamOn(nEvent);
189 ////  Temporary work-around until direct invok    170 ////  Temporary work-around until direct invokation of G4RunManager::BeamOn() works.
190   G4String str = "/run/beamOn " + G4UIcommand:    171   G4String str = "/run/beamOn " + G4UIcommand::ConvertToString(nEvent);
191   G4UImanager::GetUIpointer()->ApplyCommand(st    172   G4UImanager::GetUIpointer()->ApplyCommand(str);
192                                                   173 
193   // Restore printing requests                    174   // Restore printing requests
194   str = "/run/verbose " + G4UIcommand::Convert    175   str = "/run/verbose " + G4UIcommand::ConvertToString(runVerbosity);
195   G4UImanager::GetUIpointer()->ApplyCommand(st    176   G4UImanager::GetUIpointer()->ApplyCommand(str);
196   str = "/run/printProgress " + G4UIcommand::C    177   str = "/run/printProgress " + G4UIcommand::ConvertToString(runPrintProgress);
197   G4UImanager::GetUIpointer()->ApplyCommand(st    178   G4UImanager::GetUIpointer()->ApplyCommand(str);
198                                                   179 
199   RestoreUserActions();                           180   RestoreUserActions();
200   visMan->IgnoreStateChanges(false);              181   visMan->IgnoreStateChanges(false);
201                                                   182 
202   const G4RTRun* theRun = static_cast<const G4    183   const G4RTRun* theRun = static_cast<const G4RTRun*>(mrm->GetCurrentRun());
203   if(!theRun) return false;                       184   if(!theRun) return false;
204                                                   185 
205   G4THitsMap<G4Colour>* colMap = theRun->GetMa    186   G4THitsMap<G4Colour>* colMap = theRun->GetMap(); 
206   auto itr = colMap->GetMap()->cbegin();          187   auto itr = colMap->GetMap()->cbegin();
207   for(;itr!=colMap->GetMap()->cend();++itr)       188   for(;itr!=colMap->GetMap()->cend();++itr)
208   {                                               189   {
209     G4int key = itr->first;                       190     G4int key = itr->first;
210     G4Colour* col = itr->second;                  191     G4Colour* col = itr->second;
211     colorR[key] = (unsigned char)(G4int(255*co    192     colorR[key] = (unsigned char)(G4int(255*col->GetRed()));
212     colorG[key] = (unsigned char)(G4int(255*co    193     colorG[key] = (unsigned char)(G4int(255*col->GetGreen()));
213     colorB[key] = (unsigned char)(G4int(255*co    194     colorB[key] = (unsigned char)(G4int(255*col->GetBlue()));
214   }                                               195   }  
215                                                   196 
216   theScanner->Initialize(nRow,nColumn);           197   theScanner->Initialize(nRow,nColumn);
217   G4int iRow, iColumn;                            198   G4int iRow, iColumn;
218   while (theScanner->Coords(iRow,iColumn))        199   while (theScanner->Coords(iRow,iColumn))
219   {                                               200   {
220     G4int iCoord = iRow * nColumn + iColumn;      201     G4int iCoord = iRow * nColumn + iColumn;
221     theScanner->Draw(colorR[iCoord],colorG[iCo    202     theScanner->Draw(colorR[iCoord],colorG[iCoord],colorB[iCoord]);
222   }                                               203   }
223                                                   204 
224   return true;                                    205   return true;
225 }                                                 206 }
226                                                   207 
227                                                   208