00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include "G4RTMessenger.hh"
00034
00035 #include "G4UIdirectory.hh"
00036 #include "G4UIcmdWithABool.hh"
00037 #include "G4UIcmdWith3Vector.hh"
00038 #include "G4UIcmdWith3VectorAndUnit.hh"
00039 #include "G4UIcmdWithADoubleAndUnit.hh"
00040 #include "G4UIcmdWithAnInteger.hh"
00041 #include "G4UIcmdWithAString.hh"
00042 #include "G4TheRayTracer.hh"
00043 #include "G4RTSteppingAction.hh"
00044 #include "G4ThreeVector.hh"
00045 #include "G4VisManager.hh"
00046 #include "G4RayTracerViewer.hh"
00047
00048 G4RTMessenger* G4RTMessenger::fpInstance = 0;
00049
00050 G4RTMessenger* G4RTMessenger::GetInstance
00051 (G4TheRayTracer* p1,G4RTSteppingAction* p2)
00052 {
00053 if (!fpInstance) fpInstance = new G4RTMessenger(p1, p2);
00054 return fpInstance;
00055 }
00056
00057 G4RTMessenger::G4RTMessenger(G4TheRayTracer* p1,G4RTSteppingAction* p2)
00058 {
00059 theDefaultTracer = p1;
00060 theSteppingAction = p2;
00061
00062 rayDirectory = new G4UIdirectory("/vis/rayTracer/");
00063 rayDirectory->SetGuidance("RayTracer commands.");
00064
00065 fileCmd = new G4UIcmdWithAString("/vis/rayTracer/trace",this);
00066 fileCmd->SetGuidance("Start the ray tracing.");
00067 fileCmd->SetGuidance("Define the name of output JPEG file.");
00068 fileCmd->SetParameterName("fileName",true);
00069 fileCmd->SetDefaultValue("g4RayTracer.jpeg");
00070 fileCmd->AvailableForStates(G4State_Idle);
00071
00072 columnCmd = new G4UIcmdWithAnInteger("/vis/rayTracer/column",this);
00073 columnCmd->SetGuidance("Define the number of horizontal pixels.");
00074 columnCmd->SetParameterName("nPixel",false);
00075 columnCmd->SetRange("nPixel > 0");
00076
00077 rowCmd = new G4UIcmdWithAnInteger("/vis/rayTracer/row",this);
00078 rowCmd->SetGuidance("Define the number of virtical pixels.");
00079 rowCmd->SetParameterName("nPixel",false);
00080 rowCmd->SetRange("nPixel > 0");
00081
00082 targetCmd = new G4UIcmdWith3VectorAndUnit("/vis/rayTracer/target",this);
00083 targetCmd->SetGuidance("Define the center position of the target.");
00084 targetCmd->SetParameterName("X","Y","Z",true);
00085 targetCmd->SetDefaultValue(G4ThreeVector(0.,0.,0.));
00086 targetCmd->SetDefaultUnit("m");
00087
00088 eyePosCmd = new G4UIcmdWith3VectorAndUnit("/vis/rayTracer/eyePosition",this);
00089 eyePosCmd->SetGuidance("Define the eye position.");
00090 eyePosCmd->SetGuidance("Eye direction is calsurated from (target - eyePosition).");
00091 eyePosCmd->SetParameterName("X","Y","Z",true);
00092 eyePosCmd->SetDefaultValue(G4ThreeVector(0.,0.,0.));
00093 eyePosCmd->SetDefaultUnit("m");
00094
00095 lightCmd = new G4UIcmdWith3Vector("/vis/rayTracer/lightDirection",this);
00096 lightCmd->SetGuidance("Define the direction of illumination light.");
00097 lightCmd->SetGuidance("The vector needs not to be a unit vector, but it must not be a zero vector.");
00098 lightCmd->SetParameterName("Px","Py","Pz",true);
00099 lightCmd->SetDefaultValue(G4ThreeVector(0.1,0.2,0.3));
00100 lightCmd->SetRange("Px != 0 || Py != 0 || Pz != 0");
00101
00102 spanXCmd = new G4UIcmdWithADoubleAndUnit("/vis/rayTracer/span",this);
00103 spanXCmd->SetGuidance("Define the angle per 100 pixels.");
00104 spanXCmd->SetParameterName("span",true);
00105 spanXCmd->SetDefaultValue(50.);
00106 spanXCmd->SetDefaultUnit("deg");
00107 spanXCmd->SetRange("span>0.");
00108
00109 headCmd = new G4UIcmdWithADoubleAndUnit("/vis/rayTracer/headAngle",this);
00110 headCmd->SetGuidance("Define the head direction.");
00111 headCmd->SetParameterName("headAngle",true);
00112 headCmd->SetDefaultValue(270.);
00113 headCmd->SetDefaultUnit("deg");
00114 headCmd->SetRange("headAngle>=0. && headAngle<360.");
00115
00116 attCmd = new G4UIcmdWithADoubleAndUnit("/vis/rayTracer/attenuation",this);
00117 attCmd->SetGuidance("Define the attenuation length for transparent material.");
00118 attCmd->SetGuidance("Note that this value is independent to the attenuation length for the optical photon processes.");
00119 attCmd->SetParameterName("Length",true);
00120 attCmd->SetDefaultValue(1.0);
00121 attCmd->SetDefaultUnit("m");
00122 attCmd->SetRange("Length > 0.");
00123
00124 distCmd = new G4UIcmdWithABool("/vis/rayTracer/distortion",this);
00125 distCmd->SetGuidance("Distortion effect of the fish eye lens.");
00126 distCmd->SetParameterName("flag",true);
00127 distCmd->SetDefaultValue(false);
00128
00129 transCmd = new G4UIcmdWithABool("/vis/rayTracer/ignoreTransparency",this);
00130 transCmd->SetGuidance("Ignore transparency even if the alpha of G4Colour < 1.");
00131 transCmd->SetParameterName("flag",true);
00132 transCmd->SetDefaultValue(false);
00133
00134 bkgColCmd = new G4UIcmdWith3Vector("/vis/rayTracer/backgroundColour",this);
00135 bkgColCmd->SetGuidance("Command has been deprecated. Use /vis/viewer/set/background instead.");
00136 bkgColCmd->SetParameterName("red","green","blue",true);
00137 bkgColCmd->SetDefaultValue(G4ThreeVector(1.,1.,1.));
00138 }
00139
00140 G4RTMessenger::~G4RTMessenger()
00141 {
00142 delete columnCmd;
00143 delete rowCmd;
00144 delete targetCmd;
00145 delete eyePosCmd;
00146 delete lightCmd;
00147 delete spanXCmd;
00148 delete headCmd;
00149 delete attCmd;
00150 delete distCmd;
00151 delete transCmd;
00152 delete fileCmd;
00153 delete bkgColCmd;
00154 delete rayDirectory;
00155 }
00156
00157 G4String G4RTMessenger::GetCurrentValue(G4UIcommand * command)
00158 {
00159 G4String currentValue;
00160 if(command==columnCmd)
00161 { currentValue = columnCmd->ConvertToString(theTracer->GetNColumn()); }
00162 else if(command==rowCmd)
00163 { currentValue = rowCmd->ConvertToString(theTracer->GetNRow()); }
00164 else if(command==targetCmd)
00165 { currentValue = targetCmd->ConvertToString(theTracer->GetTargetPosition(),"m"); }
00166 else if(command==eyePosCmd)
00167 { currentValue = eyePosCmd->ConvertToString(theTracer->GetEyePosition(),"m"); }
00168 else if(command==lightCmd)
00169 { currentValue = lightCmd->ConvertToString(theTracer->GetLightDirection()); }
00170 else if(command==spanXCmd)
00171 { currentValue = spanXCmd->ConvertToString(theTracer->GetViewSpan(),"deg"); }
00172 else if(command==headCmd)
00173 { currentValue = headCmd->ConvertToString(theTracer->GetHeadAngle(),"deg"); }
00174 else if(command==attCmd)
00175 { currentValue = attCmd->ConvertToString(theTracer->GetAttenuationLength(),"m");}
00176 else if(command==distCmd)
00177 { currentValue = distCmd->ConvertToString(theTracer->GetDistortion()); }
00178 else if(command==transCmd)
00179 { currentValue = transCmd->ConvertToString(theSteppingAction->GetIgnoreTransparency()); }
00180 else if(command==bkgColCmd)
00181 { currentValue = bkgColCmd->ConvertToString(theTracer->GetBackgroundColour()); }
00182 return currentValue;
00183 }
00184
00185 void G4RTMessenger::SetNewValue(G4UIcommand * command,G4String newValue)
00186 {
00187 G4VisManager* pVisManager = G4VisManager::GetInstance();
00188
00189 theTracer = theDefaultTracer;
00190
00191 G4VViewer* pVViewer = pVisManager->GetCurrentViewer();
00192 if (pVViewer) {
00193 G4RayTracerViewer* pViewer = dynamic_cast<G4RayTracerViewer*>(pVViewer);
00194 if (pViewer) {
00195 theTracer = pViewer->GetTracer();
00196 } else {
00197 G4cout <<
00198 "G4RTMessenger::SetNewValue: Current viewer is not of type RayTracer."
00199 "\n Use \"/vis/viewer/select\" or \"/vis/open\"."
00200 << G4endl;
00201 }
00202 }
00203
00204 if (theTracer == theDefaultTracer) {
00205 G4cout <<
00206 "G4RTMessenger::SetNewValue: No valid current viewer. Using default RayTracer."
00207 << G4endl;
00208 }
00209
00210 if(command==columnCmd)
00211 { theTracer->SetNColumn(columnCmd->GetNewIntValue(newValue)); }
00212 else if(command==rowCmd)
00213 { theTracer->SetNRow(rowCmd->GetNewIntValue(newValue)); }
00214 else if(command==targetCmd)
00215 { theTracer->SetTargetPosition(targetCmd->GetNew3VectorValue(newValue)); }
00216 else if(command==eyePosCmd)
00217 { theTracer->SetEyePosition(eyePosCmd->GetNew3VectorValue(newValue)); }
00218 else if(command==lightCmd)
00219 { theTracer->SetLightDirection(lightCmd->GetNew3VectorValue(newValue)); }
00220 else if(command==spanXCmd)
00221 { theTracer->SetViewSpan(spanXCmd->GetNewDoubleValue(newValue)); }
00222 else if(command==headCmd)
00223 { theTracer->SetHeadAngle(headCmd->GetNewDoubleValue(newValue)); }
00224 else if(command==attCmd)
00225 { theTracer->SetAttenuationLength(attCmd->GetNewDoubleValue(newValue)); }
00226 else if(command==distCmd)
00227 { theTracer->SetDistortion(distCmd->GetNewBoolValue(newValue)); }
00228 else if(command==bkgColCmd)
00229 {
00230 G4cout << "WARNING: /vis/rayTracer/backgroundColour has been deprecated."
00231 "\n Use \"/vis/viewer/set/background\" instead."
00232 << G4endl;
00233 }
00234 else if(command==transCmd)
00235 { theSteppingAction->SetIgnoreTransparency(transCmd->GetNewBoolValue(newValue)); }
00236 else if(command==fileCmd)
00237 { theTracer->Trace(newValue); }
00238 }
00239
00240
00241
00242
00243