CMS 3D CMS Logo

VisG4GeometryTwig.cc

Go to the documentation of this file.
00001 //<<<<<< INCLUDES                                                       >>>>>>
00002 
00003 #include "VisGeant4/VisG4Volumes/interface/VisG4GeometryTwig.h"
00004 #include "VisGeant4/VisG4Volumes/interface/VisG4VolumeTwig.h"
00005 #include "VisGeant4/VisG4Volumes/interface/VisG4Navigator.h"
00006 #include "VisGeant4/VisG4Core/interface/VisG4VisManager.h"
00007 #include "Iguana/Framework/interface/IgRepSet.h"
00008 #include <G4TransportationManager.hh>
00009 #include <G4LogicalVolumeStore.hh>
00010 #include <G4VPhysicalVolume.hh>
00011 #include <G4VisAttributes.hh>
00012 #include <set>
00013 
00014 //<<<<<< PRIVATE DEFINES                                                >>>>>>
00015 //<<<<<< PRIVATE CONSTANTS                                              >>>>>>
00016 //<<<<<< PRIVATE TYPES                                                  >>>>>>
00017 //<<<<<< PRIVATE VARIABLE DEFINITIONS                                   >>>>>>
00018 //<<<<<< PUBLIC VARIABLE DEFINITIONS                                    >>>>>>
00019 //<<<<<< CLASS STRUCTURE INITIALIZATION                                 >>>>>>
00020 //<<<<<< PRIVATE FUNCTION DEFINITIONS                                   >>>>>>
00021 //<<<<<< PUBLIC FUNCTION DEFINITIONS                                    >>>>>>
00022 //<<<<<< MEMBER FUNCTION DEFINITIONS                                    >>>>>>
00023 
00024 // FIXME: Use G4StateManager / G4VStateDependent?
00025 
00026 VisG4GeometryTwig::VisG4GeometryTwig (VisG4VisManager *visManager, IgTwig *parent)
00027     : IgSimpleTwig (parent, "Detector", true, true, true)
00028 { visManager->notify (lat::CreateCallback (this, &VisG4GeometryTwig::update)); }
00029 
00030 void
00031 VisG4GeometryTwig::update (void)
00032 {
00033     destroy ();
00034 
00035     G4VPhysicalVolume *world
00036         = G4TransportationManager::GetTransportationManager ()
00037         ->GetNavigatorForTracking ()->GetWorldVolume ();
00038 
00039     if (! world)
00040         return;
00041     
00042     // FIXME: retain unchanged structure?
00043     ASSERT (world->GetLogicalVolume ());
00044     ASSERT (! world->IsReplicated ());
00045     VisG4Navigator::build (1, world, new VisG4VolumeTwig
00046                           (this, world, true, false, true));
00047 
00048     // Ensure that every logical volume has an unique vis attributes
00049     // object.  Several logical volumes may share one and the same vis
00050     // attrs, and some volumes might not have any attributes at all.
00051     // This ensures every logical volume has them -- if not, default
00052     // ones are created -- and that the attributes are not shared.
00053     // Note that we blindly apply this to all volumes in the store
00054     // as that is much faster than walking the geometry hierarchy.
00055     std::set<G4VisAttributes *> seen;
00056     G4LogicalVolumeStore *volumes = G4LogicalVolumeStore::GetInstance ();
00057     for (unsigned i = 0; i < volumes->size (); ++i)
00058     {
00059         G4LogicalVolume *volume = (*volumes) [i];
00060         G4VisAttributes *attrs = const_cast<G4VisAttributes *>
00061                                  (volume->GetVisAttributes ());
00062 
00063         if (! attrs)
00064             volume->SetVisAttributes (attrs = new G4VisAttributes);
00065 
00066         if (seen.count (attrs))
00067             volume->SetVisAttributes (attrs = new G4VisAttributes (*attrs));
00068 
00069         seen.insert (attrs);
00070     }
00071 
00072     // Make sure reps reflect the change
00073     IgRepSet::invalidate (this, STRUCTURE_MASK | SELF_MASK);
00074 }

Generated on Tue Jun 9 17:50:07 2009 for CMSSW by  doxygen 1.5.4