sync markers rendering between agg and grid - closes #1309

This commit is contained in:
Dane Springmeyer 2012-08-14 17:18:44 -07:00
parent 7a5f06656c
commit a57996e661

View file

@ -24,22 +24,15 @@
porting notes --> porting notes -->
- grid includes - rasterizer -> grid_rasterizer
- detector - current_buffer_ -> pixmap_
- agg::rendering_buffer -> grid_renderering_buffer
- no gamma - no gamma
- mapnik::pixfmt_gray32 - mapnik::pixfmt_gray32
- agg::scanline_bin sl - agg::scanline_bin sl
- grid_rendering_buffer - grid_rendering_buffer
- agg::renderer_scanline_bin_solid - agg::renderer_scanline_bin_solid
- clamping: - TODO - clamp sizes to > 4 pixels of interactivity
// - clamp sizes to > 4 pixels of interactivity
if (tr.scale() < 0.5)
{
agg::trans_affine tr2;
tr2 *= agg::trans_affine_scaling(0.5);
tr = tr2;
}
tr *= agg::trans_affine_scaling(scale_factor_*(1.0/pixmap_.get_resolution()));
- svg_renderer.render_id - svg_renderer.render_id
- only encode feature if placements are found: - only encode feature if placements are found:
if (placed) if (placed)
@ -55,6 +48,7 @@ porting notes -->
#include <mapnik/grid/grid_pixfmt.hpp> #include <mapnik/grid/grid_pixfmt.hpp>
#include <mapnik/grid/grid_pixel.hpp> #include <mapnik/grid/grid_pixel.hpp>
#include <mapnik/grid/grid.hpp> #include <mapnik/grid/grid.hpp>
#include <mapnik/grid/grid_marker_helpers.hpp>
#include <mapnik/debug.hpp> #include <mapnik/debug.hpp>
#include <mapnik/geom_util.hpp> #include <mapnik/geom_util.hpp>
@ -67,7 +61,6 @@ porting notes -->
#include <mapnik/svg/svg_storage.hpp> #include <mapnik/svg/svg_storage.hpp>
#include <mapnik/svg/svg_path_adapter.hpp> #include <mapnik/svg/svg_path_adapter.hpp>
#include <mapnik/svg/svg_path_attributes.hpp> #include <mapnik/svg/svg_path_attributes.hpp>
#include <mapnik/markers_placement.hpp>
#include <mapnik/markers_symbolizer.hpp> #include <mapnik/markers_symbolizer.hpp>
// agg // agg
@ -75,15 +68,6 @@ porting notes -->
#include "agg_rendering_buffer.h" #include "agg_rendering_buffer.h"
#include "agg_pixfmt_rgba.h" #include "agg_pixfmt_rgba.h"
#include "agg_rasterizer_scanline_aa.h" #include "agg_rasterizer_scanline_aa.h"
#include "agg_scanline_u.h"
#include "agg_path_storage.h"
#include "agg_conv_clip_polyline.h"
#include "agg_conv_transform.h"
#include "agg_image_filters.h"
#include "agg_trans_bilinear.h"
#include "agg_span_allocator.h"
#include "agg_image_accessors.h"
#include "agg_span_image_filter_rgba.h"
// boost // boost
#include <boost/optional.hpp> #include <boost/optional.hpp>
@ -99,8 +83,12 @@ void grid_renderer<T>::process(markers_symbolizer const& sym,
mapnik::feature_impl & feature, mapnik::feature_impl & feature,
proj_transform const& prj_trans) proj_transform const& prj_trans)
{ {
typedef agg::renderer_base<mapnik::pixfmt_gray32> renderer_base; typedef grid_rendering_buffer buf_type;
typedef mapnik::pixfmt_gray32 pixfmt_type;
typedef agg::renderer_base<pixfmt_type> renderer_base;
typedef agg::renderer_scanline_bin_solid<renderer_base> renderer_type; typedef agg::renderer_scanline_bin_solid<renderer_base> renderer_type;
typedef label_collision_detector4 detector_type;
typedef boost::mpl::vector<clip_line_tag,clip_poly_tag,transform_tag,smooth_tag> conv_types;
std::string filename = path_processor_type::evaluate(*sym.get_filename(), feature); std::string filename = path_processor_type::evaluate(*sym.get_filename(), feature);
@ -109,129 +97,166 @@ void grid_renderer<T>::process(markers_symbolizer const& sym,
boost::optional<marker_ptr> mark = mapnik::marker_cache::instance()->find(filename, true); boost::optional<marker_ptr> mark = mapnik::marker_cache::instance()->find(filename, true);
if (mark && *mark) if (mark && *mark)
{ {
if (!(*mark)->is_vector())
{
MAPNIK_LOG_DEBUG(agg_renderer) << "agg_renderer: markers_symbolizer does not yet support non-SVG markers";
return;
}
ras_ptr->reset(); ras_ptr->reset();
agg::scanline_bin sl;
grid_rendering_buffer buf(pixmap_.raw_data(), width_, height_, width_);
mapnik::pixfmt_gray32 pixf(buf);
renderer_base renb(pixf);
renderer_type ren(renb);
agg::trans_affine geom_tr; agg::trans_affine geom_tr;
evaluate_transform(geom_tr, feature, sym.get_transform()); evaluate_transform(geom_tr, feature, sym.get_transform());
agg::trans_affine tr = agg::trans_affine_scaling(scale_factor_*(1.0/pixmap_.get_resolution()));
boost::optional<svg_path_ptr> marker = (*mark)->get_vector_data(); if ((*mark)->is_vector())
box2d<double> const& bbox = (*marker)->bounding_box();
agg::trans_affine tr;
setup_transform_scaling(tr, bbox, feature, sym);
evaluate_transform(tr, feature, sym.get_image_transform());
// - clamp sizes to > 4 pixels of interactivity
if (tr.scale() < 0.5)
{ {
agg::trans_affine tr2; using namespace mapnik::svg;
tr2 *= agg::trans_affine_scaling(0.5); typedef agg::pod_bvector<path_attributes> svg_attribute_type;
tr = tr2; typedef svg_renderer<svg_path_adapter,
} svg_attribute_type,
tr *= agg::trans_affine_scaling(scale_factor_*(1.0/pixmap_.get_resolution())); renderer_type,
pixfmt_type > svg_renderer_type;
typedef vector_markers_rasterizer_dispatch_grid<buf_type,
svg_renderer_type,
grid_rasterizer,
detector_type,
mapnik::grid > dispatch_type;
boost::optional<svg_path_ptr> const& stock_vector_marker = (*mark)->get_vector_data();
expression_ptr const& width_expr = sym.get_width();
expression_ptr const& height_expr = sym.get_height();
coord2d center = bbox.center(); // special case for simple ellipse markers
agg::trans_affine_translation recenter(-center.x, -center.y); // to allow for full control over rx/ry dimensions
agg::trans_affine marker_trans = recenter * tr; if (filename == "shape://ellipse"
&& (width_expr || height_expr))
using namespace mapnik::svg;
vertex_stl_adapter<svg_path_storage> stl_storage((*marker)->source());
svg_path_adapter svg_path(stl_storage);
agg::pod_bvector<path_attributes> attributes;
bool result = push_explicit_style( (*marker)->attributes(), attributes, sym);
svg_renderer<svg_path_adapter,
agg::pod_bvector<path_attributes>,
renderer_type,
mapnik::pixfmt_gray32 > svg_renderer(svg_path, result ? attributes : (*marker)->attributes());
marker_placement_e placement_method = sym.get_marker_placement();
bool placed = false;
BOOST_FOREACH( geometry_type & geom, feature.paths())
{
// TODO - merge this code with point_symbolizer rendering
if (placement_method == MARKER_POINT_PLACEMENT || geom.size() <= 1)
{ {
double x; svg_storage_type marker_ellipse;
double y; vertex_stl_adapter<svg_path_storage> stl_storage(marker_ellipse.source());
double z=0; svg_path_adapter svg_path(stl_storage);
label::interior_position(geom, x, y); // TODO - clamping to >= 4 pixels
prj_trans.backward(x,y,z); build_ellipse(sym, feature, marker_ellipse, svg_path);
t_.forward(&x,&y); svg_attribute_type attributes;
geom_tr.transform(&x,&y); bool result = push_explicit_style( (*stock_vector_marker)->attributes(), attributes, sym);
agg::trans_affine matrix = marker_trans; svg_renderer_type svg_renderer(svg_path, result ? attributes : (*stock_vector_marker)->attributes());
matrix.translate(x,y); evaluate_transform(tr, feature, sym.get_image_transform());
box2d<double> transformed_bbox = bbox * matrix; box2d<double> bbox = marker_ellipse.bounding_box();
coord2d center = bbox.center();
if (sym.get_allow_overlap() || agg::trans_affine_translation recenter(-center.x, -center.y);
detector_->has_placement(transformed_bbox)) agg::trans_affine marker_trans = recenter * tr;
buf_type render_buf(pixmap_.raw_data(), width_, height_, width_);
dispatch_type rasterizer_dispatch(render_buf,
svg_renderer,
*ras_ptr,
bbox,
marker_trans,
sym,
*detector_,
scale_factor_,
feature,
pixmap_);
vertex_converter<box2d<double>, dispatch_type, markers_symbolizer,
CoordTransform, proj_transform, agg::trans_affine, conv_types>
converter(query_extent_, rasterizer_dispatch, sym,t_,prj_trans,tr,scale_factor_);
if (sym.clip() && feature.paths().size() > 0) // optional clip (default: true)
{ {
placed = true; eGeomType type = feature.paths()[0].type();
svg_renderer.render_id(*ras_ptr, sl, renb, feature.id(), matrix, 1, bbox); if (type == Polygon)
if (!sym.get_ignore_placement()) converter.template set<clip_poly_tag>();
detector_->insert(transformed_bbox); else if (type == LineString)
converter.template set<clip_line_tag>();
// don't clip if type==Point
} }
} converter.template set<transform_tag>(); //always transform
else if (sym.clip()) if (sym.smooth() > 0.0) converter.template set<smooth_tag>(); // optional smooth converter
{ BOOST_FOREACH(geometry_type & geom, feature.paths())
typedef agg::conv_clip_polyline<geometry_type> clipped_geometry_type;
typedef coord_transform<CoordTransform,clipped_geometry_type> path_type;
typedef agg::conv_transform<path_type, agg::trans_affine> transformed_path_type;
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);
transformed_path_type path_transformed(path,geom_tr);
markers_placement<transformed_path_type, label_collision_detector4> placement(path_transformed, bbox, marker_trans, *detector_,
sym.get_spacing() * scale_factor_,
sym.get_max_error(),
sym.get_allow_overlap());
double x, y, angle;
while (placement.get_point(x, y, angle))
{ {
placed = true; converter.apply(geom);
agg::trans_affine matrix = marker_trans;
matrix.rotate(angle);
matrix.translate(x, y);
svg_renderer.render_id(*ras_ptr, sl, renb, feature.id(), matrix, 1, bbox);
} }
} }
else else
{ {
typedef coord_transform<CoordTransform,geometry_type> path_type; box2d<double> const& bbox = (*mark)->bounding_box();
typedef agg::conv_transform<path_type, agg::trans_affine> transformed_path_type; setup_transform_scaling(tr, bbox, feature, sym);
path_type path(t_,geom,prj_trans); evaluate_transform(tr, feature, sym.get_image_transform());
transformed_path_type path_transformed(path,geom_tr); // TODO - clamping to >= 4 pixels
markers_placement<transformed_path_type, label_collision_detector4> placement(path_transformed, bbox, marker_trans, *detector_, coord2d center = bbox.center();
sym.get_spacing() * scale_factor_, agg::trans_affine_translation recenter(-center.x, -center.y);
sym.get_max_error(), agg::trans_affine marker_trans = recenter * tr;
sym.get_allow_overlap()); vertex_stl_adapter<svg_path_storage> stl_storage((*stock_vector_marker)->source());
double x, y, angle; svg_path_adapter svg_path(stl_storage);
while (placement.get_point(x, y, angle)) svg_attribute_type attributes;
bool result = push_explicit_style( (*stock_vector_marker)->attributes(), attributes, sym);
svg_renderer_type svg_renderer(svg_path, result ? attributes : (*stock_vector_marker)->attributes());
buf_type render_buf(pixmap_.raw_data(), width_, height_, width_);
dispatch_type rasterizer_dispatch(render_buf,
svg_renderer,
*ras_ptr,
bbox,
marker_trans,
sym,
*detector_,
scale_factor_,
feature,
pixmap_);
vertex_converter<box2d<double>, dispatch_type, markers_symbolizer,
CoordTransform, proj_transform, agg::trans_affine, conv_types>
converter(query_extent_, rasterizer_dispatch, sym,t_,prj_trans,tr,scale_factor_);
if (sym.clip() && feature.paths().size() > 0) // optional clip (default: true)
{ {
placed = true; eGeomType type = feature.paths()[0].type();
agg::trans_affine matrix = marker_trans; if (type == Polygon)
matrix.rotate(angle); converter.template set<clip_poly_tag>();
matrix.translate(x, y); else if (type == LineString)
svg_renderer.render_id(*ras_ptr, sl, renb, feature.id(), matrix, 1, bbox); converter.template set<clip_line_tag>();
// don't clip if type==Point
}
converter.template set<transform_tag>(); //always transform
if (sym.smooth() > 0.0) converter.template set<smooth_tag>(); // optional smooth converter
BOOST_FOREACH(geometry_type & geom, feature.paths())
{
converter.apply(geom);
} }
} }
} }
if (placed) else // raster markers
{ {
pixmap_.add_feature(feature); box2d<double> const& bbox = (*mark)->bounding_box();
setup_transform_scaling(tr, bbox, feature, sym);
evaluate_transform(tr, feature, sym.get_image_transform());
// - 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;
boost::optional<mapnik::image_ptr> marker = (*mark)->get_bitmap_data();
typedef raster_markers_rasterizer_dispatch_grid<buf_type,
grid_rasterizer,
pixfmt_type,
renderer_base,
renderer_type,
detector_type,
mapnik::grid > dispatch_type;
buf_type render_buf(pixmap_.raw_data(), width_, height_, width_);
dispatch_type rasterizer_dispatch(render_buf,
*ras_ptr,
**marker,
marker_trans,
sym,
*detector_,
scale_factor_,
feature,
pixmap_);
vertex_converter<box2d<double>, dispatch_type, markers_symbolizer,
CoordTransform, proj_transform, agg::trans_affine, conv_types>
converter(query_extent_, rasterizer_dispatch, sym,t_,prj_trans,tr,scale_factor_);
if (sym.clip() && feature.paths().size() > 0) // optional clip (default: true)
{
eGeomType type = feature.paths()[0].type();
if (type == Polygon)
converter.template set<clip_poly_tag>();
else if (type == LineString)
converter.template set<clip_line_tag>();
// don't clip if type==Point
}
converter.template set<transform_tag>(); //always transform
if (sym.smooth() > 0.0) converter.template set<smooth_tag>(); // optional smooth converter
BOOST_FOREACH(geometry_type & geom, feature.paths())
{
converter.apply(geom);
}
} }
} }
} }