Geant4 9.6.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4KDNode Class Reference

#include <G4KDNode.hh>

Public Member Functions

 G4KDNode (G4KDTree *, const double *, void *, G4KDNode *, int axis0)
 
virtual ~G4KDNode ()
 
G4KDTreeGetTree ()
 
void SetTree (G4KDTree *)
 
const double * GetPosition ()
 
int GetDim ()
 
int GetAxis ()
 
void * GetData ()
 
void SetData (void *)
 
G4KDNodeGetParent ()
 
G4KDNodeGetLeft ()
 
G4KDNodeGetRight ()
 
G4KDNodeFindParent (const double *x0)
 
G4KDNodeInsert (const double *p, void *data)
 
int Insert (G4KDNode *newNode, double *p)
 
int Insert (G4KDNode *newNode, const double &x, const double &y, const double &z)
 
int Insert (G4KDNode *newNode)
 
void InactiveNode ()
 
void PullSubTree ()
 
void RetrieveNodeList (std::list< G4KDNode * > &node_list)
 

Protected Member Functions

int SetPosition (const double *newposition)
 

Protected Attributes

double * fPosition
 
int fAxis
 
void * fData
 
int fSide
 
G4KDTreefTree
 
G4KDNodefLeft
 
G4KDNodefRight
 
G4KDNodefParent
 

Detailed Description

G4KDNode stores one entity in G4KDTree This class is for internal use only

Definition at line 50 of file G4KDNode.hh.

Constructor & Destructor Documentation

◆ G4KDNode()

G4KDNode::G4KDNode ( G4KDTree tree,
const double *  position,
void *  data,
G4KDNode parent,
int  axis0 
)

Definition at line 71 of file G4KDNode.cc.

72 :
73 fPosition(0), fData(data), fTree(tree),
74 fLeft(0), fRight(0), fParent(parent)
75{
76 fSide = 0;
77 fAxis = axis;
79}
G4KDNode * fLeft
Definition: G4KDNode.hh:102
void * fData
Definition: G4KDNode.hh:94
G4KDTree * fTree
Definition: G4KDNode.hh:101
int SetPosition(const double *newposition)
Definition: G4KDNode.cc:125
int fAxis
Definition: G4KDNode.hh:93
double * fPosition
Definition: G4KDNode.hh:92
G4KDNode * fParent
Definition: G4KDNode.hh:102
G4KDNode * fRight
Definition: G4KDNode.hh:102
int fSide
Definition: G4KDNode.hh:95

◆ ~G4KDNode()

G4KDNode::~G4KDNode ( )
virtual

Definition at line 107 of file G4KDNode.cc.

108{
109 delete[] fPosition;
110}

Member Function Documentation

◆ FindParent()

G4KDNode * G4KDNode::FindParent ( const double *  x0)

Definition at line 138 of file G4KDNode.cc.

139{
140 G4KDNode* aParent = 0 ;
141 G4KDNode* next = this ;
142 int split = -1 ;
143 while(next)
144 {
145 split = next->fAxis ;
146 aParent = next ;
147
148 if(x0[split] > next->fPosition[split])
149 next = next->fRight ;
150 else
151 next = next->fLeft ;
152 }
153 return aParent ;
154}

Referenced by Insert().

◆ GetAxis()

int G4KDNode::GetAxis ( )
inline

Definition at line 112 of file G4KDNode.hh.

113{
114 return fAxis;
115}

Referenced by G4KDTree::__NearestInRange(), G4KDTree::__NearestToNode(), and G4KDTree::__NearestToPosition().

◆ GetData()

void * G4KDNode::GetData ( )
inline

Definition at line 117 of file G4KDNode.hh.

118{
119 return fData;
120}

Referenced by G4KDTree::__Clear_Rec(), G4KDTree::__NearestToNode(), G4KDTree::__NearestToPosition(), and GetData().

◆ GetDim()

int G4KDNode::GetDim ( )

Definition at line 112 of file G4KDNode.cc.

113{
114 if(fTree)
115 return fTree->GetDim();
116 else
117 return -1;
118}
int GetDim()
Definition: G4KDTree.hh:136

◆ GetLeft()

G4KDNode * G4KDNode::GetLeft ( )
inline

◆ GetParent()

G4KDNode * G4KDNode::GetParent ( )
inline

Definition at line 132 of file G4KDNode.hh.

133{
134 return fParent;
135}

◆ GetPosition()

const double * G4KDNode::GetPosition ( )
inline

◆ GetRight()

G4KDNode * G4KDNode::GetRight ( )
inline

◆ GetTree()

G4KDTree * G4KDNode::GetTree ( )
inline

Definition at line 147 of file G4KDNode.hh.

148{
149 return fTree;
150}

◆ InactiveNode()

void G4KDNode::InactiveNode ( )

Definition at line 120 of file G4KDNode.cc.

121{
122 fData = 0 ;
123}

Referenced by InactiveNode().

◆ Insert() [1/4]

G4KDNode * G4KDNode::Insert ( const double *  p,
void *  data 
)

Definition at line 156 of file G4KDNode.cc.

157{
158 G4KDNode* aParent = FindParent(p);
159 // TODO check p == aParent->pos
160 // Exception
161
162 G4KDNode* newNode = new G4KDNode(fTree, p, data, aParent,
163 aParent->fAxis +1 < fTree->fDim? aParent->fAxis+1:0);
164
165 if(p[aParent->fAxis] > aParent->fPosition[aParent->fAxis])
166 {
167 aParent->fRight = newNode ;
168 newNode->fSide = 1 ;
169 }
170 else
171 {
172 aParent->fLeft = newNode ;
173 newNode->fSide = -1 ;
174 }
175
176 return newNode ;
177}
G4KDNode * FindParent(const double *x0)
Definition: G4KDNode.cc:138

