Gnuplot.h 3.5 KB

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