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
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00044 #ifndef _FEATURE_ENTRY_H_
00045 #define _FEATURE_ENTRY_H_
00046
00047
00048
00049
00050
00051
00052 #include <new>
00053
00054 #include "DataStructures/DynamicArray.h"
00055 #include "Helpers/helpers.h"
00056 #include "Math/Math2d.h"
00057 #include "Math/Math3d.h"
00058
00059 #include <stdio.h>
00060 #include <string.h>
00061
00062
00063
00064
00065
00066
00067
00072 class CFeatureEntry : public CDynamicArrayElement
00073 {
00074 public:
00075
00076 enum eFeatureType { tSIFT, tMSER, tPatch, tCCH, tLCCH, tNLCCH };
00077
00078
00079
00080 CFeatureEntry(int nSize, float x, float y, float angle, float scale, Vec3d point3d = Math3d::zero_vec) : CDynamicArrayElement()
00081 {
00082 m_nSize = nSize;
00083
00084 Math2d::SetVec(point, x, y);
00085 Math3d::SetVec(this->point3d, point3d);
00086 this->angle = angle;
00087 this->scale = scale;
00088
00089 if (nSize)
00090 m_pFeature = new float[nSize];
00091 else
00092 m_pFeature = 0;
00093 }
00094
00095 CFeatureEntry(const float *pFeature, int nSize, float x, float y, float angle, float scale, Vec3d point3d = Math3d::zero_vec) : CDynamicArrayElement()
00096 {
00097 m_nSize = nSize;
00098
00099 Math2d::SetVec(point, x, y);
00100 Math3d::SetVec(this->point3d, point3d);
00101 this->angle = angle;
00102 this->scale = scale;
00103
00104 m_pFeature = new float[nSize];
00105 memcpy(m_pFeature, pFeature, nSize * sizeof(float));
00106 }
00107
00108 CFeatureEntry(const CFeatureEntry &featureEntry)
00109 {
00110 Math2d::SetVec(point, featureEntry.point);
00111 Math3d::SetVec(point3d, featureEntry.point3d);
00112 angle = featureEntry.angle;
00113 scale = featureEntry.scale;
00114 m_nSize = featureEntry.m_nSize;
00115
00116 m_pFeature = new float[m_nSize];
00117 memcpy(m_pFeature, featureEntry.m_pFeature, m_nSize * sizeof(float));
00118 }
00119
00120
00121 ~CFeatureEntry()
00122 {
00123 if (m_pFeature)
00124 delete [] m_pFeature;
00125 }
00126
00127
00128
00129 virtual bool ReadFromFileOld(FILE *pFile)
00130 {
00131 if (fread(&m_nSize, sizeof(int), 1, pFile) != 1) return false;
00132 #ifdef IVT_BIG_ENDIAN
00133 m_nSize = invert_byte_order_long(m_nSize);
00134 #endif
00135
00136 if (m_pFeature) delete [] m_pFeature;
00137 m_pFeature = new float[m_nSize];
00138
00139 float u, v;
00140
00141 if (fread(m_pFeature, m_nSize * sizeof(float), 1, pFile) != 1) return false;
00142 if (fread(&u, sizeof(float), 1, pFile) != 1) return false;
00143 if (fread(&v, sizeof(float), 1, pFile) != 1) return false;
00144 if (fread(&angle, sizeof(float), 1, pFile) != 1) return false;
00145 if (fread(&scale, sizeof(float), 1, pFile) != 1) return false;
00146
00147 #ifdef IVT_BIG_ENDIAN
00148 for (int i = 0; i < m_nSize; i++)
00149 m_pFeature[i] = invert_byte_order_float(m_pFeature[i]);
00150 u = invert_byte_order_float(u);
00151 v = invert_byte_order_float(v);
00152 angle = invert_byte_order_float(angle);
00153 scale = invert_byte_order_float(scale);
00154 #endif
00155
00156 Math2d::SetVec(point, u, v);
00157
00158 return true;
00159 }
00160
00161 virtual bool ReadFromFile(FILE *pFile)
00162 {
00163 if (fread(&m_nSize, sizeof(int), 1, pFile) != 1) return false;
00164 #ifdef IVT_BIG_ENDIAN
00165 m_nSize = invert_byte_order_long(m_nSize);
00166 #endif
00167
00168 if (m_pFeature) delete [] m_pFeature;
00169 m_pFeature = new float[m_nSize];
00170
00171 float u, v, x, y, z;
00172
00173 if (fread(m_pFeature, m_nSize * sizeof(float), 1, pFile) != 1) return false;
00174 if (fread(&u, sizeof(float), 1, pFile) != 1) return false;
00175 if (fread(&v, sizeof(float), 1, pFile) != 1) return false;
00176 if (fread(&x, sizeof(float), 1, pFile) != 1) return false;
00177 if (fread(&y, sizeof(float), 1, pFile) != 1) return false;
00178 if (fread(&z, sizeof(float), 1, pFile) != 1) return false;
00179 if (fread(&angle, sizeof(float), 1, pFile) != 1) return false;
00180 if (fread(&scale, sizeof(float), 1, pFile) != 1) return false;
00181
00182 #ifdef IVT_BIG_ENDIAN
00183 for (int i = 0; i < m_nSize; i++)
00184 m_pFeature[i] = invert_byte_order_float(m_pFeature[i]);
00185 u = invert_byte_order_float(u);
00186 v = invert_byte_order_float(v);
00187 x = invert_byte_order_float(x);
00188 y = invert_byte_order_float(y);
00189 z = invert_byte_order_float(z);
00190 angle = invert_byte_order_float(angle);
00191 scale = invert_byte_order_float(scale);
00192 #endif
00193
00194 Math2d::SetVec(point, u, v);
00195 Math3d::SetVec(point3d, x, y, z);
00196
00197 return true;
00198 }
00199
00200 virtual bool WriteToFile(FILE *pFile) const
00201 {
00202 float u = (float) point.x;
00203 float v = (float) point.y;
00204 float x = (float) point3d.x;
00205 float y = (float) point3d.y;
00206 float z = (float) point3d.z;
00207
00208 #ifdef IVT_BIG_ENDIAN
00209 const int size = invert_byte_order_long(m_nSize);
00210 for (int i = 0; i < m_nSize; i++)
00211 m_pFeature[i] = invert_byte_order_float(m_pFeature[i]);
00212 u = invert_byte_order_float(u);
00213 v = invert_byte_order_float(v);
00214 x = invert_byte_order_float(x);
00215 y = invert_byte_order_float(y);
00216 z = invert_byte_order_float(z);
00217 float angle_ = invert_byte_order_float(angle);
00218 float scale_ = invert_byte_order_float(scale);
00219 #else
00220 const int size = m_nSize;
00221 #endif
00222
00223 if (fwrite(&size, sizeof(int), 1, pFile) != 1) return false;
00224 if (fwrite(m_pFeature, m_nSize * sizeof(float), 1, pFile) != 1) return false;
00225 if (fwrite(&u, sizeof(float), 1, pFile) != 1) return false;
00226 if (fwrite(&v, sizeof(float), 1, pFile) != 1) return false;
00227 if (fwrite(&x, sizeof(float), 1, pFile) != 1) return false;
00228 if (fwrite(&y, sizeof(float), 1, pFile) != 1) return false;
00229 if (fwrite(&z, sizeof(float), 1, pFile) != 1) return false;
00230
00231 #ifdef IVT_BIG_ENDIAN
00232 if (fwrite(&angle_, sizeof(float), 1, pFile) != 1) return false;
00233 if (fwrite(&scale_, sizeof(float), 1, pFile) != 1) return false;
00234 for (int i = 0; i < m_nSize; i++)
00235 m_pFeature[i] = invert_byte_order_float(m_pFeature[i]);
00236 #else
00237 if (fwrite(&angle, sizeof(float), 1, pFile) != 1) return false;
00238 if (fwrite(&scale, sizeof(float), 1, pFile) != 1) return false;
00239 #endif
00240
00241 return true;
00242 }
00243
00244
00245 int GetSize() const { return m_nSize; }
00246
00247 virtual int GetSizeOnDisk() const
00248 {
00249 return sizeof(int) + m_nSize * sizeof(float) + 2 * sizeof(float) + 3 * sizeof(float) + 2 * sizeof(float);
00250 }
00251
00252
00253 virtual eFeatureType GetType() const = 0;
00254 virtual CFeatureEntry* Clone() const = 0;
00255 virtual float Error(const CDynamicArrayElement *pElement) const = 0;
00256
00257
00258
00259 protected:
00260
00261 int m_nSize;
00262
00263 public:
00264 float *m_pFeature;
00265 Vec2d point;
00266 Vec3d point3d;
00267 float angle;
00268 float scale;
00269 };
00270
00271
00272
00273 #endif