ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4KDNode.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4KDNode.cc
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 //
27 // Author: Mathieu Karamitros (kara (AT) cenbg . in2p3 . fr)
28 //
29 // History:
30 // -----------
31 // 10 Oct 2011 M.Karamitros created
32 //
33 // -------------------------------------------------------------------
34 
35 #include "globals.hh"
36 #include "G4KDNode.hh"
37 #include "G4KDTree.hh"
38 #include <ostream>
39 
40 //*********************************************
41 
42 //______________________________________________________________________
43 // Node functions
44 
45 //void* GetData(G4KDNode* node)
46 //{
47 // return node->GetData() ;
48 //}
49 //
50 //const double* GetNodePosition(G4KDNode* node)
51 //{
52 // return node->GetPosition() ;
53 //}
54 
55 //______________________________________________________________________
56 
58 {
59  if(node == nullptr) return;
60 // if(node->IsValid())
61  node->InactiveNode();
62 }
63 
64 void Free(G4KDNode_Base*& node)
65 {
66  if(node) delete node;
67  node = nullptr;
68 }
69 
70 //______________________________________________________________________
72  G4KDNode_Base* parent):
73  fTree(tree),
74  fLeft(0), fRight(0), fParent(parent)
75 {
76  fSide = 0;
77  fAxis = fParent == 0? 0 : fParent->fAxis +1 < fTree->fDim? fParent->fAxis+1:0;
78 }
79 
80 // Copy constructor should not be used
82  fTree(0),
83  fLeft(0), fRight(0), fParent(0)
84 {
85  fSide = 0;
86  fAxis = 0;
87 }
88 
89 // Assignement should not be used
91 {
92  if (this == &right) return *this;
93  fTree = right.fTree;
94  fLeft = right.fLeft;
95  fRight = right.fRight;
96  fParent = right.fParent;
97  fSide = right.fSide;
98  fAxis = right.fAxis;
99  return *this;
100 }
101 
103 {
104 }
105 
107 {
109 }
110 
112 {
113  if(fTree)
114  return fTree->GetDim();
115  else
116  return -1;
117 }
118 
120 {
121  G4KDNode_Base* aParent = FindParent(*newNode);
122  // TODO check p == aParent->pos
123  // Exception
124 
125  newNode->fAxis = aParent->fAxis +1 < fTree->GetDim()? aParent->fAxis+1:0;
126  newNode->fParent = aParent ;
127 
128  if((*newNode)[aParent->fAxis] > (*aParent)[aParent->fAxis])
129  {
130  aParent->fRight = newNode ;
131  newNode->fSide = 1 ;
132  }
133  else
134  {
135  aParent->fLeft = newNode ;
136  newNode->fSide = -1 ;
137  }
138 
139  newNode->fRight = 0;
140  newNode->fLeft = 0;
141 
142  return 0 ;
143 }
144 
145 
147 {
148  if(fParent)
149  {
150  if(fSide == -1)
151  {
152  fParent->fLeft = 0;
153  }
154  else
155  fParent->fRight = 0;
156  }
157  if(fLeft) fLeft -> PullSubTree();
158  if(fRight) fRight-> PullSubTree();
159 
160  fParent = 0 ;
161  fRight = 0 ;
162  fLeft = 0 ;
163  fTree = 0 ;
164 }
165 
166 void G4KDNode_Base::RetrieveNodeList(std::list<G4KDNode_Base *>& output)
167 {
168  output.push_back(this);
169 
170  if(fLeft)
171  fLeft->RetrieveNodeList(output);
172 
173  if(fRight)
174  fRight->RetrieveNodeList(output);
175 }
176 
177 void G4KDNode_Base::Print(std::ostream& out, int level) const
178 {
179  // Print node level
180  out << G4endl;
181  for (int i=0; i<level; i++) // Indent to level
182  {
183  out << " ";
184  }
185  out << level;
186 
187  // Print children
188  if(fLeft)
189  {
190  fLeft->Print(out, level + 1);
191  }
192  if(fRight)
193  {
194  fRight->Print(out, level + 1);
195  }
196 }