From dcd7a07c8e1aca06e71a12672a40fb01e3bebd3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Ka=CC=88fer?= Date: Tue, 14 Aug 2012 17:04:57 +0200 Subject: [PATCH] simplify-tolerance property boilerplate --- bindings/python/mapnik_line_symbolizer.cpp | 4 ++ bindings/python/mapnik_polygon_symbolizer.cpp | 4 ++ include/mapnik/simplify_converter.hpp | 49 +++++++++++++++++++ include/mapnik/symbolizer.hpp | 3 ++ include/mapnik/vertex_converters.hpp | 15 ++++++ src/agg/process_line_pattern_symbolizer.cpp | 3 +- src/agg/process_line_symbolizer.cpp | 4 +- .../process_polygon_pattern_symbolizer.cpp | 3 +- src/agg/process_polygon_symbolizer.cpp | 3 +- src/cairo_renderer.cpp | 9 ++-- src/grid/process_line_symbolizer.cpp | 3 +- src/grid/process_polygon_symbolizer.cpp | 3 +- src/load_map.cpp | 4 ++ src/save_map.cpp | 4 ++ src/symbolizer.cpp | 12 +++++ 15 files changed, 114 insertions(+), 9 deletions(-) create mode 100644 include/mapnik/simplify_converter.hpp diff --git a/bindings/python/mapnik_line_symbolizer.cpp b/bindings/python/mapnik_line_symbolizer.cpp index bbf49164c..1c859e62c 100644 --- a/bindings/python/mapnik_line_symbolizer.cpp +++ b/bindings/python/mapnik_line_symbolizer.cpp @@ -63,6 +63,10 @@ void export_line_symbolizer() &line_symbolizer::smooth, &line_symbolizer::set_smooth, "smooth value (0..1.0)") + .add_property("simplify_tolerance", + &line_symbolizer::simplify_tolerance, + &line_symbolizer::set_simplify_tolerance, + "simplfication tolerance measure") .add_property("offset", &line_symbolizer::offset, &line_symbolizer::set_offset, diff --git a/bindings/python/mapnik_polygon_symbolizer.cpp b/bindings/python/mapnik_polygon_symbolizer.cpp index 06f35f0d8..9933dbde3 100644 --- a/bindings/python/mapnik_polygon_symbolizer.cpp +++ b/bindings/python/mapnik_polygon_symbolizer.cpp @@ -88,6 +88,10 @@ void export_polygon_symbolizer() &polygon_symbolizer::smooth, &polygon_symbolizer::set_smooth, "smooth value (0..1.0)") + .add_property("simplify_tolerance", + &polygon_symbolizer::simplify_tolerance, + &polygon_symbolizer::set_simplify_tolerance, + "simplfication tolerance measure") ; } diff --git a/include/mapnik/simplify_converter.hpp b/include/mapnik/simplify_converter.hpp new file mode 100644 index 000000000..784804dce --- /dev/null +++ b/include/mapnik/simplify_converter.hpp @@ -0,0 +1,49 @@ +#ifndef MAPNIK_SIMPLIFY_CONVERTER_HPP +#define MAPNIK_SIMPLIFY_CONVERTER_HPP + +#include +#include +#include + +namespace mapnik +{ + +template +struct MAPNIK_DECL simplify_converter +{ +public: + simplify_converter(Geometry& geom) + : geom_(geom) + , tolerance_(0.0) + { + } + + double simplify_tolerance(double tolerance) + { + return tolerance_; + } + + void set_simplify_tolerance(double tolerance) + { + tolerance_ = tolerance; + } + + void rewind(unsigned int path_id) + { + geom_.rewind(path_id); + } + + unsigned vertex(double* x, double* y) + { + unsigned cmd = geom_.vertex(x, y); + return cmd; + } + +private: + Geometry& geom_; + double tolerance_; +}; + +} + +#endif // MAPNIK_SIMPLIFY_CONVERTER_HPP diff --git a/include/mapnik/symbolizer.hpp b/include/mapnik/symbolizer.hpp index 2141d4833..5ea4c807c 100644 --- a/include/mapnik/symbolizer.hpp +++ b/include/mapnik/symbolizer.hpp @@ -90,6 +90,8 @@ public: std::string get_transform_string() const; void set_clip(bool clip); bool clip() const; + void set_simplify_tolerance(double simplify_tolerance); + double simplify_tolerance() const; void set_smooth(double smooth); double smooth() const; private: @@ -100,6 +102,7 @@ private: composite_mode_e comp_op_; transform_type affine_transform_; bool clip_; + double simplify_tolerance_value_; double smooth_value_; }; diff --git a/include/mapnik/vertex_converters.hpp b/include/mapnik/vertex_converters.hpp index ed57a5a03..bcb361f2f 100644 --- a/include/mapnik/vertex_converters.hpp +++ b/include/mapnik/vertex_converters.hpp @@ -49,6 +49,7 @@ // mapnik #include #include +#include // agg #include "agg_conv_clip_polygon.h" #include "agg_conv_clip_polyline.h" @@ -57,12 +58,14 @@ #include "agg_conv_dash.h" #include "agg_conv_transform.h" + namespace mapnik { struct transform_tag {}; struct clip_line_tag {}; struct clip_poly_tag {}; struct smooth_tag {}; +struct simplify_tag {}; struct stroke_tag {}; struct dash_tag {}; struct affine_transform_tag {}; @@ -95,6 +98,18 @@ struct converter_traits } }; +template +struct converter_traits +{ + typedef T geometry_type; + typedef simplify_converter conv_type; + + template + static void setup(geometry_type & geom, Args const& args) + { + geom.set_simplify_tolerance(boost::fusion::at_c<2>(args).simplify_tolerance()); + } +}; template struct converter_traits diff --git a/src/agg/process_line_pattern_symbolizer.cpp b/src/agg/process_line_pattern_symbolizer.cpp index 66dc01ca2..5ff649720 100644 --- a/src/agg/process_line_pattern_symbolizer.cpp +++ b/src/agg/process_line_pattern_symbolizer.cpp @@ -109,13 +109,14 @@ void agg_renderer::process(line_pattern_symbolizer const& sym, clipping_extent.init(x0 - padding, y0 - padding, x1 + padding , y1 + padding); } - typedef boost::mpl::vector conv_types; + typedef boost::mpl::vector conv_types; vertex_converter, rasterizer_type, line_pattern_symbolizer, CoordTransform, proj_transform, agg::trans_affine, conv_types> converter(clipping_extent,ras,sym,t_,prj_trans,tr,scale_factor_); if (sym.clip()) converter.set(); //optional clip (default: true) converter.set(); //always transform + if (sym.simplify_tolerance() > 0.0) converter.set(); // optional simplify converter if (sym.smooth() > 0.0) converter.set(); // optional smooth converter BOOST_FOREACH(geometry_type & geom, feature.paths()) diff --git a/src/agg/process_line_symbolizer.cpp b/src/agg/process_line_symbolizer.cpp index 5f9c3867d..3f221a9f2 100644 --- a/src/agg/process_line_symbolizer.cpp +++ b/src/agg/process_line_symbolizer.cpp @@ -76,7 +76,7 @@ void agg_renderer::process(line_symbolizer const& sym, typedef agg::renderer_base renderer_base; typedef boost::mpl::vector conv_types; + simplify_tag, smooth_tag, dash_tag, stroke_tag> conv_types; pixfmt_comp_type pixf(buf); pixf.comp_op(static_cast(sym.comp_op())); @@ -123,6 +123,7 @@ void agg_renderer::process(line_symbolizer const& sym, converter.set(); // always transform if (fabs(sym.offset()) > 0.0) converter.set(); // parallel offset converter.set(); // optional affine transform + if (sym.simplify_tolerance() > 0.0) converter.set(); // optional simplify converter if (sym.smooth() > 0.0) converter.set(); // optional smooth converter if (stroke_.has_dash()) converter.set(); converter.set(); //always stroke @@ -145,6 +146,7 @@ void agg_renderer::process(line_symbolizer const& sym, converter.set(); // always transform if (fabs(sym.offset()) > 0.0) converter.set(); // parallel offset converter.set(); // optional affine transform + if (sym.simplify_tolerance() > 0.0) converter.set(); // optional simplify converter if (sym.smooth() > 0.0) converter.set(); // optional smooth converter if (stroke_.has_dash()) converter.set(); converter.set(); //always stroke diff --git a/src/agg/process_polygon_pattern_symbolizer.cpp b/src/agg/process_polygon_pattern_symbolizer.cpp index a8b5a7c9f..5bd6c9298 100644 --- a/src/agg/process_polygon_pattern_symbolizer.cpp +++ b/src/agg/process_polygon_pattern_symbolizer.cpp @@ -139,13 +139,14 @@ void agg_renderer::process(polygon_pattern_symbolizer const& sym, agg::trans_affine tr; evaluate_transform(tr, feature, sym.get_transform()); - typedef boost::mpl::vector conv_types; + typedef boost::mpl::vector conv_types; vertex_converter, rasterizer, polygon_pattern_symbolizer, CoordTransform, proj_transform, agg::trans_affine, conv_types> converter(query_extent_,*ras_ptr,sym,t_,prj_trans,tr,scale_factor_); if (sym.clip()) converter.set(); //optional clip (default: true) converter.set(); //always transform + if (sym.simplify_tolerance() > 0.0) converter.set(); // optional simplify converter if (sym.smooth() > 0.0) converter.set(); // optional smooth converter BOOST_FOREACH( geometry_type & geom, feature.paths()) diff --git a/src/agg/process_polygon_symbolizer.cpp b/src/agg/process_polygon_symbolizer.cpp index 323f987ef..258a43543 100644 --- a/src/agg/process_polygon_symbolizer.cpp +++ b/src/agg/process_polygon_symbolizer.cpp @@ -51,7 +51,7 @@ void agg_renderer::process(polygon_symbolizer const& sym, agg::trans_affine tr; evaluate_transform(tr, feature, sym.get_transform()); - typedef boost::mpl::vector conv_types; + typedef boost::mpl::vector conv_types; vertex_converter, rasterizer, polygon_symbolizer, CoordTransform, proj_transform, agg::trans_affine, conv_types> converter(query_extent_,*ras_ptr,sym,t_,prj_trans,tr,scale_factor_); @@ -59,6 +59,7 @@ void agg_renderer::process(polygon_symbolizer const& sym, if (sym.clip()) converter.set(); //optional clip (default: true) converter.set(); //always transform converter.set(); + if (sym.simplify_tolerance() > 0.0) converter.set(); // optional simplify converter if (sym.smooth() > 0.0) converter.set(); // optional smooth converter BOOST_FOREACH( geometry_type & geom, feature.paths()) diff --git a/src/cairo_renderer.cpp b/src/cairo_renderer.cpp index cfe8f174c..be6809511 100644 --- a/src/cairo_renderer.cpp +++ b/src/cairo_renderer.cpp @@ -865,7 +865,7 @@ void cairo_renderer_base::process(polygon_symbolizer const& sym, agg::trans_affine tr; evaluate_transform(tr, feature, sym.get_transform()); - typedef boost::mpl::vector conv_types; + typedef boost::mpl::vector conv_types; vertex_converter, cairo_context, polygon_symbolizer, CoordTransform, proj_transform, agg::trans_affine, conv_types> converter(query_extent_,context,sym,t_,prj_trans,tr,1.0); @@ -873,6 +873,7 @@ void cairo_renderer_base::process(polygon_symbolizer const& sym, if (sym.clip()) converter.set(); //optional clip (default: true) converter.set(); //always transform converter.set(); + if (sym.simplify_tolerance() > 0.0) converter.set(); // optional simplify converter if (sym.smooth() > 0.0) converter.set(); // optional smooth converter BOOST_FOREACH( geometry_type & geom, feature.paths()) @@ -1005,7 +1006,7 @@ void cairo_renderer_base::process(line_symbolizer const& sym, evaluate_transform(tr, feature, sym.get_transform()); box2d ext = query_extent_ * 1.1; - typedef boost::mpl::vector conv_types; + typedef boost::mpl::vector conv_types; vertex_converter, cairo_context, line_symbolizer, CoordTransform, proj_transform, agg::trans_affine, conv_types> converter(ext,context,sym,t_,prj_trans,tr,scale_factor_); @@ -1022,6 +1023,7 @@ void cairo_renderer_base::process(line_symbolizer const& sym, converter.set(); // always transform if (fabs(sym.offset()) > 0.0) converter.set(); // parallel offset converter.set(); // optional affine transform + if (sym.simplify_tolerance() > 0.0) converter.set(); // optional simplify converter if (sym.smooth() > 0.0) converter.set(); // optional smooth converter BOOST_FOREACH( geometry_type & geom, feature.paths()) @@ -1341,7 +1343,7 @@ void cairo_renderer_base::process(polygon_pattern_symbolizer const& sym, agg::trans_affine tr; evaluate_transform(tr, feature, sym.get_transform()); - typedef boost::mpl::vector conv_types; + typedef boost::mpl::vector conv_types; vertex_converter, cairo_context, polygon_pattern_symbolizer, CoordTransform, proj_transform, agg::trans_affine, conv_types> converter(query_extent_,context,sym,t_,prj_trans,tr,1.0); @@ -1349,6 +1351,7 @@ void cairo_renderer_base::process(polygon_pattern_symbolizer const& sym, if (sym.clip()) converter.set(); //optional clip (default: true) converter.set(); //always transform converter.set(); + if (sym.simplify_tolerance() > 0.0) converter.set(); // optional simplify converter if (sym.smooth() > 0.0) converter.set(); // optional smooth converter BOOST_FOREACH( geometry_type & geom, feature.paths()) diff --git a/src/grid/process_line_symbolizer.cpp b/src/grid/process_line_symbolizer.cpp index f1ca1d590..ec2e3ef6f 100644 --- a/src/grid/process_line_symbolizer.cpp +++ b/src/grid/process_line_symbolizer.cpp @@ -54,7 +54,7 @@ void grid_renderer::process(line_symbolizer const& sym, typedef agg::renderer_scanline_bin_solid renderer_type; typedef boost::mpl::vector conv_types; + simplify_tag, smooth_tag, dash_tag, stroke_tag> conv_types; agg::scanline_bin sl; grid_rendering_buffer buf(pixmap_.raw_data(), width_, height_, width_); @@ -93,6 +93,7 @@ void grid_renderer::process(line_symbolizer const& sym, converter.set(); // always transform if (fabs(sym.offset()) > 0.0) converter.set(); // parallel offset converter.set(); // optional affine transform + if (sym.simplify_tolerance() > 0.0) converter.set(); // optional simplify converter if (sym.smooth() > 0.0) converter.set(); // optional smooth converter if (stroke_.has_dash()) converter.set(); converter.set(); //always stroke diff --git a/src/grid/process_polygon_symbolizer.cpp b/src/grid/process_polygon_symbolizer.cpp index 355e493b3..4986373f0 100644 --- a/src/grid/process_polygon_symbolizer.cpp +++ b/src/grid/process_polygon_symbolizer.cpp @@ -55,7 +55,7 @@ void grid_renderer::process(polygon_symbolizer const& sym, agg::trans_affine tr; evaluate_transform(tr, feature, sym.get_transform()); - typedef boost::mpl::vector conv_types; + typedef boost::mpl::vector conv_types; vertex_converter, grid_rasterizer, polygon_symbolizer, CoordTransform, proj_transform, agg::trans_affine, conv_types> converter(inflated_extent,*ras_ptr,sym,t_,prj_trans,tr,scale_factor_); @@ -63,6 +63,7 @@ void grid_renderer::process(polygon_symbolizer const& sym, if (sym.clip()) converter.set(); //optional clip (default: true) converter.set(); //always transform converter.set(); + if (sym.simplify_tolerance() > 0.0) converter.set(); // optional simplify converter if (sym.smooth() > 0.0) converter.set(); // optional smooth converter diff --git a/src/load_map.cpp b/src/load_map.cpp index d98c0f94d..79c72cccc 100644 --- a/src/load_map.cpp +++ b/src/load_map.cpp @@ -882,6 +882,10 @@ void map_parser::parse_symbolizer_base(symbolizer_base &sym, xml_node const &pt) optional clip = pt.get_opt_attr("clip"); if (clip) sym.set_clip(*clip); + // simplify value + optional simplify_tolerance = pt.get_opt_attr("simplify-tolerance"); + if (simplify_tolerance) sym.set_simplify_tolerance(*simplify_tolerance); + // smooth value optional smooth = pt.get_opt_attr("smooth"); if (smooth) sym.set_smooth(*smooth); diff --git a/src/save_map.cpp b/src/save_map.cpp index 3138ca040..6bcf559f2 100644 --- a/src/save_map.cpp +++ b/src/save_map.cpp @@ -357,6 +357,10 @@ private: { set_attr( node, "clip", sym.clip() ); } + if (sym.simplify_tolerance() != dfl.simplify_tolerance() || explicit_defaults_) + { + set_attr( node, "simplify-tolerance", sym.simplify_tolerance() ); + } if (sym.smooth() != dfl.smooth() || explicit_defaults_) { set_attr( node, "smooth", sym.smooth() ); diff --git a/src/symbolizer.cpp b/src/symbolizer.cpp index 7825338c3..0a5c7c82f 100644 --- a/src/symbolizer.cpp +++ b/src/symbolizer.cpp @@ -51,6 +51,7 @@ symbolizer_base::symbolizer_base() writer_ptr_(), comp_op_(src_over), clip_(true), + simplify_tolerance_value_(0.0), smooth_value_(0.0) { } @@ -60,6 +61,7 @@ symbolizer_base::symbolizer_base(symbolizer_base const& other) : comp_op_(other.comp_op_), affine_transform_(other.affine_transform_), clip_(other.clip_), + simplify_tolerance_value_(other.simplify_tolerance_value_), smooth_value_(other.smooth_value_) {} void symbolizer_base::add_metawriter(std::string const& name, metawriter_properties const& properties) @@ -150,6 +152,16 @@ bool symbolizer_base::clip() const return clip_; } +void symbolizer_base::set_simplify_tolerance(double simplify_tolerance) +{ + simplify_tolerance_value_ = simplify_tolerance; +} + +double symbolizer_base::simplify_tolerance() const +{ + return simplify_tolerance_value_; +} + void symbolizer_base::set_smooth(double smooth) { smooth_value_ = smooth;