From 1b03c81e846d4e0c45ae36c36deb32ab2872b129 Mon Sep 17 00:00:00 2001 From: Artem Pavlenko Date: Tue, 5 Feb 2008 13:58:47 +0000 Subject: [PATCH] hide implementation details --- include/mapnik/agg_renderer.hpp | 118 ++++++++++++++-------------- src/agg_renderer.cpp | 135 ++++++++++++++++++-------------- 2 files changed, 133 insertions(+), 120 deletions(-) diff --git a/include/mapnik/agg_renderer.hpp b/include/mapnik/agg_renderer.hpp index 7133f7530..38eb5290a 100644 --- a/include/mapnik/agg_renderer.hpp +++ b/include/mapnik/agg_renderer.hpp @@ -33,70 +33,66 @@ #include #include -// agg -#define AGG_RENDERING_BUFFER row_ptr_cache -#include "agg_rendering_buffer.h" -#include "agg_pixfmt_rgba.h" -#include "agg_rasterizer_scanline_aa.h" - // boost #include -#include - +#include + namespace mapnik { - template - class MAPNIK_DECL agg_renderer : public feature_style_processor >, - private boost::noncopyable - { - public: - agg_renderer(Map const& m, T & pixmap, unsigned offset_x=0, unsigned offset_y=0); - void start_map_processing(Map const& map); - void end_map_processing(Map const& map); - void start_layer_processing(Layer const& lay); - void end_layer_processing(Layer const& lay); - void process(point_symbolizer const& sym, - Feature const& feature, - proj_transform const& prj_trans); - void process(line_symbolizer const& sym, - Feature const& feature, - proj_transform const& prj_trans); - void process(line_pattern_symbolizer const& sym, - Feature const& feature, - proj_transform const& prj_trans); - void process(polygon_symbolizer const& sym, - Feature const& feature, - proj_transform const& prj_trans); - void process(polygon_pattern_symbolizer const& sym, - Feature const& feature, - proj_transform const& prj_trans); - void process(raster_symbolizer const& sym, - Feature const& feature, - proj_transform const& prj_trans); - void process(shield_symbolizer const& sym, - Feature const& feature, - proj_transform const& prj_trans); - void process(text_symbolizer const& sym, - Feature const& feature, - proj_transform const& prj_trans); - void process(building_symbolizer const& sym, - Feature const& feature, - proj_transform const& prj_trans); - void process(markers_symbolizer const& sym, - Feature const& feature, - proj_transform const& prj_trans); - private: - T & pixmap_; - unsigned width_; - unsigned height_; - agg::rendering_buffer buf_; - agg::pixfmt_rgba32_plain pixf_; - CoordTransform t_; - freetype_engine font_engine_; - face_manager font_manager_; - label_collision_detector4 detector_; - //placement_finder finder_; - agg::rasterizer_scanline_aa<> ras_; - }; + + class rasterizer; + + template + class MAPNIK_DECL agg_renderer : public feature_style_processor >, + private boost::noncopyable + { + + public: + agg_renderer(Map const& m, Image32 & pixmap, unsigned offset_x=0, unsigned offset_y=0); + ~agg_renderer(); + void start_map_processing(Map const& map); + void end_map_processing(Map const& map); + void start_layer_processing(Layer const& lay); + void end_layer_processing(Layer const& lay); + void process(point_symbolizer const& sym, + Feature const& feature, + proj_transform const& prj_trans); + void process(line_symbolizer const& sym, + Feature const& feature, + proj_transform const& prj_trans); + void process(line_pattern_symbolizer const& sym, + Feature const& feature, + proj_transform const& prj_trans); + void process(polygon_symbolizer const& sym, + Feature const& feature, + proj_transform const& prj_trans); + void process(polygon_pattern_symbolizer const& sym, + Feature const& feature, + proj_transform const& prj_trans); + void process(raster_symbolizer const& sym, + Feature const& feature, + proj_transform const& prj_trans); + void process(shield_symbolizer const& sym, + Feature const& feature, + proj_transform const& prj_trans); + void process(text_symbolizer const& sym, + Feature const& feature, + proj_transform const& prj_trans); + void process(building_symbolizer const& sym, + Feature const& feature, + proj_transform const& prj_trans); + void process(markers_symbolizer const& sym, + Feature const& feature, + proj_transform const& prj_trans); + private: + Image32 & pixmap_; + unsigned width_; + unsigned height_; + CoordTransform t_; + freetype_engine font_engine_; + face_manager font_manager_; + label_collision_detector4 detector_; + boost::scoped_ptr ras_ptr; + }; } #endif //AGG_RENDERER_HPP diff --git a/src/agg_renderer.cpp b/src/agg_renderer.cpp index 13ef2d7a9..7f4a8cfbd 100644 --- a/src/agg_renderer.cpp +++ b/src/agg_renderer.cpp @@ -31,6 +31,10 @@ #include // agg +#define AGG_RENDERING_BUFFER row_ptr_cache +#include "agg_rendering_buffer.h" +#include "agg_pixfmt_rgba.h" +#include "agg_rasterizer_scanline_aa.h" #include "agg_basics.h" #include "agg_scanline_p.h" #include "agg_scanline_u.h" @@ -62,11 +66,12 @@ // boost #include -#include #include // stl +#ifdef MAPNIK_DEBUG #include +#endif namespace mapnik { @@ -96,18 +101,19 @@ namespace mapnik ImageData32 const& pattern_; }; + struct rasterizer : agg::rasterizer_scanline_aa<>, boost::noncopyable {}; + template - agg_renderer::agg_renderer(Map const& m, T & pixmap, unsigned offset_x, unsigned offset_y) + agg_renderer::agg_renderer(Map const& m, Image32 & pixmap, unsigned offset_x, unsigned offset_y) : feature_style_processor(m), pixmap_(pixmap), width_(pixmap_.width()), height_(pixmap_.height()), - buf_(pixmap_.raw_data(),width_,height_, width_ * 4), - pixf_(buf_), t_(m.getWidth(),m.getHeight(),m.getCurrentExtent(),offset_x,offset_y), font_engine_(), font_manager_(font_engine_), - detector_(Envelope(-64 ,-64, m.getWidth() + 64 ,m.getHeight() + 64)) + detector_(Envelope(-64 ,-64, m.getWidth() + 64 ,m.getHeight() + 64)), + ras_ptr(new rasterizer) { boost::optional bg = m.background(); if (bg) pixmap_.setBackground(*bg); @@ -115,7 +121,10 @@ namespace mapnik std::clog << "scale=" << m.scale() << "\n"; #endif } - + + template + agg_renderer::~agg_renderer() {} + template void agg_renderer::start_map_processing(Map const& map) { @@ -123,7 +132,7 @@ namespace mapnik std::clog << "start map processing bbox=" << map.getCurrentExtent() << "\n"; #endif - ras_.clip_box(0,0,width_,height_); + ras_ptr->clip_box(0,0,width_,height_); } template @@ -165,28 +174,30 @@ namespace mapnik typedef agg::renderer_scanline_aa_solid renderer; Color const& fill_ = sym.get_fill(); - ras_.reset(); agg::scanline_u8 sl; - ren_base renb(pixf_); + + agg::rendering_buffer buf(pixmap_.raw_data(),width_,height_, width_ * 4); + agg::pixfmt_rgba32_plain pixf(buf); + + ren_base renb(pixf); unsigned r=fill_.red(); unsigned g=fill_.green(); unsigned b=fill_.blue(); - renderer ren(renb); + renderer ren(renb); + + ras_ptr->reset(); + for (unsigned i=0;i 2) { path_type path(t_,geom,prj_trans); - //agg::conv_smooth_poly1 smooth(path); - //smooth.smooth_value(0.6); - //agg::conv_curve > curve(smooth); - ras_.add_path(path); - //ras_.add_path(curve); + ras_ptr->add_path(path); } } ren.color(agg::rgba8(r, g, b, int(255 * sym.get_opacity()))); - agg::render_scanlines(ras_, sl, ren); + agg::render_scanlines(*ras_ptr, sl, ren); } typedef boost::tuple segment_t; @@ -207,15 +218,18 @@ namespace mapnik typedef agg::renderer_base ren_base; typedef agg::renderer_scanline_aa_solid renderer; - ren_base renb(pixf_); + agg::rendering_buffer buf(pixmap_.raw_data(),width_,height_, width_ * 4); + agg::pixfmt_rgba32_plain pixf(buf); + ren_base renb(pixf); + Color const& fill_ = sym.get_fill(); unsigned r=fill_.red(); unsigned g=fill_.green(); unsigned b=fill_.blue(); renderer ren(renb); agg::scanline_u8 sl; - ras_.reset(); - + + ras_ptr->reset(); double height = 0.7071 * sym.height(); // height in meters for (unsigned i=0;iline_to(itr->get<0>(),itr->get<1>() + height); path_type faces_path (t_,*faces,prj_trans); - ras_.add_path(faces_path); + ras_ptr->add_path(faces_path); ren.color(agg::rgba8(int(r*0.8), int(g*0.8), int(b*0.8), int(255 * sym.get_opacity()))); - agg::render_scanlines(ras_, sl, ren); - ras_.reset(); + agg::render_scanlines(*ras_ptr, sl, ren); + ras_ptr->reset(); frame->move_to(itr->get<0>(),itr->get<1>()); frame->line_to(itr->get<0>(),itr->get<1>()+height); @@ -287,16 +301,15 @@ namespace mapnik } path_type path(t_,*frame,prj_trans); agg::conv_stroke stroke(path); - ras_.add_path(stroke); + ras_ptr->add_path(stroke); ren.color(agg::rgba8(128, 128, 128, int(255 * sym.get_opacity()))); - agg::render_scanlines(ras_, sl, ren); - ras_.reset(); + agg::render_scanlines(*ras_ptr, sl, ren); + ras_ptr->reset(); path_type roof_path (t_,*roof,prj_trans); - ras_.add_path(roof_path); + ras_ptr->add_path(roof_path); ren.color(agg::rgba8(r, g, b, int(255 * sym.get_opacity()))); - agg::render_scanlines(ras_, sl, ren); - + agg::render_scanlines(*ras_ptr, sl, ren); } } @@ -304,8 +317,8 @@ namespace mapnik template void agg_renderer::process(line_symbolizer const& sym, - Feature const& feature, - proj_transform const& prj_trans) + Feature const& feature, + proj_transform const& prj_trans) { typedef agg::renderer_base ren_base; typedef coord_transform2 path_type; @@ -313,14 +326,17 @@ namespace mapnik typedef agg::rasterizer_outline_aa rasterizer_outline_aa; typedef agg::renderer_scanline_aa_solid renderer; - ren_base renb(pixf_); + agg::rendering_buffer buf(pixmap_.raw_data(),width_,height_, width_ * 4); + agg::pixfmt_rgba32_plain pixf(buf); + + ren_base renb(pixf); mapnik::stroke const& stroke_ = sym.get_stroke(); Color const& col = stroke_.get_color(); unsigned r=col.red(); unsigned g=col.green(); unsigned b=col.blue(); renderer ren(renb); - ras_.reset(); + ras_ptr->reset(); agg::scanline_p8 sl; for (unsigned i=0;iadd_path(stroke); } else @@ -390,18 +406,18 @@ namespace mapnik stroke.generator().miter_limit(4.0); stroke.generator().width(stroke_.get_width()); - ras_.add_path(stroke); + ras_ptr->add_path(stroke); } } } ren.color(agg::rgba8(r, g, b, int(255*stroke_.get_opacity()))); - agg::render_scanlines(ras_, sl, ren); + agg::render_scanlines(*ras_ptr, sl, ren); } template void agg_renderer::process(point_symbolizer const& sym, - Feature const& feature, - proj_transform const& prj_trans) + Feature const& feature, + proj_transform const& prj_trans) { double x; double y; @@ -491,8 +507,8 @@ namespace mapnik template void agg_renderer::process(line_pattern_symbolizer const& sym, - Feature const& feature, - proj_transform const& prj_trans) + Feature const& feature, + proj_transform const& prj_trans) { typedef coord_transform2 path_type; typedef agg::line_image_pattern pattern_type; @@ -500,8 +516,11 @@ namespace mapnik typedef agg::renderer_outline_image renderer_type; typedef agg::rasterizer_outline_aa rasterizer_type; + agg::rendering_buffer buf(pixmap_.raw_data(),width_,height_, width_ * 4); + agg::pixfmt_rgba32_plain pixf(buf); + ImageData32 pat = * sym.get_image(); - renderer_base ren_base(pixf_); + renderer_base ren_base(pixf); agg::pattern_filter_bilinear_rgba8 filter; pattern_source source(pat); pattern_type pattern (filter,source); @@ -541,9 +560,13 @@ namespace mapnik agg::span_allocator, span_gen_type> renderer_type; - ras_.reset(); - ren_base renb(pixf_); + + agg::rendering_buffer buf(pixmap_.raw_data(),width_,height_, width_ * 4); + agg::pixfmt_rgba32_plain pixf(buf); + ren_base renb(pixf); + agg::scanline_u8 sl; + ras_ptr->reset(); ImageData32 const& pattern = * sym.get_image(); unsigned w=pattern.width(); @@ -571,10 +594,10 @@ namespace mapnik if (geom.num_points() > 2) { path_type path(t_,geom,prj_trans); - ras_.add_path(path); + ras_ptr->add_path(path); } } - agg::render_scanlines(ras_, sl, rp); + agg::render_scanlines(*ras_ptr, sl, rp); } template @@ -604,12 +627,13 @@ namespace mapnik typedef agg::renderer_base ren_base; typedef agg::renderer_scanline_aa_solid renderer; arrow arrow_; - //double k = ::pow(1.2, 0.7); - //arrow_.head(4 * k, 4 * k, 3 * k, 2 * k); - //Color const& fill_ = sym.get_fill(); - ras_.reset(); + ras_ptr->reset(); + agg::scanline_u8 sl; - ren_base renb(pixf_); + agg::rendering_buffer buf(pixmap_.raw_data(),width_,height_, width_ * 4); + agg::pixfmt_rgba32_plain pixf(buf); + ren_base renb(pixf); + unsigned r = 0;// fill_.red(); unsigned g = 0; //fill_.green(); unsigned b = 255; //fill_.blue(); @@ -623,17 +647,16 @@ namespace mapnik agg::conv_dash dash(path); dash.add_dash(20.0,200.0); - //dash.dash_start(100.0); markers_converter, arrow, label_collision_detector4> marker(dash, arrow_, detector_); - ras_.add_path(marker); + ras_ptr->add_path(marker); } } ren.color(agg::rgba8(r, g, b, 255)); - agg::render_scanlines(ras_, sl, ren); -} + agg::render_scanlines(*ras_ptr, sl, ren); + } template void agg_renderer::process(text_symbolizer const& sym, @@ -666,12 +689,6 @@ namespace mapnik if (geom.num_points() > 0) // don't bother with empty geometries { path_type path(t_,geom,prj_trans); - //agg::conv_clip_polyline clipped_path(path); - //clipped_path.clip_box(0,0,width_,height_); - //placement > - // text_placement(&info, &t_, &prj_trans, clipped_path, sym); - //placement_finder, - // label_collision_detector4> finder(detector_); placement text_placement(info,sym); if (sym.get_label_placement() == POINT_PLACEMENT) {