• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

external_src/gnu_wrapper/gnuplot_i.hpp

Go to the documentation of this file.
00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 // original source http://code.google.com/p/gnuplot-cpp/
00030 
00031 #ifndef _GNUPLOT_PIPES_H_
00032 #define _GNUPLOT_PIPES_H_
00033 
00034 
00035 #include <iostream>
00036 #include <string>
00037 #include <vector>
00038 #include <fstream>  
00039 #include <sstream>              // for std::ostringstream
00040 #include <stdexcept> 
00041 #include <cstdio>     
00042 #include <cstdlib>              // for getenv()
00043 #include <list>                 // for std::list
00044 
00045 
00046 #if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__TOS_WIN__) 
00047 //defined for 32 and 64-bit environments
00048  #include <io.h>                // for _access(), _mktemp()
00049  #define GP_MAX_TMP_FILES  27   // 27 temporary files it's Microsoft restriction
00050 #elif defined(unix) || defined(__unix) || defined(__unix__) || defined(__APPLE__) 
00051 //all UNIX-like OSs (Linux, *BSD, MacOSX, Solaris, ...)
00052  #include <unistd.h>            // for access(), mkstemp()
00053  #define GP_MAX_TMP_FILES  64
00054 #else
00055  #error unsupported or unknown operating system
00056 #endif
00057 
00058 //declare classes in global namespace
00059 
00060 namespace gnuplot
00061 {
00062 
00063 
00064 
00065 class GnuplotException : public std::runtime_error
00066 {
00067     public:
00068         GnuplotException(const std::string &msg) : std::runtime_error(msg){}
00069 };
00070 
00071 
00072 
00073 class Gnuplot
00074 {
00075     private:
00076 
00077     //----------------------------------------------------------------------------------
00078     // member data
00080         FILE                    *gnucmd; 
00082         bool                     valid;  
00084         bool                     two_dim;  
00086         int                      nplots;  
00088         std::string              pstyle;  
00090         std::string              smooth;    
00092         std::vector<std::string> tmpfile_list; 
00093 
00094     //----------------------------------------------------------------------------------
00095     // static data
00097         static int               tmpfile_num;   
00099         static std::string       m_sGNUPlotFileName; 
00101         static std::string       m_sGNUPlotPath;
00103         static std::string       terminal_std;       
00104 
00105     //----------------------------------------------------------------------------------
00106     // member functions (auxiliary functions)
00107         // ---------------------------------------------------
00113         // ---------------------------------------------------
00114         void           init(); 
00115         // ---------------------------------------------------
00121         // ---------------------------------------------------                          
00122         std::string    create_tmpfile(std::ofstream &tmp);  
00123 
00124     //----------------------------------------------------------------------------------
00130         // ---------------------------------------------------------------------------------
00131     static bool    get_program_path(); 
00132         
00133         // ---------------------------------------------------------------------------------
00140         // ---------------------------------------------------------------------------------                                  
00141     bool file_available(const std::string &filename);
00142       
00143         // ---------------------------------------------------------------------------------
00150         // ---------------------------------------------------------------------------------                                  
00151     static bool    file_exists(const std::string &filename, int mode=0); 
00152 
00153     public:
00154 
00155                 // ----------------------------------------------------------------------------
00162                 // ----------------------------------------------------------------------------
00163         static bool set_GNUPlotPath(const std::string &path);
00164 
00165 
00166                 // ----------------------------------------------------------------------------
00173                 // ----------------------------------------------------------------------------
00174         static void set_terminal_std(const std::string &type);
00175 
00176         //-----------------------------------------------------------------------------
00177         // constructors
00178                 // ----------------------------------------------------------------------------
00179 
00180 
00182         Gnuplot(const std::string &style = "points");
00183 
00185         Gnuplot(const std::vector<float> &x,
00186                 const std::string &title = "",
00187                 const std::string &style = "points",
00188                 const std::string &labelx = "x",
00189                 const std::string &labely = "y");
00190 
00192         Gnuplot(const std::vector<float> &x,
00193                 const std::vector<float> &y,
00194                 const std::string &title = "",
00195                 const std::string &style = "points",
00196                 const std::string &labelx = "x",
00197                 const std::string &labely = "y");
00198 
00200         Gnuplot(const std::vector<float> &x,
00201                 const std::vector<float> &y,
00202                 const std::vector<float> &z,
00203                 const std::string &title = "",
00204                 const std::string &style = "points",
00205                 const std::string &labelx = "x",
00206                 const std::string &labely = "y",
00207                 const std::string &labelz = "z");
00208 
00210         ~Gnuplot();
00211 
00212 
00213     //----------------------------------------------------------------------------------
00214 
00216         Gnuplot& cmd(const std::string &cmdstr);
00217         // -------------------------------------------------------------------------
00224         // -------------------------------------------------------------------------
00225     inline Gnuplot& operator<<(const std::string &cmdstr){
00226         cmd(cmdstr);
00227         return(*this);
00228     }
00229 
00230 
00231 
00232     //--------------------------------------------------------------------------
00233     // show on screen or write to file
00234 
00236     Gnuplot& showonscreen(); // window output is set by default (win/x11/aqua)
00237 
00239     Gnuplot& savetofigure(const std::string filename, 
00240             const std::string terminal="ps");
00241 
00242     //--------------------------------------------------------------------------
00243     // set and unset
00244 
00248     Gnuplot& set_style(const std::string &stylestr = "points");
00249 
00254     Gnuplot& set_smooth(const std::string &stylestr = "csplines");
00255 
00256     // ----------------------------------------------------------------------
00263     // ----------------------------------------------------------------------
00264     inline Gnuplot& unset_smooth(){ smooth = ""; return *this;}; 
00265 
00266 
00268     Gnuplot& set_pointsize(const float pointsize = 1.0);
00269 
00271     inline Gnuplot& set_grid()  {cmd("set grid");return *this;};
00273     inline Gnuplot& unset_grid(){cmd("unset grid");return *this;}; 
00274 
00275     // -----------------------------------------------
00281     // -----------------------------------------------
00282     inline Gnuplot& set_multiplot(){cmd("set multiplot") ;return *this;};
00283 
00284     // -----------------------------------------------
00290     // -----------------------------------------------
00291     inline Gnuplot& unset_multiplot(){cmd("unset multiplot");return *this;};
00292     
00293 
00294 
00296     Gnuplot& set_samples(const int samples = 100);
00298     Gnuplot& set_isosamples(const int isolines = 10);
00299 
00300     // --------------------------------------------------------------------------
00306     // --------------------------------------------------------------------------
00307     Gnuplot& set_hidden3d(){cmd("set hidden3d");return *this;};
00308 
00309     // ---------------------------------------------------------------------------
00315     // ---------------------------------------------------------------------------
00316     inline Gnuplot& unset_hidden3d(){cmd("unset hidden3d"); return *this;}; 
00317 
00320     Gnuplot& set_contour(const std::string &position = "base");
00321     // --------------------------------------------------------------------------
00327     // ------------------------------------------------------------------
00328     inline Gnuplot& unset_contour(){cmd("unset contour");return *this;};
00329 
00330     // ------------------------------------------------------------
00336     // ------------------------------------------------------------------
00337     inline Gnuplot& set_surface(){cmd("set surface");return *this;}; 
00338 
00339     // ----------------------------------------------------------
00346     // ------------------------------------------------------------------
00347     inline Gnuplot& unset_surface(){cmd("unset surface"); return *this;}
00348 
00349 
00352     Gnuplot& set_legend(const std::string &position = "default"); 
00353 
00354     // ------------------------------------------------------------------
00361     // ------------------------------------------------------------------
00362     inline Gnuplot& unset_legend(){cmd("unset key"); return *this;}
00363 
00364     // ----------------------------------------------------------------------- 
00370     // ----------------------------------------------------------------------- 
00371     inline Gnuplot& set_title(const std::string &title = "")
00372     {
00373         std::string cmdstr;
00374         cmdstr = "set title \"";
00375         cmdstr+=title;
00376         cmdstr+="\"";
00377         *this<<cmdstr;
00378         return *this;
00379     }
00380 
00381     //----------------------------------------------------------------------------------
00388     // ---------------------------------------------------------------------------------
00389     inline Gnuplot& unset_title(){this->set_title();return *this;}
00390 
00391 
00393     Gnuplot& set_ylabel(const std::string &label = "x");
00395     Gnuplot& set_xlabel(const std::string &label = "y");
00397     Gnuplot& set_zlabel(const std::string &label = "z");
00398 
00400     Gnuplot& set_xrange(const float iFrom,
00401                         const float iTo);
00403     Gnuplot& set_yrange(const float iFrom,
00404                         const float iTo);
00406     Gnuplot& set_zrange(const float iFrom,
00407                         const float iTo);
00413     // -----------------------------------------------
00414     inline Gnuplot& set_xautoscale(){cmd("set xrange restore");cmd("set autoscale x");return *this;};
00415 
00416     // -----------------------------------------------
00422     // -----------------------------------------------
00423     inline Gnuplot& set_yautoscale(){cmd("set yrange restore");cmd("set autoscale y");return *this;};
00424 
00425     // -----------------------------------------------
00431     // -----------------------------------------------
00432     inline Gnuplot& set_zautoscale(){cmd("set zrange restore");cmd("set autoscale z");return *this;};
00433 
00434 
00436     Gnuplot& set_xlogscale(const float base = 10);
00438     Gnuplot& set_ylogscale(const float base = 10);
00440     Gnuplot& set_zlogscale(const float base = 10);
00441 
00442     // ----------------------------------------------- 
00448     // -----------------------------------------------  
00449     inline Gnuplot& unset_xlogscale(){cmd("unset logscale x"); return *this;};
00450 
00451     // ----------------------------------------------- 
00457     // -----------------------------------------------  
00458     inline Gnuplot& unset_ylogscale(){cmd("unset logscale y"); return *this;};
00459 
00460     // ----------------------------------------------- 
00466     // -----------------------------------------------          
00467     inline Gnuplot& unset_zlogscale(){cmd("unset logscale z"); return *this;};
00468 
00469 
00471     Gnuplot& set_cbrange(const float iFrom, const float iTo);
00472 
00473 
00474     //--------------------------------------------------------------------------
00475     // plot
00476 
00479     Gnuplot& plotfile_x(const std::string &filename,
00480                         const unsigned int column = 1,
00481                         const std::string &title = "");
00483     template<typename X>
00484     Gnuplot& plot_x(const X& x, const std::string &title = "");
00485 
00486 
00489     Gnuplot& plotfile_xy(const std::string &filename,
00490                          const unsigned int column_x = 1,
00491                          const unsigned int column_y = 2,
00492                          const std::string &title = "");
00494     template<typename X, typename Y>
00495     Gnuplot& plot_xy(const X& x, const Y& y, const std::string &title = "");
00496 
00497 
00500     Gnuplot& plotfile_xy_err(const std::string &filename,
00501                              const unsigned int column_x  = 1,
00502                              const unsigned int column_y  = 2,
00503                              const unsigned int column_dy = 3,
00504                              const std::string &title = "");
00506     template<typename X, typename Y, typename E>
00507     Gnuplot& plot_xy_err(const X &x, const Y &y, const E &dy,
00508                          const std::string &title = "");
00509 
00510 
00513     Gnuplot& plotfile_xyz(const std::string &filename,
00514                           const unsigned int column_x = 1,
00515                           const unsigned int column_y = 2,
00516                           const unsigned int column_z = 3,
00517                           const std::string &title = "");
00519     template<typename X, typename Y, typename Z>
00520     Gnuplot& plot_xyz(const X &x,
00521                       const Y &y,
00522                       const Z &z,
00523                       const std::string &title = "");
00524 
00525 
00526 
00528     Gnuplot& plot_slope(const float a,
00529                         const float b,
00530                         const std::string &title = "");
00531 
00532 
00546     Gnuplot& plot_equation(const std::string &equation,
00547                            const std::string &title = "");
00548 
00551     Gnuplot& plot_equation3d(const std::string &equation,
00552                              const std::string &title = "");
00553 
00554 
00556     Gnuplot& plot_image(const unsigned char *ucPicBuf,
00557                         const unsigned int iWidth,
00558                         const unsigned int iHeight,
00559                         const std::string &title = "");
00560 
00561 
00562     //--------------------------------------------------------------------------
00566     //   savetofigure)
00571     //--------------------------------------------------------------------------
00572     inline Gnuplot& replot(void){if (nplots > 0) cmd("replot");return *this;};
00573 
00575     Gnuplot& reset_plot();
00576 
00578     Gnuplot& reset_all();
00579 
00581     void remove_tmpfiles();
00582 
00583     // -------------------------------------------------------------------
00590     // ------------------------------------------------------------------- 
00591     inline bool is_valid(){return(valid);};
00592 
00593 };
00594 
00595 void wait_for_key();
00596 }
00597 
00598 #endif

Generated on Tue Sep 7 2010 21:03:27 for Particle Identification and Tracking by  doxygen 1.7.1