G4DAWNFILEViewer Class Reference

#include <G4DAWNFILEViewer.hh>

Inheritance diagram for G4DAWNFILEViewer:

G4VViewer

Public Member Functions

 G4DAWNFILEViewer (G4DAWNFILESceneHandler &scene, const G4String &name="")
virtual ~G4DAWNFILEViewer ()
void SetView ()
void ClearView ()
void DrawView ()
void ShowView ()
void SendViewParameters ()
const char * GetG4PrimViewer ()
const char * GetG4PrimViewerInvocation ()
const char * GetPSViewer ()
void SendDrawingStyleToDAWNGUI (std::ostream &out)

Detailed Description

Definition at line 40 of file G4DAWNFILEViewer.hh.


Constructor & Destructor Documentation

G4DAWNFILEViewer::G4DAWNFILEViewer ( G4DAWNFILESceneHandler scene,
const G4String name = "" 
)

Definition at line 63 of file G4DAWNFILEViewer.cc.

References G4DAWNFILESceneHandler::GetG4PrimFileName().

00064                                                      : 
00065   G4VViewer (sceneHandler,
00066              sceneHandler.IncrementViewCount (),
00067              name),
00068   fSceneHandler (sceneHandler)
00069 {
00070         // Set a g4.prim-file viewer 
00071         strcpy( fG4PrimViewer, "dawn" ); 
00072         if( getenv( "G4DAWNFILE_VIEWER" ) != NULL ) {
00073                 strcpy( fG4PrimViewer, getenv( "G4DAWNFILE_VIEWER" ) ) ;                        
00074         } 
00075 
00076         // string for viewer invocation
00077         if ( !strcmp( fG4PrimViewer, "NONE" ) ) {
00078                 
00079                 strcpy( fG4PrimViewerInvocation, "" );
00080         } else {
00081 
00082                 strcpy( fG4PrimViewerInvocation, fG4PrimViewer );
00083                 strcat( fG4PrimViewerInvocation, " ");
00084                 strcat( fG4PrimViewerInvocation, fSceneHandler.GetG4PrimFileName() );
00085         }
00086 
00087         // Set a PostScript Viewer
00088 //      strcpy( fPSViewer, "ghostview" ); 
00089         strcpy( fPSViewer, "gv" ); 
00090         if( getenv( "G4DAWNFILE_PS_VIEWER" ) != NULL ) {
00091                 strcpy( fPSViewer, getenv( "G4DAWNFILE_PS_VIEWER" ) ) ;                 
00092         } 
00093 
00094 }

G4DAWNFILEViewer::~G4DAWNFILEViewer (  )  [virtual]

Definition at line 97 of file G4DAWNFILEViewer.cc.

00098 {}


Member Function Documentation

void G4DAWNFILEViewer::ClearView (  )  [virtual]

Implements G4VViewer.

Definition at line 114 of file G4DAWNFILEViewer.cc.

References G4FRofstream::Close(), G4VisManager::errors, G4DAWNFILESceneHandler::fG4PrimFileName, G4DAWNFILESceneHandler::fPrimDest, FR_G4_PRIM_HEADER, G4DAWNFILESceneHandler::FRBeginModeling(), G4DAWNFILESceneHandler::FRflag_in_modeling, G4cout, G4endl, G4VisManager::GetVerbosity(), G4FRofstream::IsOpen(), G4FRofstream::Open(), and G4DAWNFILESceneHandler::SendStr().

00115 {
00116 #if defined DEBUG_FR_VIEW
00117   if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
00118         G4cout << "***** G4DAWNFILEViewer::ClearView (): No effects " << G4endl;
00119 #endif
00120         if (fSceneHandler.fPrimDest.IsOpen()) {
00121           fSceneHandler.fPrimDest.Close();
00122           // Re-open with same filename...
00123           fSceneHandler.fPrimDest.Open(fSceneHandler.fG4PrimFileName);
00124           fSceneHandler.SendStr( FR_G4_PRIM_HEADER );
00125           fSceneHandler.FRflag_in_modeling = false;
00126           fSceneHandler.FRBeginModeling();
00127         }
00128 }

void G4DAWNFILEViewer::DrawView (  )  [virtual]

Implements G4VViewer.

Definition at line 132 of file G4DAWNFILEViewer.cc.

References G4VisManager::errors, G4DAWNFILESceneHandler::FRBeginModeling(), G4cout, G4endl, G4VisManager::GetVerbosity(), G4VViewer::NeedKernelVisit(), and G4VViewer::ProcessView().

