Geant4  10.01.p02
G4KDNode.hh
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 // $Id: G4KDNode.hh 88973 2015-03-17 09:39:05Z gcosmo $
27 //
28 // Author: Mathieu Karamitros, kara@cenbg.in2p3.fr
29 
30 // The code is developed in the framework of the ESA AO7146
31 //
32 // We would be very happy hearing from you, send us your feedback! :)
33 //
34 // In order for Geant4-DNA to be maintained and still open-source,
35 // article citations are crucial.
36 // If you use Geant4-DNA chemistry and you publish papers about your software,
37 // in addition to the general paper on Geant4-DNA:
38 //
39 // Int. J. Model. Simul. Sci. Comput. 1 (2010) 157–178
40 //
41 // we would be very happy if you could please also cite the following
42 // reference papers on chemistry:
43 //
44 // J. Comput. Phys. 274 (2014) 841-882
45 // Prog. Nucl. Sci. Tec. 2 (2011) 503-508
46 
47 
48 #ifndef G4KDNODE_HH
49 #define G4KDNODE_HH
50 
51 #include <list>
52 #include <map>
53 #include <vector>
54 #include <deque>
55 #include <G4ThreeVector.hh>
56 #include <G4Allocator.hh>
57 
58 #include "globals.hh"
59 #include <ostream>
60 
61 class G4KDTree;
62 class G4KDMap;
63 
65 {
66 public :
67  //________________________
68  // For root node :
69  // parent = 0, axis = 0, side = 0
70  G4KDNode_Base(G4KDTree*, G4KDNode_Base* /*parent*/);
71  virtual ~G4KDNode_Base();
72  virtual double operator[](size_t) const = 0;
73  virtual void InactiveNode();
74  virtual bool IsValid() const{ return true; }
75 
76  //________________________
77  inline G4KDTree* GetTree() const {return fTree;}
78  inline void SetTree(G4KDTree* tree) {fTree = tree;}
79 
80  //________________________
81  int GetDim() const;
82  inline int GetAxis() const{return fAxis;}
83  inline G4KDNode_Base* GetParent(){return fParent;}
84  inline G4KDNode_Base* GetLeft(){return fLeft;}
85  inline G4KDNode_Base* GetRight(){return fRight;}
86 
87  //________________________
88  template <typename Position> G4KDNode_Base* FindParent(const Position& x0);
89  template <typename PointT> G4KDNode_Base* Insert(PointT* point);
90  int Insert(G4KDNode_Base* newNode);
91 
92  void PullSubTree();
93  void RetrieveNodeList(std::list<G4KDNode_Base*>& node_list);
94 
95  void Print(std::ostream& out, int level = 0) const ;
96 
97 // std::vector<std::deque<G4KDNode_Base* >::iterator >* GetIteratorsForSortingAlgo(G4KDMap*);
98 // std::map<G4KDMap*, std::vector<std::deque<G4KDNode_Base* >::iterator > >* fpIteratorInSortingAlgo;
99 
100 protected :
101  //°°°°°°°°°°°
102  // Members
103  //°°°°°°°°°°°
104  size_t fAxis; // axis : x, y, z ...
105  int fSide ; // left/right
106  /* fSide == 0 : Is the root node
107  * fSide == -1 : It is the left of the parent node
108  * fSide == 1 : It is the right of the parent node
109  */
110 
113  /* Left : fLeft->fPosition[axis] < this->fPosition[axis]
114  * Right : fRight->fPosition[axis] > this->fPosition[axis]
115  * Root node : fParent = 0
116  */
117 private :
120 };
121 
127 template <typename PointT>
128 class G4KDNode : public G4KDNode_Base
129 {
130 public :
131  //________________________
132  // For root node :
133  // parent = 0, axis = 0, side = 0
134  G4KDNode(G4KDTree*, PointT* /*point*/,
135  G4KDNode_Base* /*parent*/);
136  virtual ~G4KDNode();
137 
138  void *operator new(size_t);
139  void operator delete(void *);
140 
141  inline PointT* GetPoint() {
142  return fPoint;
143  }
144 
145  virtual double operator[](size_t i) const
146  {
147  if(fPoint == 0) abort();
148  return (*fPoint)[i];
149  }
150 
151  virtual void InactiveNode()
152  {
153  fValid = false;
155  }
156 
157  virtual bool IsValid() const
158  {
159  return fValid;
160  }
161 
162 protected:
163  PointT* fPoint;
165 
166 private :
169 
171 };
172 
173 template <typename PointT>
175 
176 template<typename PointT>
177 void* G4KDNode<PointT>::operator new(size_t)
178 {
179  if (!fgAllocator) fgAllocator = new G4Allocator<G4KDNode<PointT> >;
180  return (void *) fgAllocator->MallocSingle();
181 }
182 
183 template<typename PointT>
184 void G4KDNode<PointT>::operator delete(void *aNode)
185 {
186  fgAllocator->FreeSingle((G4KDNode<PointT> *) aNode);
187 }
188 
189 #include "G4KDNode.icc"
190 
191 #endif // G4KDNODE_HH
Type * MallocSingle()
Definition: G4Allocator.hh:191
void SetTree(G4KDTree *tree)
Definition: G4KDNode.hh:78
virtual bool IsValid() const
Definition: G4KDNode.hh:157
G4KDNode(G4KDTree *, PointT *, G4KDNode_Base *)
G4KDNode_Base * fLeft
Definition: G4KDNode.hh:112
PointT * GetPoint()
Definition: G4KDNode.hh:141
static G4ThreadLocal G4Allocator< G4KDNode< PointT > > * fgAllocator
Definition: G4KDNode.hh:170
G4KDNode_Base * Insert(PointT *point)
G4KDNode_Base * GetRight()
Definition: G4KDNode.hh:85
G4KDTree * GetTree() const
Definition: G4KDNode.hh:77
G4KDTree is used by the ITManager to locate the neareast neighbours.
Definition: G4KDTree.hh:72
PointT * fPoint
Definition: G4KDNode.hh:163
int GetAxis() const
Definition: G4KDNode.hh:82
virtual ~G4KDNode_Base()
Definition: G4KDNode.cc:103
#define G4ThreadLocal
Definition: tls.hh:89
void RetrieveNodeList(std::list< G4KDNode_Base * > &node_list)
Definition: G4KDNode.cc:167
void Print(std::ostream &out, int level=0) const
Definition: G4KDNode.cc:178
virtual void InactiveNode()
Definition: G4KDNode.hh:151
virtual ~G4KDNode()
int GetDim() const
Definition: G4KDNode.cc:112
bool G4bool
Definition: G4Types.hh:79
size_t fAxis
Definition: G4KDNode.hh:104
G4KDNode stores one entity in G4KDTree This class is for internal use only.
Definition: G4KDNode.hh:128
virtual void InactiveNode()
Definition: G4KDNode.cc:107
G4KDNode_Base * FindParent(const Position &x0)
G4KDNode_Base & operator=(const G4KDNode_Base &right)
Definition: G4KDNode.cc:91
virtual bool IsValid() const
Definition: G4KDNode.hh:74
G4KDNode_Base * fParent
Definition: G4KDNode.hh:112
virtual double operator[](size_t) const =0
G4KDNode_Base * GetParent()
Definition: G4KDNode.hh:83
void PullSubTree()
Definition: G4KDNode.cc:147
virtual double operator[](size_t i) const
Definition: G4KDNode.hh:145
G4KDTree * fTree
Definition: G4KDNode.hh:111
G4bool fValid
Definition: G4KDNode.hh:164
G4KDNode_Base(G4KDTree *, G4KDNode_Base *)
Definition: G4KDNode.cc:72
G4KDNode & operator=(const G4KDNode< PointT > &right)
G4KDNode_Base * fRight
Definition: G4KDNode.hh:112
G4KDNode_Base * GetLeft()
Definition: G4KDNode.hh:84