[834] | 1 | // |
---|
| 2 | // ******************************************************************** |
---|
| 3 | // * License and Disclaimer * |
---|
| 4 | // * * |
---|
| 5 | // * The Geant4 software is copyright of the Copyright Holders of * |
---|
| 6 | // * the Geant4 Collaboration. It is provided under the terms and * |
---|
| 7 | // * conditions of the Geant4 Software License, included in the file * |
---|
| 8 | // * LICENSE and available at http://cern.ch/geant4/license . These * |
---|
| 9 | // * include a list of copyright holders. * |
---|
| 10 | // * * |
---|
| 11 | // * Neither the authors of this software system, nor their employing * |
---|
| 12 | // * institutes,nor the agencies providing financial support for this * |
---|
| 13 | // * work make any representation or warranty, express or implied, * |
---|
| 14 | // * regarding this software system or assume any liability for its * |
---|
| 15 | // * use. Please see the license in the file LICENSE and URL above * |
---|
| 16 | // * for the full disclaimer and the limitation of liability. * |
---|
| 17 | // * * |
---|
| 18 | // * This code implementation is the result of the scientific and * |
---|
| 19 | // * technical work of the GEANT4 collaboration. * |
---|
| 20 | // * By using, copying, modifying or distributing the software (or * |
---|
| 21 | // * any work based on the software) you agree to acknowledge its * |
---|
| 22 | // * use in resulting scientific publications, and indicate your * |
---|
| 23 | // * acceptance of all terms of the Geant4 Software license. * |
---|
| 24 | // ******************************************************************** |
---|
| 25 | // |
---|
| 26 | // |
---|
| 27 | // $Id: G4VRML2Viewer.cc,v 1.12 2006/06/29 21:26:35 gunter Exp $ |
---|
[944] | 28 | // GEANT4 tag $Name: $ |
---|
[834] | 29 | // |
---|
| 30 | // G4VRML2Viewer.cc |
---|
| 31 | // Satoshi Tanaka & Yasuhide Sawada |
---|
| 32 | |
---|
| 33 | #ifndef WIN32 |
---|
| 34 | |
---|
| 35 | //=================// |
---|
| 36 | #ifdef G4VIS_BUILD_VRML_DRIVER |
---|
| 37 | //=================// |
---|
| 38 | |
---|
| 39 | |
---|
| 40 | //#define DEBUG_FR_VIEW |
---|
| 41 | |
---|
| 42 | #include <cmath> |
---|
| 43 | |
---|
| 44 | #include "G4Scene.hh" |
---|
| 45 | #include "G4VRML2Viewer.hh" |
---|
| 46 | #include "G4VRML2SceneHandler.hh" |
---|
| 47 | #include "G4VRML2.hh" |
---|
| 48 | #include "G4ios.hh" |
---|
| 49 | |
---|
| 50 | G4VRML2Viewer::G4VRML2Viewer(G4VRML2SceneHandler& sceneHandler, const G4String& name) : |
---|
| 51 | G4VViewer(sceneHandler, |
---|
| 52 | sceneHandler.IncrementViewCount(), |
---|
| 53 | name), |
---|
| 54 | fSceneHandler(sceneHandler), |
---|
| 55 | fDest(sceneHandler.fDest) |
---|
| 56 | { |
---|
| 57 | fViewHalfAngle = 0.5 * 0.785398 ; // 0.5 * 45*deg |
---|
| 58 | fsin_VHA = std::sin ( fViewHalfAngle ) ; |
---|
| 59 | } |
---|
| 60 | |
---|
| 61 | G4VRML2Viewer::~G4VRML2Viewer() |
---|
| 62 | {} |
---|
| 63 | |
---|
| 64 | void G4VRML2Viewer::SetView() |
---|
| 65 | { |
---|
| 66 | #if defined DEBUG_FR_VIEW |
---|
| 67 | G4cerr << "***** G4VRML2Viewer::SetView(): No effects" << G4endl; |
---|
| 68 | #endif |
---|
| 69 | |
---|
| 70 | // Do nothing, since VRML a browser is running as a different process. |
---|
| 71 | // SendViewParameters () will do this job instead. |
---|
| 72 | |
---|
| 73 | } |
---|
| 74 | |
---|
| 75 | |
---|
| 76 | void G4VRML2Viewer::DrawView() |
---|
| 77 | { |
---|
| 78 | #if defined DEBUG_FR_VIEW |
---|
| 79 | G4cerr << "***** G4VRML2Viewer::DrawView()" << G4endl; |
---|
| 80 | #endif |
---|
| 81 | fSceneHandler.VRMLBeginModeling() ; |
---|
| 82 | |
---|
| 83 | // Viewpoint node |
---|
| 84 | SendViewParameters(); |
---|
| 85 | |
---|
| 86 | // Here is a minimal DrawView() function. |
---|
| 87 | NeedKernelVisit(); |
---|
| 88 | ProcessView(); |
---|
| 89 | FinishView(); |
---|
| 90 | } |
---|
| 91 | |
---|
| 92 | void G4VRML2Viewer::ClearView(void) |
---|
| 93 | { |
---|
| 94 | #if defined DEBUG_FR_VIEW |
---|
| 95 | G4cerr << "***** G4VRML2Viewer::ClearView(): No effects" << G4endl; |
---|
| 96 | #endif |
---|
| 97 | } |
---|
| 98 | |
---|
| 99 | void G4VRML2Viewer::ShowView(void) |
---|
| 100 | { |
---|
| 101 | #if defined DEBUG_FR_VIEW |
---|
| 102 | G4cerr << "***** G4VRML2Viewer::ShowView()" << G4endl; |
---|
| 103 | #endif |
---|
| 104 | fSceneHandler.VRMLEndModeling(); |
---|
| 105 | } |
---|
| 106 | |
---|
| 107 | void G4VRML2Viewer::FinishView(void) |
---|
| 108 | { |
---|
| 109 | #if defined DEBUG_FR_VIEW |
---|
| 110 | G4cerr << "***** G4VRML2Viewer::FinishView(): No effects" << G4endl; |
---|
| 111 | #endif |
---|
| 112 | } |
---|
| 113 | |
---|
| 114 | void G4VRML2Viewer::SendViewParameters () |
---|
| 115 | { |
---|
| 116 | // Calculates view representation based on extent of object being |
---|
| 117 | // viewed and (initial) direction of camera. (Note: it can change |
---|
| 118 | // later due to user interaction via visualization system's GUI.) |
---|
| 119 | |
---|
| 120 | #if defined DEBUG_FR_VIEW |
---|
| 121 | G4cerr << "***** G4VRML2Viewer::SendViewParameters()\n"; |
---|
| 122 | #endif |
---|
| 123 | // error recovery |
---|
| 124 | if ( fsin_VHA < 1.0e-6 ) { return ; } |
---|
| 125 | |
---|
| 126 | // camera distance |
---|
| 127 | G4double extent_radius = fSceneHandler.GetScene()->GetExtent().GetExtentRadius(); |
---|
| 128 | G4double camera_distance = extent_radius / fsin_VHA ; |
---|
| 129 | |
---|
| 130 | // camera position on Z axis |
---|
| 131 | const G4Point3D& target_point |
---|
| 132 | = fSceneHandler.GetScene()->GetStandardTargetPoint() |
---|
| 133 | + fVP.GetCurrentTargetPoint(); |
---|
| 134 | G4double E_z = target_point.z() + camera_distance; |
---|
| 135 | G4Point3D E(0.0, 0.0, E_z ); |
---|
| 136 | |
---|
| 137 | // VRML codes are generated below |
---|
| 138 | fDest << "\n"; |
---|
| 139 | fDest << "#---------- CAMERA" << "\n"; |
---|
| 140 | fDest << "Viewpoint {" << "\n"; |
---|
| 141 | fDest << "\t" << "position " ; |
---|
| 142 | fDest << E.x() << " " ; |
---|
| 143 | fDest << E.y() << " " ; |
---|
| 144 | fDest << E.z() << "\n" ; |
---|
| 145 | fDest << "}" << "\n"; |
---|
| 146 | fDest << "\n"; |
---|
| 147 | |
---|
| 148 | } |
---|
| 149 | |
---|
| 150 | |
---|
| 151 | |
---|
| 152 | #endif |
---|
| 153 | #endif //WIN32 |
---|