Image Component Library (ICL)
KDTree.h
Go to the documentation of this file.
1 /********************************************************************
2 ** Image Component Library (ICL) **
3 ** **
4 ** Copyright (C) 2006-2013 CITEC, University of Bielefeld **
5 ** Neuroinformatics Group **
6 ** Website: www.iclcv.org and **
7 ** http://opensource.cit-ec.de/projects/icl **
8 ** **
9 ** File : ICLMath/src/ICLMath/KDTree.h **
10 ** Module : ICLMath **
11 ** Authors: Christian Groszewski **
12 ** **
13 ** **
14 ** GNU LESSER GENERAL PUBLIC LICENSE **
15 ** This file may be used under the terms of the GNU Lesser General **
16 ** Public License version 3.0 as published by the **
17 ** **
18 ** Free Software Foundation and appearing in the file LICENSE.LGPL **
19 ** included in the packaging of this file. Please review the **
20 ** following information to ensure the license requirements will **
21 ** be met: http://www.gnu.org/licenses/lgpl-3.0.txt **
22 ** **
23 ** The development of this software was supported by the **
24 ** Excellence Cluster EXC 277 Cognitive Interaction Technology. **
25 ** The Excellence Cluster EXC 277 is a grant of the Deutsche **
26 ** Forschungsgemeinschaft (DFG) in the context of the German **
27 ** Excellence Initiative. **
28 ** **
29 ********************************************************************/
30 #pragma once
31 
32 #include <ICLUtils/CompatMacros.h>
33 #include <ICLMath/DynMatrix.h>
34 #include <ICLUtils/Macros.h>
35 #include <ICLUtils/BasicTypes.h>
36 #include <ICLUtils/Uncopyable.h>
37 #include <vector>
38 
39 namespace icl{
40  namespace math{
41 
43 
52  private:
54  struct Node{
62  double median;
63 
65  inline Node():left(0),right(0),point(0),median(0.0){}
66 
68  inline ~Node(){
69  if(right != 0){
70  delete right;
71  right = 0;
72  }
73  if(left != 0){
74  delete left;
75  left = 0;
76  }
77 
78  }
79  };
80 
83 
85  void print(Node *node);
87  void buildTree(std::vector<math::DynMatrix<icl64f> > &list,unsigned int depth, Node *node);
89  void buildTree(std::vector<math::DynMatrix<icl64f> *> &list,unsigned int depth, Node *node);
91  void sortList(std::vector<math::DynMatrix<icl64f> > &list, unsigned int dim);
93  void sortList(std::vector<math::DynMatrix<icl64f>* > &list, unsigned int dim);
95  void releaseTree();
96 
97  public :
99 
102  KDTree(std::vector<math::DynMatrix<icl64f> > &list);
103 
105 
108  KDTree(std::vector<math::DynMatrix<icl64f>* > &list);
109 
111 
113  KDTree(){}
114 
116  ~KDTree();
117 
119 
122  inline void buildTree(std::vector<math::DynMatrix<icl64f> *> &list){
123  releaseTree();
124  buildTree(list,0,&root);
125  }
126 
128 
131  inline void buildTree(std::vector<math::DynMatrix<icl64f> > &list){
132  releaseTree();
133  buildTree(list,0,&root);
134  }
135 
137  void print();
138 
140 
142  math::DynMatrix<icl64f>* nearestNeighbour(const math::DynMatrix<icl64f> &point);
143 
145 
147  math::DynMatrix<icl64f>* nearestNeighbour(const math::DynMatrix<icl64f> *point);
148 
149  };
150  } // namespace utils
151 }
void buildTree(std::vector< math::DynMatrix< icl64f > * > &list)
builds a kd-tree
Definition: KDTree.h:122
undocument this line if you encounter any issues!
Definition: Any.h:37
Class interface for un-copyable classes.
Definition: Uncopyable.h:64
#define ICLMath_API
Definition: CompatMacros.h:173
void buildTree(std::vector< math::DynMatrix< icl64f > > &list)
builds a kd-tree
Definition: KDTree.h:131
KDTree()
Constructor.
Definition: KDTree.h:113
Simple KD-Tree implementation.
Definition: KDTree.h:51
Node * left
left node
Definition: KDTree.h:56
~Node()
Destructor.
Definition: KDTree.h:68
Node()
Constructor.
Definition: KDTree.h:65
depth
determines the pixel type of an image (8Bit-int or 32Bit-float)
Definition: Types.h:60
Node root
the root node of the tree
Definition: KDTree.h:82
Node * right
right node
Definition: KDTree.h:58
double median
median of dimension
Definition: KDTree.h:62
Keeps data of node.
Definition: KDTree.h:54
DynMatrix< icl64f > * point
point in leafnode, else null
Definition: KDTree.h:60
void print(const core::Img< T > &image)
print the images parameters to std::out