contrib/rpl/rgrl/rgrl_feature_set_bins_2d.h
Go to the documentation of this file.
00001 #ifndef rgrl_feature_set_bins_2d_h_
00002 #define rgrl_feature_set_bins_2d_h_
00003 //:
00004 // \file
00005 // \author Gehua Yang
00006 // \date   Feb 2006
00007 //
00008 // \verbatim
00009 //  Modifications
00010 //   Gehua Yang -- Modified from rgrl_feature_set_location class. 
00011 //      The reason is rsdl_bins has problems on finding k-nearest points
00012 // \endverbatim
00013 
00014 #include <rsdl/rsdl_bins_2d.h>
00015 
00016 #include "rgrl_feature.h"
00017 #include "rgrl_feature_set.h"
00018 #include "rgrl_mask.h"
00019 
00020 #include <vcl_memory.h>
00021 
00022 //: A set of features grouped only by N-d location.
00023 //
00024 // This class is used to store a collection of discrete features for
00025 // which proximity is determined only by location. There is no
00026 // concepts of "segments"; each feature is considered independent.
00027 //
00028 class rgrl_feature_set_bins_2d
00029   : public rgrl_feature_set
00030 {
00031  public:
00032   //: Constructor.
00033   //  \a bin_size is only effective when \a use_bins is set true.
00034   rgrl_feature_set_bins_2d( feature_vector const& features,
00035                              double bin_size = 10,
00036                              rgrl_feature_set_label const& label = rgrl_feature_set_label() );
00037 
00038   ~rgrl_feature_set_bins_2d();
00039 
00040   void
00041   features_in_region( feature_vector& results, rgrl_mask_box const& roi ) const;
00042 
00043   //:  Return the features in a given circle/sphere.
00044   //
00045   void
00046   features_within_radius( feature_vector& results, vnl_vector<double> const& center, double radius ) const;
00047 
00048   //: Nearest feature based on Euclidean distance
00049   rgrl_feature_sptr
00050   nearest_feature( const vnl_vector<double>& loc ) const;
00051 
00052   //: Nearest feature based on Euclidean distance
00053   rgrl_feature_sptr
00054   nearest_feature( rgrl_feature_sptr const& feature ) const;
00055 
00056   //: Return all features within a given Euclidean distance
00057   void
00058   features_within_radius( feature_vector& results, rgrl_feature_sptr const& feature, double distance ) const;
00059 
00060   //:  Return the k nearest features based on Euclidean distance.
00061   void
00062   k_nearest_features( feature_vector& results, const vnl_vector<double>& feature_loc, unsigned int k ) const;
00063 
00064   //:  Return the k nearest features based on Euclidean distance.
00065   void
00066   k_nearest_features( feature_vector& results, rgrl_feature_sptr const& feature, unsigned int k ) const;
00067 
00068   //:  Return the bounding box encloses the feature set
00069   rgrl_mask_box
00070   bounding_box() const;
00071 
00072   //:  Return the type of feature
00073   const vcl_type_info&
00074   type() const;
00075 
00076   // Defines type-related functions
00077   rgrl_type_macro( rgrl_feature_set_bins_2d, rgrl_feature_set );
00078 
00079  private:
00080   typedef rsdl_bins_2d<double,rgrl_feature_sptr> bin2d_type;
00081 
00082   const vcl_type_info* feature_type_;
00083 
00084   rgrl_mask_box bounding_box_;
00085 
00086   // Using bins as the data structure
00087   vcl_auto_ptr< bin2d_type > bins_2d_;
00088   // bool use_bins_;
00089 
00090 };
00091 
00092 
00093 #endif // rgrl_feature_set_bins_2d_h_