Go to the documentation of this file.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 
00031 
00032 
00033 
00034 
00035 
00036 
00039 #include <gtest/gtest.h>
00040 #include <pcl/common/pca.h>
00041 #include <pcl/point_types.h>
00042 #include <pcl/pcl_tests.h>
00043 
00044 using namespace pcl::test;
00045 
00046 pcl::PointCloud<pcl::PointXYZ> cloud;
00047 pcl::PCA<pcl::PointXYZ> pca;
00048 
00049 TEST(PCA, projection)
00050 {
00051   pcl::PointXYZ projected, reconstructed;
00052   for(size_t i = 0; i < cloud.size(); i++)
00053   {
00054     pca.project (cloud[i], projected);
00055     pca.reconstruct (projected, reconstructed);
00056     EXPECT_NEAR_VECTORS (reconstructed.getVector3fMap (), cloud[i].getVector3fMap (), 2.5e-4);
00057   }
00058 }
00059 
00060 TEST(PCA, copy_constructor)
00061 {
00062   
00063   pcl::PCA<pcl::PointXYZ> pca_copy(pca);
00064   try
00065   {
00066     Eigen::Matrix3f eigen_vectors_copy = pca_copy.getEigenVectors ();
00067     Eigen::Matrix3f eigen_vectors = pca.getEigenVectors ();
00068     for(size_t i = 0; i < 3; ++i)
00069       for(size_t j = 0; j < 3; ++j)
00070         EXPECT_EQ (eigen_vectors (i,j), eigen_vectors_copy (i,j));
00071   }
00072   catch (pcl::InitFailedException &)
00073   {
00074     std::cerr << "something wrong" << std::endl;
00075   }
00076 }
00077 
00078 TEST(PCA, cloud_projection)
00079 {
00080   pcl::PointCloud<pcl::PointXYZ> cloud_projected, cloud_reconstructed;
00081   try
00082   {
00083     pca.project (cloud, cloud_projected);
00084     EXPECT_EQ (cloud.size (), cloud_projected.size ());
00085     pca.reconstruct (cloud_projected, cloud_reconstructed);
00086     EXPECT_EQ (cloud_reconstructed.size (), cloud_projected.size ());
00087     for(size_t i = 0; i < cloud.size(); i++)
00088       EXPECT_NEAR_VECTORS (cloud[i].getVector3fMap (),
00089                            cloud_reconstructed[i].getVector3fMap (),
00090                            2.5e-4);
00091   }
00092   catch (pcl::InitFailedException &)
00093   {
00094     std::cerr << "something wrong" << std::endl;
00095   }
00096 }
00097 
00098 int main (int argc, char** argv)
00099 {
00100   cloud.width = 5;
00101   cloud.height = 4 ;
00102   cloud.is_dense = true;
00103   cloud.resize(20);
00104   cloud[0].x = 100;   cloud[0].y = 8;    cloud[0].z = 5;
00105   cloud[1].x = 228;   cloud[1].y = 21;   cloud[1].z = 2;
00106   cloud[2].x = 341;   cloud[2].y = 31;   cloud[2].z = 10;
00107   cloud[3].x = 472;   cloud[3].y = 40;   cloud[3].z = 15;
00108   cloud[4].x = 578;   cloud[4].y = 48;   cloud[4].z = 3;
00109   cloud[5].x = 699;   cloud[5].y = 60;   cloud[5].z = 12;
00110   cloud[6].x = 807;   cloud[6].y = 71;   cloud[6].z = 14;
00111   cloud[7].x = 929;   cloud[7].y = 79;   cloud[7].z = 16;
00112   cloud[8].x = 1040;  cloud[8].y = 92;   cloud[8].z = 18;
00113   cloud[9].x = 1160;  cloud[9].y = 101;  cloud[9].z = 38;
00114   cloud[10].x = 1262; cloud[10].y = 109; cloud[10].z = 28;
00115   cloud[11].x = 1376; cloud[11].y = 121; cloud[11].z = 32;
00116   cloud[12].x = 1499; cloud[12].y = 128; cloud[12].z = 35;
00117   cloud[13].x = 1620; cloud[13].y = 143; cloud[13].z = 28;
00118   cloud[14].x = 1722; cloud[14].y = 150; cloud[14].z = 30;
00119   cloud[15].x = 1833; cloud[15].y = 159; cloud[15].z = 15;
00120   cloud[16].x = 1948; cloud[16].y = 172; cloud[16].z = 12;
00121   cloud[17].x = 2077; cloud[17].y = 181; cloud[17].z = 33;
00122   cloud[18].x = 2282; cloud[18].y = 190; cloud[18].z = 23;
00123   cloud[19].x = 2999; cloud[19].y = 202; cloud[19].z = 29;  
00124 
00125   pca.setInputCloud (cloud.makeShared ());
00126 
00127   testing::InitGoogleTest (&argc, argv);
00128   return (RUN_ALL_TESTS ());
00129 }