5 #ifndef DATA_COLLECTOR_H
6 #define DATA_COLLECTOR_H
38 template <
typename Tx,
typename Ty>
43 DataCollector2D(
const std::string& _dataSetName,
const std::string& _axisNameX,
const std::string& _axisNameY);
47 void writeDataToFile(
const std::string& filename =
"", DataExportFormat format = GNUPLOT);
49 void appendDataToFile(
const std::string& filename,
bool firstTime, DataExportFormat format = GNUPLOT);
52 std::string dataSetName;
53 std::pair<std::string, std::string> axisNames;
54 std::multiset< std::pair<Tx, Ty> > dataSet;
56 void writeGnuPlotFile(
const std::string& filename);
58 void appendGnuPlotFile(
const std::string& filename,
bool firstTime);
69 template <
typename Tx,
typename Ty>
72 dataSetName = _dataSetName;
73 axisNames.first = _axisNameX;
74 axisNames.second = _axisNameY;
83 template <
typename Tx,
typename Ty>
86 dataSet.insert(std::make_pair(x, y));
92 template <
typename Tx,
typename Ty>
104 template <
typename Tx,
typename Ty>
107 std::string _filename;
111 _filename = dataSetName +
".dat";
115 _filename = filename;
119 if(format == GNUPLOT)
121 writeGnuPlotFile(_filename);
133 template <
typename Tx,
typename Ty>
136 std::string _filename;
140 _filename = dataSetName +
".dat";
144 _filename = filename;
148 if(format == GNUPLOT)
150 appendGnuPlotFile(_filename, firstTime);
159 template <
typename Tx,
typename Ty>
162 std::ofstream file(filename.c_str());
163 int tabLength = axisNames.first.length()+20;
165 file<<std::fixed <<std::setprecision(5);
169 file<<
"# " <<dataSetName <<
"\n";
170 file<<
"# " <<std::setw(tabLength) <<axisNames.first <<std::setw(tabLength) <<axisNames.second <<
"\n";
173 for(
typename std::multiset< std::pair<Tx, Ty> >::iterator it = dataSet.begin(); it != dataSet.end(); ++it)
175 file<<
" " <<std::setw(tabLength) <<it->first <<std::setw(tabLength) <<it->second <<
"\n";
189 template <
typename Tx,
typename Ty>
190 void DataCollector2D<Tx, Ty>::appendGnuPlotFile(
const std::string& filename,
bool firstTime)
192 std::ofstream file(filename.c_str(), std::ios::app);
193 int tabLength = axisNames.first.length()+20;
195 file<<std::fixed <<std::setprecision(5);
201 file<<
"# " <<dataSetName <<
"\n";
202 file<<
"# " <<std::setw(tabLength) <<axisNames.first <<std::setw(tabLength) <<axisNames.second <<
"\n";
206 for(
typename std::multiset< std::pair<Tx, Ty> >::iterator it = dataSet.begin(); it != dataSet.end(); ++it)
208 file<<
" " <<std::setw(tabLength) <<it->first <<std::setw(tabLength) <<it->second <<
"\n";
A class that can be used to collect 2D data.
Definition: data_collector.h:39
void appendDataToFile(const std::string &filename, bool firstTime, DataExportFormat format=GNUPLOT)
Definition: data_collector.h:134
void writeDataToFile(const std::string &filename="", DataExportFormat format=GNUPLOT)
Definition: data_collector.h:105
void addData(Tx x, Ty y)
Definition: data_collector.h:84
DataCollector2D(const std::string &_dataSetName, const std::string &_axisNameX, const std::string &_axisNameY)
Definition: data_collector.h:70
void clear()
Definition: data_collector.h:93