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: G4VRML2FileViewer.cc 77479 2013-11-25 10:01:22Z gcosmo $ 27 // 28 // 28 // G4VRML2FileViewer.cc 29 // G4VRML2FileViewer.cc 29 // Satoshi Tanaka & Yasuhide Sawada 30 // Satoshi Tanaka & Yasuhide Sawada 30 31 >> 32 31 //#define DEBUG_FR_VIEW 33 //#define DEBUG_FR_VIEW 32 34 33 #include <cmath> 35 #include <cmath> 34 36 35 #include "G4VisManager.hh" 37 #include "G4VisManager.hh" 36 #include "G4Scene.hh" 38 #include "G4Scene.hh" 37 #include "G4VRML2FileViewer.hh" 39 #include "G4VRML2FileViewer.hh" 38 #include "G4VRML2FileSceneHandler.hh" 40 #include "G4VRML2FileSceneHandler.hh" 39 #include "G4VRML2File.hh" 41 #include "G4VRML2File.hh" 40 #include "G4SystemOfUnits.hh" 42 #include "G4SystemOfUnits.hh" 41 #include "G4ios.hh" 43 #include "G4ios.hh" 42 44 43 G4VRML2FileViewer::G4VRML2FileViewer(G4VRML2Fi 45 G4VRML2FileViewer::G4VRML2FileViewer(G4VRML2FileSceneHandler& sceneHandler, 44 const G4S << 46 const G4String& name) : 45 : G4VViewer(sceneHandler, sceneHandler.Incre << 47 G4VViewer(sceneHandler, 46 , fSceneHandler(sceneHandler) << 48 sceneHandler.IncrementViewCount(), 47 , fDest(sceneHandler.fDest) << 49 name), >> 50 fSceneHandler(sceneHandler), >> 51 fDest(sceneHandler.fDest) 48 { 52 { 49 fViewHalfAngle = 30. * deg; 53 fViewHalfAngle = 30. * deg; 50 fsin_VHA = std::sin(fViewHalfAngle); << 54 fsin_VHA = std::sin ( fViewHalfAngle ) ; 51 } 55 } 52 56 53 G4VRML2FileViewer::~G4VRML2FileViewer() {} << 57 G4VRML2FileViewer::~G4VRML2FileViewer() >> 58 {} 54 59 55 void G4VRML2FileViewer::SetView() 60 void G4VRML2FileViewer::SetView() 56 { 61 { 57 #if defined DEBUG_FR_VIEW 62 #if defined DEBUG_FR_VIEW 58 if(G4VisManager::GetVerbosity() >= G4VisMana << 63 if (G4VisManager::GetVerbosity() >= G4VisManager::errors) 59 G4cout << "***** G4VRML2FileViewer::SetVie << 64 G4cout << "***** G4VRML2FileViewer::SetView(): No effects" << G4endl; 60 #endif 65 #endif 61 66 62 // Do nothing, since VRML a browser is runni << 67 // Do nothing, since VRML a browser is running as a different process. 63 // SendViewParameters () will do this job in << 68 // SendViewParameters () will do this job instead. >> 69 64 } 70 } 65 71 66 void G4VRML2FileViewer::DrawView() 72 void G4VRML2FileViewer::DrawView() 67 { 73 { 68 #if defined DEBUG_FR_VIEW 74 #if defined DEBUG_FR_VIEW 69 if(G4VisManager::GetVerbosity() >= G4VisMana << 75 if (G4VisManager::GetVerbosity() >= G4VisManager::errors) 70 G4cout << "***** G4VRML2FileViewer::DrawVi << 76 G4cout << "***** G4VRML2FileViewer::DrawView()" << G4endl; 71 #endif 77 #endif 72 78 73 fSceneHandler.VRMLBeginModeling(); << 79 fSceneHandler.VRMLBeginModeling() ; 74 80 75 // Viewpoint node << 81 // Viewpoint node 76 SendViewParameters(); << 82 SendViewParameters(); 77 83 78 // Here is a minimal DrawView() function. << 84 // Here is a minimal DrawView() function. 79 NeedKernelVisit(); << 85 NeedKernelVisit(); 80 ProcessView(); << 86 ProcessView(); 81 FinishView(); << 87 FinishView(); 82 } 88 } 83 89 84 void G4VRML2FileViewer::ClearView(void) 90 void G4VRML2FileViewer::ClearView(void) 85 { 91 { 86 #if defined DEBUG_FR_VIEW 92 #if defined DEBUG_FR_VIEW 87 if(G4VisManager::GetVerbosity() >= G4VisMana << 93 if (G4VisManager::GetVerbosity() >= G4VisManager::errors) 88 G4cout << "***** G4VRML2File1View::ClearVi << 94 G4cout << "***** G4VRML2File1View::ClearView()" << G4endl; 89 #endif 95 #endif 90 if(fSceneHandler.fFlagDestOpen) << 96 if(fSceneHandler.fFlagDestOpen) { 91 { << 92 fSceneHandler.fDest.close(); 97 fSceneHandler.fDest.close(); 93 // Re-open with same filename... 98 // Re-open with same filename... 94 fSceneHandler.fDest.open(fSceneHandler.fVR 99 fSceneHandler.fDest.open(fSceneHandler.fVRMLFileName); 95 fSceneHandler.fDest << "#VRML V2.0 utf8" << 100 fSceneHandler.fDest << "#VRML V2.0 utf8" << "\n"; 96 << "\n"; << 101 fSceneHandler.fDest << "# Generated by VRML 2.0 driver of GEANT4\n" << "\n"; 97 fSceneHandler.fDest << "# Generated by VRM << 98 << "\n"; << 99 } 102 } 100 } 103 } 101 104 102 void G4VRML2FileViewer::ShowView(void) 105 void G4VRML2FileViewer::ShowView(void) 103 { 106 { 104 #if defined DEBUG_FR_VIEW 107 #if defined DEBUG_FR_VIEW 105 if(G4VisManager::GetVerbosity() >= G4VisMana << 108 if (G4VisManager::GetVerbosity() >= G4VisManager::errors) 106 G4cout << "***** G4VRML2FileViewer::ShowVi << 109 G4cout << "***** G4VRML2FileViewer::ShowView()" << G4endl; 107 #endif 110 #endif 108 fSceneHandler.VRMLEndModeling(); << 111 fSceneHandler.VRMLEndModeling(); 109 } 112 } 110 113 111 void G4VRML2FileViewer::FinishView(void) 114 void G4VRML2FileViewer::FinishView(void) 112 { 115 { 113 #if defined DEBUG_FR_VIEW 116 #if defined DEBUG_FR_VIEW 114 if(G4VisManager::GetVerbosity() >= G4VisMana << 117 if (G4VisManager::GetVerbosity() >= G4VisManager::errors) 115 G4cout << "***** G4VRML2FileViewer::Finish << 118 G4cout << "***** G4VRML2FileViewer::FinishView(): No effects" << G4endl; 116 #endif 119 #endif 117 } 120 } 118 121 119 void G4VRML2FileViewer::SendViewParameters() << 122 void G4VRML2FileViewer::SendViewParameters () 120 { 123 { 121 // Calculates view representation based on e 124 // Calculates view representation based on extent of object being 122 // viewed and (initial) direction of camera. 125 // viewed and (initial) direction of camera. (Note: it can change 123 // later due to user interaction via visuali 126 // later due to user interaction via visualization system's GUI.) 124 127 125 #if defined DEBUG_FR_VIEW 128 #if defined DEBUG_FR_VIEW 126 if(G4VisManager::GetVerbosity() >= G4VisMana << 129 if (G4VisManager::GetVerbosity() >= G4VisManager::errors) 127 G4cout << "***** G4VRML2FileViewer::SendVi << 130 G4cout << "***** G4VRML2FileViewer::SendViewParameters()\n"; 128 #endif << 131 #endif 129 << 132 130 // error recovery << 133 // error recovery 131 if(fsin_VHA < 1.0e-6) << 134 if ( fsin_VHA < 1.0e-6 ) { return ; } 132 { << 135 133 return; << 136 // camera distance 134 } << 137 G4double extent_radius = fSceneHandler.GetScene()->GetExtent().GetExtentRadius(); >> 138 G4double camera_distance = extent_radius / fsin_VHA ; >> 139 >> 140 // camera position on Z axis >> 141 const G4Point3D& target_point >> 142 = fSceneHandler.GetScene()->GetStandardTargetPoint() >> 143 + fVP.GetCurrentTargetPoint(); >> 144 G4double E_z = target_point.z() + camera_distance; >> 145 G4Point3D E(0.0, 0.0, E_z ); >> 146 >> 147 // VRML codes are generated below >> 148 fDest << G4endl; >> 149 fDest << "#---------- CAMERA" << G4endl; >> 150 fDest << "Viewpoint {" << G4endl; >> 151 fDest << "\t" << "position " ; >> 152 fDest << E.x() << " " ; >> 153 fDest << E.y() << " " ; >> 154 fDest << E.z() << G4endl ; >> 155 fDest << "}" << G4endl; >> 156 fDest << G4endl; 135 157 136 // camera distance << 137 G4double extent_radius = << 138 fSceneHandler.GetScene()->GetExtent().GetE << 139 G4double camera_distance = extent_radius / f << 140 << 141 // camera position on Z axis << 142 const G4Point3D& target_point = << 143 fSceneHandler.GetScene()->GetStandardTarge << 144 fVP.GetCurrentTargetPoint(); << 145 G4double E_z = target_point.z() + camera_dis << 146 G4Point3D E(0.0, 0.0, E_z); << 147 << 148 // VRML codes are generated below << 149 fDest << G4endl; << 150 fDest << "#---------- CAMERA" << G4endl; << 151 fDest << "Viewpoint {" << G4endl; << 152 fDest << "\t" << 153 << "position "; << 154 fDest << E.x() << " "; << 155 fDest << E.y() << " "; << 156 fDest << E.z() << G4endl; << 157 fDest << "}" << G4endl; << 158 fDest << G4endl; << 159 } 158 } 160 159