00001 // 00002 // ******************************************************************** 00003 // * License and Disclaimer * 00004 // * * 00005 // * The Geant4 software is copyright of the Copyright Holders of * 00006 // * the Geant4 Collaboration. It is provided under the terms and * 00007 // * conditions of the Geant4 Software License, included in the file * 00008 // * LICENSE and available at http://cern.ch/geant4/license . These * 00009 // * include a list of copyright holders. * 00010 // * * 00011 // * Neither the authors of this software system, nor their employing * 00012 // * institutes,nor the agencies providing financial support for this * 00013 // * work make any representation or warranty, express or implied, * 00014 // * regarding this software system or assume any liability for its * 00015 // * use. Please see the license in the file LICENSE and URL above * 00016 // * for the full disclaimer and the limitation of liability. * 00017 // * * 00018 // * This code implementation is the result of the scientific and * 00019 // * technical work of the GEANT4 collaboration. * 00020 // * By using, copying, modifying or distributing the software (or * 00021 // * any work based on the software) you agree to acknowledge its * 00022 // * use in resulting scientific publications, and indicate your * 00023 // * acceptance of all terms of the Geant4 Software license. * 00024 // ******************************************************************** 00025 // 00026 // 00027 // $Id$ 00028 // 00029 // 00030 // John Allison 5th April 2001 00031 // A base class for a scene handler to dump geometry hierarchy. 00032 // Based on a provisional G4VTreeGraphicsScene (was in modeling). 00033 00034 #include "G4VTreeSceneHandler.hh" 00035 00036 #include "G4VSolid.hh" 00037 #include "G4PhysicalVolumeModel.hh" 00038 #include "G4VPhysicalVolume.hh" 00039 #include "G4LogicalVolume.hh" 00040 00041 G4int G4VTreeSceneHandler::fSceneIdCount = 0; 00042 // Counter for Tree scene handlers. 00043 00044 G4VTreeSceneHandler::G4VTreeSceneHandler(G4VGraphicsSystem& system, 00045 const G4String& name): 00046 G4VSceneHandler(system, fSceneIdCount++, name), 00047 fpCurrentObjectTransformation (0) 00048 {} 00049 00050 G4VTreeSceneHandler::~G4VTreeSceneHandler () {} 00051 00052 void G4VTreeSceneHandler::BeginModeling() { 00053 G4VSceneHandler::BeginModeling(); // Required: see G4VSceneHandler.hh. 00054 } 00055 00056 void G4VTreeSceneHandler::EndModeling() { 00057 fDrawnLVStore.clear(); 00058 G4VSceneHandler::EndModeling(); // Required: see G4VSceneHandler.hh. 00059 } 00060 00061 void G4VTreeSceneHandler::PreAddSolid 00062 (const G4Transform3D& objectTransformation, const G4VisAttributes& visAttribs) 00063 { 00064 G4VSceneHandler::PreAddSolid (objectTransformation, visAttribs); 00065 00066 G4PhysicalVolumeModel* pPVModel = 00067 dynamic_cast<G4PhysicalVolumeModel*>(fpModel); 00068 if (!pPVModel) return; // Not from a G4PhysicalVolumeModel. 00069 00070 // This call comes from a G4PhysicalVolumeModel, drawnPVPath is 00071 // the path of the current drawn (non-culled) volume in terms of 00072 // drawn (non-culled) ancesters. Each node is identified by a 00073 // PVNodeID object, which is a physical volume and copy number. It 00074 // is a vector of PVNodeIDs corresponding to the geometry hierarchy 00075 // actually selected, i.e., not culled. 00076 typedef G4PhysicalVolumeModel::G4PhysicalVolumeNodeID PVNodeID; 00077 typedef std::vector<PVNodeID> PVPath; 00078 const PVPath& drawnPVPath = pPVModel->GetDrawnPVPath(); 00079 //G4int currentDepth = pPVModel->GetCurrentDepth(); 00080 //G4VPhysicalVolume* pCurrentPV = pPVModel->GetCurrentPV(); 00081 //G4LogicalVolume* pCurrentLV = pPVModel->GetCurrentLV(); 00082 //G4Material* pCurrentMaterial = pPVModel->GetCurrentMaterial(); 00083 00084 // Actually, it is enough to store the logical volume of current 00085 // physical volume... 00086 fDrawnLVStore.insert 00087 (drawnPVPath.back().GetPhysicalVolume()->GetLogicalVolume()); 00088 00089 // Find mother. ri points to drawn mother, if any. 00090 PVPath::const_reverse_iterator ri = ++drawnPVPath.rbegin(); 00091 if (ri != drawnPVPath.rend()) { 00092 // This volume has a mother. 00093 G4LogicalVolume* drawnMotherLV = 00094 ri->GetPhysicalVolume()->GetLogicalVolume(); 00095 if (fDrawnLVStore.find(drawnMotherLV) != fDrawnLVStore.end()) { 00096 // Mother previously encountered. Add this volume to 00097 // appropriate node in scene graph tree. 00098 // ... 00099 } else { 00100 // Mother not previously encountered. Shouldn't happen, since 00101 // G4PhysicalVolumeModel sends volumes as it encounters them, 00102 // i.e., mothers before daughters, in its descent of the 00103 // geometry tree. Error! 00104 G4cout << "ERROR: G4XXXSceneHandler::PreAddSolid: Mother " 00105 << ri->GetPhysicalVolume()->GetName() 00106 << ':' << ri->GetCopyNo() 00107 << " not previously encountered." 00108 "\nShouldn't happen! Please report to visualization coordinator." 00109 << G4endl; 00110 // Continue anyway. Add to root of scene graph tree. 00111 // ... 00112 } 00113 } else { 00114 // This volume has no mother. Must be a top level un-culled 00115 // volume. Add to root of scene graph tree. 00116 // ... 00117 } 00118 }