Geant4 10.7.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
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//
28//
29//
30
31
32#include "G4RTMessenger.hh"
33
34#include "G4UIdirectory.hh"
35#include "G4UIcmdWithABool.hh"
36#include "G4UIcmdWith3Vector.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
47G4RTMessenger* G4RTMessenger::fpInstance = 0;
48
51{
52 if (!fpInstance) fpInstance = new G4RTMessenger(p1);
53 return fpInstance;
54}
55
56G4RTMessenger::G4RTMessenger(G4TheRayTracer* p1)
57{
58 theDefaultTracer = p1;
59 theTracer = theDefaultTracer;
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);
84 targetCmd->SetDefaultValue(G4ThreeVector(0.,0.,0.));
85 targetCmd->SetDefaultUnit("m");
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);
91 eyePosCmd->SetDefaultValue(G4ThreeVector(0.,0.,0.));
92 eyePosCmd->SetDefaultUnit("m");
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);
104 spanXCmd->SetDefaultValue(50.);
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);
136 bkgColCmd->SetDefaultValue(G4ThreeVector(1.,1.,1.));
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)
178 { currentValue = transCmd->ConvertToString(G4RTSteppingAction::GetIgnoreTransparency()); }
179 else if(command==bkgColCmd)
180 { currentValue = bkgColCmd->ConvertToString(theTracer->GetBackgroundColour()); }
181 return currentValue;
182}
183
185{
187
188 theTracer = theDefaultTracer;
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)
214 { theTracer->SetTargetPosition(targetCmd->GetNew3VectorValue(newValue)); }
215 else if(command==eyePosCmd)
216 { theTracer->SetEyePosition(eyePosCmd->GetNew3VectorValue(newValue)); }
217 else if(command==lightCmd)
218 { theTracer->SetLightDirection(lightCmd->GetNew3VectorValue(newValue)); }
219 else if(command==spanXCmd)
220 { theTracer->SetViewSpan(spanXCmd->GetNewDoubleValue(newValue)); }
221 else if(command==headCmd)
222 { theTracer->SetHeadAngle(headCmd->GetNewDoubleValue(newValue)); }
223 else if(command==attCmd)
224 { theTracer->SetAttenuationLength(attCmd->GetNewDoubleValue(newValue)); }
225 else if(command==distCmd)
226 { theTracer->SetDistortion(distCmd->GetNewBoolValue(newValue)); }
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
@ G4State_Idle
CLHEP::Hep3Vector G4ThreeVector
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
virtual void SetNewValue(G4UIcommand *command, G4String newValue)
virtual G4String GetCurrentValue(G4UIcommand *command)
virtual ~G4RTMessenger()
static G4RTMessenger * GetInstance(G4TheRayTracer *p1)
static G4bool GetIgnoreTransparency()
static void SetIgnoreTransparency(G4bool val)
G4TheRayTracer * GetTracer()
void SetTargetPosition(const G4ThreeVector &val)
G4double GetViewSpan() const
G4int GetNColumn() const
void SetViewSpan(G4double val)
void SetNRow(G4int val)
G4double GetHeadAngle() const
virtual void Trace(const G4String &fileName)
G4bool GetDistortion() const
void SetNColumn(G4int val)
void SetLightDirection(const G4ThreeVector &val)
void SetDistortion(G4bool val)
G4ThreeVector GetTargetPosition() const
void SetAttenuationLength(G4double val)
G4Colour GetBackgroundColour() const
G4ThreeVector GetLightDirection() const
G4ThreeVector GetEyePosition() const
void SetHeadAngle(G4double val)
G4double GetAttenuationLength() const
G4int GetNRow() const
void SetEyePosition(const G4ThreeVector &val)
void SetDefaultUnit(const char *defUnit)
static G4ThreeVector GetNew3VectorValue(const char *paramString)
void SetParameterName(const char *theNameX, const char *theNameY, const char *theNameZ, G4bool omittable, G4bool currentAsDefault=false)
void SetDefaultValue(G4ThreeVector defVal)
static G4ThreeVector GetNew3VectorValue(const char *paramString)
void SetParameterName(const char *theNameX, const char *theNameY, const char *theNameZ, G4bool omittable, G4bool currentAsDefault=false)
void SetDefaultValue(G4ThreeVector defVal)
static G4bool GetNewBoolValue(const char *paramString)
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
void SetDefaultValue(G4bool defVal)
void SetDefaultUnit(const char *defUnit)
static G4double GetNewDoubleValue(const char *paramString)
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
void SetDefaultValue(const char *defVal)
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
static G4int GetNewIntValue(const char *paramString)
static G4String ConvertToString(G4bool boolVal)
Definition: G4UIcommand.cc:430
void SetGuidance(const char *aGuidance)
Definition: G4UIcommand.hh:156
void SetRange(const char *rs)
Definition: G4UIcommand.hh:120
void AvailableForStates(G4ApplicationState s1)
Definition: G4UIcommand.cc:273
G4VViewer * GetCurrentViewer() const
static G4VisManager * GetInstance()