From da5574d2476987a34666e8c62a3c5839f47800a1 Mon Sep 17 00:00:00 2001 From: Matt Amos Date: Fri, 6 Dec 2013 17:30:06 +0000 Subject: [PATCH] Factored out common implementation of point symbolizer. --- .../process_point_symbolizer.hpp | 102 ++++++++++++++++++ src/agg/process_point_symbolizer.cpp | 73 ++----------- src/cairo_renderer.cpp | 67 ++---------- src/grid/process_point_symbolizer.cpp | 72 ++----------- 4 files changed, 126 insertions(+), 188 deletions(-) create mode 100644 include/mapnik/renderer_common/process_point_symbolizer.hpp diff --git a/include/mapnik/renderer_common/process_point_symbolizer.hpp b/include/mapnik/renderer_common/process_point_symbolizer.hpp new file mode 100644 index 000000000..1e97675d0 --- /dev/null +++ b/include/mapnik/renderer_common/process_point_symbolizer.hpp @@ -0,0 +1,102 @@ +/***************************************************************************** + * + * This file is part of Mapnik (c++ mapping toolkit) + * + * Copyright (C) 2013 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_RENDERER_COMMON_PROCESS_POINT_SYMBOLIZER_HPP +#define MAPNIK_RENDERER_COMMON_PROCESS_POINT_SYMBOLIZER_HPP + +namespace mapnik { + +template +void render_point_symbolizer(point_symbolizer const &sym, + mapnik::feature_impl &feature, + proj_transform const &prj_trans, + renderer_common &common, + F render_marker) +{ + std::string filename = get(sym, keys::file, feature); + boost::optional marker; + if ( !filename.empty() ) + { + marker = marker_cache::instance().find(filename, true); + } + else + { + marker.reset(std::make_shared()); + } + + if (marker) + { + double opacity = get(sym,keys::opacity,feature, 1.0); + bool allow_overlap = get(sym, keys::allow_overlap, feature, false); + bool ignore_placement = get(sym, keys::ignore_placement, feature, false); + point_placement_enum placement= get(sym, keys::point_placement_type, feature, CENTROID_POINT_PLACEMENT); + + box2d const& bbox = (*marker)->bounding_box(); + coord2d center = bbox.center(); + + agg::trans_affine tr; + auto image_transform = get_optional(sym, keys::image_transform); + if (image_transform) evaluate_transform(tr, feature, *image_transform); + + agg::trans_affine_translation recenter(-center.x, -center.y); + agg::trans_affine recenter_tr = recenter * tr; + box2d label_ext = bbox * recenter_tr * agg::trans_affine_scaling(common.scale_factor_); + + for (std::size_t i=0; ihas_placement(label_ext)) + { + + render_marker(pixel_position(x, y), + **marker, + tr, + opacity); + + if (!ignore_placement) + common.detector_->insert(label_ext); + } + } + } +} + +} // namespace mapnik + +#endif /* MAPNIK_RENDERER_COMMON_PROCESS_POINT_SYMBOLIZER_HPP */ diff --git a/src/agg/process_point_symbolizer.cpp b/src/agg/process_point_symbolizer.cpp index 9614184a1..792c6d3eb 100644 --- a/src/agg/process_point_symbolizer.cpp +++ b/src/agg/process_point_symbolizer.cpp @@ -33,7 +33,7 @@ #include #include #include - +#include // agg #include "agg_trans_affine.h" @@ -50,71 +50,14 @@ void agg_renderer::process(point_symbolizer const& sym, mapnik::feature_impl & feature, proj_transform const& prj_trans) { - std::string filename = get(sym, keys::file, feature); - boost::optional marker; - if ( !filename.empty() ) - { - marker = marker_cache::instance().find(filename, true); - } - else - { - marker.reset(std::make_shared()); - } + composite_mode_e comp_op = get(sym, keys::comp_op, feature, src_over); - if (marker) - { - double opacity = get(sym,keys::opacity,feature, 1.0); - bool allow_overlap = get(sym, keys::allow_overlap, feature, false); - bool ignore_placement = get(sym, keys::ignore_placement, feature, false); - point_placement_enum placement= get(sym, keys::point_placement_type, feature, CENTROID_POINT_PLACEMENT); - composite_mode_e comp_op = get(sym, keys::comp_op, feature, src_over); - - box2d const& bbox = (*marker)->bounding_box(); - coord2d center = bbox.center(); - - agg::trans_affine tr; - auto image_transform = get_optional(sym, keys::image_transform); - if (image_transform) evaluate_transform(tr, feature, *image_transform); - - agg::trans_affine_translation recenter(-center.x, -center.y); - agg::trans_affine recenter_tr = recenter * tr; - box2d label_ext = bbox * recenter_tr * agg::trans_affine_scaling(common_.scale_factor_); - - for (std::size_t i=0; ihas_placement(label_ext)) - { - - render_marker(pixel_position(x, y), - **marker, - tr, - opacity, - comp_op); - - if (!ignore_placement) - common_.detector_->insert(label_ext); - } - } - } + render_point_symbolizer( + sym, feature, prj_trans, common_, + [&](pixel_position const& pos, marker const& marker, + agg::trans_affine const& tr, double opacity) { + render_marker(pos, marker, tr, opacity, comp_op); + }); } template void agg_renderer::process(point_symbolizer const&, diff --git a/src/cairo_renderer.cpp b/src/cairo_renderer.cpp index 69b2f4879..aaf8945fd 100644 --- a/src/cairo_renderer.cpp +++ b/src/cairo_renderer.cpp @@ -56,6 +56,7 @@ // mapnik symbolizer generics #include +#include // cairo #include @@ -561,71 +562,17 @@ void cairo_renderer_base::process(point_symbolizer const& sym, mapnik::feature_impl & feature, proj_transform const& prj_trans) { - std::string filename = get(sym, keys::file, feature); - double opacity = get(sym, keys::opacity, feature, 1.0); - point_placement_enum placement = get(sym, keys::point_placement_type, feature, CENTROID_POINT_PLACEMENT); - bool allow_overlap = get(sym, keys::allow_overlap, feature, false); - bool ignore_placement = get(sym, keys::ignore_placement, feature, false); - auto geom_transform = get_optional(sym, keys::geometry_transform); composite_mode_e comp_op = get(sym, keys::comp_op, feature, src_over); cairo_save_restore guard(context_); context_.set_operator(comp_op); - boost::optional marker; - if ( !filename.empty() ) - { - marker = marker_cache::instance().find(filename, true); - } - else - { - marker.reset(std::make_shared()); - } - - - if (marker) - { - box2d const& bbox = (*marker)->bounding_box(); - coord2d center = bbox.center(); - - agg::trans_affine tr; - if (geom_transform) { evaluate_transform(tr, feature, *geom_transform); } - - agg::trans_affine_translation recenter(-center.x, -center.y); - agg::trans_affine recenter_tr = recenter * tr; - box2d label_ext = bbox * recenter_tr * agg::trans_affine_scaling(common_.scale_factor_); - - for (std::size_t i = 0; i < feature.num_geometries(); ++i) - { - geometry_type const& geom = feature.get_geometry(i); - double x; - double y; - double z = 0; - - if (placement == CENTROID_POINT_PLACEMENT) - { - if (!label::centroid(geom, x, y)) - return; - } - else - { - if (!label::interior_position(geom ,x, y)) - return; - } - - prj_trans.backward(x, y, z); - common_.t_.forward(&x, &y); - label_ext.re_center(x,y); - if (allow_overlap || - common_.detector_->has_placement(label_ext)) - { - render_marker(pixel_position(x,y),**marker, tr, opacity); - - if (!ignore_placement) - common_.detector_->insert(label_ext); - } - } - } + render_point_symbolizer( + sym, feature, prj_trans, common_, + [&](pixel_position const& pos, marker const& marker, + agg::trans_affine const& tr, double opacity) { + render_marker(pos, marker, tr, opacity); + }); } void cairo_renderer_base::process(shield_symbolizer const& sym, diff --git a/src/grid/process_point_symbolizer.cpp b/src/grid/process_point_symbolizer.cpp index 2cff6b9a5..bb14ee0cc 100644 --- a/src/grid/process_point_symbolizer.cpp +++ b/src/grid/process_point_symbolizer.cpp @@ -33,6 +33,7 @@ #include #include #include +#include // agg #include "agg_trans_affine.h" @@ -49,75 +50,20 @@ void grid_renderer::process(point_symbolizer const& sym, mapnik::feature_impl & feature, proj_transform const& prj_trans) { - std::string filename = get(sym, keys::file, feature); - - boost::optional marker; - if ( !filename.empty() ) - { - marker = marker_cache::instance().find(filename, true); - } - else - { - marker.reset(std::make_shared()); - } - - if (marker) - { - double opacity = get(sym,keys::opacity,feature, 1.0); - bool allow_overlap = get(sym, keys::allow_overlap, feature, false); - bool ignore_placement = get(sym, keys::ignore_placement, feature, false); - point_placement_enum placement= get(sym, keys::point_placement_type, feature, CENTROID_POINT_PLACEMENT); - auto img_transform = get_optional(sym, keys::image_transform); - composite_mode_e comp_op = get(sym, keys::comp_op, feature, src_over); - - box2d const& bbox = (*marker)->bounding_box(); - coord2d center = bbox.center(); - - agg::trans_affine tr; - if (img_transform) { evaluate_transform(tr, feature, *img_transform); } - tr = agg::trans_affine_scaling(common_.scale_factor_) * tr; - - agg::trans_affine_translation recenter(-center.x, -center.y); - agg::trans_affine recenter_tr = recenter * tr; - box2d label_ext = bbox * recenter_tr * agg::trans_affine_scaling(common_.scale_factor_) ; - - for (std::size_t i=0; ihas_placement(label_ext)) - { + composite_mode_e comp_op = get(sym, keys::comp_op, feature, src_over); + render_point_symbolizer( + sym, feature, prj_trans, common_, + [&](pixel_position const &pos, marker const &marker, + agg::trans_affine const &tr, double opacity) { render_marker(feature, pixmap_.get_resolution(), - pixel_position(x, y), - **marker, + pos, + marker, tr, opacity, comp_op); - - if (!ignore_placement) - common_.detector_->insert(label_ext); - } - } - } + }); } template void grid_renderer::process(point_symbolizer const&,