test_utils.cpp
Go to the documentation of this file.
1 
18 #include "Utils.h"
19 #include <gtest/gtest.h>
20 #include <exception>
21 
22 typedef pcl::PointCloud<pcl::PointXYZ> PointCloudXYZ;
23 typedef pcl::PointCloud<pcl::PointXYZRGB> PointCloudRGB;
24 
25 class TestUtils : public ::testing::Test {
26 
27  protected:
28 
30 
31  void cubeXYZ(PointCloudXYZ::Ptr cloud, float dim, float step){
32  pcl::PointXYZ p_rgb;
33  for (float i=0; i<dim; i+=step) {
34  for (float j=0; j<dim; j+=step){
35  for (float k=0; k<dim; k+=step){
36  p_rgb.x = i;
37  p_rgb.y = j;
38  p_rgb.z = k;
39  cloud->push_back(p_rgb);
40  }
41  }
42  }
43  }
44 
45  void cubeRGB(PointCloudRGB::Ptr cloud, float dim, float step){
46  pcl::PointXYZRGB p_rgb;
47  for (float i=0; i<dim; i+=step) {
48  for (float j=0; j<dim; j+=step){
49  for (float k=0; k<dim; k+=step){
50  p_rgb.x = i;
51  p_rgb.y = j;
52  p_rgb.z = k;
53  p_rgb.r = 255;
54  p_rgb.g = 255;
55  p_rgb.b = 255;
56  cloud->push_back(p_rgb);
57  }
58  }
59  }
60  }
61 };
62 
63 TEST_F(TestUtils, testValidCloud)
64 {
65  PointCloudXYZ::Ptr cloudXYZ {new pcl::PointCloud<pcl::PointXYZ>};
66  PointCloudRGB::Ptr cloudRGB {new pcl::PointCloud<pcl::PointXYZRGB>};
67 
68  EXPECT_FALSE(Utils::isValidCloud(cloudXYZ));
69  EXPECT_FALSE(Utils::isValidCloud(cloudRGB));
70 
71  cubeXYZ(cloudXYZ, 3, 0.1);
72  cubeRGB(cloudRGB, 3, 0.1);
73 
74  EXPECT_TRUE(Utils::isValidCloud(cloudXYZ));
75  EXPECT_TRUE(Utils::isValidCloud(cloudRGB));
76 }
77 
78 TEST_F(TestUtils, testCloudResolution)
79 {
80  PointCloudXYZ::Ptr cloudXYZ {new pcl::PointCloud<pcl::PointXYZ>};
81  PointCloudRGB::Ptr cloudRGB {new pcl::PointCloud<pcl::PointXYZRGB>};
82 
83  double res = 0.1;
84  cubeXYZ(cloudXYZ, 3, res);
85  cubeRGB(cloudRGB, 3, res);
86 
87  double res_pc = Utils::computeCloudResolution(cloudXYZ);
88  EXPECT_TRUE((res_pc >= res-0.05) && (res_pc <= res+0.05));
89 
90  res = Utils::computeCloudResolution(cloudRGB);
91  EXPECT_TRUE((res_pc >= res-0.05) && (res_pc <= res+0.05));
92 }
93 
94 TEST_F(TestUtils, testCloudConversions)
95 {
96  PointCloudXYZ::Ptr cloudXYZ {new pcl::PointCloud<pcl::PointXYZ>};
97  PointCloudRGB::Ptr cloudRGB {new pcl::PointCloud<pcl::PointXYZRGB>};
98 
99  cubeXYZ(cloudXYZ, 3, 0.1);
100  Utils::cloudToXYZRGB(cloudXYZ, cloudRGB, 255, 255, 255);
101 }
102 
103 TEST_F(TestUtils, testCloudToROSMsg)
104 {
105  ros::Time::init(); // because message stamp need ros::Time::now()
106 
107  PointCloudRGB::Ptr cloudRGB {new pcl::PointCloud<pcl::PointXYZRGB>};
108  cubeRGB(cloudRGB, 3, 0.1);
109 
110  sensor_msgs::PointCloud2 cloudMsg;
111  Utils::cloudToROSMsg(cloudRGB, cloudMsg);
112 }
113 
114 TEST_F(TestUtils, testCloudTranslate)
115 {
116  PointCloudRGB::Ptr cloudRGB_orig {new pcl::PointCloud<pcl::PointXYZRGB>};
117  PointCloudRGB::Ptr cloudRGB_tras {new pcl::PointCloud<pcl::PointXYZRGB>};
118 
119  cubeRGB(cloudRGB_orig, 3, 0.1);
120  Utils::translateCloud(cloudRGB_orig, cloudRGB_tras, 5, 0, 0);
121  std::cout << cloudRGB_tras->points[0].x << std::endl;
122  ASSERT_EQ(cloudRGB_tras->points[0].x, 5);
123 
124  Utils::translateCloud(cloudRGB_tras, cloudRGB_tras, -5, 0, 0);
125  std::cout << cloudRGB_tras->points[0].x << std::endl;
126  ASSERT_EQ(cloudRGB_tras->points[0].x, 0);
127 }
128 
129 // TEST_F(TestUtils, testCloudRotate)
130 // {
131 // // create RGB pointcloud
132 // pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud_in {new pcl::PointCloud<pcl::PointXYZRGB>};
133 // pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud_out {new pcl::PointCloud<pcl::PointXYZRGB>};
134 // cubePointCloud(cloud_in, 5, 1);
135 
136 // Utils::rotateCloud(cloud_in, cloud_out, 5, 0, 0);
137 // ASSERT_NE(*cloud_orig, *cloud_in);
138 // }
139 
140 
141 // Run all the tests that were declared with TEST()
142 int main(int argc, char **argv){
143  testing::InitGoogleTest(&argc, argv);
144 
145  return RUN_ALL_TESTS();
146 }
int main(int argc, char **argv)
Definition: test_utils.cpp:142
static void cloudToXYZRGB(PointCloudXYZ::Ptr cloud, PointCloudRGB::Ptr cloud_rgb, int R, int G, int B)
Convert XYZ cloud to XYZRGB cloud with specified RGB values.
Definition: Utils.cpp:94
static bool isValidCloud(PointCloudXYZ::Ptr cloud)
Check whether cloud contains data and is not empty.
Definition: Utils.cpp:46
TEST_F(TestUtils, testValidCloud)
Definition: test_utils.cpp:63
void cubeRGB(PointCloudRGB::Ptr cloud, float dim, float step)
Definition: test_utils.cpp:45
void cubeXYZ(PointCloudXYZ::Ptr cloud, float dim, float step)
Definition: test_utils.cpp:31
static void cloudToROSMsg(PointCloudRGB::Ptr cloud, sensor_msgs::PointCloud2 &cloud_msg, const std::string &frameid="world")
Convert XYZRGB cloud to PointCloud2.
Definition: Utils.cpp:100
static void init()
pcl::PointCloud< pcl::PointXYZRGB > PointCloudRGB
Definition: test_utils.cpp:23
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
static double computeCloudResolution(PointCloudXYZ::Ptr cloud)
Obtain the resolution of the cloud.
Definition: Utils.cpp:114
pcl::PointCloud< pcl::PointXYZ > PointCloudXYZ
Definition: test_utils.cpp:22


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