C++ Mathematical Expression Toolkit (ExprTk) release
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | Private Attributes | List of all members
exprtk_gnuplot_fx Class Reference

Public Member Functions

 exprtk_gnuplot_fx ()
 
exprtk_gnuplot_fxset_title (const std::string &title)
 
exprtk_gnuplot_fxset_domain (const double min_x, const double max_x)
 
exprtk_gnuplot_fxset_expression (const std::string &expression)
 
bool plot ()
 
bool plot ()
 
exprtk_gnuplot_fxadd_curve (const exprtk_fx_curve &curve)
 

Private Member Functions

bool generate_gp_script ()
 
bool generate_data ()
 
bool generate_gp_script ()
 
bool generate_data (const std::size_t index, exprtk_fx_curve &curve)
 

Private Attributes

std::string title_
 
std::string expression_
 
double min_x_
 
double max_x_
 
double min_y_
 
double max_y_
 
std::deque< exprtk_fx_curvecurve_list_
 

Detailed Description

Definition at line 29 of file exprtk_gnuplot.cpp.

Constructor & Destructor Documentation

◆ exprtk_gnuplot_fx()

exprtk_gnuplot_fx::exprtk_gnuplot_fx ( )
inline

Definition at line 33 of file exprtk_gnuplot.cpp.

34 : min_x_(0.0)
35 , max_x_(0.0)
36 , min_y_(0.0)
37 , max_y_(0.0)
38 {}

Member Function Documentation

◆ add_curve()

exprtk_gnuplot_fx & exprtk_gnuplot_fx::add_curve ( const exprtk_fx_curve curve)
inline

Definition at line 81 of file exprtk_gnuplot_multi.cpp.

82 {
83 curve_list_.push_back(curve);
84 return *this;
85 }
std::deque< exprtk_fx_curve > curve_list_

References curve_list_.

Referenced by main().

Here is the caller graph for this function:

◆ generate_data() [1/2]

bool exprtk_gnuplot_fx::generate_data ( )
inlineprivate

Definition at line 89 of file exprtk_gnuplot.cpp.

90 {
91 typedef exprtk::symbol_table<double> symbol_table_t;
92 typedef exprtk::expression<double> expression_t;
93 typedef exprtk::parser<double> parser_t;
94
95 double x = 0.0;
96
97 symbol_table_t symbol_table;
98 symbol_table.add_constants();
99 symbol_table.add_variable("x",x);
100
101 expression_t expression;
102 expression.register_symbol_table(symbol_table);
103
104 parser_t parser;
105
106 if (!parser.compile(expression_,expression))
107 {
108 return false;
109 }
110
111 std::ofstream stream("data.dat");
112
113 if (!stream)
114 {
115 return false;
116 }
117
118 min_y_ = +std::numeric_limits<double>::max();
119 max_y_ = -std::numeric_limits<double>::max();
120
121 stream << std::setprecision(10);
122
123 const double increment = std::min(0.00005,std::abs(max_x_ - min_x_) / 1000.0);
124
125 for (x = min_x_; x <= max_x_; x += increment)
126 {
127 const double y = expression.value();
128
129 if (y < min_y_) min_y_ = y;
130 else if (y > max_y_) max_y_ = y;
131
132 stream << x << "\t" << y << "\n";
133 }
134
135 const double diff_y = std::abs(max_y_ - min_y_);
136 const double perc7_5 = diff_y * 0.075; //7.5%
137
138 min_y_ -= perc7_5;
139 max_y_ += perc7_5;
140
141 return true;
142 }

References expression_, max_x_, max_y_, min_x_, and min_y_.

Referenced by plot().

Here is the caller graph for this function:

◆ generate_data() [2/2]

bool exprtk_gnuplot_fx::generate_data ( const std::size_t  index,
exprtk_fx_curve curve 
)
inlineprivate

Definition at line 130 of file exprtk_gnuplot_multi.cpp.

