Hermes2D  2.0
graph.h
1 // This file is part of Hermes2D.
2 //
3 // Hermes2D is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, either version 2 of the License, or
6 // (at your option) any later version.
7 //
8 // Hermes2D is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with Hermes2D. If not, see <http://www.gnu.org/licenses/>.
15 
16 #ifndef __H2D_GRAPH_H
17 #define __H2D_GRAPH_H
18 
19 #include "global.h"
20 namespace Hermes
21 {
22  namespace Hermes2D
23  {
32  class HERMES_API Graph : public Hermes::Mixins::Loggable
33  {
34  public:
35 
36  Graph(const char* title = NULL, const char* x_axis_name = NULL, const char* y_axis_name = NULL);
37 
38  void set_captions(const char* title = NULL, const char* x_axis_name = NULL, const char* y_axis_name = NULL);
39 
40  void set_log_x(bool log = true);
41  void set_log_y(bool log = true);
42 
43  void show_legend(bool show = true);
44  void show_grid(bool show = true);
45 
46  int add_row(const char* name = NULL, const char* color = "k", const char* line = "-", const char* marker = "");
47  void set_row_style(int row, const char* color = "k", const char* line = "-", const char* marker = "");
48 
49  void add_values(int row, double x, double y);
50  void add_values(double x, double y); // same as previous but uses row = 0
51  void add_values(int row, int n, double* x, double* y);
52  void add_values(int row, int n, double2* xy);
53 
54  virtual void save(const char* filename) = 0;
55  void save_numbered(const char* filename, int number);
56 
57  protected:
58 
59  std::string title, xname, yname;
60  bool logx, logy, legend, grid;
61 
62  struct Values
63  {
64  double x, y;
65  };
66 
67  struct Row
68  {
69  std::string name, color, line, marker;
70  Hermes::vector<Values> data;
71  };
72 
73  Hermes::vector<Row> rows;
74  };
75 
78  class HERMES_API SimpleGraph : public Graph
79  {
80  public:
81 
82  SimpleGraph(const char* title = NULL, const char* x_axis_name = NULL, const char* y_axis_name = NULL)
83  : Graph(title, x_axis_name, y_axis_name) {}
84 
85  virtual void save(const char* filename);
86  };
87 
90  class HERMES_API MatlabGraph : public Graph
91  {
92  public:
93 
94  MatlabGraph(const char* title = NULL, const char* x_axis_name = NULL, const char* y_axis_name = NULL)
95  : Graph(title, x_axis_name, y_axis_name) {}
96 
97  virtual void save(const char* filename);
98  };
99 
102 
103  static const char* default_terminal = "set terminal postscript eps enhanced\n";
104 
105  class HERMES_API GnuplotGraph : public Graph
106  {
107  public:
108 
109  GnuplotGraph(const char* title = NULL, const char* x_axis_name = NULL, const
110  char* y_axis_name = NULL, double lines_width = 1.0, const
111  std::string& terminal_str = default_terminal) :
112  Graph(title, x_axis_name, y_axis_name),
113  legend_pos(),
114  terminal_str(terminal_str),
115  lw(lines_width) {
116  }
117 
118  virtual void save(const char* filename);
119 
122  void set_legend_pos(const char* posspec);
123 
124  protected:
129 
133 
136  double lw;
137  };
138 
141  class HERMES_API PNGGraph : public GnuplotGraph
142  {
143  public:
144 
145  PNGGraph(const char* title = NULL, const char* x_axis_name = NULL, const char* y_axis_name = NULL,
146  double lines_width = 1.0, double plot_width = 800, double plot_height = 600);
147  };
148  }
149 }
150 #endif