00001 // 00002 // ******************************************************************** 00003 // * License and Disclaimer * 00004 // * * 00005 // * The Geant4 software is copyright of the Copyright Holders of * 00006 // * the Geant4 Collaboration. It is provided under the terms and * 00007 // * conditions of the Geant4 Software License, included in the file * 00008 // * LICENSE and available at http://cern.ch/geant4/license . These * 00009 // * include a list of copyright holders. * 00010 // * * 00011 // * Neither the authors of this software system, nor their employing * 00012 // * institutes,nor the agencies providing financial support for this * 00013 // * work make any representation or warranty, express or implied, * 00014 // * regarding this software system or assume any liability for its * 00015 // * use. Please see the license in the file LICENSE and URL above * 00016 // * for the full disclaimer and the limitation of liability. * 00017 // * * 00018 // * This code implementation is the result of the scientific and * 00019 // * technical work of the GEANT4 collaboration. * 00020 // * By using, copying, modifying or distributing the software (or * 00021 // * any work based on the software) you agree to acknowledge its * 00022 // * use in resulting scientific publications, and indicate your * 00023 // * acceptance of all terms of the Geant4 Software license. * 00024 // ******************************************************************** 00025 // 00026 // 00027 // $Id$ 00028 00029 #include "G4RayTracerViewer.hh" 00030 00031 #include "G4ios.hh" 00032 #include <sstream> 00033 #include "G4SystemOfUnits.hh" 00034 00035 #include "G4VSceneHandler.hh" 00036 #include "G4Scene.hh" 00037 #include "G4TheRayTracer.hh" 00038 #include "G4UImanager.hh" 00039 00040 G4RayTracerViewer::G4RayTracerViewer 00041 (G4VSceneHandler& sceneHandler, 00042 const G4String& name, 00043 G4TheRayTracer* aTracer): 00044 G4VViewer(sceneHandler, sceneHandler.IncrementViewCount(), name), 00045 fFileCount(0) 00046 { 00047 theTracer = aTracer; 00048 if (!aTracer) theTracer = new G4TheRayTracer; 00049 theTracer->SetNColumn(fVP.GetWindowSizeHintX()); 00050 theTracer->SetNRow(fVP.GetWindowSizeHintY()); 00051 } 00052 00053 G4RayTracerViewer::~G4RayTracerViewer() {} 00054 00055 void G4RayTracerViewer::SetView() 00056 { 00057 // Get radius of scene, etc. (See G4OpenGLViewer::SetView().) 00058 // Note that this procedure properly takes into account zoom, dolly and pan. 00059 const G4Point3D& targetPoint 00060 = fSceneHandler.GetScene()->GetStandardTargetPoint() 00061 + fVP.GetCurrentTargetPoint(); 00062 G4double radius = // See G4ViewParameters for following procedure. 00063 fSceneHandler.GetScene()->GetExtent().GetExtentRadius(); 00064 if(radius<=0.) radius = 1.; 00065 const G4double cameraDistance = fVP.GetCameraDistance(radius); 00066 const G4Point3D cameraPosition = 00067 targetPoint + cameraDistance * fVP.GetViewpointDirection().unit(); 00068 const G4double nearDistance = fVP.GetNearDistance(cameraDistance,radius); 00069 const G4double frontHalfHeight = fVP.GetFrontHalfHeight(nearDistance,radius); 00070 const G4double frontHalfAngle = std::atan(frontHalfHeight / nearDistance); 00071 00072 // Calculate and set ray tracer parameters. 00073 theTracer-> 00074 SetViewSpan(200. * frontHalfAngle / theTracer->GetNColumn()); 00075 theTracer->SetTargetPosition(targetPoint); 00076 theTracer->SetEyePosition(cameraPosition); 00077 theTracer->SetUpVector(fVP.GetUpVector()); 00078 const G4Vector3D 00079 actualLightpointDirection(-fVP.GetActualLightpointDirection()); 00080 theTracer->SetLightDirection(actualLightpointDirection); 00081 theTracer->SetBackgroundColour(fVP.GetBackgroundColour()); 00082 } 00083 00084 00085 void G4RayTracerViewer::ClearView() {} 00086 00087 void G4RayTracerViewer::DrawView() 00088 { 00089 // Trap recursive call 00090 static G4bool called = false; 00091 if (called) return; 00092 called = true; 00093 00094 if (fVP.GetFieldHalfAngle() == 0.) { // Orthogonal (parallel) projection. 00095 G4double fieldHalfAngle = perMillion; 00096 fVP.SetFieldHalfAngle(fieldHalfAngle); 00097 G4cout << 00098 "WARNING: G4RayTracerViewer::DrawView: true orthogonal projection" 00099 "\n not yet implemented. Doing a \"long shot\", i.e., a perspective" 00100 "\n projection with a half field angle of " 00101 << fieldHalfAngle << 00102 " radians." 00103 << G4endl; 00104 SetView(); // Special graphics system - bypass ProcessView(). 00105 fVP.SetFieldHalfAngle(0.); 00106 } 00107 else { 00108 SetView(); // Special graphics system - bypass ProcessView(). 00109 } 00110 std::ostringstream filename; 00111 filename << "g4RayTracer." << fShortName << '_' << fFileCount++ << ".jpeg"; 00112 theTracer->Trace(filename.str()); 00113 00114 // Reset call flag 00115 called = false; 00116 }