1.added line pattern symbolizer
2.added layer envelope check in main rendering loop
This commit is contained in:
parent
a7c154f223
commit
390b9c4655
5 changed files with 200 additions and 72 deletions
113
include/line_pattern_symbolizer.hpp
Normal file
113
include/line_pattern_symbolizer.hpp
Normal file
|
@ -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 <boost/utility.hpp>
|
||||
|
||||
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<ImageReader> reader(get_image_reader(type,file));
|
||||
reader->read(0,0,pattern_);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
std::cerr<<"exception caught..."<<std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
virtual ~line_pattern_symbolizer() {}
|
||||
|
||||
void render(geometry_type& geom,Image32& image) const
|
||||
{
|
||||
typedef agg::line_image_pattern<agg::pattern_filter_bilinear_rgba8> pattern_type;
|
||||
typedef agg::renderer_base<agg::pixfmt_rgba32> renderer_base;
|
||||
typedef agg::renderer_outline_image<renderer_base, pattern_type> renderer_type;
|
||||
typedef agg::rasterizer_outline_aa<renderer_type> rasterizer_type;
|
||||
unsigned int width=image.width();
|
||||
unsigned int height=image.height();
|
||||
agg::row_ptr_cache<agg::int8u> 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
|
|
@ -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<ren_base> 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<geometry<vertex2d> > 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<agg::conv_dash<geometry<vertex2d> > > 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<ren_base> renderer_oaa;
|
||||
typedef agg::rasterizer_outline_aa<renderer_oaa> 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<geometry<vertex2d> > stroke(geom);
|
||||
typedef agg::renderer_scanline_aa_solid<ren_base> 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<geometry<vertex2d> > 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<agg::conv_dash<geometry<vertex2d> > > 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<geometry<vertex2d> > 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -120,7 +120,6 @@ namespace mapnik
|
|||
return name_;
|
||||
}
|
||||
|
||||
|
||||
const std::string& get_title() const
|
||||
{
|
||||
return title_;
|
||||
|
|
|
@ -182,7 +182,7 @@ namespace mapnik
|
|||
for (size_t n=0;n<map.layerCount();++n)
|
||||
{
|
||||
Layer const& l=map.getLayer(n);
|
||||
if (l.isVisible(scale)) // TODO: extent check
|
||||
if (l.isVisible(scale) && l.envelope().intersects(extent))
|
||||
{
|
||||
datasource_p const& ds=l.datasource();
|
||||
if (!ds) continue;
|
||||
|
|
Loading…
Reference in a new issue