00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include <cstddef>
00031 #include <cmath>
00032 #include <vector>
00033
00034 #include <gtest/gtest.h>
00035
00036 #include <mcl_3dl/chunked_kdtree.h>
00037 #include <mcl_3dl/raycast.h>
00038
00039 TEST(Raycast, Collision)
00040 {
00041 pcl::PointCloud<pcl::PointXYZ> pc;
00042 for (float y = -1.0; y < 1.0; y += 0.1)
00043 {
00044 for (float z = -1.0; z < 1.0; z += 0.1)
00045 {
00046 pc.push_back(pcl::PointXYZ(0.5, y, z));
00047 }
00048 }
00049 mcl_3dl::ChunkedKdtree<pcl::PointXYZ>::Ptr kdtree(new mcl_3dl::ChunkedKdtree<pcl::PointXYZ>(10.0, 1.0));
00050 kdtree->setInputCloud(pc.makeShared());
00051
00052 for (float y = -0.8; y < 0.8; y += 0.11)
00053 {
00054 for (float z = -0.8; z < 0.8; z += 0.13)
00055 {
00056 bool collision = false;
00057 mcl_3dl::Raycast<pcl::PointXYZ> ray(
00058 kdtree,
00059 mcl_3dl::Vec3(0.0, 0.0, 0.0), mcl_3dl::Vec3(1.0, y * 2.0, z * 2.0), 0.1, 0.1);
00060 for (auto point : ray)
00061 {
00062 if (point.collision_)
00063 {
00064 collision = true;
00065 EXPECT_NEAR((point.pos_ - mcl_3dl::Vec3(0.5, y, z)).norm(), 0.0, 0.2);
00066 break;
00067 }
00068 }
00069 ASSERT_TRUE(collision);
00070 }
00071 }
00072 for (float y = -1.0; y < 1.0; y += 0.11)
00073 {
00074 for (float z = -1.0; z < 1.0; z += 0.13)
00075 {
00076 bool collision = false;
00077 mcl_3dl::Raycast<pcl::PointXYZ> ray(
00078 kdtree,
00079 mcl_3dl::Vec3(0.0, 0.0, 0.0), mcl_3dl::Vec3(0.5, y, z), 0.1, 0.1);
00080 for (auto point : ray)
00081 {
00082 if (point.collision_)
00083 collision = true;
00084 }
00085 ASSERT_FALSE(collision);
00086 }
00087 }
00088 {
00089 bool collision = false;
00090 mcl_3dl::Raycast<pcl::PointXYZ> ray(
00091 kdtree,
00092 mcl_3dl::Vec3(0.0, 0.0, 0.0), mcl_3dl::Vec3(0.5, 3.0, 0.0), 0.1, 0.1);
00093 for (auto point : ray)
00094 {
00095 if (point.collision_)
00096 collision = true;
00097 }
00098 ASSERT_FALSE(collision);
00099 }
00100 }
00101
00102 TEST(Raycast, CollisionTolerance)
00103 {
00104 pcl::PointCloud<pcl::PointXYZ> pc;
00105 for (float y = -1.0; y < 1.0; y += 0.05)
00106 {
00107 for (float z = -1.0; z < 1.0; z += 0.1)
00108 {
00109 pc.push_back(pcl::PointXYZ(0.5, y, z));
00110 }
00111 }
00112 mcl_3dl::ChunkedKdtree<pcl::PointXYZ>::Ptr kdtree(new mcl_3dl::ChunkedKdtree<pcl::PointXYZ>(10.0, 1.0));
00113 kdtree->setInputCloud(pc.makeShared());
00114
00115 {
00116 bool collision = false;
00117 mcl_3dl::Raycast<pcl::PointXYZ> ray(
00118 kdtree,
00119 mcl_3dl::Vec3(0.0, 0.0, 0.0), mcl_3dl::Vec3(0.7, 0.0, 0.0), 0.05, 0.1);
00120 for (auto point : ray)
00121 {
00122 if (point.collision_)
00123 {
00124 collision = true;
00125 break;
00126 }
00127 }
00128 ASSERT_TRUE(collision);
00129 }
00130 {
00131 bool collision = false;
00132 mcl_3dl::Raycast<pcl::PointXYZ> ray(
00133 kdtree,
00134 mcl_3dl::Vec3(0.0, 0.0, 0.0), mcl_3dl::Vec3(0.5, 0.0, 0.0), 0.1, 0.15);
00135 for (auto point : ray)
00136 {
00137 if (point.collision_)
00138 {
00139 collision = true;
00140 break;
00141 }
00142 }
00143 ASSERT_FALSE(collision);
00144 }
00145 {
00146 bool collision = false;
00147 mcl_3dl::Raycast<pcl::PointXYZ> ray(
00148 kdtree,
00149 mcl_3dl::Vec3(0.0, 0.0, 0.0), mcl_3dl::Vec3(0.3, 0.0, 0.0), 0.1, 0.15);
00150 for (auto point : ray)
00151 {
00152 if (point.collision_)
00153 {
00154 collision = true;
00155 break;
00156 }
00157 }
00158 ASSERT_FALSE(collision);
00159 }
00160 }
00161 TEST(Raycast, SinAng)
00162 {
00163 pcl::PointCloud<pcl::PointXYZ> pc;
00164 for (float y = -1.0; y < 1.0; y += 0.1)
00165 {
00166 for (float z = -1.0; z < 1.0; z += 0.1)
00167 {
00168 pc.push_back(pcl::PointXYZ(0.5, y, z));
00169 }
00170 }
00171 mcl_3dl::ChunkedKdtree<pcl::PointXYZ>::Ptr kdtree(new mcl_3dl::ChunkedKdtree<pcl::PointXYZ>(10.0, 1.0));
00172 kdtree->setInputCloud(pc.makeShared());
00173
00174 {
00175 bool collision = false;
00176 mcl_3dl::Raycast<pcl::PointXYZ> ray(
00177 kdtree,
00178 mcl_3dl::Vec3(0.0, 0.0, 0.0), mcl_3dl::Vec3(1.0, 0.0, 0.0), 0.1, 0.1);
00179 for (auto point : ray)
00180 {
00181 if (point.collision_)
00182 {
00183 EXPECT_NEAR(point.sin_angle_, 1.0, 0.1);
00184 collision = true;
00185 break;
00186 }
00187 }
00188 ASSERT_TRUE(collision);
00189 }
00190 {
00191 bool collision = false;
00192 mcl_3dl::Raycast<pcl::PointXYZ> ray(
00193 kdtree,
00194 mcl_3dl::Vec3(0.0, 5.0, 0.0), mcl_3dl::Vec3(1.0, -5.0, 0.0), 0.1, 0.1);
00195 for (auto point : ray)
00196 {
00197 if (point.collision_)
00198 {
00199 EXPECT_NEAR(point.sin_angle_, sinf(0.5 / 5.0), 0.05);
00200 collision = true;
00201 break;
00202 }
00203 }
00204 ASSERT_TRUE(collision);
00205 }
00206 {
00207 bool collision = false;
00208 mcl_3dl::Raycast<pcl::PointXYZ> ray(
00209 kdtree,
00210 mcl_3dl::Vec3(0.0, 3.0, 0.0), mcl_3dl::Vec3(1.0, -3.0, 0.0), 0.1, 0.1);
00211 for (auto point : ray)
00212 {
00213 if (point.collision_)
00214 {
00215 EXPECT_NEAR(point.sin_angle_, sinf(0.5 / 3.0), 0.05);
00216 collision = true;
00217 break;
00218 }
00219 }
00220 ASSERT_TRUE(collision);
00221 }
00222 }
00223
00224 int main(int argc, char** argv)
00225 {
00226 testing::InitGoogleTest(&argc, argv);
00227
00228 return RUN_ALL_TESTS();
00229 }