Geant4  10.00.p01
G4RTMessenger.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 // $Id: G4RTMessenger.cc 74050 2013-09-20 09:38:19Z gcosmo $
28 //
29 //
30 //
31 
32 
33 #include "G4RTMessenger.hh"
34 
35 #include "G4UIdirectory.hh"
36 #include "G4UIcmdWithABool.hh"
37 #include "G4UIcmdWith3Vector.hh"
40 #include "G4UIcmdWithAnInteger.hh"
41 #include "G4UIcmdWithAString.hh"
42 #include "G4RTSteppingAction.hh"
43 #include "G4ThreeVector.hh"
44 #include "G4VisManager.hh"
45 #include "G4RayTracerViewer.hh"
46 #include "G4TheRayTracer.hh"
47 
49 
52 {
53  if (!fpInstance) fpInstance = new G4RTMessenger(p1);
54  return fpInstance;
55 }
56 
58 {
59  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 virtical 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 calsurated 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 
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
void SetLightDirection(const G4ThreeVector &val)
void SetHeadAngle(G4double val)
static G4bool GetIgnoreTransparency()
G4UIcmdWithADoubleAndUnit * headCmd
G4ThreeVector GetLightDirection() const
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
G4UIcmdWithADoubleAndUnit * spanXCmd
CLHEP::Hep3Vector G4ThreeVector
G4int GetNColumn() const
virtual ~G4RTMessenger()
static G4int GetNewIntValue(const char *paramString)
G4UIcmdWithABool * transCmd
void SetDefaultUnit(const char *defUnit)
G4UIcmdWith3VectorAndUnit * targetCmd
void SetParameterName(const char *theNameX, const char *theNameY, const char *theNameZ, G4bool omittable, G4bool currentAsDefault=false)
G4UIcmdWithAnInteger * columnCmd
static G4ThreeVector GetNew3VectorValue(const char *paramString)
G4TheRayTracer * GetTracer()
G4UIcmdWith3VectorAndUnit * eyePosCmd
static G4RTMessenger * GetInstance(G4TheRayTracer *p1)
static G4String ConvertToString(G4bool boolVal)
Definition: G4UIcommand.cc:357
void SetNRow(G4int val)
G4UIcmdWithAnInteger * rowCmd
void SetNColumn(G4int val)
G4int GetNRow() const
static G4double GetNewDoubleValue(const char *paramString)
void SetParameterName(const char *theNameX, const char *theNameY, const char *theNameZ, G4bool omittable, G4bool currentAsDefault=false)
G4ThreeVector GetTargetPosition() const
static G4bool GetNewBoolValue(const char *paramString)
G4TheRayTracer * theDefaultTracer
void SetDefaultValue(G4bool defVal)
G4UIcmdWithABool * distCmd
virtual void SetNewValue(G4UIcommand *command, G4String newValue)
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
G4RTMessenger(G4TheRayTracer *p1)
virtual void Trace(const G4String &fileName)
virtual G4String GetCurrentValue(G4UIcommand *command)
G4GLOB_DLL std::ostream G4cout
static G4ThreeVector GetNew3VectorValue(const char *paramString)
static G4RTMessenger * fpInstance
void SetRange(const char *rs)
Definition: G4UIcommand.hh:125
void SetGuidance(const char *aGuidance)
Definition: G4UIcommand.hh:161
void SetViewSpan(G4double val)
G4UIcmdWithAString * fileCmd
static G4VisManager * GetInstance()
void AvailableForStates(G4ApplicationState s1)
Definition: G4UIcommand.cc:225
G4double GetAttenuationLength() const
G4UIcmdWith3Vector * lightCmd
void SetDefaultValue(G4ThreeVector defVal)
G4Colour GetBackgroundColour() const
G4ThreeVector GetEyePosition() const
void SetDefaultValue(const char *defVal)
G4UIcmdWith3Vector * bkgColCmd
static void SetIgnoreTransparency(G4bool val)
void SetDefaultUnit(const char *defUnit)
G4UIcmdWithADoubleAndUnit * attCmd
G4TheRayTracer * theTracer
#define G4endl
Definition: G4ios.hh:61
G4VViewer * GetCurrentViewer() const
G4double GetHeadAngle() const
void SetDistortion(G4bool val)
void SetDefaultValue(G4ThreeVector defVal)
void SetEyePosition(const G4ThreeVector &val)
G4double GetViewSpan() const
G4bool GetDistortion() const
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
void SetAttenuationLength(G4double val)
G4UIdirectory * rayDirectory
void SetTargetPosition(const G4ThreeVector &val)