ros_map_writing_points_processor.cc
Go to the documentation of this file.
1 /*
2  * Copyright 2016 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 
20 #include "cartographer/io/image.h"
23 
24 namespace cartographer_ros {
25 
27  const double resolution,
28  const ::cartographer::mapping::proto::
29  ProbabilityGridRangeDataInserterOptions2D& range_data_inserter_options,
30  ::cartographer::io::FileWriterFactory file_writer_factory,
31  const std::string& filestem,
33  : filestem_(filestem),
34  next_(next),
35  file_writer_factory_(file_writer_factory),
36  range_data_inserter_(range_data_inserter_options),
38 }
39 
40 std::unique_ptr<RosMapWritingPointsProcessor>
42  ::cartographer::io::FileWriterFactory file_writer_factory,
44  ::cartographer::io::PointsProcessor* const next) {
45  return ::cartographer::common::make_unique<RosMapWritingPointsProcessor>(
46  dictionary->GetDouble("resolution"),
47  ::cartographer::mapping::CreateProbabilityGridRangeDataInserterOptions2D(
48  dictionary->GetDictionary("range_data_inserter").get()),
49  file_writer_factory, dictionary->GetString("filestem"), next);
50 }
51 
53  std::unique_ptr<::cartographer::io::PointsBatch> batch) {
54  range_data_inserter_.Insert({batch->origin, batch->points, {}},
56  next_->Process(std::move(batch));
57 }
58 
61  Eigen::Array2i offset;
62  std::unique_ptr<::cartographer::io::Image> image =
63  ::cartographer::io::DrawProbabilityGrid(probability_grid_, &offset);
64  if (image != nullptr) {
65  auto pgm_writer = file_writer_factory_(filestem_ + ".pgm");
66  const std::string pgm_filename = pgm_writer->GetFilename();
67  const auto& limits = probability_grid_.limits();
68  image->Rotate90DegreesClockwise();
69 
70  WritePgm(*image, limits.resolution(), pgm_writer.get());
71  CHECK(pgm_writer->Close());
72 
73  const Eigen::Vector2d origin(
74  limits.max().x() - (offset.y() + image->width()) * limits.resolution(),
75  limits.max().y() -
76  (offset.x() + image->height()) * limits.resolution());
77  auto yaml_writer = file_writer_factory_(filestem_ + ".yaml");
78  WriteYaml(limits.resolution(), origin, pgm_filename, yaml_writer.get());
79  CHECK(yaml_writer->Close());
80  }
81 
82  switch (next_->Flush()) {
84  LOG(FATAL) << "ROS map writing must be configured to occur after any "
85  "stages that require multiple passes.";
86 
89  }
90  LOG(FATAL);
91  // The following unreachable return statement is needed to avoid a GCC bug
92  // described at https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81508
94 }
95 
96 } // 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
std::function< std::unique_ptr< FileWriter >(const std::string &filename)> FileWriterFactory
std::string GetString(const std::string &key)
void WritePgm(const ::cartographer::io::Image &image, const double resolution, ::cartographer::io::FileWriter *file_writer)
Definition: ros_map.cc:21
::cartographer::mapping::ProbabilityGrid probability_grid_
double GetDouble(const std::string &key)
static std::unique_ptr< RosMapWritingPointsProcessor > FromDictionary(::cartographer::io::FileWriterFactory file_writer_factory, ::cartographer::common::LuaParameterDictionary *dictionary, PointsProcessor *next)
::cartographer::mapping::ProbabilityGridRangeDataInserter2D range_data_inserter_
mapping::ProbabilityGrid CreateProbabilityGrid(const double resolution)
::cartographer::io::FileWriterFactory file_writer_factory_
RangeDataInserter3D range_data_inserter_
std::unique_ptr< LuaParameterDictionary > GetDictionary(const std::string &key)
const MapLimits & limits() const
void Process(std::unique_ptr<::cartographer::io::PointsBatch > batch) override
ProbabilityGrid probability_grid_
virtual void Insert(const sensor::RangeData &range_data, GridInterface *grid) const override
RosMapWritingPointsProcessor(double resolution, const ::cartographer::mapping::proto::ProbabilityGridRangeDataInserterOptions2D &range_data_inserter_options, ::cartographer::io::FileWriterFactory file_writer_factory, const std::string &filestem, PointsProcessor *next)


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