G4HepRepSceneHandler Class Reference

#include <G4HepRepSceneHandler.hh>

Inheritance diagram for G4HepRepSceneHandler:

G4VSceneHandler G4VGraphicsScene

Public Member Functions

 G4HepRepSceneHandler (G4VGraphicsSystem &system, const G4String &name="")
virtual ~G4HepRepSceneHandler ()
void AddSolid (const G4Box &box)
void AddSolid (const G4Cons &cons)
void AddSolid (const G4Tubs &tubs)
void AddSolid (const G4Trd &trd)
void AddSolid (const G4Trap &trap)
void AddSolid (const G4Sphere &sphere)
void AddSolid (const G4Para &para)
void AddSolid (const G4Torus &torus)
void AddSolid (const G4Polycone &polycone)
void AddSolid (const G4Polyhedra &polyhedra)
void AddSolid (const G4VSolid &solid)
void AddCompound (const G4VTrajectory &)
void AddCompound (const G4VHit &hit)
void AddCompound (const G4VDigi &digi)
void AddCompound (const G4THitsMap< G4double > &hits)
void PreAddSolid (const G4Transform3D &objectTransformation, const G4VisAttributes &visAttribs)
void PostAddSolid ()
void AddPrimitive (const G4Polyline &)
void AddPrimitive (const G4Text &)
void AddPrimitive (const G4Circle &)
void AddPrimitive (const G4Square &)
void AddPrimitive (const G4Polyhedron &)
void AddPrimitive (const G4NURBS &)
void AddPrimitive (const G4Polymarker &)
void AddPrimitive (const G4Scale &scale)
void BeginPrimitives (const G4Transform3D &objectTransformation)
void EndPrimitives ()
void BeginModeling ()
void EndModeling ()
void openHepRep ()
bool closeHepRep (bool final=false)
void openFile (G4String name)
void closeFile ()

Detailed Description

Definition at line 64 of file G4HepRepSceneHandler.hh.


Constructor & Destructor Documentation

G4HepRepSceneHandler::G4HepRepSceneHandler ( G4VGraphicsSystem system,
const G4String name = "" 
)

Definition at line 93 of file G4HepRepSceneHandler.cc.

References kStateGas, kStateLiquid, kStateSolid, kStateUndefined, and openHepRep().

00094         : G4VSceneHandler (system, sceneIdCount++, name),
00095           geometryLayer         ("Geometry"),
00096           eventLayer            ("Event"),
00097           calHitLayer           ("CalHit"),
00098           trajectoryLayer       ("Trajectory"),
00099           hitLayer              ("Hit"),
00100           rootVolumeName        ("Geometry"),
00101           baseName              (""),
00102           eventNumberPrefix     (""),
00103           eventNumberSuffix     (""),
00104           eventNumber           (1),
00105           eventNumberWidth      (-1),
00106           extension             (""),
00107           writeBinary           (false),
00108           writeZip              (false),
00109           writeGZ               (false),
00110           writeMultipleFiles    (false),
00111           currentHit            (NULL),
00112           currentTrack          (NULL),
00113           _heprep               (NULL),
00114           _heprepGeometry       (NULL)
00115 {
00116 
00117 #ifdef LDEBUG
00118     cout << "G4HepRepSceneHandler::G4HepRepSceneHandler: " << system << endl;
00119 #endif
00120 
00121     materialState[kStateSolid]      = G4String("Solid");
00122     materialState[kStateLiquid]     = G4String("Liquid");
00123     materialState[kStateGas]        = G4String("Gas");
00124     materialState[kStateUndefined]  = G4String("Undefined");    
00125 
00126     factory = new XMLHepRepFactory();
00127     writer = NULL;
00128     
00129     // opening of file deferred to closeHepRep();
00130     openHepRep();
00131 }

G4HepRepSceneHandler::~G4HepRepSceneHandler (  )  [virtual]

Definition at line 134 of file G4HepRepSceneHandler.cc.

References G4VSceneHandler::GetGraphicsSystem().

00134                                              {
00135 #ifdef LDEBUG
00136     cout << "G4HepRepSceneHandler::~G4HepRepSceneHandler() " << endl;
00137 #endif
00138     close();
00139 
00140     delete factory;
00141     factory = NULL;
00142 
00143     dynamic_cast<G4HepRep*>(GetGraphicsSystem())->removeSceneHandler();
00144 }


Member Function Documentation

void G4HepRepSceneHandler::AddCompound ( const G4THitsMap< G4double > &  hits  )  [inline, virtual]

Reimplemented from G4VSceneHandler.

Definition at line 87 of file G4HepRepSceneHandler.hh.

References G4VSceneHandler::AddCompound().

00087                                                             {
00088           G4VSceneHandler::AddCompound(hits);
00089         }

void G4HepRepSceneHandler::AddCompound ( const G4VDigi digi  )  [inline, virtual]

Reimplemented from G4VSceneHandler.

Definition at line 84 of file G4HepRepSceneHandler.hh.

References G4VSceneHandler::AddCompound().

00084                                                {
00085           G4VSceneHandler::AddCompound(digi);
00086         }

void G4HepRepSceneHandler::AddCompound ( const G4VHit hit  )  [virtual]

Reimplemented from G4VSceneHandler.

Definition at line 1049 of file G4HepRepSceneHandler.cc.

References G4VSceneHandler::AddCompound().

01049                                                          { 
01050 #ifdef PDEBUG
01051     cout << "G4HepRepSceneHandler::AddCompound(G4VHit&) " << endl;
01052 #endif
01053     if (dontWrite()) return;
01054     
01055     currentHit = &hit;
01056     G4VSceneHandler::AddCompound(hit); 
01057     currentHit = NULL;
01058 }

void G4HepRepSceneHandler::AddCompound ( const G4VTrajectory  )  [virtual]

Reimplemented from G4VSceneHandler.

