35 #include <octomap_msgs/GetOctomap.h> 36 using octomap_msgs::GetOctomap;
38 #define USAGE "\nUSAGE: octomap_saver [-f] <mapfile.[bt|ot]>\n" \ 39 " -f: Query for the full occupancy octree, instead of just the compact binary one\n" \ 40 " mapfile.bt: filename of map to be saved (.bt: binary tree, .ot: general octree)\n" 47 MapSaver(
const std::string& mapname,
bool full){
49 std::string servname =
"octomap_binary";
51 servname =
"octomap_full";
53 GetOctomap::Request req;
54 GetOctomap::Response resp;
68 ROS_ERROR(
"Error creating octree from received message");
69 if (resp.map.id ==
"ColorOcTree")
70 ROS_WARN(
"You requested a binary map for a ColorOcTree - this is currently not supported. Please add -f to request a full map");
76 std::string suffix = mapname.substr(mapname.length()-3, 3);
79 ROS_ERROR(
"Error writing to file %s", mapname.c_str());
81 }
else if (suffix ==
".ot"){
82 if (!octree->
write(mapname)){
83 ROS_ERROR(
"Error writing to file %s", mapname.c_str());
86 ROS_ERROR(
"Unknown file extension, must be either .bt or .ot");
91 ROS_ERROR(
"Error reading OcTree from stream");
100 int main(
int argc,
char** argv){
102 std::string mapFilename(
"");
103 bool fullmap =
false;
104 if (argc == 3 && strcmp(argv[1],
"-f")==0){
106 mapFilename = std::string(argv[2]);
107 }
else if (argc == 2)
108 mapFilename = std::string(argv[1]);
116 }
catch(std::runtime_error& e){
117 ROS_ERROR(
"octomap_saver exception: %s", e.what());
int main(int argc, char **argv)
std::string resolveName(const std::string &name, bool remap=true) const
bool call(const std::string &service_name, MReq &req, MRes &res)
static octomap::AbstractOcTree * msgToMap(const Octomap &msg)
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
virtual size_t size() const =0
virtual double getResolution() const =0
bool writeBinary(const std::string &filename)
bool write(const std::string &filename) const
MapSaver(const std::string &mapname, bool full)