test_gicp_alignment.cpp
Go to the documentation of this file.
1 
18 #include "GICPAlignment.h"
19 #include "CADToPointCloud.h"
20 #include "leica_scanstation_utils/LeicaUtils.h"
21 #include "Utils.h"
22 #include <Viewer.h>
23 #include <gtest/gtest.h>
24 
25 class TestGICPAlignment : public ::testing::Test
26 {
27 protected:
28 
29  PointCloudRGB::Ptr sourceRGB {new PointCloudRGB};
30  PointCloudRGB::Ptr targetRGB {new PointCloudRGB};
31 
33  {
35  Utils::rotateCloud(sourceRGB, targetRGB, 0, 0, 0.175); // radians rotation in yaw
36  }
37 
38  void cubePointCloud(PointCloudRGB::Ptr cloud)
39  {
40  std::string pkg_path = ros::package::getPath("leica_point_cloud_processing");
41  std::string f = pkg_path + "/test/cube.ply";
42 
43  int sample_points = 5000;
44 
45  CADToPointCloud cad2pc(f, sample_points);
46  cad2pc.convertCloud(cloud);
47  }
48 };
49 
51 {
52  GICPAlignment gicp_alignment(targetRGB, sourceRGB, false);
53 
54  Eigen::Matrix4f tf = gicp_alignment.getFineTransform();
55  ASSERT_EQ(tf, Eigen::Matrix4f::Identity()); // constructor works well
56 
57  try
58  {
59  ros::Time::init(); // because need of ros::Time::now()
60 
61  gicp_alignment.run();
62 
63  gicp_alignment.applyTFtoCloud(sourceRGB);
64 
65  double tolerance = 1e-3;
66  // check first point for translation result is conincident with first point in target
67  EXPECT_TRUE(abs(sourceRGB->points[0].x-targetRGB->points[0].x) <= tolerance);
68  EXPECT_TRUE(abs(sourceRGB->points[0].x-targetRGB->points[0].x) <= tolerance);
69  EXPECT_TRUE(abs(sourceRGB->points[0].x-targetRGB->points[0].x) <= tolerance);
70  }
71  catch(std::exception& e)
72  {
73  ADD_FAILURE()<< e.what();
74  }
75 }
76 
78 {
79  GICPAlignment gicp_alignment(targetRGB, sourceRGB, false);
80 
81  Eigen::Matrix4f tf = gicp_alignment.getFineTransform();
82  ASSERT_EQ(tf, Eigen::Matrix4f::Identity()); // constructor works well
83 
84  gicp_alignment.setMaxIterations(100);
85  gicp_alignment.setMaxCorrespondenceDistance(5);
86  gicp_alignment.setRANSACOutlierTh(5e-2);
87  gicp_alignment.setTfEpsilon(5e-4);
88 
89  try
90  {
91  ros::Time::init(); // because need of ros::Time::now()
92 
93  gicp_alignment.run();
94 
95  PointCloudRGB::Ptr aligned_cloud {new PointCloudRGB};
96  gicp_alignment.getAlignedCloud(aligned_cloud);
97 
98  EXPECT_TRUE(gicp_alignment.transform_exists_);
99  }
100  catch(std::exception& e)
101  {
102  ADD_FAILURE()<< e.what();
103  }
104 }
105 
106 TEST_F(TestGICPAlignment, testRunWithCov)
107 {
108  GICPAlignment gicp_alignment(targetRGB, sourceRGB, true);
109 
110  Eigen::Matrix4f tf = gicp_alignment.getFineTransform();
111  ASSERT_EQ(tf, Eigen::Matrix4f::Identity()); // constructor works well
112 
113  try
114  {
115  ros::Time::init(); // because need of ros::Time::now()
116 
117  gicp_alignment.run();
118 
119  PointCloudRGB::Ptr aligned_cloud {new PointCloudRGB};
120  gicp_alignment.getAlignedCloud(aligned_cloud);
121 
122  EXPECT_TRUE(gicp_alignment.transform_exists_);
123 
124  gicp_alignment.iterate();
125  EXPECT_TRUE(gicp_alignment.transform_exists_);
126  }
127  catch(std::exception& e)
128  {
129  ADD_FAILURE()<< e.what();
130  }
131 }
132 
133 // Run all the tests that were declared with TEST()
134 int main(int argc, char **argv){
135  testing::InitGoogleTest(&argc, argv);
136 
137  return RUN_ALL_TESTS();
138 }
pcl::PointCloud< pcl::PointXYZRGB > PointCloudRGB
PointCloudRGB::Ptr targetRGB
f
void run()
Perform GICP alignment.
Perform a fine alignment from source to target cloud with Generalized Iterative Closest Point...
Definition: GICPAlignment.h:32
void iterate()
Do more iterations of GICP alignment.
void applyTFtoCloud(PointCloudRGB::Ptr cloud)
Once GICP is finished, apply fine transformation to source cloud.
void setTfEpsilon(double tf_epsilon)
Set the Tf Epsilon object.
void cubePointCloud(PointCloudRGB::Ptr cloud)
static void init()
int main(int argc, char **argv)
PointCloudRGB::Ptr sourceRGB
This class is used to obtain pcl::PointCloud from CAD file. Supported formats: .OBJ.
TEST_F(TestGICPAlignment, testApplyTF)
void getAlignedCloud(PointCloudRGB::Ptr aligned_cloud)
Get the aligned cloud object.
ROSLIB_DECL std::string getPath(const std::string &package_name)
bool transform_exists_
If true, fine transformation is finished.
Definition: GICPAlignment.h:53
void convertCloud(PointCloudRGB::Ptr cloud)
convert cloud defined by path in construstor into cloud
void setRANSACOutlierTh(int ransac_threshold)
Set the RANSAC Outlier threshold.
void setMaxCorrespondenceDistance(int max_corresp_distance)
Set the Max Correspondence Distance object.
void setMaxIterations(int iterations)
Set the Max Iterations object.
static void rotateCloud(PointCloudRGB::Ptr cloud_in, PointCloudRGB::Ptr cloud_out, double roll, double pitch, double yaw)
Apply rotation to cloud. Values given in [rad].
Definition: Utils.cpp:215
Eigen::Matrix4f getFineTransform()
Get the fine transform object.


leica_point_cloud_processing
Author(s): Ines Lara Sicilia
autogenerated on Fri Feb 5 2021 03:20:30