mapnik/src/grid/grid_renderer.cpp

246 lines
8.6 KiB
C++
Raw Normal View History

2011-04-26 23:44:52 +02:00
/*****************************************************************************
*
* This file is part of Mapnik (c++ mapping toolkit)
*
2014-11-20 15:25:50 +01:00
* Copyright (C) 2014 Artem Pavlenko
2011-04-26 23:44:52 +02:00
*
* 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
*
*****************************************************************************/
#if defined(GRID_RENDERER)
2011-04-26 23:44:52 +02:00
// mapnik
#include <mapnik/grid/grid_rasterizer.hpp>
#include <mapnik/grid/grid_renderer.hpp>
2012-12-20 04:19:30 +01:00
#include <mapnik/grid/grid_renderer_base.hpp>
2011-04-26 23:44:52 +02:00
#include <mapnik/grid/grid.hpp>
#include <mapnik/image_scaling.hpp>
#include <mapnik/rule.hpp>
#include <mapnik/debug.hpp>
#include <mapnik/layer.hpp>
#include <mapnik/label_collision_detector.hpp>
#include <mapnik/feature_type_style.hpp>
#include <mapnik/marker.hpp>
2011-04-26 23:44:52 +02:00
#include <mapnik/marker_cache.hpp>
#include <mapnik/unicode.hpp>
#include <mapnik/font_set.hpp>
#include <mapnik/parse_path.hpp>
2012-01-20 22:43:05 +01:00
#include <mapnik/map.hpp>
#include <mapnik/request.hpp>
2011-04-26 23:44:52 +02:00
#include <mapnik/svg/svg_converter.hpp>
#include <mapnik/svg/svg_renderer_agg.hpp>
2011-04-26 23:44:52 +02:00
#include <mapnik/svg/svg_path_adapter.hpp>
2013-03-13 00:56:47 +01:00
#include <mapnik/pixel_position.hpp>
2011-04-26 23:44:52 +02:00
// boost
#include <boost/math/special_functions/round.hpp>
2011-04-26 23:44:52 +02:00
2011-05-17 08:19:41 +02:00
// agg
#include "agg_trans_affine.h"
2011-04-26 23:44:52 +02:00
namespace mapnik
{
template <typename T>
grid_renderer<T>::grid_renderer(Map const& m, T & pixmap, double scale_factor, unsigned offset_x, unsigned offset_y)
: feature_style_processor<grid_renderer>(m, scale_factor),
pixmap_(pixmap),
ras_ptr(new grid_rasterizer),
common_(m, attributes(), offset_x, offset_y, m.width(), m.height(), scale_factor)
{
setup(m);
}
template <typename T>
2014-05-14 03:24:17 +02:00
grid_renderer<T>::grid_renderer(Map const& m, request const& req, attributes const& vars, T & pixmap, double scale_factor, unsigned offset_x, unsigned offset_y)
: feature_style_processor<grid_renderer>(m, scale_factor),
pixmap_(pixmap),
ras_ptr(new grid_rasterizer),
common_(m, req, vars, offset_x, offset_y, req.width(), req.height(), scale_factor)
{
setup(m);
}
template <typename T>
void grid_renderer<T>::setup(Map const& m)
2011-04-26 23:44:52 +02:00
{
MAPNIK_LOG_DEBUG(grid_renderer) << "grid_renderer: Scale=" << m.scale();
// nothing to do for grids yet on setup
2011-04-26 23:44:52 +02:00
}
template <typename T>
grid_renderer<T>::~grid_renderer() {}
template <typename T>
2012-04-08 02:20:56 +02:00
void grid_renderer<T>::start_map_processing(Map const& m)
2011-04-26 23:44:52 +02:00
{
MAPNIK_LOG_DEBUG(grid_renderer) << "grid_renderer: Start map processing bbox=" << m.get_current_extent();
2012-04-08 02:20:56 +02:00
ras_ptr->clip_box(0,0,common_.width_,common_.height_);
2011-04-26 23:44:52 +02:00
}
template <typename T>
void grid_renderer<T>::end_map_processing(Map const& /*m*/)
2011-04-26 23:44:52 +02:00
{
MAPNIK_LOG_DEBUG(grid_renderer) << "grid_renderer: End map processing";
2011-04-26 23:44:52 +02:00
}
template <typename T>
void grid_renderer<T>::start_layer_processing(layer const& lay, box2d<double> const& query_extent)
2011-04-26 23:44:52 +02:00
{
MAPNIK_LOG_DEBUG(grid_renderer) << "grid_renderer: Start processing layer=" << lay.name();
MAPNIK_LOG_DEBUG(grid_renderer) << "grid_renderer: datasource=" << lay.datasource().get();
MAPNIK_LOG_DEBUG(grid_renderer) << "grid_renderer: query_extent = " << query_extent;
2012-04-08 02:20:56 +02:00
2011-04-26 23:44:52 +02:00
if (lay.clear_label_cache())
{
common_.detector_->clear();
2011-04-26 23:44:52 +02:00
}
common_.query_extent_ = query_extent;
boost::optional<box2d<double> > const& maximum_extent = lay.maximum_extent();
if (maximum_extent)
{
common_.query_extent_.clip(*maximum_extent);
}
2011-04-26 23:44:52 +02:00
}
template <typename T>
void grid_renderer<T>::end_layer_processing(layer const&)
{
MAPNIK_LOG_DEBUG(grid_renderer) << "grid_renderer: End layer processing";
2011-04-26 23:44:52 +02:00
}
template <typename buffer_type>
struct grid_render_marker_visitor
2011-04-26 23:44:52 +02:00
{
grid_render_marker_visitor(buffer_type & pixmap,
std::unique_ptr<grid_rasterizer> const& ras_ptr,
renderer_common const& common,
mapnik::feature_impl const& feature,
pixel_position const& pos,
agg::trans_affine const& tr,
double opacity)
: pixmap_(pixmap),
ras_ptr_(ras_ptr),
common_(common),
feature_(feature),
pos_(pos),
tr_(tr),
opacity_(opacity) {}
void operator() (marker_null const&) {}
void operator() (marker_svg const& marker)
2011-04-26 23:44:52 +02:00
{
using pixfmt_type = typename grid_renderer_base_type::pixfmt_type;
using renderer_type = agg::renderer_scanline_bin_solid<grid_renderer_base_type>;
2011-05-17 08:19:41 +02:00
agg::scanline_bin sl;
2012-02-02 02:53:35 +01:00
grid_rendering_buffer buf(pixmap_.raw_data(), common_.width_, common_.height_, common_.width_);
2012-12-20 04:19:30 +01:00
pixfmt_type pixf(buf);
2012-02-02 02:53:35 +01:00
2012-12-20 04:19:30 +01:00
grid_renderer_base_type renb(pixf);
renderer_type ren(renb);
2012-02-02 02:53:35 +01:00
ras_ptr_->reset();
2011-04-26 23:44:52 +02:00
box2d<double> const& bbox = marker.get_data()->bounding_box();
2011-04-26 23:44:52 +02:00
coord<double,2> 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(common_.scale_factor_);
2011-04-26 23:44:52 +02:00
// render the marker at the center of the marker box
mtx.translate(pos_.x, pos_.y);
using namespace mapnik::svg;
vertex_stl_adapter<svg_path_storage> stl_storage(marker.get_data()->source());
2011-04-26 23:44:52 +02:00
svg_path_adapter svg_path(stl_storage);
svg_renderer_agg<svg_path_adapter,
2012-02-02 02:53:35 +01:00
agg::pod_bvector<path_attributes>,
2012-12-20 04:19:30 +01:00
renderer_type,
pixfmt_type> svg_renderer(svg_path,
marker.get_data()->attributes());
2012-02-02 02:53:35 +01:00
svg_renderer.render_id(*ras_ptr_, sl, renb, feature_.id(), mtx, opacity_, bbox);
2011-04-26 23:44:52 +02:00
}
void operator() (marker_rgba8 const& marker)
2011-04-26 23:44:52 +02:00
{
image_rgba8 const& data = marker.get_data();
double width = data.width();
double height = data.height();
double cx = 0.5 * width;
double cy = 0.5 * height;
if ((std::fabs(1.0 - common_.scale_factor_) < 0.001 && tr_.is_identity()))
{
// TODO - support opacity
pixmap_.set_rectangle(feature_.id(), data,
boost::math::iround(pos_.x - cx),
boost::math::iround(pos_.y - cy));
}
else
{
image_rgba8 target(data.width(), data.height());
mapnik::scale_image_agg(target,
data,
SCALING_NEAR,
1,
1,
0.0, 0.0, 1.0); // TODO: is 1.0 a valid default here, and do we even care in grid_renderer what the image looks like?
pixmap_.set_rectangle(feature_.id(), target,
boost::math::iround(pos_.x - cx),
boost::math::iround(pos_.y - cy));
}
2011-04-26 23:44:52 +02:00
}
private:
buffer_type & pixmap_;
std::unique_ptr<grid_rasterizer> const& ras_ptr_;
renderer_common const& common_;
mapnik::feature_impl const& feature_;
pixel_position const& pos_;
agg::trans_affine const& tr_;
double opacity_;
};
template <typename T>
void grid_renderer<T>::render_marker(mapnik::feature_impl const& feature,
pixel_position const& pos,
marker const& marker,
agg::trans_affine const& tr,
double opacity,
composite_mode_e /*comp_op*/)
{
grid_render_marker_visitor<buffer_type> visitor(pixmap_,
ras_ptr,
common_,
feature,
pos,
tr,
opacity);
util::apply_visitor(visitor, marker);
2011-04-26 23:44:52 +02:00
pixmap_.add_feature(feature);
}
template class MAPNIK_DECL grid_renderer<grid>;
2011-04-26 23:44:52 +02:00
}
Merge branch '2.3.x' of github.com:mapnik/mapnik Conflicts: .travis.yml CHANGELOG.md bindings/python/build.py include/mapnik/feature_style_processor_context.hpp include/mapnik/feature_style_processor_impl.hpp include/mapnik/json/feature_collection_grammar.hpp include/mapnik/json/feature_collection_parser.hpp include/mapnik/json/feature_generator_grammar.hpp include/mapnik/json/feature_parser.hpp include/mapnik/json/geojson_generator.hpp include/mapnik/json/geometry_generator_grammar.hpp include/mapnik/json/geometry_parser.hpp plugins/input/gdal/gdal_featureset.cpp plugins/input/geojson/geojson_datasource.cpp plugins/input/occi/occi_featureset.cpp plugins/input/osm/osm_featureset.cpp plugins/input/postgis/build.py plugins/input/postgis/connection.hpp src/agg/agg_renderer.cpp src/build.py src/cairo_context.cpp src/datasource_cache.cpp src/grid/process_line_symbolizer.cpp src/grid/process_polygon_pattern_symbolizer.cpp src/grid/process_polygon_symbolizer.cpp src/grid/process_text_symbolizer.cpp src/json/feature_grammar.cpp tests/cpp_tests/fontset_runtime_test.cpp tests/visual_tests/images/collision-600-400-1.0-agg-reference.png tests/visual_tests/images/image-filters-multi-blur-512-512-1.0-agg-reference.png tests/visual_tests/images/image-filters-multi-blur-512-512-2.0-agg-reference.png tests/visual_tests/images/image-filters-multi-blur-inflate-512-512-1.0-agg-reference.png tests/visual_tests/images/image-filters-multi-blur-inflate-512-512-2.0-agg-reference.png tests/visual_tests/images/lines-1-400-400-2.0-agg-reference.png tests/visual_tests/images/lines-1-600-600-1.0-agg-reference.png tests/visual_tests/images/lines-1-600-600-2.0-agg-reference.png tests/visual_tests/images/lines-2-200-200-1.0-agg-reference.png tests/visual_tests/images/lines-2-400-400-1.0-cairo-reference.png tests/visual_tests/images/lines-2-400-400-2.0-agg-reference.png tests/visual_tests/images/lines-2-600-600-2.0-agg-reference.png tests/visual_tests/images/lines-2-800-800-2.0-agg-reference.png tests/visual_tests/images/lines-3-400-400-2.0-agg-reference.png tests/visual_tests/images/lines-3-600-600-1.0-agg-reference.png tests/visual_tests/images/lines-3-600-600-2.0-agg-reference.png tests/visual_tests/images/lines-5-200-200-1.0-agg-reference.png tests/visual_tests/images/lines-5-200-200-2.0-agg-reference.png tests/visual_tests/images/lines-5-400-400-1.0-agg-reference.png tests/visual_tests/images/lines-5-400-400-2.0-agg-reference.png tests/visual_tests/images/lines-5-600-600-1.0-agg-reference.png tests/visual_tests/images/lines-5-600-600-2.0-agg-reference.png tests/visual_tests/images/lines-5-800-800-1.0-agg-reference.png tests/visual_tests/images/lines-5-800-800-2.0-agg-reference.png tests/visual_tests/images/lines-6-200-200-1.0-agg-reference.png tests/visual_tests/images/lines-6-200-200-2.0-agg-reference.png tests/visual_tests/images/lines-6-400-400-1.0-agg-reference.png tests/visual_tests/images/lines-6-600-600-1.0-agg-reference.png tests/visual_tests/images/lines-6-600-600-2.0-agg-reference.png tests/visual_tests/images/lines-6-800-800-1.0-agg-reference.png tests/visual_tests/images/lines-6-800-800-2.0-agg-reference.png tests/visual_tests/images/lines-shield-600-600-2.0-agg-reference.png tests/visual_tests/images/lines-shield-600-600-2.0-cairo-reference.png tests/visual_tests/images/shield-on-polygon-600-400-1.0-agg-reference.png tests/visual_tests/images/shield-on-polygon-600-400-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-1-490-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-1-495-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-1-495-100-2.0-cairo-reference.png tests/visual_tests/images/shieldsymbolizer-1-497-100-1.0-cairo-reference.png tests/visual_tests/images/shieldsymbolizer-1-497-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-1-497-100-2.0-cairo-reference.png tests/visual_tests/images/shieldsymbolizer-1-498-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-1-499-100-1.0-cairo-reference.png tests/visual_tests/images/shieldsymbolizer-1-499-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-1-499-100-2.0-cairo-reference.png tests/visual_tests/images/shieldsymbolizer-1-500-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-1-501-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-1-502-100-1.0-cairo-reference.png tests/visual_tests/images/shieldsymbolizer-1-502-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-1-505-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-1-505-100-2.0-cairo-reference.png tests/visual_tests/images/shieldsymbolizer-1-510-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-3-490-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-3-495-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-3-497-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-3-498-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-3-499-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-3-500-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-3-501-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-3-502-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-3-505-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-3-510-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-4-490-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-4-495-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-4-497-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-4-498-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-4-499-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-4-500-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-4-501-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-4-502-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-4-505-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-4-510-100-2.0-agg-reference.png tests/visual_tests/test.py
2014-04-24 23:50:55 +02:00
#endif