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 <gtest/gtest.h>
00031 #include <ros/assert.h>
00032 #include <laser_slam/scan_intersection.h>
00033 #include <boost/foreach.hpp>
00034 #include <boost/assign.hpp>
00035
00036 using std::vector;
00037 namespace ls=laser_slam;
00038
00039 const double PI=3.14159265;
00040
00041 btTransform makePose (const double x, const double y, const double th)
00042 {
00043 return btTransform(btQuaternion(btVector3(0,0,1), th),
00044 btVector3(x,y,0));
00045 }
00046
00047
00048
00049 TEST(LaserSlam, ScanIntersection)
00050 {
00051 vector<btVector3> poly(4);
00052 poly[1].setX(-5);
00053 poly[1].setY(1);
00054 poly[2].setY(8);
00055 poly[3].setX(5);
00056 poly[3].setY(1);
00057
00058 ls::ScanIntersection scan_int(poly);
00059
00060 const btVector3 p(5, 5, 0);
00061 const btTransform p1 = makePose(0,0,0);
00062 const btTransform p2 = makePose(0,0,PI);
00063 const btTransform p3 = makePose(4,4,0);
00064 const btTransform p4 = makePose(4,4,PI);
00065 const btTransform p5 = makePose(-0.1, -0.1, 0);
00066
00067 EXPECT_TRUE (!scan_int.contains(p1, p));
00068 EXPECT_TRUE (!scan_int.contains(p2, p));
00069 EXPECT_TRUE (scan_int.contains(p3, p));
00070 EXPECT_TRUE (!scan_int.contains(p4, p));
00071
00072 vector<btTransform> r1;
00073 r1.push_back(p1);
00074 vector<btTransform> r2;
00075 r2.push_back(p2);
00076
00077 EXPECT_NEAR (scan_int.unseenProportion(p5, r1), 0, 0.1);
00078 EXPECT_NEAR (scan_int.unseenProportion(p5, r2), 1, 0.1);
00079 }
00080
00081 int main (int argc, char** argv)
00082 {
00083 testing::InitGoogleTest(&argc, argv);
00084 return RUN_ALL_TESTS();
00085 }
00086