Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #ifndef GRIDMAP2D_GRIDMAP2D_H_
00036 #define GRIDMAP2D_GRIDMAP2D_H_
00037
00038 #include <opencv2/core/core.hpp>
00039 #include <opencv2/imgproc/imgproc.hpp>
00040 #include <nav_msgs/OccupancyGrid.h>
00041
00042
00043
00044
00045
00046 namespace gridmap_2d{
00052 class GridMap2D {
00053 public:
00054 GridMap2D();
00055 GridMap2D(const nav_msgs::OccupancyGridConstPtr& gridMap);
00056 virtual ~GridMap2D();
00057
00058 void mapToWorld(unsigned int mx, unsigned int my, double& wx, double& wy) const;
00059 bool worldToMap(double wx, double wy, unsigned int& mx, unsigned int& my) const;
00060 void worldToMapNoBounds(double wx, double wy, unsigned int& mx, unsigned int& my) const;
00061
00063 bool inMapBounds(double wx, double wy) const;
00064
00068 void inflateMap(double inflationRaduis);
00069
00071 inline double worldDist(unsigned x1, unsigned y1, unsigned x2, unsigned y2){
00072 return worldDist(cv::Point(x1, y1), cv::Point(x2, y2));
00073 }
00074
00075 inline double worldDist(const cv::Point& p1, const cv::Point& p2){
00076 return GridMap2D::pointDist(p1, p2) * m_mapInfo.resolution;
00077 }
00078
00080 static inline double pointDist(const cv::Point& p1, const cv::Point& p2){
00081 return sqrt(pointDist2(p1, p2));
00082 }
00083
00085 static inline double pointDist2(const cv::Point& p1, const cv::Point& p2){
00086 return (p1.x - p2.x)*(p1.x - p2.x) + (p1.y - p2.y)*(p1.y - p2.y);
00087 }
00088
00090 float distanceMapAt(double wx, double wy) const;
00091
00093 float distanceMapAtCell(unsigned int mx, unsigned int my) const;
00094
00096 uchar binaryMapAt(double wx, double wy) const;
00097
00099 uchar binaryMapAtCell(unsigned int mx, unsigned int my) const;
00100
00103 bool isOccupiedAt(double wx, double wy) const;
00104
00106 bool isOccupiedAtCell(unsigned int mx, unsigned int my) const;
00107
00109 void setMap(const nav_msgs::OccupancyGridConstPtr& gridMap);
00110
00112 void setMap(const cv::Mat& binaryMap);
00113
00114 inline const nav_msgs::MapMetaData& getInfo() const {return m_mapInfo;}
00115 inline float getResolution() const {return m_mapInfo.resolution; };
00117 inline const std::string getFrameID() const {return m_frameId;}
00119 const cv::Mat& distanceMap() const {return m_distMap;}
00121 const cv::Mat& binaryMap() const {return m_binaryMap;}
00123 inline const CvSize size() const {return m_binaryMap.size();};
00124
00125
00126 protected:
00127 cv::Mat m_binaryMap;
00128 cv::Mat m_distMap;
00129 nav_msgs::MapMetaData m_mapInfo;
00130 std::string m_frameId;
00131
00132 };
00133
00134 typedef boost::shared_ptr< GridMap2D> GridMap2DPtr;
00135 }
00136
00137 #endif