00133 {
00134 #if defined DEBUG_FR_VIEW
00135   if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
00136         G4cout << "***** G4DAWNFILEViewer::DrawView () " << G4endl;
00137 #endif
00138                 //----- 
00139         fSceneHandler.FRBeginModeling() ;
00140 
00141                 //----- Always visit G4 kernel 
00142         NeedKernelVisit ();
00143                                    
00144                 //----- Draw
00145         ProcessView () ;
00146 
00147 } // G4DAWNFILEViewer::DrawView () 

const char* G4DAWNFILEViewer::GetG4PrimViewer (  )  [inline]

Definition at line 57 of file G4DAWNFILEViewer.hh.

00057 { return fG4PrimViewer ;}

const char* G4DAWNFILEViewer::GetG4PrimViewerInvocation (  )  [inline]

Definition at line 58 of file G4DAWNFILEViewer.hh.

Referenced by ShowView().

00058 { return fG4PrimViewerInvocation ;}

const char* G4DAWNFILEViewer::GetPSViewer (  )  [inline]

Definition at line 59 of file G4DAWNFILEViewer.hh.

Referenced by SendViewParameters().

00059 { return fPSViewer ;}

void G4DAWNFILEViewer::SendDrawingStyleToDAWNGUI ( std::ostream &  out  ) 

Definition at line 207 of file G4DAWNFILEViewer.cc.

References G4VViewer::fVP, G4endl, G4ViewParameters::GetDrawingStyle(), G4ViewParameters::hlhsr, G4ViewParameters::hlr, G4ViewParameters::hsr, and G4ViewParameters::wireframe.

Referenced by SendViewParameters().

00208 {
00210 //#if defined DEBUG_FR_VIEW
00211 //  G4cout << "***** G4DAWNFILEViewer::SendDrawingStyleToDAWNGUI()" << G4endl;
00212 //#endif
00214 
00215         G4int  style = fVP.GetDrawingStyle();
00216 
00217         enum {  FR_WIREFRAME_STYLE = 1, FR_WF_STORED_STYLE = 2,
00218                 FR_HID_STYLE       = 3, FR_HID2_STYLE      = 4,
00219                 FR_HID3_STYLE      = 5, FR_DRAWING_MODE_END_STYLE = 6 };
00220 
00221         switch( style )
00222         {
00223           case G4ViewParameters::wireframe: 
00224                 out <<  FR_WIREFRAME_STYLE << G4endl;
00225                 break;
00226           case G4ViewParameters::hlr:
00227                 out <<  FR_HID2_STYLE      << G4endl; // LINE
00228                 break;
00229           case G4ViewParameters::hsr:
00230           case G4ViewParameters::hlhsr:
00231                 out <<  FR_HID_STYLE       << G4endl; // SURFACE
00232                 break;
00233           default:
00234                 out <<  FR_WIREFRAME_STYLE << G4endl;
00235                 break;
00236         }
00237 
00238 } // G4DAWNFILEViewer::SendDrawingStyle()  

void G4DAWNFILEViewer::SendViewParameters (  ) 

Definition at line 243 of file G4DAWNFILEViewer.cc.

References G4VisManager::errors, FR_ENV_MULTI_WINDOW, FR_ENV_MULTI_WINDOW2, G4VViewer::fVP, G4cout, G4endl, G4ViewParameters::GetCurrentTargetPoint(), G4ViewParameters::GetDolly(), G4Scene::GetExtent(), G4VisExtent::GetExtentRadius(), G4ViewParameters::GetFieldHalfAngle(), GetPSViewer(), G4VSceneHandler::GetScene(), G4Scene::GetStandardTargetPoint(), G4VisManager::GetVerbosity(), G4ViewParameters::GetViewpointDirection(), G4ViewParameters::GetZoomFactor(), G4INCL::Math::pi, and SendDrawingStyleToDAWNGUI().

Referenced by ShowView().

