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 =
208 expected_points,
true);
212 const std::vector<mcl_3dl::Vec3> expected_points =
222 expected_points,
true);
226 TEST(RaycastUsingDDA, Intersection)
228 pcl::PointCloud<pcl::PointXYZ> pc;
229 pc.push_back(pcl::PointXYZ(0.6, -0.4, 0.0));
231 pc.push_back(pcl::PointXYZ(-2.1, -2.1, -2.1));
232 pc.push_back(pcl::PointXYZ(2.1, 2.1, 2.1));
238 const std::vector<mcl_3dl::Vec3> expected_points =
245 expected_points,
true);
248 const std::vector<mcl_3dl::Vec3> expected_points =
257 expected_points,
false);
261 int main(
int argc,
char** argv)
263 testing::InitGoogleTest(&argc, argv);
265 return RUN_ALL_TESTS();
TEST(RaycastUsingDDA, Collision)
std::shared_ptr< ChunkedKdtree > Ptr
void setInputCloud(const typename pcl::PointCloud< POINT_TYPE >::ConstPtr &cloud)
int main(int argc, char **argv)
TFSIMD_FORCE_INLINE const tfScalar & y() const
void compareRayWaypoints(const char *name, typename mcl_3dl::ChunkedKdtree< pcl::PointXYZ >::Ptr kdtree, mcl_3dl::RaycastUsingDDA< pcl::PointXYZ > &raycaster, const mcl_3dl::Vec3 &ray_begin, const mcl_3dl::Vec3 &ray_end, const std::vector< mcl_3dl::Vec3 > expected_points, const bool expected_collision)
INLINE Rall1d< T, V, S > sqrt(const Rall1d< T, V, S > &arg)
void setRay(typename ChunkedKdtree< POINT_TYPE >::Ptr kdtree, const Vec3 ray_begin, const Vec3 ray_end_org) final
TFSIMD_FORCE_INLINE const tfScalar & z() const
bool getNextCastResult(CastResult &result) final