- Main Page
- Modules
- Namespaces
- Classes
- Files
- Related Pages

- File List
- File Members

# Tools/Utils/Gnuplot.hh

    00001
    00002 //
    00003 // A C++ interface to gnuplot.
    00004 //
    00005 // This is a direct translation from the C interface
    00006 // written by N. Devillard (which is available from
    00007 // http://ndevilla.free.fr/gnuplot/).
    00008 //
    00009 // As in the C interface this uses pipes and so wont
    00010 // run on a system that doesn't have POSIX pipe
    00011 // support
    00012 //
    00013 // Rajarshi Guha
    00014 // <rajarshi@presidency.com>
    00015 //
    00016 // 07/03/03
    00017 //
    00019 //
    00020 // A little correction for Win32 compatibility
    00021 // and MS VC 6.0 done by V.Chyzhdzenka
    00022 //
    00023 // Notes:
    00024 // 1. Added private method Gnuplot::init().
    00025 // 2. Temporary file is created in th current
    00026 //    folder but not in /tmp.
    00027 // 3. Added #indef WIN32 e.t.c. where is needed.
    00028 // 4. Added private member m_sGNUPlotFileName is
    00029 //    a name of executed GNUPlot file.
    00030 //
    00031 // Viktor Chyzhdzenka
    00032 // e-mail: chyzhdzenka@mail.ru
    00033 //
    00034 // 20/05/03
    00035 //
    00037
    00038 #ifndef _GNUPLOT_HH
    00039 #define _GNUPLOT_HH
    00040
    00041 #include <OpenMesh/Core/System/config.hh>
    00042 // #ifndef WIN32
    00043 // #  include <unistd.h>
    00044 // #else
    00045 // #  pragma warning (disable : 4786) // Disable 4786 warning for MS VC 6.0
    00046 // #endif
    00047 #if defined(OM_CC_MIPS)
    00048 #  include <stdio.h>
    00049 #else
    00050 #  include <cstdio>
    00051 #endif
    00052 #include <string>
    00053 #include <vector>
    00054 #include <stdexcept>
    00055
    00056 // ----------------------------------------------------------------------------
    00057
    00058 #ifdef WIN32
    00059 #  define GP_MAX_TMP_FILES    27 //27 temporary files it's Microsoft restriction
    00060 #else
    00061 #  define GP_MAX_TMP_FILES    64
    00062 #  define GP_TMP_NAME_SIZE    512
    00063 #  define GP_TITLE_SIZE       80
    00064 #endif
    00065 #define GP_CMD_SIZE         1024
    00066
    00067 // ----------------------------------------------------------------------------
    00068
    00069 using namespace std;
    00070
    00071 // ----------------------------------------------------------------------------
    00072
    00074 class GnuplotException : public runtime_error
    00075 {
    00076 public:
    00077   GnuplotException(const string &msg) : runtime_error(msg){}
    00078 };
    00079
    00080 // ----------------------------------------------------------------------------
    00081
    00092 class Gnuplot
    00093 {
    00094 private:
    00095
    00096   FILE            *gnucmd;
    00097   string           pstyle;
    00098   vector<string>   to_delete;
    00099   int              nplots;
    00100   bool             get_program_path(const string);
    00101   bool             valid;
    00102
    00103   // Name of executed GNUPlot file
    00104   static string    gnuplot_executable_;
    00105
    00106   void init();
    00107
    00108 public:
    00109
    00111
    00112
    00113   Gnuplot();
    00114
    00116   Gnuplot(const string & _style);
    00117
    00119   Gnuplot(const string & _title,
    00120           const string & _style,
    00121           const string & _xlabel,
    00122           const string & _ylabel,
    00123           vector<double> _x, vector<double> _y);
    00124
    00126   Gnuplot(const string &_title,
    00127           const string &_style,
    00128           const string &_xlabel,
    00129           const string &_ylabel,
    00130           vector<double> _x);
    00132
    00133   ~Gnuplot();
    00134
    00136   void cmd(const char *_cmd, ...);
    00137
    00139
    00140   void set_style(const string & _style);
    00141   void set_ylabel(const string & _ylabel);
    00142   void set_xlabel(const string & _xlabel);
    00143
    00144
    00146
    00147
    00149   void plot_x(vector<double> _x, const string &_title);
    00150
    00152   void plot_xy(vector<double> _x, vector<double> _y, const string  &_title);
    00153
    00156   void plot_slope(
    00157                   double _a,
    00158                   double _b,
    00159                   const string & _title
    00160                   );
    00161
    00163   void plot_equation(
    00164                      const string & _equation,
    00165                      const string & _title
    00166                      );
    00167
    00169   void reset_plot(void);
    00170
    00172
    00174   bool is_valid(void) const { return valid; }
    00175
    00177   bool is_active(void) const { return this->nplots > 0; }
    00178 };
    00179
    00180
    00181 // ----------------------------------------------------------------------------
    00182 #endif // _GNUPLOT_HH
    00183 // ============================================================================
    00184