c++ style

This commit is contained in:
artemp 2014-07-22 15:58:37 +01:00
parent 8cc9b06e12
commit f12b5e06dd
2 changed files with 81 additions and 85 deletions

View file

@ -45,27 +45,25 @@ namespace mapnik {
class proj_transform;
/* General:
*
* The approach here is to run the normal symbolizers, but in
* a 'virtual' blank environment where the changes that they
* make are recorded (the detector, the render_* calls).
*
* The recorded boxes are then used to lay out the items and
* the offsets from old to new positions can be used to perform
* the actual rendering calls.
*
* This should allow us to re-use as much as possible of the
* existing symbolizer layout and rendering code while still
* being able to interpose our own decisions about whether
* a collision has occured or not.
*/
// General:
// The approach here is to run the normal symbolizers, but in
// a 'virtual' blank environment where the changes that they
// make are recorded (the detector, the render_* calls).
//
// The recorded boxes are then used to lay out the items and
// the offsets from old to new positions can be used to perform
// the actual rendering calls.
// This should allow us to re-use as much as possible of the
// existing symbolizer layout and rendering code while still
// being able to interpose our own decisions about whether
// a collision has occured or not.
// Thunk for rendering a particular instance of a point - this
// stores all the arguments necessary to re-render this point
// symbolizer at a later time.
/**
* Thunk for rendering a particular instance of a point - this
* stores all the arguments necessary to re-render this point
* symbolizer at a later time.
*/
struct point_render_thunk
{
pixel_position pos_;
@ -74,8 +72,8 @@ struct point_render_thunk
double opacity_;
composite_mode_e comp_op_;
point_render_thunk(pixel_position const &pos, marker const &m,
agg::trans_affine const &tr, double opacity,
point_render_thunk(pixel_position const& pos, marker const& m,
agg::trans_affine const& tr, double opacity,
composite_mode_e comp_op);
};
@ -90,65 +88,63 @@ struct text_render_thunk
composite_mode_e comp_op_;
halo_rasterizer_enum halo_rasterizer_;
text_render_thunk(placements_list const &placements,
text_render_thunk(placements_list const& placements,
double opacity, composite_mode_e comp_op,
halo_rasterizer_enum halo_rasterizer);
};
/**
* Variant type for render thunks to allow us to re-render them
* via a static visitor later.
*/
// Variant type for render thunks to allow us to re-render them
// via a static visitor later.
using render_thunk = boost::variant<point_render_thunk,
text_render_thunk>;
using render_thunk_ptr = std::shared_ptr<render_thunk>;
using render_thunk_list = std::list<render_thunk_ptr>;
/**
* Base class for extracting the bounding boxes associated with placing
* a symbolizer at a fake, virtual point - not real geometry.
*
* The bounding boxes can be used for layout, and the thunks are
* used to re-render at locations according to the group layout.
*/
// Base class for extracting the bounding boxes associated with placing
// a symbolizer at a fake, virtual point - not real geometry.
//
// The bounding boxes can be used for layout, and the thunks are
// used to re-render at locations according to the group layout.
struct render_thunk_extractor : public boost::static_visitor<>
{
render_thunk_extractor(box2d<double> &box,
render_thunk_list &thunks,
feature_impl &feature,
render_thunk_extractor(box2d<double> & box,
render_thunk_list & thunks,
feature_impl & feature,
attributes const& vars,
proj_transform const &prj_trans,
renderer_common &common,
box2d<double> const &clipping_extent);
proj_transform const& prj_trans,
renderer_common & common,
box2d<double> const& clipping_extent);
void operator()(point_symbolizer const &sym) const;
void operator()(point_symbolizer const& sym) const;
void operator()(text_symbolizer const &sym) const;
void operator()(text_symbolizer const& sym) const;
void operator()(shield_symbolizer const &sym) const;
void operator()(shield_symbolizer const& sym) const;
template <typename T>
void operator()(T const &) const
void operator()(T const& ) const
{
// TODO: warning if unimplemented?
}
private:
void extract_text_thunk(text_symbolizer_helper &helper, text_symbolizer const &sym) const;
void extract_text_thunk(text_symbolizer_helper & helper, text_symbolizer const& sym) const;
box2d<double> &box_;
render_thunk_list &thunks_;
box2d<double> & box_;
render_thunk_list & thunks_;
feature_impl & feature_;
attributes const& vars_;
proj_transform const &prj_trans_;
renderer_common &common_;
proj_transform const& prj_trans_;
renderer_common & common_;
box2d<double> clipping_extent_;
void update_box() const;
};
geometry_type *origin_point(proj_transform const &prj_trans,
renderer_common const &common);
geometry_type *origin_point(proj_transform const& prj_trans,
renderer_common const& common);
template <typename F>
void render_offset_placements(placements_list const& placements,
@ -182,12 +178,12 @@ void render_offset_placements(placements_list const& placements,
}
template <typename F>
void render_group_symbolizer(group_symbolizer const &sym,
void render_group_symbolizer(group_symbolizer const& sym,
feature_impl & feature,
attributes const& vars,
proj_transform const & prj_trans,
box2d<double> const & clipping_extent,
renderer_common &common,
proj_transform const& prj_trans,
box2d<double> const& clipping_extent,
renderer_common & common,
F render_thunks)
{
// find all column names referenced in the group rules and symbolizers
@ -319,7 +315,8 @@ void render_group_symbolizer(group_symbolizer const &sym,
// evalute the repeat key with the matched sub feature if we have one
if (rpt_key_expr)
{
rpt_key_value = boost::apply_visitor(evaluate<Feature,value_type,attributes>(*match_feature,common.vars_), *rpt_key_expr).to_unicode();
rpt_key_value = boost::apply_visitor(evaluate<Feature,value_type,attributes>(*match_feature,common.vars_),
*rpt_key_expr).to_unicode();
}
helper.add_box_element(layout_manager.offset_box_at(i), rpt_key_value);
}
@ -334,9 +331,8 @@ void render_group_symbolizer(group_symbolizer const &sym,
{
for (size_t layout_i = 0; layout_i < num_layout_thunks; ++layout_i)
{
const pixel_position &offset = layout_manager.offset_at(layout_i);
pixel_position const& offset = layout_manager.offset_at(layout_i);
pixel_position render_offset = pos + offset;
render_thunks(layout_thunks[layout_i], render_offset);
}
}

View file

@ -24,21 +24,21 @@
namespace mapnik {
point_render_thunk::point_render_thunk(pixel_position const &pos, marker const &m,
agg::trans_affine const &tr, double opacity,
point_render_thunk::point_render_thunk(pixel_position const& pos, marker const& m,
agg::trans_affine const& tr, double opacity,
composite_mode_e comp_op)
: pos_(pos), marker_(std::make_shared<marker>(m)),
tr_(tr), opacity_(opacity), comp_op_(comp_op)
{}
text_render_thunk::text_render_thunk(placements_list const &placements,
text_render_thunk::text_render_thunk(placements_list const& placements,
double opacity, composite_mode_e comp_op,
halo_rasterizer_enum halo_rasterizer)
: placements_(), glyphs_(std::make_shared<std::vector<glyph_info> >()),
opacity_(opacity), comp_op_(comp_op), halo_rasterizer_(halo_rasterizer)
{
std::vector<glyph_info> &glyph_vec = *glyphs_;
std::vector<glyph_info> & glyph_vec = *glyphs_;
size_t glyph_count = 0;
for (glyph_positions_ptr positions : placements)
@ -51,7 +51,7 @@ text_render_thunk::text_render_thunk(placements_list const &placements,
{
glyph_positions_ptr new_positions = std::make_shared<glyph_positions>();
new_positions->reserve(std::distance(positions->begin(), positions->end()));
glyph_positions &new_pos = *new_positions;
glyph_positions & new_pos = *new_positions;
new_pos.set_base_point(positions->get_base_point());
if (positions->marker())
@ -59,7 +59,7 @@ text_render_thunk::text_render_thunk(placements_list const &placements,
new_pos.set_marker(positions->marker(), positions->marker_pos());
}
for (glyph_position const &pos : *positions)
for (glyph_position const& pos : *positions)
{
glyph_vec.push_back(*pos.glyph);
new_pos.push_back(glyph_vec.back(), pos.pos, pos.rot);
@ -70,25 +70,25 @@ text_render_thunk::text_render_thunk(placements_list const &placements,
}
render_thunk_extractor::render_thunk_extractor(box2d<double> &box,
render_thunk_list &thunks,
feature_impl &feature,
render_thunk_extractor::render_thunk_extractor(box2d<double> & box,
render_thunk_list & thunks,
feature_impl & feature,
attributes const& vars,
proj_transform const &prj_trans,
renderer_common &common,
box2d<double> const &clipping_extent)
proj_transform const& prj_trans,
renderer_common & common,
box2d<double> const& clipping_extent)
: box_(box), thunks_(thunks), feature_(feature), vars_(vars), prj_trans_(prj_trans),
common_(common), clipping_extent_(clipping_extent)
{}
void render_thunk_extractor::operator()(point_symbolizer const &sym) const
void render_thunk_extractor::operator()(point_symbolizer const& sym) const
{
composite_mode_e comp_op = get<composite_mode_e>(sym, keys::comp_op, feature_, common_.vars_, src_over);
render_point_symbolizer(
sym, feature_, prj_trans_, common_,
[&](pixel_position const &pos, marker const &marker,
agg::trans_affine const &tr, double opacity) {
[&](pixel_position const& pos, marker const& marker,
agg::trans_affine const& tr, double opacity) {
point_render_thunk thunk(pos, marker, tr, opacity, comp_op);
thunks_.push_back(std::make_shared<render_thunk>(std::move(thunk)));
});
@ -96,7 +96,7 @@ void render_thunk_extractor::operator()(point_symbolizer const &sym) const
update_box();
}
void render_thunk_extractor::operator()(text_symbolizer const &sym) const
void render_thunk_extractor::operator()(text_symbolizer const& sym) const
{
box2d<double> clip_box = clipping_extent_;
text_symbolizer_helper helper(
@ -109,7 +109,7 @@ void render_thunk_extractor::operator()(text_symbolizer const &sym) const
extract_text_thunk(helper, sym);
}
void render_thunk_extractor::operator()(shield_symbolizer const &sym) const
void render_thunk_extractor::operator()(shield_symbolizer const& sym) const
{
box2d<double> clip_box = clipping_extent_;
text_symbolizer_helper helper(
@ -122,7 +122,7 @@ void render_thunk_extractor::operator()(shield_symbolizer const &sym) const
extract_text_thunk(helper, sym);
}
void render_thunk_extractor::extract_text_thunk(text_symbolizer_helper &helper, text_symbolizer const &sym) const
void render_thunk_extractor::extract_text_thunk(text_symbolizer_helper & helper, text_symbolizer const& sym) const
{
double opacity = get<double>(sym, keys::opacity, feature_, common_.vars_, 1.0);
composite_mode_e comp_op = get<composite_mode_e>(sym, keys::comp_op, feature_, common_.vars_, src_over);
@ -137,9 +137,9 @@ void render_thunk_extractor::extract_text_thunk(text_symbolizer_helper &helper,
void render_thunk_extractor::update_box() const
{
label_collision_detector4 &detector = *common_.detector_;
label_collision_detector4 & detector = *common_.detector_;
for (auto const &label : detector)
for (auto const& label : detector)
{
if (box_.width() > 0 && box_.height() > 0)
{
@ -155,8 +155,8 @@ void render_thunk_extractor::update_box() const
}
geometry_type *origin_point(proj_transform const &prj_trans,
renderer_common const &common)
geometry_type *origin_point(proj_transform const& prj_trans,
renderer_common const& common)
{
// note that we choose a point in the middle of the screen to
// try to ensure that we don't get edge artefacts due to any