Homepage Demos Overview Downloads Tutorials Reference
Credits

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 */
00040 
00041 #ifndef GNUGRAPH_H
00042 #define GNUGRAPH_H
00043 
00044 
00045 /*!
00046   @file gnugraph.h
00047   @brief Header file for graphics definitions.
00048 */
00049 
00050 //! @brief RCS/CVS version.
00051 static const char header_gnugraph_rcsid[] = "$Id: gnugraph.h,v 1.1 2004/07/20 17:55:24 ejt Exp $";
00052 
00053 #if defined(__WIN32__) || defined(_WIN32) || defined(__NT__)  || defined(__CYGWIN__)      /* Windows 95/NT */
00054 
00055 #define GNUPLOT "wgnuplot.exe"
00056 #define STRICT
00057 #include <windows.h>
00058 
00059 #ifdef _MSC_VER 
00060 #define snprintf  _snprintf
00061 #endif
00062 
00063 #else // Unix 
00064 
00065 #define GNUPLOT "gnuplot"
00066 #include <sys/types.h>
00067 #include <unistd.h>
00068 #endif
00069 
00070 #include "robot.h"
00071 #include <sys/stat.h>
00072 
00073 #ifdef __WATCOMC__
00074 #include <strstrea.h>
00075 #else
00076 #include <sstream>
00077 #endif
00078 #include <vector>
00079 
00080 #ifdef use_namespace
00081 namespace ROBOOP {
00082   using namespace NEWMAT;
00083 #endif
00084 
00085 #define OUT_OF_MEMORY       -1
00086 #define X_Y_DATA_NO_MATCH   -2
00087 #define LABELS_NBR_NO_MATCH -3
00088 
00089 short set_plot2d(const char *title_graph, const char *x_axis_title, const char *y_axis_title,
00090                  const char *label, int type, const Matrix &xdata, const Matrix &ydata,
00091                  int start_y, int end_y);
00092 
00093 short set_plot2d(const char *title_graph, const char *x_axis_title, const char *y_axis_title,
00094                  const vector<char *>label, int type, const Matrix &xdata, const Matrix &ydata,
00095                  const vector<int> & data_select);
00096 
00097 
00098 //  interface class for gnuplot
00099 
00100 #define LINES       0
00101 #define POINTS      1
00102 #define LINESPOINTS 2
00103 #define IMPULSES    3
00104 #define DOTS        4
00105 #define STEPS       5
00106 #define BOXES       6
00107 
00108 #define NCURVESMAX  10  // maximum number of curves in the same Plot2d 
00109 
00110 class Plot2d;
00111 
00112 /*!
00113   @class GNUcurve
00114   @brief Object for one curve.
00115  */
00116 class GNUcurve {
00117    friend class Plot2d; //!< Plot2d need access to private data
00118    Matrix xy;           //!< n x 2 matrix defining the curve */
00119    string clabel;       //!< string defining the curve label for the legend
00120    int ctype;           //!< curve type: lines, points, linespoints, impulses,
00121                         //!< dots, steps, boxes
00122 public:
00123    GNUcurve(const Matrix & data, const string & label = "", int type = LINES);
00124    GNUcurve(void);
00125    GNUcurve(const GNUcurve & gnuc);
00126    GNUcurve & operator=(const GNUcurve & gnuc);
00127    void dump(void);
00128 };
00129 
00130 
00131 /*!
00132   @class Plot2d
00133   @brief 2d plot object.
00134 */
00135 class Plot2d {
00136    string 
00137      title,           //!< Graph title.
00138      xlabel,          //!< Graph x axis.
00139      ylabel;          //!< Graph y axis.
00140    string gnucommand; //!< GNU plot command.
00141    int ncurves;       //!< Number of curves.
00142    GNUcurve *curves;  //!< Pointer to GNUcurve object.
00143 public:
00144    Plot2d(void);
00145    ~Plot2d(void);
00146    void dump(void);
00147    void settitle(const string & t);
00148    void setxlabel(const string & t);
00149    void setylabel(const string & t);
00150    void addcurve(const Matrix & data, const string & label = "", int type = LINES);
00151    void gnuplot(void);
00152    void addcommand(const string & gcom);
00153 };
00154 
00155 #define IO_COULD_NOT_OPEN_FILE  -1
00156 #define IO_MISMATCH_SIZE        -2
00157 #define IO_DATA_EMPTY           -3
00158 #define IO_MISMATCH_ELEMENT_NBR -4
00159 #define PROBLEM_FILE_READING    -5
00160 
00161 
00162 /*!
00163   @class IO_matrix_file.
00164   @brief Read and write data at every iterations in a file.
00165 */
00166 class IO_matrix_file {
00167 public:
00168    IO_matrix_file(const string & filename);
00169    short write(const vector<Matrix> & data);
00170    short write(const vector<Matrix> & data, const vector<string> & title);
00171    short read(vector<Matrix> & data);
00172    short read(vector<Matrix> & data, vector<string> & title);
00173    short read_all(vector<Matrix> & data, vector<string> & data_title);
00174 private:
00175    int 
00176      position_read,       //!< Position to read the file.
00177      nb_iterations_write, //!< Number of iterations in writing mode.
00178      nb_iterations_read,  //!< Number of iterations in reading mode.
00179      nb_element;          //!< Number of elements to read or write.
00180    string filename;       //!< File name.
00181 };
00182 
00183 
00184 /*!
00185   @class Plot_file
00186   @brief Creates a graphic from a data file.
00187 */
00188 class Plot_file : public IO_matrix_file, Plot2d
00189 {
00190 public:
00191    Plot_file(const string & filename);
00192    short graph(const string & title_graph, const string & label, const short x,
00193                const short y, const short x_start, const short y_start,
00194                const short y_end);
00195 private:
00196    vector<Matrix> data_from_file;  //!< Data file.
00197    vector<string> data_title;      //!< Data file title.
00198 };
00199 
00200 #ifdef use_namespace
00201 }
00202 #endif
00203 
00204 #endif
00205 

ROBOOP v1.21a
Generated Tue Oct 19 14:18:25 2004 by Doxygen 1.3.9.1