/***************************************************************************** * * This file is part of Mapnik (c++ mapping toolkit) * * Copyright (C) 2011 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 * *****************************************************************************/ //$Id$ // mapnik #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include // boost #include // agg #include "agg_trans_affine.h" // stl #ifdef MAPNIK_DEBUG #include #endif //#include namespace mapnik { template grid_renderer::grid_renderer(Map const& m, T & pixmap, double scale_factor, unsigned offset_x, unsigned offset_y) : feature_style_processor(m, scale_factor), pixmap_(pixmap), width_(pixmap_.width()), height_(pixmap_.height()), scale_factor_(scale_factor), t_(pixmap_.width(),pixmap_.height(),m.get_current_extent(),offset_x,offset_y), font_engine_(), font_manager_(font_engine_), detector_(box2d(-m.buffer_size(), -m.buffer_size(), pixmap_.width() + m.buffer_size(), pixmap_.height() + m.buffer_size())), ras_ptr(new grid_rasterizer) { #ifdef MAPNIK_DEBUG std::clog << "scale=" << m.scale() << "\n"; #endif } template grid_renderer::~grid_renderer() {} template void grid_renderer::start_map_processing(Map const& map) { #ifdef MAPNIK_DEBUG std::clog << "start map processing bbox=" << map.get_current_extent() << "\n"; #endif ras_ptr->clip_box(0,0,width_,height_); } template void grid_renderer::end_map_processing(Map const& ) { #ifdef MAPNIK_DEBUG std::clog << "end map processing\n"; #endif } template void grid_renderer::start_layer_processing(layer const& lay) { #ifdef MAPNIK_DEBUG std::clog << "start layer processing : " << lay.name() << "\n"; std::clog << "datasource = " << lay.datasource().get() << "\n"; #endif if (lay.clear_label_cache()) { detector_.clear(); } } template void grid_renderer::end_layer_processing(layer const&) { #ifdef MAPNIK_DEBUG std::clog << "end layer processing\n"; #endif } template void grid_renderer::render_marker(mapnik::feature_ptr const& feature, unsigned int step, const int x, const int y, marker &marker, const agg::trans_affine & tr, double opacity) { if (marker.is_vector()) { typedef coord_transform2 path_type; typedef agg::renderer_base ren_base; typedef agg::renderer_scanline_bin_solid renderer; agg::scanline_bin sl; grid_rendering_buffer buf(pixmap_.raw_data(), width_, height_, width_); mapnik::pixfmt_gray16 pixf(buf); ren_base renb(pixf); renderer ren(renb); ras_ptr->reset(); box2d const& bbox = (*marker.get_vector_data())->bounding_box(); coord c = bbox.center(); // center the svg marker on '0,0' agg::trans_affine mtx = agg::trans_affine_translation(-c.x,-c.y); // apply symbol transformation to get to map space mtx *= tr; mtx *= agg::trans_affine_scaling(scale_factor_*(1.0/step)); // render the marker at the center of the marker box mtx.translate(x+0.5 * marker.width(), y+0.5 * marker.height()); vertex_stl_adapter stl_storage((*marker.get_vector_data())->source()); svg_path_adapter svg_path(stl_storage); svg_renderer, renderer, mapnik::pixfmt_gray16> svg_renderer(svg_path, (*marker.get_vector_data())->attributes()); svg_renderer.render_id(*ras_ptr, sl, renb, feature->id(), mtx, opacity, bbox); } else { image_data_32 const& data = **marker.get_bitmap_data(); if (step == 1 && scale_factor_ == 1.0) { pixmap_.set_rectangle(feature->id(), data, x, y); } else { double ratio = (1.0/step); image_data_32 target(ratio * data.width(), ratio * data.height()); mapnik::scale_image_agg(target,data, SCALING_NEAR, scale_factor_, 0.0, 0.0, 1.0, ratio); pixmap_.set_rectangle(feature->id(), target, x, y); } } pixmap_.add_feature(feature); } template class hit_grid; template class grid_renderer; }