FeatureEntry.h
Go to the documentation of this file.
1 // ****************************************************************************
2 // This file is part of the Integrating Vision Toolkit (IVT).
3 //
4 // The IVT is maintained by the Karlsruhe Institute of Technology (KIT)
5 // (www.kit.edu) in cooperation with the company Keyetech (www.keyetech.de).
6 //
7 // Copyright (C) 2014 Karlsruhe Institute of Technology (KIT).
8 // All rights reserved.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are met:
12 //
13 // 1. Redistributions of source code must retain the above copyright
14 // notice, this list of conditions and the following disclaimer.
15 //
16 // 2. Redistributions in binary form must reproduce the above copyright
17 // notice, this list of conditions and the following disclaimer in the
18 // documentation and/or other materials provided with the distribution.
19 //
20 // 3. Neither the name of the KIT nor the names of its contributors may be
21 // used to endorse or promote products derived from this software
22 // without specific prior written permission.
23 //
24 // THIS SOFTWARE IS PROVIDED BY THE KIT AND CONTRIBUTORS “AS IS” AND ANY
25 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27 // DISCLAIMED. IN NO EVENT SHALL THE KIT OR CONTRIBUTORS BE LIABLE FOR ANY
28 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
29 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
31 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
33 // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 // ****************************************************************************
35 // ****************************************************************************
36 // Filename: FeatureEntry.h
37 // Author: Pedram Azad
38 // Date: 2006
39 // ****************************************************************************
40 
44 #ifndef _FEATURE_ENTRY_H_
45 #define _FEATURE_ENTRY_H_
46 
47 
48 // ****************************************************************************
49 // Necessary includes
50 // ****************************************************************************
51 
52 #include <new> // for explicitly using correct new/delete operators on VC DSPs
53 
55 #include "Helpers/helpers.h"
56 #include "Math/Math2d.h"
57 #include "Math/Math3d.h"
58 
59 #include <stdio.h>
60 #include <string.h>
61 
62 
63 
64 // ****************************************************************************
65 // CFeatureEntry
66 // ****************************************************************************
67 
73 {
74 public:
75  // enums
77 
78 
79  // constructors
80  CFeatureEntry(int nSize, float x, float y, float angle, float scale, Vec3d point3d = Math3d::zero_vec) : CDynamicArrayElement()
81  {
82  m_nSize = nSize;
83 
84  Math2d::SetVec(point, x, y);
86  this->angle = angle;
87  this->scale = scale;
88 
89  if (nSize)
90  m_pFeature = new float[nSize];
91  else
92  m_pFeature = 0;
93  }
94 
95  CFeatureEntry(const float *pFeature, int nSize, float x, float y, float angle, float scale, Vec3d point3d = Math3d::zero_vec) : CDynamicArrayElement()
96  {
97  m_nSize = nSize;
98 
99  Math2d::SetVec(point, x, y);
101  this->angle = angle;
102  this->scale = scale;
103 
104  m_pFeature = new float[nSize];
105  memcpy(m_pFeature, pFeature, nSize * sizeof(float));
106  }
107 
108  CFeatureEntry(const CFeatureEntry &featureEntry)
109  {
110  Math2d::SetVec(point, featureEntry.point);
111  Math3d::SetVec(point3d, featureEntry.point3d);
112  angle = featureEntry.angle;
113  scale = featureEntry.scale;
114  m_nSize = featureEntry.m_nSize;
115 
116  m_pFeature = new float[m_nSize];
117  memcpy(m_pFeature, featureEntry.m_pFeature, m_nSize * sizeof(float));
118  }
119 
120  // destructor
122  {
123  if (m_pFeature)
124  delete [] m_pFeature;
125  }
126 
127 
128  // public methods
129  virtual bool ReadFromFileOld(FILE *pFile)
130  {
131  if (fread(&m_nSize, sizeof(int), 1, pFile) != 1) return false;
132  #ifdef IVT_BIG_ENDIAN
134  #endif
135 
136  if (m_pFeature) delete [] m_pFeature;
137  m_pFeature = new float[m_nSize];
138 
139  float u, v;
140 
141  if (fread(m_pFeature, m_nSize * sizeof(float), 1, pFile) != 1) return false;
142  if (fread(&u, sizeof(float), 1, pFile) != 1) return false;
143  if (fread(&v, sizeof(float), 1, pFile) != 1) return false;
144  if (fread(&angle, sizeof(float), 1, pFile) != 1) return false;
145  if (fread(&scale, sizeof(float), 1, pFile) != 1) return false;
146 
147  #ifdef IVT_BIG_ENDIAN
148  for (int i = 0; i < m_nSize; i++)
154  #endif
155 
156  Math2d::SetVec(point, u, v);
157 
158  return true;
159  }
160 
161  virtual bool ReadFromFile(FILE *pFile)
162  {
163  if (fread(&m_nSize, sizeof(int), 1, pFile) != 1) return false;
164  #ifdef IVT_BIG_ENDIAN
166  #endif
167 
168  if (m_pFeature) delete [] m_pFeature;
169  m_pFeature = new float[m_nSize];
170 
171  float u, v, x, y, z;
172 
173  if (fread(m_pFeature, m_nSize * sizeof(float), 1, pFile) != 1) return false;
174  if (fread(&u, sizeof(float), 1, pFile) != 1) return false;
175  if (fread(&v, sizeof(float), 1, pFile) != 1) return false;
176  if (fread(&x, sizeof(float), 1, pFile) != 1) return false;
177  if (fread(&y, sizeof(float), 1, pFile) != 1) return false;
178  if (fread(&z, sizeof(float), 1, pFile) != 1) return false;
179  if (fread(&angle, sizeof(float), 1, pFile) != 1) return false;
180  if (fread(&scale, sizeof(float), 1, pFile) != 1) return false;
181 
182  #ifdef IVT_BIG_ENDIAN
183  for (int i = 0; i < m_nSize; i++)
192  #endif
193 
194  Math2d::SetVec(point, u, v);
195  Math3d::SetVec(point3d, x, y, z);
196 
197  return true;
198  }
199 
200  virtual bool WriteToFile(FILE *pFile) const
201  {
202  float u = (float) point.x;
203  float v = (float) point.y;
204  float x = (float) point3d.x;
205  float y = (float) point3d.y;
206  float z = (float) point3d.z;
207 
208  #ifdef IVT_BIG_ENDIAN
209  const int size = invert_byte_order_long(m_nSize);
210  for (int i = 0; i < m_nSize; i++)
217  float angle_ = invert_byte_order_float(angle);
218  float scale_ = invert_byte_order_float(scale);
219  #else
220  const int size = m_nSize;
221  #endif
222 
223  if (fwrite(&size, sizeof(int), 1, pFile) != 1) return false;
224  if (fwrite(m_pFeature, m_nSize * sizeof(float), 1, pFile) != 1) return false;
225  if (fwrite(&u, sizeof(float), 1, pFile) != 1) return false;
226  if (fwrite(&v, sizeof(float), 1, pFile) != 1) return false;
227  if (fwrite(&x, sizeof(float), 1, pFile) != 1) return false;
228  if (fwrite(&y, sizeof(float), 1, pFile) != 1) return false;
229  if (fwrite(&z, sizeof(float), 1, pFile) != 1) return false;
230 
231  #ifdef IVT_BIG_ENDIAN
232  if (fwrite(&angle_, sizeof(float), 1, pFile) != 1) return false;
233  if (fwrite(&scale_, sizeof(float), 1, pFile) != 1) return false;
234  for (int i = 0; i < m_nSize; i++)
236  #else
237  if (fwrite(&angle, sizeof(float), 1, pFile) != 1) return false;
238  if (fwrite(&scale, sizeof(float), 1, pFile) != 1) return false;
239  #endif
240 
241  return true;
242  }
243 
244  // other public methods
245  int GetSize() const { return m_nSize; }
246 
247  virtual int GetSizeOnDisk() const
248  {
249  return sizeof(int) + m_nSize * sizeof(float) + 2 * sizeof(float) + 3 * sizeof(float) + 2 * sizeof(float);
250  }
251 
252  // pure virtual methods
253  virtual eFeatureType GetType() const = 0;
254  virtual CFeatureEntry* Clone() const = 0;
255  virtual float Error(const CDynamicArrayElement *pElement) const = 0;
256 
257 
258 
259 protected:
260  // protected attribute
261  int m_nSize;
262 
263 public:
264  float *m_pFeature;
267  float angle;
268  float scale;
269 };
270 
271 
272 
273 #endif /* _FEATURE_ENTRY_H_ */
virtual bool ReadFromFile(FILE *pFile)
Definition: FeatureEntry.h:161
CFeatureEntry(int nSize, float x, float y, float angle, float scale, Vec3d point3d=Math3d::zero_vec)
Definition: FeatureEntry.h:80
GLdouble GLdouble z
Definition: glext.h:3343
float invert_byte_order_float(float x)
Definition: helpers.cpp:73
float y
Definition: Math2d.h:84
GLenum GLenum GLenum GLenum GLenum scale
Definition: glext.h:5308
unsigned long invert_byte_order_long(unsigned long x)
Definition: helpers.cpp:79
Base class for the representation of local features.
Definition: FeatureEntry.h:72
virtual eFeatureType GetType() const =0
Data structure for the representation of a 3D vector.
Definition: Math3d.h:73
float x
Definition: Math3d.h:75
float z
Definition: Math3d.h:75
GLenum GLint x
Definition: glext.h:3125
float x
Definition: Math2d.h:84
const Vec3d zero_vec
Definition: Math3d.cpp:59
void SetVec(Vec3d &vec, float x, float y, float z)
Definition: Math3d.cpp:243
virtual CFeatureEntry * Clone() const =0
virtual bool ReadFromFileOld(FILE *pFile)
Definition: FeatureEntry.h:129
float y
Definition: Math3d.h:75
CFeatureEntry(const float *pFeature, int nSize, float x, float y, float angle, float scale, Vec3d point3d=Math3d::zero_vec)
Definition: FeatureEntry.h:95
virtual bool WriteToFile(FILE *pFile) const
Definition: FeatureEntry.h:200
int GetSize() const
Definition: FeatureEntry.h:245
float * m_pFeature
Definition: FeatureEntry.h:264
CFeatureEntry(const CFeatureEntry &featureEntry)
Definition: FeatureEntry.h:108
GLsizeiptr size
Definition: glext.h:3388
virtual float Error(const CDynamicArrayElement *pElement) const =0
GLenum GLint GLint y
Definition: glext.h:3125
const GLdouble * v
Definition: glext.h:3212
Data structure for the representation of a 2D vector.
Definition: Math2d.h:82
void SetVec(Vec2d &vec, float x, float y)
Definition: Math2d.cpp:68
virtual int GetSizeOnDisk() const
Definition: FeatureEntry.h:247


asr_ivt
Author(s): Allgeyer Tobias, Hutmacher Robin, Kleinert Daniel, Meißner Pascal, Scholz Jonas, Stöckle Patrick
autogenerated on Mon Dec 2 2019 03:47:27