Geant4 Cross Reference |
1 // ******************************************************************** 2 // * License and Disclaimer * 3 // * * 4 // * The Geant4 software is copyright of the Copyright Holders of * 5 // * the Geant4 Collaboration. It is provided under the terms and * 6 // * conditions of the Geant4 Software License, included in the file * 7 // * LICENSE and available at http://cern.ch/geant4/license . These * 8 // * include a list of copyright holders. * 9 // * * 10 // * Neither the authors of this software system, nor their employing * 11 // * institutes,nor the agencies providing financial support for this * 12 // * work make any representation or warranty, express or implied, * 13 // * regarding this software system or assume any liability for its * 14 // * use. Please see the license in the file LICENSE and URL above * 15 // * for the full disclaimer and the limitation of liability. * 16 // * * 17 // * This code implementation is the result of the scientific and * 18 // * technical work of the GEANT4 collaboration. * 19 // * By using, copying, modifying or distributing the software (or * 20 // * any work based on the software) you agree to acknowledge its * 21 // * use in resulting scientific publications, and indicate your * 22 // * acceptance of all terms of the Geant4 Software license. * 23 // ******************************************************************** 24 // 25 // 26 // 27 28 #ifndef G4OctreeFinder_hh 29 #define G4OctreeFinder_hh 1 30 31 #include "globals.hh" 32 #include "G4Octree.hh" 33 #include "G4Track.hh" 34 #include "G4ITType.hh" 35 #include "G4memory.hh" 36 #include "G4TrackList.hh" 37 38 #include <map> 39 #include <functional> 40 41 #undef DEBUG 42 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 43 class G4VFinder 44 { 45 public: 46 G4VFinder() = default; 47 virtual ~G4VFinder() = default; 48 virtual void Clear() = 0; 49 virtual void SetVerboseLevel(G4int level) = 0; 50 virtual G4int GetVerboseLevel() = 0; 51 virtual G4ITType GetITType() = 0; 52 }; 53 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 54 55 #ifndef _Extractor_ 56 #define _Extractor_ 57 template<typename CONTAINER> 58 class Extractor 59 { 60 public: 61 const G4ThreeVector operator () (typename CONTAINER::iterator it) 62 { 63 return (*it)->GetPosition(); 64 } 65 std::function<G4bool(const std::pair<typename CONTAINER::iterator,G4double>, 66 const std::pair<typename CONTAINER::iterator,G4double>)> 67 compareInterval = [](const std::pair<typename CONTAINER::iterator,G4double>& iter1, 68 const std::pair<typename CONTAINER::iterator,G4double>& iter2) 69 -> G4bool 70 { 71 return (std::get<1>(iter1) < std::get<1>(iter2)); 72 }; 73 74 }; 75 #endif 76 template<class T,typename CONTAINER> 77 class G4OctreeFinder: public G4VFinder 78 { 79 using Octree = G4Octree<typename CONTAINER::iterator, 80 Extractor<CONTAINER> >; 81 using OctreeHandle = G4shared_ptr<Octree>; 82 using TreeMap = std::map<int, OctreeHandle>; 83 84 private: 85 static G4ThreadLocal G4OctreeFinder* fInstance; 86 G4OctreeFinder(); 87 int fVerbose{0}; 88 G4bool fIsOctreeUsed{false}; 89 G4bool fIsOctreeBuit{false}; 90 Extractor<CONTAINER> fExtractor; 91 TreeMap fTreeMap; 92 OctreeHandle fTree; 93 public: 94 static G4OctreeFinder * Instance(); 95 96 void SetOctreeUsed(G4bool used); 97 G4bool IsOctreeUsed() const; 98 99 void SetOctreeBuilt(G4bool used); 100 G4bool IsOctreeBuilt() const; 101 102 ~G4OctreeFinder() override; 103 void Clear() override; 104 105 void SetVerboseLevel(G4int level) override 106 { 107 fVerbose = level; 108 } 109 110 G4int GetVerboseLevel() override 111 { 112 return fVerbose; 113 } 114 115 G4ITType GetITType() override 116 { 117 return T::ITType(); 118 } 119 void BuildTreeMap(const std::map<G4int,CONTAINER*>& listMap); 120 void FindNearestInRange(const G4Track& track, 121 const int& key, 122 G4double R, 123 std::vector<std::pair<typename 124 CONTAINER::iterator,G4double>>& result, 125 G4bool isSort = false) const; 126 127 void FindNearest(const G4Track& track, 128 const int& key, 129 G4double R, 130 std::vector<std::pair<typename 131 CONTAINER::iterator,G4double>>& result, 132 G4bool isSort = false) const; 133 134 void FindNearestInRange(const G4ThreeVector& position, 135 const G4int& key, 136 G4double R, 137 std::vector<std::pair<typename 138 CONTAINER::iterator,G4double>>& result, 139 G4bool isSort = false) const; 140 141 void FindNearestInRange(const G4ThreeVector& /*from this point*/, 142 G4double R, 143 std::vector<std::pair< 144 typename CONTAINER::iterator,G4double> >& 145 result, 146 G4bool isSorted) const; 147 }; 148 149 #include "G4OctreeFinder.icc" 150 #endif 151