00244 {
00245   // Calculates view representation based on extent of object being
00246   // viewed and (initial) direction of camera.  (Note: it can change
00247   // later due to user interaction via visualization system's GUI.)
00248 
00249 #if defined DEBUG_FR_VIEW
00250   if (G4VisManager::GetVerbosity() >= G4VisManager::errors) {
00251     G4cout << "***** G4DAWNFILEViewer::SendViewParameters()  "; 
00252     G4cout << "(GUI parameters)" << G4endl;
00253   }
00254 #endif 
00255 
00256                 //----- Magic number to decide camera distance automatically
00257         const    G4double        HOW_FAR            = 1000.0       ; // to define "infinity"
00258         const    G4double        MIN_HALF_ANGLE     = 0.01         ;
00259         const    G4double        MAX_HALF_ANGLE     = 0.499 * pi ;
00260 
00261                 //----- CALC camera distance
00262                 //..... Note: Camera cannot enter inside object
00263         G4double  camera_distance ;
00264         G4double  radius = fSceneHandler.GetScene()->GetExtent().GetExtentRadius();
00265 
00266         G4double half_view_angle  = std::fabs ( fVP.GetFieldHalfAngle () ) ;
00267         if( half_view_angle > MAX_HALF_ANGLE ) { 
00268           half_view_angle = MAX_HALF_ANGLE ; 
00269         } 
00270 
00271         if( half_view_angle < MIN_HALF_ANGLE ) {
00272                         //----- infinity (or ortho projection)
00273                 camera_distance = radius * HOW_FAR ;  
00274         } else {
00275                         //----- Calc camera distance from half view angle
00276                 camera_distance = radius / std::sin ( half_view_angle );
00277                 camera_distance -= fVP.GetDolly();
00278         }
00279 
00280         if ( camera_distance < radius ) { 
00281           if (G4VisManager::GetVerbosity() >= G4VisManager::errors) {
00282                 G4cout << "WARNING from DAWNFILE driver:" << G4endl;
00283                 G4cout << "  Camera cannot enter inside objects"      << G4endl;
00284           }
00285                 camera_distance = radius ; 
00286         }
00287 
00288                 //----- CALC camera direction
00289         const G4Vector3D& camera_direction \
00290           = fVP.GetViewpointDirection().unit();
00291         const G4double v_angle =  (180.0 / pi) * camera_direction.theta() ;
00292         const G4double h_angle =  (180.0 / pi) * camera_direction.phi  () ;
00293 
00294 
00295         //########### Generation of the file .DAWN.history for DAWN GUI
00296                 //-----
00297         std::ofstream gui_out (".DAWN_1.history") ; 
00298 
00299         // ######### P1 
00300 
00301                 //----- camera position
00302         gui_out << camera_distance << G4endl;
00303         gui_out << v_angle  << G4endl ;
00304         gui_out << h_angle  << G4endl ;
00305         gui_out << "0"  << G4endl     ; // auto target
00306 
00307                 //----- target point 
00308         const G4Point3D&  target_point
00309           = fSceneHandler.GetScene()->GetStandardTargetPoint()
00310           + fVP.GetCurrentTargetPoint();
00311         gui_out << target_point.x()          << G4endl ;
00312         gui_out << target_point.y()          << G4endl ;
00313         gui_out << target_point.z()          << G4endl ;
00314 
00315                 //----- Magnification
00316         const G4double   zoom_factor  = fVP.GetZoomFactor();
00317         if( half_view_angle < MIN_HALF_ANGLE ) {
00318 
00319                 gui_out << zoom_factor << G4endl;
00320 
00321         } else {
00322                 const G4double FR_HALF_SCREEN_SIZE = 0.5 ;
00323                 G4double  focal_distance \
00324                   = FR_HALF_SCREEN_SIZE / std::tan( half_view_angle ); 
00325                 focal_distance *= zoom_factor ;
00326 
00327                 gui_out << "fd" << focal_distance << G4endl;
00328 
00329         }
00330         SendDrawingStyleToDAWNGUI( gui_out ) ; // gui_out, viewing mode
00331         gui_out << "0.001" << G4endl           ; // 3D Tolerance 
00332         gui_out << "0"     << G4endl           ; // not display parameters
00333 
00334 
00335         // ######### P2
00336         gui_out << 1 << G4endl;   // Source light 
00337         gui_out << 1 << G4endl;   
00338         gui_out << 1 << G4endl;   
00339         gui_out << 0.5 << G4endl; // Ambient light
00340         gui_out << 0.5 << G4endl;
00341         gui_out << 0.5 << G4endl;
00342         gui_out << 19.0 << G4endl; // Light direction (Polar)
00343         gui_out << 71.0 << G4endl; // Light direction (Azimuthal)
00344 
00345         // ######### P3
00346         gui_out << 0.1 << G4endl;    // Real edge width
00347         gui_out << 0.1 << G4endl;    // outline   width
00348         gui_out << 0.1 << G4endl;    // aux edge  width
00349         gui_out << 3   << G4endl;      // aux edge  style
00350         gui_out << 70.0<< G4endl;   // aux-edge threshold angle
00351         gui_out << 0.1 << G4endl;       // line width
00352         gui_out << 0   << G4endl;        // haloing
00353         gui_out << 1   << G4endl;        // Dashed edged for back faces
00354 
00355         //######### P4
00356                //----- drawing device
00357   //    enum {PS=1, XWIN=2, PS2=3, XWIN2=4, OPEN_GL=5, DEVICE_END=6};
00358         if( ( ( getenv( FR_ENV_MULTI_WINDOW ) != NULL        ) && \
00359               ( strcmp( getenv( FR_ENV_MULTI_WINDOW ),"0"  ) )       ) || \
00360             ( ( getenv( FR_ENV_MULTI_WINDOW2 ) != NULL        ) && \
00361               ( strcmp( getenv( FR_ENV_MULTI_WINDOW2 ),"0"  ) )      )     )
00362         {
00363                 gui_out << 2 << G4endl; // OpenWindow
00364         } else {
00365                 gui_out << 1 << G4endl; // Invoke PS viewer
00366         }
00367 
00368         gui_out << GetPSViewer() << G4endl; // PS viewer
00369         gui_out << 1 << G4endl            ; // Do not add showpage 
00370         gui_out << 0 << G4endl            ; // Non-append mode
00371 
00372         gui_out.close();
00373         //########### end of generating file .DAWN.history 
00374 
00375 
00376 } 

