Skip to content
Browse files

+ add optional polygon smoothing ( 0.0 < smooth < 1.0 )

  using agg_conv_poly1_curve
  • Loading branch information...
1 parent 0c537ed commit 87b22c29b208a1414fffef83fa7a2cb0901cd27e @artemp artemp committed Mar 14, 2012
View
6 include/mapnik/polygon_symbolizer.hpp
@@ -35,7 +35,7 @@ namespace mapnik
struct MAPNIK_DECL polygon_symbolizer : public symbolizer_base
{
polygon_symbolizer();
- polygon_symbolizer(color const& fill);
+ explicit polygon_symbolizer(color const& fill);
color const& get_fill() const;
void set_fill(color const& fill);
void set_opacity(double opacity);
@@ -44,12 +44,14 @@ struct MAPNIK_DECL polygon_symbolizer : public symbolizer_base
double get_gamma() const;
void set_gamma_method(gamma_method_e gamma_method);
gamma_method_e get_gamma_method() const;
-
+ void set_smooth(double smooth);
+ double smooth() const;
private:
color fill_;
double opacity_;
double gamma_;
gamma_method_e gamma_method_;
+ double smooth_;
};
}
View
29 src/agg/process_polygon_symbolizer.cpp
@@ -35,6 +35,7 @@
// for polygon_symbolizer
#include "agg_renderer_scanline.h"
#include "agg_conv_clip_polygon.h"
+#include "agg_conv_smooth_poly1.h"
// stl
#include <string>
@@ -45,11 +46,10 @@ void agg_renderer<T>::process(polygon_symbolizer const& sym,
mapnik::feature_ptr const& feature,
proj_transform const& prj_trans)
{
- typedef agg::conv_clip_polygon<geometry_type> clipped_geometry_type;
- typedef coord_transform2<CoordTransform,clipped_geometry_type> path_type;
typedef agg::renderer_base<agg::pixfmt_rgba32_plain> ren_base;
typedef agg::renderer_scanline_aa_solid<ren_base> renderer;
+ box2d<double> query_extent = query_extent_ * 1.0;
color const& fill_ = sym.get_fill();
agg::scanline_u8 sl;
@@ -92,10 +92,27 @@ void agg_renderer<T>::process(polygon_symbolizer const& sym,
geometry_type & geom=feature->get_geometry(i);
if (geom.num_points() > 2)
{
- clipped_geometry_type clipped(geom);
- clipped.clip_box(query_extent_.minx(),query_extent_.miny(),query_extent_.maxx(),query_extent_.maxy());
- path_type path(t_,clipped,prj_trans);
- ras_ptr->add_path(path);
+ if (sym.smooth() > 0.0)
+ {
+ typedef agg::conv_smooth_poly1_curve<geometry_type> smooth_type;
+ typedef agg::conv_clip_polygon<smooth_type> clipped_geometry_type;
+ typedef coord_transform2<CoordTransform,clipped_geometry_type> path_type;
+ smooth_type smooth(geom);
+ smooth.smooth_value(sym.smooth());
+ clipped_geometry_type clipped(smooth);
+ clipped.clip_box(query_extent.minx(),query_extent.miny(),query_extent.maxx(),query_extent.maxy());
+ path_type path(t_,clipped,prj_trans);
+ ras_ptr->add_path(path);
+ }
+ else
+ {
+ typedef agg::conv_clip_polygon<geometry_type> clipped_geometry_type;
+ typedef coord_transform2<CoordTransform,clipped_geometry_type> path_type;
+ clipped_geometry_type clipped(geom);
+ clipped.clip_box(query_extent.minx(),query_extent.miny(),query_extent.maxx(),query_extent.maxy());
+ path_type path(t_,clipped,prj_trans);
+ ras_ptr->add_path(path);
+ }
//if (writer.first) writer.first->add_polygon(path, *feature, t_, writer.second);
}
}
View
5 src/load_map.cpp
@@ -1295,7 +1295,10 @@ void map_parser::parse_polygon_symbolizer( rule & rule, xml_node const & sym )
// gamma method
optional<gamma_method_e> gamma_method = sym.get_opt_attr<gamma_method_e>("gamma-method");
if (gamma_method) poly_sym.set_gamma_method(*gamma_method);
-
+ // smooth value
+ optional<double> smooth = sym.get_opt_attr<double>("smooth");
+ if (smooth) poly_sym.set_smooth(*smooth);
+
parse_metawriter_in_symbolizer(poly_sym, sym);
rule.append(poly_sym);
}
View
16 src/polygon_symbolizer.cpp
@@ -32,14 +32,16 @@ polygon_symbolizer::polygon_symbolizer()
fill_(color(128,128,128)),
opacity_(1.0),
gamma_(1.0),
- gamma_method_(GAMMA_POWER) {}
+ gamma_method_(GAMMA_POWER),
+ smooth_(0.0) {}
polygon_symbolizer::polygon_symbolizer(color const& fill)
: symbolizer_base(),
fill_(fill),
opacity_(1.0),
gamma_(1.0),
- gamma_method_(GAMMA_POWER) {}
+ gamma_method_(GAMMA_POWER),
+ smooth_(0.0) {}
color const& polygon_symbolizer::get_fill() const
{
@@ -81,4 +83,14 @@ gamma_method_e polygon_symbolizer::get_gamma_method() const
return gamma_method_;
}
+void polygon_symbolizer::set_smooth(double smooth)
+{
+ smooth_ = smooth;
+}
+
+double polygon_symbolizer::smooth() const
+{
+ return smooth_;
+}
+
}
View
4 src/save_map.cpp
@@ -125,6 +125,10 @@ class serialize_symbolizer : public boost::static_visitor<>
{
set_attr( sym_node, "gamma-method", sym.get_gamma_method() );
}
+ if ( sym.smooth() != dfl.smooth() || explicit_defaults_ )
+ {
+ set_attr( sym_node, "smooth", sym.smooth() );
+ }
add_metawriter_attributes(sym_node, sym);
}

2 comments on commit 87b22c2

@springmeyer
Mapnik member

would be great to also expose in python bindings and then add the smooth property to the tests. Lastly, https://github.com/mapnik/reference.json is what is used to generate http://mapbox.com/carto/, so that would need 'smooth' added.

@artemp
Mapnik member
Please sign in to comment.
Something went wrong with that request. Please try again.