34 #include <gtest/gtest.h>
40 TEST(RaycastUsingDDA, Collision)
42 pcl::PointCloud<pcl::PointXYZ> pc;
43 for (
float y = -1.0; y < 1.0; y += 0.1)
45 for (
float z = -1.0; z < 1.0; z += 0.1)
47 pc.push_back(pcl::PointXYZ(0.5, y, z));
51 pc.push_back(pcl::PointXYZ(-2.05, -2.05, -2.05));
52 pc.push_back(pcl::PointXYZ(2.05, 2.05, 2.05));
57 const float hit_range = std::sqrt(3.0) * 0.1;
59 for (
float y = -0.8; y < 0.8; y += 0.11)
61 for (
float z = -0.8; z < 0.8; z += 0.13)
63 bool collision =
false;
75 ASSERT_TRUE(collision);
78 for (
float y = -1.0; y < 1.0; y += 0.11)
80 for (
float z = -1.0; z < 1.0; z += 0.13)
82 bool collision =
false;
90 ASSERT_FALSE(collision);
94 bool collision =
false;
102 ASSERT_FALSE(collision);
106 TEST(RaycastUsingDDA, CollisionTolerance)
108 pcl::PointCloud<pcl::PointXYZ> pc;
109 for (
float y = -1.0; y < 1.0; y += 0.05)
111 for (
float z = -1.0; z < 1.0; z += 0.1)
113 pc.push_back(pcl::PointXYZ(0.5, y, z));
117 pc.push_back(pcl::PointXYZ(-2.05, -2.05, -2.05));
118 pc.push_back(pcl::PointXYZ(2.05, 2.05, 2.05));
126 bool collision =
false;
137 ASSERT_TRUE(collision);
140 bool collision =
false;
141 const float hit_range = std::sqrt(3.0) * 0.15;
153 ASSERT_FALSE(collision);
159 const mcl_3dl::Vec3& ray_end,
const std::vector<mcl_3dl::Vec3> expected_points,
160 const bool expected_collision)
162 raycaster.
setRay(kdtree, ray_begin, ray_end);
163 std::vector<mcl_3dl::Vec3> actual_points;
165 bool collision =
false;
168 actual_points.push_back(pos.
pos_);
175 EXPECT_EQ(expected_collision, collision) <<
"case: " << name;
176 ASSERT_EQ(expected_points.size(), actual_points.size()) <<
"case: " << name;
177 for (
size_t i = 0; i < expected_points.size(); ++i)
179 EXPECT_NEAR(expected_points[i].x_, actual_points[i].x_, 1.0e-6
f) <<
"case: " << name;
180 EXPECT_NEAR(expected_points[i].y_, actual_points[i].y_, 1.0e-6
f) <<
"case: " << name;
181 EXPECT_NEAR(expected_points[i].z_, actual_points[i].z_, 1.0e-6
f) <<
"case: " << name;
185 TEST(RaycastUsingDDA, Waypoints)
187 pcl::PointCloud<pcl::PointXYZ> pc;
188 pc.push_back(pcl::PointXYZ(0.9, 0.6, 0.0));
190 pc.push_back(pcl::PointXYZ(-2.05, -2.05, -2.05));
191 pc.push_back(pcl::PointXYZ(2.05, 2.05, 2.05));
198 const std::vector<mcl_3dl::Vec3> expected_points =
218 expected_points,
true);
222 const std::vector<mcl_3dl::Vec3> expected_points =
242 expected_points,
true);
246 TEST(RaycastUsingDDA, Intersection)
248 pcl::PointCloud<pcl::PointXYZ> pc;
249 pc.push_back(pcl::PointXYZ(0.6, -0.4, 0.0));
251 pc.push_back(pcl::PointXYZ(-2.1, -2.1, -2.1));
252 pc.push_back(pcl::PointXYZ(2.1, 2.1, 2.1));
258 const std::vector<mcl_3dl::Vec3> expected_points =
268 expected_points,
true);
271 const std::vector<mcl_3dl::Vec3> expected_points =
284 expected_points,
false);
288 int main(
int argc,
char** argv)
290 testing::InitGoogleTest(&argc, argv);
292 return RUN_ALL_TESTS();