1 #include "CsvWriter.h"
2 
CsvWriter(const string & path,const string & separator)3 CsvWriter::CsvWriter(const string &path, const string &separator){
4     _file.open(path.c_str(), ofstream::out);
5     _isFirstTerm = true;
6     _separator = separator;
7 }
8 
~CsvWriter()9 CsvWriter::~CsvWriter() {
10     _file.flush();
11     _file.close();
12 }
13 
writeXYZ(const vector<Point3f> & list_points3d)14 void CsvWriter::writeXYZ(const vector<Point3f> &list_points3d)
15 {
16     for(size_t i = 0; i < list_points3d.size(); ++i)
17     {
18         string x = FloatToString(list_points3d[i].x);
19         string y = FloatToString(list_points3d[i].y);
20         string z = FloatToString(list_points3d[i].z);
21 
22         _file << x << _separator << y << _separator << z << std::endl;
23     }
24 }
25 
writeUVXYZ(const vector<Point3f> & list_points3d,const vector<Point2f> & list_points2d,const Mat & descriptors)26 void CsvWriter::writeUVXYZ(const vector<Point3f> &list_points3d, const vector<Point2f> &list_points2d, const Mat &descriptors)
27 {
28     for(size_t i = 0; i < list_points3d.size(); ++i)
29     {
30         string u = FloatToString(list_points2d[i].x);
31         string v = FloatToString(list_points2d[i].y);
32         string x = FloatToString(list_points3d[i].x);
33         string y = FloatToString(list_points3d[i].y);
34         string z = FloatToString(list_points3d[i].z);
35 
36         _file << u << _separator << v << _separator << x << _separator << y << _separator << z;
37 
38         for(int j = 0; j < 32; ++j)
39         {
40             string descriptor_str = FloatToString(descriptors.at<float>((int)i,j));
41             _file << _separator << descriptor_str;
42         }
43         _file << std::endl;
44     }
45 }
46