From c3c2902b9228bc48c903bf439392654bf0ba2e6b Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Tue, 31 Jul 2012 16:40:30 -0700 Subject: [PATCH] move ellipse contruction code to marker_helpers --- include/mapnik/marker_helpers.hpp | 48 +++++++++++++++++++++++--- src/agg/process_markers_symbolizer.cpp | 44 +++++------------------ 2 files changed, 53 insertions(+), 39 deletions(-) diff --git a/include/mapnik/marker_helpers.hpp b/include/mapnik/marker_helpers.hpp index 4d7a2be78..f22dd6ec5 100644 --- a/include/mapnik/marker_helpers.hpp +++ b/include/mapnik/marker_helpers.hpp @@ -27,12 +27,51 @@ #include #include #include +#include +#include + +// agg +#include "agg_ellipse.h" // boost #include namespace mapnik { +template +void build_ellipse(T const& sym, mapnik::feature_impl const& feature, svg_storage_type & marker_ellipse, svg::svg_path_adapter & svg_path) +{ + expression_ptr const& width_expr = sym.get_width(); + expression_ptr const& height_expr = sym.get_height(); + double width = 0; + double height = 0; + if (width_expr && height_expr) + { + width = boost::apply_visitor(evaluate(feature), *width_expr).to_double(); + height = boost::apply_visitor(evaluate(feature), *height_expr).to_double(); + } + else if (width_expr) + { + width = boost::apply_visitor(evaluate(feature), *width_expr).to_double(); + height = width; + } + else if (height_expr) + { + height = boost::apply_visitor(evaluate(feature), *height_expr).to_double(); + width = height; + } + svg::svg_converter_type styled_svg(svg_path, marker_ellipse.attributes()); + styled_svg.push_attr(); + styled_svg.begin_path(); + agg::ellipse c(0, 0, width/2.0, height/2.0); + styled_svg.storage().concat_path(c); + styled_svg.end_path(); + styled_svg.pop_attr(); + double lox,loy,hix,hiy; + styled_svg.bounding_rect(&lox, &loy, &hix, &hiy); + marker_ellipse.set_bounding_box(lox,loy,hix,hiy); +} + template bool push_explicit_style(Attr const& src, Attr & dst, markers_symbolizer const& sym) { @@ -42,10 +81,12 @@ bool push_explicit_style(Attr const& src, Attr & dst, markers_symbolizer const& boost::optional const& fill_opacity = sym.get_fill_opacity(); if (strk || fill || opacity || fill_opacity) { + bool success = false; for(unsigned i = 0; i < src.size(); ++i) { - mapnik::svg::path_attributes attr = src[i]; - + success = true; + dst.push_back(src[i]); + mapnik::svg::path_attributes & attr = dst.last(); if (attr.stroke_flag) { // TODO - stroke attributes need to be boost::optional @@ -87,9 +128,8 @@ bool push_explicit_style(Attr const& src, Attr & dst, markers_symbolizer const& attr.fill_opacity = *fill_opacity; } } - dst.push_back(attr); } - return true; + return success; } return false; } diff --git a/src/agg/process_markers_symbolizer.cpp b/src/agg/process_markers_symbolizer.cpp index bc5f9c851..40c7336a7 100644 --- a/src/agg/process_markers_symbolizer.cpp +++ b/src/agg/process_markers_symbolizer.cpp @@ -33,7 +33,6 @@ #include #include #include -#include #include #include #include @@ -41,7 +40,6 @@ // agg #include "agg_basics.h" -#include "agg_ellipse.h" #include "agg_rendering_buffer.h" #include "agg_pixfmt_rgba.h" #include "agg_rasterizer_scanline_aa.h" @@ -317,12 +315,15 @@ void agg_renderer::process(markers_symbolizer const& sym, { using namespace mapnik::svg; typedef agg::renderer_scanline_aa_solid renderer_type; + typedef agg::pod_bvector svg_attribute_type; typedef svg_renderer, + svg_attribute_type, renderer_type, agg::pixfmt_rgba32 > svg_renderer_type; - typedef vector_markers_rasterizer_dispatch dispatch_type; - + typedef vector_markers_rasterizer_dispatch dispatch_type; boost::optional const& stock_vector_marker = (*mark)->get_vector_data(); expression_ptr const& width_expr = sym.get_width(); expression_ptr const& height_expr = sym.get_height(); @@ -332,38 +333,11 @@ void agg_renderer::process(markers_symbolizer const& sym, if (filename == "shape://ellipse" && (width_expr || height_expr)) { - double width = 0; - double height = 0; - if (width_expr && height_expr) - { - width = boost::apply_visitor(evaluate(feature), *width_expr).to_double(); - height = boost::apply_visitor(evaluate(feature), *height_expr).to_double(); - } - else if (width_expr) - { - width = boost::apply_visitor(evaluate(feature), *width_expr).to_double(); - height = width; - } - else if (height_expr) - { - height = boost::apply_visitor(evaluate(feature), *height_expr).to_double(); - width = height; - } - // create a new marker svg_storage_type marker_ellipse; vertex_stl_adapter stl_storage(marker_ellipse.source()); svg_path_adapter svg_path(stl_storage); - svg_converter_type styled_svg(svg_path, marker_ellipse.attributes()); - styled_svg.push_attr(); - styled_svg.begin_path(); - agg::ellipse c(0, 0, width/2.0, height/2.0); - styled_svg.storage().concat_path(c); - styled_svg.end_path(); - styled_svg.pop_attr(); - double lox,loy,hix,hiy; - styled_svg.bounding_rect(&lox, &loy, &hix, &hiy); - marker_ellipse.set_bounding_box(lox,loy,hix,hiy); - agg::pod_bvector attributes; + build_ellipse(sym, feature, marker_ellipse, svg_path); + svg_attribute_type attributes; bool result = push_explicit_style( (*stock_vector_marker)->attributes(), attributes, sym); svg_renderer_type svg_renderer(svg_path, result ? attributes : (*stock_vector_marker)->attributes()); evaluate_transform(tr, feature, sym.get_image_transform()); @@ -393,7 +367,7 @@ void agg_renderer::process(markers_symbolizer const& sym, agg::trans_affine marker_trans = recenter * tr; vertex_stl_adapter stl_storage((*stock_vector_marker)->source()); svg_path_adapter svg_path(stl_storage); - agg::pod_bvector attributes; + svg_attribute_type attributes; bool result = push_explicit_style( (*stock_vector_marker)->attributes(), attributes, sym); svg_renderer_type svg_renderer(svg_path, result ? attributes : (*stock_vector_marker)->attributes()); dispatch_type rasterizer_dispatch(*current_buffer_,svg_renderer,*ras_ptr,