|
Boost-Commit : |
From: JakeVoytko_at_[hidden]
Date: 2007-07-29 17:31:48
Author: jakevoytko
Date: 2007-07-29 17:31:46 EDT (Sun, 29 Jul 2007)
New Revision: 7581
URL: http://svn.boost.org/trac/boost/changeset/7581
Log:
Added curve interpolation beta
Text files modified:
sandbox/SOC/2007/visualization/boost/svg_plot/detail/axis_plot_frame.hpp | 2
sandbox/SOC/2007/visualization/boost/svg_plot/detail/svg_tag.hpp | 80 ++++++++++++++++++
sandbox/SOC/2007/visualization/boost/svg_plot/svg_1d_plot.hpp | 2
sandbox/SOC/2007/visualization/boost/svg_plot/svg_2d_plot.hpp | 174 ++++++++++++++++++++++++++++-----------
sandbox/SOC/2007/visualization/boost/svg_plot/svg_style.hpp | 5
sandbox/SOC/2007/visualization/boost/svg_plot/svg_test.cpp | 31 ++++--
6 files changed, 226 insertions(+), 68 deletions(-)
Modified: sandbox/SOC/2007/visualization/boost/svg_plot/detail/axis_plot_frame.hpp
==============================================================================
--- sandbox/SOC/2007/visualization/boost/svg_plot/detail/axis_plot_frame.hpp (original)
+++ sandbox/SOC/2007/visualization/boost/svg_plot/detail/axis_plot_frame.hpp 2007-07-29 17:31:46 EDT (Sun, 29 Jul 2007)
@@ -652,7 +652,7 @@
return derived();
}
- Derived& x_major_tick(double _inter)
+ Derived& x_major_interval(double _inter)
{
derived().x_major = _inter;
return derived();
Modified: sandbox/SOC/2007/visualization/boost/svg_plot/detail/svg_tag.hpp
==============================================================================
--- sandbox/SOC/2007/visualization/boost/svg_plot/detail/svg_tag.hpp (original)
+++ sandbox/SOC/2007/visualization/boost/svg_plot/detail/svg_tag.hpp 2007-07-29 17:31:46 EDT (Sun, 29 Jul 2007)
@@ -441,6 +441,60 @@
}
};
+struct s_path: public path_point
+{
+ double x1, y1, x, y;
+
+ void write(std::ostream& o_str)
+ {
+ if(relative)
+ {
+ o_str<<"s";
+ }
+
+ else
+ {
+ o_str<<"S";
+ }
+
+ o_str<<x1<<" "<<y1<<" "
+ <<x<<" "<<y<<" ";
+ }
+
+ s_path(double _x1, double _y1,
+ double _x, double _y, bool _rel = false):
+ x1(_x1), y1(_y1), x(_x), y(_y), path_point(_rel)
+ {
+
+ }
+};
+
+struct t_path: public path_point
+{
+ double x, y;
+
+ void write(std::ostream& o_str)
+ {
+ if(relative)
+ {
+ o_str<<"t";
+ }
+
+ else
+ {
+ o_str<<"T";
+ }
+
+ o_str<<x<<" "<<y<<" ";
+ }
+
+ t_path(double _x, double _y, bool _rel = false):
+ x(_x), y(_y), path_point(_rel)
+ {
+
+ }
+};
+
class path_element: public svg_element
{
private:
@@ -532,6 +586,30 @@
return *this;
}
+ path_element& s(double x1, double y1, double x, double y)
+ {
+ path.push_back(new s_path(x1, y1, x, y, true));
+ return *this;
+ }
+
+ path_element& S(double x1, double y1, double x, double y)
+ {
+ path.push_back(new s_path(x1, y1, x, y, false));
+ return *this;
+ }
+
+ path_element& t(double x, double y)
+ {
+ path.push_back(new t_path(x, y, true));
+ return *this;
+ }
+
+ path_element& T(double x, double y)
+ {
+ path.push_back(new t_path(x, y, false));
+ return *this;
+ }
+
void write(std::ostream& o_str)
{
o_str<<"<path d=\"";
@@ -546,7 +624,7 @@
style_info.write(o_str);
- o_str<<"/>";
+ o_str<<"fill = \"none\" />";
}
};
Modified: sandbox/SOC/2007/visualization/boost/svg_plot/svg_1d_plot.hpp
==============================================================================
--- sandbox/SOC/2007/visualization/boost/svg_plot/svg_1d_plot.hpp (original)
+++ sandbox/SOC/2007/visualization/boost/svg_plot/svg_1d_plot.hpp 2007-07-29 17:31:46 EDT (Sun, 29 Jul 2007)
@@ -12,7 +12,7 @@
#ifndef _BOOST_SVG_SVG_1D_PLOT_HPP
#define _BOOST_SVG_SVG_1D_PLOT_HPP
-#define BOOST_PARAMETER_MAX_ARITY 11
+#define BOOST_PARAMETER_MAX_ARITY 12
#include <boost/bind.hpp>
Modified: sandbox/SOC/2007/visualization/boost/svg_plot/svg_2d_plot.hpp
==============================================================================
--- sandbox/SOC/2007/visualization/boost/svg_plot/svg_2d_plot.hpp (original)
+++ sandbox/SOC/2007/visualization/boost/svg_plot/svg_2d_plot.hpp 2007-07-29 17:31:46 EDT (Sun, 29 Jul 2007)
@@ -10,7 +10,7 @@
#ifndef _BOOST_SVG_SVG_2D_PLOT_HPP
#define _BOOST_SVG_SVG_2D_PLOT_HPP
-#define BOOST_PARAMETER_MAX_ARITY 11
+#define BOOST_PARAMETER_MAX_ARITY 12
#include <boost/bind.hpp>
@@ -60,6 +60,7 @@
#endif
BOOST_PARAMETER_NAME(line_on)
+BOOST_PARAMETER_NAME(bezier_on)
BOOST_PARAMETER_NAME(line_color)
BOOST_PARAMETER_NAME(area_fill_color)
@@ -430,73 +431,145 @@
}
}
- void _draw_plot_lines()
+ void _transform_pair(std::pair<double, double>& pt)
{
- double prev_x, prev_y, temp_x(0.), temp_y(0.);
-
- for(unsigned int i = 0; i < series.size(); ++i)
+ _transform_point(pt.first, pt.second);
+ }
+
+ void _draw_bezier_lines(const svg_2d_plot_series& series)
+ {
+ g_element& g_ptr = image.get_g_element(detail::PLOT_PLOT_LINES)
+ .add_g_element();
+
+ g_ptr.style().stroke_color(series.line_style.color);
+ path_element& path = g_ptr.path();
+
+ std::pair<double, double> n_minus_2, n_minus_1, n;
+ std::pair<double, double> fwd_vtr, back_vtr;
+
+ if(series.series.size() > 2)
{
- g_element& g_ptr = image.get_g_element(detail::PLOT_PLOT_LINES).add_g_element();
+ std::multimap<double,double>::const_iterator iter = series.series.begin();
- g_ptr.style().stroke_color(series[i].line_style.color);
+ n_minus_1 = *(iter++);
+ n = *(iter++);
- path_element& path = g_ptr.path();
+ _transform_pair(n_minus_1);
+ _transform_pair(n);
+
+ path.M(n_minus_1.first, n_minus_1.second);
- if(series[i].series.size() > 1)
+ for(; iter != series.series.end(); ++iter)
{
- std::multimap<double, double>::const_iterator j = series[i].series.begin();
- prev_x = (*j).first;
- prev_y = 0.;
+ n_minus_2 = n_minus_1;
+ n_minus_1 = n;
+ n = *iter;
- // If we have to fill the area under the plot, we first have to
- // move from the X-axis to the first point.
+ _transform_pair(n);
- _transform_point(prev_x, prev_y);
+ back_vtr.first = ((n_minus_1.first - n.first) +
+ (n_minus_2.first - n_minus_1.first)) * .2;
- if(series[i].line_style.area_fill != blank)
- {
- path.style().fill_color(series[i].line_style.area_fill);
- path.M(prev_x, prev_y);
- }
+ back_vtr.second = ((n_minus_1.second - n.second) +
+ (n_minus_2.second - n_minus_1.second)) * .2;
-
- _transform_y(prev_y = (*j).second);
+ path.S(n_minus_1.first + back_vtr.first, n_minus_1.second + back_vtr.second,
+ n_minus_1.first, n_minus_1.second);
+ }
- if(series[i].line_style.area_fill != blank)
- {
- path.style().fill_color(series[i].line_style.area_fill);
- path.L(prev_x, prev_y);
- }
+ back_vtr.first = 0;
+ back_vtr.second = (n.second - n_minus_1.second)*.2;
- else
- {
- path.M(prev_x, prev_y);
- }
- ++j;
+ path.S(n.first + back_vtr.first, n.second + back_vtr.second,
+ n.first, n.second);
+ }
- for(; j != series[i].series.end(); ++j)
- {
- temp_x = (*j).first;
- temp_y = (*j).second;
+ else
+ {
+ _draw_straight_lines(series);
+ }
+
+ }
+
+ void _draw_straight_lines(const svg_2d_plot_series& series)
+ {
+ double prev_x, prev_y, temp_x(0.), temp_y;
- _transform_point(temp_x, temp_y);
+ g_element& g_ptr = image.get_g_element(detail::PLOT_PLOT_LINES).add_g_element();
- path.L(temp_x, temp_y);
-
- if(series[i].line_style.area_fill == blank)
- {
- path.M(temp_x, temp_y);
- }
+ g_ptr.style().stroke_color(series.line_style.color);
- prev_x = temp_x;
- prev_y = temp_y;
- }
+ path_element& path = g_ptr.path();
+
+ if(series.series.size() > 1)
+ {
+ std::multimap<double, double>::const_iterator j = series.series.begin();
+ prev_x = (*j).first;
+ prev_y = 0.;
+
+ // If we have to fill the area under the plot, we first have to
+ // move from the X-axis to the first point.
+
+ _transform_point(prev_x, prev_y);
- if(series[i].line_style.area_fill != blank)
+ if(series.line_style.area_fill != blank)
+ {
+ path.style().fill_color(series.line_style.area_fill);
+ path.M(prev_x, prev_y);
+ }
+
+ _transform_y(prev_y = (*j).second);
+
+ if(series.line_style.area_fill != blank)
+ {
+ path.style().fill_color(series.line_style.area_fill);
+ path.L(prev_x, prev_y);
+ }
+
+ else
+ {
+ path.M(prev_x, prev_y);
+ }
+ ++j;
+
+ for(; j != series.series.end(); ++j)
+ {
+ temp_x = (*j).first;
+ temp_y = (*j).second;
+
+ _transform_point(temp_x, temp_y);
+
+ path.L(temp_x, temp_y);
+
+ if(series.line_style.area_fill == blank)
{
- _transform_y(temp_y = 0.);
- path.L(temp_x, temp_y).z();
+ path.M(temp_x, temp_y);
}
+
+ prev_x = temp_x;
+ prev_y = temp_y;
+ }
+
+ if(series.line_style.area_fill != blank)
+ {
+ _transform_y(temp_y = 0.);
+ path.L(temp_x, temp_y).z();
+ }
+ }
+ }
+
+ void _draw_plot_lines()
+ {
+ for(unsigned int i = 0; i < series.size(); ++i)
+ {
+ if(series[i].line_style.bezier_on)
+ {
+ _draw_bezier_lines(series[i]);
+ }
+
+ else
+ {
+ _draw_straight_lines(series[i]);
}
}
}
@@ -818,11 +891,12 @@
(point_style, (point_shape), circle)
(size, (int), 10)
(line_on, (bool), true)
+ (bezier_on, (bool), false)
(x_functor, *, boost_default_2d_convert())
)
)
{
- plot_line_style line_style(line_color, line_on);
+ plot_line_style line_style(line_color, line_on, bezier_on);
if(area_fill_color != none)
{
Modified: sandbox/SOC/2007/visualization/boost/svg_plot/svg_style.hpp
==============================================================================
--- sandbox/SOC/2007/visualization/boost/svg_plot/svg_style.hpp (original)
+++ sandbox/SOC/2007/visualization/boost/svg_plot/svg_style.hpp 2007-07-29 17:31:46 EDT (Sun, 29 Jul 2007)
@@ -39,9 +39,10 @@
svg_color_constant area_fill;
bool line_on;
+ bool bezier_on;
- plot_line_style(const svg_color& _col, bool _on):
- color(_col), line_on(_on), area_fill(blank)
+ plot_line_style(const svg_color& _col, bool _on, bool _bezier_on = false):
+ color(_col), line_on(_on), area_fill(blank), bezier_on(_bezier_on)
{
}
};
Modified: sandbox/SOC/2007/visualization/boost/svg_plot/svg_test.cpp
==============================================================================
--- sandbox/SOC/2007/visualization/boost/svg_plot/svg_test.cpp (original)
+++ sandbox/SOC/2007/visualization/boost/svg_plot/svg_test.cpp 2007-07-29 17:31:46 EDT (Sun, 29 Jul 2007)
@@ -10,17 +10,17 @@
double f(double x)
{
- return sqrt(x);
+ return sin(x);
}
double g(double x)
{
- return -2 + x*x;
+ return cos(x);
}
double h(double x)
{
- return 2*x;
+ return tan(x);
}
@@ -45,25 +45,30 @@
svg_2d_plot my_2d_plot;
svg_1d_plot my_1d_plot;
- for(double i=0; i<10; i+=1)
+ double pi = 3.1415926535;
+
+ for(double i=0; i<10; i+=pi/4.)
{
- data1[i - 5.] = f(i);
+ data1[i] = f(i);
data2[i] = g(i);
- data3.push_back(h(i) - 10.);
+ data3.push_back(h(i));
}
// size/scale settings
my_2d_plot.image_size(500, 350);
my_2d_plot.title("Hello, operator")
- .plot_window_on(true)
- .legend_on(true);
+ .plot_window_on(true);
my_2d_plot.title_on(true)
.x_label_on(true)
.y_major_labels_on(true)
.x_label("sqrt(x)")
- .x_major_grid_on(false);
+ .x_major_grid_on(false)
+ .y_range(-1.1, 1.1)
+ .x_range(-.5, 10.5)
+ .y_major_interval(1)
+ .x_major_interval(pi/2.);
// .y_external_style_on(true)
// .x_external_style_on(true);
@@ -77,17 +82,17 @@
.x_label_on(true)
.x_label("sqrt(x)");
- my_2d_plot.plot_2d(data1, "sqrt(x)");
+ my_2d_plot.plot(data1, "sqrt(x)", _bezier_on = true, _size = 5);
- my_2d_plot.plot_2d(data2, "Not sqrt(x)",
+ my_2d_plot.plot(data2, "Not sqrt(x)",
_size = 6,
_point_style = square,
_stroke_color = hotpink,
_line_color = black,
_fill_color = yellow,
- _area_fill_color = red);
+ _bezier_on = true);
- my_1d_plot.plot(data3, "1D Plot");
+// my_2d_plot.plot(data3, "1D Plot", _bezier_on = true, _size = 5);
my_1d_plot.write("./test1d.svg");
my_2d_plot.write("./test2d.svg");
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk