Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
G4KDNode.hh
이 파일의 문서화 페이지로 가기
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 108087 2017-12-21 09:00:58Z gcosmo $
27 //
28 // Author: Mathieu Karamitros
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 #ifndef G4KDNODE_HH
48 #define G4KDNODE_HH
49 
50 #include <list>
51 #include <vector>
52 #include <deque>
53 #include <ostream>
54 
55 // geant4
56 #include "G4Types.hh"
57 #include "G4Allocator.hh"
58 
59 class G4KDTree;
60 class G4KDMap;
61 
63 {
64 public:
65  //----------------------------
66  // For root node :
67  // parent = 0, axis = 0, side = 0
68  G4KDNode_Base(G4KDTree*, G4KDNode_Base* /*parent*/);
69  virtual ~G4KDNode_Base();
70  virtual double operator[](size_t) const = 0;
71  virtual void InactiveNode();
72  virtual bool IsValid() const{ return true; }
73 
74  //----------------------------
75  inline G4KDTree* GetTree() const {return fTree;}
76  inline void SetTree(G4KDTree* tree) {fTree = tree;}
77 
78  //----------------------------
79  int GetDim() const;
80  inline int GetAxis() const{return fAxis;}
81  inline G4KDNode_Base* GetParent(){return fParent;}
82  inline G4KDNode_Base* GetLeft(){return fLeft;}
83  inline G4KDNode_Base* GetRight(){return fRight;}
84 
85  //----------------------------
86  template<typename Position>
87  G4KDNode_Base* FindParent(const Position& x0);
88 
89  template<typename PointT>
90  G4KDNode_Base* Insert(PointT* point);
91  template<typename PointT>
92  G4KDNode_Base* Insert(const PointT& point);
93  int Insert(G4KDNode_Base* newNode);
94 
95  void PullSubTree();
96  void RetrieveNodeList(std::list<G4KDNode_Base*>& node_list);
97 
98  void Print(std::ostream& out, int level = 0) const;
99 
100 // std::vector<std::deque<G4KDNode_Base*>::iterator>*
101 // GetIteratorsForSortingAlgo(G4KDMap*);
102 // std::map<G4KDMap*, std::vector<std::deque<G4KDNode_Base*>::iterator>>*
103 // fpIteratorInSortingAlgo;
104 
105 protected:
106  //°°°°°°°°°°°
107  // Members
108  //°°°°°°°°°°°
109  size_t fAxis; // axis : x, y, z ...
110  int fSide; // left/right
111  /* fSide == 0 : Is the root node
112  * fSide == -1 : It is the left of the parent node
113  * fSide == 1 : It is the right of the parent node
114  */
115 
118  /* Left : fLeft->fPosition[axis] < this->fPosition[axis]
119  * Right : fRight->fPosition[axis] > this->fPosition[axis]
120  * Root node : fParent = 0
121  */
122 private:
125 };
126 
132 template<typename PointT>
133  class G4KDNode : public G4KDNode_Base
134  {
135  public:
136  //----------------------------
137  // For root node :
138  // parent = 0, axis = 0, side = 0
139  G4KDNode(G4KDTree*, PointT* /*point*/, G4KDNode_Base* /*parent*/);
140  virtual ~G4KDNode();
141 
142  void *operator new(size_t);
143  void operator delete(void *);
144 
145  inline PointT* GetPoint()
146  {
147  return fPoint;
148  }
149 
150  virtual double operator[](size_t i) const
151  {
152  if(fPoint == 0) abort();
153  return (*fPoint)[i];
154  }
155 
156  virtual void InactiveNode()
157  {
158  fValid = false;
160  }
161 
162  virtual bool IsValid() const
163  {
164  return fValid;
165  }
166 
167  protected:
168  PointT* fPoint;
169  bool fValid;
170 
171  private:
174 
176  };
177 
178 template<typename PointT>
181 
182 template<typename PointT>
183  void* G4KDNode<PointT>::operator new(size_t)
184  {
185  if(!fgAllocator) fgAllocator = new G4Allocator<G4KDNode<PointT> >;
186  return (void *) fgAllocator->MallocSingle();
187  }
188 
189 template<typename PointT>
190  void G4KDNode<PointT>::operator delete(void *aNode)
191  {
192  fgAllocator->FreeSingle((G4KDNode<PointT> *) aNode);
193  }
194 
200 template<typename PointCopyT>
202  {
203  public:
204  //----------------------------
205  // For root node :
206  // parent = 0, axis = 0, side = 0
208  const PointCopyT& point,
209  G4KDNode_Base* parent) :
210  G4KDNode_Base(tree, parent)
211  {
212  fPoint = point;
213  fValid = true;
214  }
215 
216  virtual ~G4KDNodeCopy(){}
217 
218  void *operator new(size_t)
219  {
221  return (void *) fgAllocator->MallocSingle();
222  }
223 
224  void operator delete(void* aNode)
225  {
227  }
228 
229  inline const PointCopyT& GetPoint()
230  {
231  return fPoint;
232  }
233 
234  virtual double operator[](size_t i) const
235  {
236  return fPoint[i];
237  }
238 
239  virtual void InactiveNode()
240  {
241  fValid = false;
243  }
244 
245  virtual bool IsValid() const
246  {
247  return fValid;
248  }
249 
250  protected:
251  PointCopyT fPoint;
253 
254  private:
256  G4KDNode_Base(right), fPoint(0)
257  {
258  fValid = false;
259  }
260 
263  {
264  if(this == &right) return *this;
265  fPoint = right.fPoint;
266  fTree = right.fTree;
267  fLeft = right.fLeft;
268  fRight = right.fRight;
269  fParent = right.fParent;
270  fSide = right.fSide;
271  fAxis = right.fAxis;
272  return *this;
273  }
274 
276  };
277 
278 template<typename PointT>
281 
282 #include "G4KDNode.icc"
283 
284 #endif // G4KDNODE_HH
PointT * GetPoint()
Definition: G4KDNode.hh:145
G4KDNodeCopy(G4KDTree *tree, const PointCopyT &point, G4KDNode_Base *parent)
Definition: G4KDNode.hh:207
PointCopyT fPoint
Definition: G4KDNode.hh:251
G4bool fValid
Definition: G4KDNode.hh:252
virtual bool IsValid() const
Definition: G4KDNode.hh:245
void RetrieveNodeList(std::list< G4KDNode_Base * > &node_list)
Definition: G4KDNode.cc:167
static G4ThreadLocal G4Allocator< G4KDNode< PointT > > * fgAllocator
Definition: G4KDNode.hh:175
G4KDNode_Base * Insert(PointT *point)
virtual void InactiveNode()
Definition: G4KDNode.hh:156
virtual ~G4KDNodeCopy()
Definition: G4KDNode.hh:216
Type * MallocSingle()
Definition: G4Allocator.hh:202
virtual ~G4KDNode_Base()
Definition: G4KDNode.cc:103
void FreeSingle(Type *anElement)
Definition: G4Allocator.hh:212
virtual ~G4KDNode()
void SetTree(G4KDTree *tree)
Definition: G4KDNode.hh:76
G4KDNode & operator=(const G4KDNode< PointT > &right)
G4KDNode_Base * FindParent(const Position &x0)
bool fValid
Definition: G4KDNode.hh:169
#define G4ThreadLocal
Definition: tls.hh:69
void PullSubTree()
Definition: G4KDNode.cc:147
G4KDNode_Base & operator=(const G4KDNode_Base &right)
Definition: G4KDNode.cc:91
void Print(std::ostream &out, int level=0) const
Definition: G4KDNode.cc:178
int GetAxis() const
Definition: G4KDNode.hh:80
bool G4bool
Definition: G4Types.hh:79
G4KDTree * fTree
Definition: G4KDNode.hh:116
G4KDNodeCopy(const G4KDNodeCopy< PointCopyT > &right)
Definition: G4KDNode.hh:255
G4KDNode_Base * fRight
Definition: G4KDNode.hh:117
const PointCopyT & GetPoint()
Definition: G4KDNode.hh:229
G4KDNode_Base(G4KDTree *, G4KDNode_Base *)
Definition: G4KDNode.cc:72
virtual double operator[](size_t i) const
Definition: G4KDNode.hh:234
static G4ThreadLocal G4Allocator< G4KDNodeCopy< PointCopyT > > * fgAllocator
Definition: G4KDNode.hh:275
G4KDNode_Base * GetParent()
Definition: G4KDNode.hh:81
PointT * fPoint
Definition: G4KDNode.hh:168
G4KDNode_Base * fParent
Definition: G4KDNode.hh:117
G4KDNode_Base * GetRight()
Definition: G4KDNode.hh:83
G4KDNodeCopy< PointCopyT > & operator=(const G4KDNodeCopy< PointCopyT > &right)
Definition: G4KDNode.hh:262
G4KDNode(G4KDTree *, PointT *, G4KDNode_Base *)
virtual void InactiveNode()
Definition: G4KDNode.cc:107
virtual bool IsValid() const
Definition: G4KDNode.hh:162
virtual void InactiveNode()
Definition: G4KDNode.hh:239
G4KDNode_Base * GetLeft()
Definition: G4KDNode.hh:82
size_t fAxis
Definition: G4KDNode.hh:109
G4KDNode_Base * fLeft
Definition: G4KDNode.hh:117
int GetDim() const
Definition: G4KDNode.cc:112
G4KDTree * GetTree() const
Definition: G4KDNode.hh:75
virtual double operator[](size_t i) const
Definition: G4KDNode.hh:150
virtual bool IsValid() const
Definition: G4KDNode.hh:72
virtual double operator[](size_t) const =0