Geant4  10.03.p01
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
G4KDTreeResult.cc
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: G4KDTreeResult.cc 101354 2016-11-15 08:27:51Z gcosmo $
27 //
28 // Author: Mathieu Karamitros (kara (AT) cenbg . in2p3 . fr)
29 //
30 // History:
31 // -----------
32 // 10 Oct 2011 M.Karamitros created
33 //
34 // -------------------------------------------------------------------
35 
36 #include "G4KDTreeResult.hh"
37 
38 using namespace std;
39 
41 
42 struct ResNode
43 {
44 public:
45  ResNode():fNode(0),fDistanceSqr(0){;}
46  ResNode(double distsqr, G4KDNode_Base* node):
47  fNode(node),fDistanceSqr(distsqr)
48  {;}
49 
50  ResNode(const ResNode& right)
51  {
52  fNode = right.fNode;
53  fDistanceSqr= right.fDistanceSqr;
54  }
55  ResNode& operator=(const ResNode& rhs)
56  {
57  if(this == &rhs) return *this;
58  fNode = rhs.fNode;
59  fDistanceSqr= rhs.fDistanceSqr;
60  return *this;
61  }
62  ~ResNode(){;}
63 
64  bool operator<(const ResNode& right) const
65  {
66  return (fDistanceSqr < right.fDistanceSqr);
67  }
68 
69  G4KDNode_Base* GetNode() { return fNode;}
70  double GetDistanceSqr() { return fDistanceSqr;}
71 
72 protected:
74  double fDistanceSqr;
75 };
76 
77 // comparison
78 bool CompareResNode(const ResNode& left,
79  const ResNode& right)
80 {
81  return left < right;
82 }
83 
85 //std::list<ResNode>()
87 {
88  fTree = tree;
89 }
90 
92 {
93  KDTR_parent::erase(begin(),end());
94  //std::list<ResNode>::erase(begin(),end());
95 }
96 
97 void G4KDTreeResult::Insert(double dis_sq, G4KDNode_Base* node)
98 {
99  //std::list<ResNode>::push_back(ResNode(dis_sq,node));
100  KDTR_parent::push_back(ResNode(dis_sq,node));
101 }
102 
104 {
105 // std::list<ResNode>::erase(begin(),end());
106 // fIterator = std::list<ResNode>::begin();
107  KDTR_parent::erase(begin(),end());
108  fIterator = KDTR_parent::begin();
109 }
110 
112 {
113  //std::list<ResNode>::sort(CompareResNode);
114  std::sort(begin(), end(), CompareResNode);
115 }
116 
118 {
119  //return std::list<ResNode>::size();
120  return KDTR_parent::size();
121 }
122 
123 size_t G4KDTreeResult::size() const
124 {
125  return KDTR_parent::size();
126  //return std::list<ResNode>::size();
127 }
128 
130 {
131  fIterator = begin();
132 }
133 
135 {
136  return (fIterator == end());
137 }
138 
140 {
141  ++fIterator;
142 }
143 
145 {
146  return (*fIterator).GetDistanceSqr();
147 }
148 
150  return (*fIterator).GetNode();
151 }
G4KDNode_Base * fNode
ResNode(const ResNode &right)
bool CompareResNode(const ResNode &left, const ResNode &right)
bool operator<(const ResNode &right) const
virtual ~G4KDTreeResult()
G4KDTreeResult(G4KDTree *)
KDTR_parent::iterator fIterator
double fDistanceSqr
double GetDistanceSqr()
size_t GetSize() const
#define G4ThreadLocal
Definition: tls.hh:89
ResNode & operator=(const ResNode &rhs)
double GetDistanceSqr() const
G4KDNode_Base * GetNode()
#define KDTR_parent
G4DLLIMPORT G4ThreadLocal G4Allocator< G4KDTreeResult > * aKDTreeAllocator
G4KDNode_Base * GetNode() const
size_t size() const
void Insert(double, G4KDNode_Base *)
G4KDTree * fTree
ResNode(double distsqr, G4KDNode_Base *node)