Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Gnuplot.hh
1 //
3 // A C++ interface to gnuplot.
4 //
5 // This is a direct translation from the C interface
6 // written by N. Devillard (which is available from
7 // http://ndevilla.free.fr/gnuplot/).
8 //
9 // As in the C interface this uses pipes and so wont
10 // run on a system that doesn't have POSIX pipe
11 // support
12 //
13 // Rajarshi Guha
14 // <rajarshi@presidency.com>
15 //
16 // 07/03/03
17 //
19 //
20 // A little correction for Win32 compatibility
21 // and MS VC 6.0 done by V.Chyzhdzenka
22 //
23 // Notes:
24 // 1. Added private method Gnuplot::init().
25 // 2. Temporary file is created in th current
26 // folder but not in /tmp.
27 // 3. Added #indef WIN32 e.t.c. where is needed.
28 // 4. Added private member m_sGNUPlotFileName is
29 // a name of executed GNUPlot file.
30 //
31 // Viktor Chyzhdzenka
32 // e-mail: chyzhdzenka@mail.ru
33 //
34 // 20/05/03
35 //
37 
38 #ifndef _GNUPLOT_HH
39 #define _GNUPLOT_HH
40 
41 #include <OpenMesh/Core/System/config.hh>
42 // #ifndef WIN32
43 // # include <unistd.h>
44 // #else
45 // # pragma warning (disable : 4786) // Disable 4786 warning for MS VC 6.0
46 // #endif
47 #if defined(OM_CC_MIPS)
48 # include <stdio.h>
49 #else
50 # include <cstdio>
51 #endif
52 #include <string>
53 #include <vector>
54 #include <stdexcept>
55 
56 // ----------------------------------------------------------------------------
57 
58 #ifdef WIN32
59 # define GP_MAX_TMP_FILES 27 //27 temporary files it's Microsoft restriction
60 #else
61 # define GP_MAX_TMP_FILES 64
62 # define GP_TMP_NAME_SIZE 512
63 # define GP_TITLE_SIZE 80
64 #endif
65 #define GP_CMD_SIZE 1024
66 
67 // ----------------------------------------------------------------------------
68 
69 using namespace std;
70 
71 // ----------------------------------------------------------------------------
72 
74 class GnuplotException : public runtime_error
75 {
76 public:
77  GnuplotException(const string &msg) : runtime_error(msg){}
78 };
79 
80 // ----------------------------------------------------------------------------
81 
92 class Gnuplot
93 {
94 private:
95 
96  FILE *gnucmd;
97  string pstyle;
98  vector<string> to_delete;
99  int nplots;
100  bool get_program_path(const string& );
101  bool valid;
102 
103  // Name of executed GNUPlot file
104  static string gnuplot_executable_;
105 
106  void init();
107 
108 public:
109 
111 
112  Gnuplot();
114 
116  Gnuplot(const string & _style);
117 
119  Gnuplot(const string & _title,
120  const string & _style,
121  const string & _xlabel,
122  const string & _ylabel,
123  vector<double> _x, vector<double> _y);
124 
126  Gnuplot(const string &_title,
127  const string &_style,
128  const string &_xlabel,
129  const string &_ylabel,
130  vector<double> _x);
132 
133  ~Gnuplot();
134 
136  void cmd(const char *_cmd, ...);
137 
139 
140  void set_style(const string & _style);
141  void set_ylabel(const string & _ylabel);
142  void set_xlabel(const string & _xlabel);
143 
144 
146 
147 
149  void plot_x(vector<double> _x, const string &_title);
150 
152  void plot_xy(vector<double> _x, vector<double> _y, const string &_title);
153 
156  void plot_slope(
157  double _a,
158  double _b,
159  const string & _title
160  );
161 
163  void plot_equation(
164  const string & _equation,
165  const string & _title
166  );
167 
169  void reset_plot(void);
170 
172 
174  bool is_valid(void) const { return valid; }
175 
177  bool is_active(void) const { return this->nplots > 0; }
178 };
179 
180 
181 // ----------------------------------------------------------------------------
182 #endif // _GNUPLOT_HH
183 // ============================================================================
184 
bool is_valid(void) const
Is Self valid?
Definition: Gnuplot.hh:174
bool is_active(void) const
Is Self active, i.e. does it have an active plot?
Definition: Gnuplot.hh:177
Exception thrown by class Gnuplot.
Definition: Gnuplot.hh:74
STL namespace.