Geant4 9.6.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
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
40using namespace std;
41
42struct ResNode
43{
44public:
46 ResNode(double distsqr, G4KDNode* node):fNode(node),fDistanceSqr(distsqr){;}
47 ResNode(const ResNode& right)
48 {
49 fNode = right.fNode;
51 }
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
62protected:
65
66private:
67 ResNode& operator=(const ResNode& rhs)
68 {
69 if(this == &rhs) return *this;
70 return *this;
71 }
72};
73
74// comparison
75bool 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
90void 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{
103 std::list<ResNode>::sort(CompareResNode);
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
131void* 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
138void* 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
153void* 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}
bool CompareResNode(const ResNode &left, const ResNode &right)
G4KDTreeResult(G4KDTree *)
std::list< ResNode >::iterator fIterator
void Insert(double, G4KDNode *)
void * GetItem(double *&)
void * GetItemNDistanceSQ(double &)
void * GetItemData()
virtual ~G4KDTreeResult()
double GetDistanceSqr()
G4KDTree * fTree
int GetDim()
Definition: G4KDTree.hh:136
G4KDNode * GetNode()
bool operator<(const ResNode &right) const
G4KDNode * fNode
double GetDistanceSqr()
double fDistanceSqr
ResNode(const ResNode &right)
ResNode(double distsqr, G4KDNode *node)