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);
50 std::string dataSetName;
51 std::pair<std::string, std::string> axisNames;
52 std::multiset< std::pair<Tx, Ty> > dataSet;
54 void writeGnuPlotFile(
const std::string& filename);
65 template <
typename Tx,
typename Ty>
68 dataSetName = _dataSetName;
69 axisNames.first = _axisNameX;
70 axisNames.second = _axisNameY;
79 template <
typename Tx,
typename Ty>
82 dataSet.insert(std::make_pair(x, y));
88 template <
typename Tx,
typename Ty>
100 template <
typename Tx,
typename Ty>
103 std::string _filename;
107 _filename = dataSetName +
".dat";
111 _filename = filename;
115 if(format == GNUPLOT)
117 writeGnuPlotFile(_filename);
126 template <
typename Tx,
typename Ty>
129 std::ofstream file(filename.c_str());
130 int tabLength = axisNames.first.length()+20;
132 file<<std::fixed <<std::setprecision(5);
136 file<<
"# " <<dataSetName <<
"\n";
137 file<<
"# " <<std::setw(tabLength) <<axisNames.first <<std::setw(tabLength) <<axisNames.second <<
"\n";
140 for(
typename std::multiset< std::pair<Tx, Ty> >::iterator it = dataSet.begin(); it != dataSet.end(); ++it)
142 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 writeDataToFile(const std::string &filename="", DataExportFormat format=GNUPLOT)
Definition: data_collector.h:101
void addData(Tx x, Ty y)
Definition: data_collector.h:80
DataCollector2D(const std::string &_dataSetName, const std::string &_axisNameX, const std::string &_axisNameY)
Definition: data_collector.h:66
void clear()
Definition: data_collector.h:89