test_initial_alignment.cpp
Go to the documentation of this file.
1 
18 #include "InitialAlignment.h"
19 #include "CADToPointCloud.h"
20 #include "leica_scanstation_utils/LeicaUtils.h"
21 #include <Viewer.h>
22 #include <gtest/gtest.h>
23 
24 typedef pcl::PointCloud<pcl::PointXYZRGB> PointCloudRGB;
25 
26 class TestInitialAlignment : public ::testing::Test
27 {
28 protected:
29 
30  PointCloudRGB::Ptr cloudRGB {new PointCloudRGB};
31  PointCloudRGB::Ptr sourceRGB {new PointCloudRGB};
32  PointCloudRGB::Ptr targetRGB {new PointCloudRGB};
33 
35  {
37  Utils::translateCloud(sourceRGB, targetRGB, 0.05, 0.05, 0.05);
38  }
39 
40  void cubePointCloud(PointCloudRGB::Ptr cloud)
41  {
42  std::string pkg_path = ros::package::getPath("leica_point_cloud_processing");
43  std::string f = pkg_path + "/test/cube.ply";
44 
45  int sample_points = 20000;
46 
47  CADToPointCloud cad2pc(f, sample_points);
48  cad2pc.convertCloud(cloud);
49  }
50 };
51 
53 {
54  InitialAlignment initial_alignment(targetRGB, sourceRGB);
55 
56  Eigen::Matrix4f tf = initial_alignment.getRigidTransform();
57  ASSERT_EQ(tf, Eigen::Matrix4f::Identity()); // constructor works well
58 
59  initial_alignment.run(); // run method works well
60 
61  initial_alignment.applyTFtoCloud(sourceRGB);
62 
63  double tolerance = 1e-3;
64  // check first point for translation result is conincident with first point in target
65  EXPECT_TRUE(abs(sourceRGB->points[0].x-targetRGB->points[0].x) <= tolerance);
66  EXPECT_TRUE(abs(sourceRGB->points[0].x-targetRGB->points[0].x) <= tolerance);
67  EXPECT_TRUE(abs(sourceRGB->points[0].x-targetRGB->points[0].x) <= tolerance);
68 }
69 
71 {
72  InitialAlignment initial_alignment(targetRGB, sourceRGB);
73 
74  Eigen::Matrix4f tf = initial_alignment.getRigidTransform();
75  ASSERT_EQ(tf, Eigen::Matrix4f::Identity()); // constructor works well
76 
77  initial_alignment.run(); // run method works well
78 
79  tf = initial_alignment.getRigidTransform();
80 
81  double translation = 0.05;
82  double tolerance = 1e-3;
83  // check translation result is translation value applied to target
84  EXPECT_TRUE(abs(tf.col(3)[0]-translation) <= tolerance);
85  EXPECT_TRUE(abs(tf.col(3)[1]-translation) <= tolerance);
86  EXPECT_TRUE(abs(tf.col(3)[2]-translation) <= tolerance);
87 }
88 
90 {
91  InitialAlignment initial_alignment(targetRGB, sourceRGB);
92  initial_alignment.setMethod(AlignmentMethod::HARRIS);
93  initial_alignment.run(); // run method works well
94 
95  Eigen::Matrix4f tf = initial_alignment.getRigidTransform();
96  double translation = 0.05;
97  double tolerance = 1e-3;
98  // check translation result is translation value applied to target
99  EXPECT_TRUE(abs(tf.col(3)[0]-translation) <= tolerance);
100  EXPECT_TRUE(abs(tf.col(3)[1]-translation) <= tolerance);
101  EXPECT_TRUE(abs(tf.col(3)[2]-translation) <= tolerance);
102 }
103 
104 TEST_F(TestInitialAlignment, testMultiscaleAlg)
105 {
106  InitialAlignment initial_alignment(targetRGB, sourceRGB);
107  initial_alignment.setMethod(AlignmentMethod::MULTISCALE);
108  initial_alignment.run(); // run method works well
109 
110  Eigen::Matrix4f tf = initial_alignment.getRigidTransform();
111  double translation = 0.05;
112  double tolerance = 1e-3;
113  // check translation result is translation value applied to target
114  EXPECT_TRUE(abs(tf.col(3)[0]-translation) <= tolerance);
115  EXPECT_TRUE(abs(tf.col(3)[1]-translation) <= tolerance);
116  EXPECT_TRUE(abs(tf.col(3)[2]-translation) <= tolerance);
117 }
118 
119 TEST_F(TestInitialAlignment, testNormalsAlg)
120 {
121  InitialAlignment initial_alignment(targetRGB, sourceRGB);
122  initial_alignment.setMethod(AlignmentMethod::NORMALS);
123  initial_alignment.run(); // run method works well
124 
125  Eigen::Matrix4f tf = initial_alignment.getRigidTransform();
126  double translation = 0.05;
127  double tolerance = 1e-3;
128  // check translation result is translation value applied to target
129  EXPECT_TRUE(abs(tf.col(3)[0]-translation) <= tolerance);
130  EXPECT_TRUE(abs(tf.col(3)[1]-translation) <= tolerance);
131  EXPECT_TRUE(abs(tf.col(3)[2]-translation) <= tolerance);
132 
133  initial_alignment.applyTFtoCloud(sourceRGB);
134  // check first point for translation result is conincident with first point in target
135  EXPECT_TRUE(abs(sourceRGB->points[0].x-targetRGB->points[0].x) <= tolerance);
136  EXPECT_TRUE(abs(sourceRGB->points[0].x-targetRGB->points[0].x) <= tolerance);
137  EXPECT_TRUE(abs(sourceRGB->points[0].x-targetRGB->points[0].x) <= tolerance);
138 }
139 
140 // Run all the tests that were declared with TEST()
141 int main(int argc, char **argv){
142  testing::InitGoogleTest(&argc, argv);
143  return RUN_ALL_TESTS();
144 }
pcl::PointCloud< pcl::PointXYZRGB > PointCloudRGB
f
int main(int argc, char **argv)
PointCloudRGB::Ptr sourceRGB
void run()
Perform initial alignment.
pcl::PointCloud< pcl::PointXYZRGB > PointCloudRGB
Eigen::Matrix4f getRigidTransform()
Get the rigid transform object.
void applyTFtoCloud(PointCloudRGB::Ptr cloud)
Once initial alignment is finished, apply rigid transformation to given cloud.
This class is used to obtain pcl::PointCloud from CAD file. Supported formats: .OBJ.
ROSLIB_DECL std::string getPath(const std::string &package_name)
static void translateCloud(PointCloudRGB::Ptr cloud_in, PointCloudRGB::Ptr cloud_out, double x_offset=0, double y_offset=0, double z_offset=0)
Apply translation to Cloud. Values given in [m].
Definition: Utils.cpp:203
void convertCloud(PointCloudRGB::Ptr cloud)
convert cloud defined by path in construstor into cloud
void cubePointCloud(PointCloudRGB::Ptr cloud)
void setMethod(AlignmentMethod method)
Set the AlignmentMethod object.
PointCloudRGB::Ptr targetRGB
TEST_F(TestInitialAlignment, testApplyTF)


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