30 #include <gtest/gtest.h> 35 #include <pcl/point_types.h> 45 const double front_std_dev,
46 const double side_std_dev)
49 vt(0, 0) = std::cos(yaw);
50 vt(0, 1) = -std::sin(yaw);
51 vt(1, 0) = std::sin(yaw);
52 vt(1, 1) = std::cos(yaw);
54 m(0, 0) = std::pow(front_std_dev, 2);
57 m(1, 1) = std::pow(side_std_dev, 2);
58 const Eigen::Matrix2d xv_cov = vt.transpose() * m * vt;
60 std::vector<State6DOF> result(6);
61 for (
auto& state : result)
63 for (
size_t i = 0; i < 6; ++i)
68 result[0][0] = xv_cov(0, 0);
69 result[1][0] = xv_cov(1, 0);
70 result[0][1] = xv_cov(0, 1);
71 result[1][1] = xv_cov(1, 1);
75 void buildWall(pcl::PointCloud<PointXYZIL>::Ptr result_points,
double rotation_angle,
int wall_length)
77 pcl::PointCloud<PointXYZIL> points;
78 for (
int ny = 0; ny < wall_length; ++ny)
80 for (
int nz = 0; nz < wall_length; ++nz)
84 point.y = (ny - wall_length / 2) * 0.05;
85 point.z = (nz - wall_length / 2) * 0.05;
88 points.push_back(point);
93 result_points->insert(result_points->end(), points.begin(), points.end());
98 pcl::PointCloud<PointXYZIL>::Ptr pc(
new pcl::PointCloud<PointXYZIL>());
105 const double robot_yaw = M_PI / 6;
110 const std::vector<unsigned int> seeds =
121 double perform_weighting_ratio;
122 double max_weight_ratio;
124 double expected_ratio_min;
125 double expected_ratio_max;
127 const std::vector<ParameterSet> parameters =
130 {2.0, 4.0, 10.0, 0.85, 1.0},
132 {6.0, 7.0, 10.0, 0.4, 0.6},
134 {2.0, 8.0, 5.0, 0.65, 0.85},
137 for (
const unsigned int seed : seeds)
141 const int sample_num = 100;
142 for (
const ParameterSet& parameter : parameters)
144 sampler.
setParameters(parameter.perform_weighting_ratio, parameter.max_weight_ratio, parameter.max_weight, 0.4);
145 const pcl::PointCloud<PointXYZIL>::Ptr extracted_cloud = sampler.
sample(pc, sample_num);
146 EXPECT_EQ(sample_num, static_cast<int>(extracted_cloud->size()));
149 std::vector<int> counts(2, 0);
150 for (
const auto& extracted_point : *extracted_cloud)
152 const auto pred = [&extracted_point](
const PointXYZIL& p) {
153 return (p.x == extracted_point.x) && (p.y == extracted_point.y) && (p.z == extracted_point.z);
155 const size_t index = std::find_if(pc->begin(), pc->end(), pred) - pc->begin();
156 ++counts[index / std::pow(wall_length, 2)];
158 const double ratio =
static_cast<double>(counts[0]) / (counts[0] + counts[1]);
159 EXPECT_GE(ratio, parameter.expected_ratio_min) <<
"Failed at seed #" << seed;
160 EXPECT_LE(ratio, parameter.expected_ratio_max) <<
"Failed at seed #" << seed;
166 pcl::PointCloud<PointXYZIL>::Ptr invalid_cloud(
new pcl::PointCloud<PointXYZIL>());
168 EXPECT_EQ(0u, sampler.
sample(invalid_cloud, 100)->size());
171 EXPECT_EQ(1u, sampler.
sample(invalid_cloud, 100)->size());
176 int main(
int argc,
char** argv)
178 testing::InitGoogleTest(&argc, argv);
180 return RUN_ALL_TESTS();
void buildWall(pcl::PointCloud< PointXYZIL >::Ptr result_points, double rotation_angle, int wall_length)
void transform(pcl::PointCloud< PointType > &pc) const
void setParameters(const double perform_weighting_ratio, const double max_weight_ratio, const double max_weight, const double normal_search_range)
int main(int argc, char **argv)
TEST(PointCloudSamplerWithNormal, Sampling)
void setParticleStatistics(const State6DOF &mean, const std::vector< State6DOF > &covariances)
std::vector< State6DOF > buildPoseCovarianceMatrix(const double yaw, const double front_std_dev, const double side_std_dev)
pcl::PointCloud< POINT_TYPE >::Ptr sample(const typename pcl::PointCloud< POINT_TYPE >::ConstPtr &pc, const size_t num) const final