gnugraph.h
Go to the documentation of this file.
00001 /*
00002 ROBOOP -- A robotics object oriented package in C++
00003 Copyright (C) 1996-2004  Richard Gourdeau
00004 
00005 This library is free software; you can redistribute it and/or modify
00006 it under the terms of the GNU Lesser General Public License as
00007 published by the Free Software Foundation; either version 2.1 of the
00008 License, or (at your option) any later version.
00009 
00010 This library is distributed in the hope that it will be useful,
00011 but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 GNU Lesser General Public License for more details.
00014 
00015 You should have received a copy of the GNU Lesser General Public
00016 License along with this library; if not, write to the Free Software
00017 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 
00019 
00020 Report problems and direct all questions to:
00021 
00022 Richard Gourdeau
00023 Professeur Agrege
00024 Departement de genie electrique
00025 Ecole Polytechnique de Montreal
00026 C.P. 6079, Succ. Centre-Ville
00027 Montreal, Quebec, H3C 3A7
00028 
00029 email: richard.gourdeau@polymtl.ca
00030 -------------------------------------------------------------------------------
00031 Revision_history:
00032 
00033 2004/07/01: Etienne Lachance
00034    -Added doxygen documentation.
00035 
00036 2004/07/01: Ethan Tira-Thompson
00037     -Added support for newmat's use_namespace #define, using ROBOOP namespace
00038 
00039 2004/08/10: Etienne Lachance
00040     -Added class Plot3d.
00041     -Removed using ROBOOP namespace
00042 -------------------------------------------------------------------------------
00043 */
00044 
00045 #ifndef GNUGRAPH_H
00046 #define GNUGRAPH_H
00047 
00048 
00054 
00055 static const char header_gnugraph_rcsid[] = "$Id: gnugraph.h,v 1.13 2006/05/16 19:24:26 gourdeau Exp $";
00056 
00057 #ifdef _MSC_VER                  // Microsoft
00058 #pragma warning (disable:4786)  // Disable decorated name truncation warnings 
00059 #pragma warning (disable:4503)  // Disable decorated name truncation warnings 
00060 #endif
00061 
00062 #if defined(__WIN32__) || defined(_WIN32) || defined(__NT__)  || defined(__CYGWIN__)      /* Windows 95/NT */
00063 
00064 #define GNUPLOT "wgnuplot.exe"
00065 #define STRICT
00066 #include <windows.h>
00067 
00068 #ifdef _MSC_VER 
00069 #define snprintf        _snprintf
00070 #endif
00071 
00072 #else // Unix 
00073 
00074 #define GNUPLOT "gnuplot"
00075 #include <sys/types.h>
00076 #include <unistd.h>
00077 #endif
00078 
00079 #include <stdio.h>
00080 #include <stdexcept>
00081 
00082 #include <boost/shared_ptr.hpp>
00083 
00084 #define WANT_STRING                  /* include.h will get string fns */
00085 #define WANT_STREAM                  /* include.h will get stream fns */
00086 #define WANT_FSTREAM                 /* include.h will get fstream fns */
00087 #define WANT_MATH                    /* include.h will get math fns */
00088                                      /* newmatap.h will get include.h */
00089 #include "newmatap.h"                /* need matrix applications */
00090 #include "newmatio.h"                /* need matrix output routines */
00091 
00092 #ifdef use_namespace
00093 using namespace NEWMAT;
00094 #endif
00095 
00096 #include <sys/stat.h>
00097 
00098 #include <sstream>
00099 #include <vector>
00100 
00101 
00102 #define OUT_OF_MEMORY       -1
00103 #define X_Y_DATA_NO_MATCH   -2
00104 #define LABELS_NBR_NO_MATCH -3
00105 
00106 
00107 
00108 typedef enum {
00109     LINES,
00110     DATAPOINTS,
00111     LINESPOINTS,
00112     IMPULSES,
00113     DOTS,
00114     STEPS,
00115     BOXES
00116 } LineType_en;
00117 
00118 
00119 #define NCURVESMAX  10  // maximum number of curves in the same Plot2d 
00120 
00121 class Plot2d;
00122 
00127 class GNUcurve {
00128 
00129   public:
00130     GNUcurve(const std::vector<double> & x, std::vector<double> & y, 
00131              const std::string & label = "", LineType_en enLineType = LINES);
00132     GNUcurve(void);
00133     void dump(void);
00134 
00135     std::vector<double> vdX;
00136     std::vector<double> vdY;
00137     std::string clabel;       
00138     LineType_en enLineType;    
00139 };
00140 
00141 typedef boost::shared_ptr<GNUcurve> PSHR_Curve;
00142 typedef std::vector<PSHR_Curve> VectorCurves;
00143 
00144 
00149 class Plot2d {
00150 public:
00151    Plot2d(void);
00152    void dump(void);
00153    void settitle(const std::string & t);
00154    void setxlabel(const std::string & t);
00155    void setylabel(const std::string & t);
00156    void addcurve(const Matrix & data, const std::string & label = "", 
00157                  LineType_en enLineType = DATAPOINTS);
00158    void gnuplot(void);
00159    void addcommand(const std::string & gcom);
00160 
00161 private:
00162    std::string  title;        
00163    std::string  xlabel;       
00164    std::string  ylabel;       
00165    std::string  gnucommand;   
00166 
00167    VectorCurves vCurves;
00168 };
00169 
00174 class Plot3d 
00175 {
00176    std::string 
00177      title,              
00178      xlabel,             
00179      ylabel,             
00180      zlabel;             
00181 public:
00182    Plot3d(){}            
00183    void settitle(const std::string & t);
00184    void setxlabel(const std::string & t);
00185    void setylabel(const std::string & t);
00186    void setzlabel(const std::string & t);
00187    void gnuplot(const Matrix & xyz);
00188 };
00189 
00190 #define IO_COULD_NOT_OPEN_FILE  -1
00191 #define IO_MISMATCH_SIZE        -2
00192 #define IO_DATA_EMPTY           -3
00193 #define IO_MISMATCH_ELEMENT_NBR -4
00194 #define PROBLEM_FILE_READING    -5
00195 
00196 
00201 class IO_matrix_file {
00202 public:
00203    IO_matrix_file(const std::string & filename);
00204    short write(const std::vector<Matrix> & data);
00205    short write(const std::vector<Matrix> & data, const std::vector<std::string> & title);
00206    short read(std::vector<Matrix> & data);
00207    short read(std::vector<Matrix> & data, std::vector<std::string> & title);
00208    short read_all(std::vector<Matrix> & data, std::vector<std::string> & data_title);
00209 private:
00210    int 
00211      position_read,       
00212      nb_iterations_write, 
00213      nb_iterations_read,  
00214      nb_element;          
00215    std::string filename;       
00216 };
00217 
00218 
00223 class Plot_file : public IO_matrix_file, Plot2d
00224 {
00225 public:
00226    Plot_file(const std::string & filename);
00227    short graph(const std::string & title_graph, const std::string & label, const short x,
00228                const short y, const short x_start, const short y_start,
00229                const short y_end);
00230 private:
00231    std::vector<Matrix> data_from_file;  
00232    std::vector<std::string> data_title;      
00233 };
00234 
00235 
00236 
00237 short set_plot2d(const char *title_graph, const char *x_axis_title, const char *y_axis_title,
00238                  const char *label, LineType_en enLineType, const Matrix &xdata, const Matrix &ydata,
00239                  int start_y, int end_y);
00240 
00241 short set_plot2d(const char *title_graph, const char *x_axis_title, const char *y_axis_title,
00242                  const vector<char *> label, LineType_en enLineType, const Matrix &xdata, 
00243                  const Matrix &ydata, const vector<int> & data_select);
00244 
00245 short set_plot3d(const Matrix & xyz, const std::string & title_graph, const std::string & x_axis_title, 
00246                  const std::string & y_axis_title, const std::string & z_axis_title);
00247 
00248 
00249 #endif
00250 


kni
Author(s): Martin Günther
autogenerated on Mon Aug 14 2017 02:44:12