00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #define __G_ANSI_C__
00034 #define G4DAWNFILE_STRUCTURE_PRIORITY 1.
00035
00036
00037
00038 #include "G4ios.hh"
00039 #include <stdio.h>
00040 #include <string.h>
00041 #include <assert.h>
00042
00043 #include "G4VisManager.hh"
00044 #include "G4Scene.hh"
00045 #include "G4Vector3D.hh"
00046 #include "G4VisExtent.hh"
00047 #include "G4LogicalVolume.hh"
00048 #include "G4VSolid.hh"
00049 #include "G4PhysicalConstants.hh"
00050
00051 #include "G4FRConst.hh"
00052 #include "G4DAWNFILE.hh"
00053 #include "G4DAWNFILESceneHandler.hh"
00054 #include "G4DAWNFILEViewer.hh"
00055
00056
00057
00058
00059 const char FR_ENV_MULTI_WINDOW [] = "G4DAWN_MULTI_WINDOW" ;
00060 const char FR_ENV_MULTI_WINDOW2[] = "G4DAWNFILE_MULTI_WINDOW" ;
00061
00062
00063 G4DAWNFILEViewer::G4DAWNFILEViewer (G4DAWNFILESceneHandler& sceneHandler,
00064 const G4String& name):
00065 G4VViewer (sceneHandler,
00066 sceneHandler.IncrementViewCount (),
00067 name),
00068 fSceneHandler (sceneHandler)
00069 {
00070
00071 strcpy( fG4PrimViewer, "dawn" );
00072 if( getenv( "G4DAWNFILE_VIEWER" ) != NULL ) {
00073 strcpy( fG4PrimViewer, getenv( "G4DAWNFILE_VIEWER" ) ) ;
00074 }
00075
00076
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
00088
00089 strcpy( fPSViewer, "gv" );
00090 if( getenv( "G4DAWNFILE_PS_VIEWER" ) != NULL ) {
00091 strcpy( fPSViewer, getenv( "G4DAWNFILE_PS_VIEWER" ) ) ;
00092 }
00093
00094 }
00095
00096
00097 G4DAWNFILEViewer::~G4DAWNFILEViewer ()
00098 {}
00099
00100
00101 void G4DAWNFILEViewer::SetView ()
00102 {
00103 #if defined DEBUG_FR_VIEW
00104 if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
00105 G4cout << "***** G4DAWNFILEViewer::SetView(): No effects" << G4endl;
00106 #endif
00107
00108
00109 }
00110
00111
00112
00113 void
00114 G4DAWNFILEViewer::ClearView( void )
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
00123 fSceneHandler.fPrimDest.Open(fSceneHandler.fG4PrimFileName);
00124 fSceneHandler.SendStr( FR_G4_PRIM_HEADER );
00125 fSceneHandler.FRflag_in_modeling = false;
00126 fSceneHandler.FRBeginModeling();
00127 }
00128 }
00129
00130
00131
00132 void G4DAWNFILEViewer::DrawView ()
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
00142 NeedKernelVisit ();
00143
00144
00145 ProcessView () ;
00146
00147 }
00148
00149
00150
00151
00152 void G4DAWNFILEViewer::ShowView( void )
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
00162
00163
00164 fSceneHandler.FREndModeling();
00165
00166
00167 SendViewParameters();
00168
00169
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
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 {
00196 G4cout << "File " << fSceneHandler.GetG4PrimFileName() ;
00197 G4cout << " is generated." << G4endl;
00198 G4cout << "No viewer is invoked." << G4endl;
00199 }
00200
00201 }
00202
00203 }
00204
00205
00206
00207 void G4DAWNFILEViewer::SendDrawingStyleToDAWNGUI( std::ostream& out )
00208 {
00210
00211
00212
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;
00228 break;
00229 case G4ViewParameters::hsr:
00230 case G4ViewParameters::hlhsr:
00231 out << FR_HID_STYLE << G4endl;
00232 break;
00233 default:
00234 out << FR_WIREFRAME_STYLE << G4endl;
00235 break;
00236 }
00237
00238 }
00239
00240
00241
00242
00243 void G4DAWNFILEViewer::SendViewParameters ()
00244 {
00245
00246
00247
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
00257 const G4double HOW_FAR = 1000.0 ;
00258 const G4double MIN_HALF_ANGLE = 0.01 ;
00259 const G4double MAX_HALF_ANGLE = 0.499 * pi ;
00260
00261
00262
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
00273 camera_distance = radius * HOW_FAR ;
00274 } else {
00275
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
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
00296
00297 std::ofstream gui_out (".DAWN_1.history") ;
00298
00299
00300
00301
00302 gui_out << camera_distance << G4endl;
00303 gui_out << v_angle << G4endl ;
00304 gui_out << h_angle << G4endl ;
00305 gui_out << "0" << G4endl ;
00306
00307
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
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 ) ;
00331 gui_out << "0.001" << G4endl ;
00332 gui_out << "0" << G4endl ;
00333
00334
00335
00336 gui_out << 1 << G4endl;
00337 gui_out << 1 << G4endl;
00338 gui_out << 1 << G4endl;
00339 gui_out << 0.5 << G4endl;
00340 gui_out << 0.5 << G4endl;
00341 gui_out << 0.5 << G4endl;
00342 gui_out << 19.0 << G4endl;
00343 gui_out << 71.0 << G4endl;
00344
00345
00346 gui_out << 0.1 << G4endl;
00347 gui_out << 0.1 << G4endl;
00348 gui_out << 0.1 << G4endl;
00349 gui_out << 3 << G4endl;
00350 gui_out << 70.0<< G4endl;
00351 gui_out << 0.1 << G4endl;
00352 gui_out << 0 << G4endl;
00353 gui_out << 1 << G4endl;
00354
00355
00356
00357
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;
00364 } else {
00365 gui_out << 1 << G4endl;
00366 }
00367
00368 gui_out << GetPSViewer() << G4endl;
00369 gui_out << 1 << G4endl ;
00370 gui_out << 0 << G4endl ;
00371
00372 gui_out.close();
00373
00374
00375
00376 }