contrib/rpl/rgrl/rgrl_feature_region.cxx
Go to the documentation of this file.
00001 #include "rgrl_feature_region.h"
00002 //:
00003 // \file
00004 // \author Gehua yang
00005 // \date   Oct 2004
00006 
00007 
00008 #include <vcl_cassert.h>
00009 #include <vnl/vnl_vector.h>
00010 #include <vcl_vector.h>
00011 
00012 const vcl_vector< vnl_vector<int> >&
00013 rgrl_feature_region::
00014 pixel_coordinates()
00015 {
00016   // return stored pixels
00017   if ( pixel_coordinates_cached_ )
00018     return pixel_coordinates_;
00019 
00020   // otherwise, generate pixels according to spacing_ratios
00021   // 3 is fairly safe, since dim is usually
00022   // determined by feature location size
00023   spacing_ratio_.set_size(3);
00024   spacing_ratio_.fill(1.0);
00025   this->generate_pixel_coordinates( spacing_ratio_ );
00026   assert( pixel_coordinates_cached_ );
00027   return pixel_coordinates_;
00028 }
00029 
00030 // Return region(neighboring) pixels in "pixel" coordinates.
00031 vcl_vector< vnl_vector<int> > const&
00032 rgrl_feature_region ::
00033 pixel_coordinates_ratio( vnl_vector< double > const& spacing_ratio )
00034 {
00035   //  If the pixel coordinates have already been computed and cached,
00036   //  just return them.
00037 
00038   // !!!! It is dangerous, for it assumes the spacing_ratio is always the same.
00039   // Usually it holds true in practice, but there is no guarantee.
00040   // Gehua
00041   if ( !pixel_coordinates_cached_ ) {
00042     spacing_ratio_ = spacing_ratio;
00043     generate_pixel_coordinates( spacing_ratio );
00044     assert( pixel_coordinates_cached_ );
00045   }
00046 
00047   // the dimension may differ
00048   // assert( (spacing_ratio-spacing_ratio_).squared_magnitude() < 1e-6 );
00049   return pixel_coordinates_;
00050 }