Merge branch 'refactor-markers'

This commit is contained in:
artemp 2014-06-05 17:29:29 +01:00
commit 14ed48db50
10 changed files with 229 additions and 296 deletions

View file

@ -2,8 +2,7 @@ language: cpp
compiler: compiler:
- gcc - gcc
# disabled to due https://github.com/mapnik/mapnik/issues/2235 - clang
#- clang
addons: addons:
postgresql: "9.3" postgresql: "9.3"
@ -47,4 +46,5 @@ notifications:
irc: irc:
channels: channels:
- "irc.freenode.org#mapnik" - "irc.freenode.org#mapnik"
use_notice: true use_notice: true

View file

@ -41,26 +41,28 @@
namespace mapnik { namespace mapnik {
template <typename BufferType, typename Rasterizer, typename PixFmt, typename RendererBase, typename RendererType, typename Detector, typename PixMapType> template <typename RendererBase, typename RendererType, typename Detector, typename RendererContext>
struct raster_markers_rasterizer_dispatch_grid struct raster_markers_rasterizer_dispatch_grid : mapnik::noncopyable
{ {
typedef typename RendererBase::pixfmt_type pixfmt_type; typedef typename RendererBase::pixfmt_type pixfmt_type;
typedef typename RendererBase::pixfmt_type::color_type color_type; typedef typename RendererBase::pixfmt_type::color_type color_type;
raster_markers_rasterizer_dispatch_grid(BufferType & render_buffer, typedef typename std::tuple_element<0,RendererContext>::type BufferType;
Rasterizer & ras, typedef typename std::tuple_element<1,RendererContext>::type RasterizerType;
image_data_32 const& src, typedef typename std::tuple_element<2,RendererContext>::type PixMapType;
raster_markers_rasterizer_dispatch_grid(image_data_32 const& src,
agg::trans_affine const& marker_trans, agg::trans_affine const& marker_trans,
markers_symbolizer const& sym, markers_symbolizer const& sym,
Detector & detector, Detector & detector,
double scale_factor, double scale_factor,
mapnik::feature_impl const& feature, mapnik::feature_impl const& feature,
attributes const& vars, attributes const& vars,
PixMapType & pixmap) RendererContext const& renderer_context)
: buf_(render_buffer), : buf_(std::get<0>(renderer_context)),
pixf_(buf_), pixf_(buf_),
renb_(pixf_), renb_(pixf_),
ras_(ras), ras_(std::get<1>(renderer_context)),
src_(src), src_(src),
marker_trans_(marker_trans), marker_trans_(marker_trans),
sym_(sym), sym_(sym),
@ -68,10 +70,8 @@ struct raster_markers_rasterizer_dispatch_grid
scale_factor_(scale_factor), scale_factor_(scale_factor),
feature_(feature), feature_(feature),
vars_(vars), vars_(vars),
pixmap_(pixmap), pixmap_(std::get<2>(renderer_context)),
placed_(false) placed_(false) {}
{
}
template <typename T> template <typename T>
void add_path(T & path) void add_path(T & path)
@ -175,9 +175,9 @@ struct raster_markers_rasterizer_dispatch_grid
private: private:
BufferType & buf_; BufferType & buf_;
PixFmt pixf_; pixfmt_type pixf_;
RendererBase renb_; RendererBase renb_;
Rasterizer & ras_; RasterizerType & ras_;
image_data_32 const& src_; image_data_32 const& src_;
agg::trans_affine const& marker_trans_; agg::trans_affine const& marker_trans_;
markers_symbolizer const& sym_; markers_symbolizer const& sym_;
@ -190,18 +190,20 @@ private:
}; };
template <typename BufferType, typename SvgRenderer, typename Rasterizer, typename Detector, typename PixMapType> template <typename SvgRenderer, typename Detector, typename RendererContext>
struct vector_markers_rasterizer_dispatch_grid struct vector_markers_rasterizer_dispatch_grid : mapnik::noncopyable
{ {
typedef typename SvgRenderer::renderer_base renderer_base; typedef typename SvgRenderer::renderer_base renderer_base;
typedef typename SvgRenderer::vertex_source_type vertex_source_type; typedef typename SvgRenderer::vertex_source_type vertex_source_type;
typedef typename SvgRenderer::attribute_source_type attribute_source_type; typedef typename SvgRenderer::attribute_source_type attribute_source_type;
typedef typename renderer_base::pixfmt_type pixfmt_type; typedef typename renderer_base::pixfmt_type pixfmt_type;
vector_markers_rasterizer_dispatch_grid(BufferType & render_buffer, typedef typename std::tuple_element<0,RendererContext>::type BufferType;
vertex_source_type & path, typedef typename std::tuple_element<1,RendererContext>::type RasterizerType;
typedef typename std::tuple_element<2,RendererContext>::type PixMapType;
vector_markers_rasterizer_dispatch_grid(vertex_source_type & path,
attribute_source_type const& attrs, attribute_source_type const& attrs,
Rasterizer & ras,
box2d<double> const& bbox, box2d<double> const& bbox,
agg::trans_affine const& marker_trans, agg::trans_affine const& marker_trans,
markers_symbolizer const& sym, markers_symbolizer const& sym,
@ -209,12 +211,13 @@ struct vector_markers_rasterizer_dispatch_grid
double scale_factor, double scale_factor,
mapnik::feature_impl const& feature, mapnik::feature_impl const& feature,
attributes const& vars, attributes const& vars,
PixMapType & pixmap) bool snap_to_pixels,
: buf_(render_buffer), RendererContext const& renderer_context)
: buf_(std::get<0>(renderer_context)),
pixf_(buf_), pixf_(buf_),
renb_(pixf_), renb_(pixf_),
svg_renderer_(path, attrs), svg_renderer_(path, attrs),
ras_(ras), ras_(std::get<1>(renderer_context)),
bbox_(bbox), bbox_(bbox),
marker_trans_(marker_trans), marker_trans_(marker_trans),
sym_(sym), sym_(sym),
@ -222,10 +225,9 @@ struct vector_markers_rasterizer_dispatch_grid
scale_factor_(scale_factor), scale_factor_(scale_factor),
feature_(feature), feature_(feature),
vars_(vars), vars_(vars),
pixmap_(pixmap), pixmap_(std::get<2>(renderer_context)),
placed_(false) placed_(false)
{ {
//std::cerr << "vector_markers_rasterizer_dispatch_grid() ctor" << std::endl;
} }
template <typename T> template <typename T>
@ -238,6 +240,9 @@ struct vector_markers_rasterizer_dispatch_grid
double opacity = get<double>(sym_,keys::opacity, feature_, vars_, 1.0); double opacity = get<double>(sym_,keys::opacity, feature_, vars_, 1.0);
bool allow_overlap = get<bool>(sym_, keys::allow_overlap, feature_, vars_, false); bool allow_overlap = get<bool>(sym_, keys::allow_overlap, feature_, vars_, false);
coord2d center = bbox_.center();
agg::trans_affine_translation recenter(-center.x, -center.y);
if (placement_method != MARKER_LINE_PLACEMENT || if (placement_method != MARKER_LINE_PLACEMENT ||
path.type() == geometry_type::types::Point) path.type() == geometry_type::types::Point)
{ {
@ -245,34 +250,24 @@ struct vector_markers_rasterizer_dispatch_grid
double y = 0; double y = 0;
if (path.type() == geometry_type::types::LineString) if (path.type() == geometry_type::types::LineString)
{ {
if (!label::middle_point(path, x, y)) if (!label::middle_point(path, x, y)) return;
{
return;
}
} }
else if (placement_method == MARKER_INTERIOR_PLACEMENT) else if (placement_method == MARKER_INTERIOR_PLACEMENT)
{ {
if (!label::interior_position(path, x, y)) if (!label::interior_position(path, x, y)) return;
{
return;
}
} }
else else
{ {
if (!label::centroid(path, x, y)) if (!label::centroid(path, x, y)) return;
{
return;
}
} }
agg::trans_affine matrix = marker_trans_; agg::trans_affine matrix = recenter * marker_trans_;
matrix.translate(x,y); matrix.translate(x,y);
box2d<double> transformed_bbox = bbox_ * matrix; box2d<double> transformed_bbox = bbox_ * matrix;
if (allow_overlap || if (allow_overlap ||
detector_.has_placement(transformed_bbox)) detector_.has_placement(transformed_bbox))
{ {
svg_renderer_.render_id(ras_, sl_, renb_, feature_.id(), matrix, opacity, bbox_); svg_renderer_.render_id(ras_, sl_, renb_, feature_.id(), matrix, opacity, bbox_);
if (!ignore_placement) if (!ignore_placement)
{ {
detector_.insert(transformed_bbox); detector_.insert(transformed_bbox);
@ -295,7 +290,7 @@ struct vector_markers_rasterizer_dispatch_grid
double x, y, angle; double x, y, angle;
while (placement.get_point(x, y, angle, ignore_placement)) while (placement.get_point(x, y, angle, ignore_placement))
{ {
agg::trans_affine matrix = marker_trans_; agg::trans_affine matrix = recenter * marker_trans_;
matrix.rotate(angle); matrix.rotate(angle);
matrix.translate(x, y); matrix.translate(x, y);
svg_renderer_.render_id(ras_, sl_, renb_, feature_.id(), matrix, opacity, bbox_); svg_renderer_.render_id(ras_, sl_, renb_, feature_.id(), matrix, opacity, bbox_);
@ -312,7 +307,7 @@ private:
pixfmt_type pixf_; pixfmt_type pixf_;
renderer_base renb_; renderer_base renb_;
SvgRenderer svg_renderer_; SvgRenderer svg_renderer_;
Rasterizer & ras_; RasterizerType & ras_;
box2d<double> const& bbox_; box2d<double> const& bbox_;
agg::trans_affine const& marker_trans_; agg::trans_affine const& marker_trans_;
markers_symbolizer const& sym_; markers_symbolizer const& sym_;

View file

@ -58,32 +58,33 @@
namespace mapnik { namespace mapnik {
template <typename SvgRenderer, typename Detector, typename RendererContext>
template <typename BufferType, typename SvgRenderer, typename Rasterizer, typename Detector> struct vector_markers_rasterizer_dispatch : mapnik::noncopyable
struct vector_markers_rasterizer_dispatch
{ {
typedef typename SvgRenderer::renderer_base renderer_base; typedef typename SvgRenderer::renderer_base renderer_base;
typedef typename SvgRenderer::vertex_source_type vertex_source_type; typedef typename SvgRenderer::vertex_source_type vertex_source_type;
typedef typename SvgRenderer::attribute_source_type attribute_source_type; typedef typename SvgRenderer::attribute_source_type attribute_source_type;
typedef typename renderer_base::pixfmt_type pixfmt_type; typedef typename renderer_base::pixfmt_type pixfmt_type;
vector_markers_rasterizer_dispatch(BufferType & render_buffer, typedef typename std::tuple_element<0,RendererContext>::type BufferType;
vertex_source_type &path, typedef typename std::tuple_element<1,RendererContext>::type RasterizerType;
vector_markers_rasterizer_dispatch(vertex_source_type & path,
attribute_source_type const& attrs, attribute_source_type const& attrs,
Rasterizer & ras,
box2d<double> const& bbox, box2d<double> const& bbox,
agg::trans_affine const& marker_trans, agg::trans_affine const& marker_trans,
markers_symbolizer const& sym, markers_symbolizer const& sym,
Detector & detector, Detector & detector,
double scale_factor,
feature_impl & feature, feature_impl & feature,
attributes const& vars, attributes const& vars,
double scale_factor, bool snap_to_pixels,
bool snap_to_pixels) RendererContext const& renderer_context)
: buf_(render_buffer), : buf_(std::get<0>(renderer_context)),
pixf_(buf_), pixf_(buf_),
renb_(pixf_), renb_(pixf_),
svg_renderer_(path, attrs), svg_renderer_(path, attrs),
ras_(ras), ras_(std::get<1>(renderer_context)),
bbox_(bbox), bbox_(bbox),
marker_trans_(marker_trans), marker_trans_(marker_trans),
sym_(sym), sym_(sym),
@ -105,6 +106,9 @@ struct vector_markers_rasterizer_dispatch
bool allow_overlap = get<bool>(sym_, keys::allow_overlap, feature_, vars_, false); bool allow_overlap = get<bool>(sym_, keys::allow_overlap, feature_, vars_, false);
double opacity = get<double>(sym_,keys::opacity, feature_, vars_, 1.0); double opacity = get<double>(sym_,keys::opacity, feature_, vars_, 1.0);
coord2d center = bbox_.center();
agg::trans_affine_translation recenter(-center.x, -center.y);
if (placement_method != MARKER_LINE_PLACEMENT || if (placement_method != MARKER_LINE_PLACEMENT ||
path.type() == mapnik::geometry_type::types::Point) path.type() == mapnik::geometry_type::types::Point)
{ {
@ -112,26 +116,17 @@ struct vector_markers_rasterizer_dispatch
double y = 0; double y = 0;
if (path.type() == mapnik::geometry_type::types::LineString) if (path.type() == mapnik::geometry_type::types::LineString)
{ {
if (!label::middle_point(path, x, y)) if (!label::middle_point(path, x, y)) return;
{
return;
}
} }
else if (placement_method == MARKER_INTERIOR_PLACEMENT) else if (placement_method == MARKER_INTERIOR_PLACEMENT)
{ {
if (!label::interior_position(path, x, y)) if (!label::interior_position(path, x, y)) return;
{
return;
}
} }
else else
{ {
if (!label::centroid(path, x, y)) if (!label::centroid(path, x, y)) return;
{
return;
} }
} agg::trans_affine matrix = recenter * marker_trans_;
agg::trans_affine matrix = marker_trans_;
matrix.translate(x,y); matrix.translate(x,y);
if (snap_to_pixels_) if (snap_to_pixels_)
{ {
@ -165,7 +160,8 @@ struct vector_markers_rasterizer_dispatch
double angle = 0; double angle = 0;
while (placement.get_point(x, y, angle, ignore_placement)) while (placement.get_point(x, y, angle, ignore_placement))
{ {
agg::trans_affine matrix = marker_trans_;
agg::trans_affine matrix = recenter * marker_trans_;
matrix.rotate(angle); matrix.rotate(angle);
matrix.translate(x, y); matrix.translate(x, y);
svg_renderer_.render(ras_, sl_, renb_, matrix, opacity, bbox_); svg_renderer_.render(ras_, sl_, renb_, matrix, opacity, bbox_);
@ -177,7 +173,7 @@ private:
pixfmt_type pixf_; pixfmt_type pixf_;
renderer_base renb_; renderer_base renb_;
SvgRenderer svg_renderer_; SvgRenderer svg_renderer_;
Rasterizer & ras_; RasterizerType & ras_;
box2d<double> const& bbox_; box2d<double> const& bbox_;
agg::trans_affine const& marker_trans_; agg::trans_affine const& marker_trans_;
markers_symbolizer const& sym_; markers_symbolizer const& sym_;
@ -188,9 +184,12 @@ private:
bool snap_to_pixels_; bool snap_to_pixels_;
}; };
template <typename BufferType, typename Rasterizer, typename Detector> template <typename Detector,typename RendererContext>
struct raster_markers_rasterizer_dispatch struct raster_markers_rasterizer_dispatch : mapnik::noncopyable
{ {
typedef typename std::remove_reference<typename std::tuple_element<0,RendererContext>::type>::type BufferType;
typedef typename std::tuple_element<1,RendererContext>::type RasterizerType;
typedef agg::rgba8 color_type; typedef agg::rgba8 color_type;
typedef agg::order_rgba order_type; typedef agg::order_rgba order_type;
typedef agg::pixel32_type pixel_type; typedef agg::pixel32_type pixel_type;
@ -198,20 +197,19 @@ struct raster_markers_rasterizer_dispatch
typedef agg::pixfmt_custom_blend_rgba<blender_type, BufferType> pixfmt_comp_type; typedef agg::pixfmt_custom_blend_rgba<blender_type, BufferType> pixfmt_comp_type;
typedef agg::renderer_base<pixfmt_comp_type> renderer_base; typedef agg::renderer_base<pixfmt_comp_type> renderer_base;
raster_markers_rasterizer_dispatch(BufferType & render_buffer, raster_markers_rasterizer_dispatch(image_data_32 const& src,
Rasterizer & ras,
image_data_32 const& src,
agg::trans_affine const& marker_trans, agg::trans_affine const& marker_trans,
markers_symbolizer const& sym, markers_symbolizer const& sym,
Detector & detector, Detector & detector,
double scale_factor,
feature_impl & feature, feature_impl & feature,
attributes const& vars, attributes const& vars,
double scale_factor, RendererContext const& renderer_context,
bool snap_to_pixels) bool snap_to_pixels = false)
: buf_(render_buffer), : buf_(std::get<0>(renderer_context)),
pixf_(buf_), pixf_(buf_),
renb_(pixf_), renb_(pixf_),
ras_(ras), ras_(std::get<1>(renderer_context)),
src_(src), src_(src),
marker_trans_(marker_trans), marker_trans_(marker_trans),
sym_(sym), sym_(sym),
@ -240,24 +238,15 @@ struct raster_markers_rasterizer_dispatch
double y = 0; double y = 0;
if (path.type() == mapnik::geometry_type::types::LineString) if (path.type() == mapnik::geometry_type::types::LineString)
{ {
if (!label::middle_point(path, x, y)) if (!label::middle_point(path, x, y)) return;
{
return;
}
} }
else if (placement_method == MARKER_INTERIOR_PLACEMENT) else if (placement_method == MARKER_INTERIOR_PLACEMENT)
{ {
if (!label::interior_position(path, x, y)) if (!label::interior_position(path, x, y)) return;
{
return;
}
} }
else else
{ {
if (!label::centroid(path, x, y)) if (!label::centroid(path, x, y)) return;
{
return;
}
} }
agg::trans_affine matrix = marker_trans_; agg::trans_affine matrix = marker_trans_;
matrix.translate(x,y); matrix.translate(x,y);
@ -362,7 +351,7 @@ private:
BufferType & buf_; BufferType & buf_;
pixfmt_comp_type pixf_; pixfmt_comp_type pixf_;
renderer_base renb_; renderer_base renb_;
Rasterizer & ras_; RasterizerType & ras_;
image_data_32 const& src_; image_data_32 const& src_;
agg::trans_affine const& marker_trans_; agg::trans_affine const& marker_trans_;
markers_symbolizer const& sym_; markers_symbolizer const& sym_;
@ -523,6 +512,7 @@ void apply_markers_multi(feature_impl const& feature, attributes const& vars, Co
{ {
marker_multi_policy_enum multi_policy = get<marker_multi_policy_enum>(sym, keys::markers_multipolicy, feature, vars, MARKER_EACH_MULTI); marker_multi_policy_enum multi_policy = get<marker_multi_policy_enum>(sym, keys::markers_multipolicy, feature, vars, MARKER_EACH_MULTI);
marker_placement_enum placement = get<marker_placement_enum>(sym, keys::markers_placement_type, feature, vars, MARKER_POINT_PLACEMENT); marker_placement_enum placement = get<marker_placement_enum>(sym, keys::markers_placement_type, feature, vars, MARKER_POINT_PLACEMENT);
if (placement == MARKER_POINT_PLACEMENT && if (placement == MARKER_POINT_PLACEMENT &&
multi_policy == MARKER_WHOLE_MULTI) multi_policy == MARKER_WHOLE_MULTI)
{ {

View file

@ -29,16 +29,19 @@
namespace mapnik { namespace mapnik {
template <typename F1, typename F2> template <typename T0, typename T1, typename T2>
void render_markers_symbolizer(markers_symbolizer const& sym, void render_markers_symbolizer(markers_symbolizer const& sym,
mapnik::feature_impl & feature, mapnik::feature_impl & feature,
proj_transform const& prj_trans, proj_transform const& prj_trans,
renderer_common const& common, renderer_common const& common,
box2d<double> const& clip_box, box2d<double> const& clip_box,
F1 make_vector_dispatch, T2 const& renderer_context)
F2 make_raster_dispatch)
{ {
using namespace mapnik::svg; using namespace mapnik::svg;
typedef T0 vector_dispatch_type;
typedef T1 raster_dispatch_type;
typedef T2 renderer_context_type;
typedef boost::mpl::vector<clip_poly_tag,transform_tag,smooth_tag> conv_types; typedef boost::mpl::vector<clip_poly_tag,transform_tag,smooth_tag> conv_types;
typedef agg::pod_bvector<path_attributes> svg_attribute_type; typedef agg::pod_bvector<path_attributes> svg_attribute_type;
@ -47,7 +50,7 @@ void render_markers_symbolizer(markers_symbolizer const& sym,
double smooth = get<value_double>(sym, keys::smooth, feature, common.vars_, false); double smooth = get<value_double>(sym, keys::smooth, feature, common.vars_, false);
// https://github.com/mapnik/mapnik/issues/1316 // https://github.com/mapnik/mapnik/issues/1316
bool snap_pixels = !mapnik::marker_cache::instance().is_uri(filename); bool snap_to_pixels = !mapnik::marker_cache::instance().is_uri(filename);
if (!filename.empty()) if (!filename.empty())
{ {
boost::optional<marker_ptr> mark = mapnik::marker_cache::instance().find(filename, true); boost::optional<marker_ptr> mark = mapnik::marker_cache::instance().find(filename, true);
@ -76,13 +79,19 @@ void render_markers_symbolizer(markers_symbolizer const& sym,
auto image_transform = get_optional<transform_type>(sym, keys::image_transform); auto image_transform = get_optional<transform_type>(sym, keys::image_transform);
if (image_transform) evaluate_transform(tr, feature, common.vars_, *image_transform); if (image_transform) evaluate_transform(tr, feature, common.vars_, *image_transform);
box2d<double> bbox = marker_ellipse.bounding_box(); box2d<double> bbox = marker_ellipse.bounding_box();
vector_dispatch_type rasterizer_dispatch(svg_path,
result ? attributes : (*stock_vector_marker)->attributes(),
bbox,
tr,
sym,
*common.detector_,
common.scale_factor_,
feature,
common.vars_,
snap_to_pixels,
renderer_context);
auto rasterizer_dispatch = make_vector_dispatch( vertex_converter<box2d<double>, vector_dispatch_type, markers_symbolizer,
svg_path, result ? attributes : (*stock_vector_marker)->attributes(),
marker_ellipse, bbox, tr, snap_pixels);
typedef decltype(rasterizer_dispatch) dispatch_type;
vertex_converter<box2d<double>, dispatch_type, markers_symbolizer,
CoordTransform, proj_transform, agg::trans_affine, conv_types, feature_impl> CoordTransform, proj_transform, agg::trans_affine, conv_types, feature_impl>
converter(clip_box, rasterizer_dispatch, sym,common.t_,prj_trans,tr,feature,common.vars_,common.scale_factor_); converter(clip_box, rasterizer_dispatch, sym,common.t_,prj_trans,tr,feature,common.vars_,common.scale_factor_);
if (clip && feature.paths().size() > 0) // optional clip (default: true) if (clip && feature.paths().size() > 0) // optional clip (default: true)
@ -109,12 +118,19 @@ void render_markers_symbolizer(markers_symbolizer const& sym,
svg_path_adapter svg_path(stl_storage); svg_path_adapter svg_path(stl_storage);
svg_attribute_type attributes; svg_attribute_type attributes;
bool result = push_explicit_style( (*stock_vector_marker)->attributes(), attributes, sym, feature, common.vars_); bool result = push_explicit_style( (*stock_vector_marker)->attributes(), attributes, sym, feature, common.vars_);
auto rasterizer_dispatch = make_vector_dispatch( vector_dispatch_type rasterizer_dispatch(svg_path,
svg_path, result ? attributes : (*stock_vector_marker)->attributes(), result ? attributes : (*stock_vector_marker)->attributes(),
**stock_vector_marker, bbox, tr, snap_pixels); bbox,
typedef decltype(rasterizer_dispatch) dispatch_type; tr,
sym,
*common.detector_,
common.scale_factor_,
feature,
common.vars_,
snap_to_pixels,
renderer_context);
vertex_converter<box2d<double>, dispatch_type, markers_symbolizer, vertex_converter<box2d<double>, vector_dispatch_type, markers_symbolizer,
CoordTransform, proj_transform, agg::trans_affine, conv_types, feature_impl> CoordTransform, proj_transform, agg::trans_affine, conv_types, feature_impl>
converter(clip_box, rasterizer_dispatch, sym,common.t_,prj_trans,tr,feature,common.vars_,common.scale_factor_); converter(clip_box, rasterizer_dispatch, sym,common.t_,prj_trans,tr,feature,common.vars_,common.scale_factor_);
if (clip && feature.paths().size() > 0) // optional clip (default: true) if (clip && feature.paths().size() > 0) // optional clip (default: true)
@ -139,11 +155,20 @@ void render_markers_symbolizer(markers_symbolizer const& sym,
if (image_transform) evaluate_transform(tr, feature, common.vars_, *image_transform); if (image_transform) evaluate_transform(tr, feature, common.vars_, *image_transform);
box2d<double> const& bbox = (*mark)->bounding_box(); box2d<double> const& bbox = (*mark)->bounding_box();
boost::optional<mapnik::image_ptr> marker = (*mark)->get_bitmap_data(); boost::optional<mapnik::image_ptr> marker = (*mark)->get_bitmap_data();
// - clamp sizes to > 4 pixels of interactivity
coord2d center = bbox.center();
agg::trans_affine_translation recenter(-center.x, -center.y);
agg::trans_affine marker_trans = recenter * tr;
raster_dispatch_type rasterizer_dispatch(**marker,
marker_trans,
sym,
*common.detector_,
common.scale_factor_,
feature,
common.vars_,
renderer_context);
auto rasterizer_dispatch = make_raster_dispatch(**marker, tr, bbox); vertex_converter<box2d<double>, raster_dispatch_type, markers_symbolizer,
typedef decltype(rasterizer_dispatch) dispatch_type;
vertex_converter<box2d<double>, dispatch_type, markers_symbolizer,
CoordTransform, proj_transform, agg::trans_affine, conv_types, feature_impl> CoordTransform, proj_transform, agg::trans_affine, conv_types, feature_impl>
converter(clip_box, rasterizer_dispatch, sym,common.t_,prj_trans,tr,feature,common.vars_,common.scale_factor_); converter(clip_box, rasterizer_dispatch, sym,common.t_,prj_trans,tr,feature,common.vars_,common.scale_factor_);

View file

@ -25,7 +25,7 @@
// mapnik // mapnik
#include <mapnik/noncopyable.hpp> #include <mapnik/noncopyable.hpp>
#include <mapnik/box2d.hpp>
// agg // agg
#include "agg_math.h" #include "agg_math.h"
#include "agg_array.h" #include "agg_array.h"
@ -937,6 +937,10 @@ public:
return vertices_[idx].cmd; return vertices_[idx].cmd;
} }
box2d<double> const& bounding_box() const
{
vertices_.bounding_box();
}
private: private:
Container & vertices_; Container & vertices_;
}; };

View file

@ -116,10 +116,6 @@ public:
curved_stroked_(curved_), curved_stroked_(curved_),
attributes_(attributes) {} attributes_(attributes) {}
svg_renderer_agg(svg_renderer_agg &&r)
: source_(r.source_), curved_(source_), curved_stroked_(curved_),
attributes_(r.attributes_) {}
template <typename Rasterizer, typename Scanline, typename Renderer> template <typename Rasterizer, typename Scanline, typename Renderer>
void render_gradient(Rasterizer& ras, void render_gradient(Rasterizer& ras,
Scanline& sl, Scanline& sl,
@ -426,6 +422,8 @@ public:
} }
#endif #endif
inline VertexSource & source() const { return source_;}
inline AttributeSource const& attributes() const { return attributes_;}
private: private:
VertexSource & source_; VertexSource & source_;

View file

@ -293,7 +293,8 @@ struct dispatcher
dispatcher(args_type const& args) dispatcher(args_type const& args)
: args_(args) : args_(args)
{ {
std::memset(&vec_[0], 0, sizeof(unsigned)*vec_.size()); //std::memset(&vec_[0], 0, sizeof(unsigned)*vec_.size());
std::fill(vec_.begin(), vec_.end(), 0);
} }
template <typename Iter, typename End, typename Geometry> template <typename Iter, typename End, typename Geometry>

View file

@ -76,11 +76,8 @@ void agg_renderer<T0,T1>::process(markers_symbolizer const& sym,
svg_attribute_type, svg_attribute_type,
renderer_type, renderer_type,
pixfmt_comp_type > svg_renderer_type; pixfmt_comp_type > svg_renderer_type;
typedef vector_markers_rasterizer_dispatch<buf_type,
svg_renderer_type, ras_ptr->reset();
rasterizer,
detector_type > vector_dispatch_type;
typedef raster_markers_rasterizer_dispatch<buf_type,rasterizer, detector_type> raster_dispatch_type;
double gamma = get<value_double>(sym, keys::gamma, feature, common_.vars_, 1.0); double gamma = get<value_double>(sym, keys::gamma, feature, common_.vars_, 1.0);
gamma_method_enum gamma_method = get<gamma_method_enum>(sym, keys::gamma_method, feature, common_.vars_, GAMMA_POWER); gamma_method_enum gamma_method = get<gamma_method_enum>(sym, keys::gamma_method, feature, common_.vars_, GAMMA_POWER);
@ -92,44 +89,15 @@ void agg_renderer<T0,T1>::process(markers_symbolizer const& sym,
} }
buf_type render_buffer(current_buffer_->raw_data(), current_buffer_->width(), current_buffer_->height(), current_buffer_->width() * 4); buf_type render_buffer(current_buffer_->raw_data(), current_buffer_->width(), current_buffer_->height(), current_buffer_->width() * 4);
ras_ptr->reset();
box2d<double> clip_box = clipping_extent(); box2d<double> clip_box = clipping_extent();
render_markers_symbolizer( auto renderer_context = std::tie(render_buffer,*ras_ptr,pixmap_);
sym, feature, prj_trans, common_, clip_box, typedef decltype(renderer_context) context_type;
[&](svg_path_adapter &path, svg_attribute_type const &attr, svg_storage_type &, typedef vector_markers_rasterizer_dispatch<svg_renderer_type, detector_type, context_type> vector_dispatch_type;
box2d<double> const &bbox, agg::trans_affine const &tr, typedef raster_markers_rasterizer_dispatch<detector_type, context_type> raster_dispatch_type;
bool snap_pixels) -> vector_dispatch_type {
coord2d center = bbox.center(); render_markers_symbolizer<vector_dispatch_type, raster_dispatch_type>(
agg::trans_affine_translation recenter(-center.x, -center.y); sym, feature, prj_trans, common_, clip_box, renderer_context);
agg::trans_affine marker_trans = recenter * tr;
return vector_dispatch_type(render_buffer,
path, attr,
*ras_ptr,
bbox,
marker_trans,
sym,
*common_.detector_,
feature, common_.vars_,
common_.scale_factor_,
snap_pixels);
},
[&](image_data_32 const &marker, agg::trans_affine const &tr,
box2d<double> const &bbox) -> raster_dispatch_type {
coord2d center = bbox.center();
agg::trans_affine_translation recenter(-center.x, -center.y);
agg::trans_affine marker_trans = recenter * tr;
return raster_dispatch_type(render_buffer,
*ras_ptr,
marker,
marker_trans,
sym,
*common_.detector_,
feature, common_.vars_,
common_.scale_factor_,
true /*snap rasters no matter what*/);
});
} }
template void agg_renderer<image_32>::process(markers_symbolizer const&, template void agg_renderer<image_32>::process(markers_symbolizer const&,

View file

@ -419,15 +419,13 @@ void cairo_renderer_base::render_box(box2d<double> const& b)
context_.stroke(); context_.stroke();
} }
void render_vector_marker(cairo_context & context, pixel_position const& pos, mapnik::svg_storage_type & vmarker, void render_vector_marker(cairo_context & context, pixel_position const& pos,
svg::svg_path_adapter & svg_path, box2d<double> const& bbox,
agg::pod_bvector<svg::path_attributes> const & attributes, agg::pod_bvector<svg::path_attributes> const & attributes,
agg::trans_affine const& tr, double opacity, bool recenter) agg::trans_affine const& tr, double opacity, bool recenter)
{ {
using namespace mapnik::svg; using namespace mapnik::svg;
box2d<double> bbox = vmarker.bounding_box();
agg::trans_affine mtx = tr; agg::trans_affine mtx = tr;
if (recenter) if (recenter)
{ {
coord<double,2> c = bbox.center(); coord<double,2> c = bbox.center();
@ -459,9 +457,6 @@ void render_vector_marker(cairo_context & context, pixel_position const& pos, ma
context.transform(matrix); context.transform(matrix);
} }
vertex_stl_adapter<svg_path_storage> stl_storage(vmarker.source());
svg_path_adapter svg_path(stl_storage);
if (attr.fill_flag || attr.fill_gradient.get_gradient_type() != NO_GRADIENT) if (attr.fill_flag || attr.fill_gradient.get_gradient_type() != NO_GRADIENT)
{ {
context.add_agg_path(svg_path,attr.index); context.add_agg_path(svg_path,attr.index);
@ -533,8 +528,11 @@ void cairo_renderer_base::render_marker(pixel_position const& pos,
{ {
agg::trans_affine marker_tr = tr; agg::trans_affine marker_tr = tr;
marker_tr *=agg::trans_affine_scaling(common_.scale_factor_); marker_tr *=agg::trans_affine_scaling(common_.scale_factor_);
box2d<double> bbox = vmarker->bounding_box();
agg::pod_bvector<svg::path_attributes> const & attributes = vmarker->attributes(); agg::pod_bvector<svg::path_attributes> const & attributes = vmarker->attributes();
render_vector_marker(context_, pos, *vmarker, attributes, marker_tr, opacity, recenter); svg::vertex_stl_adapter<svg::svg_path_storage> stl_storage(vmarker->source());
svg::svg_path_adapter svg_path(stl_storage);
render_vector_marker(context_, pos, svg_path, bbox, attributes, marker_tr, opacity, recenter);
} }
} }
else if (marker.is_bitmap()) else if (marker.is_bitmap())
@ -773,29 +771,31 @@ void cairo_renderer_base::process(raster_symbolizer const& sym,
namespace detail { namespace detail {
template <typename Context, typename SvgPath, typename Attributes, typename Detector> template <typename RendererContext, typename SvgPath, typename Attributes, typename Detector>
struct markers_dispatch struct markers_dispatch : mapnik::noncopyable
{ {
markers_dispatch(Context & ctx, markers_dispatch(SvgPath & marker,
SvgPath & marker,
Attributes const& attributes, Attributes const& attributes,
Detector & detector,
markers_symbolizer const& sym,
box2d<double> const& bbox, box2d<double> const& bbox,
agg::trans_affine const& marker_trans, agg::trans_affine const& marker_trans,
markers_symbolizer const& sym,
Detector & detector,
double scale_factor,
feature_impl const& feature, feature_impl const& feature,
mapnik::attributes const& vars, mapnik::attributes const& vars,
double scale_factor) bool snap_to_pixels,
:ctx_(ctx), RendererContext const& renderer_context)
marker_(marker), :marker_(marker),
attributes_(attributes), attributes_(attributes),
detector_(detector),
sym_(sym),
bbox_(bbox), bbox_(bbox),
marker_trans_(marker_trans), marker_trans_(marker_trans),
sym_(sym),
detector_(detector),
scale_factor_(scale_factor),
feature_(feature), feature_(feature),
vars_(vars), vars_(vars),
scale_factor_(scale_factor) {} ctx_(std::get<0>(renderer_context))
{}
template <typename T> template <typename T>
@ -815,18 +815,15 @@ struct markers_dispatch
double y = 0; double y = 0;
if (path.type() == geometry_type::types::LineString) if (path.type() == geometry_type::types::LineString)
{ {
if (!label::middle_point(path, x, y)) if (!label::middle_point(path, x, y)) return;
return;
} }
else if (placement_method == MARKER_INTERIOR_PLACEMENT) else if (placement_method == MARKER_INTERIOR_PLACEMENT)
{ {
if (!label::interior_position(path, x, y)) if (!label::interior_position(path, x, y)) return;
return;
} }
else else
{ {
if (!label::centroid(path, x, y)) if (!label::centroid(path, x, y)) return;
return;
} }
coord2d center = bbox_.center(); coord2d center = bbox_.center();
agg::trans_affine matrix = agg::trans_affine_translation(-center.x, -center.y); agg::trans_affine matrix = agg::trans_affine_translation(-center.x, -center.y);
@ -838,7 +835,7 @@ struct markers_dispatch
if (allow_overlap || if (allow_overlap ||
detector_.has_placement(transformed_bbox)) detector_.has_placement(transformed_bbox))
{ {
render_vector_marker(ctx_, pixel_position(x,y), marker_, attributes_, marker_trans_, opacity, true); render_vector_marker(ctx_, pixel_position(x,y), marker_, bbox_, attributes_, marker_trans_, opacity, true);
if (!ignore_placement) if (!ignore_placement)
{ {
@ -857,46 +854,44 @@ struct markers_dispatch
{ {
agg::trans_affine matrix = marker_trans_; agg::trans_affine matrix = marker_trans_;
matrix.rotate(angle); matrix.rotate(angle);
render_vector_marker(ctx_, pixel_position(x,y),marker_, attributes_, matrix, opacity, true); render_vector_marker(ctx_, pixel_position(x,y), marker_, bbox_, attributes_, matrix, opacity, true);
} }
} }
} }
Context & ctx_;
SvgPath & marker_; SvgPath & marker_;
Attributes const& attributes_; Attributes const& attributes_;
Detector & detector_;
markers_symbolizer const& sym_;
box2d<double> const& bbox_; box2d<double> const& bbox_;
agg::trans_affine const& marker_trans_; agg::trans_affine const& marker_trans_;
markers_symbolizer const& sym_;
Detector & detector_;
double scale_factor_;
feature_impl const& feature_; feature_impl const& feature_;
attributes const& vars_; attributes const& vars_;
double scale_factor_; cairo_context & ctx_;
}; };
template <typename Context, typename ImageMarker, typename Detector> template <typename RendererContext, typename ImageMarker, typename Detector>
struct markers_dispatch_2 struct raster_markers_dispatch : mapnik::noncopyable
{ {
markers_dispatch_2(Context & ctx, raster_markers_dispatch(ImageMarker & marker,
ImageMarker & marker,
Detector & detector,
markers_symbolizer const& sym,
box2d<double> const& bbox,
agg::trans_affine const& marker_trans, agg::trans_affine const& marker_trans,
markers_symbolizer const& sym,
Detector & detector,
double scale_factor,
feature_impl const& feature, feature_impl const& feature,
mapnik::attributes const& vars, mapnik::attributes const& vars,
double scale_factor) RendererContext const& renderer_context)
:ctx_(ctx), :marker_(marker),
marker_(marker),
detector_(detector), detector_(detector),
sym_(sym), sym_(sym),
bbox_(bbox), bbox_(std::get<1>(renderer_context)),
marker_trans_(marker_trans), marker_trans_(marker_trans),
scale_factor_(scale_factor),
feature_(feature), feature_(feature),
vars_(vars), vars_(vars),
scale_factor_(scale_factor) {} ctx_(std::get<0>(renderer_context)) {}
template <typename T> template <typename T>
void add_path(T & path) void add_path(T & path)
@ -964,15 +959,15 @@ struct markers_dispatch_2
} }
} }
Context & ctx_;
ImageMarker & marker_; ImageMarker & marker_;
Detector & detector_; Detector & detector_;
markers_symbolizer const& sym_; markers_symbolizer const& sym_;
box2d<double> const& bbox_; box2d<double> const& bbox_;
agg::trans_affine const& marker_trans_; agg::trans_affine const& marker_trans_;
double scale_factor_;
feature_impl const& feature_; feature_impl const& feature_;
attributes const& vars_; attributes const& vars_;
double scale_factor_; cairo_context & ctx_;
}; };
} }
@ -981,29 +976,24 @@ void cairo_renderer_base::process(markers_symbolizer const& sym,
proj_transform const& prj_trans) proj_transform const& prj_trans)
{ {
typedef agg::pod_bvector<svg::path_attributes> svg_attribute_type; typedef agg::pod_bvector<svg::path_attributes> svg_attribute_type;
typedef detail::markers_dispatch_2<cairo_context, mapnik::image_data_32,
label_collision_detector4> raster_dispatch_type;
typedef detail::markers_dispatch<cairo_context, mapnik::svg_storage_type, svg_attribute_type,
label_collision_detector4> vector_dispatch_type;
cairo_save_restore guard(context_); cairo_save_restore guard(context_);
composite_mode_e comp_op = get<composite_mode_e>(sym, keys::comp_op, feature, common_.vars_, src_over); composite_mode_e comp_op = get<composite_mode_e>(sym, keys::comp_op, feature, common_.vars_, src_over);
context_.set_operator(comp_op); context_.set_operator(comp_op);
box2d<double> clip_box = common_.query_extent_; box2d<double> clip_box = common_.query_extent_;
render_markers_symbolizer( auto renderer_context = std::tie(context_, clip_box);
typedef decltype(renderer_context) RendererContextType;
typedef detail::markers_dispatch<RendererContextType, svg::path_adapter<svg::vertex_stl_adapter<svg::svg_path_storage> > , svg_attribute_type,
label_collision_detector4> vector_dispatch_type;
typedef detail::raster_markers_dispatch<RendererContextType, mapnik::image_data_32,
label_collision_detector4> raster_dispatch_type;
render_markers_symbolizer<vector_dispatch_type, raster_dispatch_type>(
sym, feature, prj_trans, common_, clip_box, sym, feature, prj_trans, common_, clip_box,
[&](svg::svg_path_adapter &, svg_attribute_type const &attr, svg_storage_type &marker, renderer_context);
box2d<double> const &bbox, agg::trans_affine const &marker_trans,
bool) -> vector_dispatch_type {
return vector_dispatch_type(context_, marker, attr, *common_.detector_, sym, bbox,
marker_trans, feature, common_.vars_, common_.scale_factor_);
},
[&](image_data_32 &marker, agg::trans_affine const &marker_trans,
box2d<double> const &bbox) -> raster_dispatch_type {
return raster_dispatch_type(context_, marker, *common_.detector_, sym, bbox,
marker_trans, feature, common_.vars_, common_.scale_factor_);
});
} }
void cairo_renderer_base::process(text_symbolizer const& sym, void cairo_renderer_base::process(text_symbolizer const& sym,

View file

@ -74,7 +74,7 @@ porting notes -->
// stl // stl
#include <algorithm> #include <algorithm>
#include <tuple>
namespace mapnik { namespace mapnik {
@ -94,63 +94,25 @@ void grid_renderer<T>::process(markers_symbolizer const& sym,
svg_attribute_type, svg_attribute_type,
renderer_type, renderer_type,
pixfmt_type > svg_renderer_type; pixfmt_type > svg_renderer_type;
typedef vector_markers_rasterizer_dispatch_grid<buf_type,
svg_renderer_type,
grid_rasterizer,
detector_type,
mapnik::grid > vector_dispatch_type;
typedef raster_markers_rasterizer_dispatch_grid<buf_type,
grid_rasterizer,
pixfmt_type,
grid_renderer_base_type,
renderer_type,
detector_type,
mapnik::grid > raster_dispatch_type;
buf_type render_buf(pixmap_.raw_data(), common_.width_, common_.height_, common_.width_); buf_type render_buf(pixmap_.raw_data(), common_.width_, common_.height_, common_.width_);
ras_ptr->reset(); ras_ptr->reset();
box2d<double> clip_box = common_.query_extent_; box2d<double> clip_box = common_.query_extent_;
render_markers_symbolizer( auto renderer_context = std::tie(render_buf,*ras_ptr,pixmap_);
sym, feature, prj_trans, common_, clip_box, typedef decltype(renderer_context) context_type;
[&](svg_path_adapter & path, svg_attribute_type const& attr, svg_storage_type &,
box2d<double> const& bbox, agg::trans_affine const& tr, typedef vector_markers_rasterizer_dispatch_grid<svg_renderer_type,
bool) -> vector_dispatch_type detector_type,
{ context_type> vector_dispatch_type;
// TODO - clamping to >= 4 pixels
coord2d center = bbox.center(); typedef raster_markers_rasterizer_dispatch_grid<grid_renderer_base_type,
agg::trans_affine_translation recenter(-center.x, -center.y); renderer_type,
agg::trans_affine marker_trans = recenter * tr; detector_type,
return vector_dispatch_type(render_buf, context_type> raster_dispatch_type;
path, attr,
*ras_ptr, render_markers_symbolizer<vector_dispatch_type, raster_dispatch_type>(
bbox, sym, feature, prj_trans, common_, clip_box,renderer_context);
marker_trans,
sym,
*common_.detector_,
common_.scale_factor_,
feature,
common_.vars_,
pixmap_);
},
[&](image_data_32 const& marker, agg::trans_affine const& tr,
box2d<double> const& bbox) -> raster_dispatch_type
{
// - clamp sizes to > 4 pixels of interactivity
coord2d center = bbox.center();
agg::trans_affine_translation recenter(-center.x, -center.y);
agg::trans_affine marker_trans = recenter * tr;
return raster_dispatch_type(render_buf,
*ras_ptr,
marker,
marker_trans,
sym,
*common_.detector_,
common_.scale_factor_,
feature,
common_.vars_,
pixmap_);
});
} }
template void grid_renderer<grid>::process(markers_symbolizer const&, template void grid_renderer<grid>::process(markers_symbolizer const&,