Jafar
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
PositionMap.hpp
00001 
00014 #ifndef LGL_POSITION_MAP_HPP
00015 #define LGL_POSITION_MAP_HPP
00016 
00017 #include <vector>
00018 #include <ostream>
00019 
00020 #include <lgl/FlexGrid.hpp>
00021 #include <lgl/GeoData.hpp>
00022 
00023 namespace jafar {
00024   namespace lgl {
00025 
00027    struct Pos2d {
00028     int x; 
00029     int y;
00030 
00031     Pos2d():x(0),y(0) {}
00032     Pos2d(int _x,int _y):x(_x),y(_y) {}
00033   
00034     void setPos(int _x, int _y) {x=_x;y=_y;}
00035 
00036 
00037     bool operator==(const  Pos2d &rhs) const
00038     {
00039       return (x == rhs.x) && (y == rhs.y);
00040     }  
00041 
00042    };
00043 
00045    struct  RasterIndex2d {
00046   
00047     int i; 
00048     int j;
00049 
00050     RasterIndex2d():i(0),j(0) {}
00051     RasterIndex2d(int _i,int _j):i(_i),j(_j) {}
00052   
00053     void setPos(int _i, int _j) {i=_i;j=_j;}
00054   
00055    };
00056 
00058    inline std::ostream& operator<< (std::ostream& out, const Pos2d& pos) {
00059     out << "(" << pos.x <<":" << pos.y << ")";
00060     return out;
00061    }
00062     
00064    inline std::ostream& operator<< (std::ostream& out, const RasterIndex2d& cell) {
00065     out << "(" << cell.i <<":" << cell.j << ")";
00066     return out;
00067    }
00068 
00069    enum {LEFT, TOP, RIGHT, BOTTOM};
00070    
00071    typedef FlexGrid<Pos2d> PosMap;
00072 
00077    class PositionMap {
00078     
00079    private :
00080 
00081     int rasterxsize, rasterysize;
00082 
00083     // this array contains all LEFT/RIGHT positions for raster cells
00084     PosMap xpos;
00085     // this array contains all TOP/BOTTOM positions for raster cells
00086     PosMap ypos;
00087     
00088     friend class NavGraph;
00089 
00090    public:
00091     
00092     PositionMap(const GeoData& grid);
00093       
00094     ~PositionMap() {}
00095       
00096     bool getPosForRasterCell(int i, int j, std::vector<Pos2d>& pos) const;
00097     int getRasterCell(std::vector< RasterIndex2d>& cells, const Pos2d& pos) const;
00098       
00099     // get all the neighboors of the given position
00100     bool getNeighboors(const Pos2d& pos, std::vector<Pos2d*>& nb);
00101       
00102     int nbPositions() const {
00103       return xpos.size()+ypos.size();
00104     }
00105 
00106    };
00107   }
00108 }
00109 
00110 #endif //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on Wed Oct 15 2014 00:37:24 for Jafar by doxygen 1.7.6.1
LAAS-CNRS