Definition at line 1037 of file G4HepRepSceneHandler.cc.

References G4VSceneHandler::AddCompound().

01037                                                                        {
01038 #ifdef PDEBUG
01039     cout << "G4HepRepSceneHandler::AddCompound(G4VTrajectory&) " << endl;
01040 #endif
01041     if (dontWrite()) return;
01042     
01043     currentTrack = &trajectory;
01044     G4VSceneHandler::AddCompound(trajectory); 
01045     currentTrack = NULL;    
01046 }

void G4HepRepSceneHandler::AddPrimitive ( const G4Scale scale  )  [virtual]

Reimplemented from G4VSceneHandler.

Definition at line 1032 of file G4HepRepSceneHandler.cc.

References G4VSceneHandler::AddPrimitive().

01032                                                              { 
01033     if (dontWrite()) return;
01034     G4VSceneHandler::AddPrimitive(scale); 
01035 }

void G4HepRepSceneHandler::AddPrimitive ( const G4Polymarker  )  [virtual]

Reimplemented from G4VSceneHandler.

Definition at line 804 of file G4HepRepSceneHandler.cc.

References G4Polymarker::circles, G4Polymarker::dots, G4VSceneHandler::fProcessing2D, G4Exception(), G4VSceneHandler::GetColor(), G4Polymarker::GetMarkerType(), JustWarning, and G4Polymarker::squares.

00804                                                                  {
00805 
00806 #ifdef PDEBUG
00807     cout << "G4HepRepSceneHandler::AddPrimitive(G4Polymarker&) " << line.size() << endl;
00808 #endif
00809     if (dontWrite()) return;
00810 
00811     if (fProcessing2D) {
00812       static G4bool warned = false;
00813       if (!warned) {
00814         warned = true;
00815         G4Exception
00816           ("G4HepRepSceneHandler::AddPrimitive (const G4Polymarker&)",
00817            "vis-HepRep1002", JustWarning,
00818            "2D polymarkers not implemented.  Ignored.");
00819       }
00820       return;
00821     }
00822 
00823     HepRepInstance* instance = factory->createHepRepInstance(getEventInstance(), getHitType());
00824 
00825     addAttributes(instance, getHitType());
00826 
00827     setColor(instance, GetColor(line));
00828 
00829     setVisibility(instance, line);
00830 
00831     setMarker(instance, line);
00832 
00833     // Default MarkName is set to Circle for this Type.
00834     int mtype = line.GetMarkerType();
00835     
00836     // Cannot be case statement since line.xxx is not a constant
00837     if (mtype == line.dots) {
00838         setAttribute(instance, "Fill", true);
00839         setColor(instance, GetColor(line), G4String("FillColor"));
00840     } else if (mtype == line.circles) {
00841     } else if (line.squares) {
00842         setAttribute(instance, "MarkName", G4String("Box"));
00843     } else {
00844         // line.line + default
00845         setAttribute(instance, "MarkName", G4String("Plus"));
00846     }
00847 
00848     for (size_t i=0; i < line.size(); i++) {
00849         G4Point3D vertex = transform * line[i];
00850         factory->createHepRepPoint(instance, vertex.x(), vertex.y(), vertex.z());
00851     }
00852 }

void G4HepRepSceneHandler::AddPrimitive ( const G4NURBS  )  [virtual]

Implements G4VSceneHandler.

Definition at line 1009 of file G4HepRepSceneHandler.cc.

01009                                                        {
01010 #ifdef PDEBUG
01011     cout << "G4HepRepSceneHandler::AddPrimitive(G4NURBS&) " << endl;
01012 #endif
01013     if (dontWrite()) return;
01014 
01015     /*** You may need this
01016     if (fProcessing2D) {
01017       static G4bool warned = false;
01018       if (!warned) {
01019         warned = true;
01020         G4Exception
01021           ("G4HepRepSceneHandler::AddPrimitive (const G4NURBS&)",
01022            "vis-HepRep1007", JustWarning,
01023            "2D NURBS not implemented.  Ignored.");
01024       }
01025       return;
01026     }
01027     ***/
01028 
01029     cout << "G4HepRepSceneHandler::AddPrimitive G4NURBS : not yet implemented. " << endl;
01030 }

void G4HepRepSceneHandler::AddPrimitive ( const G4Polyhedron  )  [virtual]

Implements G4VSceneHandler.

Definition at line 889 of file G4HepRepSceneHandler.cc.

References G4VSceneHandler::fpModel, G4VSceneHandler::fProcessing2D, G4Exception(), G4VSceneHandler::GetColor(), G4PhysicalVolumeModel::GetCurrentDepth(), and JustWarning.

00889                                                                        {
00890 
00891 #ifdef PDEBUG
00892     cout << "G4HepRepSceneHandler::AddPrimitive(G4Polyhedron&) " << endl;
00893 #endif
00894     if (dontWrite()) return;
00895 
00896     if (fProcessing2D) {
00897       static G4bool warned = false;
00898       if (!warned) {
00899         warned = true;
00900         G4Exception
00901           ("G4HepRepSceneHandler::AddPrimitive (const G4Polyhedron&)",
00902            "vis-HepRep1004", JustWarning,
00903            "2D polyhedra not implemented.  Ignored.");
00904       }
00905       return;
00906     }
00907 
00908     G4Normal3D surfaceNormal;
00909     G4Point3D vertex;
00910 
00911     if (polyhedron.GetNoFacets()==0) return;
00912 
00913     HepRepInstance* instance = getGeometryOrEventInstance(getCalHitType());
00914         
00915     addAttributes(instance, getCalHitType());
00916 
00917     setVisibility(instance, polyhedron);
00918         
00919     G4int currentDepth = 0;
00920     G4PhysicalVolumeModel* pPVModel =
00921       dynamic_cast<G4PhysicalVolumeModel*>(fpModel);
00922     if (pPVModel) currentDepth = pPVModel->GetCurrentDepth();
00923 
00924     G4bool notLastFace;
00925     do {
00926         HepRepInstance* face;
00927         if (isEventData()) {
00928             face = factory->createHepRepInstance(instance, getCalHitFaceType());
00929         } else {
00930             face = getGeometryInstance("*Face", currentDepth+1);
00931             setAttribute(face, "PickParent", true);
00932             setAttribute(face, "DrawAs", G4String("Polygon"));
00933         }
00934         
00935         setLine(face, polyhedron);
00936         setColor(face, GetColor(polyhedron));
00937         if (isEventData()) setColor(face, GetColor(polyhedron), G4String("FillColor"));
00938 
00939         notLastFace = polyhedron.GetNextNormal (surfaceNormal);
00940 
00941         G4int edgeFlag = 1;
00942         G4bool notLastEdge;
00943         do {
00944                 notLastEdge = polyhedron.GetNextVertex (vertex, edgeFlag);
00945             vertex = transform * vertex;
00946             factory->createHepRepPoint(face, vertex.x(), vertex.y(), vertex.z());
00947         } while (notLastEdge);
00948     } while (notLastFace);
00949 }

