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 <memory>
00020 #include <vector>
00021
00022 #include "cartographer/common/lua_parameter_dictionary_test_helpers.h"
00023 #include "gmock/gmock.h"
00024
00025 namespace cartographer {
00026 namespace mapping {
00027 namespace {
00028
00029 class RangeDataInserter3DTest : public ::testing::Test {
00030 protected:
00031 RangeDataInserter3DTest() : hybrid_grid_(1.f) {
00032 auto parameter_dictionary = common::MakeDictionary(
00033 "return { "
00034 "hit_probability = 0.7, "
00035 "miss_probability = 0.4, "
00036 "num_free_space_voxels = 1000, "
00037 "}");
00038 options_ = CreateRangeDataInserterOptions3D(parameter_dictionary.get());
00039 range_data_inserter_.reset(new RangeDataInserter3D(options_));
00040 }
00041
00042 void InsertPointCloud() {
00043 const Eigen::Vector3f origin = Eigen::Vector3f(0.f, 0.f, -4.f);
00044 sensor::PointCloud returns = {{Eigen::Vector3f{-3.f, -1.f, 4.f}},
00045 {Eigen::Vector3f{-2.f, 0.f, 4.f}},
00046 {Eigen::Vector3f{-1.f, 1.f, 4.f}},
00047 {Eigen::Vector3f{0.f, 2.f, 4.f}}};
00048 range_data_inserter_->Insert(sensor::RangeData{origin, returns, {}},
00049 &hybrid_grid_);
00050 }
00051
00052 float GetProbability(float x, float y, float z) const {
00053 return hybrid_grid_.GetProbability(
00054 hybrid_grid_.GetCellIndex(Eigen::Vector3f(x, y, z)));
00055 }
00056
00057 float IsKnown(float x, float y, float z) const {
00058 return hybrid_grid_.IsKnown(
00059 hybrid_grid_.GetCellIndex(Eigen::Vector3f(x, y, z)));
00060 }
00061
00062 const proto::RangeDataInserterOptions3D& options() const { return options_; }
00063
00064 private:
00065 HybridGrid hybrid_grid_;
00066 std::unique_ptr<RangeDataInserter3D> range_data_inserter_;
00067 proto::RangeDataInserterOptions3D options_;
00068 };
00069
00070 TEST_F(RangeDataInserter3DTest, InsertPointCloud) {
00071 InsertPointCloud();
00072 EXPECT_NEAR(options().miss_probability(), GetProbability(0.f, 0.f, -4.f),
00073 1e-4);
00074 EXPECT_NEAR(options().miss_probability(), GetProbability(0.f, 0.f, -3.f),
00075 1e-4);
00076 EXPECT_NEAR(options().miss_probability(), GetProbability(0.f, 0.f, -2.f),
00077 1e-4);
00078 for (int x = -4; x <= 4; ++x) {
00079 for (int y = -4; y <= 4; ++y) {
00080 if (x < -3 || x > 0 || y != x + 2) {
00081 EXPECT_FALSE(IsKnown(x, y, 4.f));
00082 } else {
00083 EXPECT_NEAR(options().hit_probability(), GetProbability(x, y, 4.f),
00084 1e-4);
00085 }
00086 }
00087 }
00088 }
00089
00090 TEST_F(RangeDataInserter3DTest, ProbabilityProgression) {
00091 InsertPointCloud();
00092 EXPECT_NEAR(options().hit_probability(), GetProbability(-2.f, 0.f, 4.f),
00093 1e-4);
00094 EXPECT_NEAR(options().miss_probability(), GetProbability(-2.f, 0.f, 3.f),
00095 1e-4);
00096 EXPECT_NEAR(options().miss_probability(), GetProbability(0.f, 0.f, -3.f),
00097 1e-4);
00098
00099 for (int i = 0; i < 1000; ++i) {
00100 InsertPointCloud();
00101 }
00102 EXPECT_NEAR(kMaxProbability, GetProbability(-2.f, 0.f, 4.f), 1e-3);
00103 EXPECT_NEAR(kMinProbability, GetProbability(-2.f, 0.f, 3.f), 1e-3);
00104 EXPECT_NEAR(kMinProbability, GetProbability(0.f, 0.f, -3.f), 1e-3);
00105 }
00106
00107 }
00108 }
00109 }