From 390b9c46555f2118c246bf2349fb228d1afa2afc Mon Sep 17 00:00:00 2001 From: Artem Pavlenko Date: Mon, 23 Jan 2006 10:33:32 +0000 Subject: [PATCH] 1.added line pattern symbolizer 2.added layer envelope check in main rendering loop --- include/line_pattern_symbolizer.hpp | 113 ++++++++++++++++++++ include/line_symbolizer.hpp | 155 +++++++++++++++------------- include/mapnik.hpp | 1 + include/rule.hpp | 1 - src/render.cpp | 2 +- 5 files changed, 200 insertions(+), 72 deletions(-) create mode 100644 include/line_pattern_symbolizer.hpp diff --git a/include/line_pattern_symbolizer.hpp b/include/line_pattern_symbolizer.hpp new file mode 100644 index 000000000..c1163cbe9 --- /dev/null +++ b/include/line_pattern_symbolizer.hpp @@ -0,0 +1,113 @@ +/* This file is part of Mapnik (c++ mapping toolkit) + * Copyright (C) 2005 Artem Pavlenko + * + * Mapnik is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +//$Id: polygon_symbolizer.hpp 39 2005-04-10 20:39:53Z pavlenko $ + +#ifndef LINE_PATTERN_SYMBOLIZER_HPP +#define LINE_PATTERN_SYMBOLIZER_HPP + +#include "symbolizer.hpp" +#include "image_reader.hpp" +#include "agg_basics.h" +#include "agg_rendering_buffer.h" +#include "agg_rasterizer_scanline_aa.h" +#include "agg_scanline_p.h" +#include "agg_scanline_u.h" +#include "agg_renderer_scanline.h" +#include "agg_pixfmt_rgba.h" +#include "agg_path_storage.h" +#include "agg_span_allocator.h" +#include "agg_span_pattern_rgba.h" +#include "agg_image_accessors.h" +#include "agg_pattern_filters_rgba.h" + +#include + +namespace mapnik +{ + class pattern_source : private boost::noncopyable + { + public: + pattern_source(ImageData32 const& pattern) + : pattern_(pattern) {} + + unsigned int width() const + { + return pattern_.width(); + } + unsigned int height() const + { + return pattern_.height(); + } + agg::rgba8 pixel(int x, int y) const + { + unsigned c = pattern_(x,y); + return agg::rgba8(c & 0xff, (c >> 8) & 0xff, (c >> 16) & 0xff,(c >> 24) & 0xff); + } + private: + ImageData32 const& pattern_; + }; + + struct line_pattern_symbolizer : public symbolizer, + private boost::noncopyable + { + private: + ImageData32 pattern_; + public: + line_pattern_symbolizer(std::string const& file, + std::string const& type, + unsigned width,unsigned height) + : symbolizer(), + pattern_(width,height) + { + try + { + std::auto_ptr reader(get_image_reader(type,file)); + reader->read(0,0,pattern_); + } + catch (...) + { + std::cerr<<"exception caught..."< pattern_type; + typedef agg::renderer_base renderer_base; + typedef agg::renderer_outline_image renderer_type; + typedef agg::rasterizer_outline_aa rasterizer_type; + unsigned int width=image.width(); + unsigned int height=image.height(); + agg::row_ptr_cache buf(image.raw_data(), width, height,width*4); + agg::pixfmt_rgba32 pixf(buf); + renderer_base ren_base(pixf); + agg::pattern_filter_bilinear_rgba8 filter; + pattern_source source(pattern_); + pattern_type pattern (filter,source); + renderer_type ren(ren_base, pattern); + ren.clip_box(0,0,width,height); + rasterizer_type ras(ren); + ras.add_path(geom); + } + }; +} + +#endif // LINE_PATTERN_SYMBOLIZER_HPP diff --git a/include/line_symbolizer.hpp b/include/line_symbolizer.hpp index 0d03c29dc..1571c7ca7 100644 --- a/include/line_symbolizer.hpp +++ b/include/line_symbolizer.hpp @@ -74,86 +74,101 @@ namespace mapnik ren_base renb(pixf); Color const& col = stroke_.get_color(); - double r=col.red()/255.0; - double g=col.green()/255.0; - double b=col.blue()/255.0; + unsigned r=col.red(); + unsigned g=col.green(); + unsigned b=col.blue(); - - typedef agg::renderer_scanline_aa_solid renderer; - renderer ren(renb); - - agg::rasterizer_scanline_aa<> ras; - agg::scanline_u8 sl; - - if (stroke_.has_dash()) + if (0)//stroke_.get_width() <= 1.0) { - - agg::conv_dash > dash(geom); - dash_array const& d = stroke_.get_dash_array(); - dash_array::const_iterator itr = d.begin(); - dash_array::const_iterator end = d.end(); - while (itr != end) - { - dash.add_dash(itr->first, itr->second); - ++itr; - } - agg::conv_stroke > > stroke(dash); - - line_join_e join=stroke_.get_line_join(); - if ( join == MITER_JOIN) - stroke.generator().line_join(agg::miter_join); - else if( join == MITER_REVERT_JOIN) - stroke.generator().line_join(agg::miter_join); - else if( join == ROUND_JOIN) - stroke.generator().line_join(agg::round_join); - else - stroke.generator().line_join(agg::bevel_join); - - line_cap_e cap=stroke_.get_line_cap(); - if (cap == BUTT_CAP) - stroke.generator().line_cap(agg::butt_cap); - else if (cap == SQUARE_CAP) - stroke.generator().line_cap(agg::square_cap); - else - stroke.generator().line_cap(agg::round_cap); + typedef agg::renderer_outline_aa renderer_oaa; + typedef agg::rasterizer_outline_aa rasterizer_outline_aa; + agg::line_profile_aa prof; + prof.width(stroke_.get_width()); + renderer_oaa ren_oaa(renb, prof); + rasterizer_outline_aa ras_oaa(ren_oaa); - stroke.generator().miter_limit(4.0); - stroke.generator().width(stroke_.get_width()); - - ras.clip_box(0,0,image.width(),image.height()); - ras.add_path(stroke); - ren.color(agg::rgba(r, g, b, stroke_.get_opacity())); - agg::render_scanlines(ras, sl, ren); + ren_oaa.color(agg::rgba8(r, g, b, int(255*stroke_.get_opacity()))); + ren_oaa.clip_box(0,0,image.width(),image.height()); + ras_oaa.add_path(geom); + } else { - agg::conv_stroke > stroke(geom); + typedef agg::renderer_scanline_aa_solid renderer; + renderer ren(renb); + agg::rasterizer_scanline_aa<> ras; + agg::scanline_u8 sl; - line_join_e join=stroke_.get_line_join(); - if ( join == MITER_JOIN) - stroke.generator().line_join(agg::miter_join); - else if( join == MITER_REVERT_JOIN) - stroke.generator().line_join(agg::miter_join); - else if( join == ROUND_JOIN) - stroke.generator().line_join(agg::round_join); - else - stroke.generator().line_join(agg::bevel_join); + if (stroke_.has_dash()) + { - line_cap_e cap=stroke_.get_line_cap(); - if (cap == BUTT_CAP) - stroke.generator().line_cap(agg::butt_cap); - else if (cap == SQUARE_CAP) - stroke.generator().line_cap(agg::square_cap); - else - stroke.generator().line_cap(agg::round_cap); + agg::conv_dash > dash(geom); + dash_array const& d = stroke_.get_dash_array(); + dash_array::const_iterator itr = d.begin(); + dash_array::const_iterator end = d.end(); + while (itr != end) + { + dash.add_dash(itr->first, itr->second); + ++itr; + } + agg::conv_stroke > > stroke(dash); + + line_join_e join=stroke_.get_line_join(); + if ( join == MITER_JOIN) + stroke.generator().line_join(agg::miter_join); + else if( join == MITER_REVERT_JOIN) + stroke.generator().line_join(agg::miter_join); + else if( join == ROUND_JOIN) + stroke.generator().line_join(agg::round_join); + else + stroke.generator().line_join(agg::bevel_join); + + line_cap_e cap=stroke_.get_line_cap(); + if (cap == BUTT_CAP) + stroke.generator().line_cap(agg::butt_cap); + else if (cap == SQUARE_CAP) + stroke.generator().line_cap(agg::square_cap); + else + stroke.generator().line_cap(agg::round_cap); - stroke.generator().miter_limit(4.0); - stroke.generator().width(stroke_.get_width()); + stroke.generator().miter_limit(4.0); + stroke.generator().width(stroke_.get_width()); + + ras.clip_box(0,0,image.width(),image.height()); + ras.add_path(stroke); + ren.color(agg::rgba8(r, g, b, int(255*stroke_.get_opacity()))); + agg::render_scanlines(ras, sl, ren); + } + else + { + agg::conv_stroke > stroke(geom); + + line_join_e join=stroke_.get_line_join(); + if ( join == MITER_JOIN) + stroke.generator().line_join(agg::miter_join); + else if( join == MITER_REVERT_JOIN) + stroke.generator().line_join(agg::miter_join); + else if( join == ROUND_JOIN) + stroke.generator().line_join(agg::round_join); + else + stroke.generator().line_join(agg::bevel_join); - ras.clip_box(0,0,image.width(),image.height()); - ras.add_path(stroke); - ren.color(agg::rgba(r, g, b, stroke_.get_opacity())); - agg::render_scanlines(ras, sl, ren); + line_cap_e cap=stroke_.get_line_cap(); + if (cap == BUTT_CAP) + stroke.generator().line_cap(agg::butt_cap); + else if (cap == SQUARE_CAP) + stroke.generator().line_cap(agg::square_cap); + else + stroke.generator().line_cap(agg::round_cap); + + stroke.generator().miter_limit(4.0); + stroke.generator().width(stroke_.get_width()); + + ras.clip_box(0,0,image.width(),image.height()); + ras.add_path(stroke); + ren.color(agg::rgba8(r, g, b, int(255*stroke_.get_opacity()))); + agg::render_scanlines(ras, sl, ren); + } } } }; diff --git a/include/mapnik.hpp b/include/mapnik.hpp index fc3d81bc6..16de08532 100644 --- a/include/mapnik.hpp +++ b/include/mapnik.hpp @@ -48,6 +48,7 @@ #include "image_reader.hpp" #include "line_symbolizer.hpp" #include "polygon_symbolizer.hpp" +#include "line_pattern_symbolizer.hpp" //#include "image_symbolizer.hpp" #include "image_util.hpp" #include "datasource.hpp" diff --git a/include/rule.hpp b/include/rule.hpp index bab36104e..1ecd1c3a6 100644 --- a/include/rule.hpp +++ b/include/rule.hpp @@ -120,7 +120,6 @@ namespace mapnik return name_; } - const std::string& get_title() const { return title_; diff --git a/src/render.cpp b/src/render.cpp index 0b29b7f24..c7903ba01 100644 --- a/src/render.cpp +++ b/src/render.cpp @@ -182,7 +182,7 @@ namespace mapnik for (size_t n=0;n