void G4HepRepSceneHandler::AddPrimitive ( const G4Square  )  [virtual]

Implements G4VSceneHandler.

Definition at line 976 of file G4HepRepSceneHandler.cc.

References G4VSceneHandler::fProcessing2D, G4Exception(), G4VMarker::GetPosition(), and JustWarning.

00976                                                                {
00977 #ifdef PDEBUG
00978     cout << "G4HepRepSceneHandler::AddPrimitive(G4Square&) " << endl;
00979 #endif
00980     if (dontWrite()) return;
00981 
00982     if (fProcessing2D) {
00983       static G4bool warned = false;
00984       if (!warned) {
00985         warned = true;
00986         G4Exception
00987           ("G4HepRepSceneHandler::AddPrimitive (const G4Square&)",
00988            "vis-HepRep1006", JustWarning,
00989            "2D squares not implemented.  Ignored.");
00990       }
00991       return;
00992     }
00993 
00994     HepRepInstance* instance = factory->createHepRepInstance(getEventInstance(), getHitType());
00995 
00996     addAttributes(instance, getHitType());
00997 
00998     G4Point3D center = transform * square.GetPosition();
00999 
01000     setColor (instance, getColorFor(square));
01001 
01002     setVisibility(instance, square);
01003 
01004     setMarker(instance, square);
01005 
01006     factory->createHepRepPoint(instance, center.x(), center.y(), center.z());
01007 }

void G4HepRepSceneHandler::AddPrimitive ( const G4Circle  )  [virtual]

Implements G4VSceneHandler.

Definition at line 855 of file G4HepRepSceneHandler.cc.

References G4VSceneHandler::fProcessing2D, G4Exception(), G4VSceneHandler::GetColor(), G4VMarker::GetPosition(), and JustWarning.

00855                                                                {
00856 #ifdef PDEBUG
00857     cout << "G4HepRepSceneHandler::AddPrimitive(G4Circle&) " << endl;
00858 #endif
00859     if (dontWrite()) return;
00860 
00861     if (fProcessing2D) {
00862       static G4bool warned = false;
00863       if (!warned) {
00864         warned = true;
00865         G4Exception
00866           ("G4HepRepSceneHandler::AddPrimitive (const G4Circle&)",
00867            "vis-HepRep1003", JustWarning,
00868            "2D circles not implemented.  Ignored.");
00869       }
00870       return;
00871     }
00872 
00873     HepRepInstance* instance = factory->createHepRepInstance(getEventInstance(), getHitType());
00874 
00875     addAttributes(instance, getHitType());
00876 
00877     G4Point3D center = transform * circle.GetPosition();
00878 
00879     setColor (instance, GetColor(circle));
00880 
00881     setVisibility(instance, circle);
00882 
00883     setMarker(instance, circle);
00884 
00885     factory->createHepRepPoint(instance, center.x(), center.y(), center.z());
00886 }

void G4HepRepSceneHandler::AddPrimitive ( const G4Text  )  [virtual]

Implements G4VSceneHandler.

Definition at line 952 of file G4HepRepSceneHandler.cc.

00952                                                       {
00953 #ifdef PDEBUG
00954     cout << "G4HepRepSceneHandler::AddPrimitive(G4Text&) " << endl;
00955 #endif
00956     if (dontWrite()) return;
00957 
00958     /*** You may need this
00959     if (fProcessing2D) {
00960       static G4bool warned = false;
00961       if (!warned) {
00962         warned = true;
00963         G4Exception
00964           ("G4HepRepSceneHandler::AddPrimitive (const G4Text&)",
00965            "vis-HepRep1005", JustWarning,
00966            "2D text not implemented.  Ignored.");
00967       }
00968       return;
00969     }
00970     ***/
00971 
00972     cout << "G4HepRepSceneHandler::AddPrimitive G4Text : not yet implemented. " << endl;
00973 }

void G4HepRepSceneHandler::AddPrimitive ( const G4Polyline  )  [virtual]

Implements G4VSceneHandler.

Definition at line 768 of file G4HepRepSceneHandler.cc.

References G4VSceneHandler::fProcessing2D, G4Exception(), G4VSceneHandler::GetColor(), and JustWarning.

