Permalink
Browse files

Merge branch 'transform_expr' of https://github.com/mirecta/mapnik

  • Loading branch information...
2 parents f374d01 + bd9609c commit 11c34b15994dd3367e9ce7edd4129f6c78e676d9 @artemp artemp committed Jun 7, 2012
Showing with 1,203 additions and 187 deletions.
  1. +7 −3 bindings/python/mapnik_svg.hpp
  2. +5 −4 deps/agg/include/agg_trans_affine.h
  3. +1 −0 deps/agg/src/agg_trans_affine.cpp
  4. +7 −0 include/mapnik/agg_renderer.hpp
  5. +34 −14 include/mapnik/attribute_collector.hpp
  6. +14 −3 include/mapnik/box2d.hpp
  7. +1 −15 include/mapnik/feature_kv_iterator.hpp
  8. +15 −0 include/mapnik/marker.hpp
  9. +243 −0 include/mapnik/parse_transform.hpp
  10. +5 −1 include/mapnik/symbolizer.hpp
  11. +15 −0 include/mapnik/symbolizer_helpers.hpp
  12. +181 −0 include/mapnik/transform_expression.hpp
  13. +121 −0 include/mapnik/transform_expression_grammar.hpp
  14. +69 −2 include/mapnik/value.hpp
  15. +19 −19 include/mapnik/vertex_converters.hpp
  16. +2 −0 include/mapnik/xml_tree.hpp
  17. +57 −3 src/agg/agg_renderer.cpp
  18. +6 −2 src/agg/process_line_pattern_symbolizer.cpp
  19. +9 −4 src/agg/process_line_symbolizer.cpp
  20. +27 −15 src/agg/process_markers_symbolizer.cpp
  21. +13 −20 src/agg/process_point_symbolizer.cpp
  22. +6 −2 src/agg/process_polygon_pattern_symbolizer.cpp
  23. +6 −2 src/agg/process_polygon_symbolizer.cpp
  24. +9 −1 src/agg/process_shield_symbolizer.cpp
  25. +42 −0 src/box2d.cpp
  26. +2 −0 src/build.py
  27. +22 −12 src/cairo_renderer.cpp
  28. +1 −2 src/grid/process_markers_symbolizer.cpp
  29. +3 −4 src/grid/process_point_symbolizer.cpp
  30. +13 −20 src/load_map.cpp
  31. +46 −0 src/parse_transform.cpp
  32. +16 −14 src/save_map.cpp
  33. +39 −22 src/symbolizer.cpp
  34. +1 −2 src/symbolizer_helpers.cpp
  35. +144 −0 src/transform_expression.cpp
  36. +2 −1 src/xml_tree.cpp
