G4VRML2Viewer.cc

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

Generated on Mon May 27 17:50:21 2013 for Geant4 by  doxygen 1.4.7