00768                                                                {
00769 
00770 #ifdef PDEBUG
00771     cout << "G4HepRepSceneHandler::AddPrimitive(G4Polyline&) " << line.size() << endl;
00772 #endif
00773     if (dontWrite()) return;
00774 
00775     if (fProcessing2D) {
00776       static G4bool warned = false;
00777       if (!warned) {
00778         warned = true;
00779         G4Exception
00780           ("G4HepRepSceneHandler::AddPrimitive (const G4Polyline&)",
00781            "vis-HepRep1001", JustWarning,
00782            "2D polylines not implemented.  Ignored.");
00783       }
00784       return;
00785     }
00786 
00787     HepRepInstance* instance = factory->createHepRepInstance(getEventInstance(), getTrajectoryType());
00788 
00789     addAttributes(instance, getTrajectoryType());
00790 
00791     setColor(instance, GetColor(line));
00792 
00793     setVisibility(instance, line);
00794 
00795     setLine(instance, line);
00796 
00797     for (size_t i=0; i < line.size(); i++) {
00798         G4Point3D vertex = transform * line[i];
00799         factory->createHepRepPoint(instance, vertex.x(), vertex.y(), vertex.z());
00800     }
00801 }

void G4HepRepSceneHandler::AddSolid ( const G4VSolid solid  )  [virtual]

Reimplemented from G4VSceneHandler.

Definition at line 762 of file G4HepRepSceneHandler.cc.

References G4VSceneHandler::AddSolid().

00762                                                           { 
00763     if (dontWrite()) return;
00764     G4VSceneHandler::AddSolid(solid); 
00765 }

void G4HepRepSceneHandler::AddSolid ( const G4Polyhedra polyhedra  )  [virtual]

Reimplemented from G4VSceneHandler.

Definition at line 757 of file G4HepRepSceneHandler.cc.

References G4VSceneHandler::AddSolid().

00757                                                                  { 
00758     if (dontWrite()) return;
00759     G4VSceneHandler::AddSolid (polyhedra); 
00760 }

void G4HepRepSceneHandler::AddSolid ( const G4Polycone polycone  )  [virtual]

Reimplemented from G4VSceneHandler.

Definition at line 752 of file G4HepRepSceneHandler.cc.

References G4VSceneHandler::AddSolid().

00752                                                                { 
00753     if (dontWrite()) return;
00754     G4VSceneHandler::AddSolid (polycone); 
00755 }

void G4HepRepSceneHandler::AddSolid ( const G4Torus torus  )  [virtual]

Reimplemented from G4VSceneHandler.

Definition at line 747 of file G4HepRepSceneHandler.cc.

References G4VSceneHandler::AddSolid().

00747                                                          { 
00748     if (dontWrite()) return;
00749     G4VSceneHandler::AddSolid (torus); 
00750 }

void G4HepRepSceneHandler::AddSolid ( const G4Para para  )  [virtual]

Reimplemented from G4VSceneHandler.

Definition at line 742 of file G4HepRepSceneHandler.cc.

References G4VSceneHandler::AddSolid().

00742                                                        { 
00743     if (dontWrite()) return;
00744     G4VSceneHandler::AddSolid (para); 
00745 }

void G4HepRepSceneHandler::AddSolid ( const G4Sphere sphere  )  [virtual]

Reimplemented from G4VSceneHandler.

Definition at line 737 of file G4HepRepSceneHandler.cc.

References G4VSceneHandler::AddSolid().

00737                                                            { 
00738     if (dontWrite()) return;
00739     G4VSceneHandler::AddSolid (sphere); 
00740 }

void G4HepRepSceneHandler::AddSolid ( const G4Trap trap  )  [virtual]

Reimplemented from G4VSceneHandler.

Definition at line 732 of file G4HepRepSceneHandler.cc.

References G4VSceneHandler::AddSolid().

00732                                                        { 
00733     if (dontWrite()) return;
00734     G4VSceneHandler::AddSolid (trap); 
00735 }

void G4HepRepSceneHandler::AddSolid ( const G4Trd trd  )  [virtual]

Reimplemented from G4VSceneHandler.

Definition at line 675 of file G4HepRepSceneHandler.cc.

References G4VSceneHandler::AddSolid(), G4HepRepMessenger::GetInstance(), G4Trd::GetXHalfLength1(), G4Trd::GetXHalfLength2(), G4Trd::GetYHalfLength1(), G4Trd::GetYHalfLength2(), G4Trd::GetZHalfLength(), and G4HepRepMessenger::useSolids().

00675                                                     {
00676 #ifdef SDEBUG
00677     cout << "G4HepRepSceneHandler::AddSolid(const G4Trd& trd)" << endl;
00678 #endif
00679     if (dontWrite()) return;
00680         
00681         G4HepRepMessenger* messenger = G4HepRepMessenger::GetInstance();
00682 
00683     if (! messenger->useSolids()) {
00684         G4VSceneHandler::AddSolid(trd);
00685         return;
00686     }
00687     
00688     G4double dx1 = trd.GetXHalfLength1();
00689     G4double dy1 = trd.GetYHalfLength1();
00690     G4double dx2 = trd.GetXHalfLength2();
00691     G4double dy2 = trd.GetYHalfLength2();
00692     G4double dz = trd.GetZHalfLength();
00693     
00694     G4Point3D vertex1(G4Point3D( dx1, dy1,-dz));
00695     G4Point3D vertex2(G4Point3D( dx1,-dy1,-dz));
00696     G4Point3D vertex3(G4Point3D(-dx1,-dy1,-dz));
00697     G4Point3D vertex4(G4Point3D(-dx1, dy1,-dz));
00698     G4Point3D vertex5(G4Point3D( dx2, dy2, dz));
00699     G4Point3D vertex6(G4Point3D( dx2,-dy2, dz));
00700     G4Point3D vertex7(G4Point3D(-dx2,-dy2, dz));
00701     G4Point3D vertex8(G4Point3D(-dx2, dy2, dz));
00702     
00703     vertex1 = (transform) * vertex1;
00704     vertex2 = (transform) * vertex2;
00705     vertex3 = (transform) * vertex3;
00706     vertex4 = (transform) * vertex4;
00707     vertex5 = (transform) * vertex5;
00708     vertex6 = (transform) * vertex6;
00709     vertex7 = (transform) * vertex7;
00710     vertex8 = (transform) * vertex8;
00711 
00712     HepRepInstance* instance = getGeometryOrEventInstance(getCalHitType());
00713 
00714     addAttributes(instance, getCalHitType());
00715 
00716     setAttribute(instance, "DrawAs", G4String("Prism"));
00717         
00718     setVisibility(instance, trd);
00719     setLine(instance, trd);
00720     setColor(instance, getColorFor(trd));
00721 
00722     factory->createHepRepPoint(instance, vertex1.x(), vertex1.y(), vertex1.z());
00723     factory->createHepRepPoint(instance, vertex2.x(), vertex2.y(), vertex2.z());
00724     factory->createHepRepPoint(instance, vertex3.x(), vertex3.y(), vertex3.z());
00725     factory->createHepRepPoint(instance, vertex4.x(), vertex4.y(), vertex4.z());
00726     factory->createHepRepPoint(instance, vertex5.x(), vertex5.y(), vertex5.z());
00727     factory->createHepRepPoint(instance, vertex6.x(), vertex6.y(), vertex6.z());
00728     factory->createHepRepPoint(instance, vertex7.x(), vertex7.y(), vertex7.z());
00729     factory->createHepRepPoint(instance, vertex8.x(), vertex8.y(), vertex8.z());
00730 }

