simplify-tolerance property boilerplate
This commit is contained in:
parent
f35f394b30
commit
dcd7a07c8e
15 changed files with 114 additions and 9 deletions
|
@ -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,
|
||||
|
|
|
@ -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")
|
||||
;
|
||||
|
||||
}
|
||||
|
|
49
include/mapnik/simplify_converter.hpp
Normal file
49
include/mapnik/simplify_converter.hpp
Normal file
|
@ -0,0 +1,49 @@
|
|||
#ifndef MAPNIK_SIMPLIFY_CONVERTER_HPP
|
||||
#define MAPNIK_SIMPLIFY_CONVERTER_HPP
|
||||
|
||||
#include <mapnik/debug.hpp>
|
||||
#include <mapnik/box2d.hpp>
|
||||
#include <mapnik/vertex.hpp>
|
||||
|
||||
namespace mapnik
|
||||
{
|
||||
|
||||
template <typename Geometry>
|
||||
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
|
|
@ -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_;
|
||||
};
|
||||
|
||||
|
|
|
@ -49,6 +49,7 @@
|
|||
// mapnik
|
||||
#include <mapnik/agg_helpers.hpp>
|
||||
#include <mapnik/offset_converter.hpp>
|
||||
#include <mapnik/simplify_converter.hpp>
|
||||
// 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<T,mapnik::smooth_tag>
|
|||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct converter_traits<T,mapnik::simplify_tag>
|
||||
{
|
||||
typedef T geometry_type;
|
||||
typedef simplify_converter<geometry_type> conv_type;
|
||||
|
||||
template <typename Args>
|
||||
static void setup(geometry_type & geom, Args const& args)
|
||||
{
|
||||
geom.set_simplify_tolerance(boost::fusion::at_c<2>(args).simplify_tolerance());
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct converter_traits<T, mapnik::clip_line_tag>
|
||||
|
|
|
@ -109,13 +109,14 @@ void agg_renderer<T>::process(line_pattern_symbolizer const& sym,
|
|||
clipping_extent.init(x0 - padding, y0 - padding, x1 + padding , y1 + padding);
|
||||
}
|
||||
|
||||
typedef boost::mpl::vector<clip_line_tag,transform_tag,smooth_tag> conv_types;
|
||||
typedef boost::mpl::vector<clip_line_tag,transform_tag,simplify_tag,smooth_tag> conv_types;
|
||||
vertex_converter<box2d<double>, 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<clip_line_tag>(); //optional clip (default: true)
|
||||
converter.set<transform_tag>(); //always transform
|
||||
if (sym.simplify_tolerance() > 0.0) converter.set<simplify_tag>(); // optional simplify converter
|
||||
if (sym.smooth() > 0.0) converter.set<smooth_tag>(); // optional smooth converter
|
||||
|
||||
BOOST_FOREACH(geometry_type & geom, feature.paths())
|
||||
|
|
|
@ -76,7 +76,7 @@ void agg_renderer<T>::process(line_symbolizer const& sym,
|
|||
typedef agg::renderer_base<pixfmt_comp_type> renderer_base;
|
||||
typedef boost::mpl::vector<clip_line_tag, transform_tag,
|
||||
offset_transform_tag, affine_transform_tag,
|
||||
smooth_tag, dash_tag, stroke_tag> conv_types;
|
||||
simplify_tag, smooth_tag, dash_tag, stroke_tag> conv_types;
|
||||
|
||||
pixfmt_comp_type pixf(buf);
|
||||
pixf.comp_op(static_cast<agg::comp_op_e>(sym.comp_op()));
|
||||
|
@ -123,6 +123,7 @@ void agg_renderer<T>::process(line_symbolizer const& sym,
|
|||
converter.set<transform_tag>(); // always transform
|
||||
if (fabs(sym.offset()) > 0.0) converter.set<offset_transform_tag>(); // parallel offset
|
||||
converter.set<affine_transform_tag>(); // optional affine transform
|
||||
if (sym.simplify_tolerance() > 0.0) converter.set<simplify_tag>(); // optional simplify converter
|
||||
if (sym.smooth() > 0.0) converter.set<smooth_tag>(); // optional smooth converter
|
||||
if (stroke_.has_dash()) converter.set<dash_tag>();
|
||||
converter.set<stroke_tag>(); //always stroke
|
||||
|
@ -145,6 +146,7 @@ void agg_renderer<T>::process(line_symbolizer const& sym,
|
|||
converter.set<transform_tag>(); // always transform
|
||||
if (fabs(sym.offset()) > 0.0) converter.set<offset_transform_tag>(); // parallel offset
|
||||
converter.set<affine_transform_tag>(); // optional affine transform
|
||||
if (sym.simplify_tolerance() > 0.0) converter.set<simplify_tag>(); // optional simplify converter
|
||||
if (sym.smooth() > 0.0) converter.set<smooth_tag>(); // optional smooth converter
|
||||
if (stroke_.has_dash()) converter.set<dash_tag>();
|
||||
converter.set<stroke_tag>(); //always stroke
|
||||
|
|
|
@ -139,13 +139,14 @@ void agg_renderer<T>::process(polygon_pattern_symbolizer const& sym,
|
|||
agg::trans_affine tr;
|
||||
evaluate_transform(tr, feature, sym.get_transform());
|
||||
|
||||
typedef boost::mpl::vector<clip_poly_tag,transform_tag,smooth_tag> conv_types;
|
||||
typedef boost::mpl::vector<clip_poly_tag,transform_tag,simplify_tag,smooth_tag> conv_types;
|
||||
vertex_converter<box2d<double>, 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<clip_poly_tag>(); //optional clip (default: true)
|
||||
converter.set<transform_tag>(); //always transform
|
||||
if (sym.simplify_tolerance() > 0.0) converter.set<simplify_tag>(); // optional simplify converter
|
||||
if (sym.smooth() > 0.0) converter.set<smooth_tag>(); // optional smooth converter
|
||||
|
||||
BOOST_FOREACH( geometry_type & geom, feature.paths())
|
||||
|
|
|
@ -51,7 +51,7 @@ void agg_renderer<T>::process(polygon_symbolizer const& sym,
|
|||
agg::trans_affine tr;
|
||||
evaluate_transform(tr, feature, sym.get_transform());
|
||||
|
||||
typedef boost::mpl::vector<clip_poly_tag,transform_tag,affine_transform_tag,smooth_tag> conv_types;
|
||||
typedef boost::mpl::vector<clip_poly_tag,transform_tag,affine_transform_tag,simplify_tag,smooth_tag> conv_types;
|
||||
vertex_converter<box2d<double>, 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<T>::process(polygon_symbolizer const& sym,
|
|||
if (sym.clip()) converter.set<clip_poly_tag>(); //optional clip (default: true)
|
||||
converter.set<transform_tag>(); //always transform
|
||||
converter.set<affine_transform_tag>();
|
||||
if (sym.simplify_tolerance() > 0.0) converter.set<simplify_tag>(); // optional simplify converter
|
||||
if (sym.smooth() > 0.0) converter.set<smooth_tag>(); // optional smooth converter
|
||||
|
||||
BOOST_FOREACH( geometry_type & geom, feature.paths())
|
||||
|
|
|
@ -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<clip_poly_tag,transform_tag,affine_transform_tag,smooth_tag> conv_types;
|
||||
typedef boost::mpl::vector<clip_poly_tag,transform_tag,affine_transform_tag,simplify_tag,smooth_tag> conv_types;
|
||||
vertex_converter<box2d<double>, 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<clip_poly_tag>(); //optional clip (default: true)
|
||||
converter.set<transform_tag>(); //always transform
|
||||
converter.set<affine_transform_tag>();
|
||||
if (sym.simplify_tolerance() > 0.0) converter.set<simplify_tag>(); // optional simplify converter
|
||||
if (sym.smooth() > 0.0) converter.set<smooth_tag>(); // 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<double> ext = query_extent_ * 1.1;
|
||||
typedef boost::mpl::vector<clip_line_tag, clip_poly_tag, transform_tag, offset_transform_tag, affine_transform_tag, smooth_tag> conv_types;
|
||||
typedef boost::mpl::vector<clip_line_tag, clip_poly_tag, transform_tag, offset_transform_tag, affine_transform_tag, simplify_tag, smooth_tag> conv_types;
|
||||
vertex_converter<box2d<double>, 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<transform_tag>(); // always transform
|
||||
if (fabs(sym.offset()) > 0.0) converter.set<offset_transform_tag>(); // parallel offset
|
||||
converter.set<affine_transform_tag>(); // optional affine transform
|
||||
if (sym.simplify_tolerance() > 0.0) converter.set<simplify_tag>(); // optional simplify converter
|
||||
if (sym.smooth() > 0.0) converter.set<smooth_tag>(); // 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<clip_poly_tag,transform_tag,affine_transform_tag,smooth_tag> conv_types;
|
||||
typedef boost::mpl::vector<clip_poly_tag,transform_tag,affine_transform_tag,simplify_tag,smooth_tag> conv_types;
|
||||
vertex_converter<box2d<double>, 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<clip_poly_tag>(); //optional clip (default: true)
|
||||
converter.set<transform_tag>(); //always transform
|
||||
converter.set<affine_transform_tag>();
|
||||
if (sym.simplify_tolerance() > 0.0) converter.set<simplify_tag>(); // optional simplify converter
|
||||
if (sym.smooth() > 0.0) converter.set<smooth_tag>(); // optional smooth converter
|
||||
|
||||
BOOST_FOREACH( geometry_type & geom, feature.paths())
|
||||
|
|
|
@ -54,7 +54,7 @@ void grid_renderer<T>::process(line_symbolizer const& sym,
|
|||
typedef agg::renderer_scanline_bin_solid<renderer_base> renderer_type;
|
||||
typedef boost::mpl::vector<clip_line_tag, transform_tag,
|
||||
offset_transform_tag, affine_transform_tag,
|
||||
smooth_tag, dash_tag, stroke_tag> 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<T>::process(line_symbolizer const& sym,
|
|||
converter.set<transform_tag>(); // always transform
|
||||
if (fabs(sym.offset()) > 0.0) converter.set<offset_transform_tag>(); // parallel offset
|
||||
converter.set<affine_transform_tag>(); // optional affine transform
|
||||
if (sym.simplify_tolerance() > 0.0) converter.set<simplify_tag>(); // optional simplify converter
|
||||
if (sym.smooth() > 0.0) converter.set<smooth_tag>(); // optional smooth converter
|
||||
if (stroke_.has_dash()) converter.set<dash_tag>();
|
||||
converter.set<stroke_tag>(); //always stroke
|
||||
|
|
|
@ -55,7 +55,7 @@ void grid_renderer<T>::process(polygon_symbolizer const& sym,
|
|||
agg::trans_affine tr;
|
||||
evaluate_transform(tr, feature, sym.get_transform());
|
||||
|
||||
typedef boost::mpl::vector<clip_poly_tag,transform_tag,affine_transform_tag,smooth_tag> conv_types;
|
||||
typedef boost::mpl::vector<clip_poly_tag,transform_tag,affine_transform_tag,simplify_tag,smooth_tag> conv_types;
|
||||
vertex_converter<box2d<double>, 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<T>::process(polygon_symbolizer const& sym,
|
|||
if (sym.clip()) converter.set<clip_poly_tag>(); //optional clip (default: true)
|
||||
converter.set<transform_tag>(); //always transform
|
||||
converter.set<affine_transform_tag>();
|
||||
if (sym.simplify_tolerance() > 0.0) converter.set<simplify_tag>(); // optional simplify converter
|
||||
if (sym.smooth() > 0.0) converter.set<smooth_tag>(); // optional smooth converter
|
||||
|
||||
|
||||
|
|
|
@ -882,6 +882,10 @@ void map_parser::parse_symbolizer_base(symbolizer_base &sym, xml_node const &pt)
|
|||
optional<boolean> clip = pt.get_opt_attr<boolean>("clip");
|
||||
if (clip) sym.set_clip(*clip);
|
||||
|
||||
// simplify value
|
||||
optional<double> simplify_tolerance = pt.get_opt_attr<double>("simplify-tolerance");
|
||||
if (simplify_tolerance) sym.set_simplify_tolerance(*simplify_tolerance);
|
||||
|
||||
// smooth value
|
||||
optional<double> smooth = pt.get_opt_attr<double>("smooth");
|
||||
if (smooth) sym.set_smooth(*smooth);
|
||||
|
|
|
@ -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() );
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue