Robowflex  v0.1
Making MoveIt Easy
gnuplot.h
Go to the documentation of this file.
1 /* Author: Zachary Kingston */
2 
3 #ifndef ROBOWFLEX_IO_GNUPLOT_
4 #define ROBOWFLEX_IO_GNUPLOT_
5 
9 
10 #if IS_BOOST_164
11 #include <boost/process.hpp>
12 #endif
13 
14 namespace robowflex
15 {
16  namespace IO
17  {
18  /** \brief Helper class to open a pipe to a GNUPlot instance for live visualization of data.
19  */
21  {
22  public:
26 
27  GNUPlotHelper() = default;
28 
29  // non-copyable
30  GNUPlotHelper(GNUPlotHelper const &) = delete;
31  void operator=(GNUPlotHelper const &) = delete;
32 
33  /** \name Plotting
34  \{ */
35 
37  {
38  std::string instance{"default"};
39 
40  struct Axis
41  {
42  std::string label; ///< Axis label.
43  double max = constants::nan; ///< Upper axis limit. If NaN, will auto-adjust.
44  double min = constants::nan; ///< Lower axis limit. If NaN, will auto-adjust.
45  };
46 
47  std::string title; ///< Title of the plot.
48  std::string mode{"qt"}; ///< Terminal mode for GNUPlot
49 
50  Axis x; ///< X-axis parameters.
51  Axis y; ///< Y-axis parameters.
52  };
53 
54  /** \brief Configure a plot using common options.
55  */
56  void configurePlot(const PlottingOptions &options);
57 
58  /** \brief Time series plotting options.
59  */
61  {
62  std::map<std::string, Series> points; ///< Map of names to time series data.
63  };
64 
65  /** \brief Plot timeseries data.
66  * \param[in] options Plotting options.
67  */
68  void timeseries(const TimeSeriesOptions &options);
69 
70  /** \brief Box plotting options.
71  */
73  {
74  bool outliers{true};
75  bool sorted{true};
76  std::map<std::string, Values> values; ///< Map of names to data.
77  };
78 
79  /** \brief Plot box data.
80  * \param[in] options Plotting options.
81  */
82  void boxplot(const BoxPlotOptions &options);
83 
84  /** \} */
85 
86  private:
87  class Instance
88  {
89  public:
90  /** \brief Constructor. Setups up pipe to GNUPlot.
91  */
92  Instance();
93 
94  /** \name Raw Input
95  \{ */
96 
97  void write(const std::string &line);
98  void writeline(const std::string &line);
99  void flush();
100 
101  /** \} */
102 
103  private:
104  // non-copyable
105  Instance(Instance const &) = delete;
106  void operator=(Instance const &) = delete;
107 
108  bool debug_{false};
109 
110 #if IS_BOOST_164
111  boost::process::opstream input_;
112  // boost::process::ipstream output_;
113  boost::process::ipstream error_;
114  boost::process::child gnuplot_;
115 #endif
116  };
117 
118  /** \brief Get the named GNUPlot instance.
119  * \param[in] name Name of instance.
120  * \return The instance.
121  */
123  std::map<std::string, std::shared_ptr<Instance>> instances_; ///< Map of open GNUPlot instances
124  };
125 
126  /** \brief Helper class to plot a real metric as a box plot using GNUPlot from benchmarking data.
127  */
129  {
130  public:
131  /** \brief Constructor.
132  */
134 
135  /** \brief Destructor.
136  */
137  ~GNUPlotPlanDataSetOutputter() override;
138 
139  /** \brief Visualize results.
140  * \param[in] results Results to visualize.
141  */
142  void dump(const PlanDataSet &results) override;
143 
144  private:
147  };
148  } // namespace IO
149 } // namespace robowflex
150 
151 #endif
void writeline(const std::string &line)
Definition: gnuplot.cpp:39
void operator=(Instance const &)=delete
void write(const std::string &line)
Definition: gnuplot.cpp:30
Instance()
Constructor. Setups up pipe to GNUPlot.
Definition: gnuplot.cpp:14
Instance(Instance const &)=delete
Helper class to open a pipe to a GNUPlot instance for live visualization of data.
Definition: gnuplot.h:21
std::map< std::string, std::shared_ptr< Instance > > instances_
Map of open GNUPlot instances.
Definition: gnuplot.h:123
void operator=(GNUPlotHelper const &)=delete
std::shared_ptr< Instance > getInstance(const std::string &name)
Get the named GNUPlot instance.
Definition: gnuplot.cpp:165
void boxplot(const BoxPlotOptions &options)
Plot box data.
Definition: gnuplot.cpp:112
GNUPlotHelper(GNUPlotHelper const &)=delete
void timeseries(const TimeSeriesOptions &options)
Plot timeseries data.
Definition: gnuplot.cpp:80
void configurePlot(const PlottingOptions &options)
Configure a plot using common options.
Definition: gnuplot.cpp:54
Helper class to plot a real metric as a box plot using GNUPlot from benchmarking data.
Definition: gnuplot.h:129
~GNUPlotPlanDataSetOutputter() override
Destructor.
Definition: gnuplot.cpp:177
void dump(const PlanDataSet &results) override
Visualize results.
Definition: gnuplot.cpp:181
GNUPlotPlanDataSetOutputter(const std::string &metric)
Constructor.
Definition: gnuplot.cpp:173
An abstract class for outputting benchmark results.
Definition: benchmarking.h:507
Detailed statistics about a benchmark of multiple queries.
Definition: benchmarking.h:141
static const double nan
Definition: constants.h:18
Main namespace. Contains all library classes and functions.
Definition: scene.cpp:25
std::map< std::string, Values > values
Map of names to data.
Definition: gnuplot.h:76
double max
Upper axis limit. If NaN, will auto-adjust.
Definition: gnuplot.h:43
double min
Lower axis limit. If NaN, will auto-adjust.
Definition: gnuplot.h:44
std::string title
Title of the plot.
Definition: gnuplot.h:47
std::string mode
Terminal mode for GNUPlot.
Definition: gnuplot.h:48
Time series plotting options.
Definition: gnuplot.h:61
std::map< std::string, Series > points
Map of names to time series data.
Definition: gnuplot.h:62