eLynx SDK
v3.3.0 C++ image processing API reference |
00001 //============================================================================ 00002 // KDTree.h Math.Component package 00003 //============================================================================ 00004 // Usage : linear algebra - KD Binary Tree 00005 //---------------------------------------------------------------------------- 00006 // Copyright (C) 2007 by eLynx project 00007 // 00008 // This library is free software; you can redistribute it and/or 00009 // modify it under the terms of the GNU Library General Public 00010 // License as published by the Free Software Foundation; either 00011 // version 2 of the License, or (at your option) any later version. 00012 // 00013 // This library is distributed in the hope that it will be useful, 00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00016 // See the GNU Library General Public License for more details. 00017 //---------------------------------------------------------------------------- 00018 #ifndef __KDTree_h__ 00019 #define __KDTree_h__ 00020 00021 #include "MathLib.h" 00022 #include <elx/math/Geometry.h> 00023 #include <boost/scoped_ptr.hpp> 00024 #include <vector> 00025 00026 namespace eLynx { 00027 namespace Math { 00028 00029 // Forward declaration 00030 template <typename T> 00031 struct KDNode; 00032 00037 template<typename T> 00038 class ExportedByMath KDTree 00039 { 00040 public: 00058 KDTree(const Point2<T>* iPoints, uint32 iSize, T iWidth, T iHeight); 00059 00064 void GetNeighbors(const Point2<T>& iPoint, uint32 iNumber, 00065 std::vector<Point2<T> >& oPoints) const; 00066 00072 bool GetNeighbor(const Point2<T>& iPoint, Point2<T>& oNeighbor, T& oDistance) const; 00073 00074 00075 protected: KDTree() {} 00076 public: ~KDTree() {} 00077 private: 00079 KDTree(const KDTree&); 00080 KDTree& operator=(const KDTree&); 00081 00083 boost::scoped_ptr<KDNode<T> > _spKDRoot; 00084 }; 00085 00086 template <typename T> 00087 struct KDNode 00088 { 00089 const KDNode<T> * _pParent; 00090 KDNode<T> * _pLeft; 00091 KDNode<T> * _pRight; 00092 Point2<T> _location; 00093 Rectangle2<T> _rectangles[2]; 00094 // For X node it's top left of the left rectangle and bottom right for the right rectangle 00095 // Y direction: Top left of the top and bottom right of the bottom rectangles 00096 00097 KDNode(); 00098 ~KDNode(); 00099 }; 00100 00101 } // namespace Math 00102 } // namespace eLynx 00103 00104 00105 #endif // __KDTree_h__