1 #include <iostream> 2 #include <vector> 3 #include "rgrl_feature_region.h" 4 //: 5 // \file 6 // \author Gehua yang 7 // \date Oct 2004 8 9 10 #include <cassert> 11 #include "vnl/vnl_vector.h" 12 #ifdef _MSC_VER 13 # include "vcl_msvc_warnings.h" 14 #endif 15 16 const std::vector< vnl_vector<int> >& 17 rgrl_feature_region:: pixel_coordinates()18pixel_coordinates() 19 { 20 // return stored pixels 21 if ( pixel_coordinates_cached_ ) 22 return pixel_coordinates_; 23 24 // otherwise, generate pixels according to spacing_ratios 25 // 3 is fairly safe, since dim is usually 26 // determined by feature location size 27 spacing_ratio_.set_size(3); 28 spacing_ratio_.fill(1.0); 29 this->generate_pixel_coordinates( spacing_ratio_ ); 30 assert( pixel_coordinates_cached_ ); 31 return pixel_coordinates_; 32 } 33 34 // Return region(neighboring) pixels in "pixel" coordinates. 35 std::vector< vnl_vector<int> > const& 36 rgrl_feature_region :: pixel_coordinates_ratio(vnl_vector<double> const & spacing_ratio)37pixel_coordinates_ratio( vnl_vector< double > const& spacing_ratio ) 38 { 39 // If the pixel coordinates have already been computed and cached, 40 // just return them. 41 42 // !!!! It is dangerous, for it assumes the spacing_ratio is always the same. 43 // Usually it holds true in practice, but there is no guarantee. 44 // Gehua 45 if ( !pixel_coordinates_cached_ ) { 46 spacing_ratio_ = spacing_ratio; 47 generate_pixel_coordinates( spacing_ratio ); 48 assert( pixel_coordinates_cached_ ); 49 } 50 51 // the dimension may differ 52 // assert( (spacing_ratio-spacing_ratio_).squared_magnitude() < 1e-6 ); 53 return pixel_coordinates_; 54 } 55