constraint_builder_3d_test.cc
Go to the documentation of this file.
00001 /*
00002  * Copyright 2018 The Cartographer Authors
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *      http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00017 #include "cartographer/mapping/internal/constraints/constraint_builder_3d.h"
00018 
00019 #include <functional>
00020 
00021 #include "cartographer/common/internal/testing/thread_pool_for_testing.h"
00022 #include "cartographer/mapping/3d/submap_3d.h"
00023 #include "cartographer/mapping/internal/constraints/constraint_builder.h"
00024 #include "cartographer/mapping/internal/testing/test_helpers.h"
00025 #include "cartographer/mapping/pose_graph.h"
00026 #include "cartographer/transform/rigid_transform.h"
00027 #include "gmock/gmock.h"
00028 #include "gtest/gtest.h"
00029 
00030 namespace cartographer {
00031 namespace mapping {
00032 namespace constraints {
00033 namespace {
00034 
00035 class MockCallback {
00036  public:
00037   MOCK_METHOD1(Run, void(const ConstraintBuilder3D::Result&));
00038 };
00039 
00040 class ConstraintBuilder3DTest : public ::testing::Test {
00041  protected:
00042   void SetUp() override {
00043     auto constraint_builder_parameters = testing::ResolveLuaParameters(R"text(
00044     include "pose_graph.lua"
00045     POSE_GRAPH.constraint_builder.sampling_ratio = 1
00046     POSE_GRAPH.constraint_builder.min_score = 0
00047     POSE_GRAPH.constraint_builder.global_localization_min_score = 0
00048     POSE_GRAPH.constraint_builder.fast_correlative_scan_matcher_3d.min_low_resolution_score = 0
00049     POSE_GRAPH.constraint_builder.fast_correlative_scan_matcher_3d.min_rotational_score = 0
00050     return POSE_GRAPH.constraint_builder)text");
00051     constraint_builder_ = absl::make_unique<ConstraintBuilder3D>(
00052         CreateConstraintBuilderOptions(constraint_builder_parameters.get()),
00053         &thread_pool_);
00054   }
00055 
00056   std::unique_ptr<ConstraintBuilder3D> constraint_builder_;
00057   MockCallback mock_;
00058   common::testing::ThreadPoolForTesting thread_pool_;
00059 };
00060 
00061 TEST_F(ConstraintBuilder3DTest, CallsBack) {
00062   EXPECT_EQ(constraint_builder_->GetNumFinishedNodes(), 0);
00063   EXPECT_CALL(mock_, Run(::testing::IsEmpty()));
00064   constraint_builder_->NotifyEndOfNode();
00065   constraint_builder_->WhenDone(
00066       [this](const constraints::ConstraintBuilder3D::Result& result) {
00067         mock_.Run(result);
00068       });
00069   thread_pool_.WaitUntilIdle();
00070   EXPECT_EQ(constraint_builder_->GetNumFinishedNodes(), 1);
00071 }
00072 
00073 TEST_F(ConstraintBuilder3DTest, FindsConstraints) {
00074   auto node_data = std::make_shared<TrajectoryNode::Data>();
00075   node_data->gravity_alignment = Eigen::Quaterniond::Identity();
00076   node_data->high_resolution_point_cloud.push_back(
00077       {Eigen::Vector3f(0.1, 0.2, 0.3)});
00078   node_data->low_resolution_point_cloud.push_back(
00079       {Eigen::Vector3f(0.1, 0.2, 0.3)});
00080   node_data->rotational_scan_matcher_histogram = Eigen::VectorXf::Zero(3);
00081   node_data->local_pose = transform::Rigid3d::Identity();
00082   SubmapId submap_id{0, 1};
00083   Submap3D submap(0.1, 0.1, transform::Rigid3d::Identity(),
00084                   Eigen::VectorXf::Zero(3));
00085   int expected_nodes = 0;
00086   for (int i = 0; i < 2; ++i) {
00087     EXPECT_EQ(constraint_builder_->GetNumFinishedNodes(), expected_nodes);
00088     for (int j = 0; j < 2; ++j) {
00089       constraint_builder_->MaybeAddConstraint(
00090           submap_id, &submap, NodeId{0, 0}, node_data.get(),
00091           transform::Rigid3d::Identity(), transform::Rigid3d::Identity());
00092     }
00093     constraint_builder_->MaybeAddGlobalConstraint(
00094         submap_id, &submap, NodeId{0, 0}, node_data.get(),
00095         Eigen::Quaterniond::Identity(), Eigen::Quaterniond::Identity());
00096     constraint_builder_->NotifyEndOfNode();
00097     thread_pool_.WaitUntilIdle();
00098     EXPECT_EQ(constraint_builder_->GetNumFinishedNodes(), ++expected_nodes);
00099     constraint_builder_->NotifyEndOfNode();
00100     thread_pool_.WaitUntilIdle();
00101     EXPECT_EQ(constraint_builder_->GetNumFinishedNodes(), ++expected_nodes);
00102     EXPECT_CALL(mock_,
00103                 Run(::testing::AllOf(
00104                     ::testing::SizeIs(3),
00105                     ::testing::Each(::testing::Field(
00106                         &PoseGraphInterface::Constraint::tag,
00107                         PoseGraphInterface::Constraint::INTER_SUBMAP)))));
00108     constraint_builder_->WhenDone(
00109         [this](const constraints::ConstraintBuilder3D::Result& result) {
00110           mock_.Run(result);
00111         });
00112     thread_pool_.WaitUntilIdle();
00113     constraint_builder_->DeleteScanMatcher(submap_id);
00114   }
00115 }
00116 
00117 }  // namespace
00118 }  // namespace constraints
00119 }  // namespace mapping
00120 }  // namespace cartographer


cartographer
Author(s): The Cartographer Authors
autogenerated on Thu May 9 2019 02:27:35