PixelPointFile.cpp
Go to the documentation of this file.
00001 
00024 #include <vector>
00025 #include <fstream>
00026 #include "PixelPointFile.h"
00027 #include "DUtils.h"
00028 
00029 using namespace std;
00030 using namespace DVision;
00031 
00032 // ---------------------------------------------------------------------------
00033 
00034 void PixelPointFile::saveFile(const std::string &filename,
00035     const std::vector<PixelPoint> &points)
00036 {
00037   // Format:
00038   // N
00039   // u v x y z idx
00040   // ...
00041   
00042   fstream f(filename.c_str(), ios::out);
00043   if(!f.is_open()) throw DUtils::DException("Cannot open file " + filename);
00044   
00045   f << points.size() << endl;
00046   
00047   f.setf(ios::fixed, ios::floatfield);
00048   f.precision(4);
00049   
00050   std::vector<PixelPoint>::const_iterator pit;
00051   for(pit = points.begin(); pit != points.end(); ++pit)
00052   {
00053     f << pit->u << " "
00054       << pit->v << " "
00055       << pit->x << " "
00056       << pit->y << " "
00057       << pit->z << " "
00058       << pit->idx << endl;
00059   }
00060 
00061   f.close();
00062 }
00063 
00064 // ---------------------------------------------------------------------------
00065 
00066 void PixelPointFile::readFile(const std::string &filename,
00067     std::vector<PixelPoint> &points)
00068 {
00069   points.clear();
00070   
00071   fstream f(filename.c_str(), ios::in);
00072   if(!f.is_open()) throw DUtils::DException("Cannot open file " + filename);
00073   
00074   int N;
00075   f >> N;
00076   
00077   points.reserve(N);
00078   
00079   for(int i = 0; i < N; ++i)
00080   {
00081     float u, v, x, y, z;
00082     int idx;
00083     f >> u >> v >> x >> y >> z >> idx;
00084     
00085     if(!f.fail())
00086     {
00087       points.push_back(PixelPoint(u, v, x, y, z, idx));
00088     }else
00089     {
00090       break;
00091     }
00092   }
00093   
00094   f.close();
00095 }
00096 
00097 // ---------------------------------------------------------------------------
00098 
00099 
00100 


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