131 {
132 typedef exprtk::symbol_table<double> symbol_table_t;
133 typedef exprtk::expression<double> expression_t;
134 typedef exprtk::parser<double> parser_t;
135
136 double x = 0.0;
137
138 symbol_table_t symbol_table;
139 symbol_table.add_constants();
140 symbol_table.add_variable("x",x);
141
142 expression_t expression;
143 expression.register_symbol_table(symbol_table);
144
145 parser_t parser;
146
147 if (!parser.compile(curve.expression_,expression))
148 {
149 return false;
150 }
151
152 const std::string file_name = std::string("data.dat") + (char)('0' + index);
153
154 std::ofstream stream(file_name.c_str());
155
156 if (!stream)
157 {
158 return false;
159 }
160
161 curve.min_y_ = +std::numeric_limits<double>::max();
162 curve.max_y_ = -std::numeric_limits<double>::max();
163
164 stream << std::setprecision(10);
165
166 const double increment = std::min(0.00005,std::abs(curve.max_x_ - curve.min_x_) / 1000.0);
167
168 for (x = curve.min_x_; x <= curve.max_x_; x += increment)
169 {
170 const double y = expression.value();
171
172 if (y < curve.min_y_) curve.min_y_ = y;
173 else if (y > curve.max_y_) curve.max_y_ = y;
174
175 stream << x << "\t" << y << "\n";
176 }
177
178 const double diff_y = std::abs(curve.max_y_ - curve.min_y_);
179 const double perc7_5 = diff_y * 0.075; //7.5%
180
181 curve.min_y_ -= perc7_5;
182 curve.max_y_ += perc7_5;
183
184 return true;
185 }

References exprtk_fx_curve::expression_, exprtk_fx_curve::max_x_, exprtk_fx_curve::max_y_, exprtk_fx_curve::min_x_, and exprtk_fx_curve::min_y_.

◆ generate_gp_script() [1/2]

bool exprtk_gnuplot_fx::generate_gp_script ( )
inlineprivate

Definition at line 69 of file exprtk_gnuplot.cpp.

70 {
71 std::ofstream stream("plot.gp");
72
73 if (!stream)
74 {
75 return false;
76 }
77
78 stream << "set term png\n";
79 stream << "set output 'plot.png'\n";
80 stream << "set xrange[" << min_x_ << ":" << max_x_ <<"]\n";
81 stream << "set yrange[" << min_y_ << ":" << max_y_ <<"]\n";
82 stream << "set xzeroaxis\n";
83 stream << "set yzeroaxis\n";
84 stream << "plot 'data.dat' using 1:2:(1.0) smooth unique title '" << title_ <<"'\n";
85
86 return true;
87 }

References max_x_, max_y_, min_x_, min_y_, and title_.

Referenced by plot().

Here is the caller graph for this function:

◆ generate_gp_script() [2/2]

bool exprtk_gnuplot_fx::generate_gp_script ( )
inlineprivate

Definition at line 89 of file exprtk_gnuplot_multi.cpp.

90 {
91 std::ofstream stream("plot.gp");
92
93 if (!stream)
94 {
95 return false;
96 }
97
98 double min_x = +std::numeric_limits<double>::max();
99 double max_x = -std::numeric_limits<double>::max();
100 double min_y = +std::numeric_limits<double>::max();
101 double max_y = -std::numeric_limits<double>::max();
102
103 for (std::size_t i = 0; i < curve_list_.size(); ++i)
104 {
105 exprtk_fx_curve& curve = curve_list_[i];
106
107 if (curve.min_x_ < min_x) min_x = curve.min_x_;
108 if (curve.max_x_ > max_x) max_x = curve.max_x_;
109 if (curve.min_y_ < min_y) min_y = curve.min_y_;
110 if (curve.max_y_ > max_y) max_y = curve.max_y_;
111 }
112
113 stream << "set term png\n";
114 stream << "set output 'plot.png'\n";
115 stream << "set xrange[" << min_x << ":" << max_x <<"]\n";
116 stream << "set yrange[" << min_y << ":" << max_y <<"]\n";
117 stream << "set xzeroaxis\n";
118 stream << "set yzeroaxis\n";
119 stream << "plot \\\n";
120
121 for (std::size_t i = 0; i < curve_list_.size(); ++i)
122 {
123 stream << "'data.dat" << i << "' using 1:2:(1.0) smooth unique title '" << curve_list_[i].title_;
124 stream << (((i + 1) < curve_list_.size()) ? "',\\\n" : "'\n");
125 }
126
127 return true;
128 }

