// Copyright 2016, University of Freiburg, // Chair of Algorithms and Data Structures. // Author: Patrick Brosi #ifndef UTIL_GEO_GRID_H_ #define UTIL_GEO_GRID_H_ #include #include #include #include "util/geo/Geo.h" namespace util { namespace geo { class GridException : public std::runtime_error { public: GridException(std::string const& msg) : std::runtime_error(msg) {} }; template class G, typename T> class Grid { public: // initialization of a point grid with cell width w and cell height h // that covers the area of bounding box bbox Grid(double w, double h, const Box& bbox); // initialization of a point grid with cell width w and cell height h // that covers the area of bounding box bbox // optional parameters specifies whether a value->cell index // should be kept (true by default!) Grid(double w, double h, const Box& bbox, bool buildValIdx); // the empty grid Grid(); // the empty grid Grid(bool buildValIdx); // add object t to this grid void add(G geom, V val); void add(size_t x, size_t y, V val); void get(const Box& btbox, std::set* s) const; void get(const G& geom, double d, std::set* s) const; void get(size_t x, size_t y, std::set* s) const; void remove(V val); void getNeighbors(const V& val, double d, std::set* s) const; void getCellNeighbors(const V& val, size_t d, std::set* s) const; void getCellNeighbors(size_t x, size_t y, size_t xPerm, size_t yPerm, std::set* s) const; std::set > getCells(const V& val) const; size_t getXWidth() const; size_t getYHeight() const; private: double _width; double _height; double _cellWidth; double _cellHeight; Box _bb; size_t _counter; size_t _xWidth; size_t _yHeight; bool _hasValIdx; std::vector > > _grid; std::map > > _index; std::set _removed; Box getBox(size_t x, size_t y) const; size_t getCellXFromX(double lon) const; size_t getCellYFromY(double lat) const; }; #include "util/geo/Grid.tpp" } // namespace geo } // namespace util #endif // UTIL_GEO_GRID_H_