Geant4 11.2.2
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4OctreeFinder.hh
Go to the documentation of this file.
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......
44{
45public:
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_
57template<typename CONTAINER>
59{
60public:
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
76template<class T,typename CONTAINER>
78{
79 using Octree = G4Octree<typename CONTAINER::iterator,
81 using OctreeHandle = G4shared_ptr<Octree>;
82 using TreeMap = std::map<int, OctreeHandle>;
83
84private:
85 static G4ThreadLocal G4OctreeFinder* fInstance;
87 int fVerbose{0};
88 G4bool fIsOctreeUsed{false};
89 G4bool fIsOctreeBuit{false};
90 Extractor<CONTAINER> fExtractor;
91 TreeMap fTreeMap;
92 OctreeHandle fTree;
93public:
95
98
101
102 ~G4OctreeFinder() override;
103 void Clear() override;
104
105 void SetVerboseLevel(G4int level) override
106 {
107 fVerbose = level;
108 }
109
111 {
112 return fVerbose;
113 }
114
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
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
double G4double
Definition G4Types.hh:83
bool G4bool
Definition G4Types.hh:86
int G4int
Definition G4Types.hh:85
#define G4shared_ptr
Definition G4memory.hh:32
std::function< G4bool(const std::pair< typename CONTAINER::iterator, G4double >, const std::pair< typename CONTAINER::iterator, G4double >)> compareInterval
const G4ThreeVector operator()(typename CONTAINER::iterator it)
void FindNearestInRange(const G4ThreeVector &position, const G4int &key, G4double R, std::vector< std::pair< typename CONTAINER::iterator, G4double > > &result, G4bool isSort=false) const
void BuildTreeMap(const std::map< G4int, CONTAINER * > &listMap)
G4ITType GetITType() override
void SetOctreeUsed(G4bool used)
static G4OctreeFinder * Instance()
void FindNearestInRange(const G4Track &track, const int &key, G4double R, std::vector< std::pair< typename CONTAINER::iterator, G4double > > &result, G4bool isSort=false) const
G4bool IsOctreeUsed() const
G4int GetVerboseLevel() override
void FindNearest(const G4Track &track, const int &key, G4double R, std::vector< std::pair< typename CONTAINER::iterator, G4double > > &result, G4bool isSort=false) const
void SetVerboseLevel(G4int level) override
void FindNearestInRange(const G4ThreeVector &, G4double R, std::vector< std::pair< typename CONTAINER::iterator, G4double > > &result, G4bool isSorted) const
~G4OctreeFinder() override
void SetOctreeBuilt(G4bool used)
G4bool IsOctreeBuilt() const
void Clear() override
virtual G4ITType GetITType()=0
virtual ~G4VFinder()=default
virtual void SetVerboseLevel(G4int level)=0
virtual void Clear()=0
G4VFinder()=default
virtual G4int GetVerboseLevel()=0
#define G4ThreadLocal
Definition tls.hh:77