From a49e1d075e75ac5ddc6101e7d85c15c8688b5a32 Mon Sep 17 00:00:00 2001 From: artemp Date: Wed, 4 Jun 2014 18:05:27 +0100 Subject: [PATCH 01/10] initial refactor pass (fixes #2235) --- include/mapnik/grid/grid_marker_helpers.hpp | 64 ++++++++--------- include/mapnik/marker_helpers.hpp | 49 +++++++------ .../process_markers_symbolizer.hpp | 66 +++++++++++++----- include/mapnik/svg/svg_renderer_agg.hpp | 16 +++-- include/mapnik/vertex_converters.hpp | 3 +- src/agg/process_markers_symbolizer.cpp | 52 +++----------- src/grid/process_markers_symbolizer.cpp | 68 ++++--------------- 7 files changed, 147 insertions(+), 171 deletions(-) diff --git a/include/mapnik/grid/grid_marker_helpers.hpp b/include/mapnik/grid/grid_marker_helpers.hpp index c1b4ba3c5..4f73e2d0f 100644 --- a/include/mapnik/grid/grid_marker_helpers.hpp +++ b/include/mapnik/grid/grid_marker_helpers.hpp @@ -41,26 +41,28 @@ namespace mapnik { -template -struct raster_markers_rasterizer_dispatch_grid +template +struct raster_markers_rasterizer_dispatch_grid : mapnik::noncopyable { typedef typename RendererBase::pixfmt_type pixfmt_type; typedef typename RendererBase::pixfmt_type::color_type color_type; - raster_markers_rasterizer_dispatch_grid(BufferType & render_buffer, - Rasterizer & ras, - image_data_32 const& src, - agg::trans_affine const& marker_trans, - markers_symbolizer const& sym, - Detector & detector, - double scale_factor, - mapnik::feature_impl const& feature, - attributes const& vars, - PixMapType & pixmap) - : buf_(render_buffer), + typedef typename std::tuple_element<0,RendererContext>::type BufferType; + typedef typename std::tuple_element<1,RendererContext>::type RasterizerType; + typedef typename std::tuple_element<2,RendererContext>::type PixMapType; + + raster_markers_rasterizer_dispatch_grid(image_data_32 const& src, + agg::trans_affine const& marker_trans, + markers_symbolizer const& sym, + Detector & detector, + double scale_factor, + mapnik::feature_impl const& feature, + attributes const& vars, + RendererContext const& renderer_context) + : buf_(std::get<0>(renderer_context)), pixf_(buf_), renb_(pixf_), - ras_(ras), + ras_(std::get<1>(renderer_context)), src_(src), marker_trans_(marker_trans), sym_(sym), @@ -68,10 +70,8 @@ struct raster_markers_rasterizer_dispatch_grid scale_factor_(scale_factor), feature_(feature), vars_(vars), - pixmap_(pixmap), - placed_(false) - { - } + pixmap_(std::get<2>(renderer_context)), + placed_(false) {} template void add_path(T & path) @@ -175,9 +175,9 @@ struct raster_markers_rasterizer_dispatch_grid private: BufferType & buf_; - PixFmt pixf_; + pixfmt_type pixf_; RendererBase renb_; - Rasterizer & ras_; + RasterizerType & ras_; image_data_32 const& src_; agg::trans_affine const& marker_trans_; markers_symbolizer const& sym_; @@ -190,18 +190,20 @@ private: }; -template -struct vector_markers_rasterizer_dispatch_grid +template +struct vector_markers_rasterizer_dispatch_grid : mapnik::noncopyable { typedef typename SvgRenderer::renderer_base renderer_base; typedef typename SvgRenderer::vertex_source_type vertex_source_type; typedef typename SvgRenderer::attribute_source_type attribute_source_type; typedef typename renderer_base::pixfmt_type pixfmt_type; - vector_markers_rasterizer_dispatch_grid(BufferType & render_buffer, - vertex_source_type & path, + typedef typename std::tuple_element<0,RendererContext>::type BufferType; + typedef typename std::tuple_element<1,RendererContext>::type RasterizerType; + typedef typename std::tuple_element<2,RendererContext>::type PixMapType; + + vector_markers_rasterizer_dispatch_grid(vertex_source_type & path, attribute_source_type const& attrs, - Rasterizer & ras, box2d const& bbox, agg::trans_affine const& marker_trans, markers_symbolizer const& sym, @@ -209,12 +211,12 @@ struct vector_markers_rasterizer_dispatch_grid double scale_factor, mapnik::feature_impl const& feature, attributes const& vars, - PixMapType & pixmap) - : buf_(render_buffer), + RendererContext const& renderer_context) + : buf_(std::get<0>(renderer_context)), pixf_(buf_), renb_(pixf_), svg_renderer_(path, attrs), - ras_(ras), + ras_(std::get<1>(renderer_context)), bbox_(bbox), marker_trans_(marker_trans), sym_(sym), @@ -222,10 +224,9 @@ struct vector_markers_rasterizer_dispatch_grid scale_factor_(scale_factor), feature_(feature), vars_(vars), - pixmap_(pixmap), + pixmap_(std::get<2>(renderer_context)), placed_(false) { - //std::cerr << "vector_markers_rasterizer_dispatch_grid() ctor" << std::endl; } template @@ -272,7 +273,6 @@ struct vector_markers_rasterizer_dispatch_grid detector_.has_placement(transformed_bbox)) { svg_renderer_.render_id(ras_, sl_, renb_, feature_.id(), matrix, opacity, bbox_); - if (!ignore_placement) { detector_.insert(transformed_bbox); @@ -312,7 +312,7 @@ private: pixfmt_type pixf_; renderer_base renb_; SvgRenderer svg_renderer_; - Rasterizer & ras_; + RasterizerType & ras_; box2d const& bbox_; agg::trans_affine const& marker_trans_; markers_symbolizer const& sym_; diff --git a/include/mapnik/marker_helpers.hpp b/include/mapnik/marker_helpers.hpp index e5167e1b7..9885a622c 100644 --- a/include/mapnik/marker_helpers.hpp +++ b/include/mapnik/marker_helpers.hpp @@ -59,31 +59,33 @@ namespace mapnik { -template -struct vector_markers_rasterizer_dispatch +template +struct vector_markers_rasterizer_dispatch : mapnik::noncopyable { typedef typename SvgRenderer::renderer_base renderer_base; typedef typename SvgRenderer::vertex_source_type vertex_source_type; typedef typename SvgRenderer::attribute_source_type attribute_source_type; typedef typename renderer_base::pixfmt_type pixfmt_type; - vector_markers_rasterizer_dispatch(BufferType & render_buffer, - vertex_source_type &path, + typedef typename std::tuple_element<0,RendererContext>::type BufferType; + typedef typename std::tuple_element<1,RendererContext>::type RasterizerType; + + vector_markers_rasterizer_dispatch(vertex_source_type & path, attribute_source_type const &attrs, - Rasterizer & ras, box2d const& bbox, agg::trans_affine const& marker_trans, markers_symbolizer const& sym, Detector & detector, + double scale_factor, feature_impl & feature, attributes const& vars, - double scale_factor, - bool snap_to_pixels) - : buf_(render_buffer), + RendererContext const& renderer_context, + bool snap_to_pixels = false) + : buf_(std::get<0>(renderer_context)), pixf_(buf_), renb_(pixf_), svg_renderer_(path, attrs), - ras_(ras), + ras_(std::get<1>(renderer_context)), bbox_(bbox), marker_trans_(marker_trans), sym_(sym), @@ -177,7 +179,7 @@ private: pixfmt_type pixf_; renderer_base renb_; SvgRenderer svg_renderer_; - Rasterizer & ras_; + RasterizerType & ras_; box2d const& bbox_; agg::trans_affine const& marker_trans_; markers_symbolizer const& sym_; @@ -188,9 +190,12 @@ private: bool snap_to_pixels_; }; -template -struct raster_markers_rasterizer_dispatch +template +struct raster_markers_rasterizer_dispatch : mapnik::noncopyable { + typedef typename std::remove_reference::type>::type BufferType; + typedef typename std::tuple_element<1,RendererContext>::type RasterizerType; + typedef agg::rgba8 color_type; typedef agg::order_rgba order_type; typedef agg::pixel32_type pixel_type; @@ -198,20 +203,21 @@ struct raster_markers_rasterizer_dispatch typedef agg::pixfmt_custom_blend_rgba pixfmt_comp_type; typedef agg::renderer_base renderer_base; - raster_markers_rasterizer_dispatch(BufferType & render_buffer, - Rasterizer & ras, - image_data_32 const& src, + + + raster_markers_rasterizer_dispatch(image_data_32 const& src, agg::trans_affine const& marker_trans, markers_symbolizer const& sym, Detector & detector, + double scale_factor, feature_impl & feature, attributes const& vars, - double scale_factor, - bool snap_to_pixels) - : buf_(render_buffer), + RendererContext const& renderer_context, + bool snap_to_pixels = false) + : buf_(std::get<0>(renderer_context)), pixf_(buf_), renb_(pixf_), - ras_(ras), + ras_(std::get<1>(renderer_context)), src_(src), marker_trans_(marker_trans), sym_(sym), @@ -362,7 +368,7 @@ private: BufferType & buf_; pixfmt_comp_type pixf_; renderer_base renb_; - Rasterizer & ras_; + RasterizerType & ras_; image_data_32 const& src_; agg::trans_affine const& marker_trans_; markers_symbolizer const& sym_; @@ -512,7 +518,7 @@ void setup_transform_scaling(agg::trans_affine & tr, // Apply markers to a feature with multiple geometries template -void apply_markers_multi(feature_impl const& feature, attributes const& vars, Converter& converter, markers_symbolizer const& sym) +void apply_markers_multi(feature_impl const& feature, attributes const& vars, Converter & converter, markers_symbolizer const& sym) { std::size_t geom_count = feature.paths().size(); if (geom_count == 1) @@ -523,6 +529,7 @@ void apply_markers_multi(feature_impl const& feature, attributes const& vars, Co { marker_multi_policy_enum multi_policy = get(sym, keys::markers_multipolicy, feature, vars, MARKER_EACH_MULTI); marker_placement_enum placement = get(sym, keys::markers_placement_type, feature, vars, MARKER_POINT_PLACEMENT); + if (placement == MARKER_POINT_PLACEMENT && multi_policy == MARKER_WHOLE_MULTI) { diff --git a/include/mapnik/renderer_common/process_markers_symbolizer.hpp b/include/mapnik/renderer_common/process_markers_symbolizer.hpp index 82f1ffb86..82893e4e5 100644 --- a/include/mapnik/renderer_common/process_markers_symbolizer.hpp +++ b/include/mapnik/renderer_common/process_markers_symbolizer.hpp @@ -29,16 +29,19 @@ namespace mapnik { -template +template void render_markers_symbolizer(markers_symbolizer const& sym, mapnik::feature_impl & feature, proj_transform const& prj_trans, renderer_common const& common, box2d const& clip_box, - F1 make_vector_dispatch, - F2 make_raster_dispatch) + T2 const& renderer_context) { using namespace mapnik::svg; + typedef T0 vector_dispatch_type; + typedef T1 raster_dispatch_type; + typedef T2 renderer_context_type; + typedef boost::mpl::vector conv_types; typedef agg::pod_bvector svg_attribute_type; @@ -77,12 +80,22 @@ void render_markers_symbolizer(markers_symbolizer const& sym, if (image_transform) evaluate_transform(tr, feature, common.vars_, *image_transform); box2d bbox = marker_ellipse.bounding_box(); - auto rasterizer_dispatch = make_vector_dispatch( - svg_path, result ? attributes : (*stock_vector_marker)->attributes(), - marker_ellipse, bbox, tr, snap_pixels); - typedef decltype(rasterizer_dispatch) dispatch_type; + vector_dispatch_type rasterizer_dispatch(//std::get<0>(renderer_context), // render_buf + svg_path, + result ? attributes : (*stock_vector_marker)->attributes(), + //std::get<1>(renderer_context), // rasterizer + bbox, + tr, + sym, + *common.detector_, + common.scale_factor_, + feature, + common.vars_, + renderer_context); - vertex_converter, dispatch_type, markers_symbolizer, + //std::get<2>(renderer_context)); // pixmap + + vertex_converter, vector_dispatch_type, markers_symbolizer, CoordTransform, proj_transform, agg::trans_affine, conv_types, feature_impl> converter(clip_box, rasterizer_dispatch, sym,common.t_,prj_trans,tr,feature,common.vars_,common.scale_factor_); if (clip && feature.paths().size() > 0) // optional clip (default: true) @@ -109,12 +122,22 @@ void render_markers_symbolizer(markers_symbolizer const& sym, svg_path_adapter svg_path(stl_storage); svg_attribute_type attributes; bool result = push_explicit_style( (*stock_vector_marker)->attributes(), attributes, sym, feature, common.vars_); - auto rasterizer_dispatch = make_vector_dispatch( - svg_path, result ? attributes : (*stock_vector_marker)->attributes(), - **stock_vector_marker, bbox, tr, snap_pixels); - typedef decltype(rasterizer_dispatch) dispatch_type; + // TODO - clamping to >= 4 pixels + coord2d center = bbox.center(); + agg::trans_affine_translation recenter(-center.x, -center.y); + agg::trans_affine marker_trans = recenter * tr; + vector_dispatch_type rasterizer_dispatch(svg_path, + result ? attributes : (*stock_vector_marker)->attributes(), + bbox, + marker_trans, + sym, + *common.detector_, + common.scale_factor_, + feature, + common.vars_, + renderer_context); - vertex_converter, dispatch_type, markers_symbolizer, + vertex_converter, vector_dispatch_type, markers_symbolizer, CoordTransform, proj_transform, agg::trans_affine, conv_types, feature_impl> converter(clip_box, rasterizer_dispatch, sym,common.t_,prj_trans,tr,feature,common.vars_,common.scale_factor_); if (clip && feature.paths().size() > 0) // optional clip (default: true) @@ -140,10 +163,21 @@ void render_markers_symbolizer(markers_symbolizer const& sym, box2d const& bbox = (*mark)->bounding_box(); boost::optional marker = (*mark)->get_bitmap_data(); - auto rasterizer_dispatch = make_raster_dispatch(**marker, tr, bbox); - typedef decltype(rasterizer_dispatch) dispatch_type; + // - clamp sizes to > 4 pixels of interactivity + coord2d center = bbox.center(); + agg::trans_affine_translation recenter(-center.x, -center.y); + agg::trans_affine marker_trans = recenter * tr; - vertex_converter, dispatch_type, markers_symbolizer, + raster_dispatch_type rasterizer_dispatch(**marker, + marker_trans, + sym, + *common.detector_, + common.scale_factor_, + feature, + common.vars_, + renderer_context); + + vertex_converter, raster_dispatch_type, markers_symbolizer, CoordTransform, proj_transform, agg::trans_affine, conv_types, feature_impl> converter(clip_box, rasterizer_dispatch, sym,common.t_,prj_trans,tr,feature,common.vars_,common.scale_factor_); diff --git a/include/mapnik/svg/svg_renderer_agg.hpp b/include/mapnik/svg/svg_renderer_agg.hpp index bcdb04857..077f2e300 100644 --- a/include/mapnik/svg/svg_renderer_agg.hpp +++ b/include/mapnik/svg/svg_renderer_agg.hpp @@ -116,9 +116,11 @@ public: curved_stroked_(curved_), attributes_(attributes) {} - svg_renderer_agg(svg_renderer_agg &&r) - : source_(r.source_), curved_(source_), curved_stroked_(curved_), - attributes_(r.attributes_) {} + //svg_renderer_agg(svg_renderer_agg const& rhs) + // : source_(rhs.source_), + // curved_(source_), + // curved_stroked_(curved_), + // attributes_(rhs.attributes_) {} template void render_gradient(Rasterizer& ras, @@ -426,11 +428,13 @@ public: } #endif + inline VertexSource & source() const { return source_;} + inline AttributeSource const& attributes() const { return attributes_;} private: - VertexSource & source_; - curved_type curved_; - curved_stroked_type curved_stroked_; + VertexSource & source_; + curved_type curved_; + curved_stroked_type curved_stroked_; AttributeSource const& attributes_; }; diff --git a/include/mapnik/vertex_converters.hpp b/include/mapnik/vertex_converters.hpp index 8ef6c24f5..9c96f2de6 100644 --- a/include/mapnik/vertex_converters.hpp +++ b/include/mapnik/vertex_converters.hpp @@ -293,7 +293,8 @@ struct dispatcher dispatcher(args_type const& args) : args_(args) { - std::memset(&vec_[0], 0, sizeof(unsigned)*vec_.size()); + //std::memset(&vec_[0], 0, sizeof(unsigned)*vec_.size()); + std::fill(vec_.begin(), vec_.end(), 0); } template diff --git a/src/agg/process_markers_symbolizer.cpp b/src/agg/process_markers_symbolizer.cpp index dafec0588..2934b9858 100644 --- a/src/agg/process_markers_symbolizer.cpp +++ b/src/agg/process_markers_symbolizer.cpp @@ -76,11 +76,8 @@ void agg_renderer::process(markers_symbolizer const& sym, svg_attribute_type, renderer_type, pixfmt_comp_type > svg_renderer_type; - typedef vector_markers_rasterizer_dispatch vector_dispatch_type; - typedef raster_markers_rasterizer_dispatch raster_dispatch_type; + + ras_ptr->reset(); double gamma = get(sym, keys::gamma, feature, common_.vars_, 1.0); gamma_method_enum gamma_method = get(sym, keys::gamma_method, feature, common_.vars_, GAMMA_POWER); @@ -90,46 +87,17 @@ void agg_renderer::process(markers_symbolizer const& sym, gamma_method_ = gamma_method; gamma_ = gamma; } - - buf_type render_buffer(current_buffer_->raw_data(), current_buffer_->width(), current_buffer_->height(), current_buffer_->width() * 4); - ras_ptr->reset(); + buf_type render_buffer(current_buffer_->raw_data(), current_buffer_->width(), current_buffer_->height(), current_buffer_->width() * 4); box2d clip_box = clipping_extent(); - render_markers_symbolizer( - sym, feature, prj_trans, common_, clip_box, - [&](svg_path_adapter &path, svg_attribute_type const &attr, svg_storage_type &, - box2d const &bbox, agg::trans_affine const &tr, - bool snap_pixels) -> vector_dispatch_type { - coord2d center = bbox.center(); - agg::trans_affine_translation recenter(-center.x, -center.y); - agg::trans_affine marker_trans = recenter * tr; - return vector_dispatch_type(render_buffer, - path, attr, - *ras_ptr, - bbox, - marker_trans, - sym, - *common_.detector_, - feature, common_.vars_, - common_.scale_factor_, - snap_pixels); - }, - [&](image_data_32 const &marker, agg::trans_affine const &tr, - box2d const &bbox) -> raster_dispatch_type { - coord2d center = bbox.center(); - agg::trans_affine_translation recenter(-center.x, -center.y); - agg::trans_affine marker_trans = recenter * tr; - return raster_dispatch_type(render_buffer, - *ras_ptr, - marker, - marker_trans, - sym, - *common_.detector_, - feature, common_.vars_, - common_.scale_factor_, - true /*snap rasters no matter what*/); - }); + auto renderer_context = std::tie(render_buffer,*ras_ptr,pixmap_); + typedef decltype(renderer_context) context_type; + typedef vector_markers_rasterizer_dispatch vector_dispatch_type; + typedef raster_markers_rasterizer_dispatch raster_dispatch_type; + + render_markers_symbolizer( + sym, feature, prj_trans, common_, clip_box, renderer_context); } template void agg_renderer::process(markers_symbolizer const&, diff --git a/src/grid/process_markers_symbolizer.cpp b/src/grid/process_markers_symbolizer.cpp index 376d4ada7..b47bd4335 100644 --- a/src/grid/process_markers_symbolizer.cpp +++ b/src/grid/process_markers_symbolizer.cpp @@ -74,7 +74,7 @@ porting notes --> // stl #include - +#include namespace mapnik { @@ -94,63 +94,25 @@ void grid_renderer::process(markers_symbolizer const& sym, svg_attribute_type, renderer_type, pixfmt_type > svg_renderer_type; - typedef vector_markers_rasterizer_dispatch_grid vector_dispatch_type; - typedef raster_markers_rasterizer_dispatch_grid raster_dispatch_type; buf_type render_buf(pixmap_.raw_data(), common_.width_, common_.height_, common_.width_); ras_ptr->reset(); box2d clip_box = common_.query_extent_; - render_markers_symbolizer( - sym, feature, prj_trans, common_, clip_box, - [&](svg_path_adapter & path, svg_attribute_type const& attr, svg_storage_type &, - box2d const& bbox, agg::trans_affine const& tr, - bool) -> vector_dispatch_type - { - // TODO - clamping to >= 4 pixels - coord2d center = bbox.center(); - agg::trans_affine_translation recenter(-center.x, -center.y); - agg::trans_affine marker_trans = recenter * tr; - return vector_dispatch_type(render_buf, - path, attr, - *ras_ptr, - bbox, - marker_trans, - sym, - *common_.detector_, - common_.scale_factor_, - feature, - common_.vars_, - pixmap_); - }, - [&](image_data_32 const& marker, agg::trans_affine const& tr, - box2d const& bbox) -> raster_dispatch_type - { - // - clamp sizes to > 4 pixels of interactivity - coord2d center = bbox.center(); - agg::trans_affine_translation recenter(-center.x, -center.y); - agg::trans_affine marker_trans = recenter * tr; - return raster_dispatch_type(render_buf, - *ras_ptr, - marker, - marker_trans, - sym, - *common_.detector_, - common_.scale_factor_, - feature, - common_.vars_, - pixmap_); - }); + auto renderer_context = std::tie(render_buf,*ras_ptr,pixmap_); + typedef decltype(renderer_context) context_type; + + typedef vector_markers_rasterizer_dispatch_grid vector_dispatch_type; + + typedef raster_markers_rasterizer_dispatch_grid raster_dispatch_type; + + render_markers_symbolizer( + sym, feature, prj_trans, common_, clip_box,renderer_context); } template void grid_renderer::process(markers_symbolizer const&, From 27b4faf4e73b61bf07a9dc8f95002c1bfe0be8b9 Mon Sep 17 00:00:00 2001 From: artemp Date: Wed, 4 Jun 2014 18:12:35 +0100 Subject: [PATCH 02/10] remove dead code --- include/mapnik/marker_helpers.hpp | 2 -- include/mapnik/svg/svg_renderer_agg.hpp | 6 ------ 2 files changed, 8 deletions(-) diff --git a/include/mapnik/marker_helpers.hpp b/include/mapnik/marker_helpers.hpp index 9885a622c..3c0c3e581 100644 --- a/include/mapnik/marker_helpers.hpp +++ b/include/mapnik/marker_helpers.hpp @@ -203,8 +203,6 @@ struct raster_markers_rasterizer_dispatch : mapnik::noncopyable typedef agg::pixfmt_custom_blend_rgba pixfmt_comp_type; typedef agg::renderer_base renderer_base; - - raster_markers_rasterizer_dispatch(image_data_32 const& src, agg::trans_affine const& marker_trans, markers_symbolizer const& sym, diff --git a/include/mapnik/svg/svg_renderer_agg.hpp b/include/mapnik/svg/svg_renderer_agg.hpp index 077f2e300..2e0eddaf5 100644 --- a/include/mapnik/svg/svg_renderer_agg.hpp +++ b/include/mapnik/svg/svg_renderer_agg.hpp @@ -116,12 +116,6 @@ public: curved_stroked_(curved_), attributes_(attributes) {} - //svg_renderer_agg(svg_renderer_agg const& rhs) - // : source_(rhs.source_), - // curved_(source_), - // curved_stroked_(curved_), - // attributes_(rhs.attributes_) {} - template void render_gradient(Rasterizer& ras, Scanline& sl, From c276e7dcac5a8b37d89bc3cec7d55c6e8a43c071 Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Wed, 4 Jun 2014 10:51:07 -0700 Subject: [PATCH 03/10] re-enable clang since #2235 should be fixed soon --- .travis.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 151d7ec22..38c03c066 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,8 +2,7 @@ language: cpp compiler: - gcc - # disabled to due https://github.com/mapnik/mapnik/issues/2235 - #- clang + - clang # http://about.travis-ci.org/blog/2013-11-29-postgresql-92-93-now-available/ addons: From 147a289936e3c6fc743ee5758a5cff97aac426ad Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Wed, 4 Jun 2014 09:31:20 -0700 Subject: [PATCH 04/10] update travis script --- .travis.yml | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/.travis.yml b/.travis.yml index 38c03c066..36337a626 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,10 +4,14 @@ compiler: - gcc - clang -# http://about.travis-ci.org/blog/2013-11-29-postgresql-92-93-now-available/ addons: postgresql: "9.3" +env: + - TESTS_TO_RUN=python BINDINGS=python CPP_TESTS=false BENCHMARK=false DEMO=False + - TESTS_TO_RUN=visual BINDINGS=python CPP_TESTS=false BENCHMARK=false DEMO=False + - TESTS_TO_RUN=cpp BINDINGS=none CPP_TESTS=true BENCHMARK=true DEMO=True + before_install: # we need at least g++-4.7 for c++11 features - sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test @@ -20,36 +24,26 @@ before_install: # upgrade compilers - sudo apt-get install -y gcc-4.8 g++-4.8 - sudo apt-get install -y make boost1.55 libgdal-dev python-nose libicu-dev libpng-dev libjpeg-dev libtiff-dev libwebp-dev libz-dev libfreetype6-dev libxml2-dev libproj-dev libcairo-dev python-cairo-dev libsqlite3-dev - - wget http://mapnik.s3.amazonaws.com/deps/harfbuzz-0.9.24.tar.bz2 - - tar xf harfbuzz-0.9.24.tar.bz2 - - cd harfbuzz-0.9.24 + - wget http://mapnik.s3.amazonaws.com/deps/harfbuzz-0.9.29.tar.bz2 + - tar xf harfbuzz-0.9.29.tar.bz2 + - cd harfbuzz-0.9.29 - ./configure && make && sudo make install - sudo ldconfig - cd ../ - - createdb template_postgis - - psql -c "CREATE EXTENSION postgis" template_postgis install: - - if [ "${CXX}" = 'g++' ]; then export CXX="g++-4.8" && export CC="gcc-4.8"; fi; - - ./configure CXX="nice ${CXX}" CC="nice ${CC}" DEMO=False BINDINGS=${BINDINGS} BENCHMARK=${BENCHMARK} CPP_TESTS=${CPP_TESTS} CAIRO=True FAST=True || cat config.log - - JOBS=4 make - -env: - - TESTS_TO_RUN=python BINDINGS=python CPP_TESTS=false BENCHMARK=false - - TESTS_TO_RUN=visual BINDINGS=python CPP_TESTS=false BENCHMARK=false - - TESTS_TO_RUN=cpp BINDINGS=none CPP_TESTS=true BENCHMARK=true + - if [[ "${CXX}" == 'g++' ]]; then export CXX="g++-4.8" && export CC="gcc-4.8"; fi; + - ./configure CXX="nice ${CXX}" CC="nice ${CC}" DEMO=${DEMO} BINDINGS=${BINDINGS} BENCHMARK=${BENCHMARK} CPP_TESTS=${CPP_TESTS} CAIRO=True FAST=True + - JOBS=3 make before_script: - make test-$TESTS_TO_RUN script: - - if [ "${BENCHMARK}" = true ]; then make bench; fi; + - if [[ "${BENCHMARK}" == true ]]; then make bench; fi; notifications: irc: channels: - "irc.freenode.org#mapnik" use_notice: true - email: - on_success: [never] - on_failure: [change] From c489549b56861520b0d120034150f82a67faf953 Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Wed, 4 Jun 2014 12:09:42 -0700 Subject: [PATCH 05/10] add benchmark of utf 32->8 encoding speed --- benchmark/test_utf_encoding.cpp | 100 ++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 benchmark/test_utf_encoding.cpp diff --git a/benchmark/test_utf_encoding.cpp b/benchmark/test_utf_encoding.cpp new file mode 100644 index 000000000..ad7fcc361 --- /dev/null +++ b/benchmark/test_utf_encoding.cpp @@ -0,0 +1,100 @@ +#include "bench_framework.hpp" +#include +#include +#include +#include + +class test : public benchmark::test_case +{ + std::string utf8_; +public: + test(mapnik::parameters const& params) + : test_case(params), + utf8_(u8"שלום") {} + bool validate() const + { + std::wstring_convert, char32_t> utf32conv; + std::u32string utf32 = utf32conv.from_bytes(utf8_); + if (utf32.size() != 4) return false; + if (utf32[0] != 0x5e9 && + utf32[1] != 0x5dc && + utf32[2] != 0x5d5 && + utf32[3] != 0x5dd) return false; + return true; + } + void operator()() const + { + std::u32string utf32; + std::wstring_convert, char32_t> utf32conv; + for (std::size_t i=0;i(utf8_); + if (utf32.size() != 4) return false; + if (utf32[0] != 0x5e9 && + utf32[1] != 0x5dc && + utf32[2] != 0x5d5 && + utf32[3] != 0x5dd) return false; + return true; + } + void operator()() const + { + std::u32string utf32; + for (std::size_t i=0;i(utf8_); + } + } +}; + +class test3 : public benchmark::test_case +{ + std::string utf8_; +public: + test3(mapnik::parameters const& params) + : test_case(params), + utf8_(u8"שלום") {} + bool validate() const + { + mapnik::transcoder tr_("utf-8"); + mapnik::value_unicode_string utf32 = tr_.transcode(utf8_.data(),utf8_.size()); + //std::u32string utf32 = boost::locale::conv::utf_to_utf(utf8_); + if (utf32.length() != 4) return false; + if (utf32[0] != 0x5e9 && + utf32[1] != 0x5dc && + utf32[2] != 0x5d5 && + utf32[3] != 0x5dd) return false; + return true; + } + void operator()() const + { + mapnik::transcoder tr_("utf-8"); + mapnik::value_unicode_string utf32; + for (std::size_t i=0;i Date: Wed, 4 Jun 2014 14:45:33 -0700 Subject: [PATCH 06/10] fix compile of utf encoding benchmark on linux --- benchmark/test_utf_encoding.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/benchmark/test_utf_encoding.cpp b/benchmark/test_utf_encoding.cpp index ad7fcc361..ea11eda43 100644 --- a/benchmark/test_utf_encoding.cpp +++ b/benchmark/test_utf_encoding.cpp @@ -1,8 +1,9 @@ #include "bench_framework.hpp" #include #include -#include #include +#ifndef __linux__ +#include class test : public benchmark::test_case { @@ -32,6 +33,8 @@ public: } }; +#endif + class test2 : public benchmark::test_case { std::string utf8_; @@ -91,8 +94,12 @@ int main(int argc, char** argv) { mapnik::parameters params; benchmark::handle_args(argc,argv,params); +#ifndef __linux__ test test_runner(params); run(test_runner,"utf encode std::codecvt"); +#else + std::clog << "skipping 'utf encode std::codecvt' test since is not supported on __linux__\n"; +#endif test2 test_runner2(params); run(test_runner2,"utf encode boost::locale"); test3 test_runner3(params); From 961bc69a1cd1826d1dc65ecac8df1b801a0913bf Mon Sep 17 00:00:00 2001 From: artemp Date: Thu, 5 Jun 2014 10:14:18 +0100 Subject: [PATCH 07/10] cleanup+format --- include/mapnik/marker_helpers.hpp | 33 +++++++------------------------ 1 file changed, 7 insertions(+), 26 deletions(-) diff --git a/include/mapnik/marker_helpers.hpp b/include/mapnik/marker_helpers.hpp index 3c0c3e581..a4bee9e4c 100644 --- a/include/mapnik/marker_helpers.hpp +++ b/include/mapnik/marker_helpers.hpp @@ -58,7 +58,6 @@ namespace mapnik { - template struct vector_markers_rasterizer_dispatch : mapnik::noncopyable { @@ -71,7 +70,7 @@ struct vector_markers_rasterizer_dispatch : mapnik::noncopyable typedef typename std::tuple_element<1,RendererContext>::type RasterizerType; vector_markers_rasterizer_dispatch(vertex_source_type & path, - attribute_source_type const &attrs, + attribute_source_type const& attrs, box2d const& bbox, agg::trans_affine const& marker_trans, markers_symbolizer const& sym, @@ -114,24 +113,15 @@ struct vector_markers_rasterizer_dispatch : mapnik::noncopyable double y = 0; if (path.type() == mapnik::geometry_type::types::LineString) { - if (!label::middle_point(path, x, y)) - { - return; - } + if (!label::middle_point(path, x, y)) return; } else if (placement_method == MARKER_INTERIOR_PLACEMENT) { - if (!label::interior_position(path, x, y)) - { - return; - } + if (!label::interior_position(path, x, y)) return; } else { - if (!label::centroid(path, x, y)) - { - return; - } + if (!label::centroid(path, x, y)) return; } agg::trans_affine matrix = marker_trans_; matrix.translate(x,y); @@ -244,24 +234,15 @@ struct raster_markers_rasterizer_dispatch : mapnik::noncopyable double y = 0; if (path.type() == mapnik::geometry_type::types::LineString) { - if (!label::middle_point(path, x, y)) - { - return; - } + if (!label::middle_point(path, x, y)) return; } else if (placement_method == MARKER_INTERIOR_PLACEMENT) { - if (!label::interior_position(path, x, y)) - { - return; - } + if (!label::interior_position(path, x, y)) return; } else { - if (!label::centroid(path, x, y)) - { - return; - } + if (!label::centroid(path, x, y)) return; } agg::trans_affine matrix = marker_trans_; matrix.translate(x,y); From bbb727e39a8702a5a6c1d7e843c1abcdf359070c Mon Sep 17 00:00:00 2001 From: artemp Date: Thu, 5 Jun 2014 15:13:01 +0100 Subject: [PATCH 08/10] update cairo_renderer --- include/mapnik/grid/grid_marker_helpers.hpp | 1 + include/mapnik/marker_helpers.hpp | 4 +- .../process_markers_symbolizer.hpp | 18 ++- include/mapnik/svg/svg_path_adapter.hpp | 6 +- src/cairo_renderer.cpp | 135 +++++++++--------- 5 files changed, 81 insertions(+), 83 deletions(-) diff --git a/include/mapnik/grid/grid_marker_helpers.hpp b/include/mapnik/grid/grid_marker_helpers.hpp index 4f73e2d0f..ceb0bc042 100644 --- a/include/mapnik/grid/grid_marker_helpers.hpp +++ b/include/mapnik/grid/grid_marker_helpers.hpp @@ -211,6 +211,7 @@ struct vector_markers_rasterizer_dispatch_grid : mapnik::noncopyable double scale_factor, mapnik::feature_impl const& feature, attributes const& vars, + bool snap_to_pixels, RendererContext const& renderer_context) : buf_(std::get<0>(renderer_context)), pixf_(buf_), diff --git a/include/mapnik/marker_helpers.hpp b/include/mapnik/marker_helpers.hpp index a4bee9e4c..2c89dfe5f 100644 --- a/include/mapnik/marker_helpers.hpp +++ b/include/mapnik/marker_helpers.hpp @@ -78,8 +78,8 @@ struct vector_markers_rasterizer_dispatch : mapnik::noncopyable double scale_factor, feature_impl & feature, attributes const& vars, - RendererContext const& renderer_context, - bool snap_to_pixels = false) + bool snap_to_pixels, + RendererContext const& renderer_context) : buf_(std::get<0>(renderer_context)), pixf_(buf_), renb_(pixf_), diff --git a/include/mapnik/renderer_common/process_markers_symbolizer.hpp b/include/mapnik/renderer_common/process_markers_symbolizer.hpp index 82893e4e5..b9d213d19 100644 --- a/include/mapnik/renderer_common/process_markers_symbolizer.hpp +++ b/include/mapnik/renderer_common/process_markers_symbolizer.hpp @@ -50,7 +50,7 @@ void render_markers_symbolizer(markers_symbolizer const& sym, double smooth = get(sym, keys::smooth, feature, common.vars_, false); // https://github.com/mapnik/mapnik/issues/1316 - bool snap_pixels = !mapnik::marker_cache::instance().is_uri(filename); + bool snap_to_pixels = !mapnik::marker_cache::instance().is_uri(filename); if (!filename.empty()) { boost::optional mark = mapnik::marker_cache::instance().find(filename, true); @@ -79,22 +79,21 @@ void render_markers_symbolizer(markers_symbolizer const& sym, auto image_transform = get_optional(sym, keys::image_transform); if (image_transform) evaluate_transform(tr, feature, common.vars_, *image_transform); box2d bbox = marker_ellipse.bounding_box(); - - vector_dispatch_type rasterizer_dispatch(//std::get<0>(renderer_context), // render_buf - svg_path, + coord2d center = bbox.center(); + agg::trans_affine_translation recenter(-center.x, -center.y); + agg::trans_affine marker_trans = recenter * tr; + vector_dispatch_type rasterizer_dispatch(svg_path, result ? attributes : (*stock_vector_marker)->attributes(), - //std::get<1>(renderer_context), // rasterizer bbox, - tr, + marker_trans, sym, *common.detector_, common.scale_factor_, feature, common.vars_, + snap_to_pixels, renderer_context); - //std::get<2>(renderer_context)); // pixmap - vertex_converter, vector_dispatch_type, markers_symbolizer, CoordTransform, proj_transform, agg::trans_affine, conv_types, feature_impl> converter(clip_box, rasterizer_dispatch, sym,common.t_,prj_trans,tr,feature,common.vars_,common.scale_factor_); @@ -135,6 +134,7 @@ void render_markers_symbolizer(markers_symbolizer const& sym, common.scale_factor_, feature, common.vars_, + snap_to_pixels, renderer_context); vertex_converter, vector_dispatch_type, markers_symbolizer, @@ -162,12 +162,10 @@ void render_markers_symbolizer(markers_symbolizer const& sym, if (image_transform) evaluate_transform(tr, feature, common.vars_, *image_transform); box2d const& bbox = (*mark)->bounding_box(); boost::optional marker = (*mark)->get_bitmap_data(); - // - clamp sizes to > 4 pixels of interactivity coord2d center = bbox.center(); agg::trans_affine_translation recenter(-center.x, -center.y); agg::trans_affine marker_trans = recenter * tr; - raster_dispatch_type rasterizer_dispatch(**marker, marker_trans, sym, diff --git a/include/mapnik/svg/svg_path_adapter.hpp b/include/mapnik/svg/svg_path_adapter.hpp index e606a088b..943e6e076 100644 --- a/include/mapnik/svg/svg_path_adapter.hpp +++ b/include/mapnik/svg/svg_path_adapter.hpp @@ -25,7 +25,7 @@ // mapnik #include - +#include // agg #include "agg_math.h" #include "agg_array.h" @@ -937,6 +937,10 @@ public: return vertices_[idx].cmd; } + box2d const& bounding_box() const + { + vertices_.bounding_box(); + } private: Container & vertices_; }; diff --git a/src/cairo_renderer.cpp b/src/cairo_renderer.cpp index 33eb1db1e..519047572 100644 --- a/src/cairo_renderer.cpp +++ b/src/cairo_renderer.cpp @@ -419,13 +419,12 @@ void cairo_renderer_base::render_box(box2d const& b) context_.stroke(); } -void render_vector_marker(cairo_context & context, pixel_position const& pos, mapnik::svg_storage_type & vmarker, +void render_vector_marker(cairo_context & context, pixel_position const& pos, + svg::svg_path_adapter & svg_path, box2d const& bbox, agg::pod_bvector const & attributes, agg::trans_affine const& tr, double opacity, bool recenter) { using namespace mapnik::svg; - box2d bbox = vmarker.bounding_box(); - agg::trans_affine mtx = tr; if (recenter) @@ -459,9 +458,6 @@ void render_vector_marker(cairo_context & context, pixel_position const& pos, ma context.transform(matrix); } - vertex_stl_adapter stl_storage(vmarker.source()); - svg_path_adapter svg_path(stl_storage); - if (attr.fill_flag || attr.fill_gradient.get_gradient_type() != NO_GRADIENT) { context.add_agg_path(svg_path,attr.index); @@ -533,8 +529,11 @@ void cairo_renderer_base::render_marker(pixel_position const& pos, { agg::trans_affine marker_tr = tr; marker_tr *=agg::trans_affine_scaling(common_.scale_factor_); + box2d bbox = vmarker->bounding_box(); agg::pod_bvector const & attributes = vmarker->attributes(); - render_vector_marker(context_, pos, *vmarker, attributes, marker_tr, opacity, recenter); + svg::vertex_stl_adapter stl_storage(vmarker->source()); + svg::svg_path_adapter svg_path(stl_storage); + render_vector_marker(context_, pos, svg_path, bbox, attributes, marker_tr, opacity, recenter); } } else if (marker.is_bitmap()) @@ -563,7 +562,7 @@ void cairo_renderer_base::process(point_symbolizer const& sym, render_point_symbolizer( sym, feature, prj_trans, common_, - [&](pixel_position const& pos, marker const& marker, + [&](pixel_position const& pos, marker const& marker, agg::trans_affine const& tr, double opacity) { render_marker(pos, marker, tr, opacity); }); @@ -773,29 +772,31 @@ void cairo_renderer_base::process(raster_symbolizer const& sym, namespace detail { -template -struct markers_dispatch +template +struct markers_dispatch : mapnik::noncopyable { - markers_dispatch(Context & ctx, - SvgPath & marker, + markers_dispatch(SvgPath & marker, Attributes const& attributes, - Detector & detector, - markers_symbolizer const& sym, box2d const& bbox, agg::trans_affine const& marker_trans, + markers_symbolizer const& sym, + Detector & detector, + double scale_factor, feature_impl const& feature, mapnik::attributes const& vars, - double scale_factor) - :ctx_(ctx), - marker_(marker), - attributes_(attributes), - detector_(detector), - sym_(sym), - bbox_(bbox), - marker_trans_(marker_trans), - feature_(feature), - vars_(vars), - scale_factor_(scale_factor) {} + bool snap_to_pixels, + RendererContext const& renderer_context) + :marker_(marker), + attributes_(attributes), + bbox_(bbox), + marker_trans_(marker_trans), + sym_(sym), + detector_(detector), + scale_factor_(scale_factor), + feature_(feature), + vars_(vars), + ctx_(std::get<0>(renderer_context)) + {} template @@ -815,18 +816,15 @@ struct markers_dispatch double y = 0; if (path.type() == geometry_type::types::LineString) { - if (!label::middle_point(path, x, y)) - return; + if (!label::middle_point(path, x, y)) return; } else if (placement_method == MARKER_INTERIOR_PLACEMENT) { - if (!label::interior_position(path, x, y)) - return; + if (!label::interior_position(path, x, y)) return; } else { - if (!label::centroid(path, x, y)) - return; + if (!label::centroid(path, x, y)) return; } coord2d center = bbox_.center(); agg::trans_affine matrix = agg::trans_affine_translation(-center.x, -center.y); @@ -838,7 +836,7 @@ struct markers_dispatch if (allow_overlap || detector_.has_placement(transformed_bbox)) { - render_vector_marker(ctx_, pixel_position(x,y), marker_, attributes_, marker_trans_, opacity, true); + render_vector_marker(ctx_, pixel_position(x,y), marker_, bbox_, attributes_, marker_trans_, opacity, true); if (!ignore_placement) { @@ -857,13 +855,12 @@ struct markers_dispatch { agg::trans_affine matrix = marker_trans_; matrix.rotate(angle); - render_vector_marker(ctx_, pixel_position(x,y),marker_, attributes_, matrix, opacity, true); + render_vector_marker(ctx_, pixel_position(x,y),marker_, bbox_, attributes_, matrix, opacity, true); } } } - Context & ctx_; SvgPath & marker_; Attributes const& attributes_; Detector & detector_; @@ -873,30 +870,33 @@ struct markers_dispatch feature_impl const& feature_; attributes const& vars_; double scale_factor_; + cairo_context & ctx_; }; -template -struct markers_dispatch_2 +template +struct markers_dispatch_2 : mapnik::noncopyable { - markers_dispatch_2(Context & ctx, - ImageMarker & marker, - Detector & detector, - markers_symbolizer const& sym, - box2d const& bbox, + + //typedef typename std::tuple_element<0,RendererContext>::type CairoContext; + + markers_dispatch_2(ImageMarker & marker, agg::trans_affine const& marker_trans, + markers_symbolizer const& sym, + Detector & detector, + //box2d const& bbox, + double scale_factor, feature_impl const& feature, mapnik::attributes const& vars, - double scale_factor) - :ctx_(ctx), - marker_(marker), - detector_(detector), - sym_(sym), - bbox_(bbox), - marker_trans_(marker_trans), - feature_(feature), - vars_(vars), - scale_factor_(scale_factor) {} - + RendererContext const& renderer_context) + :marker_(marker), + detector_(detector), + sym_(sym), + bbox_(std::get<1>(renderer_context)), + marker_trans_(marker_trans), + feature_(feature), + vars_(vars), + scale_factor_(scale_factor), + ctx_(std::get<0>(renderer_context)) {} template void add_path(T & path) @@ -964,7 +964,7 @@ struct markers_dispatch_2 } } - Context & ctx_; + cairo_context & ctx_; ImageMarker & marker_; Detector & detector_; markers_symbolizer const& sym_; @@ -981,29 +981,24 @@ void cairo_renderer_base::process(markers_symbolizer const& sym, proj_transform const& prj_trans) { typedef agg::pod_bvector svg_attribute_type; - typedef detail::markers_dispatch_2 raster_dispatch_type; - typedef detail::markers_dispatch vector_dispatch_type; cairo_save_restore guard(context_); composite_mode_e comp_op = get(sym, keys::comp_op, feature, common_.vars_, src_over); context_.set_operator(comp_op); box2d clip_box = common_.query_extent_; - render_markers_symbolizer( + auto renderer_context = std::tie(context_, clip_box); + + typedef decltype(renderer_context) RendererContextType; + typedef detail::markers_dispatch > , svg_attribute_type, + label_collision_detector4> vector_dispatch_type; + typedef detail::markers_dispatch_2 raster_dispatch_type; + + + render_markers_symbolizer( sym, feature, prj_trans, common_, clip_box, - [&](svg::svg_path_adapter &, svg_attribute_type const &attr, svg_storage_type &marker, - box2d const &bbox, agg::trans_affine const &marker_trans, - bool) -> vector_dispatch_type { - return vector_dispatch_type(context_, marker, attr, *common_.detector_, sym, bbox, - marker_trans, feature, common_.vars_, common_.scale_factor_); - }, - [&](image_data_32 &marker, agg::trans_affine const &marker_trans, - box2d const &bbox) -> raster_dispatch_type { - return raster_dispatch_type(context_, marker, *common_.detector_, sym, bbox, - marker_trans, feature, common_.vars_, common_.scale_factor_); - }); + renderer_context); } void cairo_renderer_base::process(text_symbolizer const& sym, @@ -1031,7 +1026,7 @@ void cairo_renderer_base::process(text_symbolizer const& sym, namespace { /** - * Render a thunk which was frozen from a previous call to + * Render a thunk which was frozen from a previous call to * extract_bboxes. We should now have a new offset at which * to render it, and the boxes themselves should already be * in the detector from the placement_finder. From 81c4b9dd59c58592ae1ba327f8697584a13fdc8e Mon Sep 17 00:00:00 2001 From: artemp Date: Thu, 5 Jun 2014 16:13:05 +0100 Subject: [PATCH 09/10] fix init order --- src/cairo_renderer.cpp | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/src/cairo_renderer.cpp b/src/cairo_renderer.cpp index 519047572..5c3f4c80b 100644 --- a/src/cairo_renderer.cpp +++ b/src/cairo_renderer.cpp @@ -426,7 +426,6 @@ void render_vector_marker(cairo_context & context, pixel_position const& pos, { using namespace mapnik::svg; agg::trans_affine mtx = tr; - if (recenter) { coord c = bbox.center(); @@ -855,7 +854,7 @@ struct markers_dispatch : mapnik::noncopyable { agg::trans_affine matrix = marker_trans_; matrix.rotate(angle); - render_vector_marker(ctx_, pixel_position(x,y),marker_, bbox_, attributes_, matrix, opacity, true); + render_vector_marker(ctx_, pixel_position(x,y), marker_, bbox_, attributes_, matrix, opacity, true); } } @@ -863,27 +862,23 @@ struct markers_dispatch : mapnik::noncopyable SvgPath & marker_; Attributes const& attributes_; - Detector & detector_; - markers_symbolizer const& sym_; box2d const& bbox_; agg::trans_affine const& marker_trans_; + markers_symbolizer const& sym_; + Detector & detector_; + double scale_factor_; feature_impl const& feature_; attributes const& vars_; - double scale_factor_; cairo_context & ctx_; }; template -struct markers_dispatch_2 : mapnik::noncopyable +struct raster_markers_dispatch : mapnik::noncopyable { - - //typedef typename std::tuple_element<0,RendererContext>::type CairoContext; - - markers_dispatch_2(ImageMarker & marker, + raster_markers_dispatch(ImageMarker & marker, agg::trans_affine const& marker_trans, markers_symbolizer const& sym, Detector & detector, - //box2d const& bbox, double scale_factor, feature_impl const& feature, mapnik::attributes const& vars, @@ -893,9 +888,9 @@ struct markers_dispatch_2 : mapnik::noncopyable sym_(sym), bbox_(std::get<1>(renderer_context)), marker_trans_(marker_trans), + scale_factor_(scale_factor), feature_(feature), vars_(vars), - scale_factor_(scale_factor), ctx_(std::get<0>(renderer_context)) {} template @@ -964,15 +959,15 @@ struct markers_dispatch_2 : mapnik::noncopyable } } - cairo_context & ctx_; ImageMarker & marker_; Detector & detector_; markers_symbolizer const& sym_; box2d const& bbox_; agg::trans_affine const& marker_trans_; + double scale_factor_; feature_impl const& feature_; attributes const& vars_; - double scale_factor_; + cairo_context & ctx_; }; } @@ -992,7 +987,7 @@ void cairo_renderer_base::process(markers_symbolizer const& sym, typedef decltype(renderer_context) RendererContextType; typedef detail::markers_dispatch > , svg_attribute_type, label_collision_detector4> vector_dispatch_type; - typedef detail::markers_dispatch_2 raster_dispatch_type; From de90d0ee2af82c522c71f0a436cfd69aea015d12 Mon Sep 17 00:00:00 2001 From: artemp Date: Thu, 5 Jun 2014 16:47:40 +0100 Subject: [PATCH 10/10] fix markers transforms calc --- include/mapnik/grid/grid_marker_helpers.hpp | 22 +++++++------------ include/mapnik/marker_helpers.hpp | 8 +++++-- .../process_markers_symbolizer.hpp | 11 ++-------- 3 files changed, 16 insertions(+), 25 deletions(-) diff --git a/include/mapnik/grid/grid_marker_helpers.hpp b/include/mapnik/grid/grid_marker_helpers.hpp index ceb0bc042..2db731ec3 100644 --- a/include/mapnik/grid/grid_marker_helpers.hpp +++ b/include/mapnik/grid/grid_marker_helpers.hpp @@ -240,6 +240,9 @@ struct vector_markers_rasterizer_dispatch_grid : mapnik::noncopyable double opacity = get(sym_,keys::opacity, feature_, vars_, 1.0); bool allow_overlap = get(sym_, keys::allow_overlap, feature_, vars_, false); + coord2d center = bbox_.center(); + agg::trans_affine_translation recenter(-center.x, -center.y); + if (placement_method != MARKER_LINE_PLACEMENT || path.type() == geometry_type::types::Point) { @@ -247,27 +250,18 @@ struct vector_markers_rasterizer_dispatch_grid : mapnik::noncopyable double y = 0; if (path.type() == geometry_type::types::LineString) { - if (!label::middle_point(path, x, y)) - { - return; - } + if (!label::middle_point(path, x, y)) return; } else if (placement_method == MARKER_INTERIOR_PLACEMENT) { - if (!label::interior_position(path, x, y)) - { - return; - } + if (!label::interior_position(path, x, y)) return; } else { - if (!label::centroid(path, x, y)) - { - return; - } + if (!label::centroid(path, x, y)) return; } - agg::trans_affine matrix = marker_trans_; + agg::trans_affine matrix = recenter * marker_trans_; matrix.translate(x,y); box2d transformed_bbox = bbox_ * matrix; if (allow_overlap || @@ -296,7 +290,7 @@ struct vector_markers_rasterizer_dispatch_grid : mapnik::noncopyable double x, y, angle; while (placement.get_point(x, y, angle, ignore_placement)) { - agg::trans_affine matrix = marker_trans_; + agg::trans_affine matrix = recenter * marker_trans_; matrix.rotate(angle); matrix.translate(x, y); svg_renderer_.render_id(ras_, sl_, renb_, feature_.id(), matrix, opacity, bbox_); diff --git a/include/mapnik/marker_helpers.hpp b/include/mapnik/marker_helpers.hpp index 2c89dfe5f..7d057c005 100644 --- a/include/mapnik/marker_helpers.hpp +++ b/include/mapnik/marker_helpers.hpp @@ -106,6 +106,9 @@ struct vector_markers_rasterizer_dispatch : mapnik::noncopyable bool allow_overlap = get(sym_, keys::allow_overlap, feature_, vars_, false); double opacity = get(sym_,keys::opacity, feature_, vars_, 1.0); + coord2d center = bbox_.center(); + agg::trans_affine_translation recenter(-center.x, -center.y); + if (placement_method != MARKER_LINE_PLACEMENT || path.type() == mapnik::geometry_type::types::Point) { @@ -123,7 +126,7 @@ struct vector_markers_rasterizer_dispatch : mapnik::noncopyable { if (!label::centroid(path, x, y)) return; } - agg::trans_affine matrix = marker_trans_; + agg::trans_affine matrix = recenter * marker_trans_; matrix.translate(x,y); if (snap_to_pixels_) { @@ -157,7 +160,8 @@ struct vector_markers_rasterizer_dispatch : mapnik::noncopyable double angle = 0; while (placement.get_point(x, y, angle, ignore_placement)) { - agg::trans_affine matrix = marker_trans_; + + agg::trans_affine matrix = recenter * marker_trans_; matrix.rotate(angle); matrix.translate(x, y); svg_renderer_.render(ras_, sl_, renb_, matrix, opacity, bbox_); diff --git a/include/mapnik/renderer_common/process_markers_symbolizer.hpp b/include/mapnik/renderer_common/process_markers_symbolizer.hpp index b9d213d19..424b9b2fa 100644 --- a/include/mapnik/renderer_common/process_markers_symbolizer.hpp +++ b/include/mapnik/renderer_common/process_markers_symbolizer.hpp @@ -79,13 +79,10 @@ void render_markers_symbolizer(markers_symbolizer const& sym, auto image_transform = get_optional(sym, keys::image_transform); if (image_transform) evaluate_transform(tr, feature, common.vars_, *image_transform); box2d bbox = marker_ellipse.bounding_box(); - coord2d center = bbox.center(); - agg::trans_affine_translation recenter(-center.x, -center.y); - agg::trans_affine marker_trans = recenter * tr; vector_dispatch_type rasterizer_dispatch(svg_path, result ? attributes : (*stock_vector_marker)->attributes(), bbox, - marker_trans, + tr, sym, *common.detector_, common.scale_factor_, @@ -121,14 +118,10 @@ void render_markers_symbolizer(markers_symbolizer const& sym, svg_path_adapter svg_path(stl_storage); svg_attribute_type attributes; bool result = push_explicit_style( (*stock_vector_marker)->attributes(), attributes, sym, feature, common.vars_); - // TODO - clamping to >= 4 pixels - coord2d center = bbox.center(); - agg::trans_affine_translation recenter(-center.x, -center.y); - agg::trans_affine marker_trans = recenter * tr; vector_dispatch_type rasterizer_dispatch(svg_path, result ? attributes : (*stock_vector_marker)->attributes(), bbox, - marker_trans, + tr, sym, *common.detector_, common.scale_factor_,