30 double min_x, max_x, min_y, max_y;
31 min_x = max_x = min_y = max_y = 0;
32 for (std::pair<double, double> datum: data)
34 if (datum.first < min_x) min_x = datum.first;
35 if (datum.first > max_x) max_x = datum.first;
36 if (datum.second < min_y) min_y = datum.second;
37 if (datum.second > max_y) max_y = datum.second;
40 if (data.size() > 1) xdistance = std::abs(data.at(1).first - data.at(0).first);
41 std::pair<double, double> xRange(min_x, max_x + xdistance);
42 std::pair<double, double> yRange(min_y, max_y + ((
double) 1 / data.size()));
44 initPlot(
"Tabular(" + rotaxis +
")", rotaxis,
"P(" + rotaxis +
")", xRange, yRange, data.size());
45 for (
unsigned int i = 0; i < data.size() - 1; i++)
52 addPointToBuffer(data.at(data.size() - 1).first, data.at(data.size() - 1).second);
53 addPointToBuffer(data.at(data.size() - 1).first + xdistance, data.at(data.size() - 1).second);
59 const std::string& pXLabel,
60 const std::string& pYLabel,
61 const std::pair<double, double>& pXRange,
62 const std::pair<double, double>& pYRange,
70 mPlotFileHandler.
add(
"set xrange [" + boost::lexical_cast<std::string>(pXRange.first) +
":" + boost::lexical_cast<std::string>(pXRange.second) +
"]\n");
71 mPlotFileHandler.
add(
"set yrange [" + boost::lexical_cast<std::string>(pYRange.first) +
":" + boost::lexical_cast<std::string>(pYRange.second) +
"]\n");
89 throw std::runtime_error(
"Cannot show non-existing gnuplot visualization.");
118 for (
unsigned int i = 0; i < pointBuffer.size(); i++) {
119 file << pointBuffer.at(i).first <<
" " << pointBuffer.at(i).second <<
"\n";
122 file <<
"pause -1 \"Hit return to continue\"";
void addPointToBuffer(double x, double y)
void plotOrientationHistogram(const std::string &filename, const std::vector< std::pair< double, double >> data, const std::string &rotaxis)
~GMMGnuplotVisualization()
PlotFileHandler mPlotFileHandler
void initPlot(const std::string &pPlotTitle, const std::string &pXLabel, const std::string &pYLabel, const std::pair< double, double > &pXRange, const std::pair< double, double > &pYRange, unsigned int samples)
PlotFileHandler(std::string filename)
boost::shared_ptr< Gnuplot > mGnuplotHandler
#define ROS_INFO_STREAM(args)
GMMGnuplotVisualization()
std::vector< std::pair< double, double > > mPointBuffer
void send(std::vector< std::pair< double, double >> pointBuffer)