Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
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
00041
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 }