1.polygon_symbolizer + using agg rasterrizer
2.render.cpp - exit rules loop (mastermap styles-?? not sure) 3.pre-allocate space for attributes
This commit is contained in:
parent
e123495ed0
commit
c7f9d1e568
13 changed files with 127 additions and 15 deletions
|
@ -50,7 +50,7 @@ Feature* PostgisFeatureset::next()
|
|||
if (geom)
|
||||
{
|
||||
feature=new Feature(id,geom);
|
||||
|
||||
feature->reserve_props(num_attrs_);
|
||||
unsigned start=2;
|
||||
for (unsigned pos=0;pos<num_attrs_;++pos)
|
||||
{
|
||||
|
|
|
@ -153,13 +153,14 @@ Feature* shape_index_featureset<filterT>::next()
|
|||
}
|
||||
if (attr_ids_.size())
|
||||
{
|
||||
f->reserve_props(attr_ids_.size());
|
||||
shape_.dbf().move_to(shape_.id_);
|
||||
std::vector<int>::const_iterator pos=attr_ids_.begin();
|
||||
while (pos!=attr_ids_.end())
|
||||
{
|
||||
try
|
||||
{
|
||||
shape_.dbf().add_attribute(*pos,f);//TODO optimize!!!
|
||||
shape_.dbf().add_attribute(*pos,f);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
|
||||
//$Id$
|
||||
|
||||
#include "mapnik.hpp"
|
||||
#include <iostream>
|
||||
|
||||
#ifndef COLORCUBE_HPP
|
||||
|
|
|
@ -86,7 +86,11 @@ namespace mapnik
|
|||
{
|
||||
return raster_;
|
||||
}
|
||||
|
||||
void reserve_props(unsigned n)
|
||||
{
|
||||
props_.reserve(n);
|
||||
}
|
||||
|
||||
void add_property(int v)
|
||||
{
|
||||
return props_.push_back(value(v));
|
||||
|
|
|
@ -21,6 +21,8 @@
|
|||
#ifndef IMAGE_DATA_HPP
|
||||
#define IMAGE_DATA_HPP
|
||||
|
||||
#include <cassert>
|
||||
|
||||
namespace mapnik
|
||||
{
|
||||
template <class T> class ImageData
|
||||
|
|
|
@ -21,10 +21,11 @@
|
|||
#ifndef IMAGE_READER_HPP
|
||||
#define IMAGE_READER_HPP
|
||||
|
||||
#include "mapnik.hpp"
|
||||
#include "image_data.hpp"
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
||||
|
||||
namespace mapnik
|
||||
{
|
||||
class ImageReaderException : public std::exception
|
||||
|
|
|
@ -47,8 +47,8 @@
|
|||
|
||||
#include "symbolizer.hpp"
|
||||
#include "stroke.hpp"
|
||||
#include "line_aa.hpp"
|
||||
#include "scanline_aa.hpp"
|
||||
//#include "line_aa.hpp"
|
||||
//#include "scanline_aa.hpp"
|
||||
|
||||
namespace mapnik
|
||||
{
|
||||
|
|
|
@ -21,7 +21,6 @@
|
|||
#ifndef LOCAL_DATASOURCE_HPP
|
||||
#define LOCAL_DATASOURCE_HPP
|
||||
|
||||
#include "mapnik.hpp"
|
||||
#include <vector>
|
||||
|
||||
namespace mapnik
|
||||
|
|
|
@ -22,8 +22,18 @@
|
|||
#define POLYGON_SYMBOLIZER_HPP
|
||||
|
||||
#include "symbolizer.hpp"
|
||||
#include "scanline_aa.hpp"
|
||||
#include "line_aa.hpp"
|
||||
#include "image_reader.hpp"
|
||||
//#include "scanline_aa.hpp"
|
||||
//#include "line_aa.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_pattern_rgba.h"
|
||||
|
||||
namespace mapnik
|
||||
{
|
||||
|
@ -40,15 +50,102 @@ namespace mapnik
|
|||
|
||||
void render(geometry_type& geom,Image32& image) const
|
||||
{
|
||||
ScanlineRasterizerAA<Image32> rasterizer(image);
|
||||
rasterizer.render<SHIFT8>(geom,fill_);
|
||||
//ScanlineRasterizerAA<Image32> rasterizer(image);
|
||||
//rasterizer.render<SHIFT8>(geom,fill_);
|
||||
typedef agg::renderer_base<agg::pixfmt_rgba32> ren_base;
|
||||
typedef agg::renderer_scanline_aa_solid<ren_base> renderer;
|
||||
agg::row_ptr_cache<agg::int8u> buf(image.raw_data(),image.width(),image.height(),
|
||||
image.width()*4);
|
||||
agg::pixfmt_rgba32 pixf(buf);
|
||||
ren_base renb(pixf);
|
||||
|
||||
double r=fill_.red()/255.0;
|
||||
double g=fill_.green()/255.0;
|
||||
double b=fill_.blue()/255.0;
|
||||
|
||||
renderer ren(renb);
|
||||
|
||||
agg::rasterizer_scanline_aa<> ras;
|
||||
agg::scanline_u8 sl;
|
||||
ras.clip_box(0,0,image.width(),image.height());
|
||||
ras.add_path(geom);
|
||||
ren.color(agg::rgba(r, g, b, 1.0));
|
||||
agg::render_scanlines(ras, sl, ren);
|
||||
}
|
||||
|
||||
private:
|
||||
polygon_symbolizer(const polygon_symbolizer&);
|
||||
polygon_symbolizer& operator=(const polygon_symbolizer&);
|
||||
|
||||
polygon_symbolizer& operator=(const polygon_symbolizer&);
|
||||
};
|
||||
|
||||
struct pattern_symbolizer : public symbolizer
|
||||
{
|
||||
private:
|
||||
ImageData32 pattern_;
|
||||
public:
|
||||
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));
|
||||
std::cout<<"image width="<<reader->width()<<std::endl;
|
||||
std::cout<<"image height="<<reader->height()<<std::endl;
|
||||
reader->read(0,0,pattern_);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
std::cerr<<"exception caught..."<<std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
virtual ~pattern_symbolizer() {}
|
||||
|
||||
void render(geometry_type& geom,Image32& image) const
|
||||
{
|
||||
typedef agg::renderer_base<agg::pixfmt_rgba32> ren_base;
|
||||
typedef agg::renderer_scanline_aa_solid<ren_base> renderer_solid;
|
||||
|
||||
agg::row_ptr_cache<agg::int8u> buf(image.raw_data(),image.width(),image.height(),
|
||||
image.width()*4);
|
||||
agg::pixfmt_rgba32 pixf(buf);
|
||||
ren_base renb(pixf);
|
||||
|
||||
unsigned w=pattern_.width();
|
||||
unsigned h=pattern_.height();
|
||||
agg::row_ptr_cache<agg::int8u> pattern_rbuf((agg::int8u*)pattern_.getBytes(),w,h,w*4);
|
||||
|
||||
typedef agg::wrap_mode_repeat wrap_x_type;
|
||||
typedef agg::wrap_mode_repeat wrap_y_type;
|
||||
typedef agg::span_pattern_rgba<agg::rgba8,
|
||||
agg::order_rgba,
|
||||
wrap_x_type,
|
||||
wrap_y_type> span_gen_type;
|
||||
typedef agg::renderer_scanline_aa<ren_base, span_gen_type> renderer_type;
|
||||
|
||||
unsigned offset_x = 0;
|
||||
unsigned offset_y = 0;
|
||||
agg::span_allocator<agg::rgba8> sa;
|
||||
span_gen_type sg(sa, pattern_rbuf, offset_x, offset_y);
|
||||
renderer_type rp(renb, sg);
|
||||
|
||||
agg::rasterizer_scanline_aa<> ras;
|
||||
agg::scanline_u8 sl;
|
||||
ras.clip_box(0,0,image.width(),image.height());
|
||||
ras.add_path(geom);
|
||||
//ren.color(agg::rgba(r, g, b, 1.0));
|
||||
agg::render_scanlines(ras, sl, rp);
|
||||
|
||||
}
|
||||
|
||||
private:
|
||||
pattern_symbolizer(const pattern_symbolizer&);
|
||||
pattern_symbolizer& operator=(const pattern_symbolizer&);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // POLYGON_SYMBOLIZER_HPP
|
||||
|
|
|
@ -98,6 +98,10 @@ ref_ptr<symbolizer> create_polygon_symbolizer(const Color& fill)
|
|||
return ref_ptr<symbolizer>(new polygon_symbolizer(fill));
|
||||
}
|
||||
|
||||
ref_ptr<symbolizer> create_polygon_symbolizer2(std::string const& file,unsigned w,unsigned h)
|
||||
{
|
||||
return ref_ptr<symbolizer>(new pattern_symbolizer(file,"png",w,h));
|
||||
}
|
||||
|
||||
BOOST_PYTHON_MODULE(mapnik)
|
||||
{
|
||||
|
@ -136,7 +140,7 @@ BOOST_PYTHON_MODULE(mapnik)
|
|||
def("line_symbolizer",&create_line_symbolizer);
|
||||
def("line_symbolizer",&create_line_symbolizer2);
|
||||
def("polygon_symbolizer",&create_polygon_symbolizer);
|
||||
|
||||
def("polygon_symbolizer",&create_polygon_symbolizer2);
|
||||
register_ptr_to_python<ref_ptr<symbolizer> >();
|
||||
register_ptr_to_python<filter_ptr>();
|
||||
}
|
||||
|
|
|
@ -20,6 +20,8 @@
|
|||
|
||||
|
||||
#include "image_reader.hpp"
|
||||
#include "factory.hpp"
|
||||
|
||||
namespace mapnik
|
||||
{
|
||||
typedef factory<ImageReader,std::string,
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
|
||||
#include "image_reader.hpp"
|
||||
#include <png.h>
|
||||
#include <iostream>
|
||||
|
||||
namespace mapnik
|
||||
{
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
#include "line_symbolizer.hpp"
|
||||
#include "query.hpp"
|
||||
#include "feature_layer_desc.hpp"
|
||||
#include "attribute_collector.hpp"
|
||||
#include "property_index.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
|
@ -126,6 +127,7 @@ namespace mapnik
|
|||
(*symIter)->render(*geom,image);
|
||||
++symIter;
|
||||
}
|
||||
break;// not sure !!
|
||||
}
|
||||
++itr;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue