gnugraph.h
Go to the documentation of this file.
1 /*
2 ROBOOP -- A robotics object oriented package in C++
3 Copyright (C) 1996-2004 Richard Gourdeau
4 
5 This library is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as
7 published by the Free Software Foundation; either version 2.1 of the
8 License, or (at your option) any later version.
9 
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
14 
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 
19 
20 Report problems and direct all questions to:
21 
22 Richard Gourdeau
23 Professeur Agrege
24 Departement de genie electrique
25 Ecole Polytechnique de Montreal
26 C.P. 6079, Succ. Centre-Ville
27 Montreal, Quebec, H3C 3A7
28 
29 email: richard.gourdeau@polymtl.ca
30 -------------------------------------------------------------------------------
31 Revision_history:
32 
33 2004/07/01: Etienne Lachance
34  -Added doxygen documentation.
35 
36 2004/07/01: Ethan Tira-Thompson
37  -Added support for newmat's use_namespace #define, using ROBOOP namespace
38 
39 2004/08/10: Etienne Lachance
40  -Added class Plot3d.
41  -Removed using ROBOOP namespace
42 -------------------------------------------------------------------------------
43 */
44 
45 #ifndef GNUGRAPH_H
46 #define GNUGRAPH_H
47 
48 
54 static const char header_gnugraph_rcsid[] = "$Id: gnugraph.h,v 1.13 2006/05/16 19:24:26 gourdeau Exp $";
56 
57 #ifdef _MSC_VER // Microsoft
58 #pragma warning (disable:4786) // Disable decorated name truncation warnings
59 #pragma warning (disable:4503) // Disable decorated name truncation warnings
60 #endif
61 
62 #if defined(__WIN32__) || defined(_WIN32) || defined(__NT__) || defined(__CYGWIN__) /* Windows 95/NT */
63 
64 #define GNUPLOT "wgnuplot.exe"
65 #define STRICT
66 #include <windows.h>
67 
68 #ifdef _MSC_VER
69 #define snprintf _snprintf
70 #endif
71 
72 #else // Unix
73 
74 #define GNUPLOT "gnuplot"
75 #include <sys/types.h>
76 #include <unistd.h>
77 #endif
78 
79 #include <stdio.h>
80 #include <stdexcept>
81 
82 #include <boost/shared_ptr.hpp>
83 
84 #define WANT_STRING /* include.h will get string fns */
85 #define WANT_STREAM /* include.h will get stream fns */
86 #define WANT_FSTREAM /* include.h will get fstream fns */
87 #define WANT_MATH /* include.h will get math fns */
88  /* newmatap.h will get include.h */
89 #include "newmatap.h" /* need matrix applications */
90 #include "newmatio.h" /* need matrix output routines */
91 
92 #ifdef use_namespace
93 using namespace NEWMAT;
94 #endif
95 
96 #include <sys/stat.h>
97 
98 #include <sstream>
99 #include <vector>
100 
101 
102 #define OUT_OF_MEMORY -1
103 #define X_Y_DATA_NO_MATCH -2
104 #define LABELS_NBR_NO_MATCH -3
105 
106 
107 
108 typedef enum {
116 } LineType_en;
117 
118 
119 #define NCURVESMAX 10 // maximum number of curves in the same Plot2d
120 
121 class Plot2d;
122 
127 class GNUcurve {
128 
129  public:
130  GNUcurve(const std::vector<double> & x, std::vector<double> & y,
131  const std::string & label = "", LineType_en enLineType = LINES);
132  GNUcurve(void);
133  void dump(void);
134 
135  std::vector<double> vdX;
136  std::vector<double> vdY;
137  std::string clabel;
139 };
140 
141 typedef boost::shared_ptr<GNUcurve> PSHR_Curve;
142 typedef std::vector<PSHR_Curve> VectorCurves;
143 
144 
149 class Plot2d {
150 public:
151  Plot2d(void);
152  void dump(void);
153  void settitle(const std::string & t);
154  void setxlabel(const std::string & t);
155  void setylabel(const std::string & t);
156  void addcurve(const Matrix & data, const std::string & label = "",
157  LineType_en enLineType = DATAPOINTS);
158  void gnuplot(void);
159  void addcommand(const std::string & gcom);
160 
161 private:
162  std::string title;
163  std::string xlabel;
164  std::string ylabel;
165  std::string gnucommand;
166 
168 };
169 
174 class Plot3d
175 {
176  std::string
177  title,
178  xlabel,
179  ylabel,
180  zlabel;
181 public:
182  Plot3d(){}
183  void settitle(const std::string & t);
184  void setxlabel(const std::string & t);
185  void setylabel(const std::string & t);
186  void setzlabel(const std::string & t);
187  void gnuplot(const Matrix & xyz);
188 };
189 
190 #define IO_COULD_NOT_OPEN_FILE -1
191 #define IO_MISMATCH_SIZE -2
192 #define IO_DATA_EMPTY -3
193 #define IO_MISMATCH_ELEMENT_NBR -4
194 #define PROBLEM_FILE_READING -5
195 
196 
202 public:
203  IO_matrix_file(const std::string & filename);
204  short write(const std::vector<Matrix> & data);
205  short write(const std::vector<Matrix> & data, const std::vector<std::string> & title);
206  short read(std::vector<Matrix> & data);
207  short read(std::vector<Matrix> & data, std::vector<std::string> & title);
208  short read_all(std::vector<Matrix> & data, std::vector<std::string> & data_title);
209 private:
210  int
212  nb_iterations_write,
213  nb_iterations_read,
214  nb_element;
215  std::string filename;
216 };
217 
218 
224 {
225 public:
226  Plot_file(const std::string & filename);
227  short graph(const std::string & title_graph, const std::string & label, const short x,
228  const short y, const short x_start, const short y_start,
229  const short y_end);
230 private:
231  std::vector<Matrix> data_from_file;
232  std::vector<std::string> data_title;
233 };
234 
235 
236 
237 short set_plot2d(const char *title_graph, const char *x_axis_title, const char *y_axis_title,
238  const char *label, LineType_en enLineType, const Matrix &xdata, const Matrix &ydata,
239  int start_y, int end_y);
240 
241 short set_plot2d(const char *title_graph, const char *x_axis_title, const char *y_axis_title,
242  const vector<char *> label, LineType_en enLineType, const Matrix &xdata,
243  const Matrix &ydata, const vector<int> & data_select);
244 
245 short set_plot3d(const Matrix & xyz, const std::string & title_graph, const std::string & x_axis_title,
246  const std::string & y_axis_title, const std::string & z_axis_title);
247 
248 
249 #endif
250 
std::string ylabel
Graph y axis.
Definition: gnugraph.h:164
std::vector< double > vdX
Definition: gnugraph.h:135
3d plot object.
Definition: gnugraph.h:174
static const char header_gnugraph_rcsid[]
RCS/CVS version.
Definition: gnugraph.h:55
std::string title
Graph title.
Definition: gnugraph.h:162
std::string clabel
string defining the curve label for the legend
Definition: gnugraph.h:137
std::string xlabel
Graph x axis.
Definition: gnugraph.h:163
std::vector< std::string > data_title
Data file title.
Definition: gnugraph.h:232
LineType_en enLineType
Line type.
Definition: gnugraph.h:138
Definition: gnugraph.h:113
Object for one curve.
Definition: gnugraph.h:127
std::vector< Matrix > data_from_file
Data file.
Definition: gnugraph.h:231
VectorCurves vCurves
Definition: gnugraph.h:167
std::vector< PSHR_Curve > VectorCurves
Definition: gnugraph.h:142
short set_plot2d(const char *title_graph, const char *x_axis_title, const char *y_axis_title, const char *label, LineType_en enLineType, const Matrix &xdata, const Matrix &ydata, int start_y, int end_y)
Definition: gnugraph.cpp:793
The usual rectangular matrix.
Definition: newmat.h:625
Read and write data at every iterations in a file.
Definition: gnugraph.h:201
std::string zlabel
Graph z axis.
Definition: gnugraph.h:177
2d plot object.
Definition: gnugraph.h:149
int position_read
Position to read the file.
Definition: gnugraph.h:211
Plot3d()
Default constructor.
Definition: gnugraph.h:182
std::vector< double > vdY
Definition: gnugraph.h:136
LineType_en
Definition: gnugraph.h:108
std::string gnucommand
GNU plot command.
Definition: gnugraph.h:165
short set_plot3d(const Matrix &xyz, const std::string &title_graph, const std::string &x_axis_title, const std::string &y_axis_title, const std::string &z_axis_title)
Creates a graphic from a data file.
Definition: gnugraph.h:223
boost::shared_ptr< GNUcurve > PSHR_Curve
Definition: gnugraph.h:141
std::string filename
File name.
Definition: gnugraph.h:215


kni
Author(s): Martin Günther
autogenerated on Fri Jan 3 2020 04:01:16