contrib/rpl/rgrl/rgrl_feature_point_region.cxx
Go to the documentation of this file.
00001 // \file
00002 // \author Gehua Yang
00003 // \date   Oct 2004
00004 
00005 #include "rgrl_feature_point_region.h"
00006 #include <rgrl/rgrl_util.h>
00007 #include <rgrl/rgrl_transformation.h>
00008 
00009 rgrl_feature_point_region::
00010 rgrl_feature_point_region( vnl_vector<double> const& loc, double radius )
00011   : rgrl_feature_point( loc ),
00012     radius_(radius)
00013 {     }
00014 
00015 rgrl_feature_point_region::
00016 rgrl_feature_point_region( unsigned dim )
00017   : rgrl_feature_point( dim ),
00018     radius_( 0 )
00019 {
00020 }
00021 
00022 rgrl_feature_sptr
00023 rgrl_feature_point_region::
00024 transform( rgrl_transformation const& xform ) const
00025 {
00026   rgrl_feature_point_region* result = new rgrl_feature_point_region( this->location().size() );
00027 
00028   // capture the allocation into a smart pointer for exception safety.
00029   rgrl_feature_sptr result_sptr = result;
00030 
00031   // Transform the location
00032   //
00033   xform.map_location( this->location_, result->location_ );
00034 
00035   //  Set the radius and length.  If these values truly must be
00036   //  transformed, then the function transform_region should used.
00037   result -> radius_ = this -> radius_;
00038 
00039   return result_sptr;
00040 }
00041 
00042 // Return region(neighboring) pixels in "pixel" coordinates.
00043 void
00044 rgrl_feature_point_region ::
00045 generate_pixel_coordinates( vnl_vector< double > const& spacing_ratio )
00046 {
00047   //  Create the oriented rectangular solid.  Form the set of
00048   //  orthogonal directions and radii.  The directions are combined
00049   //  from the normal direction and the basis for the tangent
00050   //  subspace.  The first radius is half the fatness of the region.
00051   //  The others are all equal to the radius of the trace region.
00052 
00053   unsigned int dim = this -> location_ . size();
00054   vcl_vector< vnl_vector<double> > directions;
00055   directions.reserve( dim );
00056 //    directions.push_back( this -> normal_ );
00057 
00058   // compute in the pixel coordinates
00059   // convert the location to the pixel coordinates
00060   vnl_vector< double > location_in_pixel( dim );
00061   vnl_vector< double > radii_in_pixel( dim, radius_ );
00062   vnl_vector< double > directions_in_pixel( dim );
00063 
00064   vnl_vector< double > direction_in_pixel( dim );
00065   for ( unsigned int i = 0; i < dim; ++i )
00066   {
00067     location_in_pixel[ i ] = this->location_[ i ] / spacing_ratio[ i ];
00068     radii_in_pixel[i] = radii_in_pixel[i] / spacing_ratio[i];
00069   }
00070 
00071   // creat indentity matrix
00072   vnl_matrix<double> tangent( dim, dim, vnl_matrix_identity );
00073 
00074   for ( unsigned int i = 0; i < dim; ++i )
00075   {
00076     direction_in_pixel = tangent.get_column( i );
00077     for ( unsigned j = 0; j < dim; ++j )
00078       direction_in_pixel[ j ] /= spacing_ratio[ j ];
00079 
00080     directions.push_back( direction_in_pixel );
00081   }
00082 
00083   //  Call the utility function to extract the pixel locations,
00084   //  record the caching and return the vector.
00085 
00086   rgrl_util_extract_region_locations( location_in_pixel, directions,
00087                                       radii_in_pixel, pixel_coordinates_ );
00088 
00089   pixel_coordinates_cached_ = true;
00090 }
00091 
00092 rgrl_feature_sptr
00093 rgrl_feature_point_region::
00094 clone() const
00095 {
00096   return new rgrl_feature_point_region(*this);
00097 }