c++ style
This commit is contained in:
parent
8cc9b06e12
commit
f12b5e06dd
2 changed files with 81 additions and 85 deletions
|
@ -45,27 +45,25 @@ namespace mapnik {
|
||||||
|
|
||||||
class proj_transform;
|
class proj_transform;
|
||||||
|
|
||||||
/* General:
|
// General:
|
||||||
*
|
|
||||||
* The approach here is to run the normal symbolizers, but in
|
// The approach here is to run the normal symbolizers, but in
|
||||||
* a 'virtual' blank environment where the changes that they
|
// a 'virtual' blank environment where the changes that they
|
||||||
* make are recorded (the detector, the render_* calls).
|
// make are recorded (the detector, the render_* calls).
|
||||||
*
|
//
|
||||||
* The recorded boxes are then used to lay out the items and
|
// 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 offsets from old to new positions can be used to perform
|
||||||
* the actual rendering calls.
|
// the actual rendering calls.
|
||||||
*
|
|
||||||
* This should allow us to re-use as much as possible of the
|
// This should allow us to re-use as much as possible of the
|
||||||
* existing symbolizer layout and rendering code while still
|
// existing symbolizer layout and rendering code while still
|
||||||
* being able to interpose our own decisions about whether
|
// being able to interpose our own decisions about whether
|
||||||
* a collision has occured or not.
|
// 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
|
struct point_render_thunk
|
||||||
{
|
{
|
||||||
pixel_position pos_;
|
pixel_position pos_;
|
||||||
|
@ -74,8 +72,8 @@ struct point_render_thunk
|
||||||
double opacity_;
|
double opacity_;
|
||||||
composite_mode_e comp_op_;
|
composite_mode_e comp_op_;
|
||||||
|
|
||||||
point_render_thunk(pixel_position const &pos, marker const &m,
|
point_render_thunk(pixel_position const& pos, marker const& m,
|
||||||
agg::trans_affine const &tr, double opacity,
|
agg::trans_affine const& tr, double opacity,
|
||||||
composite_mode_e comp_op);
|
composite_mode_e comp_op);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -90,65 +88,63 @@ struct text_render_thunk
|
||||||
composite_mode_e comp_op_;
|
composite_mode_e comp_op_;
|
||||||
halo_rasterizer_enum halo_rasterizer_;
|
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,
|
double opacity, composite_mode_e comp_op,
|
||||||
halo_rasterizer_enum halo_rasterizer);
|
halo_rasterizer_enum halo_rasterizer);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
// Variant type for render thunks to allow us to re-render them
|
||||||
* Variant type for render thunks to allow us to re-render them
|
// via a static visitor later.
|
||||||
* via a static visitor later.
|
|
||||||
*/
|
|
||||||
using render_thunk = boost::variant<point_render_thunk,
|
using render_thunk = boost::variant<point_render_thunk,
|
||||||
text_render_thunk>;
|
text_render_thunk>;
|
||||||
using render_thunk_ptr = std::shared_ptr<render_thunk>;
|
using render_thunk_ptr = std::shared_ptr<render_thunk>;
|
||||||
using render_thunk_list = std::list<render_thunk_ptr>;
|
using render_thunk_list = std::list<render_thunk_ptr>;
|
||||||
|
|
||||||
/**
|
// Base class for extracting the bounding boxes associated with placing
|
||||||
* Base class for extracting the bounding boxes associated with placing
|
// a symbolizer at a fake, virtual point - not real geometry.
|
||||||
* a symbolizer at a fake, virtual point - not real geometry.
|
//
|
||||||
*
|
// The bounding boxes can be used for layout, and the thunks are
|
||||||
* The bounding boxes can be used for layout, and the thunks are
|
// used to re-render at locations according to the group layout.
|
||||||
* used to re-render at locations according to the group layout.
|
|
||||||
*/
|
|
||||||
struct render_thunk_extractor : public boost::static_visitor<>
|
struct render_thunk_extractor : public boost::static_visitor<>
|
||||||
{
|
{
|
||||||
render_thunk_extractor(box2d<double> &box,
|
render_thunk_extractor(box2d<double> & box,
|
||||||
render_thunk_list &thunks,
|
render_thunk_list & thunks,
|
||||||
feature_impl &feature,
|
feature_impl & feature,
|
||||||
attributes const& vars,
|
attributes const& vars,
|
||||||
proj_transform const &prj_trans,
|
proj_transform const& prj_trans,
|
||||||
renderer_common &common,
|
renderer_common & common,
|
||||||
box2d<double> const &clipping_extent);
|
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>
|
template <typename T>
|
||||||
void operator()(T const &) const
|
void operator()(T const& ) const
|
||||||
{
|
{
|
||||||
// TODO: warning if unimplemented?
|
// TODO: warning if unimplemented?
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
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_;
|
box2d<double> & box_;
|
||||||
render_thunk_list &thunks_;
|
render_thunk_list & thunks_;
|
||||||
feature_impl & feature_;
|
feature_impl & feature_;
|
||||||
attributes const& vars_;
|
attributes const& vars_;
|
||||||
proj_transform const &prj_trans_;
|
proj_transform const& prj_trans_;
|
||||||
renderer_common &common_;
|
renderer_common & common_;
|
||||||
box2d<double> clipping_extent_;
|
box2d<double> clipping_extent_;
|
||||||
|
|
||||||
void update_box() const;
|
void update_box() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
geometry_type *origin_point(proj_transform const &prj_trans,
|
geometry_type *origin_point(proj_transform const& prj_trans,
|
||||||
renderer_common const &common);
|
renderer_common const& common);
|
||||||
|
|
||||||
template <typename F>
|
template <typename F>
|
||||||
void render_offset_placements(placements_list const& placements,
|
void render_offset_placements(placements_list const& placements,
|
||||||
|
@ -182,12 +178,12 @@ void render_offset_placements(placements_list const& placements,
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename F>
|
template <typename F>
|
||||||
void render_group_symbolizer(group_symbolizer const &sym,
|
void render_group_symbolizer(group_symbolizer const& sym,
|
||||||
feature_impl & feature,
|
feature_impl & feature,
|
||||||
attributes const& vars,
|
attributes const& vars,
|
||||||
proj_transform const & prj_trans,
|
proj_transform const& prj_trans,
|
||||||
box2d<double> const & clipping_extent,
|
box2d<double> const& clipping_extent,
|
||||||
renderer_common &common,
|
renderer_common & common,
|
||||||
F render_thunks)
|
F render_thunks)
|
||||||
{
|
{
|
||||||
// find all column names referenced in the group rules and symbolizers
|
// 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
|
// evalute the repeat key with the matched sub feature if we have one
|
||||||
if (rpt_key_expr)
|
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);
|
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)
|
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;
|
pixel_position render_offset = pos + offset;
|
||||||
|
|
||||||
render_thunks(layout_thunks[layout_i], render_offset);
|
render_thunks(layout_thunks[layout_i], render_offset);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,71 +24,71 @@
|
||||||
|
|
||||||
namespace mapnik {
|
namespace mapnik {
|
||||||
|
|
||||||
point_render_thunk::point_render_thunk(pixel_position const &pos, marker const &m,
|
point_render_thunk::point_render_thunk(pixel_position const& pos, marker const& m,
|
||||||
agg::trans_affine const &tr, double opacity,
|
agg::trans_affine const& tr, double opacity,
|
||||||
composite_mode_e comp_op)
|
composite_mode_e comp_op)
|
||||||
: pos_(pos), marker_(std::make_shared<marker>(m)),
|
: pos_(pos), marker_(std::make_shared<marker>(m)),
|
||||||
tr_(tr), opacity_(opacity), comp_op_(comp_op)
|
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,
|
double opacity, composite_mode_e comp_op,
|
||||||
halo_rasterizer_enum halo_rasterizer)
|
halo_rasterizer_enum halo_rasterizer)
|
||||||
: placements_(), glyphs_(std::make_shared<std::vector<glyph_info> >()),
|
: placements_(), glyphs_(std::make_shared<std::vector<glyph_info> >()),
|
||||||
opacity_(opacity), comp_op_(comp_op), halo_rasterizer_(halo_rasterizer)
|
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;
|
size_t glyph_count = 0;
|
||||||
for (glyph_positions_ptr positions : placements)
|
for (glyph_positions_ptr positions : placements)
|
||||||
{
|
{
|
||||||
glyph_count += std::distance(positions->begin(), positions->end());
|
glyph_count += std::distance(positions->begin(), positions->end());
|
||||||
}
|
}
|
||||||
glyph_vec.reserve(glyph_count);
|
glyph_vec.reserve(glyph_count);
|
||||||
|
|
||||||
for (glyph_positions_ptr positions : placements)
|
for (glyph_positions_ptr positions : placements)
|
||||||
{
|
{
|
||||||
glyph_positions_ptr new_positions = std::make_shared<glyph_positions>();
|
glyph_positions_ptr new_positions = std::make_shared<glyph_positions>();
|
||||||
new_positions->reserve(std::distance(positions->begin(), positions->end()));
|
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());
|
new_pos.set_base_point(positions->get_base_point());
|
||||||
if (positions->marker())
|
if (positions->marker())
|
||||||
{
|
{
|
||||||
new_pos.set_marker(positions->marker(), positions->marker_pos());
|
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);
|
glyph_vec.push_back(*pos.glyph);
|
||||||
new_pos.push_back(glyph_vec.back(), pos.pos, pos.rot);
|
new_pos.push_back(glyph_vec.back(), pos.pos, pos.rot);
|
||||||
}
|
}
|
||||||
|
|
||||||
placements_.push_back(new_positions);
|
placements_.push_back(new_positions);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
render_thunk_extractor::render_thunk_extractor(box2d<double> &box,
|
render_thunk_extractor::render_thunk_extractor(box2d<double> & box,
|
||||||
render_thunk_list &thunks,
|
render_thunk_list & thunks,
|
||||||
feature_impl &feature,
|
feature_impl & feature,
|
||||||
attributes const& vars,
|
attributes const& vars,
|
||||||
proj_transform const &prj_trans,
|
proj_transform const& prj_trans,
|
||||||
renderer_common &common,
|
renderer_common & common,
|
||||||
box2d<double> const &clipping_extent)
|
box2d<double> const& clipping_extent)
|
||||||
: box_(box), thunks_(thunks), feature_(feature), vars_(vars), prj_trans_(prj_trans),
|
: box_(box), thunks_(thunks), feature_(feature), vars_(vars), prj_trans_(prj_trans),
|
||||||
common_(common), clipping_extent_(clipping_extent)
|
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);
|
composite_mode_e comp_op = get<composite_mode_e>(sym, keys::comp_op, feature_, common_.vars_, src_over);
|
||||||
|
|
||||||
render_point_symbolizer(
|
render_point_symbolizer(
|
||||||
sym, feature_, prj_trans_, common_,
|
sym, feature_, prj_trans_, common_,
|
||||||
[&](pixel_position const &pos, marker const &marker,
|
[&](pixel_position const& pos, marker const& marker,
|
||||||
agg::trans_affine const &tr, double opacity) {
|
agg::trans_affine const& tr, double opacity) {
|
||||||
point_render_thunk thunk(pos, marker, tr, opacity, comp_op);
|
point_render_thunk thunk(pos, marker, tr, opacity, comp_op);
|
||||||
thunks_.push_back(std::make_shared<render_thunk>(std::move(thunk)));
|
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();
|
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_;
|
box2d<double> clip_box = clipping_extent_;
|
||||||
text_symbolizer_helper helper(
|
text_symbolizer_helper helper(
|
||||||
|
@ -109,7 +109,7 @@ void render_thunk_extractor::operator()(text_symbolizer const &sym) const
|
||||||
extract_text_thunk(helper, sym);
|
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_;
|
box2d<double> clip_box = clipping_extent_;
|
||||||
text_symbolizer_helper helper(
|
text_symbolizer_helper helper(
|
||||||
|
@ -122,7 +122,7 @@ void render_thunk_extractor::operator()(shield_symbolizer const &sym) const
|
||||||
extract_text_thunk(helper, sym);
|
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);
|
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);
|
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
|
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)
|
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,
|
geometry_type *origin_point(proj_transform const& prj_trans,
|
||||||
renderer_common const &common)
|
renderer_common const& common)
|
||||||
{
|
{
|
||||||
// note that we choose a point in the middle of the screen to
|
// 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
|
// try to ensure that we don't get edge artefacts due to any
|
||||||
|
|
Loading…
Reference in a new issue