Geant4  10.03.p01
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 86973 2014-11-21 11:57:27Z 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 
48 G4RTMessenger* G4RTMessenger::fpInstance = 0;
49 
52 {
53  if (!fpInstance) fpInstance = new G4RTMessenger(p1);
54  return fpInstance;
55 }
56 
57 G4RTMessenger::G4RTMessenger(G4TheRayTracer* p1)
58 {
59  theDefaultTracer = p1;
60  theTracer = theDefaultTracer;
61 
62  rayDirectory = new G4UIdirectory("/vis/rayTracer/");
63  rayDirectory->SetGuidance("RayTracer commands.");
64 
65  fileCmd = new G4UIcmdWithAString("/vis/rayTracer/trace",this);
66  fileCmd->SetGuidance("Start the ray tracing.");
67  fileCmd->SetGuidance("Define the name of output JPEG file.");
68  fileCmd->SetParameterName("fileName",true);
69  fileCmd->SetDefaultValue("g4RayTracer.jpeg");
71 
72  columnCmd = new G4UIcmdWithAnInteger("/vis/rayTracer/column",this);
73  columnCmd->SetGuidance("Define the number of horizontal pixels.");
74  columnCmd->SetParameterName("nPixel",false);
75  columnCmd->SetRange("nPixel > 0");
76 
77  rowCmd = new G4UIcmdWithAnInteger("/vis/rayTracer/row",this);
78  rowCmd->SetGuidance("Define the number of virtical pixels.");
79  rowCmd->SetParameterName("nPixel",false);
80  rowCmd->SetRange("nPixel > 0");
81 
82  targetCmd = new G4UIcmdWith3VectorAndUnit("/vis/rayTracer/target",this);
83  targetCmd->SetGuidance("Define the center position of the target.");
84  targetCmd->SetParameterName("X","Y","Z",true);
85  targetCmd->SetDefaultValue(G4ThreeVector(0.,0.,0.));
86  targetCmd->SetDefaultUnit("m");
87 
88  eyePosCmd = new G4UIcmdWith3VectorAndUnit("/vis/rayTracer/eyePosition",this);
89  eyePosCmd->SetGuidance("Define the eye position.");
90  eyePosCmd->SetGuidance("Eye direction is calsurated from (target - eyePosition).");
91  eyePosCmd->SetParameterName("X","Y","Z",true);
92  eyePosCmd->SetDefaultValue(G4ThreeVector(0.,0.,0.));
93  eyePosCmd->SetDefaultUnit("m");
94 
95  lightCmd = new G4UIcmdWith3Vector("/vis/rayTracer/lightDirection",this);
96  lightCmd->SetGuidance("Define the direction of illumination light.");
97  lightCmd->SetGuidance("The vector needs not to be a unit vector, but it must not be a zero vector.");
98  lightCmd->SetParameterName("Px","Py","Pz",true);
99  lightCmd->SetDefaultValue(G4ThreeVector(0.1,0.2,0.3));
100  lightCmd->SetRange("Px != 0 || Py != 0 || Pz != 0");
101 
102  spanXCmd = new G4UIcmdWithADoubleAndUnit("/vis/rayTracer/span",this);
103  spanXCmd->SetGuidance("Define the angle per 100 pixels.");
104  spanXCmd->SetParameterName("span",true);
105  spanXCmd->SetDefaultValue(50.);
106  spanXCmd->SetDefaultUnit("deg");
107  spanXCmd->SetRange("span>0.");
108 
109  headCmd = new G4UIcmdWithADoubleAndUnit("/vis/rayTracer/headAngle",this);
110  headCmd->SetGuidance("Define the head direction.");
111  headCmd->SetParameterName("headAngle",true);
112  headCmd->SetDefaultValue(270.);
113  headCmd->SetDefaultUnit("deg");
114  headCmd->SetRange("headAngle>=0. && headAngle<360.");
115 
116  attCmd = new G4UIcmdWithADoubleAndUnit("/vis/rayTracer/attenuation",this);
117  attCmd->SetGuidance("Define the attenuation length for transparent material.");
118  attCmd->SetGuidance("Note that this value is independent to the attenuation length for the optical photon processes.");
119  attCmd->SetParameterName("Length",true);
120  attCmd->SetDefaultValue(1.0);
121  attCmd->SetDefaultUnit("m");
122  attCmd->SetRange("Length > 0.");
123 
124  distCmd = new G4UIcmdWithABool("/vis/rayTracer/distortion",this);
125  distCmd->SetGuidance("Distortion effect of the fish eye lens.");
126  distCmd->SetParameterName("flag",true);
127  distCmd->SetDefaultValue(false);
128 
129  transCmd = new G4UIcmdWithABool("/vis/rayTracer/ignoreTransparency",this);
130  transCmd->SetGuidance("Ignore transparency even if the alpha of G4Colour < 1.");
131  transCmd->SetParameterName("flag",true);
132  transCmd->SetDefaultValue(false);
133 
134  bkgColCmd = new G4UIcmdWith3Vector("/vis/rayTracer/backgroundColour",this);
135  bkgColCmd->SetGuidance("Command has been deprecated. Use /vis/viewer/set/background instead.");
136  bkgColCmd->SetParameterName("red","green","blue",true);
137  bkgColCmd->SetDefaultValue(G4ThreeVector(1.,1.,1.));
138 }
139 
141 {
142  delete columnCmd;
143  delete rowCmd;
144  delete targetCmd;
145  delete eyePosCmd;
146  delete lightCmd;
147  delete spanXCmd;
148  delete headCmd;
149  delete attCmd;
150  delete distCmd;
151  delete transCmd;
152  delete fileCmd;
153  delete bkgColCmd;
154  delete rayDirectory;
155 }
156 
158 {
159  G4String currentValue;
160  if(command==columnCmd)
161  { currentValue = columnCmd->ConvertToString(theTracer->GetNColumn()); }
162  else if(command==rowCmd)
163  { currentValue = rowCmd->ConvertToString(theTracer->GetNRow()); }
164  else if(command==targetCmd)
165  { currentValue = targetCmd->ConvertToString(theTracer->GetTargetPosition(),"m"); }
166  else if(command==eyePosCmd)
167  { currentValue = eyePosCmd->ConvertToString(theTracer->GetEyePosition(),"m"); }
168  else if(command==lightCmd)
169  { currentValue = lightCmd->ConvertToString(theTracer->GetLightDirection()); }
170  else if(command==spanXCmd)
171  { currentValue = spanXCmd->ConvertToString(theTracer->GetViewSpan(),"deg"); }
172  else if(command==headCmd)
173  { currentValue = headCmd->ConvertToString(theTracer->GetHeadAngle(),"deg"); }
174  else if(command==attCmd)
175  { currentValue = attCmd->ConvertToString(theTracer->GetAttenuationLength(),"m");}
176  else if(command==distCmd)
177  { currentValue = distCmd->ConvertToString(theTracer->GetDistortion()); }
178  else if(command==transCmd)
179  { currentValue = transCmd->ConvertToString(G4RTSteppingAction::GetIgnoreTransparency()); }
180  else if(command==bkgColCmd)
181  { currentValue = bkgColCmd->ConvertToString(theTracer->GetBackgroundColour()); }
182  return currentValue;
183 }
184 
186 {
187  G4VisManager* pVisManager = G4VisManager::GetInstance();
188 
189  theTracer = theDefaultTracer;
190 
191  G4VViewer* pVViewer = pVisManager->GetCurrentViewer();
192  if (pVViewer) {
193  G4RayTracerViewer* pViewer = dynamic_cast<G4RayTracerViewer*>(pVViewer);
194  if (pViewer) {
195  theTracer = pViewer->GetTracer();
196  } else {
197  G4cout <<
198  "G4RTMessenger::SetNewValue: Current viewer is not of type RayTracer."
199  "\n Use \"/vis/viewer/select\" or \"/vis/open\"."
200  << G4endl;
201  }
202  }
203 
204  if (theTracer == theDefaultTracer) {
205  G4cout <<
206 "G4RTMessenger::SetNewValue: No valid current viewer. Using default RayTracer."
207  << G4endl;
208  }
209 
210  if(command==columnCmd)
211  { theTracer->SetNColumn(columnCmd->GetNewIntValue(newValue)); }
212  else if(command==rowCmd)
213  { theTracer->SetNRow(rowCmd->GetNewIntValue(newValue)); }
214  else if(command==targetCmd)
215  { theTracer->SetTargetPosition(targetCmd->GetNew3VectorValue(newValue)); }
216  else if(command==eyePosCmd)
217  { theTracer->SetEyePosition(eyePosCmd->GetNew3VectorValue(newValue)); }
218  else if(command==lightCmd)
219  { theTracer->SetLightDirection(lightCmd->GetNew3VectorValue(newValue)); }
220  else if(command==spanXCmd)
221  { theTracer->SetViewSpan(spanXCmd->GetNewDoubleValue(newValue)); }
222  else if(command==headCmd)
223  { theTracer->SetHeadAngle(headCmd->GetNewDoubleValue(newValue)); }
224  else if(command==attCmd)
225  { theTracer->SetAttenuationLength(attCmd->GetNewDoubleValue(newValue)); }
226  else if(command==distCmd)
227  { theTracer->SetDistortion(distCmd->GetNewBoolValue(newValue)); }
228  else if(command==bkgColCmd)
229  {
230  G4cout << "WARNING: /vis/rayTracer/backgroundColour has been deprecated."
231  "\n Use \"/vis/viewer/set/background\" instead."
232  << G4endl;
233  }
234  else if(command==transCmd)
236  else if(command==fileCmd)
237  { theTracer->Trace(newValue); }
238 }
239 
240 
241 
242 
243 
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
void SetLightDirection(const G4ThreeVector &val)
void SetHeadAngle(G4double val)
static G4bool GetIgnoreTransparency()
G4ThreeVector GetLightDirection() const
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
CLHEP::Hep3Vector G4ThreeVector
G4int GetNColumn() const
virtual ~G4RTMessenger()
static G4int GetNewIntValue(const char *paramString)
void SetDefaultUnit(const char *defUnit)
void SetParameterName(const char *theNameX, const char *theNameY, const char *theNameZ, G4bool omittable, G4bool currentAsDefault=false)
static G4ThreeVector GetNew3VectorValue(const char *paramString)
G4TheRayTracer * GetTracer()
static G4RTMessenger * GetInstance(G4TheRayTracer *p1)
static G4String ConvertToString(G4bool boolVal)
Definition: G4UIcommand.cc:372
void SetNRow(G4int val)
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)
void SetDefaultValue(G4bool defVal)
virtual void SetNewValue(G4UIcommand *command, G4String newValue)
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
virtual void Trace(const G4String &fileName)
virtual G4String GetCurrentValue(G4UIcommand *command)
G4GLOB_DLL std::ostream G4cout
static G4ThreeVector GetNew3VectorValue(const char *paramString)
void SetRange(const char *rs)
Definition: G4UIcommand.hh:125
void SetGuidance(const char *aGuidance)
Definition: G4UIcommand.hh:161
void SetViewSpan(G4double val)
static G4VisManager * GetInstance()
void AvailableForStates(G4ApplicationState s1)
Definition: G4UIcommand.cc:240
G4double GetAttenuationLength() const
void SetDefaultValue(G4ThreeVector defVal)
G4Colour GetBackgroundColour() const
G4ThreeVector GetEyePosition() const
void SetDefaultValue(const char *defVal)
static void SetIgnoreTransparency(G4bool val)
void SetDefaultUnit(const char *defUnit)
#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)
void SetTargetPosition(const G4ThreeVector &val)