Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007 #include "rgrl_trans_reader.h"
00008 #include <rgrl/rgrl_trans_translation.h>
00009 #include <rgrl/rgrl_trans_similarity.h>
00010 #include <rgrl/rgrl_trans_affine.h>
00011 #include <rgrl/rgrl_trans_reduced_quad.h>
00012 #include <rgrl/rgrl_trans_quadratic.h>
00013 #include <rgrl/rgrl_trans_homography2d.h>
00014 #include <rgrl/rgrl_trans_rad_dis_homo2d.h>
00015 #include <rgrl/rgrl_trans_rigid.h>
00016 #include <rgrl/rgrl_trans_couple.h>
00017 #include <rgrl/rgrl_trans_spline.h>
00018 #include <rgrl/rgrl_util.h>
00019 #include <vcl_iostream.h>
00020 #include <vcl_fstream.h>
00021 #include <vcl_string.h>
00022 #include <vcl_compiler.h>
00023
00024
00025 vcl_vector< rgrl_transformation_sptr > rgrl_trans_reader::xform_candidates_;
00026
00027 rgrl_transformation_sptr
00028 rgrl_trans_reader::
00029 read( char const* fn )
00030 {
00031 vcl_ifstream ifs( fn, vcl_ios_in|vcl_ios_binary );
00032 if( ifs.good() )
00033 return read( ifs );
00034 else
00035 return 0;
00036 }
00037
00038 #undef READ_THIS_TRANSFORMATION
00039 #define READ_THIS_TRANSFORMATION(tag, trans) \
00040 if ( tag_str.find(tag) == 0 ){ \
00041 trans* trans_ptr = new trans(); \
00042 if( trans_ptr->read(is) ) \
00043 return trans_ptr; \
00044 else \
00045 return 0; \
00046 }
00047
00048
00049
00050
00051
00052 rgrl_transformation_sptr
00053 rgrl_trans_reader::
00054 read( vcl_istream& is )
00055 {
00056 vcl_string tag_str;
00057 vcl_streampos pos;
00058
00059
00060
00061
00062 rgrl_util_skip_empty_lines( is );
00063
00064 pos = is.tellg();
00065 vcl_getline( is, tag_str );
00066
00067
00068
00069
00070 is.seekg( pos );
00071
00072 typedef vcl_vector< rgrl_transformation_sptr >::const_iterator iter;
00073 for( iter i=xform_candidates_.begin(); i!=xform_candidates_.end(); ++i ) {
00074
00075
00076 rgrl_transformation_sptr candidate = (*i)->clone();
00077 if( candidate->read( is) )
00078 return candidate;
00079
00080
00081 is.seekg( pos );
00082 }
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094 READ_THIS_TRANSFORMATION("TRANSLATION", rgrl_trans_translation)
00095 READ_THIS_TRANSFORMATION("SIMILARITY", rgrl_trans_similarity)
00096 READ_THIS_TRANSFORMATION("AFFINE", rgrl_trans_affine)
00097 READ_THIS_TRANSFORMATION("REDUCED_QUADRATIC", rgrl_trans_reduced_quad)
00098 READ_THIS_TRANSFORMATION("RIGID", rgrl_trans_rigid)
00099 READ_THIS_TRANSFORMATION("QUADRATIC", rgrl_trans_quadratic)
00100 READ_THIS_TRANSFORMATION("BSPLINE", rgrl_trans_spline)
00101 READ_THIS_TRANSFORMATION("HOMOGRAPHY2D_WITH_RADIAL_DISTORTION", rgrl_trans_rad_dis_homo2d)
00102 READ_THIS_TRANSFORMATION("HOMOGRAPHY2D", rgrl_trans_homography2d)
00103 READ_THIS_TRANSFORMATION("COUPLE_TRANS", rgrl_trans_couple)
00104
00105
00106 vcl_cout<< "WARNING: " << RGRL_HERE << " ( line "
00107 << __LINE__ << " )\n"
00108 << " " << "Tag [" << tag_str
00109 << "] cannot match with any existing transformations.\n"
00110 << " Try to open istream in BINARY mode!" << vcl_endl;
00111 return 0;
00112 }
00113
00114 void
00115 rgrl_trans_reader::
00116 add_xform( rgrl_transformation_sptr xform )
00117 {
00118 xform_candidates_.push_back( xform );
00119 }
00120
00121
00122 vcl_istream&
00123 operator>> (vcl_istream& is, rgrl_transformation_sptr& trans_sptr)
00124 {
00125 trans_sptr = rgrl_trans_reader::read( is );
00126 return is;
00127 }
00128