25 #include "Eigen/Geometry" 28 #include "glog/logging.h" 29 #include "webp/encode.h" 32 namespace mapping_2d {
36 void WriteDebugImage(
const string& filename,
37 const ProbabilityGrid& probability_grid) {
38 constexpr
int kUnknown = 128;
39 const CellLimits& cell_limits = probability_grid.limits().cell_limits();
40 const int width = cell_limits.num_x_cells;
41 const int height = cell_limits.num_y_cells;
42 std::vector<uint8_t> rgb;
43 for (
const Eigen::Array2i& xy_index :
44 XYIndexRangeIterator(probability_grid.limits().cell_limits())) {
45 CHECK(probability_grid.limits().Contains(xy_index));
47 probability_grid.IsKnown(xy_index)
49 (1. - probability_grid.GetProbability(xy_index)) * 255 + 0)
55 uint8_t* output =
nullptr;
57 WebPEncodeLosslessRGB(rgb.data(), width, height, 3 * width, &output);
58 std::unique_ptr<uint8_t, void (*)(void*)> output_deleter(output, std::free);
59 std::ofstream output_file(filename, std::ios::out | std::ios::binary);
60 output_file.write(reinterpret_cast<char*>(output), output_size);
62 CHECK(output_file) <<
"Writing " << filename <<
" failed.";
69 Eigen::Array2i offset;
73 const Eigen::Vector2d max =
75 resolution * Eigen::Vector2d(offset.y(), offset.x());
77 cropped_grid.StartUpdate();
79 if (probability_grid.
IsKnown(xy_index + offset)) {
80 cropped_grid.SetProbability(
89 proto::SubmapsOptions options;
90 options.set_resolution(parameter_dictionary->
GetDouble(
"resolution"));
91 options.set_half_length(parameter_dictionary->
GetDouble(
"half_length"));
92 options.set_num_range_data(
94 options.set_output_debug_images(
95 parameter_dictionary->
GetBool(
"output_debug_images"));
96 *options.mutable_range_data_inserter_options() =
98 parameter_dictionary->
GetDictionary(
"range_data_inserter").get());
99 CHECK_GT(options.num_range_data(), 0);
105 Eigen::Vector3d(origin.x(), origin.y(), 0.))),
110 mapping::proto::SubmapQuery::Response*
const response)
const {
113 Eigen::Array2i offset;
129 const uint8 alpha = delta > 0 ? 0 : -delta;
130 const uint8 value = delta > 0 ? delta : 0;
131 cells.push_back(value);
132 cells.push_back((value || alpha) ? alpha : 1);
134 constexpr
uint8 kUnknownLogOdds = 0;
135 cells.push_back(static_cast<uint8>(kUnknownLogOdds));
144 response->set_resolution(resolution);
177 CHECK_LT(index,
size());
191 if (
options_.output_debug_images()) {
193 WriteDebugImage(
"submap" + std::to_string(index) +
".webp",
202 const int num_cells_per_dimension =
205 submaps_.push_back(common::make_unique<Submap>(
207 origin.cast<
double>() +
208 options_.half_length() * Eigen::Vector2d::Ones(),
209 CellLimits(num_cells_per_dimension, num_cells_per_dimension)),
211 LOG(INFO) <<
"Added submap " <<
size();
int size() const override
ProbabilityGrid probability_grid_
size_t num_range_data() const
proto::RangeDataInserterOptions options_
std::vector< std::unique_ptr< Submap > > submaps_
bool GetBool(const string &key)
void FastGzipString(const string &uncompressed, string *compressed)
int GetNonNegativeInt(const string &key)
const Eigen::Vector2d & max() const
int RoundToInt(const float x)
void FinishSubmap(int index)
const proto::SubmapsOptions options_
transform::Rigid3d local_pose() const
void Insert(const sensor::RangeData &range_data, ProbabilityGrid *probability_grid) const
ProbabilityGrid ComputeCroppedProbabilityGrid(const ProbabilityGrid &probability_grid)
std::vector< int > insertion_indices() const
double GetDouble(const string &key)
const Submap * Get(int index) const override
double resolution() const
void ComputeCroppedLimits(Eigen::Array2i *const offset, CellLimits *const limits) const
void ToResponseProto(const transform::Rigid3d &global_submap_pose, mapping::proto::SubmapQuery::Response *response) const override
proto::RangeDataInserterOptions CreateRangeDataInserterOptions(common::LuaParameterDictionary *const parameter_dictionary)
float GetProbability(const Eigen::Array2i &xy_index) const
proto::SubmapsOptions CreateSubmapsOptions(common::LuaParameterDictionary *const parameter_dictionary)
uint8 ProbabilityToLogOddsInteger(const float probability)
Submap(const MapLimits &limits, const Eigen::Vector2f &origin)
ProbabilityGrid probability_grid_
bool IsKnown(const Eigen::Array2i &xy_index) const
RangeDataInserter range_data_inserter_
const MapLimits & limits() const
void AddSubmap(const Eigen::Vector2f &origin)
void InsertRangeData(const sensor::RangeData &range_data)
std::unique_ptr< RangeDataInserter > range_data_inserter_
std::unique_ptr< LuaParameterDictionary > GetDictionary(const string &key)
const mapping_2d::ProbabilityGrid * finished_probability_grid_