support scale_factor in geometry-transform translate and scale - refs #1926

This commit is contained in:
Dane Springmeyer 2014-02-27 11:55:58 -08:00
parent aec32f88f7
commit e49f63730e
14 changed files with 34 additions and 29 deletions

View file

@ -50,7 +50,7 @@ typedef transform_list_ptr transform_type;
class feature_impl; class feature_impl;
MAPNIK_DECL void evaluate_transform(agg::trans_affine& tr, feature_impl const& feature, MAPNIK_DECL void evaluate_transform(agg::trans_affine& tr, feature_impl const& feature,
transform_type const& trans_expr); transform_type const& trans_expr, double scale_factor=1.0);
class MAPNIK_DECL symbolizer_base class MAPNIK_DECL symbolizer_base
{ {

View file

@ -107,8 +107,12 @@ struct transform_processor
struct node_evaluator : boost::static_visitor<void> struct node_evaluator : boost::static_visitor<void>
{ {
node_evaluator(transform_type& tr, feature_type const& feat) node_evaluator(transform_type& tr,
: transform_(tr), feature_(feat) {} feature_type const& feat,
double scale_factor)
: transform_(tr),
feature_(feat),
scale_factor_(scale_factor) {}
void operator() (identity_node const& node) void operator() (identity_node const& node)
{ {
@ -117,26 +121,26 @@ struct transform_processor
void operator() (matrix_node const& node) void operator() (matrix_node const& node)
{ {
double a = eval(node.a_); double a = eval(node.a_) * scale_factor_; // scale x;
double b = eval(node.b_); double b = eval(node.b_);
double c = eval(node.c_); double c = eval(node.c_);
double d = eval(node.d_); double d = eval(node.d_) * scale_factor_; // scale y;
double e = eval(node.e_); double e = eval(node.e_) * scale_factor_; // translate x
double f = eval(node.f_); double f = eval(node.f_) * scale_factor_; // translate y
transform_.multiply(agg::trans_affine(a, b, c, d, e, f)); transform_.multiply(agg::trans_affine(a, b, c, d, e, f));
} }
void operator() (translate_node const& node) void operator() (translate_node const& node)
{ {
double tx = eval(node.tx_); double tx = eval(node.tx_) * scale_factor_;
double ty = eval(node.ty_, 0.0); double ty = eval(node.ty_, 0.0) * scale_factor_;
transform_.translate(tx, ty); transform_.translate(tx, ty);
} }
void operator() (scale_node const& node) void operator() (scale_node const& node)
{ {
double sx = eval(node.sx_); double sx = eval(node.sx_) * scale_factor_;
double sy = eval(node.sy_, sx); double sy = eval(node.sy_, sx) * scale_factor_;
transform_.scale(sx, sy); transform_.scale(sx, sy);
} }
@ -172,7 +176,7 @@ struct transform_processor
double eval(expr_node const& x) const double eval(expr_node const& x) const
{ {
mapnik::evaluate<feature_type, value_type> e(feature_); mapnik::evaluate<feature_type, value_type> e(feature_);
return boost::apply_visitor(e, x).to_double(); return boost::apply_visitor(e, x).to_double() * scale_factor_;
} }
double eval(expr_node const& x, double def) const double eval(expr_node const& x, double def) const
@ -182,6 +186,7 @@ struct transform_processor
transform_type& transform_; transform_type& transform_;
feature_type const& feature_; feature_type const& feature_;
double scale_factor_;
}; };
template <typename Container> template <typename Container>
@ -197,9 +202,9 @@ struct transform_processor
} }
static void evaluate(transform_type& tr, feature_type const& feat, static void evaluate(transform_type& tr, feature_type const& feat,
transform_list const& list) transform_list const& list, double scale_factor)
{ {
node_evaluator eval(tr, feat); node_evaluator eval(tr, feat, scale_factor);
#ifdef MAPNIK_LOG #ifdef MAPNIK_LOG
MAPNIK_LOG_DEBUG(transform) << "transform: begin with " << to_string(matrix_node(tr)); MAPNIK_LOG_DEBUG(transform) << "transform: begin with " << to_string(matrix_node(tr));

View file

@ -125,7 +125,7 @@ void agg_renderer<T>::process(line_pattern_symbolizer const& sym,
rasterizer_type ras(ren); rasterizer_type ras(ren);
agg::trans_affine tr; agg::trans_affine tr;
evaluate_transform(tr, feature, sym.get_transform()); evaluate_transform(tr, feature, sym.get_transform(), scale_factor_);
box2d<double> clip_box = clipping_extent(); box2d<double> clip_box = clipping_extent();
if (sym.clip()) if (sym.clip())

View file

@ -90,7 +90,7 @@ void agg_renderer<T>::process(line_symbolizer const& sym,
renderer_base renb(pixf); renderer_base renb(pixf);
agg::trans_affine tr; agg::trans_affine tr;
evaluate_transform(tr, feature, sym.get_transform()); evaluate_transform(tr, feature, sym.get_transform(), scale_factor_);
box2d<double> clip_box = clipping_extent(); box2d<double> clip_box = clipping_extent();
if (sym.clip()) if (sym.clip())

View file

@ -146,7 +146,7 @@ void agg_renderer<T>::process(polygon_pattern_symbolizer const& sym,
renderer_type rp(renb,sa, sg, unsigned(sym.get_opacity()*255)); renderer_type rp(renb,sa, sg, unsigned(sym.get_opacity()*255));
agg::trans_affine tr; agg::trans_affine tr;
evaluate_transform(tr, feature, sym.get_transform()); evaluate_transform(tr, feature, sym.get_transform(), scale_factor_);
typedef boost::mpl::vector<clip_poly_tag,transform_tag,affine_transform_tag,simplify_tag,smooth_tag> conv_types; typedef boost::mpl::vector<clip_poly_tag,transform_tag,affine_transform_tag,simplify_tag,smooth_tag> conv_types;
vertex_converter<box2d<double>, rasterizer, polygon_pattern_symbolizer, vertex_converter<box2d<double>, rasterizer, polygon_pattern_symbolizer,

View file

@ -57,7 +57,7 @@ void agg_renderer<T>::process(polygon_symbolizer const& sym,
gamma_ = sym.get_gamma(); gamma_ = sym.get_gamma();
} }
agg::trans_affine tr; agg::trans_affine tr;
evaluate_transform(tr, feature, sym.get_transform()); evaluate_transform(tr, feature, sym.get_transform(), scale_factor_);
box2d<double> clip_box = clipping_extent(); box2d<double> clip_box = clipping_extent();
typedef boost::mpl::vector<clip_poly_tag,transform_tag,affine_transform_tag,simplify_tag,smooth_tag> conv_types; typedef boost::mpl::vector<clip_poly_tag,transform_tag,affine_transform_tag,simplify_tag,smooth_tag> conv_types;
vertex_converter<box2d<double>, rasterizer, polygon_symbolizer, vertex_converter<box2d<double>, rasterizer, polygon_symbolizer,

View file

@ -315,7 +315,7 @@ void cairo_renderer_base::process(polygon_symbolizer const& sym,
context_.set_color(sym.get_fill(), sym.get_opacity()); context_.set_color(sym.get_fill(), sym.get_opacity());
agg::trans_affine tr; agg::trans_affine tr;
evaluate_transform(tr, feature, sym.get_transform()); evaluate_transform(tr, feature, sym.get_transform(), scale_factor_);
typedef boost::mpl::vector<clip_poly_tag,transform_tag,affine_transform_tag,simplify_tag,smooth_tag> conv_types; typedef boost::mpl::vector<clip_poly_tag,transform_tag,affine_transform_tag,simplify_tag,smooth_tag> conv_types;
vertex_converter<box2d<double>, cairo_context, polygon_symbolizer, vertex_converter<box2d<double>, cairo_context, polygon_symbolizer,
@ -466,7 +466,7 @@ void cairo_renderer_base::process(line_symbolizer const& sym,
} }
agg::trans_affine tr; agg::trans_affine tr;
evaluate_transform(tr, feature, sym.get_transform()); evaluate_transform(tr, feature, sym.get_transform(), scale_factor_);
box2d<double> clipping_extent = query_extent_; box2d<double> clipping_extent = query_extent_;
if (sym.clip()) if (sym.clip())
@ -853,7 +853,7 @@ void cairo_renderer_base::process(polygon_pattern_symbolizer const& sym,
//} //}
agg::trans_affine tr; agg::trans_affine tr;
evaluate_transform(tr, feature, sym.get_transform()); evaluate_transform(tr, feature, sym.get_transform(), scale_factor_);
typedef boost::mpl::vector<clip_poly_tag,transform_tag,affine_transform_tag,simplify_tag,smooth_tag> conv_types; typedef boost::mpl::vector<clip_poly_tag,transform_tag,affine_transform_tag,simplify_tag,smooth_tag> conv_types;
vertex_converter<box2d<double>, cairo_context, polygon_pattern_symbolizer, vertex_converter<box2d<double>, cairo_context, polygon_pattern_symbolizer,
@ -1161,7 +1161,7 @@ void cairo_renderer_base::process(markers_symbolizer const& sym,
if (mark && *mark) if (mark && *mark)
{ {
agg::trans_affine geom_tr; agg::trans_affine geom_tr;
evaluate_transform(geom_tr, feature, sym.get_transform()); evaluate_transform(geom_tr, feature, sym.get_transform(), scale_factor_);
box2d<double> const& bbox = (*mark)->bounding_box(); box2d<double> const& bbox = (*mark)->bounding_box();
setup_transform_scaling(tr, bbox.width(), bbox.height(), feature, sym); setup_transform_scaling(tr, bbox.width(), bbox.height(), feature, sym);
evaluate_transform(tr, feature, sym.get_image_transform()); evaluate_transform(tr, feature, sym.get_image_transform());

View file

@ -83,7 +83,7 @@ void grid_renderer<T>::process(line_pattern_symbolizer const& sym,
int stroke_width = (*pat)->width(); int stroke_width = (*pat)->width();
agg::trans_affine tr; agg::trans_affine tr;
evaluate_transform(tr, feature, sym.get_transform()); evaluate_transform(tr, feature, sym.get_transform(), scale_factor_);
box2d<double> clipping_extent = query_extent_; box2d<double> clipping_extent = query_extent_;
if (sym.clip()) if (sym.clip())

View file

@ -69,7 +69,7 @@ void grid_renderer<T>::process(line_symbolizer const& sym,
stroke const& stroke_ = sym.get_stroke(); stroke const& stroke_ = sym.get_stroke();
agg::trans_affine tr; agg::trans_affine tr;
evaluate_transform(tr, feature, sym.get_transform()); evaluate_transform(tr, feature, sym.get_transform(), scale_factor_);
box2d<double> clipping_extent = query_extent_; box2d<double> clipping_extent = query_extent_;
if (sym.clip()) if (sym.clip())

View file

@ -96,7 +96,7 @@ void grid_renderer<T>::process(markers_symbolizer const& sym,
{ {
ras_ptr->reset(); ras_ptr->reset();
agg::trans_affine geom_tr; agg::trans_affine geom_tr;
evaluate_transform(geom_tr, feature, sym.get_transform()); evaluate_transform(geom_tr, feature, sym.get_transform(), scale_factor_);
agg::trans_affine tr = agg::trans_affine_scaling(scale_factor_*(1.0/pixmap_.get_resolution())); agg::trans_affine tr = agg::trans_affine_scaling(scale_factor_*(1.0/pixmap_.get_resolution()));
if ((*mark)->is_vector()) if ((*mark)->is_vector())

View file

@ -68,7 +68,7 @@ void grid_renderer<T>::process(polygon_pattern_symbolizer const& sym,
ras_ptr->reset(); ras_ptr->reset();
agg::trans_affine tr; agg::trans_affine tr;
evaluate_transform(tr, feature, sym.get_transform()); evaluate_transform(tr, feature, sym.get_transform(), scale_factor_);
typedef boost::mpl::vector<clip_poly_tag,transform_tag,affine_transform_tag,smooth_tag> conv_types; typedef boost::mpl::vector<clip_poly_tag,transform_tag,affine_transform_tag,smooth_tag> conv_types;
vertex_converter<box2d<double>, grid_rasterizer, polygon_pattern_symbolizer, vertex_converter<box2d<double>, grid_rasterizer, polygon_pattern_symbolizer,

View file

@ -55,7 +55,7 @@ void grid_renderer<T>::process(polygon_symbolizer const& sym,
ras_ptr->reset(); ras_ptr->reset();
agg::trans_affine tr; agg::trans_affine tr;
evaluate_transform(tr, feature, sym.get_transform()); evaluate_transform(tr, feature, sym.get_transform(), scale_factor_);
typedef boost::mpl::vector<clip_poly_tag,transform_tag,affine_transform_tag,simplify_tag,smooth_tag> conv_types; typedef boost::mpl::vector<clip_poly_tag,transform_tag,affine_transform_tag,simplify_tag,smooth_tag> conv_types;
vertex_converter<box2d<double>, grid_rasterizer, polygon_symbolizer, vertex_converter<box2d<double>, grid_rasterizer, polygon_symbolizer,

View file

@ -29,7 +29,7 @@
namespace mapnik { namespace mapnik {
void evaluate_transform(agg::trans_affine& tr, feature_impl const& feature, void evaluate_transform(agg::trans_affine& tr, feature_impl const& feature,
transform_list_ptr const& trans_expr) transform_list_ptr const& trans_expr, double scale_factor)
{ {
if (trans_expr) if (trans_expr)
{ {
@ -37,7 +37,7 @@ void evaluate_transform(agg::trans_affine& tr, feature_impl const& feature,
MAPNIK_LOG_DEBUG(transform) << "transform: evaluate " MAPNIK_LOG_DEBUG(transform) << "transform: evaluate "
<< transform_processor_type::to_string(*trans_expr); << transform_processor_type::to_string(*trans_expr);
#endif #endif
transform_processor_type::evaluate(tr, feature, *trans_expr); transform_processor_type::evaluate(tr, feature, *trans_expr, scale_factor);
} }
} }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB