Import Geant4 0.0.0 source tree

This commit is contained in:
Gabriele Cosmo
2016-06-01 15:25:35 +02:00
parent 54d6b71f95
commit b97f8d0df7
3237 changed files with 807095 additions and 0 deletions
+131
View File
@@ -0,0 +1,131 @@
// 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: FRClient.cc,v 2.2 1998/07/13 17:12:04 urbi Exp $
// GEANT4 tag $Name: geant4-00 $
//
// FRClient.cc
// FukuiRenderer Client
// Yasuhide Sawada & Satoshi Tanaka
//=================//
#ifdef G4VIS_BUILD_VRML_DRIVER
//=================//
#include "G4ios.hh"
#include <sys/time.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <stdio.h>
#include "FRClient.h"
FRClient::FRClient()
{
fd = -1;
create();
}
FRClient::~FRClient()
{
close();
}
int FRClient::create()
{
/* stream socket */
fd = socket(AF_INET, SOCK_STREAM, 0);
if (fd < 0)
fputs("error: socket.\n", stderr);
return fd;
}
int FRClient::connect(const char *hostname, int port_)
{
// local variables
struct sockaddr_in sa;
struct hostent *hp;
// set port ( sa.sin_family, sa.sin_port )
port = port_; // Store port number to data member
memset( (char *)&sa, '\0', sizeof(sa)) ;
sa.sin_family = AF_INET;
sa.sin_port = htons(port);
// set server host ( sa.sin_addr )
if (hostname == NULL) {
hostname = "localhost";
// reset arg
}
hp = gethostbyname(hostname) ;
if ( !hp ) {
G4cerr << "ERROR: gethostbyname() failed" << endl;
return -1;
}
memcpy( (char * )&sa.sin_addr, (char * )hp->h_addr, hp->h_length );
// make connection to server
if (::connect(fd, (struct sockaddr *)&sa, sizeof(sa)) == -1) {
fputs("error: connect\n", stderr);
return -1;
}
// return file descripter (data member)
return fd;
}
int FRClient::send(const char *sendbuf)
{
int len = strlen(sendbuf);
if (::send(fd, sendbuf, len, 0) < 0) {
fputs("error: Send()\n", stderr);
len = -1;
}
return len;
}
int FRClient::receive(char *recvbuf)
{
int len;
memset(recvbuf, '\0', FRSendLength + 1);
len = ::recv(fd, recvbuf, FRSendLength, 0);
if(len < 0) {
fputs("error: Receive()\n", stderr);
len = -1;
}
return len;
}
int FRClient::close()
{
/*
shutdown :argument '2' means shutdown both send and receive.
*/
if (::shutdown(fd, 2) < 0) {
fputs("error: shutdown\n", stderr);
return -1;
}
::close(fd);
return 0;
}
#endif
@@ -0,0 +1,95 @@
// 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: G4FRClient.cc,v 2.0 1998/07/02 16:48:06 gunter Exp $
// GEANT4 tag $Name: geant4-00 $
//
// G4FRClient.cc
// Yasuhide Sawada & Satoshi Tanaka
//=================//
#ifdef G4VIS_BUILD_VRML_DRIVER
//=================//
#include <stdio.h>
#include "G4FRClient.hh"
#include "FRClient.h"
G4FRClient::G4FRClient()
{
fFRClient = NULL;
fPort = -1;
connected = false;
}
G4FRClient::~G4FRClient()
{
if (connected)
this->close();
}
G4bool G4FRClient::connect(const char *hostname, G4int port)
{
if (connected)
return false;
delete fFRClient;
fFRClient = new FRClient();
fPort = port;
connected = (fFRClient->connect(hostname, port) < 0) ? false : true ;
return connected;
}
void G4FRClient::close()
{
delete fFRClient;
fFRClient = NULL;
connected = false;
}
G4int G4FRClient::getPort() const
{
return fPort;
}
G4FRClient& G4FRClient::operator << (G4int val)
{
char buf[64];
sprintf(buf, "%d", val);
fFRClient->send(buf);
return *this;
}
G4FRClient& G4FRClient::operator << (G4double val)
{
char buf[64];
sprintf(buf, "%g", val);
fFRClient->send(buf);
return *this;
}
G4FRClient& G4FRClient::operator << (const char *pval)
{
fFRClient->send(pval);
return *this;
}
G4FRClient& G4FRClient::operator << (G4FRClient& (*func)(G4FRClient&))
{
return func(*this);
}
//manipulator
G4FRClient& endl(G4FRClient& c)
{
return c << "\n";
}
#endif
+76
View File
@@ -0,0 +1,76 @@
// 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: G4VRML1.cc,v 2.4 1998/11/09 19:33:17 allison Exp $
// GEANT4 tag $Name: geant4-00 $
//
// G4VRML1.cc
// Yasuhide Sawada & Satoshi Tanaka
//=================//
#ifdef G4VIS_BUILD_VRML_DRIVER
//=================//
#include <stdio.h> // sscanf
#include <stdlib.h> // getenv
#include "G4VScene.hh"
#include "G4VRML1.hh"
#include "G4VRML1Scene.hh"
#include "G4VRML1View.hh"
#include "G4FRClient.hh"
G4VRML1::G4VRML1() :
G4VGraphicsSystem("VRML1", "VRML1", G4VGraphicsSystem::threeD)
{
// port number
fPort = FR_VRML_DEFAULT_PORT;
char *pport = getenv(FR_VRML_PORT_ENV);
if (pport) {
sscanf(pport, "%d", &fPort);
}
// host name
fHostName = "localhost" ; // G4String::operator = ( const char* cs )
char *phostname = getenv(FR_VRML_HOST_NAME_ENV);
if (phostname) {
fHostName = phostname;
}
}
G4VRML1::~G4VRML1()
{
}
G4VScene* G4VRML1::CreateScene(const G4String& name)
{
G4VScene *p = NULL;
p = new G4VRML1Scene(*this, name);
G4cout << G4VRML1Scene::GetSceneCount()
<< " " << fName << " scenes extanct." << endl;
return p;
}
G4VView* G4VRML1::CreateView(G4VScene& scene, const G4String& name)
{
G4VView* pView = NULL;
G4VRML1Scene* pScene = (G4VRML1Scene*)&scene;
pView = new G4VRML1View(*pScene, name);
return pView;
}
#endif
@@ -0,0 +1,63 @@
// 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: G4VRML1File.cc,v 2.4 1998/11/09 19:33:18 allison Exp $
// GEANT4 tag $Name: geant4-00 $
//
// G4VRML1File.cc
// Satoshi Tanaka & Yasuhide Sawada
//=================//
#ifdef G4VIS_BUILD_VRMLFILE_DRIVER
//=================//
#include <stdio.h> // sscanf
#include <stdlib.h> // getenv
#include "G4VScene.hh"
#include "G4VRML1File.hh"
#include "G4VRML1FileScene.hh"
#include "G4VRML1FileView.hh"
#include "G4FRClient.hh"
G4VRML1File::G4VRML1File() :
G4VGraphicsSystem("VRML1FILE", "VRML1FILE", G4VGraphicsSystem::threeD)
{
}
G4VRML1File::~G4VRML1File()
{
}
G4VScene* G4VRML1File::CreateScene(const G4String& name)
{
G4VScene *p = NULL;
p = new G4VRML1FileScene(*this, name);
G4cout << G4VRML1FileScene::GetSceneCount()
<< " " << fName << " scenes extanct." << endl;
return p;
}
G4VView* G4VRML1File::CreateView(G4VScene& scene, const G4String& name)
{
G4VView* pView = NULL;
G4VRML1FileScene* pScene = (G4VRML1FileScene*)&scene;
pView = new G4VRML1FileView(*pScene, name);
return pView;
}
#endif
@@ -0,0 +1,189 @@
// 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: G4VRML1FileScene.cc,v 2.7 1998/12/07 06:40:18 stanaka Exp $
// GEANT4 tag $Name: geant4-00 $
//
// G4VRML1FileScene.cc
// Satoshi Tanaka & Yasuhide Sawada
//=================//
#ifdef G4VIS_BUILD_VRMLFILE_DRIVER
//=================//
//#define DEBUG_FR_SCENE
#include <fstream.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "globals.hh"
#include "G4VPhysicalVolume.hh"
#include "G4LogicalVolume.hh"
#include "G4Point3D.hh"
#include "G4VisAttributes.hh"
#include "G4Transform.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 "G4VRML1FileScene.hh"
#include "G4VRML1FileView.hh"
#include "G4VRML1File.hh"
// CONST
const char WRL_FILE_HEADER [] = "g4_";
const char DEFAULT_WRL_FILE_NAME[] = "g4.wrl";
const char ENV_VRML_VIEWER [] = "G4VRMLFILE_VIEWER";
const char NO_VRML_VIEWER [] = "NONE";
const char VRMLFILE_DEST_DIR [] = "G4VRMLFILE_DEST_DIR";
G4VRML1FileScene::G4VRML1FileScene(G4VRML1File& system, const G4String& name) :
G4VScene(system, fSceneIdCount++, name),
fSystem(system),
fDest() ,
fFlagDestOpen( false )
{
fSceneCount++;
fCurrentDEF = "";
strcpy(fVRMLFileName, "");
if ( getenv( VRMLFILE_DEST_DIR ) == NULL ) {
strcpy( fVRMLFileDestDir, "" );
} else {
strcpy( fVRMLFileDestDir, getenv( VRMLFILE_DEST_DIR ) );
}
// maximum number of g4.prim files in the dest directory
fMaxFileNum = 1 ; // initialization
if ( getenv( "G4VRMLFILE_MAX_FILE_NUM" ) != NULL ) {
sscanf( getenv("G4VRMLFILE_MAX_FILE_NUM"), "%d", &fMaxFileNum ) ;
} else {
fMaxFileNum = 1 ;
}
if( fMaxFileNum < 1 ) { fMaxFileNum = 1 ; }
}
G4VRML1FileScene::~G4VRML1FileScene()
{
#if defined DEBUG_FR_SCENE
G4cerr << "***** ~G4VRML1FileScene" << endl;
#endif
fSceneCount--;
}
#define G4VRML1SCENE G4VRML1FileScene
#define IS_CONNECTED this->isConnected()
#include "G4VRML1SceneFunc.icc"
#undef IS_CONNECTED
#undef G4VRML1SCENE
void G4VRML1FileScene::connectPort()
{
// g4.wrl, g4_1.wrl, ..., g4_MAX_FILE_INDEX.wrl
const int MAX_FILE_INDEX = fMaxFileNum - 1 ;
// dest directory (null if no environmental variables is set)
strcpy ( fVRMLFileName, fVRMLFileDestDir) ;
// create full path name (default)
strcat ( fVRMLFileName, DEFAULT_WRL_FILE_NAME );
// Determine VRML file name
for( int i = 0 ; i < fMaxFileNum ; i++) {
// Message
if( fMaxFileNum > 1 && i == MAX_FILE_INDEX ) {
G4cerr << "===========================================" << endl;
G4cerr << "WARNING MESSAGE from VRML1FILE 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 G4VRMLFILE_DEST_DIR/g4_i.wrl for i>0
if( i > 0 ) {
sprintf( fVRMLFileName, "%s%s%d.wrl" , fVRMLFileDestDir, WRL_FILE_HEADER, i );
}
// check validity of the file name
ifstream fin ;
fin.open(fVRMLFileName) ;
if(!fin) {
// new file
fin.close(); // error recovery
break;
} else {
// already exists (try next)
fin.close();
}
} // for
// open a VRML 1.0 file with determined file name
G4cerr << "===========================================" << endl;
G4cerr << "Output VRML 1.0 file: " << fVRMLFileName << endl;
G4cerr << "Muximal number of file in the destination directory: " << fMaxFileNum << endl;
G4cerr << " (Customizable as: setenv G4VRMLFILE_MAX_FILE_NUM number) " << endl;
G4cerr << "===========================================" << endl;
fDest.open(fVRMLFileName) ; fFlagDestOpen = true ;
}
void G4VRML1FileScene::closePort()
{
char command[256] ;
char viewer [256] ;
strcpy( viewer, NO_VRML_VIEWER ); // initialization
if( getenv( ENV_VRML_VIEWER ) ) {
strcpy( viewer, getenv( ENV_VRML_VIEWER ) ) ;
}
// close VRML file
fDest.close(); fFlagDestOpen = false ;
G4cerr << "*** VRML 1.0 File " << fVRMLFileName << " is generated." << endl;
// Invoke viewer
if ( !strcmp(viewer, NO_VRML_VIEWER )) {
G4cerr << "MESSAGE from VRML1FILE driver:" << endl;
G4cerr << " Set an environmental variable " ;
G4cerr << ENV_VRML_VIEWER << endl;
G4cerr << " if you want to visualize the generated VRML file" << endl;
G4cerr << " automatically. For example, " << endl;
G4cerr << " setenv " << ENV_VRML_VIEWER << " vrweb " << endl;
} else {
sprintf( command, "%s %s", viewer, fVRMLFileName );
system( command );
}
}
G4int G4VRML1FileScene::fSceneIdCount = 0;
G4int G4VRML1FileScene::fSceneCount = 0;
#endif
@@ -0,0 +1,78 @@
// 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: G4VRML1FileView.cc,v 2.4 1998/11/09 19:33:22 allison Exp $
// GEANT4 tag $Name: geant4-00 $
//
// G4VRMLView.cc
// Satoshi Tanaka & Yasuhide Sawada
//=================//
#ifdef G4VIS_BUILD_VRMLFILE_DRIVER
//=================//
//#define DEBUG_FR_VIEW
#include "G4SceneData.hh"
#include "G4VRML1FileView.hh"
#include "G4VRML1FileScene.hh"
#include "G4VRML1File.hh"
#include "G4ios.hh"
G4VRML1FileView::G4VRML1FileView(G4VRML1FileScene& scene,
const G4String& name) :
G4VView(scene, scene.IncrementViewCount(), name), fScene(scene)
{}
G4VRML1FileView::~G4VRML1FileView()
{}
void G4VRML1FileView::SetView()
{
#if defined DEBUG_FR_VIEW
G4cerr << "***** G4VRML1FileView::SetView()" << endl;
G4cerr << "G4VRML1FileView::SetView(); not imlemented. " << endl;
#endif
}
void G4VRML1FileView::DrawView()
{
#if defined DEBUG_FR_VIEW
G4cerr << "***** G4VRML1FileView::DrawView()" << endl;
#endif
// Here is a minimal DrawView() function.
NeedKernelVisit();
ProcessView();
FinishView();
}
void G4VRML1FileView::ClearView(void)
{
#if defined DEBUG_FR_VIEW
G4cerr << "***** G4VRML1File1View::ClearView()" << endl;
G4cerr << "G4VRML1FileView::ClearView(); not implemented. " << endl;
#endif
}
void G4VRML1FileView::ShowView(void)
{
#if defined DEBUG_FR_VIEW
G4cerr << "***** G4VRML1FileView::ShowView()" << endl;
#endif
fScene.endSending();
}
void G4VRML1FileView::FinishView(void)
{
#if defined DEBUG_FR_VIEW
G4cerr << "***** G4VRML1FileView::FinishView()" << endl;
#endif
}
#endif
@@ -0,0 +1,112 @@
// 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: G4VRML1Scene.cc,v 2.4 1998/11/09 19:33:24 allison Exp $
// GEANT4 tag $Name: geant4-00 $
//
// G4VRML1Scene.cc
// Yasuhide Sawada and Satoshi Tanaka
//=================//
#ifdef G4VIS_BUILD_VRML_DRIVER
//=================//
//#define DEBUG_FR_SCENE
#include <unistd.h>
#include <fstream.h>
#include "globals.hh"
#include "G4VPhysicalVolume.hh"
#include "G4LogicalVolume.hh"
#include "G4Point3D.hh"
#include "G4VisAttributes.hh"
#include "G4Transform.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 "G4VRML1Scene.hh"
#include "G4VRML1View.hh"
#include "G4VRML1.hh"
G4VRML1Scene::G4VRML1Scene(G4VRML1& system, const G4String& name) :
G4VScene(system, fSceneIdCount++, name),
fSystem(system),
fDest()
{
fSceneCount++;
fCurrentDEF = "";
}
G4VRML1Scene::~G4VRML1Scene()
{
#if defined DEBUG_FR_SCENE
G4cerr << "***** ~G4VRML1Scene" << endl;
#endif
fSceneCount--;
}
#define G4VRML1SCENE G4VRML1Scene
#define IS_CONNECTED fDest.isConnected()
#include "G4VRML1SceneFunc.icc"
#undef IS_CONNECTED
#undef G4VRML1SCENE
void G4VRML1Scene::connectPort(G4int max_trial)
{
G4int trial = 0 ;
int port = fSystem.getPort();
for (trial = 0; !fDest.isConnected()&& trial < max_trial; trial++, port++ ) {
if (fDest.connect( (const char * )fSystem.getHostName(), port)) {
// INET domain connection is established
G4cerr << "*** GEANT4 is connected to port ";
G4cerr << fDest.getPort();
G4cerr << " of server " << fSystem.getHostName() << endl;
break;
} else {
// Connection failed. Try the next port.
G4cerr << "*** GEANT4 incremented targeting port to ";
G4cerr << port << endl;
}
sleep (1);
} // for
if (!fDest.isConnected()) {
G4cerr << "*** INET Connection failed. " << endl;
G4cerr << " Maybe, you have not invoked viewer g4vrmlview yet, " << endl;
G4cerr << " or too many viewers are already running in the " << endl;
G4cerr << " server host(" << fSystem.getHostName() << "). " << endl;
}
}
void G4VRML1Scene::closePort()
{
fDest.close();
G4cerr << "*** INET Connection closed. " << endl;
}
G4int G4VRML1Scene::fSceneIdCount = 0;
G4int G4VRML1Scene::fSceneCount = 0;
#endif
@@ -0,0 +1,619 @@
// 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: G4VRML1SceneFunc.icc,v 2.3 1998/11/09 03:09:45 stanaka Exp $
// GEANT4 tag $Name: geant4-00 $
//
// G4VRML1SceneFunc.icc
// Satoshi Tanaka & Yasuhide Sawada
//#define DEBUG_SCENE_FUNC
// MACRO
#define ADDTHIS_WITH_NAME(Solid) \
fCurrentDEF = #Solid "_" + Solid.GetName(); \
RequestPrimitives(Solid); \
fCurrentDEF = "";
// End of MACRO
void G4VRML1SCENE::AddThis(const G4Trd& trd)
{
#if defined DEBUG_SCENE_FUNC
G4cerr << "***** AddThis trd\n";
#endif
ADDTHIS_WITH_NAME(trd)
}
void G4VRML1SCENE::AddThis(const G4Trap& trap)
{
#if defined DEBUG_SCENE_FUNC
G4cerr << "***** AddThis trap\n";
#endif
ADDTHIS_WITH_NAME(trap)
}
void G4VRML1SCENE::AddThis(const G4Para& para)
{
#if defined DEBUG_SCENE_FUNC
G4cerr << "***** AddThis para\n";
#endif
ADDTHIS_WITH_NAME(para)
}
void G4VRML1SCENE::AddThis(const G4Torus& torus )
{
#if defined DEBUG_SCENE_FUNC
G4cerr << "***** AddThis torus\n";
#endif
ADDTHIS_WITH_NAME(torus)
}
void G4VRML1SCENE::AddThis(const G4VSolid& vsolid)
{
#if defined DEBUG_SCENE_FUNC
G4cerr << "***** AddThis vsolid\n";
#endif
ADDTHIS_WITH_NAME(vsolid)
}
void G4VRML1SCENE::AddThis(const G4Tubs& tubs)
{
#if defined DEBUG_SCENE_FUNC
G4cerr << "***** AddThis tubs\n";
#endif
// set current name
fCurrentDEF = "tubs_" + tubs.GetName();
// Get data
const G4double R = tubs.GetRMax(); // outside radius
const G4double r = tubs.GetRMin(); // inside radius
const G4double dz = tubs.GetDz(); // half length in z
const G4double dp = tubs.GetDPhi(); // angle interval
// Send data
if ( r == 0.0 && dp >= 360. * deg ) {
// Send a built-in VRML node (Cylinder)
fDest << "Separator {" << endl;
SendMatrixTransformNode( fpObjectTransformation );
fDest << "\t" << "DEF " << fCurrentDEF << " Separator {" << endl;
SendMaterialNode();
SendCylinderNode(R, dz * 2);
fDest << "\t" << "}" << endl; // DEF Separator
fDest << "}" << endl; // Separator
} else {
// call AddPrimitives(Polyhedron)
RequestPrimitives(tubs);
}
// reset current name to null
fCurrentDEF = "";
}
void G4VRML1SCENE::AddThis(const G4Cons& cons)
{
#if defined DEBUG_SCENE_FUNC
G4cerr << "***** AddThis cons\n";
#endif
// set current name
fCurrentDEF = "cons_" + cons.GetName();
// Get data
const G4double r1 = cons.GetRmin1(); // inside radius at -dz
const G4double R1 = cons.GetRmax1(); // outside radius at -dz
const G4double r2 = cons.GetRmin2(); // inside radius at +dz
const G4double R2 = cons.GetRmax2(); // outside radius at +dz
const G4double dz = cons.GetDz(); // half length in z
//const G4double sp = cons.GetSPhi(); // starting angle
const G4double dp = cons.GetDPhi(); // angle width
// Send data
if ( r1 == 0.0 && r2 == 0.0 && R1 == R2 && dp >= 360. * deg) {
// Send a built-in VRML node (Cylinder)
fDest << "Separator {" << endl;
SendMatrixTransformNode( fpObjectTransformation );
fDest << "\t" << "DEF " << fCurrentDEF << " Separator {" << endl;
SendMaterialNode();
SendCylinderNode(R1, dz * 2);
fDest << "\t" << "}" << endl; // DEF Separator
fDest << "}" << endl; // Separator
} else {
// call AddPrimitives(Polyhedron)
RequestPrimitives(cons);
}
// reset current name to null
fCurrentDEF = "";
}
void G4VRML1SCENE::AddThis(const G4Box& box)
{
#if defined DEBUG_SCENE_FUNC
G4cerr << "***** AddThis box\n";
#endif
// set current name
fCurrentDEF = "box_" + box.GetName();
// Send a built-in VRML node (Cube)
fDest << "Separator {" << endl;
//fDest << "\t" << "renderCulling ON" << endl;
SendMatrixTransformNode( fpObjectTransformation );
fDest << "\t" << "DEF " << fCurrentDEF << " Separator {" << endl;
SendMaterialNode();
SendCubeNode(box.GetXHalfLength() * 2, box.GetYHalfLength() * 2, box.GetZHalfLength() * 2);
fDest << "\t" << "}" << endl; // DEF Separator
fDest << "}" << endl; // Separator
// reset current name to null
fCurrentDEF = "";
}
void G4VRML1SCENE::AddThis(const G4Sphere& sphere)
{
#if defined DEBUG_SCENE_FUNC
G4cerr << "***** AddThis sphere\n";
#endif
// set current name
fCurrentDEF = "sphere_" + sphere.GetName();
// Get data
G4double dphi = sphere.GetDPhi () ;
G4double dtheta = sphere.GetDTheta() ;
G4double rmax = sphere.GetRmax () ;
G4double rmin = sphere.GetRmin () ;
// Send data
if ( (dphi >= 360. * deg) && (dtheta >= 180. * deg) && (rmin == 0.0) ) {
// Send a built-in VRML node (Sphere)
fDest << "Separator {" << endl;
SendMatrixTransformNode( fpObjectTransformation );
fDest << "\t" << "DEF " << fCurrentDEF << " Separator {" << endl;
SendMaterialNode();
SendSphereNode( rmax );
fDest << "\t" << "}" << endl; // DEF Separator
fDest << "}" << endl; // Separator
} else {
// call AddPrimitives(Polyhedron)
RequestPrimitives( sphere );
}
// reset current name to null
fCurrentDEF = "";
}
void G4VRML1SCENE::AddPrimitive(const G4Polyline& polyline)
{
#if defined DEBUG_SCENE_FUNC
G4cerr << "***** AddPrimitive polyline\n";
#endif
fDest << "Separator {" << endl;
SendMatrixTransformNode (fpObjectTransformation );
SendMaterialNode( polyline.GetVisAttributes() );
fDest << "\t" << "Coordinate3 {" << endl;
fDest << "\t\t" << "point [" << endl;
G4int e, i;
for (i = 0, e = polyline.entries(); e; i++, e--) {
fDest << "\t\t\t";
fDest << polyline(i).x() << " ";
fDest << polyline(i).y() << " ";
fDest << polyline(i).z() << "," << endl;
}
fDest << "\t\t" << "]" << endl;
fDest << "\t" << "}" << endl; // Coordinate3
fDest << "\t" << "IndexedLineSet {" << endl;
fDest << "\t\t" << "coordIndex [";
for (i = 0, e = polyline.entries(); e; i++, e--) {
if (i % 10 == 0)
fDest << endl << "\t\t\t";
fDest << i << ", ";
}
fDest << "-1" << endl;
fDest << "\t\t" << "]" << endl;
fDest << "\t" << "}" << endl; // IndexedLineSet
fDest << "}" << endl; // Separator
}
void G4VRML1SCENE::AddPrimitive(const G4Polyhedron& polyhedron)
{
#if defined DEBUG_SCENE_FUNC
G4cerr << "***** AddPrimitive(G4Polyhedron)" << endl;
#endif
fDest << "Separator {" << endl;
SendMatrixTransformNode( fpObjectTransformation );
fDest << "\t";
if (fCurrentDEF != "")
fDest << "DEF " << fCurrentDEF << " ";
fDest << "Separator {" << endl;
//fDest << "\t\t" << "renderCulling ON" << endl;
fDest << "\t\t" << "ShapeHints {" << endl;
fDest << "\t\t\t" << "vertexOrdering COUNTERCLOCKWISE" << endl;
fDest << "\t\t\t" << "shapeType SOLID" << endl;
fDest << "\t\t\t" << "faceType CONVEX" << endl;
fDest << "\t\t" << "}" << endl;
SendMaterialNode();
fDest << "\t\t" << "Coordinate3 {" << endl;
fDest << "\t\t\t" << "point [" << endl;
G4int i, j;
for (i = 1, j = polyhedron.GetNoVertices(); j; j--, i++) {
G4Point3D point = polyhedron.GetVertex(i);
fDest << "\t\t\t\t";
fDest << point.x() << " ";
fDest << point.y() << " ";
fDest << point.z() << "," << endl;
}
fDest << "\t\t\t" << "]" << endl;
fDest << "\t\t" << "}" << endl; // Coordinate3
fDest << "\t\t" << "IndexedFaceSet {" << endl;
fDest << "\t\t\t" << "coordIndex [" << endl;
// facet loop
G4int f;
for (f = polyhedron.GetNoFacets(); f; f--) {
// edge loop
G4bool notLastEdge;
G4int index = -1, edgeFlag = 1;
fDest << "\t\t\t\t";
do {
notLastEdge = polyhedron.GetNextVertexIndex(index, edgeFlag);
fDest << index - 1 << ", ";
} while (notLastEdge);
fDest << "-1," << endl;
}
fDest << "\t\t\t" << "]" << endl;
fDest << "\t\t" << "}" << endl; // IndexFaceSet
fDest << "\t" << "}" << endl; // (DEF) Separator
fDest << "}" << endl; // Separator
#if defined DEBUG_SCENE_FUNC
G4cerr << "***** end of AddPrimitive(G4Polyhedron)\n";
#endif
}
void G4VRML1SCENE::AddPrimitive(const G4NURBS& nurb)
{
#if defined DEBUG_SCENE_FUNC
G4cerr << "***** AddPrimitive nurbs\n";
#endif
G4cerr << "G4VRML1File::AddPrimitive(G4NURBS&): not implemented. \n";
}
void G4VRML1SCENE::AddPrimitive( const G4Text& text )
{
#if defined DEBUG_SCENE_FUNC
G4cerr << "***** AddPrim mark text\n";
#endif
G4cerr <<
"***** void G4VRML1SCENE::AddPrimitive( const G4Text& text )"
" not implemented yet."
<< endl;
}
void G4VRML1SCENE::AddPrimitive( const G4Circle& circle )
{
#if defined DEBUG_SCENE_FUNC
G4cerr << "***** AddPrim mark circle\n";
#endif
// begin sending a mark
fDest << "Separator {" << endl;
// send color
SendMarkerColor ( circle ) ;
// position
SendMarkerWorldPosition ( circle ) ;
// Calc size
G4double size = GetMarkerHalfSize ( circle );
// send shape with size
fDest << "\t" << "Sphere {" << endl;
fDest << "\t\t" << "radius " << size << endl;
fDest << "\t" << "}" << endl;
// end sending a mark
fDest << "}" << endl; // Separator
}
void G4VRML1SCENE::AddPrimitive(const G4Square& Square) // mark Square
{
#if defined DEBUG_SCENE_FUNC
G4cerr << "***** AddPrim mark Square\n";
#endif
// begin sending a mark
fDest << "Separator {" << endl;
// send color
SendMarkerColor ( Square );
// position
SendMarkerWorldPosition ( Square );
// Calc size
G4double size = GetMarkerHalfSize ( Square );
size *= 2.;
// send shape with size
fDest << "\t" << "Cube {" << endl;
fDest << "\t\t" << "width " << size << endl;
fDest << "\t\t" << "height " << size << endl;
fDest << "\t\t" << "depth " << size << endl;
fDest << "\t" << "}" << endl;
// end sending a mark
fDest << "}" << endl; // Separator
}
void G4VRML1SCENE::ClearStore()
{
#if defined DEBUG_SCENE_FUNC
G4cerr << "***** ClearStore()\n";
#endif
}
void G4VRML1SCENE::BeginModeling()
{
#if defined DEBUG_SCENE_FUNC
G4cerr << "***** BeginModeling\n";
#endif
G4VScene::BeginModeling();
beginSending();
}
void G4VRML1SCENE::EndModeling()
{
#if defined DEBUG_SCENE_FUNC
G4cerr << "***** EndModeling \n";
#endif
G4VScene::EndModeling();
}
void G4VRML1SCENE::BeginPrimitives(const G4Transform3D& objectTransformation)
{
G4VScene::BeginPrimitives (objectTransformation);
fpObjectTransformation = &objectTransformation;
#if defined DEBUG_SCENE_FUNC
G4cerr << "***** BeginPrimitives \n";
#endif
beginSending();
}
void G4VRML1SCENE::EndPrimitives()
{
#if defined DEBUG_SCENE_FUNC
G4cerr << "***** EndPrimitives \n";
#endif
G4VScene::EndPrimitives();
}
void G4VRML1SCENE::SendMaterialNode( const G4VisAttributes* pVA )
{
// const double TRANSPARENCY = 0.9 ;
const double TRANSPARENCY = 0.5 ;
if (!pVA)
return;
const G4Color& color = pVA->GetColor();
fDest << "\t\t" << "Material {" << endl;
if (pVA->IsForceDrawingStyle() &&
(pVA->GetForcedDrawingStyle() == G4VisAttributes::wireframe)) {
fDest << "\t\t\t" << "transparency " << TRANSPARENCY << endl;
}
fDest << "\t\t\t" << "diffuseColor";
fDest << " " << color.GetRed();
fDest << " " << color.GetGreen();
fDest << " " << color.GetBlue();
fDest << endl;
fDest << "\t\t" << "}" << endl;
}
void G4VRML1SCENE::SendMaterialNode()
{
SendMaterialNode
( fpView->GetApplicableVisAttributes (fpVisAttribs) );
}
void G4VRML1SCENE::SendMatrixTransformNode(const G4Transform3D *trans)
{
G4Point3D B (0.0, 0.0, 0.0);
G4Point3D x1 (1.0, 0.0, 0.0);
G4Point3D y1 (0.0, 1.0, 0.0);
G4Vector3D e1 (1.0, 0.0, 0.0);
G4Vector3D e2 (0.0, 1.0, 0.0);
G4Vector3D e3 (0.0, 0.0, 1.0);
//----- transformed origin of body coord
B.transform(*trans);
//----- transformed base vectors of body coord
x1.transform(*trans);
e1 = x1 - B;
y1.transform(*trans);
e2 = y1 - B;
e3 = e1.cross(e2);
e1 = e1.unit(); // normalize again for accuracy
e2 = e2.unit(); //
e3 = e3.unit(); //
fDest << "\t" << "MatrixTransform {" << endl;
fDest << "\t\t" << "matrix ";
fDest << e1.x() << " " << e1.y() << " " << e1.z() << " 0 ";
fDest << e2.x() << " " << e2.y() << " " << e2.z() << " 0 ";
fDest << e3.x() << " " << e3.y() << " " << e3.z() << " 0 ";
fDest << B.x() << " " << B.y() << " " << B.z() << " 1" << endl;
fDest << "\t" << "}" << endl;
}
void G4VRML1SCENE::SendCubeNode(G4double w, G4double h, G4double d)
{
fDest << "\t\t" << "Cube {" << endl;
fDest << "\t\t\t" << "width " << w << endl;
fDest << "\t\t\t" << "height " << h << endl;
fDest << "\t\t\t" << "depth " << d << endl;
fDest << "\t\t" << "}" << endl;
}
void G4VRML1SCENE::SendCylinderNode(G4double R, G4double h)
{
fDest << "\t\t" << "Transform {" << endl;
fDest << "\t\t\t" << "rotation 1 0 0 " << (90. * deg) << endl;
fDest << "\t\t" << "}" << endl;
fDest << "\t\t" << "Cylinder {" << endl;
fDest << "\t\t\t" << "radius " << R << endl;
fDest << "\t\t\t" << "height " << h << endl;
fDest << "\t\t" << "}" << endl;
}
void G4VRML1SCENE::SendSphereNode(G4double R)
{
fDest << "\t\t" << "Sphere {" << endl;
fDest << "\t\t\t" << "radius " << R << endl;
fDest << "\t\t" << "}" << endl;
}
void G4VRML1SCENE::beginSending()
{
if (!IS_CONNECTED ) {
this->connectPort();
fDest << "#VRML V1.0 ascii" << endl;
fDest << "# Generated by VRML driver of GEANT4\n" << endl;
}
}
void G4VRML1SCENE::endSending()
{
if ( IS_CONNECTED ) {
fDest << "#End of file." << endl;
this->closePort();
}
}
void G4VRML1SCENE::SendMarkerColor ( const G4VMarker& mark )
{
const G4Color& color = GetColor( mark );
fDest << "\t" << "Material {" << endl;
fDest << "\t\t";
fDest << "ambientColor [] ";
fDest << "specularColor [] ";
fDest << "\t\t" << "diffuseColor";
fDest << " " << color.GetRed();
fDest << " " << color.GetGreen();
fDest << " " << color.GetBlue();
fDest << endl;
fDest << "\t\t" << "emissiveColor";
fDest << " " << color.GetRed();
fDest << " " << color.GetGreen();
fDest << " " << color.GetBlue();
fDest << endl;
fDest << "\t" << "}" << endl;
}
void
G4VRML1SCENE::SendMarkerWorldPosition ( const G4VMarker& mark )
{
G4Point3D point = mark.GetPosition();
SendMatrixTransformNode( fpObjectTransformation );
fDest << "\t\t" << "Transform {" << endl;
fDest << "\t\t\t" << "translation ";
fDest << point.x() << " " << point.y() << " " << point.z() << endl;
fDest << "\t\t" << "}" << endl;
}
G4double G4VRML1SCENE::GetMarkerHalfSize ( const G4VMarker& mark )
{
//----- return value ( marker radius in 3d units)
G4double size = 1.0 ; // initialization
//----- parameters to calculate 3d size from 2d size
const double HALF_SCREEN_SIZE_2D = 300.0 ; // pixels
double zoom_factor = fpView->GetViewParameters().GetZoomFactor() ;
if ( zoom_factor <= 0.0 ) { zoom_factor = 1.0 ; }
double extent_radius_3d = GetSceneData().GetExtent().GetExtentRadius() ;
if ( extent_radius_3d <= 0.0 ) { extent_radius_3d = 1.0 ; }
//----- get marker radius in 3D units
if ( size = mark.GetWorldSize() ) {
// get mark radius in 3D units
size = 0.5 * mark.GetWorldSize() ;
} else if ( size = mark.GetScreenSize() ) {
// local
double mark_radius_2d = 0.5 * mark.GetScreenSize() ;
// get mark radius in 3D units
size \
= extent_radius_3d * ( mark_radius_2d / HALF_SCREEN_SIZE_2D );
size *= zoom_factor ;
} else {
// local
double mark_radius_2d \
= fpView->GetViewParameters().GetDefaultMarker().GetScreenSize();
// get mark radius in 3D units
size \
= extent_radius_3d * ( mark_radius_2d / HALF_SCREEN_SIZE_2D );
size *= zoom_factor ;
}
//----- global rescaling
size *= fpView->GetViewParameters().GetGlobalMarkerScale();
//----- return size
return size ;
}
// #undef ADDTHIS_WITH_NAME(Solid)
// #undef MAKE_NAME(Solid)
// End of file.
@@ -0,0 +1,78 @@
// 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: G4VRML1View.cc,v 2.4 1998/11/09 19:33:29 allison Exp $
// GEANT4 tag $Name: geant4-00 $
//
// G4VRMLView.cc
// Yasuhide Sawada & Satoshi Tanaka
//=================//
#ifdef G4VIS_BUILD_VRML_DRIVER
//=================//
//#define DEBUG_FR_VIEW
#include "G4SceneData.hh"
#include "G4VRML1View.hh"
#include "G4VRML1Scene.hh"
#include "G4VRML1.hh"
#include "G4ios.hh"
G4VRML1View::G4VRML1View(G4VRML1Scene& scene, const G4String& name) :
G4VView(scene, scene.IncrementViewCount(), name), fScene(scene)
{}
G4VRML1View::~G4VRML1View()
{}
void G4VRML1View::SetView()
{
#if defined DEBUG_FR_VIEW
G4cerr << "***** G4VRML1View::SetView()" << endl;
G4cerr << "G4VRML1View::SetView(); not imlemented. " << endl;
#endif
}
void G4VRML1View::DrawView()
{
#if defined DEBUG_FR_VIEW
G4cerr << "***** G4VRML1View::DrawView()" << endl;
#endif
// Here is a minimal DrawView() function.
NeedKernelVisit();
ProcessView();
FinishView();
}
void G4VRML1View::ClearView(void)
{
#if defined DEBUG_FR_VIEW
G4cerr << "***** G4VRML1View::ClearView()" << endl;
G4cerr << "G4VRML1View::ClearView(); not implemented. " << endl;
#endif
}
void G4VRML1View::ShowView(void)
{
#if defined DEBUG_FR_VIEW
G4cerr << "***** G4VRML1View::ShowView()" << endl;
#endif
fScene.endSending();
}
void G4VRML1View::FinishView(void)
{
#if defined DEBUG_FR_VIEW
G4cerr << "***** G4VRML1View::FinishView()" << endl;
//G4cerr << "G4VRML1View::FinishView(); not implemented. " << endl;
#endif
//fScene.endSending();
}
#endif
+76
View File
@@ -0,0 +1,76 @@
// 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: G4VRML2.cc,v 2.2 1998/11/09 19:33:31 allison Exp $
// GEANT4 tag $Name: geant4-00 $
//
// G4VRML2.cc
// Satoshi Tanaka & Yasuhide Sawada
//=================//
#ifdef G4VIS_BUILD_VRML_DRIVER
//=================//
#include <stdio.h> // sscanf
#include <stdlib.h> // getenv
#include "G4VScene.hh"
#include "G4VRML2.hh"
#include "G4VRML2Scene.hh"
#include "G4VRML2View.hh"
#include "G4FRClient.hh"
G4VRML2::G4VRML2() :
G4VGraphicsSystem("VRML2", "VRML2", G4VGraphicsSystem::threeD)
{
// port number
fPort = FR_VRML_DEFAULT_PORT;
char *pport = getenv(FR_VRML_PORT_ENV);
if (pport) {
sscanf(pport, "%d", &fPort);
}
// host name
fHostName = "localhost" ; // G4String::operator = ( const char* cs )
char *phostname = getenv(FR_VRML_HOST_NAME_ENV);
if (phostname) {
fHostName = phostname;
}
}
G4VRML2::~G4VRML2()
{
}
G4VScene* G4VRML2::CreateScene(const G4String& name)
{
G4VScene *p = NULL;
p = new G4VRML2Scene(*this, name);
G4cout << G4VRML2Scene::GetSceneCount()
<< " " << fName << " scenes extanct." << endl;
return p;
}
G4VView* G4VRML2::CreateView(G4VScene& scene, const G4String& name)
{
G4VView* pView = NULL;
G4VRML2Scene* pScene = (G4VRML2Scene*)&scene;
pView = new G4VRML2View(*pScene, name);
return pView;
}
#endif
@@ -0,0 +1,63 @@
// 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: G4VRML2File.cc,v 2.2 1998/11/09 19:33:33 allison Exp $
// GEANT4 tag $Name: geant4-00 $
//
// G4VRML2File.cc
// Satoshi Tanaka & Yasuhide Sawada
//=================//
#ifdef G4VIS_BUILD_VRMLFILE_DRIVER
//=================//
#include <stdio.h> // sscanf
#include <stdlib.h> // getenv
#include "G4VScene.hh"
#include "G4VRML2File.hh"
#include "G4VRML2FileScene.hh"
#include "G4VRML2FileView.hh"
#include "G4FRClient.hh"
G4VRML2File::G4VRML2File() :
G4VGraphicsSystem("VRML2FILE", "VRML2FILE", G4VGraphicsSystem::threeD)
{
}
G4VRML2File::~G4VRML2File()
{
}
G4VScene* G4VRML2File::CreateScene(const G4String& name)
{
G4VScene *p = NULL;
p = new G4VRML2FileScene(*this, name);
G4cout << G4VRML2FileScene::GetSceneCount()
<< " " << fName << " scenes extanct." << endl;
return p;
}
G4VView* G4VRML2File::CreateView(G4VScene& scene, const G4String& name)
{
G4VView* pView = NULL;
G4VRML2FileScene* pScene = (G4VRML2FileScene*)&scene;
pView = new G4VRML2FileView(*pScene, name);
return pView;
}
#endif
@@ -0,0 +1,206 @@
// 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: G4VRML2FileScene.cc,v 2.6 1998/12/07 06:40:19 stanaka Exp $
// GEANT4 tag $Name: geant4-00 $
//
// G4VRML2FileScene.cc
// Satoshi Tanaka & Yasuhide Sawada
//=================//
#ifdef G4VIS_BUILD_VRMLFILE_DRIVER
//=================//
//#define DEBUG_FR_SCENE
#include <fstream.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include "globals.hh"
#include "G4VPhysicalVolume.hh"
#include "G4LogicalVolume.hh"
#include "G4Point3D.hh"
#include "G4VisAttributes.hh"
#include "G4Transform.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 "G4VRML2FileScene.hh"
#include "G4VRML2FileView.hh"
#include "G4VRML2File.hh"
// CONST
const char WRL_FILE_HEADER [] = "g4_";
const char DEFAULT_WRL_FILE_NAME[] = "g4.wrl";
const char ENV_VRML_VIEWER [] = "G4VRMLFILE_VIEWER";
const char NO_VRML_VIEWER [] = "NONE";
const char VRMLFILE_DEST_DIR [] = "G4VRMLFILE_DEST_DIR";
G4VRML2FileScene::G4VRML2FileScene(G4VRML2File& system, const G4String& name) :
G4VScene(system, fSceneIdCount++, name),
fSystem(system),
fDest() ,
fFlagDestOpen( false ),
fPVPickable ( false )
{
fSceneCount++;
// output file name
strcpy(fVRMLFileName, "");
// destination directory
if ( getenv( VRMLFILE_DEST_DIR ) == NULL ) {
strcpy( fVRMLFileDestDir, "" );
} else {
strcpy( fVRMLFileDestDir, getenv( VRMLFILE_DEST_DIR ) );
}
// maximum number of g4.prim files in the dest directory
fMaxFileNum = 1 ; // initialization
if ( getenv( "G4VRMLFILE_MAX_FILE_NUM" ) != NULL ) {
sscanf( getenv("G4VRMLFILE_MAX_FILE_NUM"), "%d", &fMaxFileNum ) ;
} else {
fMaxFileNum = 1 ;
}
if( fMaxFileNum < 1 ) { fMaxFileNum = 1 ; }
// PV name pickability
if( getenv( "G4VRML_PV_PICKABLE" ) != NULL ) {
int is_pickable ;
sscanf( getenv("G4VRML_PV_PICKABLE"), "%d", &is_pickable ) ;
if ( is_pickable ) { SetPVPickability ( true ) ; }
}
// PV Transparency
SetPVTransparency ();
}
G4VRML2FileScene::~G4VRML2FileScene()
{
#if defined DEBUG_FR_SCENE
G4cerr << "***** ~G4VRML2FileScene" << endl;
#endif
fSceneCount--;
}
#define G4VRML2SCENE G4VRML2FileScene
#define IS_CONNECTED this->isConnected()
#include "G4VRML2SceneFunc.icc"
#undef IS_CONNECTED
#undef G4VRML2SCENE
void G4VRML2FileScene::connectPort()
{
// g4.wrl, g4_1.wrl, ..., g4_MAX_FILE_INDEX.wrl
const int MAX_FILE_INDEX = fMaxFileNum - 1 ;
// dest directory (null if no environmental variables is set)
strcpy ( fVRMLFileName, fVRMLFileDestDir) ;
// create full path name (default)
strcat ( fVRMLFileName, DEFAULT_WRL_FILE_NAME );
// Determine VRML file name
for( int i = 0 ; i < fMaxFileNum ; i++) {
// Message
if( fMaxFileNum > 1 && i == MAX_FILE_INDEX ) {
G4cerr << "===========================================" << endl;
G4cerr << "WARNING MESSAGE from VRML2FILE 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 G4VRMLFILE_DEST_DIR/g4_i.wrl for i>0
if( i > 0 ) {
sprintf( fVRMLFileName, "%s%s%d.wrl" , fVRMLFileDestDir, WRL_FILE_HEADER, i );
}
// check validity of the file name
ifstream fin ;
fin.open(fVRMLFileName) ;
if(!fin) {
// new file
fin.close(); // error recovery
break;
} else {
// already exists (try next)
fin.close();
}
} // for
// open a VRML 2.0 file with determined file name
G4cerr << "===========================================" << endl;
G4cerr << "Output VRML 2.0 file: " << fVRMLFileName << endl;
G4cerr << "Muximal number of file in the destination directory: " << fMaxFileNum << endl;
G4cerr << " (Customizable as: setenv G4VRMLFILE_MAX_FILE_NUM number) " << endl;
G4cerr << "===========================================" << endl;
fDest.open(fVRMLFileName) ; fFlagDestOpen = true ;
}
void G4VRML2FileScene::closePort()
{
char command[256] ;
char viewer [256] ;
strcpy( viewer, NO_VRML_VIEWER ); // initialization
if( getenv( ENV_VRML_VIEWER ) ) {
strcpy( viewer, getenv( ENV_VRML_VIEWER ) ) ;
}
// close VRML file
fDest.close(); fFlagDestOpen = false ;
G4cerr << "*** VRML 2.0 File " << fVRMLFileName << " is generated." << endl;
// Invoke viewer
if ( !strcmp(viewer, NO_VRML_VIEWER )) {
G4cerr << "MESSAGE from VRML2FILE driver:" << endl;
G4cerr << " Set an environmental variable " ;
G4cerr << ENV_VRML_VIEWER << endl;
G4cerr << " if you want to visualize the generated VRML file" << endl;
G4cerr << " automatically. For example, " << endl;
G4cerr << " setenv " << ENV_VRML_VIEWER << " vrwave " << endl;
} else {
sprintf( command, "%s %s", viewer, fVRMLFileName );
system( command );
}
}
G4int G4VRML2FileScene::fSceneIdCount = 0;
G4int G4VRML2FileScene::fSceneCount = 0;
#endif
@@ -0,0 +1,130 @@
// 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: G4VRML2FileView.cc,v 2.2 1998/11/09 19:33:36 allison Exp $
// GEANT4 tag $Name: geant4-00 $
//
// G4VRML2FileView.cc
// Satoshi Tanaka & Yasuhide Sawada
//=================//
#ifdef G4VIS_BUILD_VRMLFILE_DRIVER
//=================//
//#define DEBUG_FR_VIEW
#include <math.h>
#include "G4SceneData.hh"
#include "G4VRML2FileView.hh"
#include "G4VRML2FileScene.hh"
#include "G4VRML2File.hh"
#include "G4ios.hh"
G4VRML2FileView::G4VRML2FileView(G4VRML2FileScene& scene,
const G4String& name) :
G4VView(scene, scene.IncrementViewCount(), name),
fScene(scene),
fDest(scene.fDest)
{
fViewHalfAngle = 0.5 * 0.785398 ; // 0.5 * 45*deg
fsin_VHA = sin ( fViewHalfAngle ) ;
}
G4VRML2FileView::~G4VRML2FileView()
{}
void G4VRML2FileView::SetView()
{
#if defined DEBUG_FR_VIEW
G4cerr << "***** G4VRML2FileView::SetView()" << endl;
G4cerr << "G4VRML2FileView::SetView(); not imlemented. " << endl;
#endif
// Do nothing, since VRML a browser is running as a different process.
// SendViewParameters () will do this job instead.
}
void G4VRML2FileView::DrawView()
{
#if defined DEBUG_FR_VIEW
G4cerr << "***** G4VRML2FileView::DrawView()" << endl;
#endif
// Open VRML2 file and output header comments
fScene.beginSending() ;
// Viewpoint node
SendViewParameters();
// Here is a minimal DrawView() function.
NeedKernelVisit();
ProcessView();
FinishView();
}
void G4VRML2FileView::ClearView(void)
{
#if defined DEBUG_FR_VIEW
G4cerr << "***** G4VRML2File1View::ClearView()" << endl;
G4cerr << "G4VRML2FileView::ClearView(); not implemented. " << endl;
#endif
}
void G4VRML2FileView::ShowView(void)
{
#if defined DEBUG_FR_VIEW
G4cerr << "***** G4VRML2FileView::ShowView()" << endl;
#endif
fScene.endSending();
}
void G4VRML2FileView::FinishView(void)
{
#if defined DEBUG_FR_VIEW
G4cerr << "***** G4VRML2FileView::FinishView()" << endl;
#endif
}
void G4VRML2FileView::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 << "***** G4VRML2FileView::SendViewParameters()\n";
#endif
// error recovery
if ( fsin_VHA < 1.0e-6 ) { return ; }
// camera distance
G4double extent_radius = fScene.GetSceneData().GetExtent().GetExtentRadius();
G4double camera_distance = extent_radius / fsin_VHA ;
// camera position on Z axis
const G4Point3D& target_point = fVP.GetCurrentTargetPoint();
G4double E_z = target_point.z() + camera_distance;
G4Point3D E(0.0, 0.0, E_z );
// VRML codes are generated below
fDest << endl;
fDest << "#---------- CAMERA" << endl;
fDest << "Viewpoint {" << endl;
fDest << "\t" << "position " ;
fDest << E.x() << " " ;
fDest << E.y() << " " ;
fDest << E.z() << endl ;
fDest << "}" << endl;
fDest << endl;
}
#endif
@@ -0,0 +1,127 @@
// 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: G4VRML2Scene.cc,v 2.4 1998/11/29 22:00:34 stanaka Exp $
// GEANT4 tag $Name: geant4-00 $
//
// G4VRML2Scene.cc
// Satoshi Tanaka & Yasuhide Sawada
//=================//
#ifdef G4VIS_BUILD_VRML_DRIVER
//=================//
//#define DEBUG_FR_SCENE
#include <unistd.h>
#include <fstream.h>
#include <math.h>
#include "globals.hh"
#include "G4VPhysicalVolume.hh"
#include "G4LogicalVolume.hh"
#include "G4Point3D.hh"
#include "G4VisAttributes.hh"
#include "G4Transform.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 "G4VRML2Scene.hh"
#include "G4VRML2View.hh"
#include "G4VRML2.hh"
G4VRML2Scene::G4VRML2Scene(G4VRML2& system, const G4String& name) :
G4VScene(system, fSceneIdCount++, name),
fSystem(system),
fDest(),
fPVPickable ( false )
{
fSceneCount++;
// PV name pickability
if( getenv( "G4VRML_PV_PICKABLE" ) != NULL ) {
int is_pickable ;
sscanf( getenv("G4VRML_PV_PICKABLE"), "%d", &is_pickable ) ;
if ( is_pickable ) { SetPVPickability ( true ) ; }
}
// PV Transparency
SetPVTransparency ();
}
G4VRML2Scene::~G4VRML2Scene()
{
#if defined DEBUG_FR_SCENE
G4cerr << "***** ~G4VRML2Scene" << endl;
#endif
fSceneCount--;
}
#define G4VRML2SCENE G4VRML2Scene
#define IS_CONNECTED fDest.isConnected()
#include "G4VRML2SceneFunc.icc"
#undef IS_CONNECTED
#undef G4VRML2SCENE
void G4VRML2Scene::connectPort(G4int max_trial)
{
G4int trial = 0 ;
int port = fSystem.getPort();
for (trial = 0; !fDest.isConnected()&& trial < max_trial; trial++, port++ ) {
if (fDest.connect( (const char * )fSystem.getHostName(), port)) {
// INET domain connection is established
G4cerr << "*** GEANT4 is connected to port ";
G4cerr << fDest.getPort();
G4cerr << " of server " << fSystem.getHostName() << endl;
break;
} else {
// Connection failed. Try the next port.
G4cerr << "*** GEANT4 incremented targeting port to ";
G4cerr << port << endl;
}
sleep (1);
} // for
if (!fDest.isConnected()) {
G4cerr << "*** INET Connection failed. " << endl;
G4cerr << " Maybe, you have not invoked viewer g4vrmlview yet, " << endl;
G4cerr << " or too many viewers are already running in the " << endl;
G4cerr << " server host(" << fSystem.getHostName() << "). " << endl;
}
}
void G4VRML2Scene::closePort()
{
fDest.close();
G4cerr << "*** INET Connection closed. " << endl;
}
G4int G4VRML2Scene::fSceneIdCount = 0;
G4int G4VRML2Scene::fSceneCount = 0;
#endif
@@ -0,0 +1,618 @@
// 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: G4VRML2SceneFunc.icc,v 2.3 1998/11/29 22:00:34 stanaka Exp $
// GEANT4 tag $Name: geant4-00 $
//
// G4VRML2SceneFunc.icc
// Satoshi Tanaka & Yasuhide Sawada
//#define DEBUG_SCENE_FUNC
void G4VRML2SCENE::AddThis(const G4Trd& trd)
{
#if defined DEBUG_SCENE_FUNC
G4cerr << "***** AddThis trd\n";
#endif
G4VScene::AddThis(trd);
}
void G4VRML2SCENE::AddThis(const G4Trap& trap)
{
#if defined DEBUG_SCENE_FUNC
G4cerr << "***** AddThis trap\n";
#endif
G4VScene::AddThis(trap);
}
void G4VRML2SCENE::AddThis(const G4Para& para)
{
#if defined DEBUG_SCENE_FUNC
G4cerr << "***** AddThis para\n";
#endif
G4VScene::AddThis(para);
}
void G4VRML2SCENE::AddThis(const G4Torus& torus )
{
#if defined DEBUG_SCENE_FUNC
G4cerr << "***** AddThis torus\n";
#endif
G4VScene::AddThis(torus);
}
void G4VRML2SCENE::AddThis(const G4VSolid& vsolid)
{
#if defined DEBUG_SCENE_FUNC
G4cerr << "***** AddThis vsolid\n";
#endif
G4VScene::AddThis(vsolid);
}
void G4VRML2SCENE::AddThis(const G4Tubs& tubs)
{
#if defined DEBUG_SCENE_FUNC
G4cerr << "***** AddThis tubs\n";
#endif
G4VScene::AddThis(tubs) ;
}
void G4VRML2SCENE::AddThis(const G4Cons& cons)
{
#if defined DEBUG_SCENE_FUNC
G4cerr << "***** AddThis cons\n";
#endif
G4VScene::AddThis(cons) ;
}
void G4VRML2SCENE::AddThis(const G4Box& box)
{
#if defined DEBUG_SCENE_FUNC
G4cerr << "***** AddThis box\n";
#endif
G4VScene::AddThis(box) ;
}
void G4VRML2SCENE::AddThis(const G4Sphere& sphere)
{
#if defined DEBUG_SCENE_FUNC
G4cerr << "***** AddThis sphere\n";
#endif
G4VScene::AddThis(sphere) ;
}
void G4VRML2SCENE::AddPrimitive(const G4Polyline& polyline)
{
#if defined DEBUG_SCENE_FUNC
G4cerr << "***** AddPrimitive polyline\n";
#endif
// VRML codes are generated below
fDest << "#---------- POLYLINE" << endl;
fDest << "Shape {" << endl;
SendLineColor ( polyline.GetVisAttributes() );
fDest << "\t" << "geometry IndexedLineSet {" << endl;
fDest << "\t\t" << "coord Coordinate {" << endl;
fDest << "\t\t\t" << "point [" << endl;
G4int e, i;
for (i = 0, e = polyline.entries(); e; i++, e--) {
G4Point3D point = polyline(i);
point.transform( *fpObjectTransformation );
fDest << "\t\t\t\t";
fDest << point.x() << " ";
fDest << point.y() << " ";
fDest << point.z() << "," << endl;
} // for
fDest << "\t\t\t" << "]" << endl; // point
fDest << "\t\t" << "}" << endl; // coord
fDest << "\t\t" << "coordIndex [";
for (i = 0, e = polyline.entries(); e; i++, e--) {
if (i % 10 == 0)
fDest << endl << "\t\t\t";
fDest << i << ", ";
}
fDest << "-1" << endl;
fDest << "\t\t" << "]" << endl; // coordIndex
fDest << "\t" << "}" << endl; // geometry IndexedLineSet
fDest << "}" << endl; // Shape
}
void G4VRML2SCENE::AddPrimitive(const G4Polyhedron& polyhedron)
{
#if defined DEBUG_SCENE_FUNC
cerr << "***** AddPrimitive(G4Polyhedron)" << endl;
#endif
// Transparency checking: If completely transparent, skip drawing
if ( GetPVTransparency() > 0.99 ) { return ; }
// Current Model
const G4VModel* pv_model = GetModel();
const char* pv_name = pv_model->GetCurrentTag() ;
// VRML codes are generated below
fDest << "#---------- SOLID: " << pv_name << endl;
if ( IsPVPickable() ) {
fDest << "Anchor {" << endl;
fDest << " description " << "\"" << pv_name << "\"" << endl;
fDest << " url \"\" " << endl;
fDest << " children [" << endl;
}
fDest << "\t"; fDest << "Shape {" << endl;
SendMaterialNode();
fDest << "\t\t" << "geometry IndexedFaceSet {" << endl;
fDest << "\t\t\t" << "coord Coordinate {" << endl;
fDest << "\t\t\t\t" << "point [" << endl;
G4int i, j;
for (i = 1, j = polyhedron.GetNoVertices(); j; j--, i++) {
G4Point3D point = polyhedron.GetVertex(i);
point.transform( *fpObjectTransformation );
fDest << "\t\t\t\t\t";
fDest << point.x() << " ";
fDest << point.y() << " ";
fDest << point.z() << "," << endl;
}
fDest << "\t\t\t\t" << "]" << endl; // point
fDest << "\t\t\t" << "}" << endl; // coord
fDest << "\t\t\t" << "coordIndex [" << endl;
// facet loop
G4int f;
for (f = polyhedron.GetNoFacets(); f; f--) {
// edge loop
G4bool notLastEdge;
G4int index = -1, edgeFlag = 1;
fDest << "\t\t\t\t";
do {
notLastEdge = polyhedron.GetNextVertexIndex(index, edgeFlag);
fDest << index - 1 << ", ";
} while (notLastEdge);
fDest << "-1," << endl;
}
fDest << "\t\t\t" << "]" << endl; // coordIndex
fDest << "\t\t\t" << "solid FALSE" << endl; // draw backfaces
fDest << "\t\t" << "}" << endl; // IndexFaceSet
fDest << "\t" << "}" << endl; // Shape
if ( IsPVPickable() ) {
fDest << " ]" << endl; // children
fDest << "}" << endl; // Anchor
}
#if defined DEBUG_SCENE_FUNC
cerr << "***** end of AddPrimitive(G4Polyhedron)\n";
#endif
}
void G4VRML2SCENE::AddPrimitive(const G4NURBS& nurb)
{
#if defined DEBUG_SCENE_FUNC
G4cerr << "***** AddPrimitive nurbs\n";
#endif
G4cerr << "G4VRML2File::AddPrimitive(G4NURBS&): not implemented. \n";
}
void G4VRML2SCENE::AddPrimitive( const G4Text& text )
{
#if defined DEBUG_SCENE_FUNC
G4cerr << "***** AddPrim mark text\n";
#endif
G4cerr <<
"***** void G4VRML2SCENE::AddPrimitive( const G4Text& text )"
" not implemented yet."
<< endl;
}
void G4VRML2SCENE::AddPrimitive( const G4Circle& circle )
{
#if defined DEBUG_SCENE_FUNC
G4cerr << "***** AddPrim mark circle\n";
#endif
// Information
// const char* info = NULL ;
const char* info = circle.GetInfo() ;
// Position and half size of circle
G4double X, Y, Z ; GetMarkerWorldPosition( circle, &X, &Y, &Z ) ;
G4double radius = GetMarkerHalfSize ( circle );
// VRML codes are generated below
fDest << "#---------- 3D MARKER (Circle)" << endl;
fDest << "Anchor {" << endl;
if( circle.GetInfo().isNull() ) {
fDest << " description " << "\"(" << X << " " ;
fDest << Y << " " ;
fDest << Z << ")\"" << endl;
} else {
fDest << " description " << "\"" << info << "\"" << endl;
}
fDest << " url \"\" " << endl;
fDest << " children [" << endl;
fDest << " Transform {" << endl;
fDest << " translation ";
fDest << X << " " << Y << " " << Z << endl;
fDest << " children [" << endl;
fDest << "\t" << "Shape {" << endl;
SendMarkerColor( circle );
// send shape with size
fDest << "\t\t" << "geometry Sphere {" << endl;
fDest << "\t\t\t" << "radius " << radius << endl;
fDest << "\t\t" << "}" << endl;
fDest << "\t" << "}" << endl; // Shape
fDest << " ]" << endl; // children
fDest << " }" << endl; // Transform
fDest << " ]" << endl; // children
fDest << "}" << endl; // Anchor
}
void G4VRML2SCENE::AddPrimitive(const G4Square& square) // mark Square
{
#if defined DEBUG_SCENE_FUNC
G4cerr << "***** AddPrim mark Square\n";
#endif
// Information
// const char* info = NULL ;
const char* info = square.GetInfo() ;
// Position and size of square
G4double X, Y, Z ; GetMarkerWorldPosition ( square, &X, &Y, &Z ) ;
G4double radius = GetMarkerHalfSize ( square );
G4double diameter = 2.0 * radius ;
// VRML codes are generated below
fDest << "#---------- 3D MARKER (Square)" << endl;
fDest << "Anchor {" << endl;
if( square.GetInfo().isNull() ) {
fDest << " description " << "\"(" << X << " " ;
fDest << Y << " " ;
fDest << Z << ")\"" << endl;
} else {
fDest << " description " << "\"" << info << "\"" << endl;
}
fDest << " url \"\" " << endl;
fDest << " children [" << endl;
fDest << " Transform {" << endl;
fDest << " translation ";
fDest << X << " " << Y << " " << Z << endl;
fDest << " children [" << endl;
fDest << "\t" << "Shape {" << endl;
SendMarkerColor( square );
// send shape with size
fDest << "\t\t" << "geometry Box {" << endl;
fDest << "\t\t\t" << "size " << diameter << " " ;
fDest << diameter << " " ;
fDest << diameter << endl ;
fDest << "\t\t" << "}" << endl;
fDest << "\t" << "}" << endl; // Shape
fDest << " ]" << endl; // children
fDest << " }" << endl; // Transform
fDest << " ]" << endl; // children
fDest << "}" << endl; // Anchor
}
void G4VRML2SCENE::ClearStore()
{
#if defined DEBUG_SCENE_FUNC
G4cerr << "***** ClearStore()\n";
#endif
}
void G4VRML2SCENE::BeginModeling()
{
#if defined DEBUG_SCENE_FUNC
G4cerr << "***** BeginModeling\n";
#endif
G4VScene::BeginModeling();
beginSending(); // error recovery:
// This function should be already called in
// DrawView() of the View class
// before camera setting
}
void G4VRML2SCENE::EndModeling()
{
#if defined DEBUG_SCENE_FUNC
G4cerr << "***** EndModeling \n";
#endif
G4VScene::EndModeling();
}
void G4VRML2SCENE::BeginPrimitives(const G4Transform3D& objectTransformation)
{
G4VScene::BeginPrimitives (objectTransformation);
fpObjectTransformation = &objectTransformation;
#if defined DEBUG_SCENE_FUNC
G4cerr << "***** BeginPrimitives \n";
#endif
beginSending(); // error recovery:
// This function should be already called in
// DrawView() of the View class
// before camera setting
}
void G4VRML2SCENE::EndPrimitives()
{
#if defined DEBUG_SCENE_FUNC
G4cerr << "***** EndPrimitives \n";
#endif
G4VScene::EndPrimitives();
}
void G4VRML2SCENE::SendMaterialNode( const G4VisAttributes* pVA )
{
// Initialization of drawing parameters
G4bool flagWF = false ;
G4double TRANSPARENCY = GetPVTransparency() ;
// Wireframe or not
const G4ViewParameters& cur_view_param = fpView -> GetViewParameters ();
if (pVA->IsForceDrawingStyle() &&
(pVA->GetForcedDrawingStyle() == G4VisAttributes::wireframe))
{
// wireframe style is assigned to this object
flagWF = true ;
} else if ( cur_view_param.GetDrawingStyle() == G4ViewParameters::wireframe )
{
// current viewing style is wireframe
flagWF = true ;
}
// VRML codes are generated below
if (!pVA) {
// Error recovery: Use default values of VRML browser
fDest << "\t\t" ;
fDest << "appearance Appearance { material Material {} }";
fDest << endl;
} else {
const G4Color& color = pVA->GetColor();
fDest << "\t\t" << "appearance Appearance {" << endl;
fDest << "\t\t\t" << "material Material {" << endl;
// diffuse color
fDest << "\t\t\t\t" << "diffuseColor ";
fDest << color.GetRed() << " " ;
fDest << color.GetGreen() << " " ;
fDest << color.GetBlue() << endl;
// emmisive color
// fDest << "\t\t\t\t" << "emissiveColor ";
// fDest << color.GetRed() << " " ;
// fDest << color.GetGreen() << " " ;
//fDest << color.GetBlue() << endl;
//
// wireframe is expressed as transparency
if ( flagWF )
{
fDest << "\t\t\t\t" << "transparency " << TRANSPARENCY << endl;
}
fDest << "\t\t\t" << "}" << endl; // material
fDest << "\t\t" << "}" << endl; // appearance
}
}
void G4VRML2SCENE::SendMaterialNode()
{
SendMaterialNode
( fpView->GetApplicableVisAttributes (fpVisAttribs) );
}
void G4VRML2SCENE::beginSending()
{
if (!IS_CONNECTED ) {
this->connectPort();
fDest << "#VRML V2.0 utf8" << endl;
fDest << "# Generated by VRML 2.0 driver of GEANT4\n" << endl;
}
}
void G4VRML2SCENE::endSending()
{
if ( IS_CONNECTED ) {
fDest << "#End of file." << endl;
this->closePort();
}
}
void G4VRML2SCENE::SendMarkerColor ( const G4VMarker& mark )
{
const G4Color& color = GetColor( mark );
fDest << "\t\t" << "appearance Appearance {" << endl;
fDest << "\t\t\t" << "material Material {" << endl;
fDest << "\t\t\t\t" << "diffuseColor ";
fDest << color.GetRed() << " " ;
fDest << color.GetGreen() << " " ;
fDest << color.GetBlue() << endl;
fDest << "\t\t\t\t" << "emissiveColor ";
fDest << color.GetRed() << " " ;
fDest << color.GetGreen() << " " ;
fDest << color.GetBlue() << endl;
fDest << "\t\t\t" << "}" << endl; // material
fDest << "\t\t" << "}" << endl; // appearance
}
void
G4VRML2SCENE::SendMarkerWorldPosition ( const G4VMarker& mark )
{
G4Point3D point = mark.GetPosition();
point.transform( *fpObjectTransformation );
fDest << " translation ";
fDest << point.x() << " " << point.y() << " " << point.z() << endl;
}
void G4VRML2SCENE::GetMarkerWorldPosition ( const G4VMarker& mark ,
double* pX ,
double* pY ,
double* pZ )
{
G4Point3D point = mark.GetPosition();
point.transform( *fpObjectTransformation );
*pX = point.x() ;
*pY = point.y() ;
*pZ = point.z() ;
}
G4double G4VRML2SCENE::GetMarkerHalfSize ( const G4VMarker& mark )
{
//----- return value ( marker radius in 3d units)
G4double size = 1.0 ; // initialization
//----- parameters to calculate 3d size from 2d size
const double HALF_SCREEN_SIZE_2D = 300.0 ; // pixels
double zoom_factor = fpView->GetViewParameters().GetZoomFactor() ;
if ( zoom_factor <= 0.0 ) { zoom_factor = 1.0 ; }
double extent_radius_3d = GetSceneData().GetExtent().GetExtentRadius() ;
if ( extent_radius_3d <= 0.0 ) { extent_radius_3d = 1.0 ; }
//----- get marker radius in 3D units
if ( size = mark.GetWorldSize() ) {
// get mark radius in 3D units
size = 0.5 * mark.GetWorldSize() ;
} else if ( size = mark.GetScreenSize() ) {
// local
double mark_radius_2d = 0.5 * mark.GetScreenSize() ;
// get mark radius in 3D units
size \
= extent_radius_3d * ( mark_radius_2d / HALF_SCREEN_SIZE_2D );
size *= zoom_factor ;
} else {
// local
double mark_radius_2d \
= fpView->GetViewParameters().GetDefaultMarker().GetScreenSize();
// get mark radius in 3D units
size \
= extent_radius_3d * ( mark_radius_2d / HALF_SCREEN_SIZE_2D );
size *= zoom_factor ;
}
//----- global rescaling
size *= fpView->GetViewParameters().GetGlobalMarkerScale();
//----- return size
return size ;
}
void G4VRML2SCENE::SendLineColor ( const G4VisAttributes* pVA )
{
const G4Color& color = pVA->GetColor();
fDest << "\t" << "appearance Appearance {" << endl;
fDest << "\t\t" << "material Material {" << endl;
fDest << "\t\t\t" << "diffuseColor ";
fDest << color.GetRed() << " " ;
fDest << color.GetGreen() << " " ;
fDest << color.GetBlue() << endl;
fDest << "\t\t\t" << "emissiveColor ";
fDest << color.GetRed() << " " ;
fDest << color.GetGreen() << " " ;
fDest << color.GetBlue() << endl;
fDest << "\t\t" << "}" << endl; // material
fDest << "\t" << "}" << endl; // appearance
}
G4double G4VRML2SCENE::SetPVTransparency ()
{
G4double TRANSPARENCY = 0.7 ; // initialization
if( getenv( "G4VRML_TRANSPARENCY" ) != NULL ) {
// get a value from the env value
sscanf( getenv("G4VRML_TRANSPARENCY"), "%lg", &TRANSPARENCY ) ;
// truncation
TRANSPARENCY = fabs ( TRANSPARENCY ) ;
if ( TRANSPARENCY > 1.0 ) { TRANSPARENCY = 1.0 ; }
}
fPVTransparency = TRANSPARENCY ;
return fPVTransparency ;
}
// End of file.
@@ -0,0 +1,132 @@
// 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: G4VRML2View.cc,v 2.2 1998/11/09 19:33:40 allison Exp $
// GEANT4 tag $Name: geant4-00 $
//
// G4VRML2View.cc
// Satoshi Tanaka & Yasuhide Sawada
//=================//
#ifdef G4VIS_BUILD_VRML_DRIVER
//=================//
//#define DEBUG_FR_VIEW
#include <math.h>
#include "G4SceneData.hh"
#include "G4VRML2View.hh"
#include "G4VRML2Scene.hh"
#include "G4VRML2.hh"
#include "G4ios.hh"
G4VRML2View::G4VRML2View(G4VRML2Scene& scene, const G4String& name) :
G4VView(scene, scene.IncrementViewCount(), name),
fScene(scene),
fDest(scene.fDest)
{
fViewHalfAngle = 0.5 * 0.785398 ; // 0.5 * 45*deg
fsin_VHA = sin ( fViewHalfAngle ) ;
}
G4VRML2View::~G4VRML2View()
{}
void G4VRML2View::SetView()
{
#if defined DEBUG_FR_VIEW
G4cerr << "***** G4VRML2View::SetView()" << endl;
G4cerr << "G4VRML2View::SetView(); not imlemented. " << endl;
#endif
// Do nothing, since VRML a browser is running as a different process.
// SendViewParameters () will do this job instead.
}
void G4VRML2View::DrawView()
{
#if defined DEBUG_FR_VIEW
G4cerr << "***** G4VRML2View::DrawView()" << endl;
#endif
// Open VRML2 file and output header comments
fScene.beginSending() ;
// Viewpoint node
SendViewParameters();
// Here is a minimal DrawView() function.
NeedKernelVisit();
ProcessView();
FinishView();
}
void G4VRML2View::ClearView(void)
{
#if defined DEBUG_FR_VIEW
G4cerr << "***** G4VRML2View::ClearView()" << endl;
G4cerr << "G4VRML2View::ClearView(); not implemented. " << endl;
#endif
}
void G4VRML2View::ShowView(void)
{
#if defined DEBUG_FR_VIEW
G4cerr << "***** G4VRML2View::ShowView()" << endl;
#endif
fScene.endSending();
}
void G4VRML2View::FinishView(void)
{
#if defined DEBUG_FR_VIEW
G4cerr << "***** G4VRML2View::FinishView()" << endl;
//G4cerr << "G4VRML2View::FinishView(); not implemented. " << endl;
#endif
//fScene.endSending();
}
void G4VRML2View::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 << "***** G4VRML2View::SendViewParameters()\n";
#endif
// error recovery
if ( fsin_VHA < 1.0e-6 ) { return ; }
// camera distance
G4double extent_radius = fScene.GetSceneData().GetExtent().GetExtentRadius();
G4double camera_distance = extent_radius / fsin_VHA ;
// camera position on Z axis
const G4Point3D& target_point = fVP.GetCurrentTargetPoint();
G4double E_z = target_point.z() + camera_distance;
G4Point3D E(0.0, 0.0, E_z );
// VRML codes are generated below
fDest << endl;
fDest << "#---------- CAMERA" << endl;
fDest << "Viewpoint {" << endl;
fDest << "\t" << "position " ;
fDest << E.x() << " " ;
fDest << E.y() << " " ;
fDest << E.z() << endl ;
fDest << "}" << endl;
fDest << endl;
}
#endif