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 // G4VRML2FileViewer.cc 00030 // Satoshi Tanaka & Yasuhide Sawada 00031 00032 00033 //#define DEBUG_FR_VIEW 00034 00035 #include <cmath> 00036 00037 #include "G4VisManager.hh" 00038 #include "G4Scene.hh" 00039 #include "G4VRML2FileViewer.hh" 00040 #include "G4VRML2FileSceneHandler.hh" 00041 #include "G4VRML2File.hh" 00042 #include "G4ios.hh" 00043 00044 G4VRML2FileViewer::G4VRML2FileViewer(G4VRML2FileSceneHandler& sceneHandler, 00045 const G4String& name) : 00046 G4VViewer(sceneHandler, 00047 sceneHandler.IncrementViewCount(), 00048 name), 00049 fSceneHandler(sceneHandler), 00050 fDest(sceneHandler.fDest) 00051 { 00052 fViewHalfAngle = 0.5 * 0.785398 ; // 0.5 * 45*deg 00053 fsin_VHA = std::sin ( fViewHalfAngle ) ; 00054 } 00055 00056 G4VRML2FileViewer::~G4VRML2FileViewer() 00057 {} 00058 00059 void G4VRML2FileViewer::SetView() 00060 { 00061 #if defined DEBUG_FR_VIEW 00062 if (G4VisManager::GetVerbosity() >= G4VisManager::errors) 00063 G4cout << "***** G4VRML2FileViewer::SetView(): No effects" << G4endl; 00064 #endif 00065 00066 // Do nothing, since VRML a browser is running as a different process. 00067 // SendViewParameters () will do this job instead. 00068 00069 } 00070 00071 void G4VRML2FileViewer::DrawView() 00072 { 00073 #if defined DEBUG_FR_VIEW 00074 if (G4VisManager::GetVerbosity() >= G4VisManager::errors) 00075 G4cout << "***** G4VRML2FileViewer::DrawView()" << G4endl; 00076 #endif 00077 00078 fSceneHandler.VRMLBeginModeling() ; 00079 00080 // Viewpoint node 00081 SendViewParameters(); 00082 00083 // Here is a minimal DrawView() function. 00084 NeedKernelVisit(); 00085 ProcessView(); 00086 FinishView(); 00087 } 00088 00089 void G4VRML2FileViewer::ClearView(void) 00090 { 00091 #if defined DEBUG_FR_VIEW 00092 if (G4VisManager::GetVerbosity() >= G4VisManager::errors) 00093 G4cout << "***** G4VRML2File1View::ClearView()" << G4endl; 00094 #endif 00095 if(fSceneHandler.fFlagDestOpen) { 00096 fSceneHandler.fDest.close(); 00097 // Re-open with same filename... 00098 fSceneHandler.fDest.open(fSceneHandler.fVRMLFileName); 00099 fSceneHandler.fDest << "#VRML V2.0 utf8" << "\n"; 00100 fSceneHandler.fDest << "# Generated by VRML 2.0 driver of GEANT4\n" << "\n"; 00101 } 00102 } 00103 00104 void G4VRML2FileViewer::ShowView(void) 00105 { 00106 #if defined DEBUG_FR_VIEW 00107 if (G4VisManager::GetVerbosity() >= G4VisManager::errors) 00108 G4cout << "***** G4VRML2FileViewer::ShowView()" << G4endl; 00109 #endif 00110 fSceneHandler.VRMLEndModeling(); 00111 } 00112 00113 void G4VRML2FileViewer::FinishView(void) 00114 { 00115 #if defined DEBUG_FR_VIEW 00116 if (G4VisManager::GetVerbosity() >= G4VisManager::errors) 00117 G4cout << "***** G4VRML2FileViewer::FinishView(): No effects" << G4endl; 00118 #endif 00119 } 00120 00121 void G4VRML2FileViewer::SendViewParameters () 00122 { 00123 // Calculates view representation based on extent of object being 00124 // viewed and (initial) direction of camera. (Note: it can change 00125 // later due to user interaction via visualization system's GUI.) 00126 00127 #if defined DEBUG_FR_VIEW 00128 if (G4VisManager::GetVerbosity() >= G4VisManager::errors) 00129 G4cout << "***** G4VRML2FileViewer::SendViewParameters()\n"; 00130 #endif 00131 00132 // error recovery 00133 if ( fsin_VHA < 1.0e-6 ) { return ; } 00134 00135 // camera distance 00136 G4double extent_radius = fSceneHandler.GetScene()->GetExtent().GetExtentRadius(); 00137 G4double camera_distance = extent_radius / fsin_VHA ; 00138 00139 // camera position on Z axis 00140 const G4Point3D& target_point 00141 = fSceneHandler.GetScene()->GetStandardTargetPoint() 00142 + fVP.GetCurrentTargetPoint(); 00143 G4double E_z = target_point.z() + camera_distance; 00144 G4Point3D E(0.0, 0.0, E_z ); 00145 00146 // VRML codes are generated below 00147 fDest << G4endl; 00148 fDest << "#---------- CAMERA" << G4endl; 00149 fDest << "Viewpoint {" << G4endl; 00150 fDest << "\t" << "position " ; 00151 fDest << E.x() << " " ; 00152 fDest << E.y() << " " ; 00153 fDest << E.z() << G4endl ; 00154 fDest << "}" << G4endl; 00155 fDest << G4endl; 00156 00157 }