Go to the documentation of this file.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 #ifndef _mrpt_vision_TSimpleFeature_H
00029 #define _mrpt_vision_TSimpleFeature_H
00030
00031 #include <mrpt/utils/TPixelCoord.h>
00032 #include <mrpt/math/KDTreeCapable.h>
00033 #include <mrpt/math/CMatrixTemplateNumeric.h>
00034 #include <mrpt/vision/types.h>
00035
00036 #include <mrpt/vision/link_pragmas.h>
00037
00038 namespace mrpt
00039 {
00040 namespace vision
00041 {
00042
00043
00044
00045
00046
00047
00048
00049 template <typename PIXEL_COORD_TYPE>
00050 struct TSimpleFeature_templ
00051 {
00052 PIXEL_COORD_TYPE pt;
00053 TFeatureID ID;
00054 TFeatureTrackStatus track_status;
00055 float response;
00056 uint8_t octave;
00057 uint8_t user_flags;
00058
00059
00060 template <typename COORD_TYPE>
00061 inline TSimpleFeature_templ(const COORD_TYPE x, const COORD_TYPE y) : pt(x,y) { }
00062
00063
00064 inline TSimpleFeature_templ() {}
00065 };
00066
00067
00068
00069
00070 typedef TSimpleFeature_templ<mrpt::utils::TPixelCoord> TSimpleFeature;
00071
00072
00073 typedef TSimpleFeature_templ<mrpt::utils::TPixelCoordf> TSimpleFeaturef;
00074
00075
00076 template <typename FEATURE> struct TSimpleFeatureTraits;
00077
00078 template <> struct TSimpleFeatureTraits<TSimpleFeature> {
00079 typedef int coord_t;
00080
00081 static inline coord_t f2coord(float f) { return mrpt::utils::round(f); }
00082 };
00083
00084 template <> struct TSimpleFeatureTraits<TSimpleFeaturef> {
00085 typedef float coord_t;
00086
00087 static inline coord_t f2coord(float f) { return f; }
00088 };
00089
00090
00091
00092
00093
00094
00095 template <typename FEATURE>
00096 struct TSimpleFeatureList_templ
00097 {
00098 public:
00099 typedef std::vector<FEATURE> TFeatureVector;
00100
00101
00102
00103
00104
00105 const TFeatureVector& getVector() const { return m_feats; }
00106
00107
00108 TFeatureID getMaxID() const {
00109 if (this->empty()) return 0;
00110 TFeatureID maxID = m_feats[0].ID;
00111 size_t N = m_feats.size()-1;
00112 for ( ; N ; --N) mrpt::utils::keep_max(maxID, m_feats[N].ID);
00113 return maxID;
00114 }
00115
00116
00117
00118
00119
00120 const std::vector<size_t> & getFirstIndexPerRowLUT() const { return m_first_index_per_row; }
00121
00122 std::vector<size_t> & getFirstIndexPerRowLUT() { return m_first_index_per_row; }
00123
00124
00125 inline mrpt::math::CMatrixBool & getOccupiedSectionsMatrix() { return m_occupied_sections; }
00126 inline const mrpt::math::CMatrixBool & getOccupiedSectionsMatrix() const { return m_occupied_sections; }
00127
00128
00129
00130
00131
00132 typedef typename TFeatureVector::iterator iterator;
00133 typedef typename TFeatureVector::const_iterator const_iterator;
00134
00135 typedef typename TFeatureVector::reverse_iterator reverse_iterator;
00136 typedef typename TFeatureVector::const_reverse_iterator const_reverse_iterator;
00137
00138 inline iterator begin() { return m_feats.begin(); }
00139 inline iterator end() { return m_feats.end(); }
00140 inline const_iterator begin() const { return m_feats.begin(); }
00141 inline const_iterator end() const { return m_feats.end(); }
00142
00143 inline reverse_iterator rbegin() { return m_feats.rbegin(); }
00144 inline reverse_iterator rend() { return m_feats.rend(); }
00145 inline const_reverse_iterator rbegin() const { return m_feats.rbegin(); }
00146 inline const_reverse_iterator rend() const { return m_feats.rend(); }
00147
00148 inline iterator erase(const iterator it) { return m_feats.erase(it); }
00149
00150 inline bool empty() const { return m_feats.empty(); }
00151 inline size_t size() const { return m_feats.size(); }
00152
00153 inline void clear() { m_feats.clear(); m_first_index_per_row.clear(); }
00154 inline void resize(size_t N) { m_feats.resize(N); }
00155 inline void reserve(size_t N) { m_feats.reserve(N); }
00156
00157 inline void push_back(const FEATURE &f) { m_feats.push_back(f); }
00158 inline void push_back_fast (const FEATURE &f) { m_feats.push_back(f); }
00159 inline void push_back_fast (const int x, const int y) { m_feats.push_back (FEATURE(x,y)); }
00160
00161 inline FEATURE & operator [](const unsigned int index) { return m_feats[index]; }
00162 inline const FEATURE & operator [](const unsigned int index) const { return m_feats[index]; }
00163
00164 inline FEATURE & back() { return m_feats.back(); }
00165 inline const FEATURE & back() const { return m_feats.back(); }
00166
00167 inline FEATURE & front() { return m_feats.front(); }
00168 inline const FEATURE & front() const { return m_feats.front(); }
00169
00170
00171
00172
00173
00174 inline typename TSimpleFeatureTraits<FEATURE>::coord_t getFeatureX(size_t i) const { return m_feats[i].pt.x; }
00175 inline typename TSimpleFeatureTraits<FEATURE>::coord_t getFeatureY(size_t i) const { return m_feats[i].pt.y; }
00176 inline TFeatureID getFeatureID(size_t i) const { return m_feats[i].ID; }
00177 inline float getFeatureResponse(size_t i) const { return m_feats[i].response; }
00178 inline bool isPointFeature(size_t i) const { return true; }
00179 inline float getScale(size_t i) const { return static_cast<float>(1<<m_feats[i].octave); }
00180 inline TFeatureTrackStatus getTrackStatus(size_t i) { return m_feats[i].track_status; }
00181
00182 inline void setFeatureX(size_t i,typename TSimpleFeatureTraits<FEATURE>::coord_t x) { m_feats[i].pt.x=x; }
00183 inline void setFeatureY(size_t i,typename TSimpleFeatureTraits<FEATURE>::coord_t y) { m_feats[i].pt.y=y; }
00184
00185 inline void setFeatureXf(size_t i,float x) { m_feats[i].pt.x=TSimpleFeatureTraits<FEATURE>::f2coord(x); }
00186 inline void setFeatureYf(size_t i,float y) { m_feats[i].pt.y=TSimpleFeatureTraits<FEATURE>::f2coord(y); }
00187
00188 inline void setFeatureID(size_t i,TFeatureID id) { m_feats[i]->ID=id; }
00189 inline void setFeatureResponse(size_t i,float r) { m_feats[i]->response=r; }
00190 inline void setScale(size_t i,float s) { m_feats[i]->octave=mrpt::utils::round(std::log(s)/std::log(2)); }
00191 inline void setTrackStatus(size_t i,TFeatureTrackStatus s) { m_feats[i].track_status=s; }
00192
00193 inline void mark_as_outdated() const { }
00194
00195
00196 private:
00197 TFeatureVector m_feats;
00198 std::vector<size_t> m_first_index_per_row;
00199 mrpt::math::CMatrixBool m_occupied_sections;
00200
00201 };
00202
00203
00204 typedef TSimpleFeatureList_templ<TSimpleFeature> TSimpleFeatureList;
00205
00206
00207 typedef TSimpleFeatureList_templ<TSimpleFeaturef> TSimpleFeaturefList;
00208
00209
00210
00211
00212
00213
00214 template <typename FEATURE_LIST>
00215 struct KeypointResponseSorter : public std::binary_function<size_t,size_t,bool>
00216 {
00217 const FEATURE_LIST &m_data;
00218 KeypointResponseSorter( const FEATURE_LIST &data ) : m_data(data) { }
00219 bool operator() (size_t k1, size_t k2 ) const {
00220 return (m_data[k1].response > m_data[k2].response);
00221 }
00222 };
00223
00224
00225
00226
00227
00228
00229 template <typename FEAT>
00230 class CFeatureListKDTree : public mrpt::math::KDTreeCapable<CFeatureListKDTree<FEAT> >
00231 {
00232 public:
00233 inline void mark_as_outdated() { mrpt::math::KDTreeCapable<CFeatureListKDTree<FEAT> >::kdtree_mark_as_outdated(); }
00234
00235 const std::vector<FEAT> & m_data;
00236 CFeatureListKDTree(const std::vector<FEAT> & data) : m_data(data) { }
00237
00238
00239
00240
00241
00242
00243 inline size_t kdtree_get_point_count() const { return m_data.size(); }
00244
00245
00246 inline float kdtree_get_pt(const size_t idx, int dim) const {
00247 ASSERTDEB_(dim==0 || dim==1)
00248 if (dim==0) return m_data[idx].pt.x;
00249 else return m_data[idx].pt.y;
00250 }
00251
00252
00253 inline float kdtree_distance(const float *p1, const size_t idx_p2,size_t size) const
00254 {
00255 ASSERTDEB_(size==2)
00256
00257 const float d0 = p1[0] - m_data[idx_p2].pt.x;
00258 const float d1 = p1[1] - m_data[idx_p2].pt.y;
00259 return d0*d0+d1*d1;
00260 }
00261
00262
00263
00264
00265 template <typename BBOX>
00266 bool kdtree_get_bbox(BBOX &bb) const { return false; }
00267
00268
00269
00270 };
00271
00272
00273
00274
00275 }
00276
00277 }
00278
00279 #endif
00280