00001 #ifndef GNUPLOT_H 00002 #define GNUPLOT_H 00003 00004 #include <boost/numeric/ublas/matrix.hpp> 00005 #include <boost/numeric/ublas/vector.hpp> 00006 #include <cstdarg> 00007 #include <float.h> 00008 #include <iomanip> 00009 #include <sstream> 00010 #include <string> 00011 #include <vector> 00012 #include "image.h" 00013 #include "rgba.h" 00014 00015 namespace mimas { 00016 00017 class gnuplot: public object 00018 { 00019 public: 00021 gnuplot( image< rgba< unsigned char > > &_img, 00022 int _width, int _height, int _timeout = 3 ) throw (mimasexception); 00025 virtual ~gnuplot(void); 00027 void finish(void) throw (mimasexception); 00031 std::string getScript(void) const { return program.str(); } 00033 template< typename T > 00034 std::ostream &operator<<( const T &t ) { program << t; return program; } 00036 std::ostream &operator<<( std::ostream& (*__pf)( std::ostream&) ) 00037 { (*__pf)( program ); return program; } 00039 template< typename T > 00040 void plot( const boost::numeric::ublas::vector< T > &vec ); 00042 template< typename T > 00043 void plot( const boost::numeric::ublas::matrix< T > &mat ); 00049 template< typename T > 00050 void plot( const boost::numeric::ublas::matrix< T > &mat, 00051 int xcol, int ycol, 00052 const std::string &style = "points", 00053 int type=1, int size=1 ) throw (mimasexception); 00056 template< typename T> 00057 void plot_histogram(const std::vector<T> &vec, std::string title = ""); 00059 template<typename T> 00060 void plot(const std::vector<T> &vector, std::string title = ""); 00061 00063 template< typename T > 00064 void plotImageProfile( const image< T > &im ); 00066 template< typename T > 00067 void plotImageProfile2( const image< T > &im, std::string title = ""); 00069 void setMultiPlot(bool multiplot); 00071 void setLineTitle(const char *title, ...); 00073 void unsetLineTitle(void); 00077 template< typename T > 00078 void plotxy( const boost::numeric::ublas::matrix< T > &mat, 00079 int xcol, int ycol, ... ) throw (mimasexception); 00080 protected: 00082 static void alarmHandler( int signal ); 00084 image< rgba< unsigned char > > *img; 00086 int timeout; 00088 bool finished; 00090 static pid_t pid; 00092 int pipes[2]; 00094 int width; 00096 int height; 00098 std::ostringstream program; 00100 std::vector< std::string > lineTitles; 00101 }; 00102 00103 #include "gnuplot.tcc" 00104 00105 } 00106 00107 #endif