void G4HepRepSceneHandler::AddSolid ( const G4Tubs tubs  )  [virtual]

Reimplemented from G4VSceneHandler.

Definition at line 615 of file G4HepRepSceneHandler.cc.

References G4VSceneHandler::AddSolid(), G4VSceneHandler::fpModel, G4PhysicalVolumeModel::GetCurrentDepth(), G4PhysicalVolumeModel::GetCurrentLV(), G4PhysicalVolumeModel::GetCurrentMaterial(), G4Tubs::GetDeltaPhiAngle(), G4Tubs::GetInnerRadius(), G4HepRepMessenger::GetInstance(), G4LogicalVolume::GetName(), G4Tubs::GetOuterRadius(), G4Tubs::GetZHalfLength(), and G4HepRepMessenger::useSolids().

00615                                                       {
00616 #ifdef SDEBUG
00617     cout << "G4HepRepSceneHandler::AddSolid(const G4Tubs& tubs)" << endl;
00618 #endif
00619 
00620     if (dontWrite()) return;
00621         
00622         G4HepRepMessenger* messenger = G4HepRepMessenger::GetInstance();
00623 
00624     if (! messenger->useSolids() || (tubs.GetDeltaPhiAngle() < twopi)) {
00625         G4VSceneHandler::AddSolid(tubs);
00626         return;
00627     }
00628     
00629     G4PhysicalVolumeModel* pPVModel =
00630       dynamic_cast<G4PhysicalVolumeModel*>(fpModel);
00631     if (!pPVModel) {
00632       G4VSceneHandler::AddSolid(tubs);
00633         return;
00634     }
00635 
00636     G4LogicalVolume* pCurrentLV = pPVModel->GetCurrentLV();
00637     G4int currentDepth = pPVModel->GetCurrentDepth();
00638     G4Material* pCurrentMaterial = pPVModel->GetCurrentMaterial();
00639 
00640     G4Point3D vertex1(G4Point3D( 0., 0., tubs.GetZHalfLength()));
00641     G4Point3D vertex2(G4Point3D( 0., 0.,-tubs.GetZHalfLength()));
00642 
00643     vertex1 = (transform) * vertex1;
00644     vertex2 = (transform) * vertex2;
00645 
00646     HepRepInstance* instance = getGeometryInstance(pCurrentLV, pCurrentMaterial, currentDepth);
00647     setAttribute(instance, "DrawAs", G4String("Cylinder"));
00648         
00649     setVisibility(instance, tubs);
00650     setLine(instance, tubs);
00651     setColor(instance, getColorFor(tubs));
00652 
00653     HepRepType* type = getGeometryType(pCurrentLV->GetName(), currentDepth);
00654 
00655     // Outer cylinder.
00656     HepRepInstance* outer = factory->createHepRepInstance(instance, type);
00657     outer->addAttValue("Radius",tubs.GetOuterRadius());
00658     outer->addAttValue("pickParent",true);
00659     outer->addAttValue("showParentAttributes",true);
00660     factory->createHepRepPoint(outer, vertex1.x(), vertex1.y(), vertex1.z());
00661     factory->createHepRepPoint(outer, vertex2.x(), vertex2.y(), vertex2.z());
00662 
00663     // Inner cylinder.
00664     if (tubs.GetInnerRadius() > 0.) {
00665         HepRepInstance* inner = factory->createHepRepInstance(instance, type);
00666         inner->addAttValue("Radius",tubs.GetInnerRadius());
00667         inner->addAttValue("pickParent",true);
00668         inner->addAttValue("showParentAttributes",true);
00669         factory->createHepRepPoint(inner, vertex1.x(), vertex1.y(), vertex1.z());
00670         factory->createHepRepPoint(inner, vertex2.x(), vertex2.y(), vertex2.z());
00671     }
00672 }

void G4HepRepSceneHandler::AddSolid ( const G4Cons cons  )  [virtual]

Reimplemented from G4VSceneHandler.

Definition at line 551 of file G4HepRepSceneHandler.cc.

References G4VSceneHandler::AddSolid(), G4VSceneHandler::fpModel, G4PhysicalVolumeModel::GetCurrentDepth(), G4PhysicalVolumeModel::GetCurrentLV(), G4PhysicalVolumeModel::GetCurrentMaterial(), G4Cons::GetDeltaPhiAngle(), G4Cons::GetInnerRadiusMinusZ(), G4Cons::GetInnerRadiusPlusZ(), G4HepRepMessenger::GetInstance(), G4LogicalVolume::GetName(), G4Cons::GetOuterRadiusMinusZ(), G4Cons::GetOuterRadiusPlusZ(), G4Cons::GetZHalfLength(), and G4HepRepMessenger::useSolids().

