|
IVT
|
00001 // **************************************************************************** 00002 // This file is part of the Integrating Vision Toolkit (IVT). 00003 // 00004 // The IVT is maintained by the Karlsruhe Institute of Technology (KIT) 00005 // (www.kit.edu) in cooperation with the company Keyetech (www.keyetech.de). 00006 // 00007 // Copyright (C) 2013 Karlsruhe Institute of Technology (KIT). 00008 // All rights reserved. 00009 // 00010 // Redistribution and use in source and binary forms, with or without 00011 // modification, are permitted provided that the following conditions are met: 00012 // 00013 // 1. Redistributions of source code must retain the above copyright 00014 // notice, this list of conditions and the following disclaimer. 00015 // 00016 // 2. Redistributions in binary form must reproduce the above copyright 00017 // notice, this list of conditions and the following disclaimer in the 00018 // documentation and/or other materials provided with the distribution. 00019 // 00020 // 3. Neither the name of the KIT nor the names of its contributors may be 00021 // used to endorse or promote products derived from this software 00022 // without specific prior written permission. 00023 // 00024 // THIS SOFTWARE IS PROVIDED BY THE KIT AND CONTRIBUTORS “AS IS” AND ANY 00025 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00026 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00027 // DISCLAIMED. IN NO EVENT SHALL THE KIT OR CONTRIBUTORS BE LIABLE FOR ANY 00028 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00029 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00030 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 00031 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00032 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 00033 // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00034 // **************************************************************************** 00035 // **************************************************************************** 00036 // Filename: FeatureEntry.h 00037 // Author: Pedram Azad 00038 // Date: 2006 00039 // **************************************************************************** 00040 00044 #ifndef _FEATURE_ENTRY_H_ 00045 #define _FEATURE_ENTRY_H_ 00046 00047 00048 // **************************************************************************** 00049 // Necessary includes 00050 // **************************************************************************** 00051 00052 #include <new> // for explicitly using correct new/delete operators on VC DSPs 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 // CFeatureEntry 00066 // **************************************************************************** 00067 00072 class CFeatureEntry : public CDynamicArrayElement 00073 { 00074 public: 00075 // enums 00076 enum eFeatureType { tSIFT, tMSER, tPatch, tCCH, tLCCH, tNLCCH }; 00077 00078 00079 // constructors 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 // destructor 00121 ~CFeatureEntry() 00122 { 00123 if (m_pFeature) 00124 delete [] m_pFeature; 00125 } 00126 00127 00128 // public methods 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 // other public methods 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 // pure virtual methods 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 // protected attribute 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 /* _FEATURE_ENTRY_H_ */