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
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2014-04-24 21:54:18 +02:00
|
|
|
#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>
|
2012-08-02 22:10:05 +02:00
|
|
|
|
2013-01-04 03:06:07 +01:00
|
|
|
|
|
|
|
#include <mapnik/image_scaling.hpp>
|
|
|
|
#include <mapnik/rule.hpp>
|
2012-08-02 22:10:05 +02:00
|
|
|
#include <mapnik/debug.hpp>
|
|
|
|
#include <mapnik/layer.hpp>
|
2013-01-04 03:06:07 +01:00
|
|
|
#include <mapnik/label_collision_detector.hpp>
|
2012-08-02 22:10:05 +02:00
|
|
|
#include <mapnik/feature_type_style.hpp>
|
2012-03-08 17:37:58 +01:00
|
|
|
#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>
|
2013-02-26 21:05:44 +01:00
|
|
|
#include <mapnik/request.hpp>
|
2011-04-26 23:44:52 +02:00
|
|
|
#include <mapnik/svg/svg_converter.hpp>
|
2012-08-28 02:58:49 +02:00
|
|
|
#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
|
2012-02-20 19:32:34 +01:00
|
|
|
#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),
|
2013-12-05 20:34:32 +01:00
|
|
|
ras_ptr(new grid_rasterizer),
|
2014-09-12 09:56:51 +02:00
|
|
|
common_(m, attributes(), offset_x, offset_y, m.width(), m.height(), scale_factor)
|
2012-08-02 22:10:05 +02:00
|
|
|
{
|
|
|
|
setup(m);
|
|
|
|
}
|
|
|
|
|
2013-02-26 21:05:44 +01:00
|
|
|
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)
|
2013-02-26 21:05:44 +01:00
|
|
|
: feature_style_processor<grid_renderer>(m, scale_factor),
|
|
|
|
pixmap_(pixmap),
|
2013-12-05 20:34:32 +01:00
|
|
|
ras_ptr(new grid_rasterizer),
|
2014-09-26 07:37:43 +02:00
|
|
|
common_(m, req, vars, offset_x, offset_y, req.width(), req.height(), scale_factor)
|
2013-02-26 21:05:44 +01:00
|
|
|
{
|
|
|
|
setup(m);
|
|
|
|
}
|
|
|
|
|
2012-08-02 22:10:05 +02:00
|
|
|
template <typename T>
|
|
|
|
void grid_renderer<T>::setup(Map const& m)
|
2011-04-26 23:44:52 +02:00
|
|
|
{
|
2012-04-09 21:41:56 +02:00
|
|
|
MAPNIK_LOG_DEBUG(grid_renderer) << "grid_renderer: Scale=" << m.scale();
|
2012-08-02 22:10:05 +02:00
|
|
|
// 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
|
|
|
{
|
2012-04-09 21:41:56 +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
|
|
|
|
2013-12-05 20:34:32 +01:00
|
|
|
ras_ptr->clip_box(0,0,common_.width_,common_.height_);
|
2011-04-26 23:44:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
2013-07-24 00:46:54 +02:00
|
|
|
void grid_renderer<T>::end_map_processing(Map const& /*m*/)
|
2011-04-26 23:44:52 +02:00
|
|
|
{
|
2012-04-09 21:41:56 +02:00
|
|
|
MAPNIK_LOG_DEBUG(grid_renderer) << "grid_renderer: End map processing";
|
2011-04-26 23:44:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
2012-03-06 14:07:04 +01:00
|
|
|
void grid_renderer<T>::start_layer_processing(layer const& lay, box2d<double> const& query_extent)
|
2011-04-26 23:44:52 +02:00
|
|
|
{
|
2012-04-09 21:41:56 +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())
|
|
|
|
{
|
2013-12-05 20:34:32 +01:00
|
|
|
common_.detector_->clear();
|
2011-04-26 23:44:52 +02:00
|
|
|
}
|
2013-12-05 20:34:32 +01:00
|
|
|
common_.query_extent_ = query_extent;
|
2012-08-02 22:10:05 +02:00
|
|
|
boost::optional<box2d<double> > const& maximum_extent = lay.maximum_extent();
|
|
|
|
if (maximum_extent)
|
|
|
|
{
|
2013-12-05 20:34:32 +01:00
|
|
|
common_.query_extent_.clip(*maximum_extent);
|
2012-08-02 22:10:05 +02:00
|
|
|
}
|
2011-04-26 23:44:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
void grid_renderer<T>::end_layer_processing(layer const&)
|
|
|
|
{
|
2012-04-09 21:41:56 +02:00
|
|
|
MAPNIK_LOG_DEBUG(grid_renderer) << "grid_renderer: End layer processing";
|
2011-04-26 23:44:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
2014-09-12 09:56:51 +02:00
|
|
|
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*/)
|
2011-04-26 23:44:52 +02:00
|
|
|
{
|
|
|
|
if (marker.is_vector())
|
|
|
|
{
|
2014-07-07 19:23:15 +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
|
|
|
|
2013-12-05 20:34:32 +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
|
|
|
|
2011-04-26 23:44:52 +02:00
|
|
|
ras_ptr->reset();
|
|
|
|
|
|
|
|
box2d<double> const& bbox = (*marker.get_vector_data())->bounding_box();
|
|
|
|
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;
|
2014-09-12 09:56:51 +02:00
|
|
|
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
|
2012-07-16 20:51:14 +02:00
|
|
|
mtx.translate(pos.x, pos.y);
|
2012-03-08 17:37:58 +01:00
|
|
|
using namespace mapnik::svg;
|
2011-04-26 23:44:52 +02:00
|
|
|
vertex_stl_adapter<svg_path_storage> stl_storage((*marker.get_vector_data())->source());
|
|
|
|
svg_path_adapter svg_path(stl_storage);
|
2012-08-28 02:58:49 +02:00
|
|
|
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,
|
2012-02-02 02:53:35 +01:00
|
|
|
(*marker.get_vector_data())->attributes());
|
2011-04-26 23:44:52 +02:00
|
|
|
|
2012-06-16 04:17:26 +02:00
|
|
|
svg_renderer.render_id(*ras_ptr, sl, renb, feature.id(), mtx, opacity, bbox);
|
2012-02-02 02:53:35 +01:00
|
|
|
|
2011-04-26 23:44:52 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-05-03 00:33:11 +02:00
|
|
|
image_data_32 const& data = **marker.get_bitmap_data();
|
2012-08-02 22:10:05 +02:00
|
|
|
double width = data.width();
|
|
|
|
double height = data.height();
|
|
|
|
double cx = 0.5 * width;
|
|
|
|
double cy = 0.5 * height;
|
2014-09-12 09:56:51 +02:00
|
|
|
if ((std::fabs(1.0 - common_.scale_factor_) < 0.001 && tr.is_identity()))
|
2011-05-03 00:33:11 +02:00
|
|
|
{
|
2012-08-02 22:10:05 +02:00
|
|
|
// TODO - support opacity
|
2012-06-16 04:17:26 +02:00
|
|
|
pixmap_.set_rectangle(feature.id(), data,
|
2012-08-02 22:10:05 +02:00
|
|
|
boost::math::iround(pos.x - cx),
|
|
|
|
boost::math::iround(pos.y - cy));
|
2011-05-03 00:33:11 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-09-12 09:56:51 +02:00
|
|
|
image_data_32 target(data.width(), data.height());
|
2013-03-07 02:41:20 +01:00
|
|
|
mapnik::scale_image_agg<image_data_32>(target,
|
|
|
|
data,
|
|
|
|
SCALING_NEAR,
|
2014-09-12 09:56:51 +02:00
|
|
|
1,
|
|
|
|
1,
|
2013-12-02 14:46:52 +01:00
|
|
|
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?
|
2012-06-16 04:17:26 +02:00
|
|
|
pixmap_.set_rectangle(feature.id(), target,
|
2012-08-02 22:10:05 +02:00
|
|
|
boost::math::iround(pos.x - cx),
|
|
|
|
boost::math::iround(pos.y - cy));
|
2011-05-03 00:33:11 +02:00
|
|
|
}
|
2011-04-26 23:44:52 +02:00
|
|
|
}
|
|
|
|
pixmap_.add_feature(feature);
|
|
|
|
}
|
|
|
|
|
|
|
|
template class grid_renderer<grid>;
|
2011-10-19 16:29:24 +02:00
|
|
|
|
2011-04-26 23:44:52 +02:00
|
|
|
}
|
2014-04-24 21:54:18 +02:00
|
|
|
|
2014-04-24 23:50:55 +02:00
|
|
|
#endif
|