ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4RTMessenger.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4RTMessenger.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 //
28 //
29 //
30 
31 
32 #include "G4RTMessenger.hh"
33 
34 #include "G4UIdirectory.hh"
35 #include "G4UIcmdWithABool.hh"
36 #include "G4UIcmdWith3Vector.hh"
39 #include "G4UIcmdWithAnInteger.hh"
40 #include "G4UIcmdWithAString.hh"
41 #include "G4RTSteppingAction.hh"
42 #include "G4ThreeVector.hh"
43 #include "G4VisManager.hh"
44 #include "G4RayTracerViewer.hh"
45 #include "G4TheRayTracer.hh"
46 
48 
51 {
52  if (!fpInstance) fpInstance = new G4RTMessenger(p1);
53  return fpInstance;
54 }
55 
57 {
58  theDefaultTracer = p1;
60 
61  rayDirectory = new G4UIdirectory("/vis/rayTracer/");
62  rayDirectory->SetGuidance("RayTracer commands.");
63 
64  fileCmd = new G4UIcmdWithAString("/vis/rayTracer/trace",this);
65  fileCmd->SetGuidance("Start the ray tracing.");
66  fileCmd->SetGuidance("Define the name of output JPEG file.");
67  fileCmd->SetParameterName("fileName",true);
68  fileCmd->SetDefaultValue("g4RayTracer.jpeg");
70 
71  columnCmd = new G4UIcmdWithAnInteger("/vis/rayTracer/column",this);
72  columnCmd->SetGuidance("Define the number of horizontal pixels.");
73  columnCmd->SetParameterName("nPixel",false);
74  columnCmd->SetRange("nPixel > 0");
75 
76  rowCmd = new G4UIcmdWithAnInteger("/vis/rayTracer/row",this);
77  rowCmd->SetGuidance("Define the number of vertical pixels.");
78  rowCmd->SetParameterName("nPixel",false);
79  rowCmd->SetRange("nPixel > 0");
80 
81  targetCmd = new G4UIcmdWith3VectorAndUnit("/vis/rayTracer/target",this);
82  targetCmd->SetGuidance("Define the center position of the target.");
83  targetCmd->SetParameterName("X","Y","Z",true);
86 
87  eyePosCmd = new G4UIcmdWith3VectorAndUnit("/vis/rayTracer/eyePosition",this);
88  eyePosCmd->SetGuidance("Define the eye position.");
89  eyePosCmd->SetGuidance("Eye direction is calculated from (target - eyePosition).");
90  eyePosCmd->SetParameterName("X","Y","Z",true);
93 
94  lightCmd = new G4UIcmdWith3Vector("/vis/rayTracer/lightDirection",this);
95  lightCmd->SetGuidance("Define the direction of illumination light.");
96  lightCmd->SetGuidance("The vector needs not to be a unit vector, but it must not be a zero vector.");
97  lightCmd->SetParameterName("Px","Py","Pz",true);
98  lightCmd->SetDefaultValue(G4ThreeVector(0.1,0.2,0.3));
99  lightCmd->SetRange("Px != 0 || Py != 0 || Pz != 0");
100 
101  spanXCmd = new G4UIcmdWithADoubleAndUnit("/vis/rayTracer/span",this);
102  spanXCmd->SetGuidance("Define the angle per 100 pixels.");
103  spanXCmd->SetParameterName("span",true);
105  spanXCmd->SetDefaultUnit("deg");
106  spanXCmd->SetRange("span>0.");
107 
108  headCmd = new G4UIcmdWithADoubleAndUnit("/vis/rayTracer/headAngle",this);
109  headCmd->SetGuidance("Define the head direction.");
110  headCmd->SetParameterName("headAngle",true);
111  headCmd->SetDefaultValue(270.);
112  headCmd->SetDefaultUnit("deg");
113  headCmd->SetRange("headAngle>=0. && headAngle<360.");
114 
115  attCmd = new G4UIcmdWithADoubleAndUnit("/vis/rayTracer/attenuation",this);
116  attCmd->SetGuidance("Define the attenuation length for transparent material.");
117  attCmd->SetGuidance("Note that this value is independent to the attenuation length for the optical photon processes.");
118  attCmd->SetParameterName("Length",true);
119  attCmd->SetDefaultValue(1.0);
120  attCmd->SetDefaultUnit("m");
121  attCmd->SetRange("Length > 0.");
122 
123  distCmd = new G4UIcmdWithABool("/vis/rayTracer/distortion",this);
124  distCmd->SetGuidance("Distortion effect of the fish eye lens.");
125  distCmd->SetParameterName("flag",true);
126  distCmd->SetDefaultValue(false);
127 
128  transCmd = new G4UIcmdWithABool("/vis/rayTracer/ignoreTransparency",this);
129  transCmd->SetGuidance("Ignore transparency even if the alpha of G4Colour < 1.");
130  transCmd->SetParameterName("flag",true);
131  transCmd->SetDefaultValue(false);
132 
133  bkgColCmd = new G4UIcmdWith3Vector("/vis/rayTracer/backgroundColour",this);
134  bkgColCmd->SetGuidance("Command has been deprecated. Use /vis/viewer/set/background instead.");
135  bkgColCmd->SetParameterName("red","green","blue",true);
137 }
138 
140 {
141  delete columnCmd;
142  delete rowCmd;
143  delete targetCmd;
144  delete eyePosCmd;
145  delete lightCmd;
146  delete spanXCmd;
147  delete headCmd;
148  delete attCmd;
149  delete distCmd;
150  delete transCmd;
151  delete fileCmd;
152  delete bkgColCmd;
153  delete rayDirectory;
154 }
155 
157 {
158  G4String currentValue;
159  if(command==columnCmd)
160  { currentValue = columnCmd->ConvertToString(theTracer->GetNColumn()); }
161  else if(command==rowCmd)
162  { currentValue = rowCmd->ConvertToString(theTracer->GetNRow()); }
163  else if(command==targetCmd)
164  { currentValue = targetCmd->ConvertToString(theTracer->GetTargetPosition(),"m"); }
165  else if(command==eyePosCmd)
166  { currentValue = eyePosCmd->ConvertToString(theTracer->GetEyePosition(),"m"); }
167  else if(command==lightCmd)
168  { currentValue = lightCmd->ConvertToString(theTracer->GetLightDirection()); }
169  else if(command==spanXCmd)
170  { currentValue = spanXCmd->ConvertToString(theTracer->GetViewSpan(),"deg"); }
171  else if(command==headCmd)
172  { currentValue = headCmd->ConvertToString(theTracer->GetHeadAngle(),"deg"); }
173  else if(command==attCmd)
174  { currentValue = attCmd->ConvertToString(theTracer->GetAttenuationLength(),"m");}
175  else if(command==distCmd)
176  { currentValue = distCmd->ConvertToString(theTracer->GetDistortion()); }
177  else if(command==transCmd)
179  else if(command==bkgColCmd)
180  { currentValue = bkgColCmd->ConvertToString(theTracer->GetBackgroundColour()); }
181  return currentValue;
182 }
183 
185 {
186  G4VisManager* pVisManager = G4VisManager::GetInstance();
187 
189 
190  G4VViewer* pVViewer = pVisManager->GetCurrentViewer();
191  if (pVViewer) {
192  G4RayTracerViewer* pViewer = dynamic_cast<G4RayTracerViewer*>(pVViewer);
193  if (pViewer) {
194  theTracer = pViewer->GetTracer();
195  } else {
196  G4cout <<
197  "G4RTMessenger::SetNewValue: Current viewer is not of type RayTracer."
198  "\n Use \"/vis/viewer/select\" or \"/vis/open\"."
199  << G4endl;
200  }
201  }
202 
203  if (theTracer == theDefaultTracer) {
204  G4cout <<
205 "G4RTMessenger::SetNewValue: No valid current viewer. Using default RayTracer."
206  << G4endl;
207  }
208 
209  if(command==columnCmd)
210  { theTracer->SetNColumn(columnCmd->GetNewIntValue(newValue)); }
211  else if(command==rowCmd)
212  { theTracer->SetNRow(rowCmd->GetNewIntValue(newValue)); }
213  else if(command==targetCmd)
215  else if(command==eyePosCmd)
217  else if(command==lightCmd)
219  else if(command==spanXCmd)
221  else if(command==headCmd)
223  else if(command==attCmd)
225  else if(command==distCmd)
227  else if(command==bkgColCmd)
228  {
229  G4cout << "WARNING: /vis/rayTracer/backgroundColour has been deprecated."
230  "\n Use \"/vis/viewer/set/background\" instead."
231  << G4endl;
232  }
233  else if(command==transCmd)
235  else if(command==fileCmd)
236  { theTracer->Trace(newValue); }
237 }
238 
239 
240 
241 
242