29 #include "gtest/gtest.h" 33 namespace scan_matching {
36 class FastCorrelativeScanMatcher3DTest :
public ::testing::Test {
38 FastCorrelativeScanMatcher3DTest()
40 options_(CreateFastCorrelativeScanMatcher3DTestOptions3D(6)) {}
42 void SetUp()
override {
44 Eigen::Vector3f(4.f, 0.f, 0.f), Eigen::Vector3f(4.5f, 0.f, 0.f),
45 Eigen::Vector3f(5.f, 0.f, 0.f), Eigen::Vector3f(5.5f, 0.f, 0.f),
46 Eigen::Vector3f(0.f, 4.f, 0.f), Eigen::Vector3f(0.f, 4.5f, 0.f),
47 Eigen::Vector3f(0.f, 5.f, 0.f), Eigen::Vector3f(0.f, 5.5f, 0.f),
48 Eigen::Vector3f(0.f, 0.f, 4.f), Eigen::Vector3f(0.f, 0.f, 4.5f),
49 Eigen::Vector3f(0.f, 0.f, 5.f), Eigen::Vector3f(0.f, 0.f, 5.5f)};
59 Eigen::AngleAxisf(theta, Eigen::Vector3f::UnitZ()));
62 static proto::FastCorrelativeScanMatcherOptions3D
63 CreateFastCorrelativeScanMatcher3DTestOptions3D(
64 const int branch_and_bound_depth) {
67 "branch_and_bound_depth = " +
68 std::to_string(branch_and_bound_depth) +
70 "full_resolution_depth = " +
71 std::to_string(branch_and_bound_depth) +
73 "min_rotational_score = 0.1, " 76 "min_low_resolution_score = 0.15, " 77 "linear_xy_search_window = 0.8, " 78 "linear_z_search_window = 0.8, " 79 "angular_search_window = 0.3, " 82 parameter_dictionary.get());
85 static mapping::proto::RangeDataInserterOptions3D
86 CreateRangeDataInserterTestOptions3D() {
89 "hit_probability = 0.7, " 90 "miss_probability = 0.4, " 91 "num_free_space_voxels = 5, " 96 std::unique_ptr<FastCorrelativeScanMatcher3D> GetFastCorrelativeScanMatcher(
97 const proto::FastCorrelativeScanMatcherOptions3D& options,
101 sensor::RangeData{pose.translation(),
107 return common::make_unique<FastCorrelativeScanMatcher3D>(
109 std::vector<TrajectoryNode>(
110 {{std::make_shared<const TrajectoryNode::Data>(
112 pose.cast<
double>()}}),
116 TrajectoryNode::Data CreateConstantData(
119 Eigen::Quaterniond::Identity(),
122 low_resolution_point_cloud,
123 Eigen::VectorXf::Zero(10)};
126 std::mt19937
prng_ = std::mt19937(42);
128 std::uniform_real_distribution<float>(-1.f, 1.f);
130 const proto::FastCorrelativeScanMatcherOptions3D
options_;
135 constexpr
float kMinScore = 0.1f;
137 TEST_F(FastCorrelativeScanMatcher3DTest, CorrectPoseForMatch) {
138 for (
int i = 0; i != 20; ++i) {
139 const auto expected_pose = GetRandomPose();
141 std::unique_ptr<FastCorrelativeScanMatcher3D> fast_correlative_scan_matcher(
142 GetFastCorrelativeScanMatcher(
options_, expected_pose));
144 const std::unique_ptr<FastCorrelativeScanMatcher3D::Result> result =
145 fast_correlative_scan_matcher->Match(
148 EXPECT_THAT(result, testing::NotNull());
149 EXPECT_LT(kMinScore, result->score);
150 EXPECT_LT(0.09f, result->rotational_score);
151 EXPECT_LT(0.14f, result->low_resolution_score);
152 EXPECT_THAT(expected_pose,
153 transform::IsNearly(result->pose_estimate.cast<
float>(), 0.05f))
157 const std::unique_ptr<FastCorrelativeScanMatcher3D::Result>
158 low_resolution_result = fast_correlative_scan_matcher->Match(
160 CreateConstantData({Eigen::Vector3f(42.f, 42.f, 42.f)}), kMinScore);
161 EXPECT_THAT(low_resolution_result, testing::IsNull())
162 << low_resolution_result->low_resolution_score;
166 TEST_F(FastCorrelativeScanMatcher3DTest, CorrectPoseForMatchFullSubmap) {
167 const auto expected_pose = GetRandomPose();
169 std::unique_ptr<FastCorrelativeScanMatcher3D> fast_correlative_scan_matcher(
170 GetFastCorrelativeScanMatcher(
options_, expected_pose));
172 const std::unique_ptr<FastCorrelativeScanMatcher3D::Result> result =
173 fast_correlative_scan_matcher->MatchFullSubmap(
174 Eigen::Quaterniond::Identity(), Eigen::Quaterniond::Identity(),
176 EXPECT_THAT(result, testing::NotNull());
177 EXPECT_LT(kMinScore, result->score);
178 EXPECT_LT(0.09f, result->rotational_score);
179 EXPECT_LT(0.14f, result->low_resolution_score);
180 EXPECT_THAT(expected_pose,
181 transform::IsNearly(result->pose_estimate.cast<
float>(), 0.05f))
185 const std::unique_ptr<FastCorrelativeScanMatcher3D::Result>
186 low_resolution_result = fast_correlative_scan_matcher->MatchFullSubmap(
187 Eigen::Quaterniond::Identity(), Eigen::Quaterniond::Identity(),
188 CreateConstantData({Eigen::Vector3f(42.f, 42.f, 42.f)}), kMinScore);
189 EXPECT_THAT(low_resolution_result, testing::IsNull())
190 << low_resolution_result->low_resolution_score;
PointCloud TransformPointCloud(const PointCloud &point_cloud, const transform::Rigid3f &transform)
std::unique_ptr< HybridGrid > hybrid_grid_
proto::RangeDataInserterOptions3D CreateRangeDataInserterOptions3D(common::LuaParameterDictionary *parameter_dictionary)
std::unique_ptr< LuaParameterDictionary > MakeDictionary(const std::string &code)
Time FromUniversal(const int64 ticks)
sensor::PointCloud point_cloud_
const proto::FastCorrelativeScanMatcherOptions3D options_
std::uniform_real_distribution< float > distribution_
std::vector< Eigen::Vector3f > PointCloud
RangeDataInserter3D range_data_inserter_
proto::FastCorrelativeScanMatcherOptions3D CreateFastCorrelativeScanMatcherOptions3D(common::LuaParameterDictionary *const parameter_dictionary)