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

ROBOOP v1.21a
Generated Thu Nov 22 00:51:28 2007 by Doxygen 1.5.4