00551                                                       {
00552 #ifdef SDEBUG
00553     cout << "G4HepRepSceneHandler::AddSolid(const G4Cons& cons)" << endl;
00554 #endif
00555 
00556     if (dontWrite()) return;
00557         
00558         G4HepRepMessenger* messenger = G4HepRepMessenger::GetInstance();
00559 
00560     if (! messenger->useSolids() || (cons.GetDeltaPhiAngle() < twopi)) {
00561         G4VSceneHandler::AddSolid(cons);
00562         return;
00563     }
00564 
00565     G4PhysicalVolumeModel* pPVModel =
00566       dynamic_cast<G4PhysicalVolumeModel*>(fpModel);
00567     if (!pPVModel) {
00568       G4VSceneHandler::AddSolid(cons);
00569         return;
00570     }
00571 
00572     G4LogicalVolume* pCurrentLV = pPVModel->GetCurrentLV();
00573     G4int currentDepth = pPVModel->GetCurrentDepth();
00574     G4Material* pCurrentMaterial = pPVModel->GetCurrentMaterial();
00575 
00576     G4Point3D vertex1(G4Point3D( 0., 0., cons.GetZHalfLength()));
00577     G4Point3D vertex2(G4Point3D( 0., 0.,-cons.GetZHalfLength()));
00578 
00579     vertex1 = (transform) * vertex1;
00580     vertex2 = (transform) * vertex2;
00581 
00582     HepRepInstance* instance = getGeometryInstance(pCurrentLV, pCurrentMaterial, currentDepth);
00583     setAttribute(instance, "DrawAs", G4String("Cylinder"));
00584         
00585     setVisibility(instance, cons);
00586     setLine(instance, cons);
00587     setColor(instance, getColorFor(cons));
00588 
00589     HepRepType* type = getGeometryType(pCurrentLV->GetName(), currentDepth);
00590 
00591     // Outer cylinder.
00592     HepRepInstance* outer = factory->createHepRepInstance(instance, type);
00593     outer->addAttValue("pickParent",true);
00594     outer->addAttValue("showParentAttributes",true);
00595     
00596     HepRepPoint* op1 = factory->createHepRepPoint(outer, vertex1.x(), vertex1.y(), vertex1.z());
00597     op1->addAttValue("Radius",cons.GetOuterRadiusPlusZ());
00598     
00599     HepRepPoint* op2 = factory->createHepRepPoint(outer, vertex2.x(), vertex2.y(), vertex2.z());
00600     op2->addAttValue("Radius",cons.GetOuterRadiusMinusZ());
00601 
00602     // Inner cylinder.
00603     HepRepInstance* inner = factory->createHepRepInstance(instance, type);
00604     inner->addAttValue("pickParent",true);
00605     inner->addAttValue("showParentAttributes",true);
00606     
00607     HepRepPoint* ip1 = factory->createHepRepPoint(inner, vertex1.x(), vertex1.y(), vertex1.z());
00608     ip1->addAttValue("Radius",cons.GetInnerRadiusPlusZ());
00609     
00610     HepRepPoint* ip2 = factory->createHepRepPoint(inner, vertex2.x(), vertex2.y(), vertex2.z());
00611     ip2->addAttValue("Radius",cons.GetInnerRadiusMinusZ());
00612 }

void G4HepRepSceneHandler::AddSolid ( const G4Box box  )  [virtual]

Reimplemented from G4VSceneHandler.

Definition at line 495 of file G4HepRepSceneHandler.cc.

References G4VSceneHandler::AddSolid(), G4HepRepMessenger::GetInstance(), G4Box::GetXHalfLength(), G4Box::GetYHalfLength(), G4Box::GetZHalfLength(), and G4HepRepMessenger::useSolids().

00495                                                     {
00496 #ifdef SDEBUG
00497     cout << "G4HepRepSceneHandler::AddSolid(const G4Box& box)" << endl;
00498 #endif
00499 
00500     if (dontWrite()) return;
00501         
00502         G4HepRepMessenger* messenger = G4HepRepMessenger::GetInstance();
00503 
00504     if (! messenger->useSolids()) {
00505         G4VSceneHandler::AddSolid(box);
00506         return;
00507     }
00508     
00509     G4double dx = box.GetXHalfLength();
00510     G4double dy = box.GetYHalfLength();
00511     G4double dz = box.GetZHalfLength();
00512     
00513     G4Point3D vertex1(G4Point3D( dx, dy,-dz));
00514     G4Point3D vertex2(G4Point3D( dx,-dy,-dz));
00515     G4Point3D vertex3(G4Point3D(-dx,-dy,-dz));
00516     G4Point3D vertex4(G4Point3D(-dx, dy,-dz));
00517     G4Point3D vertex5(G4Point3D( dx, dy, dz));
00518     G4Point3D vertex6(G4Point3D( dx,-dy, dz));
00519     G4Point3D vertex7(G4Point3D(-dx,-dy, dz));
00520     G4Point3D vertex8(G4Point3D(-dx, dy, dz));
00521     
00522     vertex1 = (transform) * vertex1;
00523     vertex2 = (transform) * vertex2;
00524     vertex3 = (transform) * vertex3;
00525     vertex4 = (transform) * vertex4;
00526     vertex5 = (transform) * vertex5;
00527     vertex6 = (transform) * vertex6;
00528     vertex7 = (transform) * vertex7;
00529     vertex8 = (transform) * vertex8;
00530 
00531     HepRepInstance* instance = getGeometryOrEventInstance(getCalHitType());
00532     addAttributes(instance, getCalHitType());
00533 
00534     setAttribute(instance, "DrawAs", G4String("Prism"));
00535         
00536     setVisibility(instance, box);
00537     setLine(instance, box);
00538     setColor(instance, getColorFor(box));
00539 
00540     factory->createHepRepPoint(instance, vertex1.x(), vertex1.y(), vertex1.z());
00541     factory->createHepRepPoint(instance, vertex2.x(), vertex2.y(), vertex2.z());
00542     factory->createHepRepPoint(instance, vertex3.x(), vertex3.y(), vertex3.z());
00543     factory->createHepRepPoint(instance, vertex4.x(), vertex4.y(), vertex4.z());
00544     factory->createHepRepPoint(instance, vertex5.x(), vertex5.y(), vertex5.z());
00545     factory->createHepRepPoint(instance, vertex6.x(), vertex6.y(), vertex6.z());
00546     factory->createHepRepPoint(instance, vertex7.x(), vertex7.y(), vertex7.z());
00547     factory->createHepRepPoint(instance, vertex8.x(), vertex8.y(), vertex8.z());
00548 }

