Gnuplot.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. ////////////////////////////////////////////
  2. //
  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 does'nt have POSIX pipe
  11. // support
  12. //
  13. // Rajarshi Guha
  14. // <rajarshi@presidency.com>
  15. //
  16. // 07/03/03
  17. //
  18. // 26/01/04 - Gnuplot::cmd() was rewritten to accept a
  19. // char* rather than a std::string, thus avoiding the
  20. // va_start warning at compile time
  21. // /////////////////////////////////////////
  22. #ifndef _GNUPLOT_PIPES_H_
  23. #define _GNUPLOT_PIPES_H_
  24. #include <stdarg.h>
  25. #include <unistd.h>
  26. #include <cstdlib>
  27. #include <cstdio>
  28. #include <cstring>
  29. #include <string>
  30. #include <iostream>
  31. #include <fstream>
  32. #include <sstream>
  33. #include <list>
  34. #include <map>
  35. #include <vector>
  36. #include <stdexcept>
  37. #define GP_MAX_TMP_FILES 64
  38. #define GP_TMP_NAME_SIZE 512
  39. #define GP_CMD_SIZE 1024
  40. #define GP_TITLE_SIZE 80
  41. namespace OBJREC
  42. {
  43. class GnuplotException: public std::runtime_error
  44. {
  45. public:
  46. GnuplotException(const std::string &msg) :
  47. std::runtime_error(msg)
  48. {
  49. }
  50. };
  51. class Gnuplot
  52. {
  53. private:
  54. FILE *gnucmd;
  55. std::string pstyle;
  56. std::vector<std::string> to_delete;
  57. int nplots;
  58. bool get_program_path(const std::string);
  59. bool valid;
  60. public:
  61. Gnuplot();
  62. // set a style during construction
  63. Gnuplot(const std::string &);
  64. // The equivilant of gnuplot_plot_once, the two forms
  65. // allow you to plot either (x,y) pairs or just a single
  66. // vector at one go
  67. Gnuplot(const std::string &, // title
  68. const std::string &, // style
  69. const std::string &, // xlabel
  70. const std::string &, // ylabel
  71. std::vector<double> , std::vector<double> );
  72. Gnuplot(const std::string &, //title
  73. const std::string &, //style
  74. const std::string &, //xlabel
  75. const std::string &, //ylabel
  76. std::vector<double> );
  77. ~Gnuplot();
  78. void checkSystemVariablesOpenGnuplotCommand();
  79. // send a command to gnuplot
  80. void cmd(const char*, ...);
  81. // set line style
  82. void set_style(const std::string &);
  83. // set name of eps file to plot to
  84. void setFileOutput(const std::string &terminal, const std::string &filename);
  85. // set y and x axis labels
  86. void set_ylabel(const std::string &);
  87. void set_xlabel(const std::string &);
  88. void set_zlabel(const std::string &);
  89. // set axis - ranges
  90. void set_xrange(const int iFrom, const int iTo);
  91. void set_yrange(const int iFrom, const int iTo);
  92. void set_zrange(const int iFrom, const int iTo);
  93. // set palette range
  94. void set_cbrange(const int iFrom, const int iTo);
  95. // plot a single vector
  96. void plot_x(std::vector<double> , const std::string & // title
  97. );
  98. // plot x,y pairs
  99. void plot_xy(std::vector<double> , std::vector<double> , const std::string & // title
  100. );
  101. // plot x,y pairs
  102. void plot_xy ( std::map<double, double> , const std::string & // title
  103. );
  104. // plot an equation of the form: y = ax + b
  105. // You supply a and b
  106. void plot_slope(double, // a
  107. double, // b
  108. const std::string & // title
  109. );
  110. // plot an equation supplied as a string
  111. void plot_equation(const std::string &, // equation
  112. const std::string & // title
  113. );
  114. // if multiple plots are present it will clear the plot area
  115. void reset_plot(void);
  116. bool is_valid(void);
  117. void plot_xyz(std::vector<double> , std::vector<double> , std::vector<double> ,
  118. const std::string &);
  119. void plot_image(unsigned char * ucPicBuf, int iWidth, int iHeight,
  120. const std::string &title);
  121. };
  122. } // namespace
  123. #endif