MetaFile.h
Go to the documentation of this file.
00001 
00033 
00034 
00035 
00036 
00037 
00038 
00039 
00040 
00041 
00042 
00043 
00044 
00045 
00046 
00047 
00048 
00049 
00050 
00051 
00052 
00053 
00054 
00055 
00056 
00057 
00058 
00059 
00060 
00061 
00062 
00063 
00064 
00065 
00066 
00067 
00068 
00069 
00070 
00071 
00072 
00073 
00074 
00075 
00076 
00077 #ifndef __META_FILE__
00078 #define __META_FILE__
00079 
00080 #include <string>
00081 #include <sstream>
00082 #include <vector>
00083 #include <opencv/cv.h>
00084 
00085 #include "rapidxml.hpp"
00086 
00087 class MetaFile
00088 {
00089 public:
00090   struct MetaData
00091   {
00092   public:
00093     struct tFaceDim
00094     {
00095       float Width;
00096       float Height;
00097       cv::Mat oTf; // transformation from object frame to face frame
00098     };
00099     
00100   public:
00101     
00102     MetaData(){ reset(); }
00103     
00104   public:
00105     std::string Name;
00106     int NFaces;
00107     std::string Type;
00108     
00109     struct tDimensions
00110     {
00111       // for 3D objects
00112       struct tVolume
00113       {
00114         float Scale; 
00115       } Volume;
00116       
00117       // for planar objects in metres
00118       struct tPlanar
00119       {
00120         float Width;
00121         float Height;
00122         float Depth;
00123         
00124         // Dimensions of each face image
00125         std::vector<tFaceDim> Faces;
00126         
00127       } Planar;
00128       
00129     } Dimensions;
00130     
00131     inline void reset()
00132     {
00133       Name = Type = "";
00134       NFaces = 0;
00135       Dimensions.Planar.Width = 0;
00136       Dimensions.Planar.Height = 0;
00137       Dimensions.Planar.Depth = 0;
00138     }
00139   };
00140   
00141 public:
00142   
00148   static void readFile(const std::string &filename, MetaData &data);
00149   
00155   static void saveFile(const std::string &filename, const MetaData &data);
00156   
00157 protected:
00158 
00164   template<class T>
00165   static T parse(const std::string &s);
00166 
00172   template<class T>
00173   static std::vector<T> parse(const std::vector<std::string> &v);
00174 
00180   template<class T>
00181   static std::string stringfy(T v);
00182 
00189   template<class T>
00190   static std::string stringfy(T* v, int N);
00191 
00192 protected:
00193 
00199   static void parseDimensions(MetaFile::MetaData &meta, 
00200     rapidxml::xml_node<> *node);
00201   
00207   static void parseFace(MetaFile::MetaData &meta, 
00208     rapidxml::xml_node<> *node);
00209 
00210 };
00211 
00212 // ----------------------------------------------------------------------------
00213 
00214 template<class T>
00215 T MetaFile::parse(const std::string &s)
00216 {
00217   std::stringstream ss(s);
00218   T v;
00219   ss >> v;
00220   return v;
00221 }
00222 
00223 // ----------------------------------------------------------------------------
00224 
00225 template<class T>
00226 std::vector<T> MetaFile::parse(const std::vector<std::string> &v)
00227 {
00228   std::vector<T> ret;
00229   ret.reserve(v.size());
00230   
00231   std::vector<std::string>::const_iterator it;
00232   for(it = v.begin(); it != v.end(); ++it)
00233   {
00234     ret.push_back( MetaFile::parse<T>(*it) );
00235   }
00236   
00237   return ret;
00238 }
00239 
00240 // ----------------------------------------------------------------------------
00241 
00242 template<class T>
00243 std::string MetaFile::stringfy(T v)
00244 {
00245   std::stringstream ss;
00246   ss << v;
00247   return ss.str();
00248 }
00249 
00250 // ----------------------------------------------------------------------------
00251 
00252 template<class T>
00253 std::string MetaFile::stringfy(T* v, int N)
00254 {
00255   std::stringstream ss;
00256   
00257   for(int i = 0; i < N; ++i)
00258     ss << v[i] << " ";
00259 
00260   return ss.str();
00261 }
00262 
00263 // ----------------------------------------------------------------------------
00264 
00265 #endif
00266 


re_vision
Author(s): Dorian Galvez-Lopez
autogenerated on Sun Jan 5 2014 11:31:59