Geant4_10
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 64057 2012-10-30 15:04:49Z 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 #include "G4KDNode.hh"
38 #include "G4KDTree.hh"
39 
40 using namespace std;
41 
42 struct ResNode
43 {
44 public:
45  ResNode():fNode(0),fDistanceSqr(0){;}
46  ResNode(double distsqr, G4KDNode* node):fNode(node),fDistanceSqr(distsqr){;}
48  {
49  fNode = right.fNode;
50  fDistanceSqr= right.fDistanceSqr;
51  }
52  ~ResNode(){;}
53 
54  bool operator<(const ResNode& right) const
55  {
56  return (fDistanceSqr < right.fDistanceSqr);
57  }
58 
59  G4KDNode* GetNode() { return fNode;}
60  double GetDistanceSqr() { return fDistanceSqr;}
61 
62 protected:
64  double fDistanceSqr;
65 
66 private:
67  ResNode& operator=(const ResNode& rhs)
68  {
69  if(this == &rhs) return *this;
70  return *this;
71  }
72 };
73 
74 // comparison
75 bool CompareResNode(const ResNode& left, const ResNode& right)
76 {
77  return left < right;
78 }
79 
81 {
82  fTree = tree;
83 }
84 
86 {
87  std::list<ResNode>::erase(begin(),end());
88 }
89 
90 void G4KDTreeResult::Insert(double pos, G4KDNode* node)
91 {
92  std::list<ResNode>::push_back(ResNode(pos,node));
93 }
94 
96 {
97  std::list<ResNode>::erase(begin(),end());
98  fIterator = std::list<ResNode>::begin();
99 }
100 
102 {
104 }
105 
107 {
108  return std::list<ResNode>::size();
109 }
110 
112 {
113  return std::list<ResNode>::size();
114 }
115 
117 {
118  fIterator = begin();
119 }
120 
122 {
123  return (fIterator == end());
124 }
125 
127 {
128  fIterator++;
129 }
130 
131 void* G4KDTreeResult::GetItem(double*& pos)
132 {
133  if(!pos) pos = new double[fTree->GetDim()];
134  memcpy(pos, (*fIterator).GetNode()->GetPosition(), fTree->GetDim() * sizeof *pos);
135  return (*fIterator).GetNode()->GetData();
136 }
137 
138 void* G4KDTreeResult::GetItem(double& x, double& y, double& z)
139 {
140  x = (*fIterator).GetNode()->GetPosition()[0];
141  y = (*fIterator).GetNode()->GetPosition()[1];
142  z = (*fIterator).GetNode()->GetPosition()[2];
143 
144  return (*fIterator).GetNode()->GetData();
145 }
146 
148 {
149  dist_sq = (*fIterator).GetDistanceSqr();
150  return (*fIterator).GetNode()->GetData();
151 }
152 
153 void* G4KDTreeResult::GetItemNDistanceSQ(double*& pos, double& dist_sq)
154 {
155  dist_sq = (*fIterator).GetDistanceSqr();
156  return GetItem(pos);
157 }
158 
160 {
161  return (*fIterator).GetNode()->GetData();
162 }
163 
165 {
166  return (*fIterator).GetDistanceSqr();
167 }
double GetDistanceSqr()
ResNode(const ResNode &right)
bool CompareResNode(const ResNode &left, const ResNode &right)
bool operator<(const ResNode &right) const
virtual ~G4KDTreeResult()
G4KDTreeResult(G4KDTree *)
double fDistanceSqr
double GetDistanceSqr()
tuple x
Definition: test.py:50
subroutine sort(A, N)
Definition: dpm25nuc7.f:4670
G4KDNode * fNode
Double_t y
Definition: plot.C:279
tuple tree
Definition: gammaraytel.py:4
void Insert(double, G4KDNode *)
std::list< ResNode >::iterator fIterator
ResNode(double distsqr, G4KDNode *node)
void * GetItemData()
void * GetItem(double *&)
G4KDTree * fTree
int GetDim()
Definition: G4KDTree.hh:143
tuple z
Definition: test.py:28
G4KDNode * GetNode()
void * GetItemNDistanceSQ(double &)