contrib/rpl/rgrl/rgrl_matcher_k_nearest.h
Go to the documentation of this file.
00001 #ifndef rgrl_matcher_k_nearest_h_
00002 #define rgrl_matcher_k_nearest_h_
00003 //:
00004 // \file
00005 // \author Amitha Perera
00006 // \date   Feb 2003
00007 
00008 #include <rgrl/rgrl_matcher.h>
00009 #include <rgrl/rgrl_mask_sptr.h>
00010 //: For each "from" feature, match the k nearest "to" features.
00011 //
00012 // This will map the "from" feature via the current transform and
00013 // select the k nearest "to" features to the mapped "from" feature.
00014 //
00015 // The some of the nearest features can optionally be discarded if it
00016 // is further than some threshold distance.
00017 //
00018 class rgrl_matcher_k_nearest
00019   : public rgrl_matcher
00020 {
00021  public:
00022   //: Initialize the matcher to select \a k correspondences per "from" feature.
00023   //
00024   rgrl_matcher_k_nearest( unsigned int k );
00025 
00026   //: Select at most \a k correspondences within the threshold.
00027   //
00028   // The matcher will select \a k correspondences from the list of
00029   // correspondences with Euclidean distance within the threshold
00030   // \a dist_thres.
00031   //
00032   rgrl_matcher_k_nearest( unsigned int k, double dist_thres );
00033 
00034   rgrl_match_set_sptr
00035   compute_matches( rgrl_feature_set const&       from_features,
00036                    rgrl_feature_set const&       to_features,
00037                    rgrl_view const&              current_view,
00038                    rgrl_transformation const&    current_xform,
00039                    rgrl_scale const&             /* current_scale */,
00040                    rgrl_match_set_sptr const& old_matches = 0 );
00041 
00042 
00043   // Defines type-related functions
00044   rgrl_type_macro( rgrl_matcher_k_nearest, rgrl_matcher);
00045 
00046  protected:
00047 
00048   //: validate the mapped feature
00049   bool validate( rgrl_feature_sptr const& mapped, rgrl_mask_sptr const& roi_sptr ) const;
00050 
00051   // nodes to be sorted based on distance
00052   struct internal_dist_node{
00053     double geo_err_;
00054     nodes_vec_iterator itr_;
00055     
00056     internal_dist_node(): geo_err_(-1.0){  }
00057     
00058     bool operator<( internal_dist_node const& rhs ) const;
00059   };
00060 
00061 
00062   //: This is internal to invert matches function.
00063   //  It is to restrict the number of nearest neighbors
00064   virtual
00065   void
00066   add_one_flipped_match( rgrl_match_set_sptr&      inv_set,
00067                          rgrl_view          const& current_view,
00068                          nodes_vec_iterator const& begin_iter,
00069                          nodes_vec_iterator const& end_iter ); 
00070  
00071  protected:
00072   unsigned int k_;
00073   double thres_;
00074 };
00075 
00076 #endif // rgrl_matcher_k_nearest_h_