Merge branch 'master' into large_csv

This commit is contained in:
artemp 2015-06-19 17:30:18 +02:00
commit fec6d11560
10 changed files with 90 additions and 46 deletions

View file

@ -45,6 +45,7 @@ benchmarks = [
"test_rendering_shared_map.cpp",
"test_offset_converter.cpp",
"test_marker_cache.cpp",
"test_quad_tree.cpp",
# "test_numeric_cast_vs_static_cast.cpp",
]
for cpp_test in benchmarks:

View file

@ -49,3 +49,11 @@ run test_offset_converter 10 1000
--height 600 \
--iterations 20 \
--threads 10
./benchmark/out/test_quad_tree \
--iterations 10000 \
--threads 1
./benchmark/out/test_quad_tree \
--iterations 10000 \
--threads 10

View file

@ -0,0 +1,54 @@
#include "bench_framework.hpp"
#include <mapnik/quad_tree.hpp>
#include <random>
using quad_tree_type = mapnik::quad_tree<std::size_t>;
class test : public benchmark::test_case
{
public:
test(mapnik::parameters const& params)
: test_case(params) {}
bool validate() const
{
return true;
}
bool operator()() const
{
std::random_device rd;
std::default_random_engine engine(rd());
std::uniform_int_distribution<int> uniform_dist(0, 2048);
quad_tree_type tree(mapnik::box2d<double>(0,0,2048,2048));
//populate
for (size_t i = 0; i < iterations_; ++i)
{
int cx = uniform_dist(engine);
int cy = uniform_dist(engine);
int sx = 0.2 * uniform_dist(engine);
int sy = 0.2 * uniform_dist(engine);
mapnik::box2d<double> box(cx - sx,cy - sy, cx + sx, cy + sy);
tree.insert(i, box);
}
// bounding box query
std::size_t count=0;
for (size_t i = 0; i < iterations_; ++i)
{
int cx = uniform_dist(engine);
int cy = uniform_dist(engine);
int sx = 0.4 * uniform_dist(engine);
int sy = 0.4 * uniform_dist(engine);
mapnik::box2d<double> box(cx - sx,cy - sy, cx + sx, cy + sy);
auto itr = tree.query_in_box(box);
auto end = tree.query_end();
for ( ;itr != end; ++itr)
{
++count;
}
}
return true;
}
};
BENCHMARK(test,"quad_tree creation")

View file

