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