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/internal/3d/scan_matching/interpolated_grid.h"
00018
00019 #include "Eigen/Core"
00020 #include "cartographer/mapping/3d/hybrid_grid.h"
00021 #include "gtest/gtest.h"
00022
00023 namespace cartographer {
00024 namespace mapping {
00025 namespace scan_matching {
00026 namespace {
00027
00028 class InterpolatedGridTest : public ::testing::Test {
00029 protected:
00030 InterpolatedGridTest()
00031 : hybrid_grid_(0.1f), interpolated_grid_(hybrid_grid_) {
00032 for (const Eigen::Vector3f& point :
00033 {Eigen::Vector3f(-3.f, 2.f, 0.f), Eigen::Vector3f(-4.f, 2.f, 0.f),
00034 Eigen::Vector3f(-5.f, 2.f, 0.f), Eigen::Vector3f(-6.f, 2.f, 0.f),
00035 Eigen::Vector3f(-6.f, 3.f, 1.f), Eigen::Vector3f(-6.f, 4.f, 2.f),
00036 Eigen::Vector3f(-7.f, 3.f, 1.f)}) {
00037 hybrid_grid_.SetProbability(hybrid_grid_.GetCellIndex(point), 1.);
00038 }
00039 }
00040
00041 float GetHybridGridProbability(float x, float y, float z) const {
00042 return hybrid_grid_.GetProbability(
00043 hybrid_grid_.GetCellIndex(Eigen::Vector3f(x, y, z)));
00044 }
00045
00046 HybridGrid hybrid_grid_;
00047 InterpolatedGrid interpolated_grid_;
00048 };
00049
00050 TEST_F(InterpolatedGridTest, InterpolatesGridPoints) {
00051 for (double z = -1.; z < 3.; z += hybrid_grid_.resolution()) {
00052 for (double y = 1.; y < 5.; y += hybrid_grid_.resolution()) {
00053 for (double x = -8.; x < -2.; x += hybrid_grid_.resolution()) {
00054 EXPECT_NEAR(GetHybridGridProbability(x, y, z),
00055 interpolated_grid_.GetProbability(x, y, z), 1e-6);
00056 }
00057 }
00058 }
00059 }
00060
00061 TEST_F(InterpolatedGridTest, MonotonicBehaviorBetweenGridPointsInX) {
00062 const double kSampleStep = hybrid_grid_.resolution() / 10.;
00063 for (double z = -1.; z < 3.; z += hybrid_grid_.resolution()) {
00064 for (double y = 1.; y < 5.; y += hybrid_grid_.resolution()) {
00065 for (double x = -8.; x < -2.; x += hybrid_grid_.resolution()) {
00066 const float start_probability = GetHybridGridProbability(x, y, z);
00067 const float next_probability =
00068 GetHybridGridProbability(x + hybrid_grid_.resolution(), y, z);
00069 const float grid_difference = next_probability - start_probability;
00070 if (std::abs(grid_difference) < 1e-6f) {
00071 continue;
00072 }
00073 for (double sample = kSampleStep;
00074 sample < hybrid_grid_.resolution() - 2 * kSampleStep;
00075 sample += kSampleStep) {
00076 EXPECT_LT(0., grid_difference * (interpolated_grid_.GetProbability(
00077 x + sample + kSampleStep, y, z) -
00078 interpolated_grid_.GetProbability(
00079 x + sample, y, z)));
00080 }
00081 }
00082 }
00083 }
00084 }
00085
00086 }
00087 }
00088 }
00089 }