26 #include "cartographer/mapping/proto/pose_graph.pb.h" 27 #include "cartographer/mapping/proto/serialization.pb.h" 28 #include "cartographer/mapping/proto/submap.pb.h" 29 #include "cartographer/mapping/proto/trajectory_builder_options.pb.h" 32 #include "gflags/gflags.h" 33 #include "glog/logging.h" 36 "Filename of a pbstream to draw a map from.");
37 DEFINE_string(map_filestem,
"map",
"Stem of the output files.");
38 DEFINE_double(resolution, 0.05,
"Resolution of a grid cell in the drawn map.");
43 void Run(
const std::string& pbstream_filename,
const std::string& map_filestem,
44 const double resolution) {
48 const auto& pose_graph = deserializer.pose_graph();
50 LOG(INFO) <<
"Loading submap slices from serialized data.";
51 std::map<::cartographer::mapping::SubmapId, ::cartographer::io::SubmapSlice>
53 ::cartographer::mapping::proto::SerializedData proto;
54 while (deserializer.ReadNextSerializedData(&proto)) {
55 if (proto.has_submap()) {
56 const auto& submap = proto.submap();
57 const ::cartographer::mapping::SubmapId
id{
58 submap.submap_id().trajectory_id(),
59 submap.submap_id().submap_index()};
60 const ::cartographer::transform::Rigid3d global_submap_pose =
61 ::cartographer::transform::ToRigid3(
62 pose_graph.trajectory(
id.trajectory_id)
63 .submap(
id.submap_index)
70 LOG(INFO) <<
"Generating combined map image from submap slices.";
72 ::cartographer::io::PaintSubmapSlices(submap_slices, resolution);
77 WritePgm(image, resolution, &pgm_writer);
79 const Eigen::Vector2d origin(
80 -result.origin.x() * resolution,
81 (result.origin.y() - image.height()) * resolution);
84 WriteYaml(resolution, origin, pgm_writer.GetFilename(), &yaml_writer);
90 int main(
int argc,
char** argv) {
91 FLAGS_alsologtostderr =
true;
92 google::InitGoogleLogging(argv[0]);
93 google::ParseCommandLineFlags(&argc, &argv,
true);
95 CHECK(!FLAGS_pbstream_filename.empty()) <<
"-pbstream_filename is missing.";
96 CHECK(!FLAGS_map_filestem.empty()) <<
"-map_filestem is missing.";
98 ::cartographer_ros::Run(FLAGS_pbstream_filename, FLAGS_map_filestem,
void WriteYaml(const double resolution, const Eigen::Vector2d &origin, const std::string &pgm_filename, ::cartographer::io::FileWriter *file_writer)
int main(int argc, char **argv)
void WritePgm(const ::cartographer::io::Image &image, const double resolution, ::cartographer::io::FileWriter *file_writer)
DEFINE_double(resolution, 0.05, "Resolution of a grid cell in the drawn map.")
void FillSubmapSlice(const ::cartographer::transform::Rigid3d &global_submap_pose, const ::cartographer::mapping::proto::Submap &proto, SubmapSlice *const submap_slice)
DEFINE_string(pbstream_filename, "", "Filename of a pbstream to draw a map from.")
void Run(const std::string &configuration_directory, const std::string &configuration_basename)