GridMap2D.h
Go to the documentation of this file.
00001 /*
00002  * A simple 2D gridmap structure
00003  *
00004  * Copyright 2011 Armin Hornung, University of Freiburg
00005  *
00006  * Redistribution and use in source and binary forms, with or without
00007  * modification, are permitted provided that the following conditions are met:
00008  *
00009  *     * Redistributions of source code must retain the above copyright
00010  *       notice, this list of conditions and the following disclaimer.
00011  *     * Redistributions in binary form must reproduce the above copyright
00012  *       notice, this list of conditions and the following disclaimer in the
00013  *       documentation and/or other materials provided with the distribution.
00014  *     * Neither the name of the University of Freiburg nor the names of its
00015  *       contributors may be used to endorse or promote products derived from
00016  *       this software without specific prior written permission.
00017  *
00018  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00019  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00020  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00021  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00022  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00023  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00024  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00025  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00026  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00027  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00028  * POSSIBILITY OF SUCH DAMAGE.
00029  */
00030 
00031 
00032 #ifndef GRIDMAP2D_GRIDMAP2D_H_
00033 #define GRIDMAP2D_GRIDMAP2D_H_
00034 
00035 #include <opencv2/core/core.hpp>
00036 #include <opencv2/imgproc/imgproc.hpp>
00037 #include <nav_msgs/OccupancyGrid.h>
00038 
00039 
00040 
00041 
00042 
00043 namespace gridmap_2d{
00049 class GridMap2D {
00050 public:
00051   GridMap2D();
00053   GridMap2D(const nav_msgs::OccupancyGridConstPtr& grid_map, bool unknown_as_obstacle = false);
00055   GridMap2D(const GridMap2D& other);
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 
00102   uchar& binaryMapAtCell(unsigned int mx, unsigned int my);
00103 
00106   bool isOccupiedAt(double wx, double wy) const;
00107 
00109   bool isOccupiedAtCell(unsigned int mx, unsigned int my) const;
00110 
00112   void setMap(const nav_msgs::OccupancyGridConstPtr& grid_map, bool unknown_as_obstacle = false);
00113 
00115   nav_msgs::OccupancyGrid toOccupancyGridMsg() const;
00116 
00118   void setMap(const cv::Mat& binary_map);
00119 
00121   void updateDistanceMap();
00122 
00123   inline const nav_msgs::MapMetaData& getInfo() const {return m_mapInfo;}
00124   inline float getResolution() const {return m_mapInfo.resolution; }
00126   inline const std::string getFrameID() const {return m_frameId;}
00128   const cv::Mat& distanceMap() const {return m_distMap;}
00130   const cv::Mat& binaryMap() const {return m_binaryMap;}
00132   inline const CvSize size() const {return m_binaryMap.size();}
00133 
00134   const static uchar FREE = 255;  
00135   const static uchar OCCUPIED = 0; 
00136 
00137 protected:
00138   cv::Mat m_binaryMap;  
00139   cv::Mat m_distMap;            
00140   nav_msgs::MapMetaData m_mapInfo;
00141   std::string m_frameId;        
00142 
00143 };
00144 
00145 typedef boost::shared_ptr< GridMap2D> GridMap2DPtr;
00146 typedef boost::shared_ptr<const GridMap2D> GridMap2DConstPtr;
00147 }
00148 
00149 #endif /* GRIDMAP2D_H_ */


gridmap_2d
Author(s): Armin Hornung
autogenerated on Sat Jun 8 2019 20:21:01