ros_map.cc
Go to the documentation of this file.
1 /*
2  * Copyright 2017 The Cartographer Authors
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
18 
19 namespace cartographer_ros {
20 
21 void WritePgm(const ::cartographer::io::Image& image, const double resolution,
22  ::cartographer::io::FileWriter* file_writer) {
23  const std::string header = "P5\n# Cartographer map; " +
24  std::to_string(resolution) + " m/pixel\n" +
25  std::to_string(image.width()) + " " +
26  std::to_string(image.height()) + "\n255\n";
27  file_writer->Write(header.data(), header.size());
28  for (int y = 0; y < image.height(); ++y) {
29  for (int x = 0; x < image.width(); ++x) {
30  const char color = image.GetPixel(x, y)[0];
31  file_writer->Write(&color, 1);
32  }
33  }
34 }
35 
36 void WriteYaml(const double resolution, const Eigen::Vector2d& origin,
37  const std::string& pgm_filename,
38  ::cartographer::io::FileWriter* file_writer) {
39  // Magic constants taken directly from ros map_saver code:
40  // https://github.com/ros-planning/navigation/blob/ac41d2480c4cf1602daf39a6e9629142731d92b0/map_server/src/map_saver.cpp#L114
41  const std::string output =
42  "image: " + pgm_filename + "\n" +
43  "resolution: " + std::to_string(resolution) + "\n" + "origin: [" +
44  std::to_string(origin.x()) + ", " + std::to_string(origin.y()) +
45  ", 0.0]\nnegate: 0\noccupied_thresh: 0.65\nfree_thresh: 0.196\n";
46  file_writer->Write(output.data(), output.size());
47 }
48 
49 } // namespace cartographer_ros
void WriteYaml(const double resolution, const Eigen::Vector2d &origin, const std::string &pgm_filename, ::cartographer::io::FileWriter *file_writer)
Definition: ros_map.cc:36
void WritePgm(const ::cartographer::io::Image &image, const double resolution, ::cartographer::io::FileWriter *file_writer)
Definition: ros_map.cc:21
virtual bool Write(const char *data, size_t len)=0
const std::string header


cartographer_ros
Author(s): The Cartographer Authors
autogenerated on Mon Feb 28 2022 22:06:05