contrib/rpl/rgrl/rgrl_feature_set_bins.h
Go to the documentation of this file.
00001 #ifndef rgrl_feature_set_bins_h_
00002 #define rgrl_feature_set_bins_h_
00003 //:
00004 // \file
00005 // \author Amitha Perera
00006 // \date   Feb 2003
00007 //
00008 // \verbatim
00009 //  Modifications
00010 //   Chuck Stewart - 8 Nov 2005 - added versions of nearest_feature and k_nearest_feature 
00011 //      based on point location alone 
00012 // \endverbatim
00013 
00014 #include <rsdl/rsdl_fwd.h>
00015 #include <rgrl/rgrl_feature_set.h>
00016 #include <rgrl/rgrl_mask.h>
00017 
00018 #include <vcl_memory.h>
00019 
00020 //: A set of features grouped only by N-d location.
00021 //
00022 // This class is used to store a collection of discrete features for
00023 // which proximity is determined only by location. There is no
00024 // concepts of "segments"; each feature is considered independent.
00025 //
00026 // The class is templated over the dimension in order to provide
00027 // efficient implementation of the queries.
00028 //
00029 // The underlying data structure is either rdsl_bins or
00030 // rsdl_kd_tree. when using rsdl_bins, the image region is divided
00031 // into rectangular bins, with the bin_size defaulted to 10 or defined
00032 // by the user during construction. Feature point locations and
00033 // associated values are stored in a list associated with the bin the
00034 // location falls into. When performing region searches, all bins that
00035 // intersect the query region are examined. When doing
00036 // nearest-neighbor searches, spiral search is performed, starting at
00037 // the bin containing the query point. rsdl_bins is the choice if the
00038 // data is well distributed.
00039 //
00040 // rsdl_kd_tree is multi-dimensional version of binary search tree. It
00041 // handles data clustering better than rsdl_bins. Example applications
00042 // include range data registration.
00043 //
00044 template<unsigned N>
00045 class rgrl_feature_set_bins
00046   : public rgrl_feature_set
00047 {
00048  public:
00049   //: Constructor.
00050   //  \a bin_size is only effective when \a use_bins is set true.
00051   rgrl_feature_set_bins( feature_vector const& features,
00052                          double bin_size = 10,
00053                          rgrl_feature_set_label const& label = rgrl_feature_set_label() );
00054 
00055   ~rgrl_feature_set_bins();
00056 
00057   void
00058   features_in_region( feature_vector& results, rgrl_mask_box const& roi ) const;
00059 
00060   //:  Return the features in a given circle/sphere.
00061   //
00062   void
00063   features_within_radius( feature_vector& results, vnl_vector<double> const& center, double radius ) const;
00064 
00065   //: Nearest feature based on Euclidean distance
00066   rgrl_feature_sptr
00067   nearest_feature( const vnl_vector<double>& loc ) const;
00068 
00069   //: Nearest feature based on Euclidean distance
00070   rgrl_feature_sptr
00071   nearest_feature( rgrl_feature_sptr const& feature ) const;
00072 
00073   //: Return all features within a given Euclidean distance
00074   void
00075   features_within_radius( feature_vector& results, rgrl_feature_sptr const& feature, double distance ) const;
00076 
00077   //:  Return the k nearest features based on Euclidean distance.
00078   void
00079   k_nearest_features( feature_vector& results, const vnl_vector<double>& feature_loc, unsigned int k ) const;
00080 
00081   //:  Return the k nearest features based on Euclidean distance.
00082   void
00083   k_nearest_features( feature_vector& results, rgrl_feature_sptr const& feature, unsigned int k ) const;
00084 
00085   //:  Return the bounding box encloses the feature set
00086   rgrl_mask_box
00087   bounding_box() const;
00088 
00089   //:  Return the type of feature
00090   const vcl_type_info&
00091   type() const;
00092 
00093   // Defines type-related functions
00094   rgrl_type_macro( rgrl_feature_set_bins, rgrl_feature_set );
00095 
00096  private:
00097   typedef rsdl_bins<N,double,rgrl_feature_sptr> bin_type;
00098 
00099   const vcl_type_info* feature_type_;
00100 
00101   rgrl_mask_box bounding_box_;
00102 
00103   // Using bins as the data structure
00104   vcl_auto_ptr< bin_type > bins_;
00105 
00106   // Using kd_tree as the data structure
00107   //feature_vector features_;
00108   //rsdl_kd_tree_sptr kd_tree_;
00109 };
00110 
00111 
00112 #endif // rgrl_feature_set_bins_h_