contrib/rpl/rgrl/rgrl_feature_set_location.h
Go to the documentation of this file.
00001 #ifndef rgrl_feature_set_location_h_
00002 #define rgrl_feature_set_location_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 class rsdl_kd_tree;
00015 #include <vbl/vbl_smart_ptr.h>
00016 typedef vbl_smart_ptr<rsdl_kd_tree> rsdl_kd_tree_sptr;
00017 #include <rsdl/rsdl_point.h>
00018 
00019 #include <rgrl/rgrl_feature_set.h>
00020 #include <rgrl/rgrl_mask.h>
00021 // not used? #include <vcl_memory.h>
00022 
00023 //: A set of features grouped only by N-d location.
00024 //
00025 // This class is used to store a collection of discrete features for
00026 // which proximity is determined only by location. There is no
00027 // concepts of "segments"; each feature is considered independent.
00028 //
00029 // The class is templated over the dimension in order to provide
00030 // efficient implementation of the queries.
00031 //
00032 // The underlying data structure is either rdsl_bins or
00033 // rsdl_kd_tree. when using rsdl_bins, the image region is divided
00034 // into rectangular bins, with the bin_size defaulted to 10 or defined
00035 // by the user during construction. Feature point locations and
00036 // associated values are stored in a list associated with the bin the
00037 // location falls into. When performing region searches, all bins that
00038 // intersect the query region are examined. When doing
00039 // nearest-neighbor searches, spiral search is performed, starting at
00040 // the bin containing the query point. rsdl_bins is the choice if the
00041 // data is well distributed.
00042 //
00043 // rsdl_kd_tree is multi-dimensional version of binary search tree. It
00044 // handles data clustering better than rsdl_bins. Example applications
00045 // include range data registration.
00046 //
00047 template<unsigned N>
00048 class rgrl_feature_set_location
00049   : public rgrl_feature_set
00050 {
00051  public:
00052   //: Constructor.
00053   //  \a bin_size is only effective when \a use_bins is set true.
00054   rgrl_feature_set_location( feature_vector const& features,
00055                              rgrl_feature_set_label const& label = rgrl_feature_set_label() );
00056 
00057   ~rgrl_feature_set_location();
00058 
00059   void
00060   features_in_region( feature_vector& results, rgrl_mask_box const& roi ) const;
00061 
00062   //:  Return the features in a given circle/sphere.
00063   //
00064   void
00065   features_within_radius( feature_vector& results, vnl_vector<double> const& center, double radius ) const;
00066 
00067   //: Nearest feature based on Euclidean distance
00068   rgrl_feature_sptr
00069   nearest_feature( const vnl_vector<double>& loc ) const;
00070 
00071   //: Nearest feature based on Euclidean distance
00072   rgrl_feature_sptr
00073   nearest_feature( rgrl_feature_sptr const& feature ) const;
00074 
00075   //: Return all features within a given Euclidean distance
00076   void
00077   features_within_radius( feature_vector& results, rgrl_feature_sptr const& feature, double distance ) const;
00078 
00079   //:  Return the k nearest features based on Euclidean distance.
00080   void
00081   k_nearest_features( feature_vector& results, const vnl_vector<double>& feature_loc, unsigned int k ) const;
00082 
00083   //:  Return the k nearest features based on Euclidean distance.
00084   void
00085   k_nearest_features( feature_vector& results, rgrl_feature_sptr const& feature, unsigned int k ) const;
00086 
00087   //:  Return the bounding box encloses the feature set
00088   rgrl_mask_box
00089   bounding_box() const;
00090 
00091   //:  Return the type of feature
00092   const vcl_type_info&
00093   type() const;
00094 
00095   // Defines type-related functions
00096   rgrl_type_macro( rgrl_feature_set_location, rgrl_feature_set );
00097 
00098  protected:
00099   inline
00100   void clear_temp_storage() const
00101   {
00102     // do not use clear() here,
00103     // because clear() may release the
00104     // storage space, which is not desired
00105     temp_points_.resize(0);
00106     temp_point_indices_.resize(0);
00107   }
00108 
00109  private:
00110   const vcl_type_info* feature_type_;
00111 
00112   rgrl_mask_box bounding_box_;
00113 
00114   // Using kd_tree as the data structure
00115   rsdl_kd_tree_sptr kd_tree_;
00116 
00117   // temp storage space
00118   mutable vcl_vector<rsdl_point> temp_points_;
00119   mutable vcl_vector<int>        temp_point_indices_;
00120 };
00121 
00122 
00123 #endif // rgrl_feature_set_location_h_