Referenced by G4KDTree::Insert(), and Insert().

◆ Insert() [2/4]

int G4KDNode::Insert ( G4KDNode newNode)

Definition at line 215 of file G4KDNode.cc.

216{
217 return Insert(newNode, newNode->fPosition);
218}
G4KDNode * Insert(const double *p, void *data)
Definition: G4KDNode.cc:156

◆ Insert() [3/4]

int G4KDNode::Insert ( G4KDNode newNode,
const double &  x,
const double &  y,
const double &  z 
)

Definition at line 206 of file G4KDNode.cc.

207{
208 double p[3] ;
209 p[0] = x;
210 p[1] = y ;
211 p[2] = z ;
212 return Insert(newNode, p);
213}

◆ Insert() [4/4]

int G4KDNode::Insert ( G4KDNode newNode,
double *  p 
)

Definition at line 180 of file G4KDNode.cc.

181{
182 G4KDNode* aParent = FindParent(p);
183 // TODO check p == aParent->pos
184 // Exception
185
186 newNode->fAxis = aParent->fAxis +1 < fTree->fDim? aParent->fAxis+1:0;
187 newNode->fParent = aParent ;
188
189 if(p[aParent->fAxis] > aParent->fPosition[aParent->fAxis])
190 {
191 aParent->fRight = newNode ;
192 newNode->fSide = 1 ;
193 }
194 else
195 {
196 aParent->fLeft = newNode ;
197 newNode->fSide = -1 ;
198 }
199
200 newNode->fRight = 0;
201 newNode->fLeft = 0;
202
203 return 0 ;
204}

◆ PullSubTree()

void G4KDNode::PullSubTree ( )

Definition at line 220 of file G4KDNode.cc.

221{
222 if(fParent)
223 {
224 if(fSide == -1)
225 {
226 fParent->fLeft = 0;
227 }
228 else
229 fParent->fRight = 0;
230 }
231 if(fLeft) fLeft -> PullSubTree();
232 if(fRight) fRight-> PullSubTree();
233
234 fParent = 0 ;
235 fRight = 0 ;
236 fLeft = 0 ;
237 fTree = 0 ;
238}
void PullSubTree()
Definition: G4KDNode.cc:220

Referenced by PullSubTree().

◆ RetrieveNodeList()

void G4KDNode::RetrieveNodeList ( std::list< G4KDNode * > &  node_list)

Definition at line 240 of file G4KDNode.cc.

241{
242 output.push_back(this);
243
244 if(fLeft)
245 fLeft->RetrieveNodeList(output);
246
247 if(fRight)
248 fRight->RetrieveNodeList(output);
249}
void RetrieveNodeList(std::list< G4KDNode * > &node_list)
Definition: G4KDNode.cc:240

Referenced by RetrieveNodeList().

◆ SetData()

void G4KDNode::SetData ( void *  data)
inline

Definition at line 122 of file G4KDNode.hh.

123{
124 fData = data;
125}

Referenced by G4KDTree::__Clear_Rec().

◆ SetPosition()

int G4KDNode::SetPosition ( const double *  newposition)
protected

Definition at line 125 of file G4KDNode.cc.

126{
127 if(!newposition) return -1;
128 if(!fPosition)
129 {
130 fPosition = new double[fTree->fDim];
131 }
132
133 memcpy(fPosition, newposition, fTree->fDim * sizeof(double));
134
135 return 0;
136}

Referenced by G4KDNode().

◆ SetTree()

void G4KDNode::SetTree ( G4KDTree tree)
inline

Definition at line 152 of file G4KDNode.hh.

153{
154 fTree = tree;
155}

Member Data Documentation

◆ fAxis

int G4KDNode::fAxis
protected

Definition at line 93 of file G4KDNode.hh.

Referenced by FindParent(), G4KDNode(), GetAxis(), and Insert().

◆ fData

void* G4KDNode::fData
protected

Definition at line 94 of file G4KDNode.hh.

Referenced by GetData(), InactiveNode(), and SetData().

◆ fLeft

G4KDNode* G4KDNode::fLeft
protected

Definition at line 102 of file G4KDNode.hh.

Referenced by FindParent(), GetLeft(), Insert(), PullSubTree(), and RetrieveNodeList().

◆ fParent

G4KDNode * G4KDNode::fParent
protected

Definition at line 102 of file G4KDNode.hh.

Referenced by GetParent(), Insert(), and PullSubTree().

◆ fPosition

double* G4KDNode::fPosition
protected

Definition at line 92 of file G4KDNode.hh.

Referenced by FindParent(), GetPosition(), Insert(), SetPosition(), and ~G4KDNode().

◆ fRight

G4KDNode * G4KDNode::fRight
protected

Definition at line 102 of file G4KDNode.hh.

Referenced by FindParent(), GetRight(), Insert(), PullSubTree(), and RetrieveNodeList().

◆ fSide

int G4KDNode::fSide
protected

Definition at line 95 of file G4KDNode.hh.

Referenced by G4KDNode(), Insert(), and PullSubTree().

◆ fTree

G4KDTree* G4KDNode::fTree
protected

Definition at line 101 of file G4KDNode.hh.

Referenced by GetDim(), GetTree(), Insert(), PullSubTree(), SetPosition(), and SetTree().


The documentation for this class was generated from the following files: