00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef CFeaturePatch_H
00030 #define CFeaturePatch_H
00031
00032 #include <mrpt/utils/utils_defs.h>
00033 #include <mrpt/utils/CImage.h>
00034 #include <mrpt/monoslam/link_pragmas.h>
00035
00036
00037 namespace mrpt
00038 {
00039 namespace monoslam
00040 {
00041 using namespace mrpt::utils;
00042
00043
00044
00045 class MONOSLAMDLLIMPEXP CFeaturePatch
00046 {
00047 protected:
00048
00049 struct MONOSLAMDLLIMPEXP feat
00050 {
00051 feat() : name(0),hits(0),patch()
00052 { }
00053
00054 int name;
00055 int hits;
00056 CImage patch;
00057 };
00058
00059 std::vector<feat> feat_vector;
00060
00061 public:
00062
00063
00064 void clear() { feat_vector.clear(); }
00065
00066
00067
00068 CFeaturePatch(const int &n,const int &h,const CImage &p) : feat_vector(1)
00069 {
00070 ASSERT_((p.getWidth()==21) & (p.getHeight()==21));
00071 feat_vector.resize(1);
00072 feat_vector[0].name=n;
00073 feat_vector[0].hits=h;
00074 feat_vector[0].patch=p;
00075 }
00076
00077
00078
00079 CFeaturePatch(const int &n,const int &h) : feat_vector(1)
00080 {
00081 feat_vector.resize(1);
00082 feat_vector[0].name=n;
00083 feat_vector[0].hits=h;
00084 }
00085
00086
00087
00088 CFeaturePatch() : feat_vector(0)
00089 {
00090 feat_vector.resize(0);
00091 }
00092
00093
00094
00095
00096 int get_name(const size_t &index)
00097 {
00098 if (index>=size())
00099 THROW_EXCEPTION("Index out of bounds in CFeaturePatch::get_name");
00100 return feat_vector[index].name;
00101 }
00102
00103
00104
00105 void get_name(const size_t &index,int &n)
00106 {
00107 if (index>=size())
00108 THROW_EXCEPTION("Index out of bounds in CFeaturePatch::get_name");
00109 n=feat_vector[index].name;
00110 }
00111
00112
00113
00114 int get_hits(const size_t &index)
00115 {
00116 if (index>=size())
00117 THROW_EXCEPTION("Index out of bounds in CFeaturePatch::get_hits");
00118 return feat_vector[index].hits;
00119 }
00120
00121
00122
00123 void get_hits(const size_t &index,int &h)
00124 {
00125 if (index>=size())
00126 THROW_EXCEPTION("Index out of bounds in CFeaturePatch::get_hits");
00127 h=feat_vector[index].hits;
00128 }
00129
00130
00131
00132 void get_patch(const size_t &index,CImage &im)
00133 {
00134 if (index>=size())
00135 THROW_EXCEPTION("Index out of bounds in CFeaturePatch::get_patch");
00136 im=feat_vector[index].patch;
00137 }
00138
00139
00140
00141 void set_name(const size_t &index,const int &n)
00142 {
00143 if (index>=size())
00144 THROW_EXCEPTION("Index out of bounds in CFeaturePatch::set_name");
00145 feat_vector[index].name=n;
00146 }
00147
00148
00149
00150 void set_hits(const size_t &index,const int &h)
00151 {
00152 if (index>=size())
00153 THROW_EXCEPTION("Index out of bounds in CFeaturePatch::set_hits");
00154 feat_vector[index].hits=h;
00155 }
00156
00157
00158
00159
00160 void set_patch(const size_t &index,const unsigned int col, const unsigned int row, CImage &img)
00161 {
00162 if (index>=size())
00163 THROW_EXCEPTION("Index out of bounds in CFeaturePatch::set_patch");
00164 if ((col<10) || (col>img.getWidth()-11) || (row<10) || (row>img.getHeight()-11) || (index >= feat_vector.size()))
00165 {
00166 std::cout<<"index: "<<index<<"\n";
00167 std::cout<<"row: "<<row<<"\n";
00168 std::cout<<"col: "<<col<<"\n";
00169 THROW_EXCEPTION("Error while setting patch in CFeaturePatch::set_patch. Try to set patch out of image bounds");
00170 }
00171 img.extract_patch(feat_vector[index].patch,col-10,row-10,21,21);
00172 }
00173
00174
00175
00176 void set_patch(const size_t &index,const CImage &p)
00177 {
00178 if (index>=size())
00179 THROW_EXCEPTION("Index out of bounds in CFeaturePatch::set_patch");
00180 if (index >= feat_vector.size())
00181 THROW_EXCEPTION("Error while setting patch, index out of range");
00182 feat_vector[index].patch = p;
00183 }
00184
00185
00186
00187 size_t size(){return feat_vector.size();}
00188
00189
00190
00191 void insert_feature()
00192 {
00193 if (feat_vector.size()>0)
00194 {
00195 int n = feat_vector[feat_vector.size()-1].name + 1;
00196 feat_vector.resize(1+feat_vector.size());
00197 feat_vector[feat_vector.size()-1].name=n;
00198 feat_vector[feat_vector.size()-1].hits=0;
00199 }
00200 else
00201 {
00202 feat_vector.resize(1);
00203 feat_vector[0].name=0;
00204 feat_vector[0].hits=0;
00205 }
00206 }
00207
00208
00209
00210 void insert_feature(const int &n, const int &h)
00211 {
00212 feat_vector.resize(1+feat_vector.size());
00213 feat_vector[feat_vector.size()-1].name=n;
00214 feat_vector[feat_vector.size()-1].hits=h;
00215 }
00216
00217
00218
00219 void delete_feature(const size_t &index)
00220 {
00221 if (index>=feat_vector.size())
00222 THROW_EXCEPTION("Feature for delete out of bounds in CFeaturePatch::delete_feature");
00223 for (size_t i=index;i<feat_vector.size()-1;i++)
00224 {
00225 feat_vector[i]=feat_vector[i+1];
00226 feat_vector[i].name=i;
00227 }
00228 feat_vector.resize(feat_vector.size()-1);
00229 }
00230
00231 };
00232 }
00233 }
00234
00235 #endif //__CFeature_H