void G4HepRepSceneHandler::BeginModeling (  )  [virtual]

Reimplemented from G4VSceneHandler.

Definition at line 480 of file G4HepRepSceneHandler.cc.

References G4VSceneHandler::BeginModeling().

00480                                          {
00481 #ifdef SDEBUG
00482     cout << "G4HepRepSceneHandler::BeginModeling() " << endl;
00483 #endif
00484     G4VSceneHandler::BeginModeling();
00485 }

void G4HepRepSceneHandler::BeginPrimitives ( const G4Transform3D objectTransformation  )  [virtual]

Reimplemented from G4VSceneHandler.

Definition at line 1080 of file G4HepRepSceneHandler.cc.

References G4VSceneHandler::BeginPrimitives().

01080                                                                                      {
01081 #ifdef SDEBUG
01082     cout << "G4HepRepSceneHandler::BeginPrimitives(G4Transform3D&)" << endl;
01083 #endif
01084 
01085     G4VSceneHandler::BeginPrimitives (objectTransformation);
01086     transform = objectTransformation;
01087 }

void G4HepRepSceneHandler::closeFile (  ) 

Definition at line 462 of file G4HepRepSceneHandler.cc.

Referenced by closeHepRep().

00462                                      {
00463     writer->close();
00464     delete writer;
00465     writer = NULL;
00466 
00467     delete out;
00468     out = NULL;
00469 }

bool G4HepRepSceneHandler::closeHepRep ( bool  final = false  ) 

Returns true if the HepRep was (already) closed, false if the HepRep is still open

Definition at line 322 of file G4HepRepSceneHandler.cc.

References G4HepRepMessenger::appendGeometry(), closeFile(), G4VViewer::DrawView(), G4VSceneHandler::GetCurrentViewer(), G4HepRepMessenger::GetInstance(), G4VSceneHandler::GetName(), G4VSceneHandler::GetScene(), and openFile().

Referenced by G4HepRepViewer::ShowView().

00322                                                  {
00323     if (_heprep == NULL) return true;
00324 
00325 #ifdef LDEBUG
00326     cout << "G4HepRepSceneHandler::CloseHepRep() start" << endl;
00327 #endif
00328 
00329     // if this is the final close, then there should not be any event pending to be written.
00330     if (final) {
00331         if (_eventInstanceTree != NULL) {
00332             cerr << "WARNING: you probably used '/vis/viewer/endOfEventAction accumulate' and "
00333                  << "forgot to call /vis/viewer/update before exit. No event written." << endl;
00334         }
00335     } else {
00336                 
00337                 G4HepRepMessenger* messenger = G4HepRepMessenger::GetInstance();
00338 
00339         // add geometry to the heprep if there is an event (separate geometries are written
00340         // using DrawView() called from /vis/viewer/flush)
00341         if (_eventInstanceTree != NULL) {
00342             GetCurrentViewer()->DrawView();
00343         
00344             // couple geometry
00345 
00346             if ( messenger->appendGeometry()) {
00347                 // couple geometry to event if geometry was written
00348                 if ((_geometryInstanceTree != NULL)) {
00349                     getEventInstanceTree()->addInstanceTree(getGeometryInstanceTree());
00350                 }
00351             } else {
00352                 char name[128];
00353                 if (writeMultipleFiles) {
00354                     sprintf(name, "%s%s%s#%s", baseName.c_str(), "-geometry", extension.c_str(), "G4GeometryData");
00355                 } else {
00356                     sprintf(name, "%s%s#%s", "geometry", (writeBinary ? ".bheprep" : ".heprep"), "G4GeometryData");
00357                 }   
00358                 getEventInstanceTree()->addInstanceTree(factory->createHepRepTreeID(name, "1.0"));
00359             }
00360         }
00361     
00362         // force inclusion of all subtypes of event
00363         if (_eventInstanceTree != NULL) {
00364             getEventType();
00365             getTrajectoryType();
00366             getHitType();
00367             getCalHitType();
00368             getCalHitFaceType();
00369         }
00370     
00371         // Give this HepRep all of the layer order info for both geometry and event,
00372         // since these will both end up in a single HepRep.
00373         writeLayers(_heprepGeometry);
00374         writeLayers(_heprep);
00375 
00376         // open heprep file
00377         if (writer == NULL) {
00378             open((GetScene() == NULL) ? G4String("G4HepRepOutput.heprep.zip") : GetScene()->GetName());
00379         }
00380 
00381         // write out separate geometry
00382         if (! messenger->appendGeometry() && (_heprepGeometry != NULL)) {
00383             if (writeMultipleFiles) {
00384                 char fileName[128];
00385                 sprintf(fileName, "%s%s%s", baseName.c_str(), "-geometry", extension.c_str());
00386                 openFile(G4String(fileName));
00387             }
00388 
00389             char name[128];
00390             sprintf(name, "%s%s", "geometry", (writeBinary ? ".bheprep" : ".heprep"));
00391             if (!writeMultipleFiles) {
00392                 writer->addProperty("RecordLoop.ignore", name);
00393             }
00394 
00395             writer->write(_heprepGeometry, G4String(name));
00396             
00397             delete _heprepGeometry;
00398             _heprepGeometry = NULL;
00399             
00400             if (writeMultipleFiles) closeFile();
00401         }
00402     
00403         if (writeMultipleFiles) {
00404 // NOTE: does not work on Solaris 5.2 and Linux 2.95.2
00405 //            stringstream fileName;
00406 //            fileName << baseName << eventNumberPrefix << setw(eventNumberWidth) << setfill('0') << eventNumber << eventNumberSuffix << extension;
00407 //            openFile(fileName.str());
00408 // Use instead:
00409             char fileName[128];
00410             char fileFormat[128];
00411             sprintf(fileFormat, "%s%d%s", "%s%s%0", eventNumberWidth, "d%s%s");
00412             sprintf(fileName, fileFormat, baseName.c_str(), eventNumberPrefix.c_str(), eventNumber, eventNumberSuffix.c_str(), extension.c_str());
00413             openFile(G4String(fileName));
00414         }
00415             
00416         // write out the heprep
00417 // NOTE: does not work on Solaris 5.2 and Linux 2.95.2
00418 //        stringstream eventName;
00419 //        eventName << "event-" << setw(eventNumberWidth) << setfill('0') << eventNumber << (writeBinary ? ".bheprep" : ".heprep");
00420 //        writer->write(_heprep, eventName.str());
00421 // Use instead:
00422         char eventName[128];
00423         char eventFormat[128];
00424         sprintf(eventFormat, "%s%d%s%s", "event-%0", eventNumberWidth, "d", (writeBinary ? ".bheprep" : ".heprep"));
00425         sprintf(eventName, eventFormat, eventNumber);
00426         writer->write(_heprep, G4String(eventName));
00427 
00428         eventNumber++;
00429     }
00430     
00431     delete _heprep;
00432     _heprep = NULL;
00433 
00434     if (writeMultipleFiles) closeFile();
00435 
00436     return true;
00437 }

