Warning, file /include/root/TKDTree.h was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 #ifndef ROOT_TKDTree
0002 #define ROOT_TKDTree
0003
0004 #include "TObject.h"
0005
0006 #include "TMath.h"
0007 #include <vector>
0008
0009 template <typename Index, typename Value> class TKDTree : public TObject
0010 {
0011 public:
0012
0013 TKDTree();
0014 TKDTree(Index npoints, Index ndim, UInt_t bsize);
0015 TKDTree(Index npoints, Index ndim, UInt_t bsize, Value **data);
0016 ~TKDTree() override;
0017
0018 void Build();
0019
0020 Double_t Distance(const Value *point, Index ind, Int_t type=2) const;
0021 void DistanceToNode(const Value *point, Index inode, Value &min, Value &max, Int_t type=2);
0022
0023
0024 Int_t GetLeft(Int_t inode) const {return inode*2+1;}
0025 Int_t GetRight(Int_t inode) const {return (inode+1)*2;}
0026 Int_t GetParent(Int_t inode) const {return (inode-1)/2;}
0027
0028
0029 Index* GetPointsIndexes(Int_t node) const;
0030 void GetNodePointsIndexes(Int_t node, Int_t &first1, Int_t &last1, Int_t &first2, Int_t &last2) const;
0031 UChar_t GetNodeAxis(Int_t id) const {return (id < 0 || id >= fNNodes) ? 0 : fAxis[id];}
0032 Value GetNodeValue(Int_t id) const {return (id < 0 || id >= fNNodes) ? 0 : fValue[id];}
0033 Int_t GetNNodes() const {return fNNodes;}
0034 Int_t GetTotalNodes() const {return fTotalNodes;}
0035 Value* GetBoundaries();
0036 Value* GetBoundariesExact();
0037 Value* GetBoundary(const Int_t node);
0038 Value* GetBoundaryExact(const Int_t node);
0039 Index GetNPoints() { return fNPoints; }
0040 Index GetNDim() { return fNDim; }
0041 Index GetNPointsNode(Int_t node) const;
0042
0043
0044 Int_t GetRowT0() {return fRowT0;}
0045 Int_t GetCrossNode() {return fCrossNode;}
0046 Int_t GetOffset() {return fOffset;}
0047 Index* GetIndPoints() {return fIndPoints;}
0048 Index GetBucketSize() {return fBucketSize;}
0049
0050 void FindNearestNeighbors(const Value *point, Int_t k, Index *ind, Value *dist);
0051 Index FindNode(const Value * point) const;
0052 void FindPoint(Value * point, Index &index, Int_t &iter);
0053 void FindInRange(Value *point, Value range, std::vector<Index> &res);
0054 void FindBNodeA(Value * point, Value * delta, Int_t &inode);
0055
0056 Bool_t IsTerminal(Index inode) const {return (inode>=fNNodes);}
0057 Int_t IsOwner() { return fDataOwner; }
0058 Value KOrdStat(Index ntotal, Value *a, Index k, Index *index) const;
0059
0060
0061 void MakeBoundaries(Value *range = nullptr);
0062 void MakeBoundariesExact();
0063 void SetData(Index npoints, Index ndim, UInt_t bsize, Value **data);
0064 Int_t SetData(Index idim, Value *data);
0065 void SetOwner(Int_t owner) { fDataOwner = owner; }
0066 void Spread(Index ntotal, Value *a, Index *index, Value &min, Value &max) const;
0067
0068 private:
0069 TKDTree(const TKDTree &);
0070 TKDTree<Index, Value>& operator=(const TKDTree<Index, Value>&);
0071 void CookBoundaries(const Int_t node, Bool_t left);
0072
0073 void UpdateNearestNeighbors(Index inode, const Value *point, Int_t kNN, Index *ind, Value *dist);
0074 void UpdateRange(Index inode, Value *point, Value range, std::vector<Index> &res);
0075
0076 protected:
0077 Int_t fDataOwner;
0078 Int_t fNNodes;
0079 Int_t fTotalNodes;
0080 Index fNDim;
0081 Index fNDimm;
0082 Index fNPoints;
0083 Index fBucketSize;
0084 UChar_t *fAxis;
0085 Value *fValue;
0086
0087 Value *fRange;
0088 Value **fData;
0089 Value *fBoundaries;
0090
0091
0092 Index *fIndPoints;
0093 Int_t fRowT0;
0094 Int_t fCrossNode;
0095 Int_t fOffset;
0096
0097
0098
0099
0100 ClassDefOverride(TKDTree, 1)
0101 };
0102
0103
0104 typedef TKDTree<Int_t, Double_t> TKDTreeID;
0105 typedef TKDTree<Int_t, Float_t> TKDTreeIF;
0106
0107
0108 TKDTreeIF * TKDTreeTestBuild();
0109
0110 #endif
0111