+ re-introduce transform on symbolizer_with_image

This commit is contained in:
Artem Pavlenko 2012-05-01 16:47:33 +01:00
parent 2e9a7d9cc8
commit 77dfac5622
13 changed files with 73 additions and 47 deletions

View file

@ -36,7 +36,7 @@ using namespace boost::python;
template <class T>
const std::string get_svg_transform(T& symbolizer)
{
return symbolizer.get_transform_string();
return symbolizer.get_image_transform_string();
}
template <class T>
@ -46,12 +46,14 @@ void set_svg_transform(T& symbolizer, std::string const& transform_wkt)
if (!mapnik::svg::parse_transform(transform_wkt.c_str(), tr))
{
std::stringstream ss;
ss << "Could not parse transform from '" << transform_wkt << "', expected string like: 'matrix(1, 0, 0, 1, 0, 0)'";
ss << "Could not parse transform from '"
<< transform_wkt
<< "', expected SVG transform attribute";
throw mapnik::value_error(ss.str());
}
mapnik::transform_type matrix;
tr.store_to(&matrix[0]);
symbolizer.set_transform(matrix);
symbolizer.set_image_transform(matrix);
}
} // end of namespace mapnik

View file

@ -121,11 +121,15 @@ public:
void set_filename(path_expression_ptr filename);
void set_opacity(float opacity);
float get_opacity() const;
void set_image_transform(transform_type const& tr);
transform_type const& get_image_transform() const;
std::string get_image_transform_string() const;
protected:
symbolizer_with_image(path_expression_ptr filename = path_expression_ptr());
symbolizer_with_image(symbolizer_with_image const& rhs);
path_expression_ptr image_filename_;
float image_opacity_;
transform_type image_transform_;
};
}

View file

@ -153,7 +153,7 @@ public:
bool next();
pixel_position get_marker_position(text_path const& p);
marker & get_marker() const;
agg::trans_affine const& get_transform() const;
agg::trans_affine const& get_image_transform() const;
protected:
bool next_point_placement();
bool next_line_placement();
@ -166,8 +166,7 @@ protected:
double marker_h_;
double marker_x_;
double marker_y_;
// F***ing templates...
// http://womble.decadent.org.uk/c++/template-faq.html#base-lookup
using text_symbolizer_helper<FaceManagerT, DetectorT>::geometries_to_process_;
using text_symbolizer_helper<FaceManagerT, DetectorT>::placement_;
using text_symbolizer_helper<FaceManagerT, DetectorT>::next_placement;

View file

@ -68,7 +68,7 @@ void agg_renderer<T>::process(markers_symbolizer const& sym,
renderer_base renb(pixf);
renderer_solid ren(renb);
agg::trans_affine tr;
boost::array<double,6> const& m = sym.get_transform();
boost::array<double,6> const& m = sym.get_image_transform();
tr.load_from(&m[0]);
tr = agg::trans_affine_scaling(scale_factor_) * tr;
std::string filename = path_processor_type::evaluate(*sym.get_filename(), *feature);

View file

@ -66,7 +66,7 @@ void agg_renderer<T>::process(point_symbolizer const& sym,
double w = (*marker)->width();
double h = (*marker)->height();
agg::trans_affine tr;
boost::array<double,6> const& m = sym.get_transform();
boost::array<double,6> const& m = sym.get_image_transform();
tr.load_from(&m[0]);
double px0 = - 0.5 * w;
double py0 = - 0.5 * h;

View file

@ -54,7 +54,7 @@ void agg_renderer<T>::process(shield_symbolizer const& sym,
{
render_marker(helper.get_marker_position(placements[ii]),
helper.get_marker(),
helper.get_transform(),
helper.get_image_transform(),
sym.get_opacity());
ren.prepare_glyphs(&(placements[ii]));

View file

@ -1062,7 +1062,7 @@ void cairo_renderer_base::start_map_processing(Map const& map)
detector_.has_placement(label_ext))
{
agg::trans_affine mtx;
boost::array<double,6> const& m = sym.get_transform();
boost::array<double,6> const& m = sym.get_image_transform();
mtx.load_from(&m[0]);
render_marker(pixel_position(px,py),**marker, mtx, sym.get_opacity());
@ -1097,7 +1097,7 @@ void cairo_renderer_base::start_map_processing(Map const& map)
{
pixel_position marker_pos = helper.get_marker_position(placements[ii]);
render_marker(marker_pos,
helper.get_marker(), helper.get_transform(),
helper.get_marker(), helper.get_image_transform(),
sym.get_opacity());
context.add_text(placements[ii], face_manager_, font_manager_);
}
@ -1266,7 +1266,7 @@ void cairo_renderer_base::start_map_processing(Map const& map)
typedef coord_transform2<CoordTransform,clipped_geometry_type> path_type;
agg::trans_affine tr;
boost::array<double,6> const& m = sym.get_transform();
boost::array<double,6> const& m = sym.get_image_transform();
tr.load_from(&m[0]);
// TODO - use this?
//tr = agg::trans_affine_scaling(scale_factor_) * tr;

View file

@ -69,7 +69,7 @@ void grid_renderer<T>::process(markers_symbolizer const& sym,
ras_ptr->reset();
agg::trans_affine tr;
boost::array<double,6> const& m = sym.get_transform();
boost::array<double,6> const& m = sym.get_image_transform();
tr.load_from(&m[0]);
tr = agg::trans_affine_scaling(scale_factor_*(1.0/pixmap_.get_resolution())) * tr;
std::string filename = path_processor_type::evaluate(*sym.get_filename(), *feature);

View file

@ -79,7 +79,7 @@ void grid_renderer<T>::process(point_symbolizer const& sym,
detector_.has_placement(label_ext))
{
agg::trans_affine tr;
boost::array<double,6> const& m = sym.get_transform();
boost::array<double,6> const& m = sym.get_image_transform();
tr.load_from(&m[0]);
render_marker(feature, pixmap_.get_resolution(),

View file

@ -61,7 +61,7 @@ void grid_renderer<T>::process(shield_symbolizer const& sym,
{
render_marker(feature, pixmap_.get_resolution(),
helper.get_marker_position(placements[ii]),
helper.get_marker(), helper.get_transform(),
helper.get_marker(), helper.get_image_transform(),
sym.get_opacity());
ren.prepare_glyphs(&(placements[ii]));

View file

@ -842,7 +842,7 @@ void map_parser::parse_metawriter_in_symbolizer(symbolizer_base &sym, xml_node c
if (!mapnik::svg::parse_transform((*transform_wkt).c_str(),tr))
{
std::stringstream ss;
ss << "Could not parse transform from '" << transform_wkt << "', expected string like: 'matrix(1, 0, 0, 1, 0, 0)'";
ss << "Could not parse transform from '" << transform_wkt << "', expected SVG transform attribute";
if (strict_)
throw config_error(ss.str()); // value_error here?
else
@ -872,8 +872,6 @@ void map_parser::parse_point_symbolizer(rule & rule, xml_node const & sym)
optional<boolean> ignore_placement = sym.get_opt_attr<boolean>("ignore-placement");
optional<float> opacity = sym.get_opt_attr<float>("opacity");
//optional<std::string> transform_wkt = sym.get_opt_attr<std::string>("transform");
point_symbolizer symbol;
if (allow_overlap)
{
@ -914,15 +912,15 @@ void map_parser::parse_point_symbolizer(rule & rule, xml_node const & sym)
symbol.set_filename(expr);
#if 0
if (transform_wkt)
optional<std::string> image_transform_wkt = sym.get_opt_attr<std::string>("image-transform");
if (image_transform_wkt)
{
agg::trans_affine tr;
if (!mapnik::svg::parse_transform((*transform_wkt).c_str(),tr))
if (!mapnik::svg::parse_transform((*image_transform_wkt).c_str(),tr))
{
std::stringstream ss;
ss << "Could not parse transform from '" << transform_wkt
<< "', expected string like: 'matrix(1, 0, 0, 1, 0, 0)'";
ss << "Could not parse transform from '" << *image_transform_wkt
<< "', expected SVG transform attribute";
if (strict_)
{
throw config_error(ss.str()); // value_error here?
@ -936,8 +934,6 @@ void map_parser::parse_point_symbolizer(rule & rule, xml_node const & sym)
tr.store_to(&matrix[0]);
symbol.set_transform(matrix);
}
#endif
}
catch (image_reader_exception const & ex)
{
@ -971,7 +967,6 @@ void map_parser::parse_markers_symbolizer(rule & rule, xml_node const& sym)
std::string filename("");
optional<std::string> file = sym.get_opt_attr<std::string>("file");
optional<std::string> base = sym.get_opt_attr<std::string>("base");
//optional<std::string> transform_wkt = sym.get_opt_attr<std::string>("transform");
if (file)
{
@ -1011,15 +1006,16 @@ void map_parser::parse_markers_symbolizer(rule & rule, xml_node const& sym)
optional<float> opacity = sym.get_opt_attr<float>("opacity");
if (opacity) symbol.set_opacity(*opacity);
#if 0
if (transform_wkt)
optional<std::string> image_transform_wkt = sym.get_opt_attr<std::string>("image-transform");
if (image_transform_wkt)
{
agg::trans_affine tr;
if (!mapnik::svg::parse_transform((*transform_wkt).c_str(),tr))
if (!mapnik::svg::parse_transform((*image_transform_wkt).c_str(),tr))
{
std::stringstream ss;
ss << "Could not parse transform from '" << transform_wkt
<< "', expected string like: 'matrix(1, 0, 0, 1, 0, 0)'";
ss << "Could not parse transform from '" << *image_transform_wkt
<< "', expected SVG transform attribute";
if (strict_)
{
throw config_error(ss.str()); // value_error here?
@ -1033,8 +1029,7 @@ void map_parser::parse_markers_symbolizer(rule & rule, xml_node const& sym)
tr.store_to(&matrix[0]);
symbol.set_transform(matrix);
}
#endif
optional<color> c = sym.get_opt_attr<color>("fill");
if (c) symbol.set_fill(*c);
optional<double> spacing = sym.get_opt_attr<double>("spacing");
@ -1256,16 +1251,16 @@ void map_parser::parse_shield_symbolizer(rule & rule, xml_node const& sym)
}
shield_symbolizer shield_symbol = shield_symbolizer(placement_finder);
/* Symbolizer specific attributes. */
#if 0
optional<std::string> transform_wkt = sym.get_opt_attr<std::string>("transform");
if (transform_wkt)
optional<std::string> image_transform_wkt = sym.get_opt_attr<std::string>("image-transform");
if (image_transform_wkt)
{
agg::trans_affine tr;
if (!mapnik::svg::parse_transform((*transform_wkt).c_str(),tr))
if (!mapnik::svg::parse_transform((*image_transform_wkt).c_str(),tr))
{
std::stringstream ss;
ss << "Could not parse transform from '" << transform_wkt << "', expected string like: 'matrix(1, 0, 0, 1, 0, 0)'";
ss << "Could not parse transform from '" << *image_transform_wkt
<< "', expected SVG transform attribute";
if (strict_)
{
throw config_error(ss.str()); // value_error here?
@ -1277,10 +1272,9 @@ void map_parser::parse_shield_symbolizer(rule & rule, xml_node const& sym)
}
boost::array<double,6> matrix;
tr.store_to(&matrix[0]);
shield_symbol.set_transform(matrix);
shield_symbol.set_image_transform(matrix);
}
#endif
// shield displacement
double shield_dx = sym.get_attr("shield-dx", 0.0);
double shield_dy = sym.get_attr("shield-dy", 0.0);

View file

@ -113,14 +113,22 @@ bool symbolizer_base::clip() const
symbolizer_with_image::symbolizer_with_image(path_expression_ptr file)
: image_filename_( file ),
image_opacity_(1.0f)
image_opacity_(1.0f)
{
image_transform_[0] = 1.0;
image_transform_[1] = 0.0;
image_transform_[2] = 0.0;
image_transform_[3] = 1.0;
image_transform_[4] = 0.0;
image_transform_[5] = 0.0;
}
symbolizer_with_image::symbolizer_with_image( symbolizer_with_image const& rhs)
: image_filename_(rhs.image_filename_),
image_opacity_(rhs.image_opacity_) {}
image_opacity_(rhs.image_opacity_),
image_transform_(rhs.image_transform_)
{
}
path_expression_ptr symbolizer_with_image::get_filename() const
{
@ -142,6 +150,25 @@ float symbolizer_with_image::get_opacity() const
return image_opacity_;
}
void symbolizer_with_image::set_image_transform(transform_type const& tr)
{
image_transform_ = tr;
}
transform_type const& symbolizer_with_image::get_image_transform() const
{
return image_transform_;
}
std::string symbolizer_with_image::get_image_transform_string() const
{
std::stringstream ss;
ss << "matrix(" << image_transform_[0] << ", " << image_transform_[1] << ", "
<< image_transform_[2] << ", " << image_transform_[3] << ", "
<< image_transform_[4] << ", " << image_transform_[5] << ")";
return ss.str();
}
} // end of namespace mapnik

View file

@ -350,7 +350,7 @@ template <typename FaceManagerT, typename DetectorT>
void shield_symbolizer_helper<FaceManagerT, DetectorT>::init_marker()
{
std::string filename = path_processor_type::evaluate(*sym_.get_filename(), this->feature_);
boost::array<double,6> const& m = sym_.get_transform();
boost::array<double,6> const& m = sym_.get_image_transform();
transform_.load_from(&m[0]);
marker_.reset();
if (!filename.empty())
@ -410,7 +410,7 @@ marker& shield_symbolizer_helper<FaceManagerT, DetectorT>::get_marker() const
}
template <typename FaceManagerT, typename DetectorT>
agg::trans_affine const& shield_symbolizer_helper<FaceManagerT, DetectorT>::get_transform() const
agg::trans_affine const& shield_symbolizer_helper<FaceManagerT, DetectorT>::get_image_transform() const
{
return transform_;
}