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
00041 #include <occupancy_grid_utils/coordinate_conversions.h>
00042
00043 namespace occupancy_grid_utils
00044 {
00045
00046 namespace gm=geometry_msgs;
00047 namespace nm=nav_msgs;
00048
00049 gm::Polygon cellPolygon (const nm::MapMetaData& info, const Cell& c)
00050 {
00051 const float dx[4] = {0.0, 0.0, 1.0, 1.0};
00052 const float dy[4] = {0.0, 1.0, 1.0, 0.0};
00053
00054 const tf::Transform trans = mapToWorld(info);
00055 gm::Polygon p;
00056 p.points.resize(4);
00057 for (unsigned i=0; i<4; i++) {
00058 tf::Point pt((c.x+dx[i])*info.resolution, (c.y+dy[i])*info.resolution, 0.0);
00059 tf::Point transformed = trans*pt;
00060 p.points[i].x = transformed.x();
00061 p.points[i].y = transformed.y();
00062 p.points[i].z = transformed.z();
00063 }
00064 return p;
00065 }
00066
00067
00068 gm::Polygon gridPolygon (const nm::MapMetaData& info)
00069 {
00070 const float x[4] = {0.0, 0.0, 1.0, 1.0};
00071 const float y[4] = {0.0, 1.0, 1.0, 0.0};
00072
00073 const tf::Transform trans = mapToWorld(info);
00074 gm::Polygon p;
00075 p.points.resize(4);
00076
00077 for (unsigned i=0; i<4; i++) {
00078 tf::Point pt(x[i]*info.resolution*info.width, y[i]*info.resolution*info.height, 0.0);
00079 tf::Point transformed=trans*pt;
00080 p.points[i].x = transformed.x();
00081 p.points[i].y = transformed.y();
00082 p.points[i].z = transformed.z();
00083 }
00084 return p;
00085 }
00086
00087 void verifyDataSize (const nm::OccupancyGrid& g)
00088 {
00089 const size_t expected = g.info.height*g.info.width;
00090 if (expected!=g.data.size())
00091 throw std::logic_error("OccupancyGrid reported size and its real data size"
00092 " differs. Corrupted OccupancyGrid?");
00093 }
00094
00095
00096 }