Import Geant4 11.0.0 source tree

This commit is contained in:
Gabriele Cosmo
2021-12-10 14:46:44 +01:00
committed by Ben Morgan
parent 6399a014b6
commit 80e2389dd8
3932 changed files with 202519 additions and 246221 deletions
-158
View File
@@ -1,158 +0,0 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
//
//
// FRClient.cc
// FukuiRenderer Client
// Yasuhide Sawada & Satoshi Tanaka
//=================//
#ifndef WIN32
//=================//
//=================//
#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 "G4VisManager.hh"
#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 ) {
if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
G4cout << "ERROR: gethostbyname() failed" << G4endl;
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 //G4VIS_BUILD_VRML_DRIVER
#endif // WIN32
-123
View File
@@ -1,123 +0,0 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
//
//
// G4FRClient.cc
// Yasuhide Sawada & Satoshi Tanaka
//=================//
#ifndef WIN32
//=================//
//=================//
#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 //G4VIS_BUILD_VRML_DRIVER
#endif //WIN32
-94
View File
@@ -1,94 +0,0 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
//
//
// G4VRML1.cc
// Yasuhide Sawada & Satoshi Tanaka
#ifndef WIN32
//=================//
#ifdef G4VIS_BUILD_VRML_DRIVER
//=================//
#include <stdio.h> // sscanf
#include <stdlib.h> // getenv
#include "G4VSceneHandler.hh"
#include "G4VRML1.hh"
#include "G4VRML1SceneHandler.hh"
#include "G4VRML1Viewer.hh"
#include "G4FRClient.hh"
G4VRML1::G4VRML1() :
G4VGraphicsSystem("VRML1", "VRML1", G4VGraphicsSystem::threeD)
{
// port number
fPort = FR_VRML_DEFAULT_PORT;
char *pport = std::getenv(FR_VRML_PORT_ENV);
if (pport) {
sscanf(pport, "%d", &fPort);
}
// host name
fHostName = "localhost" ; // G4String::operator = ( const char* cs )
char *phostname = std::getenv(FR_VRML_HOST_NAME_ENV);
if (phostname) {
fHostName = phostname;
}
}
G4VRML1::~G4VRML1()
{
}
G4VSceneHandler* G4VRML1::CreateSceneHandler(const G4String& name)
{
G4VSceneHandler *p = NULL;
p = new G4VRML1SceneHandler(*this, name);
return p;
}
G4VViewer* G4VRML1::CreateViewer(G4VSceneHandler& scene, const G4String& name)
{
G4VViewer* pView = NULL;
G4VRML1SceneHandler* pScene = (G4VRML1SceneHandler*)&scene;
pView = new G4VRML1Viewer(*pScene, name);
return pView;
}
#endif
#endif
@@ -1,70 +0,0 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
//
//
// G4VRML1File.cc
// Satoshi Tanaka & Yasuhide Sawada
#include <stdio.h> // sscanf
#include <stdlib.h> // getenv
#include "G4VSceneHandler.hh"
#include "G4VRML1File.hh"
#include "G4VRML1FileSceneHandler.hh"
#include "G4VRML1FileViewer.hh"
#include "G4FRClient.hh"
G4VRML1File::G4VRML1File() :
G4VGraphicsSystem("VRML1FILE", "VRML1FILE", G4VGraphicsSystem::fileWriter)
{
}
G4VRML1File::~G4VRML1File()
{
}
G4VSceneHandler* G4VRML1File::CreateSceneHandler(const G4String& name)
{
G4VSceneHandler *p = NULL;
p = new G4VRML1FileSceneHandler(*this, name);
return p;
}
G4VViewer* G4VRML1File::CreateViewer(G4VSceneHandler& scene, const G4String& name)
{
G4VViewer* pView = NULL;
G4VRML1FileSceneHandler* pScene = (G4VRML1FileSceneHandler*)&scene;
pView = new G4VRML1FileViewer(*pScene, name);
return pView;
}
@@ -1,227 +0,0 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
//
//
// G4VRML1FileSceneHandler.cc
// Satoshi Tanaka & Yasuhide Sawada
//#define DEBUG_FR_SCENE
#include <fstream>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sstream>
#include <iomanip>
#include "globals.hh"
#include "G4VisManager.hh"
#include "G4Scene.hh"
#include "G4VPhysicalVolume.hh"
#include "G4LogicalVolume.hh"
#include "G4Point3D.hh"
#include "G4VisAttributes.hh"
#include "G4Polyhedron.hh"
#include "G4Box.hh"
#include "G4Cons.hh"
#include "G4Polyline.hh"
#include "G4Trd.hh"
#include "G4Tubs.hh"
#include "G4Trap.hh"
#include "G4Para.hh"
#include "G4Torus.hh"
#include "G4Sphere.hh"
#include "G4Text.hh"
#include "G4Circle.hh"
#include "G4Square.hh"
#include "G4VRML1FileSceneHandler.hh"
#include "G4VRML1FileViewer.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";
const int DEFAULT_MAX_WRL_FILE_NUM = 100 ;
G4VRML1FileSceneHandler::G4VRML1FileSceneHandler(G4VRML1File& system, const G4String& name) :
G4VSceneHandler(system, fSceneIdCount++, name),
fSystem(system),
fDest() ,
fFlagDestOpen( false )
{
fCurrentDEF = "";
strcpy(fVRMLFileName, "");
if ( std::getenv( VRMLFILE_DEST_DIR ) == NULL ) {
strcpy( fVRMLFileDestDir, "" );
} else {
strcpy( fVRMLFileDestDir, std::getenv( VRMLFILE_DEST_DIR ) );
}
// maximum number of g4.wrl files in the dest directory
fMaxFileNum = DEFAULT_MAX_WRL_FILE_NUM ; // initialization
if ( std::getenv( "G4VRMLFILE_MAX_FILE_NUM" ) != NULL ) {
sscanf( std::getenv("G4VRMLFILE_MAX_FILE_NUM"), "%d", &fMaxFileNum ) ;
} else {
fMaxFileNum = DEFAULT_MAX_WRL_FILE_NUM ;
}
if( fMaxFileNum < 1 ) { fMaxFileNum = 1; }
}
G4VRML1FileSceneHandler::~G4VRML1FileSceneHandler()
{
#if defined DEBUG_FR_SCENE
if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
G4cout << "***** ~G4VRML1FileSceneHandler" << G4endl;
#endif
VRMLEndModeling();
}
#define G4VRML1SCENEHANDLER G4VRML1FileSceneHandler
#define IS_CONNECTED this->isConnected()
#include "G4VRML1SceneHandlerFunc.icc"
#undef IS_CONNECTED
#undef G4VRML1SCENEHANDLER
void G4VRML1FileSceneHandler::connectPort()
{
// g4_00.wrl, g4_01.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 in the final execution
if( i == MAX_FILE_INDEX )
{
if (G4VisManager::GetVerbosity() >= G4VisManager::errors) {
G4cout << "===========================================" << G4endl;
G4cout << "WARNING MESSAGE from VRML1FILE driver: " << G4endl;
G4cout << " This file name is the final one in the " << G4endl;
G4cout << " automatic updation of the output file name." << G4endl;
G4cout << " You may overwrite existing files, i.e. " << G4endl;
G4cout << " g4_XX.wrl. " << G4endl;
G4cout << "===========================================" << G4endl;
}
}
// re-determine file name as G4VRMLFILE_DEST_DIR/g4_XX.wrl
std::ostringstream filename;
filename
<< fVRMLFileDestDir << WRL_FILE_HEADER
<< std::setw(2) << std::setfill('0') << i << ".wrl";
strncpy(fVRMLFileName,filename.str().c_str(),sizeof(fVRMLFileName)-1);
fVRMLFileName[sizeof(fVRMLFileName)-1] = '\0';
// check validity of the file name
std::ifstream fin ;
fin.open(fVRMLFileName) ;
if(!fin) {
// new file
fin.close();
break;
} else {
// already exists (try next)
fin.close();
}
} // for
// open a VRML 1.0 file with determined file name
if (G4VisManager::GetVerbosity() >= G4VisManager::errors) {
G4cout << "===========================================" << G4endl;
G4cout << "Output VRML 1.0 file: " << fVRMLFileName << G4endl;
G4cout << "Maximum number of files in the destination directory: " << fMaxFileNum << G4endl;
G4cout << " (Customizable with the environment variable: G4VRMLFILE_MAX_FILE_NUM) " << G4endl;
G4cout << "===========================================" << G4endl;
}
fDest.open(fVRMLFileName) ; fFlagDestOpen = true ;
}
void G4VRML1FileSceneHandler::closePort()
{
char command[256] ;
char viewer [256] ;
strcpy( viewer, NO_VRML_VIEWER ); // initialization
if( std::getenv( ENV_VRML_VIEWER ) ) {
strcpy( viewer, std::getenv( ENV_VRML_VIEWER ) ) ;
}
// close VRML file
fDest.close(); fFlagDestOpen = false ;
if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
G4cout << "*** VRML 1.0 File " << fVRMLFileName << " is generated." << G4endl;
// Invoke viewer
if ( !strcmp(viewer, NO_VRML_VIEWER )) {
if (G4VisManager::GetVerbosity() >= G4VisManager::errors) {
G4cout << "MESSAGE from VRML1FILE driver:" << G4endl;
G4cout << " Set an environmental variable " ;
G4cout << ENV_VRML_VIEWER << G4endl;
G4cout << " if you want to visualize the generated VRML file" << G4endl;
G4cout << " automatically. For example, " << G4endl;
G4cout << " setenv " << ENV_VRML_VIEWER << " vrweb " << G4endl;
}
} else {
std::ostringstream ossCommand;
ossCommand << viewer << ' ' << fVRMLFileName;
strncpy(command,ossCommand.str().c_str(),sizeof(command)-1);
command[sizeof(command)-1] = '\0';
int iErr = system( command );
if ( iErr != 0 ) {
G4ExceptionDescription ed;
ed << "Error " << iErr
<< " when calling system with \"" << command
<< "\".";
G4Exception("G4VRML1FileSceneHandler::closePort()",
"VRML-1006", JustWarning, ed);
}
}
}
G4int G4VRML1FileSceneHandler::fSceneIdCount = 0;
@@ -1,105 +0,0 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
//
//
// G4VRMLView.cc
// Satoshi Tanaka & Yasuhide Sawada
//#define DEBUG_FR_VIEW
#include "G4VisManager.hh"
#include "G4Scene.hh"
#include "G4VRML1FileViewer.hh"
#include "G4VRML1FileSceneHandler.hh"
#include "G4VRML1File.hh"
#include "G4ios.hh"
G4VRML1FileViewer::G4VRML1FileViewer(G4VRML1FileSceneHandler& sceneHandler,
const G4String& name) :
G4VViewer(sceneHandler,
sceneHandler.IncrementViewCount(),
name),
fSceneHandler(sceneHandler)
{}
G4VRML1FileViewer::~G4VRML1FileViewer()
{}
void G4VRML1FileViewer::SetView()
{
#if defined DEBUG_FR_VIEW
if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
G4cout << "***** G4VRML1FileViewer::SetView(): No effects" << G4endl;
#endif
}
void G4VRML1FileViewer::DrawView()
{
#if defined DEBUG_FR_VIEW
if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
G4cout << "***** G4VRML1FileViewer::DrawView()" << G4endl;
#endif
fSceneHandler.VRMLBeginModeling();
// Here is a minimal DrawView() function.
NeedKernelVisit();
ProcessView();
FinishView();
}
void G4VRML1FileViewer::ClearView(void)
{
#if defined DEBUG_FR_VIEW
if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
G4cout << "***** G4VRML1File1View::ClearView()" << G4endl;
#endif
if(fSceneHandler.fFlagDestOpen) {
fSceneHandler.fDest.close();
// Re-open with same filename...
fSceneHandler.fDest.open(fSceneHandler.fVRMLFileName);
fSceneHandler.fDest << "#VRML V1.0 ascii" << "\n";
fSceneHandler.fDest << "# Generated by VRML 1.0 driver of GEANT4\n" << "\n";
}
}
void G4VRML1FileViewer::ShowView(void)
{
#if defined DEBUG_FR_VIEW
if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
G4cout << "***** G4VRML1FileViewer::ShowView()" << G4endl;
#endif
fSceneHandler.VRMLEndModeling();
}
void G4VRML1FileViewer::FinishView(void)
{
#if defined DEBUG_FR_VIEW
if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
G4cout << "***** G4VRML1FileViewer::FinishView(): No effects" << G4endl;
#endif
}
@@ -1,142 +0,0 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
//
//
// G4VRML1SceneHandler.cc
// Yasuhide Sawada and Satoshi Tanaka
#ifndef WIN32
//=================//
#ifdef G4VIS_BUILD_VRML_DRIVER
//=================//
//#define DEBUG_FR_SCENE
#include <unistd.h>
#include <fstream>
#include "globals.hh"
#include "G4VisManager.hh"
#include "G4VPhysicalVolume.hh"
#include "G4LogicalVolume.hh"
#include "G4Point3D.hh"
#include "G4Scene.hh"
#include "G4VisAttributes.hh"
#include "G4Polyhedron.hh"
#include "G4Box.hh"
#include "G4Cons.hh"
#include "G4Polyline.hh"
#include "G4Trd.hh"
#include "G4Tubs.hh"
#include "G4Trap.hh"
#include "G4Para.hh"
#include "G4Torus.hh"
#include "G4Sphere.hh"
#include "G4Text.hh"
#include "G4Circle.hh"
#include "G4Square.hh"
#include "G4VRML1SceneHandler.hh"
#include "G4VRML1Viewer.hh"
#include "G4VRML1.hh"
G4VRML1SceneHandler::G4VRML1SceneHandler(G4VRML1& system, const G4String& name) :
G4VSceneHandler(system, fSceneIdCount++, name),
fSystem(system),
fDest()
{
fCurrentDEF = "";
}
G4VRML1SceneHandler::~G4VRML1SceneHandler()
{
#if defined DEBUG_FR_SCENE
if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
G4cout << "***** ~G4VRML1SceneHandler" << G4endl;
#endif
}
#define G4VRML1SCENEHANDLER G4VRML1SceneHandler
#define IS_CONNECTED fDest.isConnected()
#include "G4VRML1SceneHandlerFunc.icc"
#undef IS_CONNECTED
#undef G4VRML1SCENEHANDLER
void G4VRML1SceneHandler::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
if (G4VisManager::GetVerbosity() >= G4VisManager::errors) {
G4cout << "*** GEANT4 is connected to port ";
G4cout << fDest.getPort();
G4cout << " of server " << fSystem.getHostName() << G4endl;
}
break;
} else {
// Connection failed. Try the next port.
if (G4VisManager::GetVerbosity() >= G4VisManager::errors) {
G4cout << "*** GEANT4 incremented targeting port to ";
G4cout << port << G4endl;
}
}
sleep (1);
} // for
if (!fDest.isConnected()) {
if (G4VisManager::GetVerbosity() >= G4VisManager::errors) {
G4cout << "*** INET Connection failed. " << G4endl;
G4cout << " Maybe, you have not invoked viewer g4vrmlview yet, " << G4endl;
G4cout << " or too many viewers are already running in the " << G4endl;
G4cout << " server host(" << fSystem.getHostName() << "). " << G4endl;
}
}
}
void G4VRML1SceneHandler::closePort()
{
fDest.close();
if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
G4cout << "*** INET Connection closed. " << G4endl;
}
G4int G4VRML1SceneHandler::fSceneIdCount = 0;
#endif
#endif
@@ -1,747 +0,0 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
//
//
// G4VRML1SceneHandlerFunc.icc
// Satoshi Tanaka & Yasuhide Sawada
#include <CLHEP/Units/SystemOfUnits.h>
#include "G4VisManager.hh"
//#define DEBUG_SCENE_FUNC
// MACRO
#define ADDTHIS_WITH_NAME(Solid) \
fCurrentDEF = #Solid "_" + Solid.GetName(); \
RequestPrimitives(Solid); \
fCurrentDEF = "";
// End of MACRO
void G4VRML1SCENEHANDLER::AddSolid(const G4Trd& trd)
{
#if defined DEBUG_SCENE_FUNC
if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
G4cout << "***** AddSolid trd" << "\n" ;
#endif
VRMLBeginModeling () ;
ADDTHIS_WITH_NAME(trd)
}
void G4VRML1SCENEHANDLER::AddSolid(const G4Trap& trap)
{
#if defined DEBUG_SCENE_FUNC
if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
G4cout << "***** AddSolid trap" << "\n" ;
#endif
VRMLBeginModeling () ;
ADDTHIS_WITH_NAME(trap)
}
void G4VRML1SCENEHANDLER::AddSolid(const G4Para& para)
{
#if defined DEBUG_SCENE_FUNC
if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
G4cout << "***** AddSolid para" << "\n" ;
#endif
VRMLBeginModeling () ;
ADDTHIS_WITH_NAME(para)
}
void G4VRML1SCENEHANDLER::AddSolid(const G4Torus& torus )
{
#if defined DEBUG_SCENE_FUNC
if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
G4cout << "***** AddSolid torus" << "\n" ;
#endif
VRMLBeginModeling () ;
ADDTHIS_WITH_NAME(torus)
}
void G4VRML1SCENEHANDLER::AddSolid(const G4VSolid& vsolid)
{
#if defined DEBUG_SCENE_FUNC
if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
G4cout << "***** AddSolid vsolid" << "\n" ;
#endif
VRMLBeginModeling () ;
ADDTHIS_WITH_NAME(vsolid)
}
void G4VRML1SCENEHANDLER::AddSolid(const G4Tubs& tubs)
{
#if defined DEBUG_SCENE_FUNC
if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
G4cout << "***** AddSolid tubs" << "\n" ;
#endif
VRMLBeginModeling () ;
// set current name
fCurrentDEF = "tubs_" + tubs.GetName();
// Get data
const G4double R = tubs.GetOuterRadius(); // outside radius
const G4double r = tubs.GetInnerRadius(); // inside radius
const G4double dz = tubs.GetZHalfLength(); // half length in z
const G4double dp = tubs.GetDeltaPhiAngle(); // angle interval
// Send data
if ( r == 0.0 && dp >= 360. * CLHEP::deg ) {
// Send a built-in VRML node (Cylinder)
fDest << "Separator {" << "\n";
SendMatrixTransformNode( fObjectTransformation );
fDest << "\t" << "DEF " << fCurrentDEF << " Separator {" << "\n";
SendMaterialNode();
SendCylinderNode(R, dz * 2);
fDest << "\t" << "}" << "\n"; // DEF Separator
fDest << "}" << "\n"; // Separator
} else {
// call AddPrimitive(Polyhedron)
RequestPrimitives(tubs);
}
// reset current name to null
fCurrentDEF = "";
}
void G4VRML1SCENEHANDLER::AddSolid(const G4Cons& cons)
{
#if defined DEBUG_SCENE_FUNC
if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
G4cout << "***** AddSolid cons" << "\n" ;
#endif
VRMLBeginModeling () ;
// set current name
fCurrentDEF = "cons_" + cons.GetName();
// Get data
const G4double r1 = cons.GetInnerRadiusMinusZ(); // inside radius at -dz
const G4double R1 = cons.GetOuterRadiusMinusZ(); // outside radius at -dz
const G4double r2 = cons.GetInnerRadiusPlusZ(); // inside radius at +dz
const G4double R2 = cons.GetOuterRadiusPlusZ(); // outside radius at +dz
const G4double dz = cons.GetZHalfLength(); // half length in z
//const G4double sp = cons.GetStartPhiAngle(); // starting angle
const G4double dp = cons.GetDeltaPhiAngle(); // angle width
// Send data
if ( r1 == 0.0 && r2 == 0.0 && R1 == R2 && dp >= 360. * CLHEP::deg) {
// Send a built-in VRML node (Cylinder)
fDest << "Separator {" << "\n";
SendMatrixTransformNode( fObjectTransformation );
fDest << "\t" << "DEF " << fCurrentDEF << " Separator {" << "\n";
SendMaterialNode();
SendCylinderNode(R1, dz * 2);
fDest << "\t" << "}" << "\n"; // DEF Separator
fDest << "}" << "\n"; // Separator
} else {
// call AddPrimitive(Polyhedron)
RequestPrimitives(cons);
}
// reset current name to null
fCurrentDEF = "";
}
void G4VRML1SCENEHANDLER::AddSolid(const G4Box& box)
{
#if defined DEBUG_SCENE_FUNC
if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
G4cout << "***** AddSolid box" << "\n" ;
#endif
VRMLBeginModeling () ;
// set current name
fCurrentDEF = "box_" + box.GetName();
// Send a built-in VRML node (Cube)
fDest << "Separator {" << "\n";
//fDest << "\t" << "renderCulling ON" << "\n";
SendMatrixTransformNode( fObjectTransformation );
fDest << "\t" << "DEF " << fCurrentDEF << " Separator {" << "\n";
SendMaterialNode();
SendCubeNode(box.GetXHalfLength() * 2, box.GetYHalfLength() * 2, box.GetZHalfLength() * 2);
fDest << "\t" << "}" << "\n"; // DEF Separator
fDest << "}" << "\n"; // Separator
// reset current name to null
fCurrentDEF = "";
}
void G4VRML1SCENEHANDLER::AddSolid(const G4Sphere& sphere)
{
#if defined DEBUG_SCENE_FUNC
if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
G4cout << "***** AddSolid sphere" << "\n" ;
#endif
VRMLBeginModeling () ;
// set current name
fCurrentDEF = "sphere_" + sphere.GetName();
// Get data
G4double dphi = sphere.GetDeltaPhiAngle () ;
G4double dtheta = sphere.GetDeltaThetaAngle() ;
G4double rmax = sphere.GetOuterRadius () ;
G4double rmin = sphere.GetInnerRadius () ;
// Send data
if ( (dphi >= 360. * CLHEP::deg) && (dtheta >= 180. * CLHEP::deg) && (rmin == 0.0) ) {
// Send a built-in VRML node (Sphere)
fDest << "Separator {" << "\n";
SendMatrixTransformNode( fObjectTransformation );
fDest << "\t" << "DEF " << fCurrentDEF << " Separator {" << "\n";
SendMaterialNode();
SendSphereNode( rmax );
fDest << "\t" << "}" << "\n"; // DEF Separator
fDest << "}" << "\n"; // Separator
} else {
// call AddPrimitive(Polyhedron)
RequestPrimitives( sphere );
}
// reset current name to null
fCurrentDEF = "";
}
void G4VRML1SCENEHANDLER::AddPrimitive(const G4Polyline& polyline)
{
#if defined DEBUG_SCENE_FUNC
if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
G4cout << "***** AddPrimitive polyline" << "\n" ;
#endif
if (fProcessing2D) {
static G4bool warned = false;
if (!warned) {
warned = true;
G4Exception
("G4VRML1SCENEHANDLER::AddPrimitive (const G4Polyline&)",
"VRML-1001", JustWarning,
"2D polylines not implemented. Ignored.");
}
return;
}
VRMLBeginModeling () ;
fDest << "Separator {" << "\n";
SendMatrixTransformNode (fObjectTransformation );
SendMaterialNode( polyline.GetVisAttributes() );
fDest << "\t" << "Coordinate3 {" << "\n";
fDest << "\t\t" << "point [" << "\n";
G4int e, i;
for (i = 0, e = polyline.size(); e; i++, e--) {
fDest << "\t\t\t";
fDest << polyline[i].x() << " ";
fDest << polyline[i].y() << " ";
fDest << polyline[i].z() << "," << "\n";
}
fDest << "\t\t" << "]" << "\n";
fDest << "\t" << "}" << "\n"; // Coordinate3
fDest << "\t" << "IndexedLineSet {" << "\n";
fDest << "\t\t" << "coordIndex [";
for (i = 0, e = polyline.size(); e; i++, e--) {
if (i % 10 == 0)
fDest << "\n" << "\t\t\t";
fDest << i << ", ";
}
fDest << "-1" << "\n";
fDest << "\t\t" << "]" << "\n";
fDest << "\t" << "}" << "\n"; // IndexedLineSet
fDest << "}" << "\n"; // Separator
}
void G4VRML1SCENEHANDLER::AddPrimitive(const G4Polyhedron& polyhedron)
{
#if defined DEBUG_SCENE_FUNC
if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
G4cout << "***** AddPrimitive(G4Polyhedron)" << "\n";
#endif
if (polyhedron.GetNoFacets() == 0) return;
if (fProcessing2D) {
static G4bool warned = false;
if (!warned) {
warned = true;
G4Exception
("G4VRML1SCENEHANDLER::AddPrimitive (const G4Polyhedron&)",
"VRML-1002", JustWarning,
"2D polyhedra not implemented. Ignored.");
}
return;
}
VRMLBeginModeling () ;
fDest << "Separator {" << "\n";
SendMatrixTransformNode( fObjectTransformation );
fDest << "\t";
if (fCurrentDEF != "")
fDest << "DEF " << fCurrentDEF << " ";
fDest << "Separator {" << "\n";
//fDest << "\t\t" << "renderCulling ON" << "\n";
fDest << "\t\t" << "ShapeHints {" << "\n";
fDest << "\t\t\t" << "vertexOrdering COUNTERCLOCKWISE" << "\n";
fDest << "\t\t\t" << "shapeType SOLID" << "\n";
fDest << "\t\t\t" << "faceType CONVEX" << "\n";
fDest << "\t\t" << "}" << "\n";
SendMaterialNode();
fDest << "\t\t" << "Coordinate3 {" << "\n";
fDest << "\t\t\t" << "point [" << "\n";
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() << "," << "\n";
}
fDest << "\t\t\t" << "]" << "\n";
fDest << "\t\t" << "}" << "\n"; // Coordinate3
fDest << "\t\t" << "IndexedFaceSet {" << "\n";
fDest << "\t\t\t" << "coordIndex [" << "\n";
// 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," << "\n";
}
fDest << "\t\t\t" << "]" << "\n";
fDest << "\t\t" << "}" << "\n"; // IndexFaceSet
fDest << "\t" << "}" << "\n"; // (DEF) Separator
fDest << "}" << "\n"; // Separator
}
void G4VRML1SCENEHANDLER::AddPrimitive( const G4Text& )
{
#if defined DEBUG_SCENE_FUNC
if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
G4cout << "***** AddPrimitive text" << "\n" ;
#endif
/*** You might need this
if (fProcessing2D) {
static G4bool warned = false;
if (!warned) {
warned = true;
G4Exception
("G4VRML1SCENEHANDLER::AddPrimitive (const G4Text&)",
"VRML-1003", JustWarning,
"2D text not implemented. Ignored.");
}
return;
}
***/
if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
G4cout <<
"***** void G4VRML1SCENEHANDLER::AddPrimitive( const G4Text& text )"
" not implemented yet."
<< "\n";
VRMLBeginModeling () ;
}
void G4VRML1SCENEHANDLER::AddPrimitive( const G4Circle& circle )
{
#if defined DEBUG_SCENE_FUNC
if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
G4cout << "***** AddPrimitive circle" << "\n" ;
#endif
if (fProcessing2D) {
static G4bool warned = false;
if (!warned) {
warned = true;
G4Exception
("G4VRML1SCENEHANDLER::AddPrimitive (const G4Circle&)",
"VRML-1004", JustWarning,
"2D circles not implemented. Ignored.");
}
return;
}
VRMLBeginModeling () ;
// begin sending a mark
fDest << "Separator {" << "\n";
// send color
SendMarkerColor ( circle ) ;
// position
SendMarkerWorldPosition ( circle ) ;
// Calc size
G4double size = GetMarkerHalfSize ( circle );
// send shape with size
fDest << "\t" << "Sphere {" << "\n";
fDest << "\t\t" << "radius " << size << "\n";
fDest << "\t" << "}" << "\n";
// end sending a mark
fDest << "}" << "\n"; // Separator
}
void G4VRML1SCENEHANDLER::AddPrimitive(const G4Square& square)
{
#if defined DEBUG_SCENE_FUNC
if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
G4cout << "***** AddPrimitive square" << "\n" ;
#endif
if (fProcessing2D) {
static G4bool warned = false;
if (!warned) {
warned = true;
G4Exception
("G4VRML1SCENEHANDLER::AddPrimitive (const G4Square&)",
"VRML-1005", JustWarning,
"2D squares not implemented. Ignored.");
}
return;
}
VRMLBeginModeling () ;
// begin sending a mark
fDest << "Separator {" << "\n";
// send color
SendMarkerColor ( square );
// position
SendMarkerWorldPosition ( square );
// Calc size
G4double size = GetMarkerHalfSize ( square );
size *= 2.;
// send shape with size
fDest << "\t" << "Cube {" << "\n";
fDest << "\t\t" << "width " << size << "\n";
fDest << "\t\t" << "height " << size << "\n";
fDest << "\t\t" << "depth " << size << "\n";
fDest << "\t" << "}" << "\n";
// end sending a mark
fDest << "}" << "\n"; // Separator
}
void G4VRML1SCENEHANDLER::BeginModeling()
{
#if defined DEBUG_SCENE_FUNC
if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
G4cout << "***** BeginModeling " << "\n" ;
#endif
G4VSceneHandler::BeginModeling();
}
void G4VRML1SCENEHANDLER::EndModeling()
{
#if defined DEBUG_SCENE_FUNC
if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
G4cout << "***** EndModeling " << "\n" ;
#endif
G4VSceneHandler::EndModeling();
}
void G4VRML1SCENEHANDLER::BeginPrimitives(const G4Transform3D& objectTransformation)
{
G4VSceneHandler::BeginPrimitives (objectTransformation);
#if defined DEBUG_SCENE_FUNC
if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
G4cout << "***** BeginPrimitives " << "\n" ;
#endif
VRMLBeginModeling();
}
void G4VRML1SCENEHANDLER::EndPrimitives()
{
#if defined DEBUG_SCENE_FUNC
if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
G4cout << "***** EndPrimitives " << "\n" ;
#endif
G4VSceneHandler::EndPrimitives();
}
void G4VRML1SCENEHANDLER::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 {" << "\n";
if (pVA->IsForceDrawingStyle() &&
(pVA->GetForcedDrawingStyle() == G4VisAttributes::wireframe)) {
fDest << "\t\t\t" << "transparency " << TRANSPARENCY << "\n";
}
fDest << "\t\t\t" << "diffuseColor";
fDest << " " << color.GetRed();
fDest << " " << color.GetGreen();
fDest << " " << color.GetBlue();
fDest << "\n";
fDest << "\t\t" << "}" << "\n";
}
void G4VRML1SCENEHANDLER::SendMaterialNode()
{
SendMaterialNode
( fpViewer->GetApplicableVisAttributes (fpVisAttribs) );
}
void G4VRML1SCENEHANDLER::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 {" << "\n";
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" << "\n";
fDest << "\t" << "}" << "\n";
}
void G4VRML1SCENEHANDLER::SendCubeNode(G4double w, G4double h, G4double d)
{
fDest << "\t\t" << "Cube {" << "\n";
fDest << "\t\t\t" << "width " << w << "\n";
fDest << "\t\t\t" << "height " << h << "\n";
fDest << "\t\t\t" << "depth " << d << "\n";
fDest << "\t\t" << "}" << "\n";
}
void G4VRML1SCENEHANDLER::SendCylinderNode(G4double R, G4double h)
{
fDest << "\t\t" << "Transform {" << "\n";
fDest << "\t\t\t" << "rotation 1 0 0 " << (90. * CLHEP::deg) << "\n";
fDest << "\t\t" << "}" << "\n";
fDest << "\t\t" << "Cylinder {" << "\n";
fDest << "\t\t\t" << "radius " << R << "\n";
fDest << "\t\t\t" << "height " << h << "\n";
fDest << "\t\t" << "}" << "\n";
}
void G4VRML1SCENEHANDLER::SendSphereNode(G4double R)
{
fDest << "\t\t" << "Sphere {" << "\n";
fDest << "\t\t\t" << "radius " << R << "\n";
fDest << "\t\t" << "}" << "\n";
}
void G4VRML1SCENEHANDLER::VRMLBeginModeling()
{
if (!IS_CONNECTED ) {
#if defined DEBUG_SCENE_FUNC
if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
G4cout << "***** VRMLBeginModeling() (started)" << "\n" ;
#endif
this->connectPort();
fDest << "#VRML V1.0 ascii" << "\n";
fDest << "# Generated by VRML 1.0 driver of GEANT4\n" << "\n";
}
}
void G4VRML1SCENEHANDLER::VRMLEndModeling()
{
if ( IS_CONNECTED ) {
#if defined DEBUG_SCENE_FUNC
if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
G4cout << "***** VRMLEndModeling() (started)" << "\n" ;
#endif
fDest << "#End of file." << "\n";
this->closePort();
}
}
void G4VRML1SCENEHANDLER::SendMarkerColor ( const G4VMarker& marker )
{
fpVisAttribs = marker.GetVisAttributes();
const G4Color& color = GetColor();
fDest << "\t" << "Material {" << "\n";
fDest << "\t\t";
fDest << "ambientColor [] ";
fDest << "specularColor [] ";
fDest << "\t\t" << "diffuseColor";
fDest << " " << color.GetRed();
fDest << " " << color.GetGreen();
fDest << " " << color.GetBlue();
fDest << "\n";
fDest << "\t\t" << "emissiveColor";
fDest << " " << color.GetRed();
fDest << " " << color.GetGreen();
fDest << " " << color.GetBlue();
fDest << "\n";
fDest << "\t" << "}" << "\n";
}
void
G4VRML1SCENEHANDLER::SendMarkerWorldPosition ( const G4VMarker& mark )
{
G4Point3D point = mark.GetPosition();
SendMatrixTransformNode( fObjectTransformation );
fDest << "\t\t" << "Transform {" << "\n";
fDest << "\t\t\t" << "translation ";
fDest << point.x() << " " << point.y() << " " << point.z() << "\n";
fDest << "\t\t" << "}" << "\n" ;
}
G4double G4VRML1SCENEHANDLER::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 = fpViewer->GetViewParameters().GetZoomFactor() ;
if ( zoom_factor <= 0.0 ) { zoom_factor = 1.0 ; }
double extent_radius_3d = GetScene()->GetExtent().GetExtentRadius() ;
if ( extent_radius_3d <= 0.0 ) { extent_radius_3d = 1.0 ; }
//----- get marker radius in 3D units
if ( mark.GetWorldSize() > 0.0 ) {
// get mark radius in 3D units
size = 0.5 * mark.GetWorldSize() ;
} else if ( mark.GetScreenSize() > 0.0 ) {
// 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 \
= fpViewer->GetViewParameters().GetDefaultMarker().GetScreenSize();
mark_radius_2d *= 0.1 ; // Magic number?
// get mark radius in 3D units
size \
= extent_radius_3d * ( mark_radius_2d / HALF_SCREEN_SIZE_2D );
size *= zoom_factor ;
}
//----- global rescaling
size *= fpViewer->GetViewParameters().GetGlobalMarkerScale();
//----- return size
return size ;
}
void G4VRML1SCENEHANDLER::ClearTransientStore()
{
// This is typically called after an update and before drawing hits
// of the next event. To simulate the clearing of "transients"
// (hits, etc.) the detector is redrawn...
if (fpViewer) {
fpViewer -> SetView ();
fpViewer -> ClearView ();
fpViewer -> DrawView ();
}
}
// #undef ADDTHIS_WITH_NAME(Solid)
// #undef MAKE_NAME(Solid)
// End of file.
@@ -1,104 +0,0 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
//
//
// G4VRMLView.cc
// Yasuhide Sawada & Satoshi Tanaka
#ifndef WIN32
//=================//
#ifdef G4VIS_BUILD_VRML_DRIVER
//=================//
//#define DEBUG_FR_VIEW
#include "G4VisManager.hh"
#include "G4Scene.hh"
#include "G4VRML1Viewer.hh"
#include "G4VRML1SceneHandler.hh"
#include "G4VRML1.hh"
#include "G4ios.hh"
G4VRML1Viewer::G4VRML1Viewer(G4VRML1SceneHandler& scene, const G4String& name) :
G4VViewer(scene, scene.IncrementViewCount(), name), fSceneHandler(scene)
{}
G4VRML1Viewer::~G4VRML1Viewer()
{}
void G4VRML1Viewer::SetView()
{
#if defined DEBUG_FR_VIEW
if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
G4cout << "***** G4VRML1Viewer::SetView(): No effects" << G4endl;
#endif
}
void G4VRML1Viewer::DrawView()
{
#if defined DEBUG_FR_VIEW
if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
G4cout << "***** G4VRML1Viewer::DrawView()" << G4endl;
#endif
fSceneHandler.VRMLBeginModeling();
// Here is a minimal DrawView() function.
NeedKernelVisit();
ProcessView();
FinishView();
}
void G4VRML1Viewer::ClearView(void)
{
#if defined DEBUG_FR_VIEW
if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
G4cout << "***** G4VRML1Viewer::ClearView(): No effects" << G4endl;
#endif
}
void G4VRML1Viewer::ShowView(void)
{
#if defined DEBUG_FR_VIEW
if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
G4cout << "***** G4VRML1Viewer::ShowView()" << G4endl;
#endif
fSceneHandler.VRMLEndModeling();
}
void G4VRML1Viewer::FinishView(void)
{
#if defined DEBUG_FR_VIEW
if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
G4cout << "***** G4VRML1Viewer::FinishView(): No effects" << G4endl;
#endif
}
#endif
#endif //WIN32
-93
View File
@@ -1,93 +0,0 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
//
//
// G4VRML2.cc
// Satoshi Tanaka & Yasuhide Sawada
#ifndef WIN32
//=================//
#ifdef G4VIS_BUILD_VRML_DRIVER
//=================//
#include <stdio.h> // sscanf
#include <stdlib.h> // getenv
#include "G4VSceneHandler.hh"
#include "G4VRML2.hh"
#include "G4VRML2SceneHandler.hh"
#include "G4VRML2Viewer.hh"
#include "G4FRClient.hh"
G4VRML2::G4VRML2() :
G4VGraphicsSystem("VRML2", "VRML2", G4VGraphicsSystem::threeD)
{
// port number
fPort = FR_VRML_DEFAULT_PORT;
char *pport = std::getenv(FR_VRML_PORT_ENV);
if (pport) {
sscanf(pport, "%d", &fPort);
}
// host name
fHostName = "localhost" ; // G4String::operator = ( const char* cs )
char *phostname = std::getenv(FR_VRML_HOST_NAME_ENV);
if (phostname) {
fHostName = phostname;
}
}
G4VRML2::~G4VRML2()
{
}
G4VSceneHandler* G4VRML2::CreateSceneHandler(const G4String& name)
{
G4VSceneHandler *p = NULL;
p = new G4VRML2SceneHandler(*this, name);
return p;
}
G4VViewer* G4VRML2::CreateViewer(G4VSceneHandler& scene, const G4String& name)
{
G4VViewer* pView = NULL;
G4VRML2SceneHandler* pScene = (G4VRML2SceneHandler*)&scene;
pView = new G4VRML2Viewer(*pScene, name);
return pView;
}
#endif
#endif //WIN32
+20 -27
View File
@@ -28,8 +28,8 @@
// G4VRML2File.cc
// Satoshi Tanaka & Yasuhide Sawada
#include <stdio.h> // sscanf
#include <stdlib.h> // getenv
#include <stdio.h> // sscanf
#include <stdlib.h> // getenv
#include "G4VSceneHandler.hh"
@@ -37,35 +37,28 @@
#include "G4VRML2FileSceneHandler.hh"
#include "G4VRML2FileViewer.hh"
#include "G4FRClient.hh"
G4VRML2File::G4VRML2File()
: G4VGraphicsSystem("VRML2FILE", "VRML2FILE", G4VGraphicsSystem::fileWriter)
{}
G4VRML2File::~G4VRML2File() {}
G4VRML2File::G4VRML2File() :
G4VGraphicsSystem("VRML2FILE", "VRML2FILE", G4VGraphicsSystem::fileWriter
)
G4VSceneHandler* G4VRML2File::CreateSceneHandler(const G4String& name)
{
G4VSceneHandler* p = NULL;
p = new G4VRML2FileSceneHandler(*this, name);
return p;
}
G4VRML2File::~G4VRML2File()
G4VViewer* G4VRML2File::CreateViewer(G4VSceneHandler& scene,
const G4String& name)
{
}
G4VSceneHandler* G4VRML2File::CreateSceneHandler(const G4String& name)
{
G4VSceneHandler *p = NULL;
p = new G4VRML2FileSceneHandler(*this, name);
return p;
}
G4VViewer* G4VRML2File::CreateViewer(G4VSceneHandler& scene, const G4String& name)
{
G4VViewer* pView = NULL;
G4VRML2FileSceneHandler* pScene = (G4VRML2FileSceneHandler*)&scene;
pView = new G4VRML2FileViewer(*pScene, name);
return pView;
G4VViewer* pView = NULL;
G4VRML2FileSceneHandler* pScene = (G4VRML2FileSceneHandler*) &scene;
pView = new G4VRML2FileViewer(*pScene, name);
return pView;
}
@@ -28,7 +28,6 @@
// G4VRML2FileSceneHandler.cc
// Satoshi Tanaka & Yasuhide Sawada
//#define DEBUG_FR_SCENE
#include <fstream>
@@ -63,179 +62,214 @@
// 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";
const int DEFAULT_MAX_WRL_FILE_NUM = 100 ;
const char WRL_FILE_HEADER[] = "g4_";
const char ENV_WRL_FILE_HEADER[] = "G4VRMLFILE_HEADER";
const char ENV_WRL_FILE_NAME[] = "G4VRMLFILE_FILE_NAME";
const char ENV_VRML_VIEWER[] = "G4VRMLFILE_VIEWER";
const char NO_VRML_VIEWER[] = "NONE";
const char VRMLFILE_DEST_DIR[] = "G4VRMLFILE_DEST_DIR";
const int DEFAULT_MAX_WRL_FILE_NUM = 100;
G4VRML2FileSceneHandler::G4VRML2FileSceneHandler(G4VRML2File& system, const G4String& name) :
G4VSceneHandler(system, fSceneIdCount++, name),
fSystem(system),
fFlagDestOpen( false ),
fPVPickable ( false ),
fDest()
G4VRML2FileSceneHandler::G4VRML2FileSceneHandler(G4VRML2File& system,
const G4String& name)
: G4VSceneHandler(system, fSceneIdCount++, name)
, fSystem(system)
, fFlagDestOpen(false)
, fPVPickable(false)
, fDest()
{
// output file name
strcpy(fVRMLFileName, "");
// output file name
strcpy(fVRMLFileName, "");
// destination directory
if ( std::getenv( VRMLFILE_DEST_DIR ) == NULL ) {
strcpy( fVRMLFileDestDir, "" );
} else {
strcpy( fVRMLFileDestDir, std::getenv( VRMLFILE_DEST_DIR ) );
}
// destination directory
if(std::getenv(VRMLFILE_DEST_DIR) == NULL)
{
strcpy(fVRMLFileDestDir, "");
}
else
{
strcpy(fVRMLFileDestDir, std::getenv(VRMLFILE_DEST_DIR));
}
// maximum number of g4.prim files in the dest directory
fMaxFileNum = DEFAULT_MAX_WRL_FILE_NUM; // initialization
if(std::getenv("G4VRMLFILE_MAX_FILE_NUM") != NULL)
{
sscanf(std::getenv("G4VRMLFILE_MAX_FILE_NUM"), "%d", &fMaxFileNum);
}
else
{
fMaxFileNum = DEFAULT_MAX_WRL_FILE_NUM;
}
if(fMaxFileNum < 1)
{
fMaxFileNum = 1;
}
// maximum number of g4.prim files in the dest directory
fMaxFileNum = DEFAULT_MAX_WRL_FILE_NUM ; // initialization
if ( std::getenv( "G4VRMLFILE_MAX_FILE_NUM" ) != NULL ) {
sscanf( std::getenv("G4VRMLFILE_MAX_FILE_NUM"), "%d", &fMaxFileNum ) ;
// PV name pickability
if(std::getenv("G4VRML_PV_PICKABLE") != NULL)
{
int is_pickable;
sscanf(std::getenv("G4VRML_PV_PICKABLE"), "%d", &is_pickable);
} else {
fMaxFileNum = DEFAULT_MAX_WRL_FILE_NUM ;
}
if( fMaxFileNum < 1 ) { fMaxFileNum = 1; }
// PV name pickability
if( std::getenv( "G4VRML_PV_PICKABLE" ) != NULL ) {
int is_pickable ;
sscanf( std::getenv("G4VRML_PV_PICKABLE"), "%d", &is_pickable ) ;
if ( is_pickable ) { SetPVPickability ( true ) ; }
}
// PV Transparency
SetPVTransparency ();
if(is_pickable)
{
SetPVPickability(true);
}
}
// PV Transparency
SetPVTransparency();
}
G4VRML2FileSceneHandler::~G4VRML2FileSceneHandler()
{
#if defined DEBUG_FR_SCENE
if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
G4cout << "***** ~G4VRML2FileSceneHandler" << G4endl;
#endif
VRMLEndModeling();
if(G4VisManager::GetVerbosity() >= G4VisManager::errors)
G4cout << "***** ~G4VRML2FileSceneHandler" << G4endl;
#endif
VRMLEndModeling();
}
#define G4VRML2SCENEHANDLER G4VRML2FileSceneHandler
#define IS_CONNECTED this->isConnected()
#define G4VRML2SCENEHANDLER G4VRML2FileSceneHandler
#define IS_CONNECTED this->isConnected()
#include "G4VRML2SceneHandlerFunc.icc"
#undef IS_CONNECTED
#undef G4VRML2SCENEHANDLER
#undef IS_CONNECTED
#undef G4VRML2SCENEHANDLER
void G4VRML2FileSceneHandler::connectPort()
{
// g4_00.wrl, g4_01.wrl, ..., g4_MAX_FILE_INDEX.wrl
const int MAX_FILE_INDEX = fMaxFileNum - 1 ;
// g4_00.wrl, g4_01.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) ;
// dest directory (null if no environmental variables is set)
strcpy(fVRMLFileName, fVRMLFileDestDir);
// add filename if environment variable supplied
if(std::getenv(ENV_WRL_FILE_NAME))
{
strcat(fVRMLFileName, std::getenv(ENV_WRL_FILE_NAME));
}
else
{
// Determine VRML file name
for(int i = 0; i < fMaxFileNum; i++)
{
// Message in the final execution
if(i == MAX_FILE_INDEX)
{
if(G4VisManager::GetVerbosity() >= G4VisManager::errors)
{
G4cout << "===========================================" << G4endl;
G4cout << "WARNING MESSAGE from VRML2FILE driver: " << G4endl;
G4cout << " This file name is the final one in the " << G4endl;
G4cout << " automatic updation of the output file name." << G4endl;
G4cout << " You may overwrite existing files, i.e. " << G4endl;
G4cout << " g4_XX.wrl. " << G4endl;
G4cout << "===========================================" << G4endl;
}
}
// create full path name (default)
strcat ( fVRMLFileName, DEFAULT_WRL_FILE_NAME );
// re-determine file name as G4VRMLFILE_DEST_DIR/g4_XX.wrl
std::ostringstream filename;
filename << fVRMLFileDestDir;
if(std::getenv(ENV_WRL_FILE_HEADER) == NULL)
{
filename << WRL_FILE_HEADER;
}
else
{
filename << std::getenv(ENV_WRL_FILE_HEADER) << '_';
}
filename << std::setw(2) << std::setfill('0') << i << ".wrl";
strncpy(fVRMLFileName, filename.str().c_str(), sizeof(fVRMLFileName) - 1);
fVRMLFileName[sizeof(fVRMLFileName) - 1] = '\0';
// Determine VRML file name
for( int i = 0 ; i < fMaxFileNum ; i++) {
// check validity of the file name
std::ifstream fin;
fin.open(fVRMLFileName);
if(!fin)
{
// new file
fin.close();
break;
}
else
{
// already exists (try next)
fin.close();
}
// Message in the final execution
if( i == MAX_FILE_INDEX )
{
if (G4VisManager::GetVerbosity() >= G4VisManager::errors) {
G4cout << "===========================================" << G4endl;
G4cout << "WARNING MESSAGE from VRML2FILE driver: " << G4endl;
G4cout << " This file name is the final one in the " << G4endl;
G4cout << " automatic updation of the output file name." << G4endl;
G4cout << " You may overwrite existing files, i.e. " << G4endl;
G4cout << " g4_XX.wrl. " << G4endl;
G4cout << "===========================================" << G4endl;
}
}
} // for
}
// re-determine file name as G4VRMLFILE_DEST_DIR/g4_XX.wrl
std::ostringstream filename;
filename
<< fVRMLFileDestDir << WRL_FILE_HEADER
<< std::setw(2) << std::setfill('0') << i << ".wrl";
strncpy(fVRMLFileName,filename.str().c_str(),sizeof(fVRMLFileName)-1);
fVRMLFileName[sizeof(fVRMLFileName)-1] = '\0';
// check validity of the file name
std::ifstream fin ;
fin.open(fVRMLFileName) ;
if(!fin) {
// new file
fin.close();
break;
} else {
// already exists (try next)
fin.close();
}
} // for
// open a VRML 2.0 file with determined file name
if (G4VisManager::GetVerbosity() >= G4VisManager::errors) {
G4cout << "===========================================" << G4endl;
G4cout << "Output VRML 2.0 file: " << fVRMLFileName << G4endl;
G4cout << "Maximum number of files in the destination directory: " << fMaxFileNum << G4endl;
G4cout << " (Customizable with the environment variable: G4VRMLFILE_MAX_FILE_NUM) " << G4endl;
G4cout << "===========================================" << G4endl;
}
fDest.open(fVRMLFileName) ; fFlagDestOpen = true ;
// open a VRML 2.0 file with determined file name
if(G4VisManager::GetVerbosity() >= G4VisManager::errors)
{
G4cout << "===========================================" << G4endl;
G4cout << "Output VRML 2.0 file: " << fVRMLFileName << G4endl;
G4cout << "Maximum number of files in the destination directory: "
<< fMaxFileNum << G4endl;
G4cout << " (Customizable with the environment variable: "
"G4VRMLFILE_MAX_FILE_NUM) "
<< G4endl;
G4cout << "===========================================" << G4endl;
}
fDest.open(fVRMLFileName);
fFlagDestOpen = true;
}
void G4VRML2FileSceneHandler::closePort()
{
char command[256] ;
char viewer [256] ;
strcpy( viewer, NO_VRML_VIEWER ); // initialization
if( std::getenv( ENV_VRML_VIEWER ) ) {
strcpy( viewer, std::getenv( ENV_VRML_VIEWER ) ) ;
}
char command[256];
char viewer[256];
strcpy(viewer, NO_VRML_VIEWER); // initialization
if(std::getenv(ENV_VRML_VIEWER))
{
strcpy(viewer, std::getenv(ENV_VRML_VIEWER));
}
// close VRML file
fDest.close(); fFlagDestOpen = false ;
if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
G4cout << "*** VRML 2.0 File " << fVRMLFileName << " is generated." << G4endl;
// close VRML file
fDest.close();
fFlagDestOpen = false;
if(G4VisManager::GetVerbosity() >= G4VisManager::errors)
G4cout << "*** VRML 2.0 File " << fVRMLFileName << " is generated."
<< G4endl;
// Invoke viewer
// Invoke viewer
if ( !strcmp(viewer, NO_VRML_VIEWER )) {
if (G4VisManager::GetVerbosity() >= G4VisManager::errors) {
G4cout << "MESSAGE from VRML2FILE driver:" << G4endl;
G4cout << " Set an environmental variable " ;
G4cout << ENV_VRML_VIEWER << G4endl;
G4cout << " if you want to visualize the generated VRML file" << G4endl;
G4cout << " automatically. For example, " << G4endl;
G4cout << " setenv " << ENV_VRML_VIEWER << " vrwave " << G4endl;
}
} else {
std::ostringstream ossCommand;
ossCommand << viewer << ' ' << fVRMLFileName;
strncpy(command,ossCommand.str().c_str(),sizeof(command)-1);
command[sizeof(command)-1] = '\0';
int iErr = system( command );
if ( iErr != 0 ) {
G4ExceptionDescription ed;
ed << "Error " << iErr
<< " when calling system with \"" << command
<< "\".";
G4Exception("G4VRML2FileSceneHandler::closePort()",
"VRML-2006", JustWarning, ed);
}
}
if(!strcmp(viewer, NO_VRML_VIEWER))
{
if(G4VisManager::GetVerbosity() >= G4VisManager::errors)
{
G4cout << "MESSAGE from VRML2FILE driver:" << G4endl;
G4cout << " Set an environmental variable ";
G4cout << ENV_VRML_VIEWER << G4endl;
G4cout << " if you want to visualize the generated VRML file"
<< G4endl;
G4cout << " automatically. For example, " << G4endl;
G4cout << " setenv " << ENV_VRML_VIEWER << " vrwave " << G4endl;
G4cout << "ALSO you may change the file header with "
<< ENV_WRL_FILE_HEADER << G4endl;
G4cout << " or the whole filename with " << ENV_WRL_FILE_NAME
<< G4endl;
}
}
else
{
std::ostringstream ossCommand;
ossCommand << viewer << ' ' << fVRMLFileName;
strncpy(command, ossCommand.str().c_str(), sizeof(command) - 1);
command[sizeof(command) - 1] = '\0';
int iErr = system(command);
if(iErr != 0)
{
G4ExceptionDescription ed;
ed << "Error " << iErr << " when calling system with \"" << command
<< "\".";
G4Exception("G4VRML2FileSceneHandler::closePort()", "VRML-2006",
JustWarning, ed);
}
}
}
G4int G4VRML2FileSceneHandler::fSceneIdCount = 0;
@@ -28,7 +28,6 @@
// G4VRML2FileViewer.cc
// Satoshi Tanaka & Yasuhide Sawada
//#define DEBUG_FR_VIEW
#include <cmath>
@@ -42,116 +41,119 @@
#include "G4ios.hh"
G4VRML2FileViewer::G4VRML2FileViewer(G4VRML2FileSceneHandler& sceneHandler,
const G4String& name) :
G4VViewer(sceneHandler,
sceneHandler.IncrementViewCount(),
name),
fSceneHandler(sceneHandler),
fDest(sceneHandler.fDest)
const G4String& name)
: G4VViewer(sceneHandler, sceneHandler.IncrementViewCount(), name)
, fSceneHandler(sceneHandler)
, fDest(sceneHandler.fDest)
{
fViewHalfAngle = 30. * deg;
fsin_VHA = std::sin ( fViewHalfAngle ) ;
fsin_VHA = std::sin(fViewHalfAngle);
}
G4VRML2FileViewer::~G4VRML2FileViewer()
{}
G4VRML2FileViewer::~G4VRML2FileViewer() {}
void G4VRML2FileViewer::SetView()
{
#if defined DEBUG_FR_VIEW
if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
G4cout << "***** G4VRML2FileViewer::SetView(): No effects" << G4endl;
if(G4VisManager::GetVerbosity() >= G4VisManager::errors)
G4cout << "***** G4VRML2FileViewer::SetView(): No effects" << G4endl;
#endif
// Do nothing, since VRML a browser is running as a different process.
// SendViewParameters () will do this job instead.
// Do nothing, since VRML a browser is running as a different process.
// SendViewParameters () will do this job instead.
}
void G4VRML2FileViewer::DrawView()
{
#if defined DEBUG_FR_VIEW
if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
G4cout << "***** G4VRML2FileViewer::DrawView()" << G4endl;
if(G4VisManager::GetVerbosity() >= G4VisManager::errors)
G4cout << "***** G4VRML2FileViewer::DrawView()" << G4endl;
#endif
fSceneHandler.VRMLBeginModeling() ;
fSceneHandler.VRMLBeginModeling();
// Viewpoint node
SendViewParameters();
// Viewpoint node
SendViewParameters();
// Here is a minimal DrawView() function.
NeedKernelVisit();
ProcessView();
FinishView();
// Here is a minimal DrawView() function.
NeedKernelVisit();
ProcessView();
FinishView();
}
void G4VRML2FileViewer::ClearView(void)
{
#if defined DEBUG_FR_VIEW
if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
G4cout << "***** G4VRML2File1View::ClearView()" << G4endl;
if(G4VisManager::GetVerbosity() >= G4VisManager::errors)
G4cout << "***** G4VRML2File1View::ClearView()" << G4endl;
#endif
if(fSceneHandler.fFlagDestOpen) {
if(fSceneHandler.fFlagDestOpen)
{
fSceneHandler.fDest.close();
// Re-open with same filename...
fSceneHandler.fDest.open(fSceneHandler.fVRMLFileName);
fSceneHandler.fDest << "#VRML V2.0 utf8" << "\n";
fSceneHandler.fDest << "# Generated by VRML 2.0 driver of GEANT4\n" << "\n";
fSceneHandler.fDest << "#VRML V2.0 utf8"
<< "\n";
fSceneHandler.fDest << "# Generated by VRML 2.0 driver of GEANT4\n"
<< "\n";
}
}
void G4VRML2FileViewer::ShowView(void)
{
#if defined DEBUG_FR_VIEW
if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
G4cout << "***** G4VRML2FileViewer::ShowView()" << G4endl;
if(G4VisManager::GetVerbosity() >= G4VisManager::errors)
G4cout << "***** G4VRML2FileViewer::ShowView()" << G4endl;
#endif
fSceneHandler.VRMLEndModeling();
fSceneHandler.VRMLEndModeling();
}
void G4VRML2FileViewer::FinishView(void)
{
#if defined DEBUG_FR_VIEW
if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
G4cout << "***** G4VRML2FileViewer::FinishView(): No effects" << G4endl;
if(G4VisManager::GetVerbosity() >= G4VisManager::errors)
G4cout << "***** G4VRML2FileViewer::FinishView(): No effects" << G4endl;
#endif
}
void G4VRML2FileViewer::SendViewParameters ()
void G4VRML2FileViewer::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
if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
G4cout << "***** G4VRML2FileViewer::SendViewParameters()\n";
#endif
if(G4VisManager::GetVerbosity() >= G4VisManager::errors)
G4cout << "***** G4VRML2FileViewer::SendViewParameters()\n";
#endif
// error recovery
if ( fsin_VHA < 1.0e-6 ) { return ; }
// error recovery
if(fsin_VHA < 1.0e-6)
{
return;
}
// camera distance
G4double extent_radius = fSceneHandler.GetScene()->GetExtent().GetExtentRadius();
G4double camera_distance = extent_radius / fsin_VHA ;
// camera distance
G4double extent_radius =
fSceneHandler.GetScene()->GetExtent().GetExtentRadius();
G4double camera_distance = extent_radius / fsin_VHA;
// camera position on Z axis
const G4Point3D& target_point
= fSceneHandler.GetScene()->GetStandardTargetPoint()
+ fVP.GetCurrentTargetPoint();
G4double E_z = target_point.z() + camera_distance;
G4Point3D E(0.0, 0.0, E_z );
// VRML codes are generated below
fDest << G4endl;
fDest << "#---------- CAMERA" << G4endl;
fDest << "Viewpoint {" << G4endl;
fDest << "\t" << "position " ;
fDest << E.x() << " " ;
fDest << E.y() << " " ;
fDest << E.z() << G4endl ;
fDest << "}" << G4endl;
fDest << G4endl;
// camera position on Z axis
const G4Point3D& target_point =
fSceneHandler.GetScene()->GetStandardTargetPoint() +
fVP.GetCurrentTargetPoint();
G4double E_z = target_point.z() + camera_distance;
G4Point3D E(0.0, 0.0, E_z);
// VRML codes are generated below
fDest << G4endl;
fDest << "#---------- CAMERA" << G4endl;
fDest << "Viewpoint {" << G4endl;
fDest << "\t"
<< "position ";
fDest << E.x() << " ";
fDest << E.y() << " ";
fDest << E.z() << G4endl;
fDest << "}" << G4endl;
fDest << G4endl;
}
@@ -1,155 +0,0 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
//
//
// G4VRML2SceneHandler.cc
// Satoshi Tanaka & Yasuhide Sawada
#ifndef WIN32
//=================//
#ifdef G4VIS_BUILD_VRML_DRIVER
//=================//
//#define DEBUG_FR_SCENE
#include <unistd.h>
#include <fstream>
#include <cmath>
#include "globals.hh"
#include "G4VisManager.hh"
#include "G4VPhysicalVolume.hh"
#include "G4LogicalVolume.hh"
#include "G4Point3D.hh"
#include "G4VModel.hh"
#include "G4Scene.hh"
#include "G4VisAttributes.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 "G4VRML2SceneHandler.hh"
#include "G4VRML2Viewer.hh"
#include "G4VRML2.hh"
G4VRML2SceneHandler::G4VRML2SceneHandler(G4VRML2& system, const G4String& name) :
G4VSceneHandler(system, fSceneIdCount++, name),
fSystem(system),
fPVPickable ( false ),
fDest()
{
// PV name pickability
if( std::getenv( "G4VRML_PV_PICKABLE" ) != NULL ) {
int is_pickable ;
sscanf( std::getenv("G4VRML_PV_PICKABLE"), "%d", &is_pickable ) ;
if ( is_pickable ) { SetPVPickability ( true ) ; }
}
// PV Transparency
SetPVTransparency ();
}
G4VRML2SceneHandler::~G4VRML2SceneHandler()
{
#if defined DEBUG_FR_SCENE
if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
G4cout << "***** ~G4VRML2SceneHandler" << G4endl;
#endif
}
#define G4VRML2SCENEHANDLER G4VRML2SceneHandler
#define IS_CONNECTED fDest.isConnected()
#include "G4VRML2SceneHandlerFunc.icc"
#undef IS_CONNECTED
#undef G4VRML2SCENEHANDLER
void G4VRML2SceneHandler::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
if (G4VisManager::GetVerbosity() >= G4VisManager::errors) {
G4cout << "*** GEANT4 is connected to port ";
G4cout << fDest.getPort();
G4cout << " of server " << fSystem.getHostName() << G4endl;
}
break;
} else {
// Connection failed. Try the next port.
if (G4VisManager::GetVerbosity() >= G4VisManager::errors) {
G4cout << "*** GEANT4 incremented targeting port to ";
G4cout << port << G4endl;
}
}
sleep (1);
} // for
if (!fDest.isConnected()) {
if (G4VisManager::GetVerbosity() >= G4VisManager::errors) {
G4cout << "*** INET Connection failed. " << G4endl;
G4cout << " Maybe, you have not invoked viewer g4vrmlview yet, " << G4endl;
G4cout << " or too many viewers are already running in the " << G4endl;
G4cout << " server host(" << fSystem.getHostName() << "). " << G4endl;
}
}
}
void G4VRML2SceneHandler::closePort()
{
fDest.close();
if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
G4cout << "*** INET Connection closed. " << G4endl;
}
G4int G4VRML2SceneHandler::fSceneIdCount = 0;
#endif
#endif //WIN32
File diff suppressed because it is too large Load Diff
@@ -1,158 +0,0 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
//
//
// G4VRML2Viewer.cc
// Satoshi Tanaka & Yasuhide Sawada
#ifndef WIN32
//=================//
#ifdef G4VIS_BUILD_VRML_DRIVER
//=================//
//#define DEBUG_FR_VIEW
#include <cmath>
#include "G4VisManager.hh"
#include "G4Scene.hh"
#include "G4VRML2Viewer.hh"
#include "G4VRML2SceneHandler.hh"
#include "G4VRML2.hh"
#include "G4ios.hh"
G4VRML2Viewer::G4VRML2Viewer(G4VRML2SceneHandler& sceneHandler, const G4String& name) :
G4VViewer(sceneHandler,
sceneHandler.IncrementViewCount(),
name),
fSceneHandler(sceneHandler),
fDest(sceneHandler.fDest)
{
fViewHalfAngle = 0.5 * 0.785398 ; // 0.5 * 45*deg
fsin_VHA = std::sin ( fViewHalfAngle ) ;
}
G4VRML2Viewer::~G4VRML2Viewer()
{}
void G4VRML2Viewer::SetView()
{
#if defined DEBUG_FR_VIEW
if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
G4cout << "***** G4VRML2Viewer::SetView(): No effects" << G4endl;
#endif
// Do nothing, since VRML a browser is running as a different process.
// SendViewParameters () will do this job instead.
}
void G4VRML2Viewer::DrawView()
{
#if defined DEBUG_FR_VIEW
if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
G4cout << "***** G4VRML2Viewer::DrawView()" << G4endl;
#endif
fSceneHandler.VRMLBeginModeling() ;
// Viewpoint node
SendViewParameters();
// Here is a minimal DrawView() function.
NeedKernelVisit();
ProcessView();
FinishView();
}
void G4VRML2Viewer::ClearView(void)
{
#if defined DEBUG_FR_VIEW
if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
G4cout << "***** G4VRML2Viewer::ClearView(): No effects" << G4endl;
#endif
}
void G4VRML2Viewer::ShowView(void)
{
#if defined DEBUG_FR_VIEW
if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
G4cout << "***** G4VRML2Viewer::ShowView()" << G4endl;
#endif
fSceneHandler.VRMLEndModeling();
}
void G4VRML2Viewer::FinishView(void)
{
#if defined DEBUG_FR_VIEW
if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
G4cout << "***** G4VRML2Viewer::FinishView(): No effects" << G4endl;
#endif
}
void G4VRML2Viewer::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
if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
G4cout << "***** G4VRML2Viewer::SendViewParameters()\n";
#endif
// error recovery
if ( fsin_VHA < 1.0e-6 ) { return ; }
// camera distance
G4double extent_radius = fSceneHandler.GetScene()->GetExtent().GetExtentRadius();
G4double camera_distance = extent_radius / fsin_VHA ;
// camera position on Z axis
const G4Point3D& target_point
= fSceneHandler.GetScene()->GetStandardTargetPoint()
+ fVP.GetCurrentTargetPoint();
G4double E_z = target_point.z() + camera_distance;
G4Point3D E(0.0, 0.0, E_z );
// VRML codes are generated below
fDest << "\n";
fDest << "#---------- CAMERA" << "\n";
fDest << "Viewpoint {" << "\n";
fDest << "\t" << "position " ;
fDest << E.x() << " " ;
fDest << E.y() << " " ;
fDest << E.z() << "\n" ;
fDest << "}" << "\n";
fDest << "\n";
}
#endif
#endif //WIN32