diff --git a/include/mapnik/renderer_common/process_building_symbolizer.hpp b/include/mapnik/renderer_common/process_building_symbolizer.hpp index 148409a2d..589107dcf 100644 --- a/include/mapnik/renderer_common/process_building_symbolizer.hpp +++ b/include/mapnik/renderer_common/process_building_symbolizer.hpp @@ -23,119 +23,103 @@ #ifndef MAPNIK_RENDERER_COMMON_PROCESS_BUILDING_SYMBOLIZER_HPP #define MAPNIK_RENDERER_COMMON_PROCESS_BUILDING_SYMBOLIZER_HPP -#include #include #include #include +#include -#include -#include +#pragma GCC diagnostic push +#include +#include "agg_conv_transform.h" +#pragma GCC diagnostic pop namespace mapnik { -namespace detail { - -template -void make_building(geometry::polygon const& poly, double height, F1 const& face_func, F2 const& frame_func, F3 const& roof_func) +struct render_building_symbolizer { - path_type frame(path_type::types::LineString); - path_type roof(path_type::types::Polygon); - std::deque face_segments; - double ring_begin_x, ring_begin_y; - double x0 = 0; - double y0 = 0; - double x,y; - geometry::polygon_vertex_adapter va(poly); - va.rewind(0); - for (unsigned cm = va.vertex(&x, &y); cm != SEG_END; - cm = va.vertex(&x, &y)) + using vertex_adapter_type = geometry::polygon_vertex_adapter; + using transform_path_type = transform_path_adapter; + using roof_type = agg::conv_transform; + + template + static void apply(feature_impl const& feature, + proj_transform const& prj_trans, + view_transform const& view_trans, + double height, + F1 face_func, F2 frame_func, F3 roof_func) { - if (cm == SEG_MOVETO) + auto const& geom = feature.get_geometry(); + if (geom.is>()) { - frame.move_to(x,y); - ring_begin_x = x; - ring_begin_y = y; + auto const& poly = geom.get>(); + vertex_adapter_type va(poly); + transform_path_type transformed(view_trans, va, prj_trans); + make_building(transformed, height, face_func, frame_func, roof_func); } - else if (cm == SEG_LINETO) + else if (geom.is>()) { - frame.line_to(x,y); - face_segments.emplace_back(x0,y0,x,y); - } - else if (cm == SEG_CLOSE) - { - frame.close_path(); - if (!face_segments.empty()) + auto const& multi_poly = geom.get>(); + for (auto const& poly : multi_poly) { - face_segments.emplace_back(x0, y0, ring_begin_x, ring_begin_y); + vertex_adapter_type va(poly); + transform_path_type transformed(view_trans, va, prj_trans); + make_building(transformed, height, face_func, frame_func, roof_func); } } - x0 = x; - y0 = y; } - std::sort(face_segments.begin(),face_segments.end(), y_order); - for (auto const& seg : face_segments) +private: + template + static void render_face(double x0, double y0, double x, double y, double height, F const& face_func, path_type & frame) { path_type faces(path_type::types::Polygon); - faces.move_to(std::get<0>(seg),std::get<1>(seg)); - faces.line_to(std::get<2>(seg),std::get<3>(seg)); - faces.line_to(std::get<2>(seg),std::get<3>(seg) + height); - faces.line_to(std::get<0>(seg),std::get<1>(seg) + height); - + faces.move_to(x0, y0); + faces.line_to(x, y); + faces.line_to(x, y - height); + faces.line_to(x0, y0 - height); face_func(faces); - // - frame.move_to(std::get<0>(seg),std::get<1>(seg)); - frame.line_to(std::get<0>(seg),std::get<1>(seg)+height); + + frame.move_to(x0, y0); + frame.line_to(x, y); + frame.line_to(x, y - height); + frame.line_to(x0, y0 - height); } - va.rewind(0); - for (unsigned cm = va.vertex(&x, &y); cm != SEG_END; - cm = va.vertex(&x, &y)) + template + static void make_building(Geom & poly, double height, F1 const& face_func, F2 const& frame_func, F3 const& roof_func) { - if (cm == SEG_MOVETO) + path_type frame(path_type::types::LineString); + double ring_begin_x, ring_begin_y; + double x0 = 0; + double y0 = 0; + double x, y; + poly.rewind(0); + for (unsigned cm = poly.vertex(&x, &y); cm != SEG_END; cm = poly.vertex(&x, &y)) { - frame.move_to(x,y+height); - roof.move_to(x,y+height); - } - else if (cm == SEG_LINETO) - { - frame.line_to(x,y+height); - roof.line_to(x,y+height); - } - else if (cm == SEG_CLOSE) - { - frame.close_path(); - roof.close_path(); + if (cm == SEG_MOVETO) + { + ring_begin_x = x; + ring_begin_y = y; + } + else if (cm == SEG_LINETO) + { + render_face(x0, y0, x, y, height, face_func, frame); + } + else if (cm == SEG_CLOSE) + { + render_face(x0, y0, ring_begin_x, ring_begin_y, height, face_func, frame); + } + x0 = x; + y0 = y; } + + frame_func(frame); + + agg::trans_affine_translation tr(0, -height); + roof_type roof(poly, tr); + roof_func(roof); } - - frame_func(frame); - roof_func(roof); -} - -} // ns detail - -template -void render_building_symbolizer(mapnik::feature_impl const& feature, - double height, - F1 face_func, F2 frame_func, F3 roof_func) -{ - - auto const& geom = feature.get_geometry(); - if (geom.is >()) - { - auto const& poly = geom.get >(); - detail::make_building(poly, height, face_func, frame_func, roof_func); - } - else if (geom.is >()) - { - auto const& multi_poly = geom.get >(); - for (auto const& poly : multi_poly) - { - detail::make_building(poly, height, face_func, frame_func, roof_func); - } - } -} +}; } // namespace mapnik diff --git a/include/mapnik/segment.hpp b/include/mapnik/segment.hpp deleted file mode 100644 index 854b9d79e..000000000 --- a/include/mapnik/segment.hpp +++ /dev/null @@ -1,43 +0,0 @@ -/***************************************************************************** - * - * This file is part of Mapnik (c++ mapping toolkit) - * - * Copyright (C) 2017 Artem Pavlenko - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - *****************************************************************************/ - -#ifndef MAPNIK_SEGMENT_HPP -#define MAPNIK_SEGMENT_HPP - -#include -#include - -namespace mapnik -{ - -using segment_t = std::tuple; - -static inline bool y_order(segment_t const& first,segment_t const& second) -{ - double miny0 = std::min(std::get<1>(first), std::get<3>(first)); - double miny1 = std::min(std::get<1>(second), std::get<3>(second)); - return miny0 > miny1; -} - -} - -#endif // MAPNIK_SEGMENT_HPP diff --git a/src/agg/process_building_symbolizer.cpp b/src/agg/process_building_symbolizer.cpp index 71a76be41..97f1e5479 100644 --- a/src/agg/process_building_symbolizer.cpp +++ b/src/agg/process_building_symbolizer.cpp @@ -27,12 +27,10 @@ #include #include #include -#include #include #include #include #include -#include // stl #include @@ -58,7 +56,6 @@ void agg_renderer::process(building_symbolizer const& sym, mapnik::feature_impl & feature, proj_transform const& prj_trans) { - using transform_path_type = transform_path_adapter; using ren_base = agg::renderer_base; using renderer = agg::renderer_scanline_aa_solid; @@ -88,13 +85,12 @@ void agg_renderer::process(building_symbolizer const& sym, double height = get(sym, feature, common_.vars_) * common_.scale_factor_; - render_building_symbolizer( - feature, height, + render_building_symbolizer::apply( + feature, prj_trans, common_.t_, height, [&,r,g,b,a,opacity](path_type const& faces) { vertex_adapter va(faces); - transform_path_type faces_path (this->common_.t_,va,prj_trans); - ras_ptr->add_path(faces_path); + ras_ptr->add_path(va); ren.color(agg::rgba8_pre(int(r*0.8), int(g*0.8), int(b*0.8), int(a * opacity))); agg::render_scanlines(*ras_ptr, sl, ren); this->ras_ptr->reset(); @@ -102,19 +98,17 @@ void agg_renderer::process(building_symbolizer const& sym, [&,r,g,b,a,opacity](path_type const& frame) { vertex_adapter va(frame); - transform_path_type path(common_.t_,va, prj_trans); - agg::conv_stroke stroke(path); + agg::conv_stroke stroke(va); stroke.width(common_.scale_factor_); + stroke.miter_limit(common_.scale_factor_ / 2.0); ras_ptr->add_path(stroke); ren.color(agg::rgba8_pre(int(r*0.8), int(g*0.8), int(b*0.8), int(a * opacity))); agg::render_scanlines(*ras_ptr, sl, ren); ras_ptr->reset(); }, - [&,r,g,b,a,opacity](path_type const& roof) + [&,r,g,b,a,opacity](render_building_symbolizer::roof_type & roof) { - vertex_adapter va(roof); - transform_path_type roof_path (common_.t_,va,prj_trans); - ras_ptr->add_path(roof_path); + ras_ptr->add_path(roof); ren.color(agg::rgba8_pre(r, g, b, int(a * opacity))); agg::render_scanlines(*ras_ptr, sl, ren); }); diff --git a/src/cairo/process_building_symbolizer.cpp b/src/cairo/process_building_symbolizer.cpp index ae6337f96..914534a83 100644 --- a/src/cairo/process_building_symbolizer.cpp +++ b/src/cairo/process_building_symbolizer.cpp @@ -28,7 +28,6 @@ #include #include #include -#include // mapnik symbolizer generics #include @@ -44,7 +43,6 @@ void cairo_renderer::process(building_symbolizer const& sym, mapnik::feature_impl & feature, proj_transform const& prj_trans) { - using transform_path_type = transform_path_adapter; cairo_save_restore guard(context_); composite_mode_e comp_op = get(sym, feature, common_.vars_); mapnik::color fill = get(sym, feature, common_.vars_); @@ -53,33 +51,30 @@ void cairo_renderer::process(building_symbolizer const& sym, context_.set_operator(comp_op); - render_building_symbolizer( - feature, height, + render_building_symbolizer::apply( + feature, prj_trans, common_.t_, height, [&](path_type const& faces) { vertex_adapter va(faces); - transform_path_type faces_path(common_.t_, va, prj_trans); context_.set_color(fill.red() * 0.8 / 255.0, fill.green() * 0.8 / 255.0, fill.blue() * 0.8 / 255.0, fill.alpha() * opacity / 255.0); - context_.add_path(faces_path); + context_.add_path(va); context_.fill(); }, [&](path_type const& frame) { vertex_adapter va(frame); - transform_path_type path(common_.t_, va, prj_trans); context_.set_color(fill.red() * 0.8 / 255.0, fill.green() * 0.8/255.0, fill.blue() * 0.8 / 255.0, fill.alpha() * opacity / 255.0); context_.set_line_width(common_.scale_factor_); - context_.add_path(path); + context_.set_miter_limit(common_.scale_factor_ / 2.0); + context_.add_path(va); context_.stroke(); }, - [&](path_type const& roof) + [&](render_building_symbolizer::roof_type & roof) { - vertex_adapter va(roof); - transform_path_type roof_path(common_.t_, va, prj_trans); context_.set_color(fill, opacity); - context_.add_path(roof_path); + context_.add_path(roof); context_.fill(); }); } diff --git a/src/grid/process_building_symbolizer.cpp b/src/grid/process_building_symbolizer.cpp index 144bb4c4b..940e648ca 100644 --- a/src/grid/process_building_symbolizer.cpp +++ b/src/grid/process_building_symbolizer.cpp @@ -29,8 +29,6 @@ #include #include #include -#include -#include #include #include #include @@ -59,7 +57,6 @@ void grid_renderer::process(building_symbolizer const& sym, using pixfmt_type = typename grid_renderer_base_type::pixfmt_type; using color_type = typename grid_renderer_base_type::pixfmt_type::color_type; using renderer_type = agg::renderer_scanline_bin_solid; - using transform_path_type = transform_path_adapter; agg::scanline_bin sl; grid_rendering_buffer buf(pixmap_.raw_data(), common_.width_, common_.height_, common_.width_); @@ -72,13 +69,12 @@ void grid_renderer::process(building_symbolizer const& sym, double height = get(sym, keys::height, feature, common_.vars_, 0.0); - render_building_symbolizer( - feature, height, + render_building_symbolizer::apply( + feature, prj_trans, common_.t_, height, [&](path_type const& faces) { vertex_adapter va(faces); - transform_path_type faces_path (common_.t_,va,prj_trans); - ras_ptr->add_path(faces_path); + ras_ptr->add_path(va); ren.color(color_type(feature.id())); agg::render_scanlines(*ras_ptr, sl, ren); ras_ptr->reset(); @@ -86,18 +82,16 @@ void grid_renderer::process(building_symbolizer const& sym, [&](path_type const& frame) { vertex_adapter va(frame); - transform_path_type path(common_.t_,va,prj_trans); - agg::conv_stroke stroke(path); + agg::conv_stroke stroke(va); + stroke.miter_limit(common_.scale_factor_ / 2.0); ras_ptr->add_path(stroke); ren.color(color_type(feature.id())); agg::render_scanlines(*ras_ptr, sl, ren); ras_ptr->reset(); }, - [&](path_type const& roof) + [&](render_building_symbolizer::roof_type & roof) { - vertex_adapter va(roof); - transform_path_type roof_path (common_.t_,va,prj_trans); - ras_ptr->add_path(roof_path); + ras_ptr->add_path(roof); ren.color(color_type(feature.id())); agg::render_scanlines(*ras_ptr, sl, ren); }); diff --git a/test/data-visual b/test/data-visual index 574ad9bf8..bbeb5ec35 160000 --- a/test/data-visual +++ b/test/data-visual @@ -1 +1 @@ -Subproject commit 574ad9bf84450708a7f8befa63dddbc0a377cfa5 +Subproject commit bbeb5ec35c75fa8b5712f8215f132a19e84ea1fb