28 #include "gtest/gtest.h" 31 namespace mapping_3d {
32 namespace scan_matching {
35 proto::FastCorrelativeScanMatcherOptions
36 CreateFastCorrelativeScanMatcherTestOptions(
const int branch_and_bound_depth) {
39 "branch_and_bound_depth = " +
40 std::to_string(branch_and_bound_depth) +
42 "full_resolution_depth = " +
43 std::to_string(branch_and_bound_depth) +
45 "rotational_histogram_size = 30, " 46 "min_rotational_score = 0.1, " 47 "linear_xy_search_window = 0.8, " 48 "linear_z_search_window = 0.8, " 49 "angular_search_window = 0.3, " 54 mapping_3d::proto::RangeDataInserterOptions
55 CreateRangeDataInserterTestOptions() {
58 "hit_probability = 0.7, " 59 "miss_probability = 0.4, " 60 "num_free_space_voxels = 5, " 65 TEST(FastCorrelativeScanMatcherTest, CorrectPose) {
66 std::mt19937 prng(42);
67 std::uniform_real_distribution<float> distribution(-1.f, 1.f);
68 RangeDataInserter range_data_inserter(CreateRangeDataInserterTestOptions());
69 constexpr
float kMinScore = 0.1f;
70 const auto options = CreateFastCorrelativeScanMatcherTestOptions(5);
73 Eigen::Vector3f(4.f, 0.f, 0.f), Eigen::Vector3f(4.5f, 0.f, 0.f),
74 Eigen::Vector3f(5.f, 0.f, 0.f), Eigen::Vector3f(5.5f, 0.f, 0.f),
75 Eigen::Vector3f(0.f, 4.f, 0.f), Eigen::Vector3f(0.f, 4.5f, 0.f),
76 Eigen::Vector3f(0.f, 5.f, 0.f), Eigen::Vector3f(0.f, 5.5f, 0.f),
77 Eigen::Vector3f(0.f, 0.f, 4.f), Eigen::Vector3f(0.f, 0.f, 4.5f),
78 Eigen::Vector3f(0.f, 0.f, 5.f), Eigen::Vector3f(0.f, 0.f, 5.5f)};
80 for (
int i = 0; i != 20; ++i) {
81 const float x = 0.7f * distribution(prng);
82 const float y = 0.7f * distribution(prng);
83 const float z = 0.7f * distribution(prng);
84 const float theta = 0.2f * distribution(prng);
85 const auto expected_pose =
88 Eigen::AngleAxisf(theta, Eigen::Vector3f::UnitZ()));
90 HybridGrid hybrid_grid(0.05f);
91 hybrid_grid.StartUpdate();
92 range_data_inserter.Insert(
94 expected_pose.translation(),
99 FastCorrelativeScanMatcher fast_correlative_scan_matcher(hybrid_grid, {},
103 EXPECT_TRUE(fast_correlative_scan_matcher.Match(
105 &score, &pose_estimate));
106 EXPECT_LT(kMinScore, score);
107 EXPECT_THAT(expected_pose,
108 transform::IsNearly(pose_estimate.cast<
float>(), 0.05f))
proto::FastCorrelativeScanMatcherOptions CreateFastCorrelativeScanMatcherOptions(common::LuaParameterDictionary *const parameter_dictionary)
PointCloud TransformPointCloud(const PointCloud &point_cloud, const transform::Rigid3f &transform)
proto::RangeDataInserterOptions CreateRangeDataInserterOptions(common::LuaParameterDictionary *parameter_dictionary)
std::unique_ptr< LuaParameterDictionary > MakeDictionary(const string &code)
std::vector< Eigen::Vector3f > PointCloud