References curve_list_, exprtk_fx_curve::max_x_, exprtk_fx_curve::max_y_, exprtk_fx_curve::min_x_, and exprtk_fx_curve::min_y_.

◆ plot() [1/2]

bool exprtk_gnuplot_fx::plot ( )
inline

Definition at line 59 of file exprtk_gnuplot.cpp.

60 {
61 if (!generate_data())
62 return false;
63 else
64 return generate_gp_script();
65 }

References generate_data(), and generate_gp_script().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ plot() [2/2]

bool exprtk_gnuplot_fx::plot ( )
inline

Definition at line 70 of file exprtk_gnuplot_multi.cpp.

71 {
72 for (std::size_t i = 0; i < curve_list_.size(); ++i)
73 {
74 if (!generate_data(i,curve_list_[i]))
75 return false;
76 }
77
78 return generate_gp_script();
79 }

References curve_list_, generate_data(), and generate_gp_script().

Here is the call graph for this function:

◆ set_domain()

exprtk_gnuplot_fx & exprtk_gnuplot_fx::set_domain ( const double  min_x,
const double  max_x 
)
inline

Definition at line 46 of file exprtk_gnuplot.cpp.

47 {
48 min_x_ = min_x;
49 max_x_ = max_x;
50 return *this;
51 }

References max_x_, and min_x_.

Referenced by main().

Here is the caller graph for this function:

◆ set_expression()

exprtk_gnuplot_fx & exprtk_gnuplot_fx::set_expression ( const std::string &  expression)
inline

Definition at line 53 of file exprtk_gnuplot.cpp.

54 {
55 expression_ = expression;
56 return *this;
57 }

References expression_.

Referenced by main().

Here is the caller graph for this function:

◆ set_title()

exprtk_gnuplot_fx & exprtk_gnuplot_fx::set_title ( const std::string &  title)
inline

Definition at line 40 of file exprtk_gnuplot.cpp.

41 {
42 title_ = title;
43 return *this;
44 }

References title_.

Referenced by main().

Here is the caller graph for this function:

Member Data Documentation

◆ curve_list_

std::deque<exprtk_fx_curve> exprtk_gnuplot_fx::curve_list_
private

Definition at line 187 of file exprtk_gnuplot_multi.cpp.

Referenced by add_curve(), generate_gp_script(), and plot().

◆ expression_

std::string exprtk_gnuplot_fx::expression_
private

Definition at line 145 of file exprtk_gnuplot.cpp.

Referenced by generate_data(), and set_expression().

◆ max_x_

double exprtk_gnuplot_fx::max_x_
private

Definition at line 147 of file exprtk_gnuplot.cpp.

Referenced by generate_data(), generate_gp_script(), and set_domain().

◆ max_y_

double exprtk_gnuplot_fx::max_y_
private

Definition at line 149 of file exprtk_gnuplot.cpp.

Referenced by generate_data(), and generate_gp_script().

◆ min_x_

double exprtk_gnuplot_fx::min_x_
private

Definition at line 146 of file exprtk_gnuplot.cpp.

Referenced by generate_data(), generate_gp_script(), and set_domain().

◆ min_y_

double exprtk_gnuplot_fx::min_y_
private

Definition at line 148 of file exprtk_gnuplot.cpp.

Referenced by generate_data(), and generate_gp_script().

◆ title_

std::string exprtk_gnuplot_fx::title_
private

Definition at line 144 of file exprtk_gnuplot.cpp.

Referenced by generate_gp_script(), and set_title().


The documentation for this class was generated from the following files: