implement vertex interface in vertex_adapter and make mapnik::geometry_type immutable

This commit is contained in:
artemp 2015-02-06 16:45:51 +01:00
parent 187a42f006
commit e19fdad3a6
46 changed files with 410 additions and 203 deletions

View file

@ -102,20 +102,21 @@ std::shared_ptr<mapnik::geometry_container> from_geojson_impl(std::string const&
return paths;
}
mapnik::box2d<double> envelope_impl(mapnik::geometry_container & p)
mapnik::box2d<double> envelope_impl2(mapnik::geometry_container & p)
{
mapnik::box2d<double> b;
bool first = true;
for (mapnik::geometry_type const& geom : p)
{
auto bbox = ::mapnik::envelope(geom);
if (first)
{
b = geom.envelope();
b = bbox;
first=false;
}
else
{
b.expand_to_include(geom.envelope());
b.expand_to_include(bbox);
}
}
return b;
@ -211,13 +212,17 @@ std::string to_geojson2(mapnik::geometry_container const& geom)
std::string to_svg(mapnik::geometry_type const& geom)
{
std::string svg;
if (!mapnik::util::to_svg(svg,geom))
if (!mapnik::util::to_svg(svg, geom))
{
throw std::runtime_error("Generate SVG failed");
}
return svg;
}
mapnik::box2d<double> envelope_impl(mapnik::geometry_type const& geom)
{
return ::mapnik::envelope(geom);
}
/*
// https://github.com/mapnik/mapnik/issues/1437
std::string to_svg2( mapnik::geometry_container const& geom)
@ -249,7 +254,7 @@ void export_geometry()
using mapnik::geometry_type;
class_<mapnik::geometry_type, std::shared_ptr<mapnik::geometry_type>, boost::noncopyable>("Geometry2d",no_init)
.def("envelope",&mapnik::geometry_type::envelope)
.def("envelope",&envelope_impl)
// .def("__str__",&mapnik::geometry_type::to_string)
.def("type",&mapnik::geometry_type::type)
.def("to_wkb",&to_wkb)
@ -262,7 +267,7 @@ void export_geometry()
class_<mapnik::geometry_container, std::shared_ptr<mapnik::geometry_container>, boost::noncopyable>("Path")
.def("__getitem__", getitem_impl,return_value_policy<reference_existing_object>())
.def("__len__", &mapnik::geometry_container::size)
.def("envelope",envelope_impl)
.def("envelope",envelope_impl2)
.def("add_wkt",add_wkt_impl)
.def("add_wkb",add_wkb_impl)
.def("add_geojson",add_geojson_impl)

View file

@ -55,23 +55,33 @@ void add_stop(raster_colorizer_ptr & rc, colorizer_stop & stop)
{
rc->add_stop(stop);
}
void add_stop2(raster_colorizer_ptr & rc, float v) {
void add_stop2(raster_colorizer_ptr & rc, float v)
{
colorizer_stop stop(v, rc->get_default_mode(), rc->get_default_color());
rc->add_stop(stop);
}
void add_stop3(raster_colorizer_ptr &rc, float v, color c) {
void add_stop3(raster_colorizer_ptr &rc, float v, color c)
{
colorizer_stop stop(v, rc->get_default_mode(), c);
rc->add_stop(stop);
}
void add_stop4(raster_colorizer_ptr &rc, float v, colorizer_mode_enum m) {
void add_stop4(raster_colorizer_ptr &rc, float v, colorizer_mode_enum m)
{
colorizer_stop stop(v, m, rc->get_default_color());
rc->add_stop(stop);
}
void add_stop5(raster_colorizer_ptr &rc, float v, colorizer_mode_enum m, color c) {
void add_stop5(raster_colorizer_ptr &rc, float v, colorizer_mode_enum m, color c)
{
colorizer_stop stop(v, m, c);
rc->add_stop(stop);
}
mapnik::color get_color(raster_colorizer_ptr &rc, float value) {
mapnik::color get_color(raster_colorizer_ptr &rc, float value)
{
unsigned rgba = rc->get_color(value);
unsigned r = (rgba & 0xff);
unsigned g = (rgba >> 8 ) & 0xff;
@ -84,6 +94,7 @@ colorizer_stops const& get_stops(raster_colorizer_ptr & rc)
{
return rc->get_stops();
}
}
void export_raster_colorizer()

View file

@ -26,3 +26,4 @@
using sink_type = std::back_insert_iterator<std::string>;
template struct mapnik::svg::svg_path_generator<sink_type, mapnik::geometry_type>;
template struct mapnik::svg::svg_path_generator<sink_type, mapnik::vertex_adapter>;

View file

@ -233,13 +233,13 @@ public:
{
if (first)
{
box2d<double> box = geom.envelope();
box2d<double> box = ::mapnik::envelope(geom);
result.init(box.minx(),box.miny(),box.maxx(),box.maxy());
first = false;
}
else
{
result.expand_to_include(geom.envelope());
result.expand_to_include(::mapnik::envelope(geom));
}
}
return result;

View file

@ -392,9 +392,10 @@ bool centroid_geoms(Iter start, Iter end, double & x, double & y)
double ytmp = 0.0;
unsigned count = 0;
while (start!=end)
while (start != end)
{
typename Iter::value_type const& path = *start++;
typename Iter::value_type const& geom = *start++;
vertex_adapter path(geom);
path.rewind(0);
unsigned command = path.vertex(&x0, &y0);
if (command == SEG_END) continue;

View file

@ -49,20 +49,17 @@ public:
using container_type = Container<coord_type>;
using value_type = typename container_type::value_type;
using size_type = typename container_type::size_type;
private:
//private:
container_type cont_;
types type_;
mutable size_type itr_;
public:
geometry()
: type_(Unknown),
itr_(0)
: type_(Unknown)
{}
explicit geometry(types type)
: type_(type),
itr_(0)
: type_(type)
{}
types type() const
@ -89,6 +86,63 @@ public:
{
return cont_.size();
}
void push_vertex(coord_type x, coord_type y, CommandType c)
{
cont_.push_back(x,y,c);
}
void line_to(coord_type x,coord_type y)
{
push_vertex(x,y,SEG_LINETO);
}
void move_to(coord_type x,coord_type y)
{
push_vertex(x,y,SEG_MOVETO);
}
void close_path()
{
push_vertex(0,0,SEG_CLOSE);
}
};
namespace detail {
template <typename Geometry>
struct vertex_adapter : private util::noncopyable
{
using size_type = typename Geometry::size_type;
using value_type = typename Geometry::value_type;
using types = typename Geometry::types;
vertex_adapter(Geometry const& geom)
: geom_(geom),
itr_(0) {}
size_type size() const
{
return geom_.size();
}
unsigned vertex(double* x, double* y) const
{
return geom_.cont_.get_vertex(itr_++,x,y);
}
unsigned vertex(std::size_t index, double* x, double* y) const
{
return geom_.cont_.get_vertex(index, x, y);
}
void rewind(unsigned ) const
{
itr_ = 0;
}
types type() const
{
return geom_.type();
}
box2d<double> envelope() const
{
@ -112,44 +166,20 @@ public:
}
return result;
}
void push_vertex(coord_type x, coord_type y, CommandType c)
{
cont_.push_back(x,y,c);
}
void line_to(coord_type x,coord_type y)
{
push_vertex(x,y,SEG_LINETO);
}
void move_to(coord_type x,coord_type y)
{
push_vertex(x,y,SEG_MOVETO);
}
void close_path()
{
push_vertex(0,0,SEG_CLOSE);
}
unsigned vertex(double* x, double* y) const
{
return cont_.get_vertex(itr_++,x,y);
}
unsigned vertex(std::size_t index, double* x, double* y) const
{
return cont_.get_vertex(index, x, y);
}
void rewind(unsigned ) const
{
itr_=0;
}
Geometry const& geom_;
mutable size_type itr_;
};
}
template <typename Geometry>
box2d<double> envelope(Geometry const& geom)
{
detail::vertex_adapter<Geometry> va(geom);
return va.envelope();
}
using geometry_type = geometry<double,vertex_vector>;
using vertex_adapter = detail::vertex_adapter<geometry_type>;
}

View file

@ -42,7 +42,8 @@ public:
{
for (geometry_type & geom : feature.paths())
{
if (label::hit_test(geom, x_,y_,tol_))
vertex_adapter va(geom);
if (label::hit_test(va, x_,y_,tol_))
return true;
}
return false;

View file

@ -66,8 +66,8 @@ struct get_first
result_type operator() (Geometry const& geom) const
{
typename Geometry::value_type coord;
geom.rewind(0);
std::get<0>(coord) = geom.vertex(&std::get<1>(coord),&std::get<2>(coord));
//geom.rewind(0);
std::get<0>(coord) = geom.cont_.get_vertex(0, &std::get<1>(coord),&std::get<2>(coord));
return coord;
}
};

View file

@ -194,7 +194,8 @@ void apply_markers_multi(feature_impl const& feature, attributes const& vars, Co
std::size_t geom_count = feature.paths().size();
if (geom_count == 1)
{
converter.apply(const_cast<geometry_type&>(feature.paths()[0]));
vertex_adapter va(feature.paths()[0]);
converter.apply(va);
}
else if (geom_count > 1)
{
@ -211,7 +212,8 @@ void apply_markers_multi(feature_impl const& feature, attributes const& vars, Co
pt.move_to(x, y);
// unset any clipping since we're now dealing with a point
converter.template unset<clip_poly_tag>();
converter.apply(pt);
vertex_adapter va(pt);
converter.apply(va);
}
}
else if ((placement == MARKER_POINT_PLACEMENT || placement == MARKER_INTERIOR_PLACEMENT) &&
@ -223,7 +225,8 @@ void apply_markers_multi(feature_impl const& feature, attributes const& vars, Co
geometry_type const* largest = 0;
for (geometry_type const& geom : feature.paths())
{
const box2d<double>& env = geom.envelope();
vertex_adapter va(geom);
const box2d<double>& env = va.envelope();
double area = env.width() * env.height();
if (area > maxarea)
{
@ -233,7 +236,8 @@ void apply_markers_multi(feature_impl const& feature, attributes const& vars, Co
}
if (largest)
{
converter.apply(const_cast<geometry_type&>(*largest));
vertex_adapter va(*largest);
converter.apply(va);
}
}
else
@ -244,7 +248,8 @@ void apply_markers_multi(feature_impl const& feature, attributes const& vars, Co
}
for (geometry_type const& path : feature.paths())
{
converter.apply(const_cast<geometry_type&>(path));
vertex_adapter va(path);
converter.apply(va);
}
}
}

View file

@ -80,7 +80,7 @@ public:
for (std::size_t i=0; i<(*pos_)->num_geometries();++i)
{
geometry_type & geom = (*pos_)->get_geometry(i);
if (bbox_.intersects(geom.envelope()))
if (bbox_.intersects(::mapnik::envelope(geom)))
{
return *pos_++;
}

View file

@ -41,15 +41,17 @@ void render_building_symbolizer(mapnik::feature_impl &feature,
{
if (geom.size() > 2)
{
const std::unique_ptr<geometry_type> frame(new geometry_type(geometry_type::types::LineString));
const std::unique_ptr<geometry_type> roof(new geometry_type(geometry_type::types::Polygon));
std::deque<segment_t> face_segments;
double x0 = 0;
double y0 = 0;
double x,y;
geom.rewind(0);
for (unsigned cm = geom.vertex(&x, &y); cm != SEG_END;
cm = geom.vertex(&x, &y))
vertex_adapter va(geom);
va.rewind(0);
for (unsigned cm = va.vertex(&x, &y); cm != SEG_END;
cm = va.vertex(&x, &y))
{
if (cm == SEG_MOVETO)
{
@ -84,9 +86,9 @@ void render_building_symbolizer(mapnik::feature_impl &feature,
}
geom.rewind(0);
for (unsigned cm = geom.vertex(&x, &y); cm != SEG_END;
cm = geom.vertex(&x, &y))
va.rewind(0);
for (unsigned cm = va.vertex(&x, &y); cm != SEG_END;
cm = va.vertex(&x, &y))
{
if (cm == SEG_MOVETO)
{

View file

@ -66,17 +66,18 @@ void render_point_symbolizer(point_symbolizer const &sym,
for (std::size_t i=0; i<feature.num_geometries(); ++i)
{
geometry_type const& geom = feature.get_geometry(i);
vertex_adapter va(geom);
double x;
double y;
double z=0;
if (placement == CENTROID_POINT_PLACEMENT)
{
if (!label::centroid(geom, x, y))
if (!label::centroid(va, x, y))
return;
}
else
{
if (!label::interior_position(geom ,x, y))
if (!label::interior_position(va ,x, y))
return;
}
@ -101,4 +102,4 @@ void render_point_symbolizer(point_symbolizer const &sym,
} // namespace mapnik
#endif /* MAPNIK_RENDERER_COMMON_PROCESS_POINT_SYMBOLIZER_HPP */
#endif // MAPNIK_RENDERER_COMMON_PROCESS_POINT_SYMBOLIZER_HPP

View file

@ -62,7 +62,8 @@ void render_polygon_symbolizer(polygon_symbolizer const &sym,
{
if (geom.size() > 2)
{
converter.apply(geom);
vertex_adapter va(geom);
converter.apply(va);
}
}

View file

@ -54,7 +54,7 @@
namespace boost { namespace spirit { namespace traits {
// TODO - this needs to be made generic to any path type
using path_type = mapnik::transform_path_adapter<mapnik::view_transform, mapnik::geometry_type>;
using path_type = mapnik::transform_path_adapter<mapnik::view_transform, mapnik::vertex_adapter>;
template <>
struct is_container<path_type const> : mpl::true_ {} ;
@ -119,6 +119,20 @@ namespace mapnik { namespace svg {
}
};
template <>
struct get_first<mapnik::geometry_type>
{
using geometry_type = mapnik::geometry_type;
using result_type = typename geometry_type::value_type const;
result_type operator() (geometry_type const& geom) const
{
typename geometry_type::value_type coord;
std::get<0>(coord) = geom.cont_.get_vertex(0, &std::get<1>(coord),&std::get<2>(coord));
return coord;
}
};
template <typename T>
struct coordinate_policy : karma::real_policies<T>
{

View file

@ -57,16 +57,16 @@ struct transform_path_adapter
using value_type = typename select_value_type<Geometry, void>::type;
transform_path_adapter(Transform const& t,
Geometry & geom,
proj_transform const& prj_trans)
Geometry & geom,
proj_transform const& prj_trans)
: t_(&t),
geom_(geom),
prj_trans_(&prj_trans) {}
geom_(geom),
prj_trans_(&prj_trans) {}
explicit transform_path_adapter(Geometry & geom)
: t_(0),
geom_(geom),
prj_trans_(0) {}
geom_(geom),
prj_trans_(0) {}
void set_proj_trans(proj_transform const& prj_trans)
{

View file

@ -39,16 +39,26 @@ namespace boost { namespace spirit { namespace traits {
template <>
struct is_container<mapnik::geometry_type const> : mpl::true_ {} ;
template <>
struct is_container<mapnik::vertex_adapter const> : mpl::true_ {} ;
// make gcc and darwin toolsets happy.
template <>
struct is_container<mapnik::geometry_container const> : mpl::false_ {} ;
//
template <>
struct container_iterator<mapnik::geometry_type const>
{
using type = mapnik::util::path_iterator<mapnik::geometry_type>;
};
template <>
struct container_iterator<mapnik::vertex_adapter const>
{
using type = mapnik::util::path_iterator<mapnik::vertex_adapter>;
};
template <>
struct begin_container<mapnik::geometry_type const>
{
@ -59,6 +69,16 @@ struct begin_container<mapnik::geometry_type const>
}
};
template <>
struct begin_container<mapnik::vertex_adapter const>
{
static mapnik::util::path_iterator<mapnik::vertex_adapter>
call (mapnik::vertex_adapter const& g)
{
return mapnik::util::path_iterator<mapnik::vertex_adapter>(g);
}
};
template <>
struct end_container<mapnik::geometry_type const>
{
@ -69,6 +89,16 @@ struct end_container<mapnik::geometry_type const>
}
};
template <>
struct end_container<mapnik::vertex_adapter const>
{
static mapnik::util::path_iterator<mapnik::vertex_adapter>
call (mapnik::vertex_adapter const&)
{
return mapnik::util::path_iterator<mapnik::vertex_adapter>();
}
};
}}}
#endif // CONTAINER_ADAPTER_HPP

View file

@ -238,17 +238,17 @@ template<typename GeometryType>
wkb_buffer_ptr to_wkb(GeometryType const& g, wkbByteOrder byte_order )
{
wkb_buffer_ptr wkb;
switch (g.type())
vertex_adapter va(g);
switch (va.type())
{
case mapnik::geometry_type::types::Point:
wkb = to_point_wkb(g, byte_order);
wkb = to_point_wkb(va, byte_order);
break;
case mapnik::geometry_type::types::LineString:
wkb = to_line_string_wkb(g, byte_order);
wkb = to_line_string_wkb(va, byte_order);
break;
case mapnik::geometry_type::types::Polygon:
wkb = to_polygon_wkb(g, byte_order);
wkb = to_polygon_wkb(va, byte_order);
break;
default:
break;

View file

@ -34,6 +34,7 @@ inline bool to_wkt(std::string & wkt, mapnik::geometry_type const& geom)
{
using sink_type = std::back_insert_iterator<std::string>;
sink_type sink(wkt);
//vertex_adapter va(geom);
static const mapnik::wkt::wkt_generator<sink_type, mapnik::geometry_type> generator(true);
return boost::spirit::karma::generate(sink, generator, geom);
}

View file

@ -78,9 +78,57 @@ private:
value_type v_;
const path_type *vertices_;
unsigned pos_;
};
// specialization for mapnik::geometry_type - vertex interfacce has been removed
template <>
class path_iterator<geometry_type>
: public boost::iterator_facade< path_iterator<geometry_type>,
std::tuple<unsigned,double,double> const,
boost::forward_traversal_tag
>
{
public:
using path_type = mapnik::geometry_type;
using value_type = typename std::tuple<unsigned, double, double>;
using size_type = typename path_type::size_type;
path_iterator()
: v_(mapnik::SEG_END,0,0),
vertices_()
{}
explicit path_iterator(path_type const& vertices)
: vertices_(&vertices),
pos_(0)
{
increment();
}
private:
friend class boost::iterator_core_access;
void increment()
{
std::get<0>(v_) = vertices_->cont_.get_vertex(pos_++, &std::get<1>(v_), &std::get<2>(v_));
}
bool equal( path_iterator const& other) const
{
return std::get<0>(v_) == std::get<0>(other.v_);
}
value_type const& dereference() const
{
return v_;
}
value_type v_;
const path_type *vertices_;
size_type pos_;
};
}}

View file

@ -390,9 +390,9 @@ struct vertex_converter : private util::noncopyable
double scale_factor)
: disp_(proc,bbox,sym,tr,prj_trans,affine_trans,feature,vars,scale_factor) {}
void apply(geometry_type & geom)
void apply(vertex_adapter & geom)
{
detail::converters_helper<dispatcher_type, ConverterTypes...>:: template forward<geometry_type>(disp_, geom);
detail::converters_helper<dispatcher_type, ConverterTypes...>:: template forward<vertex_adapter>(disp_, geom);
}
template <typename Converter>

View file

@ -72,8 +72,7 @@ struct get_first
typename geometry_type::value_type const operator() (Geometry const& geom) const
{
typename Geometry::value_type coord;
geom.rewind(0);
std::get<0>(coord) = geom.vertex(&std::get<1>(coord),&std::get<2>(coord));
std::get<0>(coord) = geom.cont_.get_vertex(0, &std::get<1>(coord),&std::get<2>(coord));
return coord;
}
};

View file

@ -200,7 +200,7 @@ public:
{
for (unsigned i=0; i<paths.size(); ++i)
{
mapnik::box2d<double> const& bbox = paths[i].envelope();
mapnik::box2d<double> const& bbox = ::mapnik::envelope(paths[i]);
if (bbox.valid())
{
if (first)
@ -288,13 +288,14 @@ public:
{
for (unsigned i=0; i<paths.size(); ++i)
{
auto b = ::mapnik::envelope(paths[i]);
if (i==0)
{
bbox = paths[i].envelope();
bbox = b;
}
else
{
bbox.expand_to_include(paths[i].envelope());
bbox.expand_to_include(b);
}
}
}
@ -374,7 +375,7 @@ public:
{
for (unsigned i=0; i<paths.size(); ++i)
{
mapnik::box2d<double> const& bbox = paths[i].envelope();
mapnik::box2d<double> const& bbox = ::mapnik::envelope(paths[i]);
if (bbox.valid())
{
const int type_oid = rs->column_type(1);

View file

@ -54,7 +54,7 @@ void agg_renderer<T0,T1>::process(building_symbolizer const& sym,
mapnik::feature_impl & feature,
proj_transform const& prj_trans)
{
using path_type = transform_path_adapter<view_transform,geometry_type>;
using path_type = transform_path_adapter<view_transform, vertex_adapter>;
using ren_base = agg::renderer_base<agg::pixfmt_rgba32_pre>;
using renderer = agg::renderer_scanline_aa_solid<ren_base>;
@ -85,15 +85,19 @@ void agg_renderer<T0,T1>::process(building_symbolizer const& sym,
render_building_symbolizer(
feature, height,
[&,r,g,b,a,opacity](geometry_type &faces) {
path_type faces_path (this->common_.t_,faces,prj_trans);
[&,r,g,b,a,opacity](geometry_type const& faces)
{
vertex_adapter va(faces);
path_type faces_path (this->common_.t_,va,prj_trans);
ras_ptr->add_path(faces_path);
ren.color(agg::rgba8_pre(int(r*0.8), int(g*0.8), int(b*0.8), int(a * opacity)));
agg::render_scanlines(*ras_ptr, sl, ren);
this->ras_ptr->reset();
},
[&,r,g,b,a,opacity](geometry_type &frame) {
path_type path(common_.t_,frame,prj_trans);
[&,r,g,b,a,opacity](geometry_type const& frame)
{
vertex_adapter va(frame);
path_type path(common_.t_,va, prj_trans);
agg::conv_stroke<path_type> stroke(path);
stroke.width(common_.scale_factor_);
ras_ptr->add_path(stroke);
@ -101,8 +105,10 @@ void agg_renderer<T0,T1>::process(building_symbolizer const& sym,
agg::render_scanlines(*ras_ptr, sl, ren);
ras_ptr->reset();
},
[&,r,g,b,a,opacity](geometry_type &roof) {
path_type roof_path (common_.t_,roof,prj_trans);
[&,r,g,b,a,opacity](geometry_type const& roof)
{
vertex_adapter va(roof);
path_type roof_path (common_.t_,va,prj_trans);
ras_ptr->add_path(roof_path);
ren.color(agg::rgba8_pre(r, g, b, int(a * opacity)));
agg::render_scanlines(*ras_ptr, sl, ren);

View file

@ -72,9 +72,10 @@ void agg_renderer<T0,T1>::process(debug_symbolizer const& sym,
double x;
double y;
double z = 0;
geom.rewind(0);
vertex_adapter va(geom);
va.rewind(0);
unsigned cmd = 1;
while ((cmd = geom.vertex(&x, &y)) != mapnik::SEG_END)
while ((cmd = va.vertex(&x, &y)) != mapnik::SEG_END)
{
if (cmd == SEG_CLOSE) continue;
prj_trans.backward(x,y,z);

View file

@ -83,18 +83,22 @@ void agg_renderer<T0,T1>::process(dot_symbolizer const& sym,
ren.color(agg::rgba8_pre(fill.red(), fill.green(), fill.blue(), int(fill.alpha() * opacity)));
agg::ellipse el(0,0,rx,ry);
unsigned num_steps = el.num_steps();
for (geometry_type const& geom : feature.paths()) {
double x,y,z = 0;
unsigned cmd = 1;
geom.rewind(0);
while ((cmd = geom.vertex(&x, &y)) != mapnik::SEG_END) {
if (cmd == SEG_CLOSE) continue;
prj_trans.backward(x,y,z);
common_.t_.forward(&x,&y);
el.init(x,y,rx,ry,num_steps);
ras_ptr->add_path(el);
agg::render_scanlines(*ras_ptr, sl, ren);
}
for (geometry_type const& geom : feature.paths())
{
double x,y,z = 0;
unsigned cmd = 1;
vertex_adapter va(geom);
va.rewind(0);
while ((cmd = va.vertex(&x, &y)) != mapnik::SEG_END)
{
if (cmd == SEG_CLOSE) continue;
prj_trans.backward(x,y,z);
common_.t_.forward(&x,&y);
el.init(x,y,rx,ry,num_steps);
ras_ptr->add_path(el);
agg::render_scanlines(*ras_ptr, sl, ren);
}
}
}

View file

@ -135,11 +135,12 @@ void agg_renderer<T0,T1>::process(line_pattern_symbolizer const& sym,
converter.set<affine_transform_tag>(); // optional affine transform
if (smooth > 0.0) converter.set<smooth_tag>(); // optional smooth converter
for (geometry_type & geom : feature.paths())
for (geometry_type const& geom : feature.paths())
{
if (geom.size() > 1)
{
converter.apply(geom);
vertex_adapter va(geom);
converter.apply(va);
}
}
}

View file

@ -182,7 +182,8 @@ void agg_renderer<T0,T1>::process(line_symbolizer const& sym,
{
if (geom.size() > 1)
{
converter.apply(geom);
vertex_adapter va(geom);
converter.apply(va);
}
}
}
@ -209,7 +210,8 @@ void agg_renderer<T0,T1>::process(line_symbolizer const& sym,
{
if (geom.size() > 1)
{
converter.apply(geom);
vertex_adapter va(geom);
converter.apply(va);
}
}

View file

@ -80,7 +80,7 @@ void agg_renderer<T0,T1>::process(polygon_pattern_symbolizer const& sym,
if (!pat) return;
using clipped_geometry_type = agg::conv_clip_polygon<geometry_type>;
using clipped_geometry_type = agg::conv_clip_polygon<vertex_adapter>;
using path_type = transform_path_adapter<view_transform,clipped_geometry_type>;
agg::rendering_buffer buf(current_buffer_->raw_data(), current_buffer_->width(),
@ -140,7 +140,8 @@ void agg_renderer<T0,T1>::process(polygon_pattern_symbolizer const& sym,
double y0 = 0;
if (feature.num_geometries() > 0)
{
clipped_geometry_type clipped(feature.get_geometry(0));
vertex_adapter va(feature.get_geometry(0));
clipped_geometry_type clipped(va);
clipped.clip_box(clip_box.minx(),clip_box.miny(),clip_box.maxx(),clip_box.maxy());
path_type path(common_.t_,clipped,prj_trans);
path.vertex(&x0,&y0);
@ -171,7 +172,8 @@ void agg_renderer<T0,T1>::process(polygon_pattern_symbolizer const& sym,
{
if (geom.size() > 2)
{
converter.apply(geom);
vertex_adapter va(geom);
converter.apply(va);
}
}
agg::scanline_u8 sl;

View file

@ -43,7 +43,7 @@ void cairo_renderer<T>::process(building_symbolizer const& sym,
mapnik::feature_impl & feature,
proj_transform const& prj_trans)
{
using path_type = transform_path_adapter<view_transform,geometry_type>;
using path_type = transform_path_adapter<view_transform,vertex_adapter>;
cairo_save_restore guard(context_);
composite_mode_e comp_op = get<composite_mode_e, keys::comp_op>(sym, feature, common_.vars_);
mapnik::color fill = get<color, keys::fill>(sym, feature, common_.vars_);
@ -54,23 +54,29 @@ void cairo_renderer<T>::process(building_symbolizer const& sym,
render_building_symbolizer(
feature, height,
[&](geometry_type &faces) {
path_type faces_path(common_.t_, faces, prj_trans);
[&](geometry_type const& faces)
{
vertex_adapter va(faces);
path_type faces_path(common_.t_, va, prj_trans);
context_.set_color(fill.red() * 0.8 / 255.0, fill.green() * 0.8 / 255.0,
fill.blue() * 0.8 / 255.0, fill.alpha() * opacity / 255.0);
context_.add_path(faces_path);
context_.fill();
},
[&](geometry_type &frame) {
path_type path(common_.t_, frame, prj_trans);
[&](geometry_type const& frame)
{
vertex_adapter va(frame);
path_type path(common_.t_, va, prj_trans);
context_.set_color(fill.red() * 0.8 / 255.0, fill.green() * 0.8/255.0,
fill.blue() * 0.8 / 255.0, fill.alpha() * opacity / 255.0);
context_.set_line_width(common_.scale_factor_);
context_.add_path(path);
context_.stroke();
},
[&](geometry_type &roof) {
path_type roof_path(common_.t_, roof, prj_trans);
[&](geometry_type const& roof)
{
vertex_adapter va(roof);
path_type roof_path(common_.t_, va, prj_trans);
context_.set_color(fill, opacity);
context_.add_path(roof_path);
context_.fill();

View file

@ -85,9 +85,10 @@ void cairo_renderer<T>::process(debug_symbolizer const& sym,
double x;
double y;
double z = 0;
geom.rewind(0);
vertex_adapter va(geom);
va.rewind(0);
unsigned cmd = 1;
while ((cmd = geom.vertex(&x, &y)) != mapnik::SEG_END)
while ((cmd = va.vertex(&x, &y)) != mapnik::SEG_END)
{
if (cmd == SEG_CLOSE) continue;
prj_trans.backward(x,y,z);

View file

@ -119,11 +119,12 @@ void cairo_renderer<T>::process(line_pattern_symbolizer const& sym,
if (smooth > 0.0) converter.set<smooth_tag>(); // optional smooth converter
for (auto & geom : feature.paths())
for (auto const& geom : feature.paths())
{
if (geom.size() > 1)
{
converter.apply(geom);
vertex_adapter va(geom);
converter.apply(va);
}
}
}

View file

@ -95,11 +95,12 @@ void cairo_renderer<T>::process(line_symbolizer const& sym,
if (simplify_tolerance > 0.0) converter.set<simplify_tag>(); // optional simplify converter
if (smooth > 0.0) converter.set<smooth_tag>(); // optional smooth converter
for (geometry_type & geom : feature.paths())
for (geometry_type const& geom : feature.paths())
{
if (geom.size() > 1)
{
converter.apply(geom);
vertex_adapter va(geom);
converter.apply(va);
}
}
// stroke

View file

@ -69,9 +69,10 @@ void cairo_renderer<T>::process(polygon_pattern_symbolizer const& sym,
if (feature.num_geometries() > 0)
{
using clipped_geometry_type = agg::conv_clip_polygon<geometry_type>;
using clipped_geometry_type = agg::conv_clip_polygon<vertex_adapter>;
using path_type = transform_path_adapter<view_transform,clipped_geometry_type>;
clipped_geometry_type clipped(feature.get_geometry(0));
vertex_adapter va(feature.get_geometry(0));
clipped_geometry_type clipped(va);
clipped.clip_box(clip_box.minx(), clip_box.miny(),
clip_box.maxx(), clip_box.maxy());
path_type path(common_.t_, clipped, prj_trans);
@ -115,7 +116,8 @@ void cairo_renderer<T>::process(polygon_pattern_symbolizer const& sym,
{
if (geom.size() > 2)
{
converter.apply(geom);
vertex_adapter va(geom);
converter.apply(va);
}
}
// fill polygon

View file

@ -56,7 +56,7 @@ void grid_renderer<T>::process(building_symbolizer const& sym,
using pixfmt_type = typename grid_renderer_base_type::pixfmt_type;
using color_type = typename grid_renderer_base_type::pixfmt_type::color_type;
using renderer_type = agg::renderer_scanline_bin_solid<grid_renderer_base_type>;
using path_type = transform_path_adapter<view_transform,geometry_type>;
using path_type = transform_path_adapter<view_transform, vertex_adapter>;
agg::scanline_bin sl;
grid_rendering_buffer buf(pixmap_.raw_data(), common_.width_, common_.height_, common_.width_);
@ -71,23 +71,29 @@ void grid_renderer<T>::process(building_symbolizer const& sym,
render_building_symbolizer(
feature, height,
[&](geometry_type &faces) {
path_type faces_path (common_.t_,faces,prj_trans);
[&](geometry_type const& faces)
{
vertex_adapter va(faces);
path_type faces_path (common_.t_,va,prj_trans);
ras_ptr->add_path(faces_path);
ren.color(color_type(feature.id()));
agg::render_scanlines(*ras_ptr, sl, ren);
ras_ptr->reset();
},
[&](geometry_type &frame) {
path_type path(common_.t_,frame,prj_trans);
[&](geometry_type const& frame)
{
vertex_adapter va(frame);
path_type path(common_.t_,va,prj_trans);
agg::conv_stroke<path_type> stroke(path);
ras_ptr->add_path(stroke);
ren.color(color_type(feature.id()));
agg::render_scanlines(*ras_ptr, sl, ren);
ras_ptr->reset();
},
[&](geometry_type &roof) {
path_type roof_path (common_.t_,roof,prj_trans);
[&](geometry_type const& roof)
{
vertex_adapter va(roof);
path_type roof_path (common_.t_,va,prj_trans);
ras_ptr->add_path(roof_path);
ren.color(color_type(feature.id()));
agg::render_scanlines(*ras_ptr, sl, ren);

View file

@ -130,11 +130,12 @@ void grid_renderer<T>::process(line_pattern_symbolizer const& sym,
if (smooth > 0.0) converter.set<smooth_tag>(); // optional smooth converter
converter.set<stroke_tag>(); //always stroke
for (geometry_type & geom : feature.paths())
for (geometry_type const& geom : feature.paths())
{
if (geom.size() > 1)
{
converter.apply(geom);
vertex_adapter va(geom);
converter.apply(va);
}
}

View file

@ -102,11 +102,12 @@ void grid_renderer<T>::process(line_symbolizer const& sym,
if (has_dash) converter.set<dash_tag>();
converter.set<stroke_tag>(); //always stroke
for ( geometry_type & geom : feature.paths())
for ( geometry_type const& geom : feature.paths())
{
if (geom.size() > 1)
{
converter.apply(geom);
vertex_adapter va(geom);
converter.apply(va);
}
}

View file

@ -86,11 +86,12 @@ void grid_renderer<T>::process(polygon_pattern_symbolizer const& sym,
if (simplify_tolerance > 0.0) converter.set<simplify_tag>(); // optional simplify converter
if (smooth > 0.0) converter.set<smooth_tag>(); // optional smooth converter
for ( geometry_type & geom : feature.paths())
for ( geometry_type const& geom : feature.paths())
{
if (geom.size() > 2)
{
converter.apply(geom);
vertex_adapter va(geom);
converter.apply(va);
}
}
using pixfmt_type = typename grid_renderer_base_type::pixfmt_type;

View file

@ -61,12 +61,13 @@ pixel_position_list const& group_symbolizer_helper::get()
}
else
{
for (auto const& geom : geometries_to_process_)
for (auto const* geom : geometries_to_process_)
{
// TODO to support clipped geometries this needs to use
// vertex_converters
using path_type = transform_path_adapter<view_transform,geometry_type>;
path_type path(t_, *geom, prj_trans_);
using path_type = transform_path_adapter<view_transform,vertex_adapter>;
vertex_adapter va(*geom);
path_type path(t_, va, prj_trans_);
find_line_placements(path);
}
}

View file

@ -44,19 +44,21 @@ struct accumulate_extent
accumulate_extent(box2d<double> & ext)
: ext_(ext),first_(true) {}
void operator() (feature_ptr feat)
void operator() (feature_ptr const& feat)
{
for (std::size_t i=0;i<feat->num_geometries();++i)
auto size = feat->num_geometries();
for (std::size_t i = 0; i < size; ++i)
{
geometry_type & geom = feat->get_geometry(i);
auto bbox = ::mapnik::envelope(geom);
if ( first_ )
{
first_ = false;
ext_ = geom.envelope();
ext_ = bbox;
}
else
{
ext_.expand_to_include(geom.envelope());
ext_.expand_to_include(bbox);
}
}
}

View file

@ -79,7 +79,7 @@ bool svg_renderer<OutputIterator>::process(rule::symbolizers const& syms,
proj_transform const& prj_trans)
{
// svg renderer supports processing of multiple symbolizers.
using path_type = transform_path_adapter<view_transform, geometry_type>;
using path_type = transform_path_adapter<view_transform, vertex_adapter>;
bool process_path = false;
// process each symbolizer to collect its (path) information.
@ -101,7 +101,8 @@ bool svg_renderer<OutputIterator>::process(rule::symbolizers const& syms,
{
if(geom.size() > 0)
{
path_type path(common_.t_, geom, prj_trans);
vertex_adapter va(geom);
path_type path(common_.t_, va, prj_trans);
generate_path(generator_.output_iterator_, path, path_attributes_);
}
}

View file

@ -70,8 +70,8 @@ struct largest_bbox_first
{
bool operator() (geometry_type const* g0, geometry_type const* g1) const
{
box2d<double> b0 = g0->envelope();
box2d<double> b1 = g1->envelope();
box2d<double> b0 = ::mapnik::envelope(*g0);
box2d<double> b1 = ::mapnik::envelope(*g1);
return b0.width()*b0.height() > b1.width()*b1.height();
}
};
@ -89,7 +89,7 @@ void base_symbolizer_helper::initialize_geometries() const
{
if (minimum_path_length > 0)
{
box2d<double> gbox = t_.forward(geom.envelope(), prj_trans_);
box2d<double> gbox = t_.forward(::mapnik::envelope(geom), prj_trans_);
if (gbox.width() < minimum_path_length)
{
continue;
@ -129,12 +129,13 @@ void base_symbolizer_helper::initialize_points() const
for (auto * geom_ptr : geometries_to_process_)
{
geometry_type const& geom = *geom_ptr;
vertex_adapter va(geom);
if (how_placed == VERTEX_PLACEMENT)
{
geom.rewind(0);
for(unsigned i = 0; i < geom.size(); ++i)
va.rewind(0);
for(unsigned i = 0; i < va.size(); ++i)
{
geom.vertex(&label_x, &label_y);
va.vertex(&label_x, &label_y);
prj_trans_.backward(label_x, label_y, z);
t_.forward(&label_x, &label_y);
points_.emplace_back(label_x, label_y);
@ -147,15 +148,15 @@ void base_symbolizer_helper::initialize_points() const
// https://github.com/mapnik/mapnik/issues/1350
if (geom.type() == geometry_type::types::LineString)
{
success = label::middle_point(geom, label_x,label_y);
success = label::middle_point(va, label_x,label_y);
}
else if (how_placed == POINT_PLACEMENT)
{
success = label::centroid(geom, label_x, label_y);
success = label::centroid(va, label_x, label_y);
}
else if (how_placed == INTERIOR_PLACEMENT)
{
success = label::interior_position(geom, label_x, label_y);
success = label::interior_position(va, label_x, label_y);
}
else
{
@ -227,8 +228,8 @@ bool text_symbolizer_helper::next_line_placement() const
geo_itr_ = geometries_to_process_.begin();
continue; //Reexecute size check
}
converter_.apply(**geo_itr_);
vertex_adapter va(**geo_itr_);
converter_.apply(va);
if (adapter_.status())
{
//Found a placement

View file

@ -46,10 +46,11 @@ std::string dump_path(T & path)
}
std::string clip_line(mapnik::box2d<double> const& bbox,
mapnik::geometry_type & geom)
mapnik::geometry_type const& geom)
{
using line_clipper = agg::conv_clip_polyline<mapnik::geometry_type>;
line_clipper clipped(geom);
using line_clipper = agg::conv_clip_polyline<mapnik::vertex_adapter>;
mapnik::vertex_adapter va(geom);
line_clipper clipped(va);
clipped.clip_box(bbox.minx(),bbox.miny(),bbox.maxx(),bbox.maxy());
return dump_path(clipped);
}

View file

@ -71,9 +71,10 @@ boost::optional<std::string> linestring_bbox_clipping(mapnik::box2d<double> bbox
throw std::runtime_error("Failed to parse WKT");
}
for (geometry_type & geom : p)
for (geometry_type const& geom : p)
{
converter.apply(geom);
vertex_adapter va(geom);
converter.apply(va);
}
using sink_type = std::back_insert_iterator<std::string>;
@ -113,9 +114,10 @@ boost::optional<std::string> polygon_bbox_clipping(mapnik::box2d<double> bbox,
throw std::runtime_error("Failed to parse WKT");
}
for (geometry_type & geom : p)
for (geometry_type const& geom : p)
{
converter.apply(geom);
vertex_adapter va(geom);
converter.apply(va);
}
using sink_type = std::back_insert_iterator<std::string>;

View file

@ -19,24 +19,29 @@ int main(int argc, char** argv)
// reused these for simplicity
double x,y;
// single point
mapnik::geometry_type pt(mapnik::geometry_type::types::Point);
// single point
pt.move_to(10,10);
BOOST_TEST( mapnik::label::centroid(pt, x, y) );
BOOST_TEST( x == 10 );
BOOST_TEST( y == 10 );
{
mapnik::vertex_adapter va(pt);
BOOST_TEST( mapnik::label::centroid(va, x, y) );
BOOST_TEST( x == 10 );
BOOST_TEST( y == 10 );
}
// two points
pt.move_to(20,20);
BOOST_TEST( mapnik::label::centroid(pt, x, y) );
BOOST_TEST_EQ( x, 15 );
BOOST_TEST_EQ( y, 15 );
{
mapnik::vertex_adapter va(pt);
BOOST_TEST( mapnik::label::centroid(va, x, y) );
BOOST_TEST_EQ( x, 15 );
BOOST_TEST_EQ( y, 15 );
}
// line with two verticies
mapnik::geometry_type line(mapnik::geometry_type::types::LineString);
line.move_to(0,0);
line.line_to(50,50);
BOOST_TEST( mapnik::label::centroid(line, x, y) );
mapnik::vertex_adapter va(line);
BOOST_TEST( mapnik::label::centroid(va, x, y) );
BOOST_TEST( x == 25 );
BOOST_TEST( y == 25 );
@ -44,17 +49,23 @@ int main(int argc, char** argv)
// MULTIPOLYGON(((-52 40,-60 32,-68 40,-60 48,-52 40)),((-60 50,-80 30,-100 49.9999999999999,-80.0000000000001 70,-60 50)),((-52 60,-60 52,-68 60,-60 68,-52 60)))
// hit tests
mapnik::geometry_type pt_hit(mapnik::geometry_type::types::Point);
pt_hit.move_to(10,10);
BOOST_TEST( mapnik::label::hit_test(pt_hit, 10, 10, 0.1) );
BOOST_TEST( !mapnik::label::hit_test(pt_hit, 9, 9, 0) );
BOOST_TEST( mapnik::label::hit_test(pt_hit, 9, 9, 1.5) );
mapnik::geometry_type line_hit(mapnik::geometry_type::types::LineString);
line_hit.move_to(0,0);
line_hit.line_to(50,50);
BOOST_TEST( mapnik::label::hit_test(line_hit, 0, 0, 0.001) );
BOOST_TEST( !mapnik::label::hit_test(line_hit, 1, 1, 0) );
BOOST_TEST( mapnik::label::hit_test(line_hit, 1, 1, 1.001) );
{
mapnik::geometry_type pt_hit(mapnik::geometry_type::types::Point);
pt_hit.move_to(10,10);
mapnik::vertex_adapter va(pt_hit);
BOOST_TEST( mapnik::label::hit_test(va, 10, 10, 0.1) );
BOOST_TEST( !mapnik::label::hit_test(va, 9, 9, 0) );
BOOST_TEST( mapnik::label::hit_test(va, 9, 9, 1.5) );
}
{
mapnik::geometry_type line_hit(mapnik::geometry_type::types::LineString);
line_hit.move_to(0,0);
line_hit.line_to(50,50);
mapnik::vertex_adapter va(line_hit);
BOOST_TEST( mapnik::label::hit_test(va, 0, 0, 0.001) );
BOOST_TEST( !mapnik::label::hit_test(va, 1, 1, 0) );
BOOST_TEST( mapnik::label::hit_test(va, 1, 1, 1.001) );
}
}
catch (std::exception const & ex)
{

View file

@ -24,7 +24,8 @@ void simplify(std::string const& wkt_in, double tolerance, std::string const& me
throw std::runtime_error("Failed to parse WKT");
}
//setup the generalization
mapnik::simplify_converter<mapnik::geometry_type> generalizer(multi_input.front());
mapnik::vertex_adapter va(multi_input.front());
mapnik::simplify_converter<mapnik::vertex_adapter> generalizer(va);
generalizer.set_simplify_algorithm(mapnik::simplify_algorithm_from_string(method).get());
generalizer.set_simplify_tolerance(tolerance);
//suck the vertices back out of it

View file

@ -391,7 +391,7 @@ void pgsql2sqlite(Connection conn,
&& feat.num_geometries() > 0)
{
geometry_type const& geom=feat.get_geometry(0);
box2d<double> bbox = geom.envelope();
box2d<double> bbox = ::mapnik::envelope(geom);
if (bbox.valid())
{
sqlite::record_type rec;