Merge branch 'master' of github.com:mapnik/mapnik

This commit is contained in:
Dane Springmeyer 2012-03-14 11:53:58 -07:00
commit 586416b523
16 changed files with 208 additions and 132 deletions

View file

@ -84,7 +84,11 @@ void export_polygon_symbolizer()
.add_property("gamma_method",
&polygon_symbolizer::get_gamma_method,
&polygon_symbolizer::set_gamma_method,
"Set/get the gamma correction method of the polygon")
"gamma correction method")
.add_property("smooth",
&polygon_symbolizer::smooth,
&polygon_symbolizer::set_smooth,
"smooth value (0..1.0)")
;
}

View file

@ -138,7 +138,9 @@ qcdrain_lyr.datasource = mapnik.Shapefile(file='../data/qcdrainage')
qcdrain_style = mapnik.Style()
qcdrain_rule = mapnik.Rule()
qcdrain_rule.filter = mapnik.Expression('[HYC] = 8')
qcdrain_rule.symbols.append(mapnik.PolygonSymbolizer(mapnik.Color(153, 204, 255)))
sym = mapnik.PolygonSymbolizer(mapnik.Color(153, 204, 255))
sym.smooth = 1.0 # very smooth
qcdrain_rule.symbols.append(sym)
qcdrain_style.rules.append(qcdrain_rule)
m.append_style('drainage', qcdrain_style)

View file

@ -30,6 +30,7 @@
#include <mapnik/ctrans.hpp>
#include <mapnik/memory_datasource.hpp>
#include <mapnik/feature_kv_iterator.hpp>
#include <mapnik/config_error.hpp>
#include "mapwidget.hpp"
#include "info_dialog.hpp"
@ -487,7 +488,7 @@ void MapWidget::updateMap()
}
catch (mapnik::config_error & ex)
{
std::cerr << ex.what() << std::endl;
std::cerr << ex.what() << std::endl;
}
catch (...)
{

View file

@ -0,0 +1,91 @@
/*****************************************************************************
*
* This file is part of Mapnik (c++ mapping toolkit)
*
* Copyright (C) 2012 Artem Pavlenko
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*****************************************************************************/
#ifndef MAPNIK_AGG_HELPERS_HPP
#define MAPNIK_AGG_HELPERS_HPP
#include "agg_gamma_functions.h"
#include "agg_math_stroke.h"
namespace mapnik {
template <typename T0, typename T1>
void set_gamma_method(T0 const& obj, T1 & ras_ptr)
{
switch (obj.get_gamma_method())
{
case GAMMA_POWER:
ras_ptr->gamma(agg::gamma_power(obj.get_gamma()));
break;
case GAMMA_LINEAR:
ras_ptr->gamma(agg::gamma_linear(0.0, obj.get_gamma()));
break;
case GAMMA_NONE:
ras_ptr->gamma(agg::gamma_none());
break;
case GAMMA_THRESHOLD:
ras_ptr->gamma(agg::gamma_threshold(obj.get_gamma()));
break;
case GAMMA_MULTIPLY:
ras_ptr->gamma(agg::gamma_multiply(obj.get_gamma()));
break;
default:
ras_ptr->gamma(agg::gamma_power(obj.get_gamma()));
}
}
template <typename Stroke,typename PathType>
void set_join_caps(Stroke const& stroke_, PathType & stroke)
{
line_join_e join=stroke_.get_line_join();
switch (join)
{
case MITER_JOIN:
stroke.generator().line_join(agg::miter_join);
break;
case MITER_REVERT_JOIN:
stroke.generator().line_join(agg::miter_join);
break;
case ROUND_JOIN:
stroke.generator().line_join(agg::round_join);
break;
default:
stroke.generator().line_join(agg::bevel_join);
}
line_cap_e cap=stroke_.get_line_cap();
switch (cap)
{
case BUTT_CAP:
stroke.generator().line_cap(agg::butt_cap);
break;
case SQUARE_CAP:
stroke.generator().line_cap(agg::square_cap);
break;
default:
stroke.generator().line_cap(agg::round_cap);
}
}
}
#endif //MAPNIK_AGG_HELPERS_HPP

View file

@ -35,7 +35,7 @@ namespace mapnik
struct MAPNIK_DECL polygon_symbolizer : public symbolizer_base
{
polygon_symbolizer();
polygon_symbolizer(color const& fill);
explicit polygon_symbolizer(color const& fill);
color const& get_fill() const;
void set_fill(color const& fill);
void set_opacity(double opacity);
@ -44,12 +44,14 @@ struct MAPNIK_DECL polygon_symbolizer : public symbolizer_base
double get_gamma() const;
void set_gamma_method(gamma_method_e gamma_method);
gamma_method_e get_gamma_method() const;
void set_smooth(double smooth);
double smooth() const;
private:
color fill_;
double opacity_;
double gamma_;
gamma_method_e gamma_method_;
double smooth_;
};
}

