ros_map.cc
Go to the documentation of this file.
00001 /*
00002  * Copyright 2017 The Cartographer Authors
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *      http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00017 #include "cartographer_ros/ros_map.h"
00018 
00019 #include "absl/strings/str_cat.h"
00020 
00021 namespace cartographer_ros {
00022 
00023 void WritePgm(const ::cartographer::io::Image& image, const double resolution,
00024               ::cartographer::io::FileWriter* file_writer) {
00025   const std::string header =
00026       absl::StrCat("P5\n# Cartographer map; ", resolution, " m/pixel\n",
00027                    image.width(), " ", image.height(), "\n255\n");
00028   file_writer->Write(header.data(), header.size());
00029   for (int y = 0; y < image.height(); ++y) {
00030     for (int x = 0; x < image.width(); ++x) {
00031       const char color = image.GetPixel(x, y)[0];
00032       file_writer->Write(&color, 1);
00033     }
00034   }
00035 }
00036 
00037 void WriteYaml(const double resolution, const Eigen::Vector2d& origin,
00038                const std::string& pgm_filename,
00039                ::cartographer::io::FileWriter* file_writer) {
00040   // Magic constants taken directly from ros map_saver code:
00041   // https://github.com/ros-planning/navigation/blob/ac41d2480c4cf1602daf39a6e9629142731d92b0/map_server/src/map_saver.cpp#L114
00042   const std::string output = absl::StrCat(
00043       "image: ", pgm_filename, "\n", "resolution: ", resolution, "\n",
00044       "origin: [", origin.x(), ", ", origin.y(),
00045       ", 0.0]\nnegate: 0\noccupied_thresh: 0.65\nfree_thresh: 0.196\n");
00046   file_writer->Write(output.data(), output.size());
00047 }
00048 
00049 }  // namespace cartographer_ros


cartographer_ros
Author(s): The Cartographer Authors
autogenerated on Wed Jul 10 2019 04:10:28