Geant4  10.00.p01
G4KDTree.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: G4KDTree.hh 70171 2013-05-24 13:34:18Z gcosmo $
27 //
28 // Author: Mathieu Karamitros (kara (AT) cenbg . in2p3 . fr)
29 //
30 // WARNING : This class is released as a prototype.
31 // It might strongly evolve or even disapear in the next releases.
32 //
33 // History:
34 // -----------
35 // 10 Oct 2011 M.Karamitros created
36 //
37 // -------------------------------------------------------------------
38 
39 #ifndef G4KDTREE_HH
40 #define G4KDTREE_HH
41 
42 #include <vector>
43 #include "G4KDTreeResult.hh"
44 
45 class G4KDMap;
46 
47 //__________________________________
48 // Methods to act on kdnode
49 // Methods defined in G4KDNode.cc :
50 void InactiveNode(G4KDNode*);
51 void Free(G4KDNode*&);
52 void* GetData(G4KDNode*);
53 const double* GetNodePosition(G4KDNode*);
54 //__________________________________
55 
62 class G4KDTree
63 {
64  friend class G4KDNode ;
65  int fDim;
66  struct HyperRect *fRect;
67  void (*fDestr)(void*);
68  int fNbNodes;
70 
71 protected :
73 
74 public :
75  G4KDTree(int dim = 3);
76  virtual ~G4KDTree();
77 
78  void Clear();
79 
80  inline int GetDim();
81  inline void SetDataDestructor(void (*fDestr)(void*));
82 
83  int GetNbNodes() { return fNbNodes; }
84  G4KDNode* GetRoot() { return fRoot ; }
85 
86  G4KDNode* InsertMap(const double& x, const double& y, const double& z, void *data);
87  G4KDNode* InsertMap(const double *pos, void *data);
88  void Build();
89 
90  // Insert and attache the data to a node at the specified position
91  // In return, it gives you the corresponding node
92  G4KDNode* Insert(const double *pos, void *data);
93  G4KDNode* Insert(const double& x, const double& y, const double& z, void *data); // 3D
94 
95  /* Find one of the nearest nodes from the specified point.
96  *
97  * This function returns a pointer to a result set with at most one element.
98  */
99  G4KDTreeResultHandle Nearest( const double *pos);
100  G4KDTreeResultHandle Nearest( const double& x, const double& y, const double& z); // 3D
102 
103  /* Find any nearest nodes from the specified point within a range.
104  *
105  * This function returns a pointer to a result set, which can be manipulated
106  * by the G4KDTreeResult.
107  * The returned pointer can be null as an indication of an error. Otherwise
108  * a valid result set is always returned which may contain 0 or more elements.
109  */
110  G4KDTreeResultHandle NearestInRange( const double *pos, const double& range);
111  G4KDTreeResultHandle NearestInRange( const double& x,
112  const double& y,
113  const double& z,
114  const double& range); // 3D
115  G4KDTreeResultHandle NearestInRange( G4KDNode* node, const double& range);
116 
117 protected :
118  void __Clear_Rec(G4KDNode *node) ;
119 
120  int __NearestInRange(G4KDNode *node,
121  const double *pos,
122  const double& range_sq,
123  const double& range,
124  G4KDTreeResult& list,
125  int ordered,
126  G4KDNode *source_node = 0);
127 
128  void __NearestToPosition(G4KDNode *node,
129  const double *pos,
130  G4KDNode *&result,
131  double *result_dist_sq,
132  struct HyperRect* fRect);
133 
134  void __NearestToNode(G4KDNode *source_node,
135  G4KDNode *node,
136  const double *pos,
137  std::vector<G4KDNode*>& result,
138  double *result_dist_sq,
139  struct HyperRect* fRect,
140  int& nbresult) ;
141 };
142 
143 inline int G4KDTree::GetDim()
144 {
145  return fDim ;
146 }
147 
148 void G4KDTree::SetDataDestructor(void (*fct)(void*))
149 {
150  fDestr = fct;
151 }
152 
153 #endif // G4KDTREE_HH
void(* fDestr)(void *)
Definition: G4KDTree.hh:67
void SetDataDestructor(void(*fDestr)(void *))
Definition: G4KDTree.hh:148
void Clear()
Definition: G4KDTree.cc:193
void InactiveNode(G4KDNode *)
Definition: G4KDNode.cc:57
void __Clear_Rec(G4KDNode *node)
Definition: G4KDTree.cc:206
G4double z
Definition: TRTMaterials.hh:39
G4KDNode * GetRoot()
Definition: G4KDTree.hh:84
G4KDTree(int dim=3)
Definition: G4KDTree.cc:170
G4KDTree is used by the ITManager to locate the neareast neighbours.
Definition: G4KDTree.hh:62
int fNbNodes
Definition: G4KDTree.hh:68
struct HyperRect * fRect
Definition: G4KDTree.hh:66
int __NearestInRange(G4KDNode *node, const double *pos, const double &range_sq, const double &range, G4KDTreeResult &list, int ordered, G4KDNode *source_node=0)
Definition: G4KDTree.cc:303
G4KDMap * fKDMap
Definition: G4KDTree.hh:69
G4KDTreeResultHandle Nearest(const double *pos)
Definition: G4KDTree.cc:428
G4KDNode stores one entity in G4KDTree This class is for internal use only.
Definition: G4KDNode.hh:50
void Build()
Definition: G4KDTree.cc:241
void __NearestToNode(G4KDNode *source_node, G4KDNode *node, const double *pos, std::vector< G4KDNode * > &result, double *result_dist_sq, struct HyperRect *fRect, int &nbresult)
Definition: G4KDTree.cc:462
G4KDNode * InsertMap(const double &x, const double &y, const double &z, void *data)
Definition: G4KDTree.cc:224
int fDim
Definition: G4KDTree.hh:65
int GetDim()
Definition: G4KDTree.hh:143
const double * GetNodePosition(G4KDNode *)
Definition: G4KDNode.cc:50
void __NearestToPosition(G4KDNode *node, const double *pos, G4KDNode *&result, double *result_dist_sq, struct HyperRect *fRect)
Definition: G4KDTree.cc:350
G4KDTreeResultHandle NearestInRange(const double *pos, const double &range)
Definition: G4KDTree.cc:603
virtual ~G4KDTree()
Definition: G4KDTree.cc:179
void Free(G4KDNode *&)
Definition: G4KDNode.cc:63
G4KDNode * fRoot
Definition: G4KDTree.hh:72
void * GetData(G4KDNode *)
Definition: G4KDNode.cc:45
G4KDNode * Insert(const double *pos, void *data)
Definition: G4KDTree.cc:263
static const G4double pos
int GetNbNodes()
Definition: G4KDTree.hh:83
G4KDTreeResult enables to go through the nearest entities found by G4KDTree.