@ -78,7 +78,7 @@ public:
tree_t::query_iterator end = tree_.query_end();
for ( ;itr != end; ++itr)
{
if (itr->intersects(box)) return false;
if (itr->get().intersects(box)) return false;
}
tree_.insert(box,box);
return true;
@ -108,7 +108,7 @@ public:
for ( ;itr != end; ++itr)
{
if (itr->intersects(box)) return false;
if (itr->get().intersects(box)) return false;
}
return true;
}
@ -155,7 +155,7 @@ public:
for ( ;itr != end; ++itr)
{
if (itr->box.intersects(box)) return false;
if (itr->get().box.intersects(box)) return false;
}
return true;
@ -173,7 +173,7 @@ public:
for (;itr != end; ++itr)
{
if (itr->box.intersects(margin_box))
if (itr->get().box.intersects(margin_box))
{
return false;
}
@ -201,7 +201,7 @@ public:
for ( ;itr != end; ++itr)
{
if (itr->box.intersects(margin_box) || (text == itr->text && itr->box.intersects(repeat_box)))
if (itr->get().box.intersects(margin_box) || (text == itr->get().text && itr->get().box.intersects(repeat_box)))
{
return false;
}

View file

@ -26,17 +26,7 @@
// mapnik
#include <mapnik/box2d.hpp>
#include <mapnik/util/noncopyable.hpp>
// boost
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
#pragma GCC diagnostic ignored "-Wunused-local-typedef"
#pragma GCC diagnostic ignored "-Wshadow"
#pragma GCC diagnostic ignored "-Wsign-conversion"
#pragma GCC diagnostic ignored "-Wconversion"
#include <boost/ptr_container/ptr_vector.hpp>
#pragma GCC diagnostic pop
#include <mapnik/make_unique.hpp>
// stl
#include <algorithm>
#include <vector>
@ -89,17 +79,16 @@ class quad_tree : util::noncopyable
~node () {}
};
using nodes_t = boost::ptr_vector<node>;
using nodes_t = std::vector<std::unique_ptr<node> >;
using cont_t = typename node::cont_t;
using node_data_iterator = typename cont_t::iterator;
public:
using iterator = typename nodes_t::iterator;
using const_iterator = typename nodes_t::const_iterator;
using result_t = typename boost::ptr_vector<T,boost::view_clone_allocator>;
using result_t = typename std::vector<std::reference_wrapper<T> >;
using query_iterator = typename result_t::iterator;
explicit quad_tree(box2d<double> const& ext,
unsigned int max_depth = 8,
double ratio = 0.55)
@ -108,8 +97,8 @@ public:
query_result_(),
nodes_()
{
nodes_.push_back(new node(ext));
root_ = &nodes_[0];
nodes_.push_back(std::make_unique<node>(ext));
root_ = nodes_[0].get();
}
void insert(T data, box2d<double> const& box)
@ -145,8 +134,8 @@ public:
{
box2d<double> ext = root_->extent_;
nodes_.clear();
nodes_.push_back(new node(ext));
root_ = &nodes_[0];
nodes_.push_back(std::make_unique<node>(ext));
root_ = nodes_[0].get();
}
box2d<double> const& extent() const
@ -163,12 +152,9 @@ private:
box2d<double> const& node_extent = node_->extent();
if (box.intersects(node_extent))
{
node_data_iterator i=node_->begin();
node_data_iterator end=node_->end();
while ( i!=end)
for (auto & n : *node_)
{
result.push_back(&(*i));
++i;
result.push_back(std::ref(n));
}
for (int k = 0; k < 4; ++k)
{
@ -195,8 +181,8 @@ private:
{
if (!n->children_[i])
{
nodes_.push_back(new node(ext[i]));
n->children_[i]=&nodes_.back();
nodes_.push_back(std::make_unique<node>(ext[i]));
n->children_[i]=nodes_.back().get();
}
do_insert_data(data,box,n->children_[i],depth);
return;
@ -208,8 +194,6 @@ private:
void split_box(box2d<double> const& node_extent,box2d<double> * ext)
{
//coord2d c=node_extent.center();
double width=node_extent.width();
double height=node_extent.height();

View file

@ -24,6 +24,7 @@
#define MAPNIK_SVG_PARSER_HPP
// mapnik
#include <mapnik/config.hpp>
#include <mapnik/svg/svg_path_attributes.hpp>
#include <mapnik/svg/svg_converter.hpp>
#include <mapnik/svg/svg_path_adapter.hpp>
@ -35,7 +36,7 @@
namespace mapnik { namespace svg {
class svg_parser : private util::noncopyable
class MAPNIK_DECL svg_parser : private util::noncopyable
{
public:
explicit svg_parser(svg_converter_type & path);

View file

@ -230,11 +230,9 @@ void agg_renderer<T0,T1>::process(debug_symbolizer const& sym,
}
else if (mode == DEBUG_SYM_MODE_COLLISION)
{
typename detector_type::query_iterator itr = common_.detector_->begin();
typename detector_type::query_iterator end = common_.detector_->end();
for ( ;itr!=end; ++itr)
for (auto const& n : *common_.detector_)
{
draw_rect(pixmap_, itr->box);
draw_rect(pixmap_, n.get().box);
}
}
else if (mode == DEBUG_SYM_MODE_VERTEX)

View file

@ -106,11 +106,9 @@ void cairo_renderer<T>::process(debug_symbolizer const& sym,
if (mode == DEBUG_SYM_MODE_COLLISION)
{
typename detector_type::query_iterator itr = common_.detector_->begin();
typename detector_type::query_iterator end = common_.detector_->end();
for ( ;itr!=end; ++itr)
for (auto & n : *common_.detector_)
{
render_debug_box(context_, itr->box);
render_debug_box(context_, n.get().box);
}
}
else if (mode == DEBUG_SYM_MODE_VERTEX)

View file

@ -219,11 +219,11 @@ void render_thunk_extractor::update_box() const
{
if (box_.width() > 0 && box_.height() > 0)
{
box_.expand_to_include(label.box);
box_.expand_to_include(label.get().box);
}
else
{
box_ = label.box;
box_ = label.get().box;
}
}

@ -1 +1 @@
Subproject commit bdbab20649674eec2c793b83dd05bbfb379321f8
Subproject commit 9702e69c49b60ff49da4c48d1e33e54289b9c4b1