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/mapping/3d/range_data_inserter_3d.h"
00018
00019 #include "Eigen/Core"
00020 #include "cartographer/mapping/probability_values.h"
00021 #include "glog/logging.h"
00022
00023 namespace cartographer {
00024 namespace mapping {
00025 namespace {
00026
00027 void InsertMissesIntoGrid(const std::vector<uint16>& miss_table,
00028 const Eigen::Vector3f& origin,
00029 const sensor::PointCloud& returns,
00030 HybridGrid* hybrid_grid,
00031 const int num_free_space_voxels) {
00032 const Eigen::Array3i origin_cell = hybrid_grid->GetCellIndex(origin);
00033 for (const sensor::RangefinderPoint& hit : returns) {
00034 const Eigen::Array3i hit_cell = hybrid_grid->GetCellIndex(hit.position);
00035
00036 const Eigen::Array3i delta = hit_cell - origin_cell;
00037 const int num_samples = delta.cwiseAbs().maxCoeff();
00038 CHECK_LT(num_samples, 1 << 15);
00039
00040
00041
00042
00043
00044
00045 for (int position = std::max(0, num_samples - num_free_space_voxels);
00046 position < num_samples; ++position) {
00047 const Eigen::Array3i miss_cell =
00048 origin_cell + delta * position / num_samples;
00049 hybrid_grid->ApplyLookupTable(miss_cell, miss_table);
00050 }
00051 }
00052 }
00053
00054 }
00055
00056 proto::RangeDataInserterOptions3D CreateRangeDataInserterOptions3D(
00057 common::LuaParameterDictionary* parameter_dictionary) {
00058 proto::RangeDataInserterOptions3D options;
00059 options.set_hit_probability(
00060 parameter_dictionary->GetDouble("hit_probability"));
00061 options.set_miss_probability(
00062 parameter_dictionary->GetDouble("miss_probability"));
00063 options.set_num_free_space_voxels(
00064 parameter_dictionary->GetInt("num_free_space_voxels"));
00065 CHECK_GT(options.hit_probability(), 0.5);
00066 CHECK_LT(options.miss_probability(), 0.5);
00067 return options;
00068 }
00069
00070 RangeDataInserter3D::RangeDataInserter3D(
00071 const proto::RangeDataInserterOptions3D& options)
00072 : options_(options),
00073 hit_table_(
00074 ComputeLookupTableToApplyOdds(Odds(options_.hit_probability()))),
00075 miss_table_(
00076 ComputeLookupTableToApplyOdds(Odds(options_.miss_probability()))) {}
00077
00078 void RangeDataInserter3D::Insert(const sensor::RangeData& range_data,
00079 HybridGrid* hybrid_grid) const {
00080 CHECK(hybrid_grid != nullptr);
00081
00082 for (const sensor::RangefinderPoint& hit : range_data.returns) {
00083 const Eigen::Array3i hit_cell = hybrid_grid->GetCellIndex(hit.position);
00084 hybrid_grid->ApplyLookupTable(hit_cell, hit_table_);
00085 }
00086
00087
00088
00089 InsertMissesIntoGrid(miss_table_, range_data.origin, range_data.returns,
00090 hybrid_grid, options_.num_free_space_voxels());
00091 hybrid_grid->FinishUpdate();
00092 }
00093
00094 }
00095 }