test_fod_detector.cpp
Go to the documentation of this file.
1 
18 #include "FODDetector.h"
19 #include "Utils.h"
20 #include <gtest/gtest.h>
21 #include <exception>
22 #include <Viewer.h>
23 
24 
25 typedef pcl::PointCloud<pcl::PointXYZRGB> PointCloudRGB;
26 
27 class TestFODDetector : public ::testing::Test
28 {
29  protected:
30 
32 
33  void cubesPointCloud(PointCloudRGB::Ptr cloud, float pos, float dim, float step){
34  pcl::PointXYZRGB p_rgb;
35  for (float i=pos; i<pos+dim; i+=step) {
36  for (float j=pos; j<pos+dim; j+=step){
37  for (float k=pos; k<pos+dim; k+=step){
38  p_rgb.x = i;
39  p_rgb.y = j;
40  p_rgb.z = k;
41  p_rgb.r = 255;
42  p_rgb.g = 255;
43  p_rgb.b = 255;
44  cloud->push_back(p_rgb);
45  }
46  }
47  }
48  }
49 };
50 
51 // Test TestFODDetector should return 3 cluster indices
52 TEST_F(TestFODDetector, testFODClustering)
53 {
54  PointCloudRGB::Ptr cloudRGB {new pcl::PointCloud<pcl::PointXYZRGB>};
55 
56  cubesPointCloud(cloudRGB, 0, 3, 0.1);
57  cubesPointCloud(cloudRGB, 10, 3, 0.1);
58  cubesPointCloud(cloudRGB, 20, 3, 0.1);
59 
60  int min_fod_points = 3;
61  double voxelize_factor = 3;
62  double th = 4e-3 * voxelize_factor;
63 
64  FODDetector fod_detector(cloudRGB, th*10, min_fod_points);
65  fod_detector.clusterPossibleFODs();
66 
67  std::vector<PointCloudRGB::Ptr> fods_cloud_array;
68  int num_of_fods = fod_detector.fodIndicesToPointCloud(fods_cloud_array);
69 
70  ASSERT_EQ(num_of_fods,3);
71  ASSERT_EQ(fods_cloud_array.size(),3);
72 }
73 
74 // Test TestFODDetector should return error with empty cloud
75 TEST_F(TestFODDetector, testEmptyCloud)
76 {
77  pcl::PointCloud<pcl::PointXYZRGB>::Ptr empty_cloud {new pcl::PointCloud<pcl::PointXYZRGB>};
78 
79  int min_fod_points = 3;
80  double voxelize_factor = 3;
81  double th = 4e-3 * voxelize_factor;
82 
83  FODDetector fod_detector(empty_cloud, th*10, min_fod_points);
84  fod_detector.clusterPossibleFODs();
85 
86  std::vector<PointCloudRGB::Ptr> fods_cloud_array;
87  int num_of_fods = fod_detector.fodIndicesToPointCloud(fods_cloud_array);
88 
89  ASSERT_EQ(num_of_fods, 0);
90  ASSERT_EQ(fods_cloud_array.size(), 0);
91 }
92 
93 // // Test testFODROSmsg should return success
94 TEST_F(TestFODDetector, testFODmsg)
95 {
97 
98  pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloudRGB {new pcl::PointCloud<pcl::PointXYZRGB>};
99 
100  cubesPointCloud(cloudRGB, 0, 3, 0.1);
101  cubesPointCloud(cloudRGB, 10, 3, 0.1);
102  cubesPointCloud(cloudRGB, 20, 3, 0.1);
103 
104  int min_fod_points = 3;
105  double voxelize_factor = 3;
106  double th = 4e-3 * voxelize_factor;
107 
108  FODDetector fod_detector(cloudRGB, th*10, min_fod_points);
109  fod_detector.clusterPossibleFODs();
110 
111  std::vector<sensor_msgs::PointCloud2> cluster_msg_array;
112  int num_of_fods = fod_detector.fodIndicesToROSMsg(cluster_msg_array);
113 
114  ASSERT_EQ(num_of_fods, 3);
115  ASSERT_EQ(cluster_msg_array.size(), 3);
116 }
117 
118 // Run all the tests that were declared with TEST()
119 int main(int argc, char **argv){
120  testing::InitGoogleTest(&argc, argv);
121 
122  return RUN_ALL_TESTS();
123 }
int fodIndicesToPointCloud(std::vector< PointCloudRGB::Ptr > &cloud_array)
Save each cluster (possible FOD) in a pcl::PointCloudRGB. Give back an array of all generated clouds...
Definition: FODDetector.cpp:60
int main(int argc, char **argv)
TEST_F(TestFODDetector, testFODClustering)
static void init()
void clusterPossibleFODs()
Extract cluster indices from input cloud with resolution set. Each cluster is a possible FOD...
Definition: FODDetector.cpp:45
int fodIndicesToROSMsg(std::vector< sensor_msgs::PointCloud2 > &cluster_msg_array)
Save each cluster (possible FOD) in a PointCloud2 msg. Give back an array of all generated msgs...
Definition: FODDetector.cpp:80
pcl::PointCloud< pcl::PointXYZRGB > PointCloudRGB
void cubesPointCloud(PointCloudRGB::Ptr cloud, float pos, float dim, float step)


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