2013-11-22 06:47:55 +00:00
|
|
|
#include "bench_framework.hpp"
|
|
|
|
#include <mapnik/map.hpp>
|
|
|
|
#include <mapnik/image_util.hpp>
|
|
|
|
#include <mapnik/load_map.hpp>
|
|
|
|
#include <mapnik/agg_renderer.hpp>
|
|
|
|
#include <mapnik/datasource_cache.hpp>
|
2014-10-08 21:23:33 +00:00
|
|
|
#include <mapnik/font_engine_freetype.hpp>
|
2013-11-22 06:47:55 +00:00
|
|
|
#include <stdexcept>
|
|
|
|
|
|
|
|
class test : public benchmark::test_case
|
|
|
|
{
|
|
|
|
std::string xml_;
|
|
|
|
mapnik::box2d<double> extent_;
|
|
|
|
mapnik::value_integer width_;
|
|
|
|
mapnik::value_integer height_;
|
2014-10-10 00:33:01 +00:00
|
|
|
double scale_factor_;
|
2013-11-22 06:47:55 +00:00
|
|
|
std::string preview_;
|
2022-01-26 22:32:21 +00:00
|
|
|
|
|
|
|
public:
|
2013-11-22 06:47:55 +00:00
|
|
|
test(mapnik::parameters const& params)
|
2022-01-26 22:32:21 +00:00
|
|
|
: test_case(params)
|
|
|
|
, xml_()
|
|
|
|
, extent_()
|
|
|
|
, width_(*params.get<mapnik::value_integer>("width", 256))
|
|
|
|
, height_(*params.get<mapnik::value_integer>("height", 256))
|
|
|
|
, scale_factor_(*params.get<mapnik::value_double>("scale_factor", 1.0))
|
|
|
|
, preview_(*params.get<std::string>("preview", ""))
|
|
|
|
{
|
2013-11-22 06:47:55 +00:00
|
|
|
boost::optional<std::string> map = params.get<std::string>("map");
|
|
|
|
if (!map)
|
|
|
|
{
|
2015-10-01 21:47:25 +00:00
|
|
|
throw std::runtime_error("please provide a --map <path to xml> arg");
|
2013-11-22 06:47:55 +00:00
|
|
|
}
|
|
|
|
xml_ = *map;
|
|
|
|
|
|
|
|
boost::optional<std::string> ext = params.get<std::string>("extent");
|
|
|
|
if (ext && !ext->empty())
|
|
|
|
{
|
|
|
|
if (!extent_.from_string(*ext))
|
|
|
|
throw std::runtime_error("could not parse `extent` string" + *ext);
|
|
|
|
}
|
2014-10-08 21:23:33 +00:00
|
|
|
/*
|
2013-11-22 06:47:55 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
throw std::runtime_error("please provide a --extent=<minx,miny,maxx,maxy> arg");
|
2014-10-08 21:23:33 +00:00
|
|
|
}*/
|
2022-01-26 22:32:21 +00:00
|
|
|
}
|
2013-11-22 06:47:55 +00:00
|
|
|
bool validate() const
|
|
|
|
{
|
2022-01-26 22:32:21 +00:00
|
|
|
mapnik::Map m(width_, height_);
|
|
|
|
mapnik::load_map(m, xml_, true);
|
|
|
|
if (extent_.valid())
|
|
|
|
{
|
2014-10-08 21:23:33 +00:00
|
|
|
m.zoom_to_box(extent_);
|
2022-01-26 22:32:21 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-10-08 21:23:33 +00:00
|
|
|
m.zoom_all();
|
|
|
|
}
|
2022-01-26 22:32:21 +00:00
|
|
|
mapnik::image_rgba8 im(m.width(), m.height());
|
|
|
|
mapnik::agg_renderer<mapnik::image_rgba8> ren(m, im, scale_factor_);
|
2013-11-22 06:47:55 +00:00
|
|
|
ren.apply();
|
2022-01-26 22:32:21 +00:00
|
|
|
if (!preview_.empty())
|
|
|
|
{
|
2014-12-12 16:59:45 +00:00
|
|
|
std::clog << "preview available at " << preview_ << "\n";
|
2022-01-26 22:32:21 +00:00
|
|
|
mapnik::save_to_file(im, preview_);
|
2014-12-12 16:59:45 +00:00
|
|
|
}
|
2013-11-22 06:47:55 +00:00
|
|
|
return true;
|
|
|
|
}
|
2014-12-12 16:59:45 +00:00
|
|
|
bool operator()() const
|
2013-11-22 06:47:55 +00:00
|
|
|
{
|
2022-01-26 22:32:21 +00:00
|
|
|
if (!preview_.empty())
|
|
|
|
{
|
2014-12-12 16:59:45 +00:00
|
|
|
return false;
|
|
|
|
}
|
2022-01-26 22:32:21 +00:00
|
|
|
mapnik::Map m(width_, height_);
|
|
|
|
mapnik::load_map(m, xml_);
|
|
|
|
if (extent_.valid())
|
|
|
|
{
|
2014-10-08 21:23:33 +00:00
|
|
|
m.zoom_to_box(extent_);
|
2022-01-26 22:32:21 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-10-08 21:23:33 +00:00
|
|
|
m.zoom_all();
|
|
|
|
}
|
2022-01-26 22:32:21 +00:00
|
|
|
for (unsigned i = 0; i < iterations_; ++i)
|
2013-11-22 06:47:55 +00:00
|
|
|
{
|
2022-01-26 22:32:21 +00:00
|
|
|
mapnik::image_rgba8 im(m.width(), m.height());
|
|
|
|
mapnik::agg_renderer<mapnik::image_rgba8> ren(m, im, scale_factor_);
|
2013-11-22 06:47:55 +00:00
|
|
|
ren.apply();
|
|
|
|
}
|
2014-12-12 16:59:45 +00:00
|
|
|
return true;
|
2013-11-22 06:47:55 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
int main(int argc, char** argv)
|
|
|
|
{
|
2015-09-14 13:21:51 +00:00
|
|
|
int return_value = 0;
|
2013-11-22 06:47:55 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
mapnik::parameters params;
|
2022-01-26 22:32:21 +00:00
|
|
|
benchmark::handle_args(argc, argv, params);
|
2013-11-22 06:47:55 +00:00
|
|
|
boost::optional<std::string> name = params.get<std::string>("name");
|
|
|
|
if (!name)
|
|
|
|
{
|
|
|
|
std::clog << "please provide a name for this test\n";
|
|
|
|
return -1;
|
|
|
|
}
|
2022-01-26 22:32:21 +00:00
|
|
|
mapnik::freetype_engine::register_fonts("./fonts/", true);
|
2013-11-22 06:47:55 +00:00
|
|
|
mapnik::datasource_cache::instance().register_datasources("./plugins/input/");
|
|
|
|
{
|
|
|
|
test test_runner(params);
|
2022-01-26 22:32:21 +00:00
|
|
|
return_value = run(test_runner, *name);
|
2013-11-22 06:47:55 +00:00
|
|
|
}
|
2022-01-26 22:32:21 +00:00
|
|
|
} catch (std::exception const& ex)
|
2013-11-22 06:47:55 +00:00
|
|
|
{
|
|
|
|
std::clog << ex.what() << "\n";
|
|
|
|
return -1;
|
|
|
|
}
|
2015-09-14 13:21:51 +00:00
|
|
|
return return_value;
|
2013-11-22 06:47:55 +00:00
|
|
|
}
|