Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members

mitkKdTree.h

00001 /*=========================================================================
00002 
00003   Program:   3DMed
00004   Date:      $Date: 2014-02-25 18:30:00 +0800 $
00005   Version:   $Version: 4.6.0 $
00006   Copyright: MIPG, Institute of Automation, Chinese Academy of Sciences
00007 
00008 =========================================================================*/
00009 
00010 
00011 #ifndef __mitkKdTree_h
00012 #define __mitkKdTree_h
00013 
00014 #include "mitkRegistrationIncludes.h"
00015 #include "mitkObject.h"
00016 #include "mitkPointSet.h"
00017 
00018 
00019 class mitkKdTreeNode;
00020 class mitk_kd_heap_entry;
00021 
00028 class MITK_REGISTRATION_API mitkKdTree
00029 {
00030 public:
00036     mitkKdTree(mitkPointSet* points, int points_per_leaf=4 );
00037 
00041     ~mitkKdTree();
00042 
00049     void GetPointsKNearest(double* queryPoint, int k, vector<int>& closestIndices);
00050 
00056     void GetPointsInBoundingBox(mitkBoundingBox<double>& box, vector<int>& indices_in_box);
00057 
00064     void GetPointsInRadius(double* query_point, double radius, vector<int>& indices_in_radius);
00065 
00070     void SetFlagUseHeap(bool flag) {m_FlagUseHeap = flag;}
00071 
00072 protected:
00073     mitkBoundingBox<double> Build_inner_box(const vector<int>* indices);
00074 
00075     mitkKdTreeNode* Build_kd_tree(int points_per_leaf,mitkBoundingBox<double>& outer_box,int depth,vector<int>* indices );
00076 
00077     int Find_greatest_variation(const vector<int>* indices);
00078 
00079     void Free_kd_tree(mitkKdTreeNode* p);
00080 
00081     void K_nearest_with_stack(double* query_point, int k, mitkKdTreeNode* root, vector<int>& closestIndices,
00082         vector<double>& sq_distances, int& num_found);
00083 
00084     void K_nearest_with_heap(double* query_point, int k,mitkKdTreeNode* root, vector<int>& closest_indices,
00085         vector<double>& sq_distances, int& num_found,int max_leaves);
00086 
00087     void Update_closest(double* query_point, int k, mitkKdTreeNode* p, vector<int>& closestIndices,
00088         vector<double>& sq_distances, int& num_found );
00089 
00090     bool Bounded_at_leaf(double* query_point, int k, mitkKdTreeNode* current, vector<double>& sq_distances, int& num_found );
00091 
00092     void Points_in_bounding_box(mitkKdTreeNode* current, mitkBoundingBox<double>& box, vector<int>& indices_in_box);
00093 
00094     void Report_all_in_subtree(mitkKdTreeNode* current, vector<int>& indices);
00095 
00096     mitkKdTreeNode* m_RootNode;
00097     mitkPointSet*   m_Points;
00098 
00099     unsigned int    m_PointSetDimension;
00100     int             m_Leaf_count;
00101     int             m_Leaf_examined;
00102     int             m_Internal_count;
00103     int             m_Internal_examined;
00104 
00105     bool            m_FlagUseHeap;
00106     
00107 
00108 private:
00109     mitkKdTree(const mitkKdTree&);
00110     void operator=(const mitkKdTree&);
00111 };
00112 
00113 class mitkKdTreeNode
00114 {
00115 public:
00116     //for internal node
00117     mitkKdTreeNode(mitkBoundingBox<double>& outerBox, mitkBoundingBox<double>& innerBox, unsigned int depth);
00118 
00119     //for leaf node
00120     mitkKdTreeNode(mitkBoundingBox<double>& outerBox, mitkBoundingBox<double>& innerBox, unsigned int depth, vector<int>* pointsInNode);
00121 
00122     mitkBoundingBox<double>     m_OuterBoundingBox;
00123     mitkBoundingBox<double>     m_InnerBoundingBox;
00124     vector<int>*                m_PointsInNode;
00125     unsigned int                m_Depth;
00126     mitkKdTreeNode*             m_LeftNode;
00127     mitkKdTreeNode*             m_RightNode;
00128 };
00129 
00130 class mitk_kd_heap_entry
00131 {
00132     public:
00133         mitk_kd_heap_entry() {}
00134         //~mitk_kd_heap_entry();
00135         mitk_kd_heap_entry( double dist, mitkKdTreeNode* p ): dist_(dist), p_(p) {}
00136         bool operator< ( const mitk_kd_heap_entry& right ) const { return right.dist_ < this->dist_; }
00137 
00138         double dist_;
00139         mitkKdTreeNode* p_;
00140 };
00141 
00142 
00143 //#define DEFINED_mitkKdTree
00144 
00145 
00146 
00147 #endif
00148 

Generated on Tue Feb 25 15:00:37 2014 for MITK (Medical Imaging ToolKit) by  doxygen 1.4.3