void G4DAWNFILEViewer::SetView (  )  [virtual]

Implements G4VViewer.

Definition at line 101 of file G4DAWNFILEViewer.cc.

References G4VisManager::errors, G4cout, G4endl, and G4VisManager::GetVerbosity().

00102 {
00103 #if defined DEBUG_FR_VIEW
00104   if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
00105     G4cout << "***** G4DAWNFILEViewer::SetView(): No effects" << G4endl;
00106 #endif 
00107 // Do nothing, since DAWN is running as a different process.
00108 // SendViewParameters () will do this job instead.
00109 }

void G4DAWNFILEViewer::ShowView (  )  [virtual]

Reimplemented from G4VViewer.

Definition at line 152 of file G4DAWNFILEViewer.cc.

References G4FRofstream::DoesFileExist(), G4VisManager::errors, G4DAWNFILESceneHandler::FREndModeling(), G4DAWNFILESceneHandler::FRIsInModeling(), G4cout, G4endl, G4DAWNFILESceneHandler::GetG4PrimFileName(), GetG4PrimViewerInvocation(), G4VisManager::GetVerbosity(), and SendViewParameters().

00153 {
00154 #if defined DEBUG_FR_VIEW
00155   if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
00156         G4cout << "***** G4DAWNFILEViewer::ShowView () " << G4endl;
00157 #endif
00158 
00159         if( fSceneHandler.FRIsInModeling() ) 
00160         {
00161                         //----- End of modeling
00162                         // !EndModeling, !DrawAll, !CloseDevice,
00163                         // close g4.prim
00164                 fSceneHandler.FREndModeling();
00165 
00166                         //----- Output DAWN GUI file 
00167                 SendViewParameters(); 
00168 
00169                         //----- string for viewer invocation
00170                 if ( !strcmp( fG4PrimViewer, "NONE" ) ) {
00171                 
00172                         strcpy( fG4PrimViewerInvocation, "" );
00173                 } else {
00174 
00175                         strcpy( fG4PrimViewerInvocation, fG4PrimViewer );
00176                         strcat( fG4PrimViewerInvocation, " ");
00177                         strcat( fG4PrimViewerInvocation, fSceneHandler.GetG4PrimFileName() );
00178                 }
00179 
00180 
00181                 //----- Invoke DAWN
00182                 G4cout << G4endl ;
00183                 if( false == G4FRofstream::DoesFileExist( fSceneHandler.GetG4PrimFileName() ) )   
00184                 {
00185                         G4cout << "ERROR: Failed to generate file  ";
00186                         G4cout << fSceneHandler.GetG4PrimFileName() << G4endl;
00187 
00188                 } else  if( strcmp( GetG4PrimViewerInvocation(), "" ) )  
00189                 {
00190                         G4cout << "File  " << fSceneHandler.GetG4PrimFileName() ;
00191                         G4cout << "  is generated." << G4endl;
00192                         G4cout << GetG4PrimViewerInvocation() << G4endl;
00193                         (void) system( GetG4PrimViewerInvocation() );
00194 
00195                 } else { // no view, i.e., only file generation
00196                         G4cout << "File  " << fSceneHandler.GetG4PrimFileName() ; 
00197                         G4cout << "  is generated." << G4endl;
00198                         G4cout << "No viewer is invoked." << G4endl;
00199                 }
00200 
00201         }
00202 
00203 } // G4DAWNFILEViewer::ShowView()


The documentation for this class was generated from the following files:
Generated on Mon May 27 17:51:44 2013 for Geant4 by  doxygen 1.4.7