G4FukuiRendererViewer.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 // 
00030 // Satoshi TANAKA, Fri Jun 28 12:09:11 JST 1996
00031 // FukuiRenderer view - opens window, hard copy, etc.
00032 
00033 
00034 //=================//
00035 #ifdef G4VIS_BUILD_DAWN_DRIVER
00036 //=================//
00037 
00038 #define __G_ANSI_C__
00039 #define G4FukuiRenderer_STRUCTURE_PRIORITY  1.
00040 
00041 // #define DEBUG_FR_VIEW
00042 
00043 #include "G4ios.hh"
00044 #include <stdio.h>
00045 #include <string.h>
00046 #include <assert.h>
00047 
00048 #include "G4VisManager.hh"
00049 #include "G4Scene.hh"
00050 #include "G4Vector3D.hh"
00051 #include "G4VisExtent.hh"
00052 #include "G4LogicalVolume.hh"
00053 #include "G4VSolid.hh"
00054 #include "G4PhysicalConstants.hh"
00055 
00056 #include "G4FRConst.hh"
00057 #include "G4FukuiRenderer.hh"
00058 #include "G4FukuiRendererSceneHandler.hh"
00059 #include "G4FukuiRendererViewer.hh"
00060 
00061 
00062 //----- Constructor
00063 G4FukuiRendererViewer::G4FukuiRendererViewer (G4FukuiRendererSceneHandler& sceneHandler,
00064                                           const G4String& name): 
00065   G4VViewer (sceneHandler,
00066              sceneHandler.IncrementViewCount (),
00067              name),
00068   fSceneHandler (sceneHandler)
00069 {}
00070 
00071 //----- Destructor
00072 G4FukuiRendererViewer::~G4FukuiRendererViewer () 
00073 {}
00074 
00075 //----- 
00076 void G4FukuiRendererViewer::SetView () 
00077 {
00078 #if defined DEBUG_FR_VIEW
00079   if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
00080     G4cout << "***** G4FukuiRendererViewer::SetView(): No effects" << G4endl;
00081 #endif 
00082 // Do nothing, since DAWN is running as a different process.
00083 // SendViewParameters () will do this job instead.
00084 }
00085 
00086 //----- 
00087 void
00088 G4FukuiRendererViewer::ClearView( void )
00089 {
00090 #if defined DEBUG_FR_VIEW
00091   if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
00092     G4cout << "***** G4FukuiRendererViewer::ClearView (): No effects " << G4endl;
00093 #endif
00094 
00095 }
00096 
00097 
00098 //----- 
00099 void G4FukuiRendererViewer::DrawView () 
00100 {
00101 #if defined DEBUG_FR_VIEW
00102   if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
00103         G4cout << "***** G4FukuiRendererViewer::DrawView () " << G4endl;
00104 #endif
00105 
00106         //----- Begin modeling 3D 
00107         fSceneHandler.FRBeginModeling();        
00108 
00109         //----- Always visit G4 kernel 
00110         NeedKernelVisit ();
00111                                    
00112         //----- Draw
00113         ProcessView () ;
00114 
00115 } 
00116 
00117 
00118 //----- 
00119 void G4FukuiRendererViewer::ShowView( void )
00120 {
00121 #if defined DEBUG_FR_VIEW
00122   if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
00123         G4cout << "***** G4FukuiRendererViewer::ShowView () " << G4endl;
00124 #endif
00125 
00126         if( fSceneHandler.FRIsInModeling() ) 
00127         {
00128                         //----- End of modeling
00129                         // !EndModeling, !DrawAll, !CloseDevice,
00130                         // close g4.prim
00131                 fSceneHandler.FREndModeling();
00132 
00133                         //----- Wait user clicks drawing Area
00134                 this->Wait();
00135         }
00136 
00137 } 
00138 
00139 
00140 //----- 
00141 void  G4FukuiRendererViewer::Wait()
00142 {
00143 #if defined DEBUG_FR_VIEW
00144   if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
00145         G4cout << "***** G4FukuiRendererViewer::Wait () : Begin" << G4endl;
00146 #endif
00147   fSceneHandler.SendStr    ( FR_WAIT );
00148   fSceneHandler.GetPrimDest().WaitSendBack( FR_WAIT );
00149 #if defined DEBUG_FR_VIEW
00150   if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
00151         G4cout << "***** G4FukuiRendererViewer::Wait () : end" << G4endl;
00152 #endif
00153 
00154 }
00155 
00156 
00157 //----- 
00158 void
00159 G4FukuiRendererViewer::SendDevice( FRDEV dev )
00160 {
00161 #if defined DEBUG_FR_VIEW
00162   if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
00163         G4cout << "***** G4FukuiRendererViewer::SendDevice() " << G4endl;
00164 #endif
00165 
00166   //    enum {PS=1, XWIN=2, PS2=3, XWIN2=4, OPEN_GL=5, DEVICE_END=6};
00167   
00168         if( dev >= FRDEV_PS || dev < FRDEV_DEVICE_END ) {
00169                 fSceneHandler.SendStrInt ( FR_DEVICE, dev );
00170         }
00171 }
00172 
00173 
00174 //----- 
00175 void  G4FukuiRendererViewer::SendDrawingStyle() 
00176 {
00177 #if defined DEBUG_FR_VIEW
00178   if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
00179         G4cout << "***** G4FukuiRendererViewer::SendDrawingStyle() " << G4endl;
00180 #endif
00181 
00182         G4int  style = fVP.GetDrawingStyle();
00183 
00184         switch( style )
00185         {
00186           case G4ViewParameters::wireframe: 
00187                 fSceneHandler.SendStr( FR_WIREFRAME );
00188                 break;
00189           case G4ViewParameters::hlr:
00190                 fSceneHandler.SendStr( FR_LINES     );
00191                 break;
00192           case G4ViewParameters::hsr:
00193           case G4ViewParameters::hlhsr:
00194                 fSceneHandler.SendStr( FR_SURFACE   );
00195                 break;
00196           default:
00197                 fSceneHandler.SendStr( FR_WIREFRAME );
00198                 break;
00199         }
00200 
00201 } 
00202 
00203 
00204 //----- 
00205 void G4FukuiRendererViewer::SendViewParameters () 
00206 {
00207   // Calculates view representation based on extent of object being
00208   // viewed and (initial) direction of camera.  (Note: it can change
00209   // later due to user interaction via visualization system's GUI.)
00210 
00211 #if defined DEBUG_FR_VIEW
00212   if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
00213     G4cout << "***** G4FukuiRendererViewer::SendViewParameters()" << G4endl;
00214 #endif 
00215 
00216                 //----- Magic number to decide camera distance automatically
00217         const    G4double        HOW_FAR            = 1000.0       ; // to define "infinity"
00218         const    G4double        MIN_HALF_ANGLE     = 0.01         ;
00219         const    G4double        MAX_HALF_ANGLE     = 0.499 * pi ;
00220 
00221                 //----- (2A) CALC camera distance
00222                 //..... Note: Camera cannot enter inside object
00223         G4double  camera_distance ;
00224         G4double  radius = fSceneHandler.GetScene()->GetExtent().GetExtentRadius();
00225 
00226         G4double half_view_angle  = std::fabs ( fVP.GetFieldHalfAngle () ) ;
00227         if( half_view_angle > MAX_HALF_ANGLE ) { 
00228           half_view_angle = MAX_HALF_ANGLE ; 
00229         } 
00230 
00231         if( half_view_angle < MIN_HALF_ANGLE ) {
00232                         //----- infinity (or ortho projection)
00233                 camera_distance = radius * HOW_FAR ;  
00234         } else {
00235                         //----- Calc camera distance from half view angle
00236                 camera_distance = radius / std::sin ( half_view_angle );
00237                 camera_distance -= fVP.GetDolly();
00238         }
00239 
00240         if ( camera_distance < radius ) { 
00241           if (G4VisManager::GetVerbosity() >= G4VisManager::errors) {
00242                 G4cout << "WARNING from FukuiRenderer (DAWN) driver:" << G4endl;
00243                 G4cout << "  Camera cannot enter inside objects"      << G4endl;
00244           }
00245                 camera_distance = radius ; 
00246         }
00247 
00248                 //----- (3A) CALC camera direction
00249         const G4Vector3D& camera_direction \
00250           = fVP.GetViewpointDirection().unit();
00251         const G4double v_angle =  (180.0 / pi) * camera_direction.theta() ;
00252         const G4double h_angle =  (180.0 / pi) * camera_direction.phi  () ;
00253 
00254                 //----- (2B), (3B) SEND camera position
00255         fSceneHandler.SendStrDouble3( FR_CAMERA_POSITION, 
00256                                camera_distance, 
00257                                v_angle, 
00258                                h_angle ); 
00259 
00260                 //----- (4A) CALC target point
00261         const G4Point3D&  target_point
00262           = fSceneHandler.GetScene()->GetStandardTargetPoint()
00263           + fVP.GetCurrentTargetPoint();
00264 
00265                 //----- (4B) SEND target point
00266         fSceneHandler.SendStrDouble3( FR_TARGET_POINT, 
00267                                target_point.x(), 
00268                                target_point.y(), 
00269                                target_point.z() );
00270 
00271                 //----- (5A) CALC zoom factor
00272         const G4double   zoom_factor  = fVP.GetZoomFactor();
00273 
00274                 //----- (5B) SEND zoom factor or focal length
00275         if( half_view_angle < MIN_HALF_ANGLE ) {
00276 
00277                 const G4Point3D&  std_target_point \
00278                         = fSceneHandler.GetScene()->GetStandardTargetPoint();
00279 
00280                 fSceneHandler.SendStrDouble4( FR_ZOOM_FACTOR, 
00281                                        zoom_factor ,
00282                                        std_target_point.x(), 
00283                                        std_target_point.y(), 
00284                                        std_target_point.z());
00285                         // Note that target point, camera position, 
00286                         // and bounding box have already been sent above.
00287                         // The std_target_point is necessary to
00288                         // Calc focal distance from the zoom factor.
00289         } else {
00290                 const G4double FR_HALF_SCREEN_SIZE = 0.5 ;
00291                 G4double  focal_distance \
00292                   = FR_HALF_SCREEN_SIZE / std::tan( half_view_angle ); 
00293                 focal_distance *= zoom_factor ;
00294                 fSceneHandler.SendStrDouble ( FR_FOCAL_DISTANCE, focal_distance );
00295         }
00296 
00297                 //----- INVOKE GUI: not executed in the default setting
00298         if( fSceneHandler.GetSystem().IsGUIMode() ) {
00299                         //----- send GUI command
00300                 fSceneHandler.SendStr( FR_GUI );
00301 
00302                         //----- wait the same command is sent back:
00303                         //..... This avoids to send many data before
00304                         //..... GUI session is over.
00305                 fSceneHandler.GetPrimDest().WaitSendBack( FR_GUI );
00306         }
00307 
00308 } 
00309 
00310 #endif // G4VIS_BUILD_DAWN_DRIVER
00311 
00312 

Generated on Mon May 27 17:48:18 2013 for Geant4 by  doxygen 1.4.7