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 #include <global_planner_tests/easy_costmap.h>
00036 #include <global_planner_tests/util.h>
00037 #include <map_server/image_loader.h>
00038 #include <string>
00039 #include <vector>
00040 #include <algorithm>
00041
00042 namespace global_planner_tests
00043 {
00044
00045 EasyCostmap::EasyCostmap(const std::string& filename, const double resolution, const bool origin_at_center)
00046 {
00047 loadMapFromFile(filename, resolution, origin_at_center);
00048 }
00049
00050 void EasyCostmap::loadMapFromFile(const std::string& filename, const double resolution, const bool origin_at_center)
00051 {
00052 double origin[3] = {0.0, 0.0, 0.0};
00053 nav_msgs::GetMap::Response map_resp;
00054 map_server::loadMapFromFile(&map_resp, resolve_filename(filename).c_str(), resolution, true, 0.0, 0.0, origin, RAW);
00055
00056 if (origin_at_center)
00057 {
00058 map_resp.map.info.origin.position.x = map_resp.map.info.width * resolution / -2;
00059 map_resp.map.info.origin.position.y = map_resp.map.info.height * resolution / -2;
00060 }
00061 original_grid_ = map_resp.map;
00062 original_grid_.header.frame_id = "map";
00063 reset();
00064 }
00065
00066 void EasyCostmap::reset()
00067 {
00068 nav_grid::NavGridInfo new_info;
00069 new_info.width = original_grid_.info.width;
00070 new_info.height = original_grid_.info.height;
00071 new_info.resolution = original_grid_.info.resolution;
00072 new_info.frame_id = original_grid_.header.frame_id;
00073 new_info.origin_x = original_grid_.info.origin.position.x;
00074 new_info.origin_y = original_grid_.info.origin.position.y;
00075
00076 if (info_ != new_info)
00077 {
00078 info_ = new_info;
00079 data_.resize(info_.width * info_.height);
00080 }
00081 for (unsigned int i=0; i < data_.size(); i++)
00082 {
00083 data_[i] = static_cast<unsigned char>(original_grid_.data[i]);
00084 }
00085 }
00086
00087 }