void G4HepRepSceneHandler::EndModeling (  )  [virtual]

Reimplemented from G4VSceneHandler.

Definition at line 488 of file G4HepRepSceneHandler.cc.

References G4VSceneHandler::EndModeling().

00488                                        {
00489 #ifdef SDEBUG
00490     cout << "G4HepRepSceneHandler::EndModeling() " << endl;
00491 #endif
00492     G4VSceneHandler::EndModeling();
00493 }

void G4HepRepSceneHandler::EndPrimitives (  )  [virtual]

Reimplemented from G4VSceneHandler.

Definition at line 1090 of file G4HepRepSceneHandler.cc.

References G4VSceneHandler::EndPrimitives().

01090                                           {
01091 #ifdef SDEBUG
01092     cout << "G4HepRepSceneHandler::EndPrimitives" << endl;
01093 #endif
01094     G4VSceneHandler::EndPrimitives ();
01095 }

void G4HepRepSceneHandler::openFile ( G4String  name  ) 

Definition at line 457 of file G4HepRepSceneHandler.cc.

Referenced by closeHepRep().

00457                                                  {
00458     out = new ofstream(name.c_str(), std::ios::out | std::ios::binary );
00459     writer = factory->createHepRepWriter(out, writeZip, writeZip || writeGZ);
00460 }

void G4HepRepSceneHandler::openHepRep (  ) 

Definition at line 292 of file G4HepRepSceneHandler.cc.

Referenced by G4HepRepSceneHandler(), and G4HepRepViewer::ShowView().

00292                                       {
00293 #ifdef LDEBUG
00294     cout << "G4HepRepSceneHandler::OpenHepRep() " << endl;
00295 #endif
00296 
00297     if (_heprep != NULL) return;
00298 
00299     // all done on demand, once pointers are set to NULL
00300     _heprepGeometry       = NULL;
00301     _geometryInstanceTree = NULL;
00302     _geometryRootInstance = NULL;
00303     _geometryInstance.clear();
00304     _geometryTypeTree     = NULL;
00305     _geometryRootType     = NULL;
00306     _geometryTypeName.clear();
00307     _geometryType.clear();
00308     _eventInstanceTree    = NULL;
00309     _eventInstance        = NULL;
00310     _eventTypeTree        = NULL;
00311     _eventType            = NULL;
00312     _trajectoryType       = NULL;
00313     _hitType              = NULL;
00314     _calHitType           = NULL;
00315     _calHitFaceType       = NULL;     
00316 }

void G4HepRepSceneHandler::PostAddSolid (  )  [virtual]

Reimplemented from G4VSceneHandler.

Definition at line 1072 of file G4HepRepSceneHandler.cc.

References G4VSceneHandler::PostAddSolid().

01072                                          {
01073 #ifdef SDEBUG
01074     cout << "G4HepRepSceneHandler::PostAddSolid()" << endl;
01075 #endif
01076     G4VSceneHandler::PostAddSolid();
01077 }

void G4HepRepSceneHandler::PreAddSolid ( const G4Transform3D objectTransformation,
const G4VisAttributes visAttribs 
) [virtual]

Reimplemented from G4VSceneHandler.

Definition at line 1060 of file G4HepRepSceneHandler.cc.

References G4VSceneHandler::PreAddSolid().

01061                                                                      {
01062 
01063     G4VSceneHandler::PreAddSolid (objectTransformation, visAttribs);
01064 
01065     transform = objectTransformation;
01066 #ifdef SDEBUG
01067     cout << "G4HepRepSceneHandler::PreAddSolid(G4Transform3D&, G4VisAttributes&)" << endl;
01068 #endif
01069 }


The documentation for this class was generated from the following files:
Generated on Mon May 27 17:52:12 2013 for Geant4 by  doxygen 1.4.7