#include "bench_framework.hpp" #include #include #include #include #include #include #include class test : public benchmark::test_case { std::string xml_; mapnik::box2d extent_; mapnik::value_integer width_; mapnik::value_integer height_; double scale_factor_; std::string preview_; public: test(mapnik::parameters const& params) : test_case(params) , xml_() , extent_() , width_(*params.get("width", 256)) , height_(*params.get("height", 256)) , scale_factor_(*params.get("scale_factor", 1.0)) , preview_(*params.get("preview", "")) { boost::optional map = params.get("map"); if (!map) { throw std::runtime_error("please provide a --map arg"); } xml_ = *map; boost::optional ext = params.get("extent"); if (ext && !ext->empty()) { if (!extent_.from_string(*ext)) throw std::runtime_error("could not parse `extent` string" + *ext); } /* else { throw std::runtime_error("please provide a --extent= arg"); }*/ } bool validate() const { mapnik::Map m(width_, height_); mapnik::load_map(m, xml_, true); if (extent_.valid()) { m.zoom_to_box(extent_); } else { m.zoom_all(); } mapnik::image_rgba8 im(m.width(), m.height()); mapnik::agg_renderer ren(m, im, scale_factor_); ren.apply(); if (!preview_.empty()) { std::clog << "preview available at " << preview_ << "\n"; mapnik::save_to_file(im, preview_); } return true; } bool operator()() const { if (!preview_.empty()) { return false; } mapnik::Map m(width_, height_); mapnik::load_map(m, xml_); if (extent_.valid()) { m.zoom_to_box(extent_); } else { m.zoom_all(); } for (unsigned i = 0; i < iterations_; ++i) { mapnik::image_rgba8 im(m.width(), m.height()); mapnik::agg_renderer ren(m, im, scale_factor_); ren.apply(); } return true; } }; int main(int argc, char** argv) { int return_value = 0; try { mapnik::parameters params; benchmark::handle_args(argc, argv, params); boost::optional name = params.get("name"); if (!name) { std::clog << "please provide a name for this test\n"; return -1; } mapnik::freetype_engine::register_fonts("./fonts/", true); mapnik::datasource_cache::instance().register_datasources("./plugins/input/"); { test test_runner(params); return_value = run(test_runner, *name); } } catch (std::exception const& ex) { std::clog << ex.what() << "\n"; return -1; } return return_value; }