Loading...
Searching...
No Matches
Gnuplot.hh
//
// A C++ interface to gnuplot.
//
// This is a direct translation from the C interface
// written by N. Devillard (which is available from
// http://ndevilla.free.fr/gnuplot/).
//
// As in the C interface this uses pipes and so wont
// run on a system that doesn't have POSIX pipe
// support
//
// Rajarshi Guha
// <rajarshi@presidency.com>
//
// 07/03/03
//
//
// A little correction for Win32 compatibility
// and MS VC 6.0 done by V.Chyzhdzenka
//
// Notes:
// 1. Added private method Gnuplot::init().
// 2. Temporary file is created in th current
// folder but not in /tmp.
// 3. Added #indef WIN32 e.t.c. where is needed.
// 4. Added private member m_sGNUPlotFileName is
// a name of executed GNUPlot file.
//
// Viktor Chyzhdzenka
// e-mail: chyzhdzenka@mail.ru
//
// 20/05/03
//
#ifndef _GNUPLOT_HH
#define _GNUPLOT_HH
#include <OpenMesh/Core/System/config.hh>
// #ifndef WIN32
// # include <unistd.h>
// #else
// # pragma warning (disable : 4786) // Disable 4786 warning for MS VC 6.0
// #endif
#if defined(OM_CC_MIPS)
# include <stdio.h>
#else
# include <cstdio>
#endif
#include <string>
#include <vector>
#include <stdexcept>
// ----------------------------------------------------------------------------
#ifdef WIN32
# define GP_MAX_TMP_FILES 27 //27 temporary files it's Microsoft restriction
#else
# define GP_MAX_TMP_FILES 64
# define GP_TMP_NAME_SIZE 512
# define GP_TITLE_SIZE 80
#endif
#define GP_CMD_SIZE 1024
// ----------------------------------------------------------------------------
using namespace std;
// ----------------------------------------------------------------------------
class GnuplotException : public runtime_error
{
public:
explicit GnuplotException(const string &msg) : runtime_error(msg){}
};
// ----------------------------------------------------------------------------
class Gnuplot
{
private:
FILE *gnucmd;
string pstyle;
vector<string> to_delete;
int nplots;
bool get_program_path(const string& );
bool valid;
// Name of executed GNUPlot file
static string gnuplot_executable_;
void init();
public:
Gnuplot();
explicit Gnuplot(const string & _style);
Gnuplot(const string & _title,
const string & _style,
const string & _xlabel,
const string & _ylabel,
const vector<double>& _x, const vector<double>& _y);
Gnuplot(const string &_title,
const string &_style,
const string &_xlabel,
const string &_ylabel,
const vector<double>& _x);
~Gnuplot();
void cmd(const char *_cmd, ...);
void set_style(const string & _style);
void set_ylabel(const string & _ylabel);
void set_xlabel(const string & _xlabel);
void plot_x(const vector<double>& _x, const string &_title);
void plot_xy(const vector<double>& _x, const vector<double>& _y, const string &_title);
void plot_slope(
double _a,
double _b,
const string & _title
);
void plot_equation(
const string & _equation,
const string & _title
);
void reset_plot(void);
bool is_valid(void) const { return valid; }
bool is_active(void) const { return this->nplots > 0; }
};
// ----------------------------------------------------------------------------
#endif // _GNUPLOT_HH
// ============================================================================
GnuplotException
Exception thrown by class Gnuplot.
Definition Gnuplot.hh:75
Gnuplot
Utility class interfacing with Gnuplot.
Definition Gnuplot.hh:93
Gnuplot::is_valid
bool is_valid(void) const
Is Self valid?
Definition Gnuplot.hh:174
Gnuplot::set_xlabel
void set_xlabel(const string &_xlabel)
set x axis label
Definition Gnuplot.cc:290
Gnuplot::plot_slope
void plot_slope(double _a, double _b, const string &_title)
Plot an equation of the form: y = ax + b You supply a and b.
Definition Gnuplot.cc:305
Gnuplot::cmd
void cmd(const char *_cmd,...)
Send a command to gnuplot (low-level function use by all plot functions.)
Definition Gnuplot.cc:261
Gnuplot::~Gnuplot
~Gnuplot()
Default constructor.
Definition Gnuplot.cc:191
Gnuplot::plot_x
void plot_x(const vector< double > &_x, const string &_title)
Plot a single vector.
Definition Gnuplot.cc:352
Gnuplot::plot_xy
void plot_xy(const vector< double > &_x, const vector< double > &_y, const string &_title)
Plot x,y pairs.
Definition Gnuplot.cc:421
Gnuplot::Gnuplot
Gnuplot()
Default constructor.
Definition Gnuplot.cc:110
Gnuplot::reset_plot
void reset_plot(void)
If multiple plots are present it will clear the plot area.
Definition Gnuplot.cc:230
Gnuplot::set_style
void set_style(const string &_style)
set line style
Definition Gnuplot.cc:243
Gnuplot::is_active
bool is_active(void) const
Is Self active, i.e. does it have an active plot?
Definition Gnuplot.hh:177
Gnuplot::plot_equation
void plot_equation(const string &_equation, const string &_title)
Plot an equation supplied as a string.
Definition Gnuplot.cc:328
Gnuplot::set_ylabel
void set_ylabel(const string &_ylabel)
set x axis label
Definition Gnuplot.cc:278