Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer << 3 // * DISCLAIMER * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th << 5 // * The following disclaimer summarizes all the specific disclaimers * 6 // * the Geant4 Collaboration. It is provided << 6 // * of contributors to this software. The specific disclaimers,which * 7 // * conditions of the Geant4 Software License << 7 // * govern, are listed with their locations in: * 8 // * LICENSE and available at http://cern.ch/ << 8 // * http://cern.ch/geant4/license * 9 // * include a list of copyright holders. << 10 // * 9 // * * 11 // * Neither the authors of this software syst 10 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 11 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 12 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 13 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file << 14 // * use. * 16 // * for the full disclaimer and the limitatio << 17 // * 15 // * * 18 // * This code implementation is the result << 16 // * This code implementation is the intellectual property of the * 19 // * technical work of the GEANT4 collaboratio << 17 // * GEANT4 collaboration. * 20 // * By using, copying, modifying or distri << 18 // * By copying, distributing or modifying the Program (or any work * 21 // * any work based on the software) you ag << 19 // * based on the Program) you indicate your acceptance of this * 22 // * use in resulting scientific publicati << 20 // * statement, and all its terms. * 23 // * acceptance of all terms of the Geant4 Sof << 24 // ******************************************* 21 // ******************************************************************** 25 // 22 // 26 // 23 // >> 24 // $Id: G4RTMessenger.cc,v 1.4.4.1 2001/06/28 19:15:53 gunter Exp $ >> 25 // GEANT4 tag $Name: $ 27 // 26 // 28 // 27 // 29 // 28 // 30 29 31 30 32 #include "G4RTMessenger.hh" 31 #include "G4RTMessenger.hh" 33 32 34 #include "G4UIdirectory.hh" 33 #include "G4UIdirectory.hh" 35 #include "G4UIcmdWithABool.hh" 34 #include "G4UIcmdWithABool.hh" 36 #include "G4UIcmdWith3Vector.hh" 35 #include "G4UIcmdWith3Vector.hh" 37 #include "G4UIcmdWith3VectorAndUnit.hh" 36 #include "G4UIcmdWith3VectorAndUnit.hh" 38 #include "G4UIcmdWithADoubleAndUnit.hh" 37 #include "G4UIcmdWithADoubleAndUnit.hh" 39 #include "G4UIcmdWithAnInteger.hh" 38 #include "G4UIcmdWithAnInteger.hh" 40 #include "G4UIcmdWithAString.hh" 39 #include "G4UIcmdWithAString.hh" >> 40 #include "G4RayTracer.hh" 41 #include "G4RTSteppingAction.hh" 41 #include "G4RTSteppingAction.hh" 42 #include "G4ThreeVector.hh" 42 #include "G4ThreeVector.hh" 43 #include "G4VisManager.hh" << 44 #include "G4RayTracerViewer.hh" << 45 #include "G4TheRayTracer.hh" << 46 43 47 #define G4warn G4cout << 44 G4RTMessenger::G4RTMessenger(G4RayTracer* p1,G4RTSteppingAction* p2) 48 << 49 G4RTMessenger* G4RTMessenger::fpInstance = 0; << 50 << 51 G4RTMessenger* G4RTMessenger::GetInstance << 52 (G4TheRayTracer* p1) << 53 { << 54 if (!fpInstance) fpInstance = new G4RTMessen << 55 return fpInstance; << 56 } << 57 << 58 G4RTMessenger::G4RTMessenger(G4TheRayTracer* p << 59 { 45 { 60 theDefaultTracer = p1; << 46 theTracer = p1; 61 theTracer = theDefaultTracer; << 47 theSteppingAction = p2; 62 48 63 rayDirectory = new G4UIdirectory("/vis/rayTr 49 rayDirectory = new G4UIdirectory("/vis/rayTracer/"); 64 rayDirectory->SetGuidance("RayTracer command 50 rayDirectory->SetGuidance("RayTracer commands."); 65 51 66 fileCmd = new G4UIcmdWithAString("/vis/rayTr 52 fileCmd = new G4UIcmdWithAString("/vis/rayTracer/trace",this); 67 fileCmd->SetGuidance("Start the ray tracing. 53 fileCmd->SetGuidance("Start the ray tracing."); 68 fileCmd->SetGuidance("Define the name of out 54 fileCmd->SetGuidance("Define the name of output JPEG file."); 69 fileCmd->SetParameterName("fileName",true); 55 fileCmd->SetParameterName("fileName",true); 70 fileCmd->SetDefaultValue("g4RayTracer.jpeg") 56 fileCmd->SetDefaultValue("g4RayTracer.jpeg"); 71 fileCmd->AvailableForStates(G4State_Idle); << 57 fileCmd->AvailableForStates(Idle); 72 58 73 columnCmd = new G4UIcmdWithAnInteger("/vis/r 59 columnCmd = new G4UIcmdWithAnInteger("/vis/rayTracer/column",this); 74 columnCmd->SetGuidance("Define the number of 60 columnCmd->SetGuidance("Define the number of horizontal pixels."); 75 columnCmd->SetParameterName("nPixel",false); 61 columnCmd->SetParameterName("nPixel",false); 76 columnCmd->SetRange("nPixel > 0"); 62 columnCmd->SetRange("nPixel > 0"); 77 63 78 rowCmd = new G4UIcmdWithAnInteger("/vis/rayT 64 rowCmd = new G4UIcmdWithAnInteger("/vis/rayTracer/row",this); 79 rowCmd->SetGuidance("Define the number of ve << 65 rowCmd->SetGuidance("Define the number of virtical pixels."); 80 rowCmd->SetParameterName("nPixel",false); 66 rowCmd->SetParameterName("nPixel",false); 81 rowCmd->SetRange("nPixel > 0"); 67 rowCmd->SetRange("nPixel > 0"); 82 68 83 targetCmd = new G4UIcmdWith3VectorAndUnit("/ 69 targetCmd = new G4UIcmdWith3VectorAndUnit("/vis/rayTracer/target",this); 84 targetCmd->SetGuidance("Define the center po 70 targetCmd->SetGuidance("Define the center position of the target."); 85 targetCmd->SetParameterName("X","Y","Z",true 71 targetCmd->SetParameterName("X","Y","Z",true); 86 targetCmd->SetDefaultValue(G4ThreeVector(0., 72 targetCmd->SetDefaultValue(G4ThreeVector(0.,0.,0.)); 87 targetCmd->SetDefaultUnit("m"); 73 targetCmd->SetDefaultUnit("m"); 88 74 89 eyePosCmd = new G4UIcmdWith3VectorAndUnit("/ 75 eyePosCmd = new G4UIcmdWith3VectorAndUnit("/vis/rayTracer/eyePosition",this); 90 eyePosCmd->SetGuidance("Define the eye posit 76 eyePosCmd->SetGuidance("Define the eye position."); 91 eyePosCmd->SetGuidance("Eye direction is cal << 77 eyePosCmd->SetGuidance("Eye direction is calsurated from (target - eyePosition)."); 92 eyePosCmd->SetParameterName("X","Y","Z",true 78 eyePosCmd->SetParameterName("X","Y","Z",true); 93 eyePosCmd->SetDefaultValue(G4ThreeVector(0., 79 eyePosCmd->SetDefaultValue(G4ThreeVector(0.,0.,0.)); 94 eyePosCmd->SetDefaultUnit("m"); 80 eyePosCmd->SetDefaultUnit("m"); 95 81 96 lightCmd = new G4UIcmdWith3Vector("/vis/rayT 82 lightCmd = new G4UIcmdWith3Vector("/vis/rayTracer/lightDirection",this); 97 lightCmd->SetGuidance("Define the direction 83 lightCmd->SetGuidance("Define the direction of illumination light."); 98 lightCmd->SetGuidance("The vector needs not 84 lightCmd->SetGuidance("The vector needs not to be a unit vector, but it must not be a zero vector."); 99 lightCmd->SetParameterName("Px","Py","Pz",tr 85 lightCmd->SetParameterName("Px","Py","Pz",true); 100 lightCmd->SetDefaultValue(G4ThreeVector(0.1, 86 lightCmd->SetDefaultValue(G4ThreeVector(0.1,0.2,0.3)); 101 lightCmd->SetRange("Px != 0 || Py != 0 || Pz 87 lightCmd->SetRange("Px != 0 || Py != 0 || Pz != 0"); 102 88 103 spanXCmd = new G4UIcmdWithADoubleAndUnit("/v 89 spanXCmd = new G4UIcmdWithADoubleAndUnit("/vis/rayTracer/span",this); 104 spanXCmd->SetGuidance("Define the angle per 90 spanXCmd->SetGuidance("Define the angle per 100 pixels."); 105 spanXCmd->SetParameterName("span",true); 91 spanXCmd->SetParameterName("span",true); 106 spanXCmd->SetDefaultValue(50.); 92 spanXCmd->SetDefaultValue(50.); 107 spanXCmd->SetDefaultUnit("deg"); 93 spanXCmd->SetDefaultUnit("deg"); 108 spanXCmd->SetRange("span>0."); 94 spanXCmd->SetRange("span>0."); 109 95 110 headCmd = new G4UIcmdWithADoubleAndUnit("/vi 96 headCmd = new G4UIcmdWithADoubleAndUnit("/vis/rayTracer/headAngle",this); 111 headCmd->SetGuidance("Define the head direct 97 headCmd->SetGuidance("Define the head direction."); 112 headCmd->SetParameterName("headAngle",true); 98 headCmd->SetParameterName("headAngle",true); 113 headCmd->SetDefaultValue(270.); 99 headCmd->SetDefaultValue(270.); 114 headCmd->SetDefaultUnit("deg"); 100 headCmd->SetDefaultUnit("deg"); 115 headCmd->SetRange("headAngle>=0. && headAngl 101 headCmd->SetRange("headAngle>=0. && headAngle<360."); 116 102 117 attCmd = new G4UIcmdWithADoubleAndUnit("/vis 103 attCmd = new G4UIcmdWithADoubleAndUnit("/vis/rayTracer/attenuation",this); 118 attCmd->SetGuidance("Define the attenuation 104 attCmd->SetGuidance("Define the attenuation length for transparent material."); 119 attCmd->SetGuidance("Note that this value is 105 attCmd->SetGuidance("Note that this value is independent to the attenuation length for the optical photon processes."); 120 attCmd->SetParameterName("Length",true); 106 attCmd->SetParameterName("Length",true); 121 attCmd->SetDefaultValue(1.0); 107 attCmd->SetDefaultValue(1.0); 122 attCmd->SetDefaultUnit("m"); 108 attCmd->SetDefaultUnit("m"); 123 attCmd->SetRange("Length > 0."); 109 attCmd->SetRange("Length > 0."); 124 110 125 distCmd = new G4UIcmdWithABool("/vis/rayTrac 111 distCmd = new G4UIcmdWithABool("/vis/rayTracer/distortion",this); 126 distCmd->SetGuidance("Distortion effect of t 112 distCmd->SetGuidance("Distortion effect of the fish eye lens."); 127 distCmd->SetParameterName("flag",true); 113 distCmd->SetParameterName("flag",true); 128 distCmd->SetDefaultValue(false); 114 distCmd->SetDefaultValue(false); 129 115 130 transCmd = new G4UIcmdWithABool("/vis/rayTra 116 transCmd = new G4UIcmdWithABool("/vis/rayTracer/ignoreTransparency",this); 131 transCmd->SetGuidance("Ignore transparency e 117 transCmd->SetGuidance("Ignore transparency even if the alpha of G4Colour < 1."); 132 transCmd->SetParameterName("flag",true); 118 transCmd->SetParameterName("flag",true); 133 transCmd->SetDefaultValue(false); 119 transCmd->SetDefaultValue(false); 134 << 135 bkgColCmd = new G4UIcmdWith3Vector("/vis/ray << 136 bkgColCmd->SetGuidance("Command has been dep << 137 bkgColCmd->SetParameterName("red","green","b << 138 bkgColCmd->SetDefaultValue(G4ThreeVector(1., << 139 } 120 } 140 121 141 G4RTMessenger::~G4RTMessenger() 122 G4RTMessenger::~G4RTMessenger() 142 { 123 { 143 delete columnCmd; 124 delete columnCmd; 144 delete rowCmd; 125 delete rowCmd; 145 delete targetCmd; 126 delete targetCmd; 146 delete eyePosCmd; 127 delete eyePosCmd; 147 delete lightCmd; 128 delete lightCmd; 148 delete spanXCmd; 129 delete spanXCmd; 149 delete headCmd; 130 delete headCmd; 150 delete attCmd; 131 delete attCmd; 151 delete distCmd; 132 delete distCmd; 152 delete transCmd; 133 delete transCmd; 153 delete fileCmd; 134 delete fileCmd; 154 delete bkgColCmd; << 155 delete rayDirectory; 135 delete rayDirectory; 156 } 136 } 157 137 158 G4String G4RTMessenger::GetCurrentValue(G4UIco 138 G4String G4RTMessenger::GetCurrentValue(G4UIcommand * command) 159 { 139 { 160 G4String currentValue; 140 G4String currentValue; 161 if(command==columnCmd) 141 if(command==columnCmd) 162 { currentValue = columnCmd->ConvertToString( 142 { currentValue = columnCmd->ConvertToString(theTracer->GetNColumn()); } 163 else if(command==rowCmd) 143 else if(command==rowCmd) 164 { currentValue = rowCmd->ConvertToString(the 144 { currentValue = rowCmd->ConvertToString(theTracer->GetNRow()); } 165 else if(command==targetCmd) 145 else if(command==targetCmd) 166 { currentValue = targetCmd->ConvertToString( 146 { currentValue = targetCmd->ConvertToString(theTracer->GetTargetPosition(),"m"); } 167 else if(command==eyePosCmd) 147 else if(command==eyePosCmd) 168 { currentValue = eyePosCmd->ConvertToString( 148 { currentValue = eyePosCmd->ConvertToString(theTracer->GetEyePosition(),"m"); } 169 else if(command==lightCmd) 149 else if(command==lightCmd) 170 { currentValue = lightCmd->ConvertToString(t 150 { currentValue = lightCmd->ConvertToString(theTracer->GetLightDirection()); } 171 else if(command==spanXCmd) 151 else if(command==spanXCmd) 172 { currentValue = spanXCmd->ConvertToString(t 152 { currentValue = spanXCmd->ConvertToString(theTracer->GetViewSpan(),"deg"); } 173 else if(command==headCmd) 153 else if(command==headCmd) 174 { currentValue = headCmd->ConvertToString(th 154 { currentValue = headCmd->ConvertToString(theTracer->GetHeadAngle(),"deg"); } 175 else if(command==attCmd) 155 else if(command==attCmd) 176 { currentValue = attCmd->ConvertToString(the 156 { currentValue = attCmd->ConvertToString(theTracer->GetAttenuationLength(),"m");} 177 else if(command==distCmd) 157 else if(command==distCmd) 178 { currentValue = distCmd->ConvertToString(th 158 { currentValue = distCmd->ConvertToString(theTracer->GetDistortion()); } 179 else if(command==transCmd) 159 else if(command==transCmd) 180 { currentValue = transCmd->ConvertToString(G << 160 { currentValue = transCmd->ConvertToString(theSteppingAction->GetIgnoreTransparency()); } 181 else if(command==bkgColCmd) << 182 { currentValue = bkgColCmd->ConvertToString( << 183 return currentValue; 161 return currentValue; 184 } 162 } 185 163 186 void G4RTMessenger::SetNewValue(G4UIcommand * 164 void G4RTMessenger::SetNewValue(G4UIcommand * command,G4String newValue) 187 { 165 { 188 G4VisManager* pVisManager = G4VisManager::Ge << 189 << 190 theTracer = theDefaultTracer; << 191 << 192 G4VViewer* pVViewer = pVisManager->GetCurren << 193 if (pVViewer) { << 194 G4RayTracerViewer* pViewer = dynamic_cast< << 195 if (pViewer) { << 196 theTracer = pViewer->GetTracer(); << 197 } else { << 198 G4warn << << 199 "G4RTMessenger::SetNewValue: Current viewer << 200 "\n Use \"/vis/viewer/select\" or \"/vis/op << 201 << G4endl; << 202 } << 203 } << 204 << 205 if (theTracer == theDefaultTracer) { << 206 G4warn << << 207 "G4RTMessenger::SetNewValue: No valid current << 208 << G4endl; << 209 } << 210 << 211 if(command==columnCmd) 166 if(command==columnCmd) 212 { theTracer->SetNColumn(columnCmd->GetNewInt 167 { theTracer->SetNColumn(columnCmd->GetNewIntValue(newValue)); } 213 else if(command==rowCmd) 168 else if(command==rowCmd) 214 { theTracer->SetNRow(rowCmd->GetNewIntValue( 169 { theTracer->SetNRow(rowCmd->GetNewIntValue(newValue)); } 215 else if(command==targetCmd) 170 else if(command==targetCmd) 216 { theTracer->SetTargetPosition(targetCmd->Ge 171 { theTracer->SetTargetPosition(targetCmd->GetNew3VectorValue(newValue)); } 217 else if(command==eyePosCmd) 172 else if(command==eyePosCmd) 218 { theTracer->SetEyePosition(eyePosCmd->GetNe 173 { theTracer->SetEyePosition(eyePosCmd->GetNew3VectorValue(newValue)); } 219 else if(command==lightCmd) 174 else if(command==lightCmd) 220 { theTracer->SetLightDirection(lightCmd->Get 175 { theTracer->SetLightDirection(lightCmd->GetNew3VectorValue(newValue)); } 221 else if(command==spanXCmd) 176 else if(command==spanXCmd) 222 { theTracer->SetViewSpan(spanXCmd->GetNewDou 177 { theTracer->SetViewSpan(spanXCmd->GetNewDoubleValue(newValue)); } 223 else if(command==headCmd) 178 else if(command==headCmd) 224 { theTracer->SetHeadAngle(headCmd->GetNewDou 179 { theTracer->SetHeadAngle(headCmd->GetNewDoubleValue(newValue)); } 225 else if(command==attCmd) 180 else if(command==attCmd) 226 { theTracer->SetAttenuationLength(attCmd->Ge 181 { theTracer->SetAttenuationLength(attCmd->GetNewDoubleValue(newValue)); } 227 else if(command==distCmd) 182 else if(command==distCmd) 228 { theTracer->SetDistortion(distCmd->GetNewBo 183 { theTracer->SetDistortion(distCmd->GetNewBoolValue(newValue)); } 229 else if(command==bkgColCmd) << 230 { << 231 G4warn << "WARNING: /vis/rayTracer/backgroun << 232 "\n Use \"/vis/viewer/set/background\" inst << 233 << G4endl; << 234 } << 235 else if(command==transCmd) 184 else if(command==transCmd) 236 { G4RTSteppingAction::SetIgnoreTransparency( << 185 { theSteppingAction->SetIgnoreTransparency(transCmd->GetNewBoolValue(newValue)); } 237 else if(command==fileCmd) 186 else if(command==fileCmd) 238 { theTracer->Trace(newValue); } 187 { theTracer->Trace(newValue); } 239 } 188 } 240 189 241 190 242 191 243 192 244 193 245 194