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:
- gcc
# disabled to due https://github.com/mapnik/mapnik/issues/2235
#- clang
- clang
addons:
postgresql: "9.3"
@ -47,4 +46,5 @@ notifications:
irc:
channels:
- "irc.freenode.org#mapnik"
use_notice: true
use_notice: true

View file

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

View file

@ -58,32 +58,33 @@
namespace mapnik {
template <typename BufferType, typename SvgRenderer, typename Rasterizer, typename Detector>
struct vector_markers_rasterizer_dispatch
template <typename SvgRenderer, typename Detector, typename RendererContext>
struct vector_markers_rasterizer_dispatch : mapnik::noncopyable
{
typedef typename SvgRenderer::renderer_base renderer_base;
typedef typename SvgRenderer::vertex_source_type vertex_source_type;
typedef typename SvgRenderer::attribute_source_type attribute_source_type;
typedef typename renderer_base::pixfmt_type pixfmt_type;
vector_markers_rasterizer_dispatch(BufferType & render_buffer,
vertex_source_type &path,
attribute_source_type const &attrs,
Rasterizer & ras,
typedef typename std::tuple_element<0,RendererContext>::type BufferType;
typedef typename std::tuple_element<1,RendererContext>::type RasterizerType;
vector_markers_rasterizer_dispatch(vertex_source_type & path,
attribute_source_type const& attrs,
box2d<double> const& bbox,
agg::trans_affine const& marker_trans,
markers_symbolizer const& sym,
Detector & detector,
double scale_factor,
feature_impl & feature,
attributes const& vars,
double scale_factor,
bool snap_to_pixels)
: buf_(render_buffer),
bool snap_to_pixels,
RendererContext const& renderer_context)
: buf_(std::get<0>(renderer_context)),
pixf_(buf_),
renb_(pixf_),
svg_renderer_(path, attrs),
ras_(ras),
ras_(std::get<1>(renderer_context)),
bbox_(bbox),
marker_trans_(marker_trans),
sym_(sym),
@ -105,6 +106,9 @@ struct vector_markers_rasterizer_dispatch
bool allow_overlap = get<bool>(sym_, keys::allow_overlap, feature_, vars_, false);
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 ||
path.type() == mapnik::geometry_type::types::Point)
{
@ -112,26 +116,17 @@ struct vector_markers_rasterizer_dispatch
double y = 0;
if (path.type() == mapnik::geometry_type::types::LineString)
{
if (!label::middle_point(path, x, y))
{
return;
}
if (!label::middle_point(path, x, y)) return;
}
else if (placement_method == MARKER_INTERIOR_PLACEMENT)
{
if (!label::interior_position(path, x, y))
{
return;
}
if (!label::interior_position(path, x, y)) return;
}
else
{
if (!label::centroid(path, x, y))
{
return;
}
if (!label::centroid(path, x, y)) return;
}
agg::trans_affine matrix = marker_trans_;
agg::trans_affine matrix = recenter * marker_trans_;
matrix.translate(x,y);
if (snap_to_pixels_)
{
@ -165,7 +160,8 @@ struct vector_markers_rasterizer_dispatch
double angle = 0;
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.translate(x, y);
svg_renderer_.render(ras_, sl_, renb_, matrix, opacity, bbox_);
@ -177,7 +173,7 @@ private:
pixfmt_type pixf_;
renderer_base renb_;
SvgRenderer svg_renderer_;
Rasterizer & ras_;
RasterizerType & ras_;
box2d<double> const& bbox_;
agg::trans_affine const& marker_trans_;
markers_symbolizer const& sym_;
@ -188,9 +184,12 @@ private:
bool snap_to_pixels_;
};
template <typename BufferType, typename Rasterizer, typename Detector>
struct raster_markers_rasterizer_dispatch
template <typename Detector,typename RendererContext>
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::order_rgba order_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::renderer_base<pixfmt_comp_type> renderer_base;
raster_markers_rasterizer_dispatch(BufferType & render_buffer,
Rasterizer & ras,
image_data_32 const& src,
raster_markers_rasterizer_dispatch(image_data_32 const& src,
agg::trans_affine const& marker_trans,
markers_symbolizer const& sym,
Detector & detector,
double scale_factor,
feature_impl & feature,
attributes const& vars,
double scale_factor,
bool snap_to_pixels)
: buf_(render_buffer),
RendererContext const& renderer_context,
bool snap_to_pixels = false)
: buf_(std::get<0>(renderer_context)),
pixf_(buf_),
renb_(pixf_),
ras_(ras),
ras_(std::get<1>(renderer_context)),
src_(src),
marker_trans_(marker_trans),
sym_(sym),
@ -240,24 +238,15 @@ struct raster_markers_rasterizer_dispatch
double y = 0;
if (path.type() == mapnik::geometry_type::types::LineString)
{
if (!label::middle_point(path, x, y))
{
return;
}
if (!label::middle_point(path, x, y)) return;
}
else if (placement_method == MARKER_INTERIOR_PLACEMENT)
{
if (!label::interior_position(path, x, y))
{
return;
}
if (!label::interior_position(path, x, y)) return;
}
else
{
if (!label::centroid(path, x, y))
{
return;
}
if (!label::centroid(path, x, y)) return;
}
agg::trans_affine matrix = marker_trans_;
matrix.translate(x,y);
@ -362,7 +351,7 @@ private:
BufferType & buf_;
pixfmt_comp_type pixf_;
renderer_base renb_;
Rasterizer & ras_;
RasterizerType & ras_;
image_data_32 const& src_;
agg::trans_affine const& marker_trans_;
markers_symbolizer const& sym_;
@ -512,7 +501,7 @@ void setup_transform_scaling(agg::trans_affine & tr,
// Apply markers to a feature with multiple geometries
template <typename Converter>
void apply_markers_multi(feature_impl const& feature, attributes const& vars, Converter& converter, markers_symbolizer const& sym)
void apply_markers_multi(feature_impl const& feature, attributes const& vars, Converter & converter, markers_symbolizer const& sym)
{
std::size_t geom_count = feature.paths().size();
if (geom_count == 1)
@ -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_placement_enum placement = get<marker_placement_enum>(sym, keys::markers_placement_type, feature, vars, MARKER_POINT_PLACEMENT);
if (placement == MARKER_POINT_PLACEMENT &&
multi_policy == MARKER_WHOLE_MULTI)
{

View file

@ -29,16 +29,19 @@
namespace mapnik {
template <typename F1, typename F2>
template <typename T0, typename T1, typename T2>
void render_markers_symbolizer(markers_symbolizer const& sym,
mapnik::feature_impl & feature,
proj_transform const& prj_trans,
renderer_common const& common,
box2d<double> const& clip_box,
F1 make_vector_dispatch,
F2 make_raster_dispatch)
T2 const& renderer_context)
{
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 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);
// 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())
{
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);
if (image_transform) evaluate_transform(tr, feature, common.vars_, *image_transform);
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(
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,
vertex_converter<box2d<double>, vector_dispatch_type, markers_symbolizer,
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_);
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_attribute_type attributes;
bool result = push_explicit_style( (*stock_vector_marker)->attributes(), attributes, sym, feature, common.vars_);
auto rasterizer_dispatch = make_vector_dispatch(
svg_path, result ? attributes : (*stock_vector_marker)->attributes(),
**stock_vector_marker, bbox, tr, snap_pixels);
typedef decltype(rasterizer_dispatch) dispatch_type;
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);
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>
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)
@ -139,11 +155,20 @@ void render_markers_symbolizer(markers_symbolizer const& sym,
if (image_transform) evaluate_transform(tr, feature, common.vars_, *image_transform);
box2d<double> const& bbox = (*mark)->bounding_box();
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);
typedef decltype(rasterizer_dispatch) dispatch_type;
vertex_converter<box2d<double>, dispatch_type, markers_symbolizer,
vertex_converter<box2d<double>, raster_dispatch_type, markers_symbolizer,
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_);

View file

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

View file

@ -116,10 +116,6 @@ public:
curved_stroked_(curved_),
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>
void render_gradient(Rasterizer& ras,
Scanline& sl,
@ -426,11 +422,13 @@ public:
}
#endif
inline VertexSource & source() const { return source_;}
inline AttributeSource const& attributes() const { return attributes_;}
private:
VertexSource & source_;
curved_type curved_;
curved_stroked_type curved_stroked_;
VertexSource & source_;
curved_type curved_;
curved_stroked_type curved_stroked_;
AttributeSource const& attributes_;
};

View file

@ -293,7 +293,8 @@ struct dispatcher
dispatcher(args_type const& 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>

View file

@ -76,11 +76,8 @@ void agg_renderer<T0,T1>::process(markers_symbolizer const& sym,
svg_attribute_type,
renderer_type,
pixfmt_comp_type > svg_renderer_type;
typedef vector_markers_rasterizer_dispatch<buf_type,
svg_renderer_type,
rasterizer,
detector_type > vector_dispatch_type;
typedef raster_markers_rasterizer_dispatch<buf_type,rasterizer, detector_type> raster_dispatch_type;
ras_ptr->reset();
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);
@ -90,46 +87,17 @@ void agg_renderer<T0,T1>::process(markers_symbolizer const& sym,
gamma_method_ = gamma_method;
gamma_ = gamma;
}
buf_type render_buffer(current_buffer_->raw_data(), current_buffer_->width(), current_buffer_->height(), current_buffer_->width() * 4);
ras_ptr->reset();
buf_type render_buffer(current_buffer_->raw_data(), current_buffer_->width(), current_buffer_->height(), current_buffer_->width() * 4);
box2d<double> clip_box = clipping_extent();
render_markers_symbolizer(
sym, feature, prj_trans, common_, clip_box,
[&](svg_path_adapter &path, svg_attribute_type const &attr, svg_storage_type &,
box2d<double> const &bbox, agg::trans_affine const &tr,
bool snap_pixels) -> vector_dispatch_type {
coord2d center = bbox.center();
agg::trans_affine_translation recenter(-center.x, -center.y);
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*/);
});
auto renderer_context = std::tie(render_buffer,*ras_ptr,pixmap_);
typedef decltype(renderer_context) context_type;
typedef vector_markers_rasterizer_dispatch<svg_renderer_type, detector_type, context_type> vector_dispatch_type;
typedef raster_markers_rasterizer_dispatch<detector_type, context_type> raster_dispatch_type;
render_markers_symbolizer<vector_dispatch_type, raster_dispatch_type>(
sym, feature, prj_trans, common_, clip_box, renderer_context);
}
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();
}
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::trans_affine const& tr, double opacity, bool recenter)
{
using namespace mapnik::svg;
box2d<double> bbox = vmarker.bounding_box();
agg::trans_affine mtx = tr;
if (recenter)
{
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);
}
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)
{
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;
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();
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())
@ -563,7 +561,7 @@ void cairo_renderer_base::process(point_symbolizer const& sym,
render_point_symbolizer(
sym, feature, prj_trans, common_,
[&](pixel_position const& pos, marker const& marker,
[&](pixel_position const& pos, marker const& marker,
agg::trans_affine const& tr, double opacity) {
render_marker(pos, marker, tr, opacity);
});
@ -773,29 +771,31 @@ void cairo_renderer_base::process(raster_symbolizer const& sym,
namespace detail {
template <typename Context, typename SvgPath, typename Attributes, typename Detector>
struct markers_dispatch
template <typename RendererContext, typename SvgPath, typename Attributes, typename Detector>
struct markers_dispatch : mapnik::noncopyable
{
markers_dispatch(Context & ctx,
SvgPath & marker,
markers_dispatch(SvgPath & marker,
Attributes const& attributes,
Detector & detector,
markers_symbolizer const& sym,
box2d<double> const& bbox,
agg::trans_affine const& marker_trans,
markers_symbolizer const& sym,
Detector & detector,
double scale_factor,
feature_impl const& feature,
mapnik::attributes const& vars,
double scale_factor)
:ctx_(ctx),
marker_(marker),
attributes_(attributes),
detector_(detector),
sym_(sym),
bbox_(bbox),
marker_trans_(marker_trans),
feature_(feature),
vars_(vars),
scale_factor_(scale_factor) {}
bool snap_to_pixels,
RendererContext const& renderer_context)
:marker_(marker),
attributes_(attributes),
bbox_(bbox),
marker_trans_(marker_trans),
sym_(sym),
detector_(detector),
scale_factor_(scale_factor),
feature_(feature),
vars_(vars),
ctx_(std::get<0>(renderer_context))
{}
template <typename T>
@ -815,18 +815,15 @@ struct markers_dispatch
double y = 0;
if (path.type() == geometry_type::types::LineString)
{
if (!label::middle_point(path, x, y))
return;
if (!label::middle_point(path, x, y)) return;
}
else if (placement_method == MARKER_INTERIOR_PLACEMENT)
{
if (!label::interior_position(path, x, y))
return;
if (!label::interior_position(path, x, y)) return;
}
else
{
if (!label::centroid(path, x, y))
return;
if (!label::centroid(path, x, y)) return;
}
coord2d center = bbox_.center();
agg::trans_affine matrix = agg::trans_affine_translation(-center.x, -center.y);
@ -838,7 +835,7 @@ struct markers_dispatch
if (allow_overlap ||
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)
{
@ -857,46 +854,44 @@ struct markers_dispatch
{
agg::trans_affine matrix = marker_trans_;
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_;
Attributes const& attributes_;
Detector & detector_;
markers_symbolizer const& sym_;
box2d<double> const& bbox_;
agg::trans_affine const& marker_trans_;
markers_symbolizer const& sym_;
Detector & detector_;
double scale_factor_;
feature_impl const& feature_;
attributes const& vars_;
double scale_factor_;
cairo_context & ctx_;
};
template <typename Context, typename ImageMarker, typename Detector>
struct markers_dispatch_2
template <typename RendererContext, typename ImageMarker, typename Detector>
struct raster_markers_dispatch : mapnik::noncopyable
{
markers_dispatch_2(Context & ctx,
ImageMarker & marker,
Detector & detector,
markers_symbolizer const& sym,
box2d<double> const& bbox,
raster_markers_dispatch(ImageMarker & marker,
agg::trans_affine const& marker_trans,
markers_symbolizer const& sym,
Detector & detector,
double scale_factor,
feature_impl const& feature,
mapnik::attributes const& vars,
double scale_factor)
:ctx_(ctx),
marker_(marker),
detector_(detector),
sym_(sym),
bbox_(bbox),
marker_trans_(marker_trans),
feature_(feature),
vars_(vars),
scale_factor_(scale_factor) {}
RendererContext const& renderer_context)
:marker_(marker),
detector_(detector),
sym_(sym),
bbox_(std::get<1>(renderer_context)),
marker_trans_(marker_trans),
scale_factor_(scale_factor),
feature_(feature),
vars_(vars),
ctx_(std::get<0>(renderer_context)) {}
template <typename T>
void add_path(T & path)
@ -964,15 +959,15 @@ struct markers_dispatch_2
}
}
Context & ctx_;
ImageMarker & marker_;
Detector & detector_;
markers_symbolizer const& sym_;
box2d<double> const& bbox_;
agg::trans_affine const& marker_trans_;
double scale_factor_;
feature_impl const& feature_;
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)
{
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_);
composite_mode_e comp_op = get<composite_mode_e>(sym, keys::comp_op, feature, common_.vars_, src_over);
context_.set_operator(comp_op);
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,
[&](svg::svg_path_adapter &, svg_attribute_type const &attr, svg_storage_type &marker,
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_);
});
renderer_context);
}
void cairo_renderer_base::process(text_symbolizer const& sym,
@ -1031,7 +1021,7 @@ void cairo_renderer_base::process(text_symbolizer const& sym,
namespace {
/**
* Render a thunk which was frozen from a previous call to
* Render a thunk which was frozen from a previous call to
* extract_bboxes. We should now have a new offset at which
* to render it, and the boxes themselves should already be
* in the detector from the placement_finder.

View file

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