+ add optional smothing to line_symbolizer

( TODO: conv_dash )
This commit is contained in:
Artem Pavlenko 2012-03-15 10:26:53 +00:00
parent 926404d9ae
commit 70512dc03b
5 changed files with 60 additions and 16 deletions

View file

@ -62,5 +62,9 @@ void export_line_symbolizer()
(&line_symbolizer::get_stroke,
return_value_policy<copy_const_reference>()),
&line_symbolizer::set_stroke)
.add_property("smooth",
&line_symbolizer::smooth,
&line_symbolizer::set_smooth,
"smooth value (0..1.0)")
;
}

View file

@ -44,17 +44,20 @@ struct MAPNIK_DECL line_symbolizer : public symbolizer_base
explicit line_symbolizer()
: symbolizer_base(),
stroke_(),
rasterizer_p_(RASTERIZER_FULL) {}
rasterizer_p_(RASTERIZER_FULL),
smooth_(0.0) {}
line_symbolizer(stroke const& stroke)
: symbolizer_base(),
stroke_(stroke),
rasterizer_p_(RASTERIZER_FULL) {}
rasterizer_p_(RASTERIZER_FULL),
smooth_(0.0) {}
line_symbolizer(color const& pen,float width=1.0)
: symbolizer_base(),
stroke_(pen,width),
rasterizer_p_(RASTERIZER_FULL) {}
rasterizer_p_(RASTERIZER_FULL),
smooth_(0.0) {}
stroke const& get_stroke() const
{
@ -76,9 +79,20 @@ struct MAPNIK_DECL line_symbolizer : public symbolizer_base
return rasterizer_p_;
}
void set_smooth(double smooth)
{
smooth_ = smooth;
}
double smooth() const
{
return smooth_;
}
private:
stroke stroke_;
line_rasterizer_e rasterizer_p_;
double smooth_;
};
}

View file

@ -40,7 +40,7 @@
#include "agg_renderer_outline_aa.h"
#include "agg_rasterizer_outline_aa.h"
#include "agg_conv_clip_polyline.h"
#include "agg_conv_smooth_poly1.h"
// stl
#include <string>
@ -105,8 +105,6 @@ void agg_renderer<T>::process(line_symbolizer const& sym,
set_gamma_method(stroke_, ras_ptr);
//metawriter_with_properties writer = sym.get_metawriter();
for (unsigned i=0;i<feature->num_geometries();++i)
{
@ -137,14 +135,35 @@ void agg_renderer<T>::process(line_symbolizer const& sym,
}
else
{
clipped_geometry_type clipped(geom);
clipped.clip_box(ext.minx(),ext.miny(),ext.maxx(),ext.maxy());
path_type path(t_,clipped,prj_trans);
agg::conv_stroke<path_type> stroke(path);
set_join_caps(stroke_,stroke);
stroke.generator().miter_limit(4.0);
stroke.generator().width(stroke_.get_width() * scale_factor_);
ras_ptr->add_path(stroke);
if (sym.smooth() > 0.0)
{
typedef agg::conv_clip_polyline<geometry_type> clipped_geometry_type;
typedef coord_transform2<CoordTransform,clipped_geometry_type> path_type;
typedef agg::conv_smooth_poly1_curve<path_type> smooth_type;
clipped_geometry_type clipped(geom);
clipped.clip_box(ext.minx(),ext.miny(),ext.maxx(),ext.maxy());
path_type path(t_,clipped,prj_trans);
smooth_type smooth(path);
smooth.smooth_value(sym.smooth());
agg::conv_stroke<smooth_type> stroke(smooth);
set_join_caps(stroke_,stroke);
stroke.generator().miter_limit(4.0);
stroke.generator().width(stroke_.get_width() * scale_factor_);
ras_ptr->add_path(stroke);
}
else
{
typedef agg::conv_clip_polyline<geometry_type> clipped_geometry_type;
typedef coord_transform2<CoordTransform,clipped_geometry_type> path_type;
clipped_geometry_type clipped(geom);
clipped.clip_box(ext.minx(),ext.miny(),ext.maxx(),ext.maxy());
path_type path(t_,clipped,prj_trans);
agg::conv_stroke<path_type> stroke(path);
set_join_caps(stroke_,stroke);
stroke.generator().miter_limit(4.0);
stroke.generator().width(stroke_.get_width() * scale_factor_);
ras_ptr->add_path(stroke);
}
//if (writer.first) writer.first->add_line(path, *feature, t_, writer.second);
}
}

View file

@ -1266,7 +1266,10 @@ void map_parser::parse_line_symbolizer( rule & rule, xml_node const & sym )
line_rasterizer_e rasterizer = sym.get_attr<line_rasterizer_e>("rasterizer", RASTERIZER_FULL);
//optional<line_rasterizer_e> rasterizer_method = sym.get_opt_attr<line_rasterizer_e>("full");
symbol.set_rasterizer(rasterizer);
// smooth value
optional<double> smooth = sym.get_opt_attr<double>("smooth");
if (smooth) symbol.set_smooth(*smooth);
// meta-writer
parse_metawriter_in_symbolizer(symbol, sym);
rule.append(symbol);
}

View file

@ -91,8 +91,12 @@ public:
{
set_attr( sym_node, "rasterizer", sym.get_rasterizer() );
}
if ( sym.smooth() != dfl.smooth() || explicit_defaults_ )
{
set_attr( sym_node, "smooth", sym.smooth() );
}
}
void operator () ( line_pattern_symbolizer const& sym )
{
ptree & sym_node = rule_.push_back(