2010-06-01 15:31:08 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
*
|
|
|
|
* This file is part of Mapnik (c++ mapping toolkit)
|
|
|
|
*
|
2011-10-23 15:04:25 +02:00
|
|
|
* Copyright (C) 2011 Artem Pavlenko
|
2010-06-01 15:31:08 +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
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2012-04-08 02:20:56 +02:00
|
|
|
// mapnik
|
|
|
|
#include <mapnik/debug.hpp>
|
2012-05-09 13:39:23 +02:00
|
|
|
#include <mapnik/graphics.hpp>
|
2010-06-01 15:31:08 +02:00
|
|
|
#include <mapnik/agg_renderer.hpp>
|
2010-06-13 14:03:42 +02:00
|
|
|
#include <mapnik/agg_rasterizer.hpp>
|
2011-09-01 02:43:46 +02:00
|
|
|
#include <mapnik/expression_evaluator.hpp>
|
2010-06-01 15:31:08 +02:00
|
|
|
#include <mapnik/image_util.hpp>
|
2012-03-08 17:37:58 +01:00
|
|
|
#include <mapnik/marker.hpp>
|
2011-01-26 02:18:40 +01:00
|
|
|
#include <mapnik/marker_cache.hpp>
|
2010-06-08 12:16:22 +02:00
|
|
|
#include <mapnik/svg/svg_renderer.hpp>
|
2010-06-14 18:38:02 +02:00
|
|
|
#include <mapnik/svg/svg_path_adapter.hpp>
|
2010-06-01 15:31:08 +02:00
|
|
|
#include <mapnik/markers_placement.hpp>
|
|
|
|
#include <mapnik/arrow.hpp>
|
2012-01-20 22:43:05 +01:00
|
|
|
#include <mapnik/markers_symbolizer.hpp>
|
2010-06-01 15:31:08 +02:00
|
|
|
|
|
|
|
#include "agg_basics.h"
|
|
|
|
#include "agg_rendering_buffer.h"
|
|
|
|
#include "agg_pixfmt_rgba.h"
|
|
|
|
#include "agg_rasterizer_scanline_aa.h"
|
|
|
|
#include "agg_scanline_u.h"
|
2010-08-19 19:33:01 +02:00
|
|
|
#include "agg_scanline_p.h"
|
|
|
|
#include "agg_path_storage.h"
|
|
|
|
#include "agg_ellipse.h"
|
|
|
|
#include "agg_conv_stroke.h"
|
2012-03-07 13:48:51 +01:00
|
|
|
#include "agg_conv_clip_polyline.h"
|
2012-06-26 16:00:42 +02:00
|
|
|
#include "agg_conv_transform.h"
|
2010-06-01 15:31:08 +02:00
|
|
|
|
|
|
|
namespace mapnik {
|
|
|
|
|
2012-07-05 18:17:35 +02:00
|
|
|
|
|
|
|
template <typename Attr>
|
|
|
|
bool push_explicit_style(Attr const& src, Attr & dst, markers_symbolizer const& sym)
|
|
|
|
{
|
|
|
|
boost::optional<stroke> const& strk = sym.get_stroke();
|
|
|
|
boost::optional<color> const& fill = sym.get_fill();
|
|
|
|
if (strk || fill)
|
|
|
|
{
|
|
|
|
for(unsigned i = 0; i < src.size(); ++i)
|
|
|
|
{
|
|
|
|
mapnik::svg::path_attributes attr = src[i];
|
|
|
|
|
|
|
|
if (strk)
|
|
|
|
{
|
|
|
|
attr.stroke_width = (*strk).get_width();
|
|
|
|
color const& s_color = (*strk).get_color();
|
|
|
|
attr.stroke_color = agg::rgba(s_color.red()/255.0,s_color.green()/255.0,
|
|
|
|
s_color.blue()/255.0,s_color.alpha()/255.0);
|
|
|
|
}
|
|
|
|
if (fill)
|
|
|
|
{
|
|
|
|
|
|
|
|
color const& f_color = *fill;
|
|
|
|
attr.fill_color = agg::rgba(f_color.red()/255.0,f_color.green()/255.0,
|
|
|
|
f_color.blue()/255.0,f_color.alpha()/255.0);
|
|
|
|
}
|
|
|
|
dst.push_back(attr);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-07-09 11:22:19 +02:00
|
|
|
template <typename T>
|
|
|
|
void setup_label_transform(agg::trans_affine & tr, box2d<double> const& bbox, mapnik::feature_impl const& feature, T const& sym)
|
|
|
|
{
|
|
|
|
int width = 0;
|
|
|
|
int height = 0;
|
|
|
|
|
|
|
|
expression_ptr const& width_expr = sym.get_width();
|
|
|
|
if (width_expr)
|
|
|
|
width = boost::apply_visitor(evaluate<Feature,value_type>(feature), *width_expr).to_int();
|
|
|
|
|
|
|
|
expression_ptr const& height_expr = sym.get_height();
|
|
|
|
if (height_expr)
|
|
|
|
height = boost::apply_visitor(evaluate<Feature,value_type>(feature), *height_expr).to_int();
|
|
|
|
|
|
|
|
if (width > 0 && height > 0)
|
|
|
|
{
|
|
|
|
double sx = width/bbox.width();
|
|
|
|
double sy = height/bbox.height();
|
|
|
|
tr *= agg::trans_affine_scaling(sx,sy);
|
|
|
|
}
|
|
|
|
else if (width > 0)
|
|
|
|
{
|
|
|
|
double sx = width/bbox.width();
|
|
|
|
tr *= agg::trans_affine_scaling(sx);
|
|
|
|
}
|
|
|
|
else if (height > 0)
|
|
|
|
{
|
|
|
|
double sy = height/bbox.height();
|
|
|
|
tr *= agg::trans_affine_scaling(sy);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
evaluate_transform(tr, feature, sym.get_image_transform());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-01 15:31:08 +02:00
|
|
|
template <typename T>
|
|
|
|
void agg_renderer<T>::process(markers_symbolizer const& sym,
|
2012-06-16 04:17:26 +02:00
|
|
|
mapnik::feature_impl & feature,
|
2010-06-02 13:03:30 +02:00
|
|
|
proj_transform const& prj_trans)
|
2010-06-01 15:31:08 +02:00
|
|
|
{
|
2012-03-07 13:48:51 +01:00
|
|
|
typedef agg::conv_clip_polyline<geometry_type> clipped_geometry_type;
|
2012-05-31 13:13:09 +02:00
|
|
|
typedef coord_transform<CoordTransform,clipped_geometry_type> path_type;
|
2012-06-26 16:00:42 +02:00
|
|
|
typedef agg::conv_transform<path_type, agg::trans_affine> transformed_path_type;
|
2012-05-15 17:13:08 +02:00
|
|
|
typedef agg::rgba8 color_type;
|
|
|
|
typedef agg::order_rgba order_type;
|
|
|
|
typedef agg::pixel32_type pixel_type;
|
2012-06-19 00:47:30 +02:00
|
|
|
typedef agg::comp_op_adaptor_rgba_pre<color_type, order_type> blender_type; // comp blender
|
2012-05-15 17:13:08 +02:00
|
|
|
typedef agg::pixfmt_custom_blend_rgba<blender_type, agg::rendering_buffer> pixfmt_comp_type;
|
|
|
|
typedef agg::renderer_base<pixfmt_comp_type> renderer_base;
|
|
|
|
typedef agg::renderer_scanline_aa_solid<renderer_base> renderer_type;
|
2012-06-26 16:00:42 +02:00
|
|
|
|
2010-06-01 15:31:08 +02:00
|
|
|
ras_ptr->reset();
|
2012-01-13 18:20:03 +01:00
|
|
|
ras_ptr->gamma(agg::gamma_power());
|
2010-06-01 15:31:08 +02:00
|
|
|
agg::scanline_u8 sl;
|
2012-06-21 21:19:45 +02:00
|
|
|
agg::rendering_buffer buf(current_buffer_->raw_data(), width_, height_, width_ * 4);
|
2012-05-15 17:13:08 +02:00
|
|
|
pixfmt_comp_type pixf(buf);
|
|
|
|
pixf.comp_op(static_cast<agg::comp_op_e>(sym.comp_op()));
|
2010-06-01 15:31:08 +02:00
|
|
|
renderer_base renb(pixf);
|
2012-05-15 17:13:08 +02:00
|
|
|
renderer_type ren(renb);
|
2012-06-26 16:00:42 +02:00
|
|
|
|
2012-06-27 14:46:52 +02:00
|
|
|
agg::trans_affine geom_tr;
|
2012-07-04 15:50:11 +02:00
|
|
|
evaluate_transform(geom_tr, feature, sym.get_transform());
|
2012-06-27 14:46:52 +02:00
|
|
|
|
2012-06-16 04:17:26 +02:00
|
|
|
std::string filename = path_processor_type::evaluate(*sym.get_filename(), feature);
|
2010-08-19 19:33:01 +02:00
|
|
|
marker_placement_e placement_method = sym.get_marker_placement();
|
2012-02-02 02:53:35 +01:00
|
|
|
|
2010-06-02 14:53:23 +02:00
|
|
|
if (!filename.empty())
|
|
|
|
{
|
2011-01-26 02:18:40 +01:00
|
|
|
boost::optional<marker_ptr> mark = mapnik::marker_cache::instance()->find(filename, true);
|
2011-06-24 22:34:21 +02:00
|
|
|
if (mark && *mark)
|
2010-06-02 14:53:23 +02:00
|
|
|
{
|
2012-04-08 02:20:56 +02:00
|
|
|
if (!(*mark)->is_vector())
|
|
|
|
{
|
2012-06-04 20:11:29 +02:00
|
|
|
MAPNIK_LOG_DEBUG(agg_renderer) << "agg_renderer: markers_symbolizer does not yet support non-SVG markers";
|
2011-06-24 22:34:21 +02:00
|
|
|
return;
|
|
|
|
}
|
2012-07-09 11:22:19 +02:00
|
|
|
|
2011-01-26 02:18:40 +01:00
|
|
|
boost::optional<path_ptr> marker = (*mark)->get_vector_data();
|
2010-06-08 12:16:31 +02:00
|
|
|
box2d<double> const& bbox = (*marker)->bounding_box();
|
2012-05-27 23:50:09 +02:00
|
|
|
|
2012-07-09 11:22:19 +02:00
|
|
|
|
|
|
|
agg::trans_affine tr;
|
|
|
|
|
|
|
|
|
|
|
|
setup_label_transform(tr, bbox, feature, sym);
|
|
|
|
tr = agg::trans_affine_scaling(scale_factor_) * tr;
|
|
|
|
|
|
|
|
|
|
|
|
coord2d center = bbox.center();
|
2012-07-05 18:17:35 +02:00
|
|
|
agg::trans_affine_translation recenter(-center.x, -center.y);
|
|
|
|
agg::trans_affine marker_trans = recenter * tr;
|
2012-06-27 14:46:52 +02:00
|
|
|
|
2010-06-14 18:38:02 +02:00
|
|
|
using namespace mapnik::svg;
|
|
|
|
vertex_stl_adapter<svg_path_storage> stl_storage((*marker)->source());
|
|
|
|
svg_path_adapter svg_path(stl_storage);
|
2012-06-26 16:00:42 +02:00
|
|
|
|
2012-07-05 18:17:35 +02:00
|
|
|
agg::pod_bvector<path_attributes> attributes;
|
|
|
|
bool result = push_explicit_style( (*marker)->attributes(), attributes, sym);
|
|
|
|
|
2012-02-02 02:53:35 +01:00
|
|
|
svg_renderer<svg_path_adapter,
|
2012-07-05 18:17:35 +02:00
|
|
|
agg::pod_bvector<path_attributes>,
|
|
|
|
renderer_type,
|
|
|
|
agg::pixfmt_rgba32 > svg_renderer(svg_path, result ? attributes : (*marker)->attributes());
|
2010-06-14 18:38:02 +02:00
|
|
|
|
2012-07-05 18:17:35 +02:00
|
|
|
BOOST_FOREACH( geometry_type & geom, feature.paths())
|
2010-06-08 13:14:31 +02:00
|
|
|
{
|
2011-11-16 18:56:35 +01:00
|
|
|
// TODO - merge this code with point_symbolizer rendering
|
|
|
|
if (placement_method == MARKER_POINT_PLACEMENT || geom.num_points() <= 1)
|
2010-08-19 19:33:01 +02:00
|
|
|
{
|
2011-11-16 18:56:35 +01:00
|
|
|
double x;
|
|
|
|
double y;
|
|
|
|
double z=0;
|
|
|
|
geom.label_interior_position(&x, &y);
|
|
|
|
prj_trans.backward(x,y,z);
|
|
|
|
t_.forward(&x,&y);
|
2012-06-27 14:46:52 +02:00
|
|
|
geom_tr.transform(&x,&y);
|
|
|
|
agg::trans_affine matrix = marker_trans;
|
2012-06-26 16:00:42 +02:00
|
|
|
matrix.translate(x,y);
|
|
|
|
box2d<double> transformed_bbox = bbox * matrix;
|
2012-06-27 14:46:52 +02:00
|
|
|
|
2011-11-16 18:56:35 +01:00
|
|
|
if (sym.get_allow_overlap() ||
|
2012-06-26 16:00:42 +02:00
|
|
|
detector_->has_placement(transformed_bbox))
|
2011-11-16 18:56:35 +01:00
|
|
|
{
|
2012-06-27 14:46:52 +02:00
|
|
|
svg_renderer.render(*ras_ptr, sl, renb, matrix, sym.get_opacity(), bbox);
|
|
|
|
if (/* DEBUG */ 0)
|
2012-06-26 16:00:42 +02:00
|
|
|
{
|
|
|
|
debug_draw_box(buf, transformed_bbox, 0, 0, 0.0);
|
2012-05-27 23:50:09 +02:00
|
|
|
}
|
2012-06-27 14:46:52 +02:00
|
|
|
|
2012-06-26 16:00:42 +02:00
|
|
|
if (!sym.get_ignore_placement())
|
|
|
|
detector_->insert(transformed_bbox);
|
2011-11-16 18:56:35 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2010-06-08 13:14:31 +02:00
|
|
|
{
|
2012-03-07 13:48:51 +01:00
|
|
|
clipped_geometry_type clipped(geom);
|
|
|
|
clipped.clip_box(query_extent_.minx(),query_extent_.miny(),query_extent_.maxx(),query_extent_.maxy());
|
|
|
|
path_type path(t_,clipped,prj_trans);
|
2012-06-26 16:00:42 +02:00
|
|
|
transformed_path_type path_transformed(path,geom_tr);
|
|
|
|
markers_placement<transformed_path_type, label_collision_detector4> placement(path_transformed, bbox, marker_trans, *detector_,
|
2012-07-05 18:17:35 +02:00
|
|
|
sym.get_spacing() * scale_factor_,
|
|
|
|
sym.get_max_error(),
|
|
|
|
sym.get_allow_overlap());
|
2011-11-16 18:56:35 +01:00
|
|
|
double x, y, angle;
|
2012-06-26 16:00:42 +02:00
|
|
|
while (placement.get_point(x, y, angle))
|
2011-11-16 18:56:35 +01:00
|
|
|
{
|
2012-06-26 16:00:42 +02:00
|
|
|
agg::trans_affine matrix = marker_trans;
|
2012-05-27 23:50:09 +02:00
|
|
|
matrix.rotate(angle);
|
2012-06-27 14:46:52 +02:00
|
|
|
matrix.translate(x, y);
|
2012-06-26 16:00:42 +02:00
|
|
|
svg_renderer.render(*ras_ptr, sl, renb, matrix, sym.get_opacity(), bbox);
|
2012-06-27 14:46:52 +02:00
|
|
|
|
|
|
|
if (/* DEBUG */ 0)
|
|
|
|
{
|
2012-06-26 16:00:42 +02:00
|
|
|
debug_draw_box(buf, bbox*matrix, 0, 0, 0.0);
|
2012-05-27 23:50:09 +02:00
|
|
|
}
|
2010-10-15 02:12:51 +02:00
|
|
|
}
|
2010-08-19 19:33:01 +02:00
|
|
|
}
|
|
|
|
}
|
2010-06-01 15:31:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-04 15:22:44 +02:00
|
|
|
|
2010-06-01 15:31:08 +02:00
|
|
|
template void agg_renderer<image_32>::process(markers_symbolizer const&,
|
2012-06-16 04:17:26 +02:00
|
|
|
mapnik::feature_impl &,
|
2010-06-02 13:03:30 +02:00
|
|
|
proj_transform const&);
|
2010-06-01 15:31:08 +02:00
|
|
|
}
|