5 #ifndef DATA_COLLECTOR_H
6 #define DATA_COLLECTOR_H
37 template <
typename Tx,
typename Ty,
typename Tz>
42 DataCollector3D(
const std::string& _dataSetName,
const std::string& _axisNameX,
const std::string& _axisNameY,
const std::string& _axisNameZ);
46 void writeDataToFile(
const std::string& filename =
"", DataExportFormat format = GNUPLOT,
int tabLength=-1);
49 std::string dataSetName;
50 std::pair<std::string, std::pair<std::string, std::string> > axisNames;
51 std::multimap< Tx, std::pair<Ty, Tz> > dataSet;
53 void writeGnuPlotFile(
const std::string& filename,
int tabLength=-1);
65 template <
typename Tx,
typename Ty,
typename Tz>
68 dataSetName = _dataSetName;
69 axisNames.first = _axisNameX;
70 axisNames.second = std::make_pair(_axisNameY, _axisNameZ);
80 template <
typename Tx,
typename Ty,
typename Tz>
83 dataSet.insert(std::make_pair(x, std::make_pair(y,z)));
89 template <
typename Tx,
typename Ty,
typename Tz>
102 template <
typename Tx,
typename Ty,
typename Tz>
105 std::string _filename;
109 _filename = dataSetName +
".dat";
113 _filename = filename;
117 if(format == GNUPLOT)
119 writeGnuPlotFile(_filename, tabLength);
129 template <
typename Tx,
typename Ty,
typename Tz>
132 std::ofstream file(filename.c_str());
135 tabLength = axisNames.first.length()+10;
138 file<<std::fixed <<std::setprecision(5);
142 file<<
"# " <<dataSetName <<
"\n";
143 file<<
"# " <<std::setw(tabLength) <<axisNames.first <<std::setw(tabLength) <<axisNames.second.first <<std::setw(tabLength) <<axisNames.second.second <<
"\n";
145 const Tx *pLastKey = NULL;
148 for(
typename std::multimap< Tx, std::pair<Ty, Tz> >::iterator it = dataSet.begin(); it != dataSet.end(); ++it)
150 if( (pLastKey!=NULL) && (*pLastKey==it->first) )
154 pLastKey = &(it->first);
156 typename std::pair<typename std::multimap< Tx, std::pair<Ty, Tz> >::iterator,
typename std::multimap< Tx, std::pair<Ty, Tz> >::iterator> range = dataSet.equal_range(*pLastKey);
158 for(
typename std::multimap< Tx, std::pair<Ty, Tz> >::iterator i = range.first; i != range.second; ++i)
160 file<<
" " <<std::setw(tabLength) <<(*pLastKey)<<std::setw(tabLength)<<i->second.first<<std::setw(tabLength)<<i->second.second<<
"\n";
void writeDataToFile(const std::string &filename="", DataExportFormat format=GNUPLOT, int tabLength=-1)
Definition: data_collector_3d.h:103
void addData(Tx x, Ty y, Tz z)
Definition: data_collector_3d.h:81
void clear()
Definition: data_collector_3d.h:90
DataCollector3D(const std::string &_dataSetName, const std::string &_axisNameX, const std::string &_axisNameY, const std::string &_axisNameZ)
Definition: data_collector_3d.h:66
A class that can be used to collect 2D data.
Definition: data_collector_3d.h:38