diff --git a/include/mapnik/grid/grid.hpp b/include/mapnik/grid/grid.hpp index 223d4a209..a00479e93 100644 --- a/include/mapnik/grid/grid.hpp +++ b/include/mapnik/grid/grid.hpp @@ -57,8 +57,8 @@ public: static const value_type base_mask; private: - unsigned width_; - unsigned height_; + std::size_t width_; + std::size_t height_; std::string key_; data_type data_; std::string id_name_; @@ -70,7 +70,7 @@ private: public: - hit_grid(int width, int height, std::string const& key); + hit_grid(std::size_t width, std::size_t height, std::string const& key); hit_grid(hit_grid const& rhs); @@ -145,20 +145,20 @@ public: return data_.data(); } - inline value_type const * get_row(unsigned row) const + inline value_type const * get_row(std::size_t row) const { return data_.get_row(row); } - inline mapnik::grid_view get_view(unsigned x, unsigned y, unsigned w, unsigned h) + inline mapnik::grid_view get_view(std::size_t x, std::size_t y, std::size_t w, std::size_t h) { - return mapnik::grid_view(x,y,w,h, - data_,key_,id_name_,names_,f_keys_,features_); + return mapnik::grid_view(x, y, w, h, + data_, key_, id_name_, names_, f_keys_, features_); } private: - inline bool checkBounds(unsigned x, unsigned y) const + inline bool checkBounds(std::size_t x, std::size_t y) const { return (x < width_ && y < height_); } @@ -166,39 +166,39 @@ private: hit_grid& operator=(const hit_grid&); public: - inline void setPixel(int x,int y,value_type feature_id) + inline void setPixel(std::size_t x, std::size_t y, value_type feature_id) { - if (checkBounds(x,y)) + if (checkBounds(x, y)) { - data_(x,y) = feature_id; + data_(x, y) = feature_id; } } - inline unsigned width() const + inline std::size_t width() const { return width_; } - inline unsigned height() const + inline std::size_t height() const { return height_; } - inline void set_rectangle(value_type id,image_rgba8 const& data,int x0,int y0) + inline void set_rectangle(value_type id, image_rgba8 const& data, std::size_t x0, std::size_t y0) { - box2d ext0(0,0,width_,height_); - box2d ext1(x0,y0,x0+data.width(),y0+data.height()); + box2d ext0(0, 0, width_, height_); + box2d ext1(x0, y0, x0 + data.width(), y0 + data.height()); if (ext0.intersects(ext1)) { box2d box = ext0.intersect(ext1); - for (int y = box.miny(); y < box.maxy(); ++y) + for (std::size_t y = box.miny(); y < box.maxy(); ++y) { value_type* row_to = data_.get_row(y); - unsigned int const * row_from = data.get_row(y-y0); + image_rgba8::pixel_type const * row_from = data.get_row(y - y0); - for (int x = box.minx(); x < box.maxx(); ++x) + for (std::size_t x = box.minx(); x < box.maxx(); ++x) { - unsigned rgba = row_from[x-x0]; + image_rgba8::pixel_type rgba = row_from[x - x0]; unsigned a = (rgba >> 24) & 0xff; // if the pixel is more than a tenth // opaque then burn in the feature id diff --git a/src/grid/grid.cpp b/src/grid/grid.cpp index 0ca796558..279ac4c6e 100644 --- a/src/grid/grid.cpp +++ b/src/grid/grid.cpp @@ -37,7 +37,7 @@ template const typename hit_grid::value_type hit_grid::base_mask = std::numeric_limits::min(); template -hit_grid::hit_grid(int width, int height, std::string const& key) +hit_grid::hit_grid(std::size_t width, std::size_t height, std::string const& key) : width_(width), height_(height), key_(key), diff --git a/test/visual/renderer.hpp b/test/visual/renderer.hpp index d3b9cda77..6d99c3a74 100644 --- a/test/visual/renderer.hpp +++ b/test/visual/renderer.hpp @@ -33,6 +33,7 @@ // mapnik #include #include +#include #if defined(HAVE_CAIRO) #include #include @@ -139,14 +140,49 @@ struct svg_renderer : renderer_base }; #endif -struct grid_renderer : renderer_base +struct grid_renderer : renderer_base { static constexpr const char * name = "grid"; + void convert(mapnik::grid::data_type const & grid, image_type & image) const + { + for (std::size_t y = 0; y < grid.height(); ++y) + { + mapnik::grid::value_type const * grid_row = grid.get_row(y); + image_type::pixel_type * image_row = image.get_row(y); + for (std::size_t x = 0; x < grid.width(); ++x) + { + mapnik::grid::value_type val = grid_row[x]; + + if (val == mapnik::grid::base_mask) + { + image_row[x] = 0; + continue; + } + if (val < 0) + { + throw std::runtime_error("grid renderer: feature id is negative."); + } + + val *= 100; + + if (val > 0x00ffffff) + { + throw std::runtime_error("grid renderer: feature id is too high."); + } + + image_row[x] = val | 0xff000000; + } + } + } + image_type render(mapnik::Map const & map, double scale_factor) const { + mapnik::grid grid(map.width(), map.height(), "__id__"); + mapnik::grid_renderer ren(map, grid, scale_factor); + ren.apply(); image_type image(map.width(), map.height()); - // TODO: Render grid here. + convert(grid.data(), image); return image; } }; @@ -156,7 +192,7 @@ class renderer { public: renderer(boost::filesystem::path const & output_dir, boost::filesystem::path const & reference_dir, bool overwrite) - : output_dir(output_dir), reference_dir(reference_dir), overwrite(overwrite) + : ren(), output_dir(output_dir), reference_dir(reference_dir), overwrite(overwrite) { } @@ -208,7 +244,7 @@ private: return s.str(); } - Renderer ren; + const Renderer ren; boost::filesystem::path const & output_dir; boost::filesystem::path const & reference_dir; const bool overwrite; diff --git a/test/visual/run.cpp b/test/visual/run.cpp index f9b5fb266..89e7b0a67 100644 --- a/test/visual/run.cpp +++ b/test/visual/run.cpp @@ -87,13 +87,21 @@ int main(int argc, char** argv) report_type report = vm.count("verbose") ? report_type((console_report())) : report_type((console_short_report())); result_list results; - if (vm.count("styles")) + try { - results = run.test(vm["styles"].as>(), report); + if (vm.count("styles")) + { + results = run.test(vm["styles"].as>(), report); + } + else + { + results = run.test_all(report); + } } - else + catch (std::exception & e) { - results = run.test_all(report); + std::cerr << "Error runnig tests: " << e.what() << std::endl; + return 1; } unsigned failed_count = mapnik::util::apply_visitor(summary_visitor(results), report); diff --git a/test/visual/runner.cpp b/test/visual/runner.cpp index 02ce46a3e..317c7cf62 100644 --- a/test/visual/runner.cpp +++ b/test/visual/runner.cpp @@ -67,8 +67,8 @@ runner::runner(runner::path_type const & styles_dir, #if defined(SVG_RENDERER) ,renderer(output_dir_, reference_dir_, overwrite) #endif - /*,renderer(output_dir_, reference_dir_, overwrite)*/ - } + ,renderer(output_dir_, reference_dir_, overwrite) + } { } diff --git a/test/visual/runner.hpp b/test/visual/runner.hpp index 21fcb9ed0..5a4fd39a4 100644 --- a/test/visual/runner.hpp +++ b/test/visual/runner.hpp @@ -42,7 +42,7 @@ class runner #if defined(SVG_RENDERER) ,renderer #endif - /*renderer*/>; + ,renderer>; using path_type = boost::filesystem::path; using files_iterator = std::vector::const_iterator;