Import Geant4 0.0.0 source tree
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
// This code implementation is the intellectual property of
|
||||
// the RD44 GEANT4 collaboration.
|
||||
//
|
||||
// By copying, distributing or modifying the Program (or any work
|
||||
// based on the Program) you indicate your acceptance of this statement,
|
||||
// and all its terms.
|
||||
//
|
||||
// $Id: G4DAWNFILE.cc,v 2.2 1998/11/06 13:41:44 allison Exp $
|
||||
// GEANT4 tag $Name: geant4-00 $
|
||||
//
|
||||
// Satoshi TANAKA
|
||||
// DAWNFILE factory.
|
||||
|
||||
//=================//
|
||||
#ifdef G4VIS_BUILD_DAWNFILE_DRIVER
|
||||
//=================//
|
||||
|
||||
|
||||
#include "G4DAWNFILE.hh"
|
||||
|
||||
#define __G_ANSI_C__
|
||||
|
||||
//#include "G4VisFeaturesOfDAWNFILE.hh"
|
||||
#include "G4FRFeatures.hh"
|
||||
#include "G4VScene.hh"
|
||||
#include "G4DAWNFILEScene.hh"
|
||||
#include "G4DAWNFILEView.hh"
|
||||
#include "G4FRConst.hh"
|
||||
|
||||
|
||||
//----- G4DAWNFILE, constructor
|
||||
G4DAWNFILE::G4DAWNFILE ():
|
||||
G4VGraphicsSystem ("DAWNFILE",
|
||||
"DAWNFILE",
|
||||
FR_DAWNFILE_FEATURES,
|
||||
G4VGraphicsSystem::threeD)
|
||||
{}
|
||||
|
||||
//----- G4DAWNFILE, destructor
|
||||
G4DAWNFILE::~G4DAWNFILE ()
|
||||
{}
|
||||
|
||||
|
||||
//----- G4DAWNFILE::CreateScene (const G4String& name)
|
||||
G4VScene* G4DAWNFILE::CreateScene (const G4String& name)
|
||||
{
|
||||
G4VScene* p = new G4DAWNFILEScene (*this, name);
|
||||
|
||||
G4cout << G4DAWNFILEScene::GetSceneCount ()
|
||||
<< ' ' << fName << " scenes extanct." << endl;
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
//----- G4DAWNFILE::CreateView ()
|
||||
G4VView* G4DAWNFILE::CreateView (G4VScene& scene, const G4String& name)
|
||||
{
|
||||
G4VView* pView =
|
||||
new G4DAWNFILEView ((G4DAWNFILEScene&) scene, name);
|
||||
return pView;
|
||||
}
|
||||
|
||||
|
||||
#endif // G4VIS_BUILD_DAWNFILE_DRIVER
|
||||
@@ -0,0 +1,198 @@
|
||||
// This code implementation is the intellectual property of
|
||||
// the RD44 GEANT4 collaboration.
|
||||
//
|
||||
// By copying, distributing or modifying the Program (or any work
|
||||
// based on the Program) you indicate your acceptance of this statement,
|
||||
// and all its terms.
|
||||
//
|
||||
// $Id: G4DAWNFILEScene.cc,v 2.6 1998/12/04 07:31:12 stanaka Exp $
|
||||
// GEANT4 tag $Name: geant4-00 $
|
||||
//
|
||||
// Satoshi TANAKA
|
||||
// DAWNFILE scene.
|
||||
|
||||
|
||||
//=================//
|
||||
#ifdef G4VIS_BUILD_DAWNFILE_DRIVER
|
||||
//=================//
|
||||
|
||||
|
||||
#define __G_ANSI_C__
|
||||
|
||||
//#define DEBUG_FR_SCENE
|
||||
|
||||
//----- header files
|
||||
#include <fstream.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "globals.hh"
|
||||
#include "G4FRConst.hh"
|
||||
#include "G4DAWNFILE.hh"
|
||||
#include "G4DAWNFILEScene.hh"
|
||||
#include "G4DAWNFILEView.hh"
|
||||
#include "G4Point3D.hh"
|
||||
#include "G4VisAttributes.hh"
|
||||
#include "G4Transform3D.hh"
|
||||
#include "G4Polyhedron.hh"
|
||||
#include "G4Box.hh"
|
||||
#include "G4Cons.hh"
|
||||
#include "G4Polyline.hh"
|
||||
#include "G4Trd.hh"
|
||||
#include "G4Tubs.hh"
|
||||
#include "G4Text.hh"
|
||||
#include "G4Circle.hh"
|
||||
#include "G4Square.hh"
|
||||
#include "G4ModelingParameters.hh"
|
||||
#include "G4VPhysicalVolume.hh"
|
||||
|
||||
//----- constants
|
||||
const char FR_ENV_CULL_INVISIBLE_OBJECTS [] = "G4DAWN_CULL_INVISIBLE_OBJECTS";
|
||||
const char G4PRIM_FILE_HEADER [] = "g4_";
|
||||
const char DEFAULT_G4PRIM_FILE_NAME[] = "g4.prim";
|
||||
|
||||
|
||||
///////////////////////////
|
||||
// Driver-dependent part //
|
||||
///////////////////////////
|
||||
|
||||
|
||||
//----- G4DAWNFILEScene, constructor
|
||||
G4DAWNFILEScene::G4DAWNFILEScene (G4DAWNFILE& system, const G4String& name):
|
||||
fSystem (system) ,
|
||||
G4VScene (system, fSceneIdCount++, name) ,
|
||||
fPrimDest () ,
|
||||
flag_in_modeling (false) ,
|
||||
flag_saving_g4_prim (false) ,
|
||||
COMMAND_BUF_SIZE (G4FRofstream::SEND_BUFMAX)
|
||||
{
|
||||
// count instantiated scenes
|
||||
fSceneCount++;
|
||||
|
||||
// g4.prim filename and its directory
|
||||
if ( getenv( "G4DAWNFILE_DEST_DIR" ) == NULL ) {
|
||||
strcpy( fG4PrimDestDir , "" );
|
||||
strcpy( fG4PrimFileName, DEFAULT_G4PRIM_FILE_NAME );
|
||||
} else {
|
||||
strcpy( fG4PrimDestDir , getenv( "G4DAWNFILE_DEST_DIR" ) );
|
||||
strcpy( fG4PrimFileName, DEFAULT_G4PRIM_FILE_NAME );
|
||||
}
|
||||
|
||||
// maximum number of g4.prim files in the dest directory
|
||||
fMaxFileNum = 1 ; // initialization
|
||||
if ( getenv( "G4DAWNFILE_MAX_FILE_NUM" ) != NULL ) {
|
||||
|
||||
sscanf( getenv("G4DAWNFILE_MAX_FILE_NUM"), "%d", &fMaxFileNum ) ;
|
||||
|
||||
} else {
|
||||
fMaxFileNum = 1 ;
|
||||
}
|
||||
if( fMaxFileNum < 1 ) { fMaxFileNum = 1 ; }
|
||||
|
||||
}
|
||||
|
||||
|
||||
//----- G4DAWNFILEScene, destructor
|
||||
G4DAWNFILEScene::~G4DAWNFILEScene ()
|
||||
{
|
||||
#if defined DEBUG_FR_SCENE
|
||||
G4cerr << "***** ~G4DAWNFILEScene" << endl;
|
||||
#endif
|
||||
fSceneCount--;
|
||||
ClearStore (); // clear current scene
|
||||
|
||||
}
|
||||
|
||||
void G4DAWNFILEScene::SetG4PrimFileName()
|
||||
{
|
||||
// g4.prim, g4_1.prim, ..., g4_MAX_FILE_INDEX.prim
|
||||
const int MAX_FILE_INDEX = fMaxFileNum - 1 ;
|
||||
|
||||
// dest directory (null if no environmental variables is set)
|
||||
strcpy ( fG4PrimFileName, fG4PrimDestDir) ;
|
||||
|
||||
// create full path name (default)
|
||||
strcat ( fG4PrimFileName, DEFAULT_G4PRIM_FILE_NAME );
|
||||
|
||||
// Automatic updation of file names
|
||||
for( int i = 0 ; i < fMaxFileNum ; i++) {
|
||||
|
||||
// Message
|
||||
if( fMaxFileNum > 1 && i == MAX_FILE_INDEX ) {
|
||||
G4cerr << "===========================================" << endl;
|
||||
G4cerr << "WARNING MESSAGE from DAWNFILE driver: " << endl;
|
||||
G4cerr << " This file name is the final one in the " << endl;
|
||||
G4cerr << " automatic updation of the output file name." << endl;
|
||||
G4cerr << " You may overwrite an existing file of " << endl;
|
||||
G4cerr << " the same name. " << endl;
|
||||
G4cerr << "===========================================" << endl;
|
||||
}
|
||||
|
||||
// re-determine file to G4DAWNFILE_DEST_DIR/g4_i.prim for i>0
|
||||
if( i > 0 ) {
|
||||
sprintf( fG4PrimFileName, "%s%s%d.prim" , fG4PrimDestDir, G4PRIM_FILE_HEADER, i );
|
||||
}
|
||||
|
||||
// check validity of the file name
|
||||
ifstream fin ;
|
||||
fin.open(fG4PrimFileName) ;
|
||||
if(!fin) {
|
||||
// new file
|
||||
fin.close(); // error recovery
|
||||
break;
|
||||
} else {
|
||||
// already exists (try next)
|
||||
fin.close();
|
||||
}
|
||||
|
||||
} // for
|
||||
|
||||
G4cerr << "===========================================" << endl;
|
||||
G4cerr << "Output file: " << fG4PrimFileName << endl;
|
||||
G4cerr << "Muximal number of file in the destination directory: " << fMaxFileNum << endl;
|
||||
G4cerr << " (Customizable as: setenv G4DAWNFILE_MAX_FILE_NUM number) " << endl;
|
||||
G4cerr << "===========================================" << endl;
|
||||
|
||||
} // G4DAWNFILEScene::SetG4PrimFileName()
|
||||
|
||||
|
||||
void G4DAWNFILEScene::BeginSavingG4Prim( void )
|
||||
{
|
||||
if( !IsSavingG4Prim() )
|
||||
{
|
||||
SetG4PrimFileName() ; // returned to fG4PrimFileName
|
||||
fPrimDest.Open(fG4PrimFileName) ;
|
||||
|
||||
SendStr( FR_G4_PRIM_HEADER ) ;
|
||||
flag_saving_g4_prim = true ;
|
||||
}
|
||||
}
|
||||
|
||||
void G4DAWNFILEScene::EndSavingG4Prim ( void )
|
||||
{
|
||||
if( IsSavingG4Prim() )
|
||||
{
|
||||
fPrimDest.Close() ;
|
||||
flag_saving_g4_prim = false ;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////
|
||||
// Common to DAWN and DAWNFILE drivers //
|
||||
/////////////////////////////////////////
|
||||
|
||||
#define G4FRSCENE G4DAWNFILEScene
|
||||
#include "G4FRSceneFunc.icc"
|
||||
#undef G4FRSCENE
|
||||
|
||||
//////////////////////
|
||||
// static variables //
|
||||
//////////////////////
|
||||
|
||||
//----- static variables
|
||||
G4int G4DAWNFILEScene::fSceneIdCount = 0;
|
||||
|
||||
G4int G4DAWNFILEScene::fSceneCount = 0;
|
||||
// num of existing instances
|
||||
|
||||
#endif // G4VIS_BUILD_DAWNFILE_DRIVER
|
||||
@@ -0,0 +1,381 @@
|
||||
// This code implementation is the intellectual property of
|
||||
// the RD44 GEANT4 collaboration.
|
||||
//
|
||||
// By copying, distributing or modifying the Program (or any work
|
||||
// based on the Program) you indicate your acceptance of this statement,
|
||||
// and all its terms.
|
||||
//
|
||||
// $Id: G4DAWNFILEView.cc,v 2.5 1998/11/29 21:33:12 stanaka Exp $
|
||||
// GEANT4 tag $Name: geant4-00 $
|
||||
//
|
||||
// Satoshi TANAKA
|
||||
// DAWNFILE view - opens window, hard copy, etc.
|
||||
|
||||
|
||||
//=================//
|
||||
#ifdef G4VIS_BUILD_DAWNFILE_DRIVER
|
||||
//=================//
|
||||
|
||||
#define __G_ANSI_C__
|
||||
#define G4DAWNFILE_STRUCTURE_PRIORITY 1.
|
||||
|
||||
// #define DEBUG_FR_VIEW
|
||||
|
||||
#include "G4ios.hh"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "G4SceneData.hh"
|
||||
#include "G4Vector3D.hh"
|
||||
#include "G4VisExtent.hh"
|
||||
#include "G4LogicalVolume.hh"
|
||||
#include "G4VSolid.hh"
|
||||
|
||||
#include "G4FRConst.hh"
|
||||
#include "G4DAWNFILE.hh"
|
||||
#include "G4DAWNFILEScene.hh"
|
||||
#include "G4DAWNFILEView.hh"
|
||||
|
||||
|
||||
|
||||
//----- constants
|
||||
const char FR_ENV_MULTI_WINDOW[] = "G4DAWN_MULTI_WINDOW" ;
|
||||
|
||||
//----- G4DAWNFILEView, constructor
|
||||
G4DAWNFILEView::G4DAWNFILEView (G4DAWNFILEScene& scene,
|
||||
const G4String& name):
|
||||
G4VView (scene, scene.IncrementViewCount (), name), fScene (scene)
|
||||
{
|
||||
// Set a g4.prim-file viewer
|
||||
strcpy( fG4PrimViewer, "dawn" );
|
||||
if( getenv( "G4DAWNFILE_VIEWER" ) != NULL ) {
|
||||
strcpy( fG4PrimViewer, getenv( "G4DAWNFILE_VIEWER" ) ) ;
|
||||
}
|
||||
|
||||
// string for viewer invocation
|
||||
if ( !strcmp( fG4PrimViewer, "NONE" ) ) {
|
||||
|
||||
strcpy( fG4PrimViewerInvocation, "" );
|
||||
} else {
|
||||
|
||||
strcpy( fG4PrimViewerInvocation, fG4PrimViewer );
|
||||
strcat( fG4PrimViewerInvocation, " ");
|
||||
strcat( fG4PrimViewerInvocation, fScene.GetG4PrimFileName() );
|
||||
}
|
||||
|
||||
// Set a PostScript Viewer
|
||||
strcpy( fPSViewer, "ghostview" );
|
||||
if( getenv( "G4DAWNFILE_PS_VIEWER" ) != NULL ) {
|
||||
strcpy( fPSViewer, getenv( "G4DAWNFILE_PS_VIEWER" ) ) ;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//----- G4DAWNFILEView, destructor
|
||||
G4DAWNFILEView::~G4DAWNFILEView ()
|
||||
{}
|
||||
|
||||
//----- G4DAWNFILEView::SetView ()
|
||||
void G4DAWNFILEView::SetView ()
|
||||
{
|
||||
#if defined DEBUG_FR_VIEW
|
||||
G4cerr << "***** G4DAWNFILEView::SetView()\n";
|
||||
#endif
|
||||
// Do nothing, since DAWN is running as a different process.
|
||||
// SendViewParameters () will do this job instead.
|
||||
}
|
||||
|
||||
|
||||
//----- G4DAWNFILEView::ClearView()
|
||||
void
|
||||
G4DAWNFILEView::ClearView( void )
|
||||
{
|
||||
#if defined DEBUG_FR_VIEW
|
||||
G4cerr << "***** G4DAWNFILEView::ClearView () " << endl;
|
||||
#endif
|
||||
|
||||
//----- Begin saving data to g4.prim
|
||||
fScene.BeginSavingG4Prim();
|
||||
|
||||
//----- Clear old data
|
||||
fScene.SendStr( FR_CLEAR_DATA );
|
||||
|
||||
}
|
||||
|
||||
|
||||
//----- G4DAWNFILEView::DrawView ()
|
||||
void G4DAWNFILEView::DrawView ()
|
||||
{
|
||||
#if defined DEBUG_FR_VIEW
|
||||
G4cerr << "***** G4DAWNFILEView::DrawView () " << endl;
|
||||
#endif
|
||||
//----- Error recovery
|
||||
if( fScene.IsInModeling() ) {
|
||||
G4cerr << "WARNING from DAWNFILE driver:" << endl;
|
||||
G4cerr << " You've invoked a drawing command before " << endl;
|
||||
G4cerr << " completing your previous visualization." << endl;
|
||||
// G4cerr << " You should have invoked command, /vis~/show/view," << endl;
|
||||
// G4cerr << " to complete it." << endl;
|
||||
|
||||
FlushView();
|
||||
}
|
||||
|
||||
//----- Begin Saving g4.prim file
|
||||
fScene.BeginSavingG4Prim();
|
||||
|
||||
//----- set view if necessary
|
||||
SendViewParameters();
|
||||
// Camera data should be sent at every time, even if
|
||||
// the setting is unchanged at GEANT 4 side.
|
||||
|
||||
//----- Always visit G4 kernel
|
||||
NeedKernelVisit ();
|
||||
|
||||
//----- Draw
|
||||
ProcessView () ;
|
||||
|
||||
} // G4DAWNFILEView::DrawView ()
|
||||
|
||||
|
||||
|
||||
//----- G4DAWNFILEView::ShowView()
|
||||
void G4DAWNFILEView::ShowView( void )
|
||||
{
|
||||
#if defined DEBUG_FR_VIEW
|
||||
G4cerr << "***** G4DAWNFILEView::ShowView () " << endl;
|
||||
#endif
|
||||
|
||||
if( fScene.IsInModeling() ) // if( fScene.flag_in_modeling )
|
||||
{
|
||||
|
||||
//----- End of Data
|
||||
fScene.FREndModeling();
|
||||
|
||||
//----- Draw all
|
||||
fScene.SendStr( FR_DRAW_ALL );
|
||||
|
||||
//----- Close device
|
||||
fScene.SendStr( FR_CLOSE_DEVICE );
|
||||
|
||||
//----- End saving data to g4.prim
|
||||
fScene.EndSavingG4Prim() ;
|
||||
|
||||
|
||||
//----- string for viewer invocation
|
||||
if ( !strcmp( fG4PrimViewer, "NONE" ) ) {
|
||||
|
||||
strcpy( fG4PrimViewerInvocation, "" );
|
||||
} else {
|
||||
|
||||
strcpy( fG4PrimViewerInvocation, fG4PrimViewer );
|
||||
strcat( fG4PrimViewerInvocation, " ");
|
||||
strcat( fG4PrimViewerInvocation, fScene.GetG4PrimFileName() );
|
||||
}
|
||||
|
||||
|
||||
//----- Invoke DAWN
|
||||
if( false == G4FRofstream::DoesFileExist( fScene.GetG4PrimFileName() ) )
|
||||
{
|
||||
G4cout << "ERROR: Failed to generate file ";
|
||||
G4cout << fScene.GetG4PrimFileName() << endl;
|
||||
|
||||
} else if( strcmp( GetG4PrimViewerInvocation(), "" ) )
|
||||
{
|
||||
G4cout << "File " << fScene.GetG4PrimFileName() ;
|
||||
G4cout << " is generated." << endl;
|
||||
G4cout << GetG4PrimViewerInvocation() << endl;
|
||||
system( GetG4PrimViewerInvocation() );
|
||||
|
||||
} else { // no view, i.e., only file generation
|
||||
G4cout << "File " << fScene.GetG4PrimFileName() ;
|
||||
G4cout << " is generated." << endl;
|
||||
G4cout << "No viewer is invoked." << endl;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} // G4DAWNFILEView::ShowView()
|
||||
|
||||
|
||||
//----- G4DAWNFILEView::FlushView()
|
||||
void G4DAWNFILEView::FlushView( void )
|
||||
{
|
||||
#if defined DEBUG_FR_VIEW
|
||||
G4cerr << "***** G4DAWNFILEView::Flush () " << endl;
|
||||
#endif
|
||||
|
||||
ShowView();
|
||||
}
|
||||
|
||||
|
||||
|
||||
//----- G4DAWNFILEView::SendDrawingStyleToDAWNGUI( ostream& out )
|
||||
void G4DAWNFILEView::SendDrawingStyleToDAWNGUI( ostream& out )
|
||||
{
|
||||
#if defined DEBUG_FR_VIEW
|
||||
G4cerr << "***** G4DAWNFILEView::SendDrawingStyle() " << endl;
|
||||
#endif
|
||||
|
||||
G4int style = fVP.GetDrawingStyle();
|
||||
|
||||
enum { FR_WIREFRAME = 1, FR_WF_STORED = 2, FR_HID =3 , \
|
||||
FR_HID2 = 4, FR_HID3 = 5, FR_DRAWING_MODE_END = 6 };
|
||||
|
||||
switch( style )
|
||||
{
|
||||
case G4ViewParameters::wireframe:
|
||||
out << FR_WIREFRAME << endl;
|
||||
break;
|
||||
case G4ViewParameters::hlr:
|
||||
out << FR_HID2 << endl; // LINE
|
||||
break;
|
||||
case G4ViewParameters::hsr:
|
||||
case G4ViewParameters::hlhsr:
|
||||
out << FR_HID << endl; // SURFACE
|
||||
break;
|
||||
default:
|
||||
out << FR_WIREFRAME << endl;
|
||||
break;
|
||||
}
|
||||
|
||||
} // G4DAWNFILEView::SendDrawingStyle()
|
||||
|
||||
|
||||
|
||||
//----- G4DAWNFILEView::SendViewParameters ()
|
||||
void G4DAWNFILEView::SendViewParameters ()
|
||||
{
|
||||
// Calculates view representation based on extent of object being
|
||||
// viewed and (initial) direction of camera. (Note: it can change
|
||||
// later due to user interaction via visualization system's GUI.)
|
||||
|
||||
#if defined DEBUG_FR_VIEW
|
||||
G4cerr << "***** G4DAWNFILEView::SendViewParameters()\n";
|
||||
#endif
|
||||
|
||||
//----- Magic number to decide camera distance automatically
|
||||
const G4double HOW_FAR = 1000.0 ; // to define "infinity"
|
||||
const G4double MIN_HALF_ANGLE = 0.01 ;
|
||||
const G4double MAX_HALF_ANGLE = 0.499 * M_PI ;
|
||||
|
||||
//----- Send Bounding Box
|
||||
fScene.SendBoundingBox();
|
||||
|
||||
//----- CALC camera distance
|
||||
//..... Note: Camera cannot enter inside object
|
||||
G4double camera_distance ;
|
||||
G4double radius = fScene.GetSceneData().GetExtent().GetExtentRadius();
|
||||
|
||||
G4double half_view_angle = fabs ( fVP.GetFieldHalfAngle () ) ;
|
||||
if( half_view_angle > MAX_HALF_ANGLE ) {
|
||||
half_view_angle = MAX_HALF_ANGLE ;
|
||||
}
|
||||
|
||||
if( half_view_angle < MIN_HALF_ANGLE ) {
|
||||
//----- infinity (or ortho projection)
|
||||
camera_distance = radius * HOW_FAR ;
|
||||
} else {
|
||||
//----- Calc camera distance from half view angle
|
||||
camera_distance = radius / sin ( half_view_angle );
|
||||
camera_distance -= fVP.GetDolly();
|
||||
}
|
||||
|
||||
if ( camera_distance < radius ) {
|
||||
G4cerr << "WARNING from DAWNFILE driver:" << endl;
|
||||
G4cerr << " Camera cannot enter inside objects" << endl;
|
||||
camera_distance = radius ;
|
||||
}
|
||||
|
||||
//----- CALC camera direction
|
||||
const G4Vector3D& camera_direction \
|
||||
= fVP.GetViewpointDirection().unit();
|
||||
const G4double v_angle = (180.0 / M_PI) * camera_direction.theta() ;
|
||||
const G4double h_angle = (180.0 / M_PI) * camera_direction.phi () ;
|
||||
|
||||
|
||||
//########### Generation of the file .DAWN.history for DAWN GUI
|
||||
//-----
|
||||
ofstream gui_out (".DAWN.history") ;
|
||||
|
||||
// ######### P1
|
||||
|
||||
//----- camera position
|
||||
gui_out << camera_distance << endl;
|
||||
gui_out << v_angle << endl ;
|
||||
gui_out << h_angle << endl ;
|
||||
gui_out << "0" << endl ; // auto target
|
||||
|
||||
//----- target point
|
||||
const G4Point3D& target_point = fVP.GetCurrentTargetPoint();
|
||||
gui_out << target_point.x() << endl ;
|
||||
gui_out << target_point.y() << endl ;
|
||||
gui_out << target_point.z() << endl ;
|
||||
|
||||
//----- Magnification
|
||||
const G4double zoom_factor = fVP.GetZoomFactor();
|
||||
if( half_view_angle < MIN_HALF_ANGLE ) {
|
||||
|
||||
gui_out << zoom_factor << endl;
|
||||
|
||||
} else {
|
||||
const G4double FR_HALF_SCREEN_SIZE = 0.5 ;
|
||||
G4double focal_distance \
|
||||
= FR_HALF_SCREEN_SIZE / tan( half_view_angle );
|
||||
focal_distance *= zoom_factor ;
|
||||
|
||||
gui_out << "fd" << focal_distance << endl;
|
||||
|
||||
}
|
||||
SendDrawingStyleToDAWNGUI( gui_out ) ; // gui_out, viewing mode
|
||||
gui_out << "0.001" << endl ; // 3D Tolerance
|
||||
gui_out << "0" << endl ; // not display parameters
|
||||
|
||||
|
||||
// ######### P2
|
||||
gui_out << 1 << endl; // Source light
|
||||
gui_out << 1 << endl;
|
||||
gui_out << 1 << endl;
|
||||
gui_out << 0.5 << endl; // Ambient light
|
||||
gui_out << 0.5 << endl;
|
||||
gui_out << 0.5 << endl;
|
||||
gui_out << 19.0 << endl; // Light direction (Polar)
|
||||
gui_out << 71.0 << endl; // Light direction (Azimuthal)
|
||||
|
||||
// ######### P3
|
||||
gui_out << 0.1 << endl; // Real edge width
|
||||
gui_out << 0.1 << endl; // outline width
|
||||
gui_out << 0.1 << endl; // aux edge width
|
||||
gui_out << 3 << endl; // aux edge style
|
||||
gui_out << 70.0<< endl; // aux-edge threshold angle
|
||||
gui_out << 0.1 << endl; // line width
|
||||
gui_out << 0 << endl; // haloing
|
||||
gui_out << 1 << endl; // Dashed edged for back faces
|
||||
|
||||
//######### P4
|
||||
//----- drawing device
|
||||
// enum {PS=1, XWIN=2, PS2=3, XWIN2=4, OPEN_GL=5, DEVICE_END=6};
|
||||
if( ( getenv( FR_ENV_MULTI_WINDOW ) != NULL ) && \
|
||||
( strcmp( getenv( FR_ENV_MULTI_WINDOW ),"0" ) ) )
|
||||
{
|
||||
gui_out << 2 << endl; // OpenWindow
|
||||
} else {
|
||||
gui_out << 1 << endl; // Invoke PS viewer
|
||||
}
|
||||
gui_out << GetPSViewer() << endl; // PS viewer
|
||||
gui_out << 0; // Add showpage
|
||||
|
||||
|
||||
|
||||
gui_out.close();
|
||||
//########### end of generating file .DAWN.history
|
||||
|
||||
|
||||
//----- SET CAMERA
|
||||
fScene.SendStr( FR_SET_CAMERA );
|
||||
|
||||
|
||||
} // G4DAWNFILEView::SendViewParameters ()
|
||||
|
||||
|
||||
#endif // G4VIS_BUILD_DAWNFILE_DRIVER
|
||||
@@ -0,0 +1,318 @@
|
||||
// This code implementation is the intellectual property of
|
||||
// the RD44 GEANT4 collaboration.
|
||||
//
|
||||
// By copying, distributing or modifying the Program (or any work
|
||||
// based on the Program) you indicate your acceptance of this statement,
|
||||
// and all its terms.
|
||||
//
|
||||
// $Id: G4FRClientServer.cc,v 2.1 1998/07/13 17:11:01 urbi Exp $
|
||||
// GEANT4 tag $Name: geant4-00 $
|
||||
//
|
||||
// Satoshi TANAKA, Wed Jul 3 14:14:29 JST 1996
|
||||
////////////////////////////////
|
||||
///// G4FRClientServer.cc /////
|
||||
////////////////////////////////
|
||||
|
||||
|
||||
//=================//
|
||||
#ifdef G4VIS_BUILD_DAWN_DRIVER
|
||||
//=================//
|
||||
|
||||
#include "G4FRSocketConfig.hh"
|
||||
#include "G4FRSocketMacro.hh"
|
||||
#include "G4FRClientServer.hh"
|
||||
|
||||
// #define DEBUG_CLIENT_SERVER
|
||||
|
||||
#include<sys/param.h>
|
||||
|
||||
//----- const
|
||||
const char DEFAULT_SUN_PATH[] = "FR_TMP3" ;
|
||||
const int DEFAULT_PORT_NUMBER = 40701 ;
|
||||
//const char FR_ENV_SERVER_HOST_NAME[] = "G4DAWN_HOST_NAME" ; // moved to .hh
|
||||
const int MAX_BINDING_TRIAL = 10 ;
|
||||
const int BINDING_TRIAL_INTERVAL = 5 ;
|
||||
const int MAX_CONNECT_TRIAL = 10 ;
|
||||
|
||||
|
||||
//----- G4FRClientServer::G4FRClientServer ()
|
||||
G4FRClientServer::G4FRClientServer ( char terminator , char end_line ) :
|
||||
TERMINATOR ( terminator ) ,
|
||||
END_OF_LINE( end_line ) ,
|
||||
fSocketFd ( -1 )
|
||||
{
|
||||
SetSunPath ( DEFAULT_SUN_PATH ) ; // for Unix domain
|
||||
SetPortNumber ( DEFAULT_PORT_NUMBER ) ;
|
||||
ClearReceivedMessage () ;
|
||||
}
|
||||
|
||||
|
||||
//----- G4FRClientServer::ConnectUnix()
|
||||
int G4FRClientServer::ConnectUnix()
|
||||
{
|
||||
//----- local
|
||||
int flag_connected = 0 ;
|
||||
struct sockaddr_un server_address ;
|
||||
|
||||
//----- make socket
|
||||
fSocketFd = socket( AF_UNIX, SOCK_STREAM, 0 );
|
||||
if( fSocketFd < 0 ) { Err("G4FRClientServer::ConnectUnix(),socket"); }
|
||||
|
||||
//----- set server address
|
||||
memset( (char *)&server_address, '\0', sizeof(server_address)) ;
|
||||
server_address.sun_family = AF_UNIX ;
|
||||
strcpy( server_address.sun_path, SUN_PATH );
|
||||
|
||||
//----- connection
|
||||
int connection_status = -1 ;
|
||||
int num_trial = 0 ;
|
||||
while( connection_status < 0 && num_trial <= MAX_CONNECT_TRIAL ) {
|
||||
num_trial++ ;
|
||||
connection_status = connect( fSocketFd, (struct sockaddr * )(&server_address), sizeof( server_address ) ) ;
|
||||
if( connection_status <0 )
|
||||
{
|
||||
#if defined DEBUG_CLIENT_SERVER
|
||||
Err("G4FRClientServer::ConnectUnix(),connect => RETRY");
|
||||
#endif
|
||||
flag_connected = 0 ;
|
||||
} else {
|
||||
flag_connected = 1 ;
|
||||
break ;
|
||||
}
|
||||
|
||||
sleep(1);
|
||||
|
||||
} // while(connection_status...)
|
||||
|
||||
//----- return status of connection
|
||||
return flag_connected ;
|
||||
|
||||
} // G4FRClientServer::ConnectUnix()
|
||||
|
||||
|
||||
//----- G4FRClientServer::Receive()
|
||||
void G4FRClientServer::Receive()
|
||||
{
|
||||
//-----
|
||||
ClearReceivedMessage () ;
|
||||
if( recv( fSocketFd, fReceivedMessage, G4FRClientServer::RECV_BUFMAX , 0 ) < 0 )
|
||||
{
|
||||
Err("G4FRClientServer::Receive(), recv");
|
||||
}
|
||||
|
||||
#if defined DEBUG_CLIENT_SERVER
|
||||
G4cerr << ">>>>> receivedMessage = " << fReceivedMessage << endl;
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
|
||||
//----- G4FRClientServer::ReceiveLine()
|
||||
void G4FRClientServer::ReceiveLine()
|
||||
{
|
||||
//----- local
|
||||
char buf[1];
|
||||
int index = 0 ;
|
||||
|
||||
//----- receive a line (until newline)
|
||||
memset(fReceivedMessage, '\0', RECV_BUFMAX) ;
|
||||
while( read( fSocketFd, buf, 1 ) == 1 ) {
|
||||
fReceivedMessage[index++] = buf[0];
|
||||
if( IsEndOfLine(buf[0]) ) { break ;}
|
||||
}
|
||||
} // G4FRClientServer::ReceiveLine()
|
||||
|
||||
|
||||
//----- G4FRClientServer::Send()
|
||||
void G4FRClientServer::Send()
|
||||
{
|
||||
if( send( fSocketFd, fSendingMessage, strlen(fSendingMessage) , 0 ) < 0 )
|
||||
{
|
||||
Err("G4FRClientServer::Send(), send");
|
||||
}
|
||||
|
||||
#if defined DEBUG_CLIENT_SERVER
|
||||
G4cerr << "<<<<< SentMessage = " << fSendingMessage << endl;
|
||||
#endif
|
||||
|
||||
} // G4FRClientServer::Send()
|
||||
|
||||
|
||||
//----- G4FRClientServer::Send( message )
|
||||
void G4FRClientServer::Send( const char* message )
|
||||
{
|
||||
this->SetSendingMessage( message ) ;
|
||||
this->Send();
|
||||
|
||||
} // G4FRClientServer::Send( message )
|
||||
|
||||
|
||||
//----- G4FRClientServer::SendLine()
|
||||
void G4FRClientServer::SendLine( const char* message )
|
||||
{
|
||||
//----- local
|
||||
int smsg_length ;
|
||||
|
||||
//----- set message to sending buf
|
||||
this->SetSendingMessage( message ) ;
|
||||
smsg_length = GetSendingMessageLength() ;
|
||||
|
||||
//----- add newline if necessary
|
||||
if( !IsEndOfLine( fSendingMessage[ (smsg_length - 1)] ) ) {
|
||||
fSendingMessage[ smsg_length ] = GetEndOfLine() ;
|
||||
fSendingMessage[ (smsg_length +1) ] = '\0' ;
|
||||
smsg_length = GetSendingMessageLength();
|
||||
}
|
||||
|
||||
//----- send
|
||||
this->Send();
|
||||
|
||||
}// G4FRClientServer::SendLine()
|
||||
|
||||
|
||||
//----- G4FRClientServer::DisConnect()
|
||||
void G4FRClientServer::DisConnect()
|
||||
{
|
||||
//----- close connection
|
||||
if( shutdown(fSocketFd,2) < 0 ) {
|
||||
Err("G4FRClientServer::DisConnect,shutdown");
|
||||
}
|
||||
close( fSocketFd );
|
||||
|
||||
this->Clear();
|
||||
}
|
||||
|
||||
|
||||
|
||||
//----- G4FRClientServer::Clear()
|
||||
void G4FRClientServer::Clear()
|
||||
{
|
||||
unlink(SUN_PATH) ;
|
||||
fSocketFd = -1 ;
|
||||
}
|
||||
|
||||
|
||||
//----- G4FRClientServer::ConnectINET()
|
||||
int G4FRClientServer::ConnectINET()
|
||||
{
|
||||
//----- local
|
||||
int flag_connected = 0 ;
|
||||
sockaddr_in server_address ;
|
||||
char server_hostname[32] ;
|
||||
hostent* server_host_p ;
|
||||
|
||||
//----- make socket
|
||||
fSocketFd = socket( AF_INET, SOCK_STREAM, 0 );
|
||||
if( fSocketFd < 0 ) {
|
||||
#if defined DEBUG_CLIENT_SERVER
|
||||
Err("G4FRClientServer::ConnectINET(),socket");
|
||||
#endif
|
||||
}
|
||||
|
||||
//----- get IP address of server from its name
|
||||
if( getenv( FR_ENV_SERVER_HOST_NAME ) != NULL )
|
||||
{
|
||||
//----- get server name
|
||||
strcpy( server_hostname, getenv( FR_ENV_SERVER_HOST_NAME ) );
|
||||
|
||||
//----- get IP address of server from its name,
|
||||
//..... reading /etc/hosts
|
||||
server_host_p = gethostbyname( server_hostname ) ;
|
||||
|
||||
//----- If the host specified by FR_ENV_SERVER_HOST_NAME
|
||||
//..... is not written in /etc/hosts,
|
||||
//...... server host is set to the same as the
|
||||
//...... client host
|
||||
if( !server_host_p ) {
|
||||
#if defined DEBUG_CLIENT_SERVER
|
||||
Err("G4FRClientServer::ConnectINET(), gethostbyname");
|
||||
#endif
|
||||
//----- get server name
|
||||
if( GET_HOSTNAME( server_hostname, sizeof( server_hostname ) ) < 0 )
|
||||
{ Err("G4FRClientServer::ConnectNET(), GET_HOSTNAME");}
|
||||
|
||||
//----- get IP address of server from its name
|
||||
if( !(server_host_p = gethostbyname( server_hostname ) ) )
|
||||
{ Err("G4FRClientServer::ConnectINET(), gethostbyname");}
|
||||
}
|
||||
|
||||
} else {
|
||||
//----- If FR_ENV_SERVER_HOST_NAME is not set,
|
||||
//...... server host is set to the same as the
|
||||
//...... client host.
|
||||
|
||||
//----- get server name
|
||||
if( GET_HOSTNAME( server_hostname, sizeof( server_hostname ) ) < 0 )
|
||||
{ Err("G4FRClientServer::ConnectNET(), GET_HOSTNAME");}
|
||||
|
||||
//----- get IP address of server from its name
|
||||
if( !(server_host_p = gethostbyname( server_hostname ) ) )
|
||||
{ Err("G4FRClientServer::ConnectINET(), gethostbyname");}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// #if defined DEBUG_CLIENT_SERVER
|
||||
G4cerr << "***** Trying connection to " << server_hostname << endl;
|
||||
// #endif
|
||||
|
||||
|
||||
//----- connection and binding
|
||||
memset( (char *)&server_address, '\0', sizeof(server_address)) ;
|
||||
// clear server_address
|
||||
server_address.sin_family = AF_INET ;
|
||||
server_address.sin_port = htons( PORT_NUMBER );
|
||||
memcpy( (char *)(&server_address.sin_addr ),
|
||||
(char *)( server_host_p->h_addr ),
|
||||
server_host_p->h_length );
|
||||
|
||||
int connection_status = -1 ;
|
||||
int num_trial = 0 ;
|
||||
while( connection_status < 0 && num_trial <= MAX_CONNECT_TRIAL ) {
|
||||
num_trial++ ;
|
||||
connection_status = connect( fSocketFd, (struct sockaddr * )(&server_address), sizeof( server_address ) ) ;
|
||||
if( connection_status <0 )
|
||||
{
|
||||
#if defined DEBUG_CLIENT_SERVER
|
||||
Err("G4FRClientServer::ConnectINET(),connect => RETRY");
|
||||
#endif
|
||||
flag_connected = 0 ;
|
||||
} else {
|
||||
flag_connected = 1 ;
|
||||
break ;
|
||||
}
|
||||
|
||||
sleep(1);
|
||||
|
||||
} // while(connection_status...)
|
||||
|
||||
//----- return status of connection
|
||||
return flag_connected ;
|
||||
|
||||
} // G4FRClientServer::ConnectINET()
|
||||
|
||||
|
||||
//----- G4FRClientServer::WaitSendBack()
|
||||
void G4FRClientServer::WaitSendBack( const char* command_string )
|
||||
{
|
||||
//----- wait for sending back
|
||||
while(1) {
|
||||
this->ReceiveLine();
|
||||
|
||||
if( !strncmp( this->GetReceivedMessage(), \
|
||||
command_string , \
|
||||
(strlen(command_string)) ) )
|
||||
{
|
||||
break;
|
||||
} else {
|
||||
sleep(2);
|
||||
}
|
||||
|
||||
} // while
|
||||
|
||||
//----- clear buffer to receive message
|
||||
this->ClearReceivedMessage();
|
||||
|
||||
} // G4FRClientServer::WaitSendBack()
|
||||
|
||||
#endif // G4VIS_BUILD_DAWN_DRIVER
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,238 @@
|
||||
// This code implementation is the intellectual property of
|
||||
// the RD44 GEANT4 collaboration.
|
||||
//
|
||||
// By copying, distributing or modifying the Program (or any work
|
||||
// based on the Program) you indicate your acceptance of this statement,
|
||||
// and all its terms.
|
||||
//
|
||||
// $Id: G4FukuiRenderer.cc,v 2.3 1998/11/06 13:41:46 allison Exp $
|
||||
// GEANT4 tag $Name: geant4-00 $
|
||||
//
|
||||
//
|
||||
// Satoshi TANAKA
|
||||
// FukuiRenderer factory.
|
||||
|
||||
//=================//
|
||||
#ifdef G4VIS_BUILD_DAWN_DRIVER
|
||||
//=================//
|
||||
|
||||
//#define DEBUG_FR_SYSTEM
|
||||
|
||||
|
||||
#include "G4FukuiRenderer.hh"
|
||||
|
||||
#define __G_ANSI_C__
|
||||
|
||||
//#include "G4VisFeaturesOfFukuiRenderer.hh"
|
||||
#include "G4VScene.hh"
|
||||
#include "G4FukuiRendererScene.hh"
|
||||
#include "G4FukuiRendererView.hh"
|
||||
#include "G4FRClientServer.hh"
|
||||
#include "G4FRConst.hh"
|
||||
#include "G4FRFeatures.hh"
|
||||
|
||||
//----- constant
|
||||
const int FR_DEFAULT_CONNECTION_TIME = 5 ;
|
||||
const char FR_ENV_CONNECTION_TIME [] = "G4DAWN_CONNECTION_TIME";
|
||||
const char FR_ENV_DAWN_GUI_ALWAYS [] = "G4DAWN_GUI_ALWAYS";
|
||||
|
||||
//----- G4FukuiRenderer, constructor
|
||||
G4FukuiRenderer::G4FukuiRenderer ():
|
||||
G4VGraphicsSystem ("FukuiRenderer",
|
||||
"DAWN",
|
||||
FR_DAWNFILE_FEATURES,
|
||||
G4VGraphicsSystem::threeD),
|
||||
fPrimDest() ,
|
||||
fIPMode( G4FukuiRenderer::IP_UNIX ),
|
||||
flag_use_gui (false) ,
|
||||
flag_connected (0)
|
||||
{
|
||||
//----- sorting of objects
|
||||
if( ( getenv( FR_ENV_DAWN_GUI_ALWAYS ) != NULL ) && \
|
||||
( strcmp( getenv( FR_ENV_DAWN_GUI_ALWAYS ),"0" ) ) )
|
||||
{
|
||||
flag_use_gui = true ;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//----- G4FukuiRenderer, destructor
|
||||
G4FukuiRenderer::~G4FukuiRenderer ()
|
||||
{
|
||||
if( flag_connected ) {
|
||||
//----- Terminate FukuiRenderer
|
||||
fPrimDest.SendLine( FR_TERMINATE_DAWND ) ;
|
||||
|
||||
//----- disconnection
|
||||
fPrimDest.DisConnect();
|
||||
flag_connected = 0 ;
|
||||
}
|
||||
}
|
||||
|
||||
//----- G4FukuiRenderer::CreateScene ()
|
||||
G4VScene* G4FukuiRenderer::CreateScene (const G4String& name)
|
||||
{
|
||||
G4VScene* p = new G4FukuiRendererScene (*this, name);
|
||||
|
||||
if(!flag_connected) { delete p ; p = NULL ; }
|
||||
|
||||
G4cout << G4FukuiRendererScene::GetSceneCount ()
|
||||
<< ' ' << fName << " scenes extanct." << endl;
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
//----- G4FukuiRenderer::CreateView ()
|
||||
G4VView* G4FukuiRenderer::CreateView (G4VScene& scene, const G4String& name)
|
||||
{
|
||||
if(!flag_connected) return NULL;
|
||||
G4VView* pView =
|
||||
new G4FukuiRendererView ((G4FukuiRendererScene&) scene, name);
|
||||
return pView;
|
||||
}
|
||||
|
||||
//----- G4FukuiRenderer::UseInetDomainAuto()
|
||||
void G4FukuiRenderer::UseInetDomainAuto()
|
||||
{
|
||||
int pid ;
|
||||
|
||||
#if defined DEBUG_FR_SYSTEM
|
||||
G4cerr << "***** Unix Inet Domain (AUTO mode)" << endl;
|
||||
#endif
|
||||
fIPMode = G4FukuiRenderer::IP_UNIX ;
|
||||
|
||||
if( ( pid = fork() ) == 0 ) { // child
|
||||
if ( execlp ( "dawn", "dawn", "-G" , (char *)0 ) < 0 )
|
||||
{
|
||||
perror("dawn") ;
|
||||
}
|
||||
} else { // parent
|
||||
|
||||
//----- Set waiting time to ensure connection
|
||||
int connection_time = FR_DEFAULT_CONNECTION_TIME ;
|
||||
if( getenv( FR_ENV_CONNECTION_TIME ) != NULL ) {
|
||||
int sscanf_status = \
|
||||
sscanf( getenv( FR_ENV_CONNECTION_TIME ), "%d", &connection_time) ;
|
||||
if ( sscanf_status == EOF ) {
|
||||
connection_time = FR_DEFAULT_CONNECTION_TIME ;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//----- Wait for starting up of FukuiRenderer
|
||||
sleep(connection_time);
|
||||
|
||||
//----- establish connection
|
||||
this->ConnectPort();
|
||||
}
|
||||
|
||||
if(!flag_connected) {
|
||||
G4cerr << "***** ERROR: Connection failed" << endl;
|
||||
}
|
||||
else {
|
||||
G4cerr << "***** GEANT4 is connected to FukuiRenderer DAWN ";
|
||||
G4cerr << "in the same host" << endl;
|
||||
}
|
||||
|
||||
} // G4FukuiRenderer::UseInetDomainAuto()
|
||||
|
||||
|
||||
//----- G4FukuiRenderer::UseInetDomain()
|
||||
void
|
||||
G4FukuiRenderer::UseInetDomain()
|
||||
{
|
||||
#if defined DEBUG_FR_SYSTEM
|
||||
G4cerr << "***** INET Domain " << endl;
|
||||
#endif
|
||||
fIPMode = G4FukuiRenderer::IP_INET ;
|
||||
|
||||
this->ConnectPort();
|
||||
|
||||
if(!flag_connected) {
|
||||
G4cerr << "***** ERROR: Connection failed" << endl;
|
||||
}
|
||||
else {
|
||||
G4cerr << "GEANT4 is connected to FukuiRenderer DAWN via socket" ;
|
||||
G4cerr << endl;
|
||||
}
|
||||
|
||||
} // G4FukuiRenderer::UseInetDomain()
|
||||
|
||||
void
|
||||
G4FukuiRenderer::ConnectPort( int max_port_incr )
|
||||
{
|
||||
//----- establish connection
|
||||
int connect_trial = 0 ;
|
||||
while(1) {
|
||||
if ( ++connect_trial > max_port_incr ) {
|
||||
this->flag_connected = 0 ;
|
||||
G4cerr << "***** INET Connection failed." << endl;
|
||||
G4cerr << " Maybe, you have not invoked DAWN yet," << endl;
|
||||
G4cerr << " or too many DAWN's are already running" << endl;
|
||||
G4cerr << " in the server host." << endl;
|
||||
fPrimDest.IncrementPortNumber( (- FR_MAX_PORT_INCR) );
|
||||
return ;
|
||||
} else if ( fPrimDest.ConnectINET() ) {
|
||||
// INET domain connection is established
|
||||
this->flag_connected = 1 ;
|
||||
G4cerr << "***** GEANT4 is connected to port " ;
|
||||
G4cerr << fPrimDest.GetPortNumber() ;
|
||||
G4cerr << " of server" << endl;
|
||||
break ;
|
||||
} else {
|
||||
// Connection failed. Try the next port.
|
||||
this->flag_connected = 0 ;
|
||||
fPrimDest.IncrementPortNumber();
|
||||
G4cerr << "***** GEANT4 incremented targeting port to " ;
|
||||
G4cerr << fPrimDest.GetPortNumber() << endl;
|
||||
|
||||
} // if-elseif-else
|
||||
|
||||
} // while (1)
|
||||
}
|
||||
|
||||
|
||||
//----- G4FukuiRenderer::UseBSDUnixDomainAuto()
|
||||
void G4FukuiRenderer::UseBSDUnixDomainAuto()
|
||||
{
|
||||
int pid ;
|
||||
|
||||
#if defined DEBUG_FR_SYSTEM
|
||||
G4cerr << "***** UseBSDUnixDomainAuto " << endl;
|
||||
#endif
|
||||
fIPMode = G4FukuiRenderer::IP_UNIX ; // Unix domain
|
||||
|
||||
if( ( pid = fork() ) == 0 ) { // child
|
||||
if ( execlp ( "dawn", "dawn", "-g" , (char *)0 ) < 0 )
|
||||
{
|
||||
perror("dawn") ;
|
||||
}
|
||||
} else { // parent
|
||||
|
||||
//----- Sleep for a while to make sure that
|
||||
//..... FukuiRenderer is ready
|
||||
int connection_time = FR_DEFAULT_CONNECTION_TIME ;
|
||||
if( getenv( FR_ENV_CONNECTION_TIME ) != NULL ) {
|
||||
int sscanf_status = \
|
||||
sscanf( getenv( FR_ENV_CONNECTION_TIME ), "%d", &connection_time) ;
|
||||
if ( sscanf_status == EOF ) { connection_time = FR_DEFAULT_CONNECTION_TIME ;}
|
||||
}
|
||||
sleep(connection_time);
|
||||
|
||||
//----- connect GEANT4 to FukuiRenderer
|
||||
this->flag_connected = fPrimDest.ConnectUnix();
|
||||
|
||||
//----- display status
|
||||
if(!flag_connected) {
|
||||
G4cerr << "***** ERROR: Connection failed" << endl;
|
||||
} else {
|
||||
G4cerr << "*** GEANT4 is connected to FukuiRenderer DAWN ";
|
||||
G4cerr << "in the same host" << endl;
|
||||
}
|
||||
|
||||
} // if--else
|
||||
|
||||
}// G4FukuiRenderer::UseBSDUnixDomainAuto()
|
||||
|
||||
|
||||
#endif // G4VIS_BUILD_DAWN_DRIVER
|
||||
@@ -0,0 +1,125 @@
|
||||
// This code implementation is the intellectual property of
|
||||
// the RD44 GEANT4 collaboration.
|
||||
//
|
||||
// By copying, distributing or modifying the Program (or any work
|
||||
// based on the Program) you indicate your acceptance of this statement,
|
||||
// and all its terms.
|
||||
//
|
||||
// $Id: G4FukuiRendererScene.cc,v 2.3 1998/11/06 13:41:47 allison Exp $
|
||||
// GEANT4 tag $Name: geant4-00 $
|
||||
//
|
||||
//
|
||||
// Satoshi TANAKA, Fri Jun 28 11:34:24 JST 1996
|
||||
// FukuiRenderer scene.
|
||||
|
||||
|
||||
//=================//
|
||||
#ifdef G4VIS_BUILD_DAWN_DRIVER
|
||||
//=================//
|
||||
|
||||
|
||||
#define __G_ANSI_C__
|
||||
|
||||
//#define DEBUG_FR_SCENE
|
||||
|
||||
//----- header files
|
||||
#include <fstream.h>
|
||||
//#include <strstream.h>
|
||||
#include <string.h>
|
||||
#include "globals.hh"
|
||||
#include "G4FRConst.hh"
|
||||
#include "G4FukuiRenderer.hh"
|
||||
#include "G4FukuiRendererScene.hh"
|
||||
#include "G4FukuiRendererView.hh"
|
||||
#include "G4Point3D.hh"
|
||||
#include "G4VisAttributes.hh"
|
||||
#include "G4Transform3D.hh"
|
||||
#include "G4Polyhedron.hh"
|
||||
#include "G4Box.hh"
|
||||
#include "G4Cons.hh"
|
||||
#include "G4Polyline.hh"
|
||||
#include "G4Trd.hh"
|
||||
#include "G4Tubs.hh"
|
||||
#include "G4Text.hh"
|
||||
#include "G4Circle.hh"
|
||||
#include "G4Square.hh"
|
||||
#include "G4ModelingParameters.hh"
|
||||
#include "G4VPhysicalVolume.hh"
|
||||
|
||||
//----- constants
|
||||
const char FR_ENV_CULL_INVISIBLE_OBJECTS [] = "G4DAWN_CULL_INVISIBLE_OBJECTS";
|
||||
|
||||
|
||||
///////////////////////////
|
||||
// Driver-dependent part //
|
||||
///////////////////////////
|
||||
|
||||
|
||||
//----- G4FukuiRendererScene, constructor
|
||||
G4FukuiRendererScene::G4FukuiRendererScene (G4FukuiRenderer& system,
|
||||
const G4String& name):
|
||||
fSystem (system) ,
|
||||
G4VScene (system, fSceneIdCount++, name) ,
|
||||
fPrimDest (system.GetPrimDest() ) ,
|
||||
flag_in_modeling (false) ,
|
||||
flag_saving_g4_prim (false) ,
|
||||
COMMAND_BUF_SIZE (G4FRClientServer::SEND_BUFMAX)
|
||||
{
|
||||
|
||||
//----- Connection to FukuiRenderer is set in the first scene
|
||||
if( !fSystem.IsConnected() )
|
||||
{
|
||||
if ( getenv( FR_ENV_NAMED_PIPE_CONNECTION ) != NULL &&\
|
||||
strcmp( getenv( FR_ENV_NAMED_PIPE_CONNECTION ), "0" ) )
|
||||
{
|
||||
// Invoke DAWN locally and make connection
|
||||
// via named pipe (not supported in AIX etc)
|
||||
fSystem.UseBSDUnixDomainAuto();
|
||||
} else if( getenv( FR_ENV_SERVER_HOST_NAME ) == NULL )
|
||||
{
|
||||
// Invoke DAWN locally and make connection
|
||||
// via socket
|
||||
fSystem.UseInetDomainAuto();
|
||||
} else {
|
||||
// Connect to remote DAWN via socket
|
||||
fSystem.UseInetDomain();
|
||||
}
|
||||
}
|
||||
|
||||
//----- count instantiated scenes
|
||||
fSceneCount++;
|
||||
|
||||
} // G4FukuiRendererScene, constructor
|
||||
|
||||
|
||||
//----- G4FukuiRendererScene, destructor
|
||||
G4FukuiRendererScene::~G4FukuiRendererScene ()
|
||||
{
|
||||
#if defined DEBUG_FR_SCENE
|
||||
G4cerr << "***** ~G4FukuiRendererScene" << endl;
|
||||
#endif
|
||||
fSceneCount--;
|
||||
ClearStore (); // clear current scene
|
||||
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////
|
||||
// Common to DAWN and DAWNFILE drivers //
|
||||
/////////////////////////////////////////
|
||||
|
||||
#define G4FRSCENE G4FukuiRendererScene
|
||||
#include "G4FRSceneFunc.icc"
|
||||
#undef G4FRSCENE
|
||||
|
||||
//////////////////////
|
||||
// static variables //
|
||||
//////////////////////
|
||||
|
||||
//----- static variables
|
||||
G4int G4FukuiRendererScene::fSceneIdCount = 0;
|
||||
|
||||
G4int G4FukuiRendererScene::fSceneCount = 0;
|
||||
// num of existing instances
|
||||
|
||||
#endif // G4VIS_BUILD_DAWN_DRIVER
|
||||
@@ -0,0 +1,359 @@
|
||||
// This code implementation is the intellectual property of
|
||||
// the RD44 GEANT4 collaboration.
|
||||
//
|
||||
// By copying, distributing or modifying the Program (or any work
|
||||
// based on the Program) you indicate your acceptance of this statement,
|
||||
// and all its terms.
|
||||
//
|
||||
// $Id: G4FukuiRendererView.cc,v 2.4 1998/11/06 13:41:48 allison Exp $
|
||||
// GEANT4 tag $Name: geant4-00 $
|
||||
//
|
||||
//
|
||||
// Satoshi TANAKA, Fri Jun 28 12:09:11 JST 1996
|
||||
// FukuiRenderer view - opens window, hard copy, etc.
|
||||
|
||||
|
||||
//=================//
|
||||
#ifdef G4VIS_BUILD_DAWN_DRIVER
|
||||
//=================//
|
||||
|
||||
#define __G_ANSI_C__
|
||||
#define G4FukuiRenderer_STRUCTURE_PRIORITY 1.
|
||||
|
||||
// #define DEBUG_FR_VIEW
|
||||
|
||||
#include "G4ios.hh"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "G4SceneData.hh"
|
||||
#include "G4Vector3D.hh"
|
||||
#include "G4VisExtent.hh"
|
||||
#include "G4LogicalVolume.hh"
|
||||
#include "G4VSolid.hh"
|
||||
|
||||
#include "G4FRConst.hh"
|
||||
#include "G4FukuiRenderer.hh"
|
||||
#include "G4FukuiRendererScene.hh"
|
||||
#include "G4FukuiRendererView.hh"
|
||||
|
||||
|
||||
//----- constants
|
||||
const char FR_ENV_MULTI_WINDOW[] = "G4DAWN_MULTI_WINDOW" ;
|
||||
|
||||
//----- G4FukuiRendererView, constructor
|
||||
G4FukuiRendererView::G4FukuiRendererView (G4FukuiRendererScene& scene,
|
||||
const G4String& name):
|
||||
G4VView (scene, scene.IncrementViewCount (), name), fScene (scene)
|
||||
{}
|
||||
|
||||
//----- G4FukuiRendererView, destructor
|
||||
G4FukuiRendererView::~G4FukuiRendererView ()
|
||||
{}
|
||||
|
||||
//----- G4FukuiRendererView::SetView ()
|
||||
void G4FukuiRendererView::SetView ()
|
||||
{
|
||||
#if defined DEBUG_FR_VIEW
|
||||
G4cerr << "***** G4FukuiRendererView::SetView()\n";
|
||||
#endif
|
||||
// Do nothing, since DAWN is running as a different process.
|
||||
// SendViewParameters () will do this job instead.
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//----- G4FukuiRendererView::ClearView()
|
||||
void
|
||||
G4FukuiRendererView::ClearView( void )
|
||||
{
|
||||
#if defined DEBUG_FR_VIEW
|
||||
G4cerr << "***** G4FukuiRendererView::ClearView () " << endl;
|
||||
#endif
|
||||
|
||||
//----- Begin saving data to g4.prim
|
||||
fScene.BeginSavingG4Prim();
|
||||
|
||||
//----- Clear old data
|
||||
fScene.SendStr( FR_CLEAR_DATA );
|
||||
|
||||
}
|
||||
|
||||
|
||||
//----- G4FukuiRendererView::DrawView ()
|
||||
void G4FukuiRendererView::DrawView ()
|
||||
{
|
||||
#if defined DEBUG_FR_VIEW
|
||||
G4cerr << "***** G4FukuiRendererView::DrawView () " << endl;
|
||||
#endif
|
||||
//----- Error recovery
|
||||
if( fScene.IsInModeling() ) {
|
||||
G4cerr << "WARNING from FukuiRenderer (DAWN) driver:" << endl;
|
||||
G4cerr << " You've invoked a drawing command before " << endl;
|
||||
G4cerr << " completing your previous visualization." << endl;
|
||||
// G4cerr << " You should have invoked command, /vis~/show/view," << endl;
|
||||
// G4cerr << " to complete it." << endl;
|
||||
|
||||
FlushView();
|
||||
}
|
||||
|
||||
//----- Begin Saving g4.prim file
|
||||
fScene.BeginSavingG4Prim();
|
||||
|
||||
//----- drawing device
|
||||
if( ( getenv( FR_ENV_MULTI_WINDOW ) != NULL ) && \
|
||||
( strcmp( getenv( FR_ENV_MULTI_WINDOW ),"0" ) ) )
|
||||
{
|
||||
SendDevice( FRDEV_XWIN ) ;
|
||||
} else {
|
||||
SendDevice( FRDEV_PS ) ;
|
||||
}
|
||||
|
||||
//----- drawing style
|
||||
SendDrawingStyle() ;
|
||||
|
||||
//----- set view if necessary
|
||||
SendViewParameters();
|
||||
// Camera data should be sent at every time, even if
|
||||
// the setting is unchanged at GEANT 4 side.
|
||||
|
||||
//----- Always visit G4 kernel
|
||||
NeedKernelVisit ();
|
||||
|
||||
//----- Draw
|
||||
ProcessView () ;
|
||||
|
||||
} // G4FukuiRendererView::DrawView ()
|
||||
|
||||
|
||||
|
||||
//----- G4FukuiRendererView::ShowView()
|
||||
void G4FukuiRendererView::ShowView( void )
|
||||
{
|
||||
#if defined DEBUG_FR_VIEW
|
||||
G4cerr << "***** G4FukuiRendererView::ShowView () " << endl;
|
||||
#endif
|
||||
|
||||
if( fScene.IsInModeling() ) // if( fScene.flag_in_modeling )
|
||||
{
|
||||
|
||||
//----- End of Data
|
||||
fScene.FREndModeling();
|
||||
|
||||
//----- Draw all
|
||||
fScene.SendStr( FR_DRAW_ALL );
|
||||
|
||||
//----- Close device
|
||||
fScene.SendStr( FR_CLOSE_DEVICE );
|
||||
|
||||
//----- End saving data to g4.prim
|
||||
fScene.EndSavingG4Prim() ;
|
||||
|
||||
//----- Wait user clicks drawing Area
|
||||
this->Wait();
|
||||
}
|
||||
|
||||
} // G4FukuiRendererView::ShowView()
|
||||
|
||||
|
||||
//----- G4FukuiRendererView::FlushView()
|
||||
void G4FukuiRendererView::FlushView( void )
|
||||
{
|
||||
#if defined DEBUG_FR_VIEW
|
||||
G4cerr << "***** G4FukuiRendererView::Flush () " << endl;
|
||||
#endif
|
||||
|
||||
if( fScene.IsInModeling() ) // if( fScene.flag_in_modeling )
|
||||
{
|
||||
|
||||
//----- End of Data
|
||||
fScene.FREndModeling();
|
||||
|
||||
//----- Draw all
|
||||
fScene.SendStr( FR_DRAW_ALL );
|
||||
|
||||
//----- Close device
|
||||
fScene.SendStr( FR_CLOSE_DEVICE );
|
||||
|
||||
//----- End saving data to g4.prim
|
||||
fScene.EndSavingG4Prim() ;
|
||||
|
||||
}
|
||||
|
||||
} // G4FukuiRendererView::FlushView()
|
||||
|
||||
|
||||
|
||||
//----- G4FukuiRendererView::Wait()
|
||||
void
|
||||
G4FukuiRendererView::Wait()
|
||||
{
|
||||
#if defined DEBUG_FR_VIEW
|
||||
G4cerr << "***** G4FukuiRendererView::Wait () " << endl;
|
||||
#endif
|
||||
fScene.SendStr ( FR_WAIT );
|
||||
fScene.GetPrimDest().WaitSendBack( FR_WAIT );
|
||||
#if defined DEBUG_FR_VIEW
|
||||
G4cerr << "***** G4FukuiRendererView::Wait () : end" << endl;
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
|
||||
//----- G4FukuiRendererView::SendDevice()
|
||||
void
|
||||
G4FukuiRendererView::SendDevice( FRDEV dev )
|
||||
{
|
||||
#if defined DEBUG_FR_VIEW
|
||||
G4cerr << "***** G4FukuiRendererView::SendDevice() " << endl;
|
||||
#endif
|
||||
|
||||
|
||||
// enum {PS=1, XWIN=2, PS2=3, XWIN2=4, OPEN_GL=5, DEVICE_END=6};
|
||||
|
||||
if( dev >= FRDEV_PS || dev < FRDEV_DEVICE_END ) {
|
||||
fScene.SendStrInt ( FR_DEVICE, dev );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//----- G4FukuiRendererView::SendDrawingStyle()
|
||||
void G4FukuiRendererView::SendDrawingStyle()
|
||||
{
|
||||
#if defined DEBUG_FR_VIEW
|
||||
G4cerr << "***** G4FukuiRendererView::SendDrawingStyle() " << endl;
|
||||
#endif
|
||||
|
||||
G4int style = fVP.GetDrawingStyle();
|
||||
|
||||
switch( style )
|
||||
{
|
||||
case G4ViewParameters::wireframe:
|
||||
fScene.SendStr( FR_WIREFRAME );
|
||||
break;
|
||||
case G4ViewParameters::hlr:
|
||||
fScene.SendStr( FR_LINES );
|
||||
break;
|
||||
case G4ViewParameters::hsr:
|
||||
case G4ViewParameters::hlhsr:
|
||||
fScene.SendStr( FR_SURFACE );
|
||||
break;
|
||||
default:
|
||||
fScene.SendStr( FR_WIREFRAME );
|
||||
break;
|
||||
}
|
||||
|
||||
} // G4FukuiRendererView::SendDrawingStyle()
|
||||
|
||||
|
||||
|
||||
//----- G4FukuiRendererView::SendViewParameters ()
|
||||
void G4FukuiRendererView::SendViewParameters ()
|
||||
{
|
||||
// Calculates view representation based on extent of object being
|
||||
// viewed and (initial) direction of camera. (Note: it can change
|
||||
// later due to user interaction via visualization system's GUI.)
|
||||
|
||||
#if defined DEBUG_FR_VIEW
|
||||
G4cerr << "***** G4FukuiRendererView::SendViewParameters()\n";
|
||||
#endif
|
||||
|
||||
//----- Magic number to decide camera distance automatically
|
||||
const G4double HOW_FAR = 1000.0 ; // to define "infinity"
|
||||
const G4double MIN_HALF_ANGLE = 0.01 ;
|
||||
const G4double MAX_HALF_ANGLE = 0.499 * M_PI ;
|
||||
|
||||
//----- Send Bounding Box
|
||||
fScene.SendBoundingBox();
|
||||
|
||||
//----- (2A) CALC camera distance
|
||||
//..... Note: Camera cannot enter inside object
|
||||
G4double camera_distance ;
|
||||
G4double radius = fScene.GetSceneData().GetExtent().GetExtentRadius();
|
||||
|
||||
G4double half_view_angle = fabs ( fVP.GetFieldHalfAngle () ) ;
|
||||
if( half_view_angle > MAX_HALF_ANGLE ) {
|
||||
half_view_angle = MAX_HALF_ANGLE ;
|
||||
}
|
||||
|
||||
if( half_view_angle < MIN_HALF_ANGLE ) {
|
||||
//----- infinity (or ortho projection)
|
||||
camera_distance = radius * HOW_FAR ;
|
||||
} else {
|
||||
//----- Calc camera distance from half view angle
|
||||
camera_distance = radius / sin ( half_view_angle );
|
||||
camera_distance -= fVP.GetDolly();
|
||||
}
|
||||
|
||||
if ( camera_distance < radius ) {
|
||||
G4cerr << "WARNING from FukuiRenderer (DAWN) driver:" << endl;
|
||||
G4cerr << " Camera cannot enter inside objects" << endl;
|
||||
camera_distance = radius ;
|
||||
}
|
||||
|
||||
//----- (3A) CALC camera direction
|
||||
const G4Vector3D& camera_direction \
|
||||
= fVP.GetViewpointDirection().unit();
|
||||
const G4double v_angle = (180.0 / M_PI) * camera_direction.theta() ;
|
||||
const G4double h_angle = (180.0 / M_PI) * camera_direction.phi () ;
|
||||
|
||||
//----- (2B), (3B) SEND camera position
|
||||
fScene.SendStrDouble3( FR_CAMERA_POSITION,
|
||||
camera_distance,
|
||||
v_angle,
|
||||
h_angle );
|
||||
|
||||
//----- (4A) CALC target point
|
||||
const G4Point3D& target_point = fVP.GetCurrentTargetPoint();
|
||||
|
||||
//----- (4B) SEND target point
|
||||
fScene.SendStrDouble3( FR_TARGET_POINT,
|
||||
target_point.x(),
|
||||
target_point.y(),
|
||||
target_point.z() );
|
||||
|
||||
//----- (5A) CALC zoom factor
|
||||
const G4double zoom_factor = fVP.GetZoomFactor();
|
||||
|
||||
//----- (5B) SEND zoom factor or focal length
|
||||
if( half_view_angle < MIN_HALF_ANGLE ) {
|
||||
|
||||
const G4Point3D& std_target_point \
|
||||
= fScene.GetSceneData().GetStandardTargetPoint();
|
||||
|
||||
fScene.SendStrDouble4( FR_ZOOM_FACTOR,
|
||||
zoom_factor ,
|
||||
std_target_point.x(),
|
||||
std_target_point.y(),
|
||||
std_target_point.z());
|
||||
// Note that target point, camera position,
|
||||
// and bounding box have already been sent above.
|
||||
// The std_target_point is necessary to
|
||||
// Calc focal distance from the zoom factor.
|
||||
} else {
|
||||
const G4double FR_HALF_SCREEN_SIZE = 0.5 ;
|
||||
G4double focal_distance \
|
||||
= FR_HALF_SCREEN_SIZE / tan( half_view_angle );
|
||||
focal_distance *= zoom_factor ;
|
||||
fScene.SendStrDouble ( FR_FOCAL_DISTANCE, focal_distance );
|
||||
}
|
||||
|
||||
//----- INVOKE GUI: not executed in the default setting
|
||||
if( fScene.GetSystem().IsGUIMode() ) {
|
||||
//----- send GUI command
|
||||
fScene.SendStr( FR_GUI );
|
||||
|
||||
//----- wait the same command is sent back:
|
||||
//..... This avoids to send many data before
|
||||
//..... GUI session is over.
|
||||
fScene.GetPrimDest().WaitSendBack( FR_GUI );
|
||||
}
|
||||
|
||||
//----- SET CAMERA
|
||||
fScene.SendStr( FR_SET_CAMERA );
|
||||
|
||||
} // G4FukuiRendererView::SendViewParameters ()
|
||||
|
||||
#endif // G4VIS_BUILD_DAWN_DRIVER
|
||||
Reference in New Issue
Block a user