Import Geant4 4.1.0 source tree

This commit is contained in:
Gabriele Cosmo
2016-06-08 16:39:52 +02:00
parent 921d3b1cda
commit 330b82b769
4524 changed files with 178689 additions and 43575 deletions
@@ -21,13 +21,13 @@
// ********************************************************************
//
//
// $Id: G4HepRepFileSceneHandler.cc,v 1.3 2001/11/19 15:07:28 johna Exp $
// GEANT4 tag $Name: geant4-04-00 $
// $Id: G4HepRepFileSceneHandler.cc,v 1.7 2002/02/03 22:22:58 perl Exp $
// GEANT4 tag $Name: geant4-04-01 $
//
//
// John Allison 5th April 2001
// A base class for a scene handler to dump geometry hierarchy.
// Based on a provisional G4HepRepFileGraphicsScene (was in modeling).
// Joseph Perl 27th January 2002
// A base class for a scene handler to export geometry and trajectories
// to the HepRep xml file format.
#include "G4HepRepFileSceneHandler.hh"
#include "G4HepRepFile.hh"
@@ -65,12 +65,39 @@ G4HepRepFileSceneHandler::G4HepRepFileSceneHandler(G4VGraphicsSystem& system,
fSceneCount++;
hepRepXMLWriter = ((G4HepRepFile*)(&system))->GetHepRepXMLWriter();
G4cout << " From scene handler const: opening file, G4HepRepFile.xml"
<< G4endl;
fileCounter = 0;
}
G4HepRepFileSceneHandler::~G4HepRepFileSceneHandler() {}
void G4HepRepFileSceneHandler::EstablishSpecials
(G4PhysicalVolumeModel& pvModel) {
pvModel.DefinePointersToWorkingSpace (&fCurrentDepth,
&fpCurrentPV,
&fpCurrentLV);
}
void G4HepRepFileSceneHandler::BeginModeling() {
G4VSceneHandler::BeginModeling(); // Required: see G4VSceneHandler.hh.
// Force culling off...
if (fpModel) {
fpOriginalMP = fpModel->GetModelingParameters();
if (fpOriginalMP) {
fpNonCullingMP = new G4ModelingParameters(*fpOriginalMP);
fpNonCullingMP->SetCulling(false);
fpModel->SetModelingParameters(fpNonCullingMP);
}
}
}
void G4HepRepFileSceneHandler::EndModeling() {
if (fpModel && fpOriginalMP) {
fpModel->SetModelingParameters(fpOriginalMP);
delete fpNonCullingMP;
}
G4VSceneHandler::EndModeling(); // Required: see G4VSceneHandler.hh.
}
#ifdef G4HEPREPFILEDEBUG
void G4HepRepFileSceneHandler::PrintThings() {
G4cout <<
@@ -97,7 +124,6 @@ void G4HepRepFileSceneHandler::AddThis(const G4Box& box) {
<< G4endl;
PrintThings();
#endif
hepRepXMLWriter->addType(fpCurrentPV->GetName());
G4VSceneHandler::AddThis(box); // Invoke default action.
}
@@ -109,7 +135,6 @@ void G4HepRepFileSceneHandler::AddThis(const G4Cons& cons) {
<< G4endl;
PrintThings();
#endif
hepRepXMLWriter->addType(fpCurrentPV->GetName());
G4VSceneHandler::AddThis(cons); // Invoke default action.
}
@@ -121,7 +146,6 @@ void G4HepRepFileSceneHandler::AddThis(const G4Tubs& tubs) {
<< G4endl;
PrintThings();
#endif
hepRepXMLWriter->addType(fpCurrentPV->GetName());
G4VSceneHandler::AddThis(tubs); // Invoke default action.
}
@@ -133,7 +157,6 @@ void G4HepRepFileSceneHandler::AddThis(const G4Trd& trd) {
<< G4endl;
PrintThings();
#endif
hepRepXMLWriter->addType(fpCurrentPV->GetName());
G4VSceneHandler::AddThis(trd); // Invoke default action.
}
@@ -145,7 +168,6 @@ void G4HepRepFileSceneHandler::AddThis(const G4Trap& trap) {
<< G4endl;
PrintThings();
#endif
hepRepXMLWriter->addType(fpCurrentPV->GetName());
G4VSceneHandler::AddThis(trap); // Invoke default action.
}
@@ -157,7 +179,6 @@ void G4HepRepFileSceneHandler::AddThis(const G4Sphere& sphere) {
<< G4endl;
PrintThings();
#endif
hepRepXMLWriter->addType(fpCurrentPV->GetName());
G4VSceneHandler::AddThis(sphere); // Invoke default action.
}
@@ -169,7 +190,6 @@ void G4HepRepFileSceneHandler::AddThis(const G4Para& para) {
<< G4endl;
PrintThings();
#endif
hepRepXMLWriter->addType(fpCurrentPV->GetName());
G4VSceneHandler::AddThis(para); // Invoke default action.
}
@@ -181,7 +201,6 @@ void G4HepRepFileSceneHandler::AddThis(const G4Torus& torus) {
<< G4endl;
PrintThings();
#endif
hepRepXMLWriter->addType(fpCurrentPV->GetName());
G4VSceneHandler::AddThis(torus); // Invoke default action.
}
@@ -193,7 +212,6 @@ void G4HepRepFileSceneHandler::AddThis(const G4Polycone& polycone) {
<< G4endl;
PrintThings();
#endif
hepRepXMLWriter->addType(fpCurrentPV->GetName());
G4VSceneHandler::AddThis(polycone); // Invoke default action.
}
@@ -205,7 +223,6 @@ void G4HepRepFileSceneHandler::AddThis(const G4Polyhedra& polyhedra) {
<< G4endl;
PrintThings();
#endif
hepRepXMLWriter->addType(fpCurrentPV->GetName());
G4VSceneHandler::AddThis(polyhedra); // Invoke default action.
}
@@ -217,7 +234,6 @@ void G4HepRepFileSceneHandler::AddThis(const G4VSolid& solid) {
<< G4endl;
PrintThings();
#endif
hepRepXMLWriter->addType(fpCurrentPV->GetName());
G4VSceneHandler::AddThis(solid); // Invoke default action.
}
@@ -231,11 +247,7 @@ void G4HepRepFileSceneHandler::AddPrimitive(const G4Polyline& polyline) {
PrintThings();
#endif
hepRepXMLWriter->addInstance();
hepRepXMLWriter->addAttValue("DrawAs","Line");
G4Colour color = GetColour(polyline);
hepRepXMLWriter->addAttValue("LineColor", color.GetRed(), color.GetGreen(), color.GetBlue());
AddHepRepInstance("Line",polyline);
hepRepXMLWriter->addPrimitive();
@@ -254,15 +266,10 @@ void G4HepRepFileSceneHandler::AddPrimitive (const G4Polymarker& line) {
PrintThings();
#endif
hepRepXMLWriter->addInstance();
hepRepXMLWriter->addAttValue("DrawAs","Point");
AddHepRepInstance("Point",line);
// FIXME: should be taken from G4
hepRepXMLWriter->addAttValue("MarkName", "Square");
hepRepXMLWriter->addAttValue("MarkSize", 5);
G4Colour color = GetColour(line);
hepRepXMLWriter->addAttValue("LineColor", color.GetRed(), color.GetGreen(), color.GetBlue());
hepRepXMLWriter->addAttValue("MarkName", "Dot");
hepRepXMLWriter->addAttValue("MarkSize", 4);
hepRepXMLWriter->addPrimitive();
@@ -292,18 +299,13 @@ void G4HepRepFileSceneHandler::AddPrimitive(const G4Circle& circle) {
PrintThings();
#endif
hepRepXMLWriter->addInstance();
hepRepXMLWriter->addAttValue("DrawAs","Point");
AddHepRepInstance("Point",circle);
hepRepXMLWriter->addAttValue("MarkName", "Dot");
G4Colour color = GetColour(circle);
hepRepXMLWriter->addAttValue("LineColor", color.GetRed(), color.GetGreen(), color.GetBlue());
hepRepXMLWriter->addAttValue("MarkSize", 4);
hepRepXMLWriter->addPrimitive();
G4double radius = circle.GetWorldSize();
hepRepXMLWriter->addAttValue("MarkSize", radius);
G4Point3D center = (*fpObjectTransformation) * circle.GetPosition();
hepRepXMLWriter->addPoint(center.x(), center.y(), center.z());
}
@@ -317,18 +319,13 @@ void G4HepRepFileSceneHandler::AddPrimitive(const G4Square& square) {
PrintThings();
#endif
hepRepXMLWriter->addInstance();
hepRepXMLWriter->addAttValue("DrawAs","Point");
hepRepXMLWriter->addAttValue("MarkName", "Square");
AddHepRepInstance("Point",square);
G4Colour color = GetColour(square);
hepRepXMLWriter->addAttValue("LineColor", color.GetRed(), color.GetGreen(), color.GetBlue());
hepRepXMLWriter->addAttValue("MarkName", "Square");
hepRepXMLWriter->addAttValue("MarkSize", 4);
hepRepXMLWriter->addPrimitive();
G4double size = square.GetWorldSize();
hepRepXMLWriter->addAttValue("MarkSize", size);
G4Point3D center = (*fpObjectTransformation) * square.GetPosition();
hepRepXMLWriter->addPoint(center.x(), center.y(), center.z());
}
@@ -340,26 +337,14 @@ void G4HepRepFileSceneHandler::AddPrimitive(const G4Polyhedron& polyhedron) {
<< G4endl;
PrintThings();
#endif
AddHepRepInstance("Polygon",polyhedron);
if(polyhedron.GetNoFacets()==0)return;
G4Normal3D surfaceNormal;
G4Point3D vertex;
hepRepXMLWriter->addInstance();
hepRepXMLWriter->addAttValue("DrawAs","Polygon");
G4Colour color = GetColour(polyhedron);
hepRepXMLWriter->addAttValue("LineColor", color.GetRed(), color.GetGreen(), color.GetBlue());
// Additional attributes.
hepRepXMLWriter->addAttValue("LVol", fpCurrentLV->GetName());
hepRepXMLWriter->addAttValue("Solid", fpCurrentLV->GetSolid()->GetName());
hepRepXMLWriter->addAttValue("EType", fpCurrentLV->GetSolid()->GetEntityType());
hepRepXMLWriter->addAttValue("Material", fpCurrentLV->GetMaterial()->GetName());
hepRepXMLWriter->addAttValue("Density", fpCurrentLV->GetMaterial()->GetDensity());
hepRepXMLWriter->addAttValue("State", fpCurrentLV->GetMaterial()->GetState());
hepRepXMLWriter->addAttValue("Radlen", fpCurrentLV->GetMaterial()->GetRadlen());
G4bool notLastFace;
do {
hepRepXMLWriter->addPrimitive();
@@ -385,13 +370,112 @@ void G4HepRepFileSceneHandler::AddPrimitive(const G4NURBS& nurbs) {
G4cout << "G4HepRepFileSceneHandler::AddPrimitive G4NURBS : not implemented. " << G4endl;
}
void G4HepRepFileSceneHandler::EstablishSpecials
(G4PhysicalVolumeModel& pvModel) {
pvModel.DefinePointersToWorkingSpace(&fCurrentDepth,
&fpCurrentPV,
&fpCurrentLV);
}
HepRepXMLWriter *G4HepRepFileSceneHandler::GetHepRepXMLWriter() {
return hepRepXMLWriter;
}
void G4HepRepFileSceneHandler::AddHepRepInstance(const char* primName,
const G4Visible visible) {
#ifdef G4HEPREPFILEDEBUG
G4cout <<
"G4HepRepFileSceneHandler::AddHepRepInstance called."
<< G4endl;
#endif
if (!hepRepXMLWriter->isOpen) {
char* newFileSpec;
newFileSpec = new char [100];
int length;
length = sprintf (newFileSpec, "%s%d%s","G4Data",fileCounter,".heprep");
hepRepXMLWriter->open(newFileSpec);
fileCounter++;
hepRepXMLWriter->addAttDef("LVol", "Logical Volume", "Physics","");
hepRepXMLWriter->addAttDef("Solid", "Solid Name", "Physics","");
hepRepXMLWriter->addAttDef("EType", "Entity Type", "Physics","");
hepRepXMLWriter->addAttDef("Material", "Material Name", "Physics","");
hepRepXMLWriter->addAttDef("Density", "Material Density", "Physics","");
hepRepXMLWriter->addAttDef("State", "Material State", "Physics","");
hepRepXMLWriter->addAttDef("Radlen", "Material Radiation Length", "Physics","");
}
// Handle Type declaration for Event Data.
// Should be able to just test on fReadyForTransients, but this seems to
// be falsely false if no geometry has yet been drawn.
// So I test on both !fpCurrentPV (means no geometry has yet been drawn)
// and fReadyForTransients.
if (!fpCurrentPV || fReadyForTransients) {
if (strcmp("Event Data",hepRepXMLWriter->prevTypeName[0])!=0) {
hepRepXMLWriter->addType("Event Data",0);
hepRepXMLWriter->addInstance();
}
if (strcmp("Line",primName)==0)
hepRepXMLWriter->addType("Trajectories",1);
else {
if (strcmp(hepRepXMLWriter->prevTypeName[1],"Trajectories")==0)
hepRepXMLWriter->addType("Trajectory Points",2);
else
hepRepXMLWriter->addType("Trajectory Points",1);
}
hepRepXMLWriter->addInstance();
// Handle Type declaration for Detector Geometry,
// replacing G4's top geometry level name "worldPhysical" with the
// name "Detector Geometry".
} else {
if (strcmp("Detector Geometry",hepRepXMLWriter->prevTypeName[0])!=0) {
hepRepXMLWriter->addType("Detector Geometry",0);
hepRepXMLWriter->addInstance();
}
// Re-insert any layers of the hierarchy that were removed by G4's culling process.
while (hepRepXMLWriter->typeDepth < (fCurrentDepth-1)) {
hepRepXMLWriter->addType("G4 Culled Layer", hepRepXMLWriter->typeDepth + 1);
hepRepXMLWriter->addInstance();
}
if (fCurrentDepth!=0) {
// Add the HepRepType for the current volume.
hepRepXMLWriter->addType(fpCurrentPV->GetName(),fCurrentDepth);
hepRepXMLWriter->addInstance();
}
// Additional attributes.
hepRepXMLWriter->addAttValue("LVol", fpCurrentLV->GetName());
hepRepXMLWriter->addAttValue("Solid", fpCurrentLV->GetSolid()->GetName());
hepRepXMLWriter->addAttValue("EType", fpCurrentLV->GetSolid()->GetEntityType());
hepRepXMLWriter->addAttValue("Material", fpCurrentLV->GetMaterial()->GetName());
hepRepXMLWriter->addAttValue("Density", fpCurrentLV->GetMaterial()->GetDensity());
hepRepXMLWriter->addAttValue("State", fpCurrentLV->GetMaterial()->GetState());
hepRepXMLWriter->addAttValue("Radlen", fpCurrentLV->GetMaterial()->GetRadlen());
}
hepRepXMLWriter->addAttValue("DrawAs",primName);
hepRepXMLWriter->addAttValue("Layer",hepRepXMLWriter->typeDepth);
// Handle color attribute, avoiding drawing anything black on black.
G4Colour colour = GetColour(visible);
float redness = colour.GetRed();
float greenness = colour.GetGreen();
float blueness = colour.GetBlue();
if (redness==0. && greenness==0. && blueness==0.) {
redness = 1.;
greenness = 1.;
blueness = 1.;
}
if (strcmp(primName,"Point")==0)
hepRepXMLWriter->addAttValue("MarkColor",redness,greenness,blueness);
else
hepRepXMLWriter->addAttValue("LineColor",redness,greenness,blueness);
// Handle visibility attribute.
const G4VisAttributes* visAtts = visible.GetVisAttributes();
if (visAtts && (visAtts->IsVisible()==0))
hepRepXMLWriter->addAttValue("Visibility",false);
else
hepRepXMLWriter->addAttValue("Visibility",true);
}