View file

@ -25,7 +25,15 @@
//mapnik
#include <mapnik/xml_node.hpp>
#include <mapnik/expression_grammar.hpp>
// boost
#include <boost/format.hpp>
#if BOOST_VERSION >= 104500
#include <mapnik/css_color_grammar.hpp>
#else
#include <mapnik/css_color_grammar_deprecated.hpp>
#endif
//stl
#include <string>

View file

@ -127,7 +127,7 @@ void dbf_file::add_attribute(int col, mapnik::transcoder const& tr, Feature & f)
if (col>=0 && col<num_fields_)
{
std::string name=fields_[col].name_;
std::string const& name=fields_[col].name_;
switch (fields_[col].type_)
{

View file

@ -44,15 +44,15 @@ shape_index_featureset<filterT>::shape_index_featureset(filterT const& filter,
std::string const& shape_name,
int row_limit)
: filter_(filter),
ctx_(boost::make_shared<mapnik::context_type>()),
shape_(shape),
tr_(new transcoder(encoding)),
row_limit_(row_limit),
count_(0)
{
ctx_ = boost::make_shared<mapnik::context_type>();
shape_.shp().skip(100);
setup_attributes(ctx_, attribute_names, shape_name, shape_,attr_ids_);
boost::shared_ptr<shape_file> index = shape_.index();
if (index)
{

View file

@ -23,6 +23,7 @@
// mapnik
#include <mapnik/agg_renderer.hpp>
#include <mapnik/agg_helpers.hpp>
#include <mapnik/agg_rasterizer.hpp>
#include <mapnik/line_symbolizer.hpp>
@ -71,7 +72,6 @@ void agg_renderer<T>::process(line_symbolizer const& sym,
typedef agg::rasterizer_outline_aa<renderer_type> rasterizer_type;
agg::line_profile_aa profile;
//agg::line_profile_aa profile(stroke_.get_width() * scale_factor_, agg::gamma_none());
profile.width(stroke_.get_width() * scale_factor_);
ren_base base_ren(pixf);
renderer_type ren(base_ren, profile);
@ -102,26 +102,10 @@ void agg_renderer<T>::process(line_symbolizer const& sym,
ren_base renb(pixf);
renderer ren(renb);
ras_ptr->reset();
switch (stroke_.get_gamma_method())
{
case GAMMA_POWER:
ras_ptr->gamma(agg::gamma_power(stroke_.get_gamma()));
break;
case GAMMA_LINEAR:
ras_ptr->gamma(agg::gamma_linear(0.0, stroke_.get_gamma()));
break;
case GAMMA_NONE:
ras_ptr->gamma(agg::gamma_none());
break;
case GAMMA_THRESHOLD:
ras_ptr->gamma(agg::gamma_threshold(stroke_.get_gamma()));
break;
case GAMMA_MULTIPLY:
ras_ptr->gamma(agg::gamma_multiply(stroke_.get_gamma()));
break;
default:
ras_ptr->gamma(agg::gamma_power(stroke_.get_gamma()));
}
set_gamma_method(stroke_, ras_ptr);
//metawriter_with_properties writer = sym.get_metawriter();
for (unsigned i=0;i<feature->num_geometries();++i)
@ -129,12 +113,12 @@ void agg_renderer<T>::process(line_symbolizer const& sym,
geometry_type & geom = feature->get_geometry(i);
if (geom.num_points() > 1)
{
clipped_geometry_type clipped(geom);
clipped.clip_box(ext.minx(),ext.miny(),ext.maxx(),ext.maxy());
path_type path(t_,clipped,prj_trans);
if (stroke_.has_dash())
{
clipped_geometry_type clipped(geom);
clipped.clip_box(ext.minx(),ext.miny(),ext.maxx(),ext.maxy());
path_type path(t_,clipped,prj_trans);
agg::conv_dash<path_type> dash(path);
dash_array const& d = stroke_.get_dash_array();
dash_array::const_iterator itr = d.begin();
@ -144,27 +128,8 @@ void agg_renderer<T>::process(line_symbolizer const& sym,
dash.add_dash(itr->first * scale_factor_,
itr->second * scale_factor_);
}
agg::conv_stroke<agg::conv_dash<path_type > > 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);
set_join_caps(stroke_,stroke);
stroke.generator().miter_limit(4.0);
stroke.generator().width(stroke_.get_width() * scale_factor_);
ras_ptr->add_path(stroke);
@ -172,25 +137,11 @@ void agg_renderer<T>::process(line_symbolizer const& sym,
}
else
{
agg::conv_stroke<path_type> stroke(path);
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);
clipped_geometry_type clipped(geom);
clipped.clip_box(ext.minx(),ext.miny(),ext.maxx(),ext.maxy());
path_type path(t_,clipped,prj_trans);
agg::conv_stroke<path_type> stroke(path);
set_join_caps(stroke_,stroke);
stroke.generator().miter_limit(4.0);
stroke.generator().width(stroke_.get_width() * scale_factor_);
ras_ptr->add_path(stroke);

View file

@ -23,6 +23,7 @@
// mapnik
#include <mapnik/agg_renderer.hpp>
#include <mapnik/agg_helpers.hpp>
#include <mapnik/agg_rasterizer.hpp>
#include <mapnik/marker.hpp>
#include <mapnik/marker_cache.hpp>
@ -72,27 +73,8 @@ void agg_renderer<T>::process(polygon_pattern_symbolizer const& sym,
agg::scanline_u8 sl;
ras_ptr->reset();
switch (sym.get_gamma_method())
{
case GAMMA_POWER:
ras_ptr->gamma(agg::gamma_power(sym.get_gamma()));
break;
case GAMMA_LINEAR:
ras_ptr->gamma(agg::gamma_linear(0.0, sym.get_gamma()));
break;
case GAMMA_NONE:
ras_ptr->gamma(agg::gamma_none());
break;
case GAMMA_THRESHOLD:
ras_ptr->gamma(agg::gamma_threshold(sym.get_gamma()));
break;
case GAMMA_MULTIPLY:
ras_ptr->gamma(agg::gamma_multiply(sym.get_gamma()));
break;
default:
ras_ptr->gamma(agg::gamma_power(sym.get_gamma()));
}
set_gamma_method(sym,ras_ptr);
std::string filename = path_processor_type::evaluate( *sym.get_filename(), *feature);
boost::optional<mapnik::marker_ptr> marker;
if ( !filename.empty() )

View file

@ -23,6 +23,7 @@
// mapnik
#include <mapnik/agg_renderer.hpp>
#include <mapnik/agg_helpers.hpp>
#include <mapnik/agg_rasterizer.hpp>
#include <mapnik/polygon_symbolizer.hpp>
@ -35,6 +36,7 @@
// for polygon_symbolizer
#include "agg_renderer_scanline.h"
#include "agg_conv_clip_polygon.h"
#include "agg_conv_smooth_poly1.h"
// stl
#include <string>
@ -45,8 +47,6 @@ void agg_renderer<T>::process(polygon_symbolizer const& sym,
mapnik::feature_ptr const& feature,
proj_transform const& prj_trans)
{
typedef agg::conv_clip_polygon<geometry_type> clipped_geometry_type;
typedef coord_transform2<CoordTransform,clipped_geometry_type> path_type;
typedef agg::renderer_base<agg::pixfmt_rgba32_plain> ren_base;
typedef agg::renderer_scanline_aa_solid<ren_base> renderer;
@ -65,37 +65,37 @@ void agg_renderer<T>::process(polygon_symbolizer const& sym,
renderer ren(renb);
ras_ptr->reset();
switch (sym.get_gamma_method())
{
case GAMMA_POWER:
ras_ptr->gamma(agg::gamma_power(sym.get_gamma()));
break;
case GAMMA_LINEAR:
ras_ptr->gamma(agg::gamma_linear(0.0, sym.get_gamma()));
break;
case GAMMA_NONE:
ras_ptr->gamma(agg::gamma_none());
break;
case GAMMA_THRESHOLD:
ras_ptr->gamma(agg::gamma_threshold(sym.get_gamma()));
break;
case GAMMA_MULTIPLY:
ras_ptr->gamma(agg::gamma_multiply(sym.get_gamma()));
break;
default:
ras_ptr->gamma(agg::gamma_power(sym.get_gamma()));
}
set_gamma_method(sym,ras_ptr);
//metawriter_with_properties writer = sym.get_metawriter();
box2d<double> inflated_extent = query_extent_ * 1.1;
for (unsigned i=0;i<feature->num_geometries();++i)
{
geometry_type & geom=feature->get_geometry(i);
if (geom.num_points() > 2)
{
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);
ras_ptr->add_path(path);
if (sym.smooth() > 0.0)
{
typedef agg::conv_clip_polygon<geometry_type> clipped_geometry_type;
typedef coord_transform2<CoordTransform,clipped_geometry_type> path_type;
typedef agg::conv_smooth_poly1_curve<path_type> smooth_type;
clipped_geometry_type clipped(geom);
clipped.clip_box(inflated_extent.minx(),inflated_extent.miny(),inflated_extent.maxx(),inflated_extent.maxy());
path_type path(t_,clipped,prj_trans);
smooth_type smooth(path);
smooth.smooth_value(sym.smooth());
ras_ptr->add_path(smooth);
}
else
{
typedef agg::conv_clip_polygon<geometry_type> clipped_geometry_type;
typedef coord_transform2<CoordTransform,clipped_geometry_type> 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);
ras_ptr->add_path(path);
}
//if (writer.first) writer.first->add_polygon(path, *feature, t_, writer.second);
}
}

View file

@ -53,6 +53,7 @@
// agg
#include "agg_conv_clip_polyline.h"
#include "agg_conv_clip_polygon.h"
#include "agg_conv_smooth_poly1.h"
// stl
#ifdef MAPNIK_DEBUG
@ -725,23 +726,37 @@ void cairo_renderer_base::start_map_processing(Map const& map)
proj_transform const& prj_trans)
{
typedef agg::conv_clip_polygon<geometry_type> clipped_geometry_type;
typedef coord_transform2<CoordTransform,clipped_geometry_type> path_type;
cairo_context context(context_);
context.set_color(sym.get_fill(), sym.get_opacity());
box2d<double> inflated_extent = query_extent_ * 1.1;
for (unsigned i = 0; i < feature->num_geometries(); ++i)
{
geometry_type & geom = feature->get_geometry(i);
if (geom.num_points() > 2)
{
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);
context.add_path(path);
context.fill();
if (sym.smooth() > 0.0)
{
typedef agg::conv_clip_polygon<geometry_type> clipped_geometry_type;
typedef coord_transform2<CoordTransform,clipped_geometry_type> path_type;
typedef agg::conv_smooth_poly1_curve<path_type> smooth_type;
clipped_geometry_type clipped(geom);
clipped.clip_box(inflated_extent.minx(),inflated_extent.miny(),inflated_extent.maxx(),inflated_extent.maxy());
path_type path(t_,clipped,prj_trans);
smooth_type smooth(path);
smooth.smooth_value(sym.smooth());
context.add_agg_path(smooth);
context.fill();
}
else
{
typedef agg::conv_clip_polygon<geometry_type> clipped_geometry_type;
typedef coord_transform2<CoordTransform,clipped_geometry_type> 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);
context.add_path(path);
context.fill();
}
}
}
}

View file

@ -166,6 +166,7 @@ bool color_factory::parse_from_string(color & c, std::string const& css_color,
c.set_alpha(css_.a);
return true;
}
return false;
#endif
}

View file

@ -1295,7 +1295,10 @@ void map_parser::parse_polygon_symbolizer( rule & rule, xml_node const & sym )
// gamma method
optional<gamma_method_e> gamma_method = sym.get_opt_attr<gamma_method_e>("gamma-method");
if (gamma_method) poly_sym.set_gamma_method(*gamma_method);
// smooth value
optional<double> smooth = sym.get_opt_attr<double>("smooth");
if (smooth) poly_sym.set_smooth(*smooth);
parse_metawriter_in_symbolizer(poly_sym, sym);
rule.append(poly_sym);
}

View file

@ -32,14 +32,16 @@ polygon_symbolizer::polygon_symbolizer()
fill_(color(128,128,128)),
opacity_(1.0),
gamma_(1.0),
gamma_method_(GAMMA_POWER) {}
gamma_method_(GAMMA_POWER),
smooth_(0.0) {}
polygon_symbolizer::polygon_symbolizer(color const& fill)
: symbolizer_base(),
fill_(fill),
opacity_(1.0),
gamma_(1.0),
gamma_method_(GAMMA_POWER) {}
gamma_method_(GAMMA_POWER),
smooth_(0.0) {}
color const& polygon_symbolizer::get_fill() const
{
@ -81,4 +83,14 @@ gamma_method_e polygon_symbolizer::get_gamma_method() const
return gamma_method_;
}
void polygon_symbolizer::set_smooth(double smooth)
{
smooth_ = smooth;
}
double polygon_symbolizer::smooth() const
{
return smooth_;
}
}

View file

@ -125,6 +125,10 @@ public:
{
set_attr( sym_node, "gamma-method", sym.get_gamma_method() );
}
if ( sym.smooth() != dfl.smooth() || explicit_defaults_ )
{
set_attr( sym_node, "smooth", sym.smooth() );
}
add_metawriter_attributes(sym_node, sym);
}