@@ -23,10 +23,14 @@
#define MAPNIK_PYTHON_BINDING_SVG_INCLUDED
// mapnik
+#include <mapnik/parse_transform.hpp>
#include <mapnik/symbolizer.hpp>
#include <mapnik/svg/svg_path_parser.hpp>
#include <mapnik/value_error.hpp>
+// boost
+#include <boost/make_shared.hpp>
+
// agg
#include "agg_trans_affine.h"
@@ -51,9 +55,9 @@ void set_svg_transform(T& symbolizer, std::string const& transform_wkt)
<< "', expected SVG transform attribute";
throw mapnik::value_error(ss.str());
}
- mapnik::transform_type matrix;
- tr.store_to(&matrix[0]);
- symbolizer.set_image_transform(matrix);
+ transform_list_ptr trans = boost::make_shared<transform_list>();
+ trans->push_back(matrix_node(tr));
+ symbolizer.set_image_transform(trans);
}
} // end of namespace mapnik
@@ -86,6 +86,7 @@ namespace agg
//----------------------------------------------------------------------
struct trans_affine
{
+ static const trans_affine identity;
double sx, shy, shx, sy, tx, ty;
//------------------------------------------ Construction
@@ -210,15 +211,15 @@ namespace agg
}
// Multiply the matrix by another one and return
- // the result in a separete matrix.
- trans_affine operator * (const trans_affine& m)
+ // the result in a separate matrix.
+ trans_affine operator * (const trans_affine& m) const
{
return trans_affine(*this).multiply(m);
}
// Multiply the matrix by inverse of another one
- // and return the result in a separete matrix.
- trans_affine operator / (const trans_affine& m)
+ // and return the result in a separate matrix.
+ trans_affine operator / (const trans_affine& m) const
{
return trans_affine(*this).multiply_inv(m);
}
@@ -22,6 +22,7 @@
namespace agg
{
+ const trans_affine trans_affine::identity;
//------------------------------------------------------------------------
const trans_affine& trans_affine::parl_to_parl(const double* src,
@@ -115,6 +115,13 @@ class MAPNIK_DECL agg_renderer : public feature_style_processor<agg_renderer<T>
void painted(bool painted);
+protected:
+ template <typename R>
+ void debug_draw_box(R& buf, box2d<double> const& extent,
+ double x, double y, double angle = 0.0);
+ void debug_draw_box(box2d<double> const& extent,
+ double x, double y, double angle = 0.0);
+
private:
buffer_type & pixmap_;
boost::shared_ptr<buffer_type> internal_buffer_;
@@ -25,6 +25,7 @@
// mapnik
#include <mapnik/rule.hpp>
+#include <mapnik/parse_transform.hpp>
// boost
#include <boost/utility.hpp>
#include <boost/variant.hpp>
@@ -35,9 +36,10 @@
namespace mapnik {
+template <typename Container>
struct expression_attributes : boost::static_visitor<void>
{
- explicit expression_attributes(std::set<std::string> & names)
+ explicit expression_attributes(Container& names)
: names_(names) {}
void operator() (value_type const& x) const
@@ -53,35 +55,35 @@ struct expression_attributes : boost::static_visitor<void>
template <typename Tag>
void operator() (binary_node<Tag> const& x) const
{
- boost::apply_visitor(expression_attributes(names_),x.left);
- boost::apply_visitor(expression_attributes(names_),x.right);
+ boost::apply_visitor(*this, x.left);
+ boost::apply_visitor(*this, x.right);
}
template <typename Tag>
void operator() (unary_node<Tag> const& x) const
{
- boost::apply_visitor(expression_attributes(names_),x.expr);
+ boost::apply_visitor(*this, x.expr);
}
void operator() (regex_match_node const& x) const
{
- boost::apply_visitor(expression_attributes(names_),x.expr);
+ boost::apply_visitor(*this, x.expr);
}
void operator() (regex_replace_node const& x) const
{
- boost::apply_visitor(expression_attributes(names_),x.expr);
+ boost::apply_visitor(*this, x.expr);
}
private:
- std::set<std::string>& names_;
+ Container& names_;
};
struct symbolizer_attributes : public boost::static_visitor<>
{
symbolizer_attributes(std::set<std::string>& names)
- : names_(names) {}
+ : names_(names), f_attr(names) {}
template <typename T>
void operator () (T const&) const {}
@@ -91,12 +93,12 @@ struct symbolizer_attributes : public boost::static_visitor<>
expression_set::const_iterator it;
expression_set expressions;
sym.get_placement_options()->add_expressions(expressions);
- expression_attributes f_attr(names_);
for (it=expressions.begin(); it != expressions.end(); it++)
{
if (*it) boost::apply_visitor(f_attr, **it);
}
collect_metawriter(sym);
+ collect_transform(sym.get_transform());
}
void operator () (point_symbolizer const& sym)
@@ -107,12 +109,14 @@ struct symbolizer_attributes : public boost::static_visitor<>
path_processor_type::collect_attributes(*filename_expr,names_);
}
collect_metawriter(sym);
-
+ collect_transform(sym.get_image_transform());
+ collect_transform(sym.get_transform());
}
void operator () (line_symbolizer const& sym)
{
collect_metawriter(sym);
+ collect_transform(sym.get_transform());
}
void operator () (line_pattern_symbolizer const& sym)
@@ -123,11 +127,14 @@ struct symbolizer_attributes : public boost::static_visitor<>
path_processor_type::collect_attributes(*filename_expr,names_);
}
collect_metawriter(sym);
+ collect_transform(sym.get_image_transform());
+ collect_transform(sym.get_transform());
}
void operator () (polygon_symbolizer const& sym)
{
collect_metawriter(sym);
+ collect_transform(sym.get_transform());
}
void operator () (polygon_pattern_symbolizer const& sym)
@@ -138,14 +145,15 @@ struct symbolizer_attributes : public boost::static_visitor<>
path_processor_type::collect_attributes(*filename_expr,names_);
}
collect_metawriter(sym);
+ collect_transform(sym.get_image_transform());
+ collect_transform(sym.get_transform());
}
void operator () (shield_symbolizer const& sym)
{
expression_set::const_iterator it;
expression_set expressions;
sym.get_placement_options()->add_expressions(expressions);
- expression_attributes f_attr(names_);
for (it=expressions.begin(); it != expressions.end(); it++)
{
if (*it) boost::apply_visitor(f_attr, **it);
@@ -157,43 +165,56 @@ struct symbolizer_attributes : public boost::static_visitor<>
path_processor_type::collect_attributes(*filename_expr,names_);
}
collect_metawriter(sym);
+ collect_transform(sym.get_image_transform());
+ collect_transform(sym.get_transform());
}
void operator () (markers_symbolizer const& sym)
{
collect_metawriter(sym);
+ collect_transform(sym.get_image_transform());
+ collect_transform(sym.get_transform());
}
void operator () (building_symbolizer const& sym)
{
expression_ptr const& height_expr = sym.height();
if (height_expr)
{
- expression_attributes f_attr(names_);
boost::apply_visitor(f_attr,*height_expr);
}
collect_metawriter(sym);
+ collect_transform(sym.get_transform());
}
// TODO - support remaining syms
private:
std::set<std::string>& names_;
+ expression_attributes<std::set<std::string> > f_attr;
void collect_metawriter(symbolizer_base const& sym)
{
metawriter_properties const& properties = sym.get_metawriter_properties();
names_.insert(properties.begin(), properties.end());
}
+ void collect_transform(transform_list_ptr const& trans_expr)
+ {
+ if (trans_expr)
+ {
+ transform_processor_type::collect_attributes(names_, *trans_expr);
+ }
+ }
};
class attribute_collector : public boost::noncopyable
{
private:
std::set<std::string>& names_;
+ expression_attributes<std::set<std::string> > f_attr;
public:
attribute_collector(std::set<std::string>& names)
- : names_(names) {}
+ : names_(names), f_attr(names) {}
template <typename RuleType>
void operator() (RuleType const& r)
@@ -207,7 +228,6 @@ class attribute_collector : public boost::noncopyable
}
expression_ptr const& expr = r.get_filter();
- expression_attributes f_attr(names_);
boost::apply_visitor(f_attr,*expr);
}
};
@@ -33,6 +33,12 @@
// stl
#include <iomanip>
+// agg
+// forward declare so that apps using mapnik do not need agg headers
+namespace agg {
+struct trans_affine;
+}
+
namespace mapnik {
/*!
@@ -56,6 +62,7 @@ template <typename T> class MAPNIK_DECL box2d
box2d(T minx,T miny,T maxx,T maxy);
box2d(const coord<T,2>& c0,const coord<T,2>& c1);
box2d(const box2d_type& rhs);
+ box2d(const box2d_type& rhs, const agg::trans_affine& tr);
T minx() const;
T miny() const;
T maxx() const;
@@ -88,6 +95,10 @@ template <typename T> class MAPNIK_DECL box2d
box2d_type& operator*=(T);
box2d_type& operator/=(T);
T operator[](int index) const;
+
+ // compute the bounding box of this one transformed
+ box2d_type operator* (agg::trans_affine const& tr) const;
+ box2d_type& operator*=(agg::trans_affine const& tr);
};
template <class charT,class traits,class T>
@@ -98,9 +109,9 @@ operator << (std::basic_ostream<charT,traits>& out,
std::basic_ostringstream<charT,traits> s;
s.copyfmt(out);
s.width(0);
- s <<"box2d(" << std::setprecision(16)
- << e.minx() << "," << e.miny() <<","
- << e.maxx() << "," << e.maxy() <<")";
+ s << "box2d(" << std::setprecision(16)
+ << e.minx() << ',' << e.miny() << ','
+ << e.maxx() << ',' << e.maxy() << ')';
out << s.str();
return out;
}
@@ -64,25 +64,11 @@ class MAPNIK_DECL feature_kv_iterator :
};
-struct is_null : public boost::static_visitor<bool>
-{
- bool operator() (value_null const& val) const
- {
- return true;
- }
-
- template <typename T>
- bool operator() (T val) const
- {
- return false;
- }
-};
-
struct value_not_null
{
bool operator() (feature_kv_iterator::value_type const& kv) const
{
- return !boost::apply_visitor(is_null(),boost::get<1>(kv).base());
+ return !boost::apply_visitor(is_null, boost::get<1>(kv).base());
}
};
@@ -79,6 +79,21 @@ class marker
{
}
+ box2d<double> bounding_box() const
+ {
+ if (is_vector())
+ {
+ return (*vector_data_)->bounding_box();
+ }
+ if (is_bitmap())
+ {
+ double width = (*bitmap_data_)->width();
+ double height = (*bitmap_data_)->height();
+ return box2d<double>(0, 0, width, height);
+ }
+ return box2d<double>();
+ }
+
inline double width() const
{
if (is_bitmap())
Oops, something went wrong. Retry.

0 comments on commit 11c34b1

Please sign in to comment.