contrib/rpl/rgrl/rgrl_feature_set_location_masked.cxx
Go to the documentation of this file.
00001 #include "rgrl_feature_set_location_masked.h"
00002 //:
00003 // \file
00004 // \brief Derived class to represent point feature set with masked region
00005 // \author Charlene Tsai
00006 // \date   Sep 2003
00007 //
00008 // \verbatim
00009 //  Modifications
00010 //   Peter Vanroose - 14 aug 2004 - moved all impl from .txx to .h to avoid VC60 internal compile error
00011 //   Chuck Stewart - 8 Nov 2005 - added versions of nearest_feature and k_nearest_feature
00012 //      based on point location alone
00013 // \endverbatim
00014 
00015 #include <rgrl/rgrl_feature_sptr.h>
00016 #include <rgrl/rgrl_mask.h>
00017 
00018 //:  Return the bounding box encloses the feature set
00019 rgrl_mask_box
00020 rgrl_feature_set_location_masked::
00021 bounding_box() const
00022 { return fea_set_sptr_->bounding_box(); }
00023 
00024 void
00025 rgrl_feature_set_location_masked::
00026 features_in_region( feature_vector& final_results, rgrl_mask_box const& roi ) const
00027 {
00028   feature_vector results;
00029   fea_set_sptr_->features_in_region( results, roi );
00030   // check if features are in the valid region
00031   typedef feature_vector::iterator fvec_itr;
00032   for ( fvec_itr fitr = results.begin(); fitr != results.end(); ++fitr )
00033     if ( mask_->inside( (*fitr)->location() ) )
00034       final_results.push_back( *fitr );
00035 }
00036 
00037 //:  Return the features in a given circle/sphere.
00038 //
00039 void
00040 rgrl_feature_set_location_masked::
00041 features_within_radius( feature_vector& final_results, vnl_vector<double> const& center, double radius ) const
00042 {
00043   feature_vector results;
00044   fea_set_sptr_->features_within_radius( results, center, radius );
00045   // check if features are in the valid region
00046   typedef feature_vector::iterator fvec_itr;
00047   for ( fvec_itr fitr = results.begin(); fitr != results.end(); ++fitr )
00048     if ( mask_->inside( (*fitr)->location() ) )
00049       final_results.push_back( *fitr );
00050 }
00051 
00052 //: Nearest feature based on Euclidean distance
00053 //
00054 rgrl_feature_sptr
00055 rgrl_feature_set_location_masked::
00056 nearest_feature( rgrl_feature_sptr const& feature ) const
00057 {
00058   return mask_->inside(feature->location()) ?
00059          fea_set_sptr_->nearest_feature( feature ) :
00060          (rgrl_feature_sptr)0;
00061 }
00062 
00063 //: Nearest feature based on Euclidean distance
00064 //
00065 rgrl_feature_sptr
00066 rgrl_feature_set_location_masked::
00067 nearest_feature( const vnl_vector<double>& loc ) const
00068 {
00069   return mask_->inside(loc) ?
00070          fea_set_sptr_->nearest_feature( loc ) :
00071          (rgrl_feature_sptr)0;
00072 }
00073 
00074 //: Return all features within a given Euclidean distance
00075 //
00076 void
00077 rgrl_feature_set_location_masked::
00078 features_within_radius( feature_vector& results, rgrl_feature_sptr const& feature, double distance ) const
00079 {
00080   if ( mask_->inside(feature->location()) )
00081     fea_set_sptr_->features_within_radius(results, feature , distance);
00082 }
00083 
00084 //: Return the k nearest features based on Euclidean distance
00085 void
00086 rgrl_feature_set_location_masked::
00087 k_nearest_features( feature_vector& results, const vnl_vector<double>& loc, unsigned int k ) const
00088 {
00089   if ( mask_->inside(loc) )
00090     fea_set_sptr_->k_nearest_features(results, loc, k);
00091 }
00092 
00093 //: Return the k nearest features based on Euclidean distance
00094 void
00095 rgrl_feature_set_location_masked::
00096 k_nearest_features( feature_vector& results, rgrl_feature_sptr const& feature, unsigned int k ) const
00097 {
00098   if ( mask_->inside(feature->location()) )
00099     fea_set_sptr_->k_nearest_features(results, feature, k);
00100 }