Warning, file /include/Geant4/G4KDNode.icc was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036 template<typename PointT>
0037 G4KDNode<PointT>::G4KDNode(G4KDTree* tree,
0038 PointT* point,
0039 G4KDNode_Base* parent) :
0040 G4KDNode_Base(tree, parent)
0041 {
0042 fPoint = point;
0043 fValid = true;
0044 }
0045
0046
0047 template<typename PointT>
0048 G4KDNode<PointT>::G4KDNode(const G4KDNode<PointT>& right) :
0049 G4KDNode_Base(right), fPoint(0)
0050 {
0051 fValid = false;
0052 }
0053
0054 template<typename PointT>
0055 G4KDNode<PointT>::~G4KDNode() {}
0056
0057
0058
0059 template<typename PointT>
0060 G4KDNode<PointT>& G4KDNode<PointT>::operator=(const G4KDNode<PointT>& right)
0061 {
0062 if(this == &right) return *this;
0063 fPoint = right.fPoint;
0064 fTree = right.fTree;
0065 fLeft = right.fLeft;
0066 fRight = right.fRight;
0067 fParent = right.fParent;
0068 fSide = right.fSide;
0069 fAxis = right.fAxis;
0070 return *this;
0071 }
0072
0073 template<typename Position>
0074 G4KDNode_Base* G4KDNode_Base::FindParent(const Position& x0)
0075 {
0076 G4KDNode_Base* aParent = nullptr;
0077 G4KDNode_Base* next = this;
0078 G4int split = -1;
0079 while(next)
0080 {
0081 split = (G4int)next->fAxis;
0082 aParent = next;
0083
0084
0085 if(x0[split] > (*next)[split]) next = next->fRight;
0086 else next = next->fLeft;
0087 }
0088 return aParent;
0089 }
0090
0091 template<typename PointT>
0092 G4KDNode_Base* G4KDNode_Base::Insert(PointT* point)
0093 {
0094 G4KDNode_Base* aParent = FindParent(*point);
0095
0096
0097
0098 G4KDNode_Base* newNode = new G4KDNode<PointT>(fTree, point, aParent);
0099
0100 if((*point)[(G4int)aParent->fAxis] > (*aParent)[aParent->fAxis])
0101 {
0102 aParent->fRight = newNode;
0103 newNode->fSide = 1;
0104 }
0105 else
0106 {
0107 aParent->fLeft = newNode;
0108 newNode->fSide = -1;
0109 }
0110
0111 return newNode;
0112 }
0113
0114 template<typename PointT>
0115 G4KDNode_Base* G4KDNode_Base::Insert(const PointT& point)
0116 {
0117 G4KDNode_Base* aParent = FindParent(point);
0118
0119
0120
0121 G4KDNode_Base* newNode = new G4KDNodeCopy<PointT>(fTree, point, aParent);
0122
0123 if(point[aParent->fAxis] > (*aParent)[aParent->fAxis])
0124 {
0125 aParent->fRight = newNode;
0126 newNode->fSide = 1;
0127 }
0128 else
0129 {
0130 aParent->fLeft = newNode;
0131 newNode->fSide = -1;
0132 }
0133
0134 return newNode;
0135 }
0136