Go to the documentation of this file.00001 #include "../utest.h"
00002
00003 using namespace std;
00004 using namespace PointMatcherSupport;
00005
00006
00007
00008
00009
00010 TEST(IOTest, loadYaml)
00011 {
00012
00013
00014 std::ifstream ifs0((dataPath + "default-convert.yaml").c_str());
00015 EXPECT_NO_THROW(PM::DataPointsFilters filters(ifs0));
00016
00017
00018 PM::ICP icp;
00019
00020 std::ifstream ifs1((dataPath + "default.yaml").c_str());
00021 EXPECT_NO_THROW(icp.loadFromYaml(ifs1));
00022
00023 std::ifstream ifs2((dataPath + "unit_tests/badIcpConfig_InvalidParameter.yaml").c_str());
00024 EXPECT_THROW(icp.loadFromYaml(ifs2), PointMatcherSupport::Parametrizable::InvalidParameter);
00025
00026 std::ifstream ifs3((dataPath + "unit_tests/badIcpConfig_InvalidModuleType.yaml").c_str());
00027 EXPECT_THROW(icp.loadFromYaml(ifs3), PointMatcherSupport::InvalidModuleType);
00028 }
00029
00030 TEST(IOTest, loadPLY)
00031 {
00032 typedef PointMatcherIO<float> IO;
00033 std::istringstream is;
00034
00035 is.str(
00036 ""
00037 );
00038
00039 EXPECT_THROW(IO::loadPLY(is), runtime_error);
00040
00041 is.clear();
00042 is.str(
00043 "ply\n"
00044 "format binary_big_endian 1.0\n"
00045 );
00046
00047 EXPECT_THROW(IO::loadPLY(is), runtime_error);
00048
00049 is.clear();
00050 is.str(
00051 "ply\n"
00052 "format ascii 2.0\n"
00053 );
00054
00055 EXPECT_THROW(IO::loadPLY(is), runtime_error);
00056
00057 is.clear();
00058 is.str(
00059 "ply\n"
00060 "format ascii 1.0\n"
00061 );
00062
00063 EXPECT_THROW(IO::loadPLY(is), runtime_error);
00064
00065 is.clear();
00066 is.str(
00067 "ply\n"
00068 "format ascii 1.0\n"
00069 "element vertex 5\n"
00070 "\n"
00071 "property float z\n"
00072 "property float y\n"
00073 "property float x\n"
00074 "property float grrrr\n"
00075 "property float nz\n"
00076 "property float ny\n"
00077 "property float nx\n"
00078 "end_header\n"
00079 "3 2 1 99 33 22 11\n"
00080 "3 2 1 99 33 22 11\n"
00081 "\n"
00082 "3 2 1 99 33 22 11 3 2 1 99 33 22 11\n"
00083 "3 2 1 99 33 22 11\n"
00084
00085 );
00086
00087 DP pointCloud = IO::loadPLY(is);
00088
00089
00090 EXPECT_TRUE(pointCloud.features.cols() == 5);
00091 EXPECT_TRUE(pointCloud.features.rows() == 4);
00092 EXPECT_TRUE(pointCloud.descriptors.cols() == 5);
00093 EXPECT_TRUE(pointCloud.descriptors.rows() == 3);
00094
00095
00096 EXPECT_TRUE(pointCloud.features(0, 0) == 1);
00097 EXPECT_TRUE(pointCloud.features(2, 2) == 3);
00098 EXPECT_TRUE(pointCloud.descriptors(1, 1) == 22);
00099 EXPECT_TRUE(pointCloud.descriptors(2, 4) == 33);
00100
00101 }
00102
00103 class IOLoadSaveTest : public testing::Test
00104 {
00105
00106 public:
00107 virtual void SetUp()
00108 {
00109 nbPts = 10;
00110 addRandomFeature("x", 1);
00111 addRandomFeature("y", 1);
00112 addRandomFeature("z", 1);
00113 ptCloud.addFeature("pad", PM::Matrix::Ones(1, nbPts));
00114
00115 addRandomDescriptor("normals",3);
00116 addRandomDescriptor("eigValues",3);
00117 addRandomDescriptor("eigVectors",9);
00118 addRandomDescriptor("color",4);
00119 }
00120
00121 void addRandomFeature(const string& featureName, const int rows)
00122 {
00123 ptCloud.addFeature(featureName,PM::Matrix::Random(rows, nbPts));
00124 }
00125
00126 void addRandomDescriptor(const string& descriptorName, const int rows)
00127 {
00128 ptCloud.addDescriptor(descriptorName, PM::Matrix::Random(rows, nbPts));
00129 }
00130
00131 virtual void loadSaveTest(const string& testFileName, const int nbPts = 10)
00132 {
00133 this->testFileName = testFileName;
00134 ptCloud.save(testFileName);
00135
00136 ptCloudFromFile = DP::load(testFileName);
00137
00138 EXPECT_TRUE(ptCloudFromFile.features.cols() == ptCloud.features.cols());
00139 EXPECT_TRUE(ptCloudFromFile.descriptorExists("normals",3));
00140 EXPECT_TRUE(ptCloudFromFile.getDescriptorViewByName("normals").isApprox(ptCloud.getDescriptorViewByName("normals")));
00141 EXPECT_TRUE(ptCloudFromFile.descriptorExists("eigValues",3));
00142 EXPECT_TRUE(ptCloudFromFile.getDescriptorViewByName("eigValues").isApprox(ptCloud.getDescriptorViewByName("eigValues")));
00143 EXPECT_TRUE(ptCloudFromFile.descriptorExists("eigVectors",9));
00144 EXPECT_TRUE(ptCloudFromFile.getDescriptorViewByName("eigVectors").isApprox(ptCloud.getDescriptorViewByName("eigVectors")));
00145 EXPECT_TRUE(ptCloudFromFile.descriptorExists("color",4));
00146 EXPECT_TRUE(ptCloudFromFile.getDescriptorViewByName("color").isApprox(ptCloud.getDescriptorViewByName("color")));
00147
00148 EXPECT_TRUE(ptCloudFromFile.features.isApprox(ptCloud.features));
00149
00150 }
00151
00152 virtual void TearDown()
00153 {
00154 EXPECT_TRUE(boost::filesystem::remove(boost::filesystem::path(testFileName)));
00155 }
00156
00157
00158 protected:
00159 int nbPts;
00160 DP::Labels featureLabels;
00161 DP ptCloud;
00162 DP ptCloudFromFile;
00163 string testFileName;
00164
00165 };
00166
00167 TEST_F(IOLoadSaveTest, VTK)
00168 {
00169 ptCloud.addDescriptor("genericScalar", PM::Matrix::Random(1, nbPts));
00170 ptCloud.addDescriptor("genericVector", PM::Matrix::Random(3, nbPts));
00171
00172 loadSaveTest("unit_test.vtk");
00173
00174 EXPECT_TRUE(ptCloudFromFile.descriptorExists("genericScalar",1));
00175 EXPECT_TRUE(ptCloudFromFile.descriptorExists("genericVector",3));
00176
00177 }
00178
00179 TEST_F(IOLoadSaveTest, PLY)
00180 {
00181 loadSaveTest("unit_test.ply");
00182 }
00183
00184 TEST_F(IOLoadSaveTest, PCD)
00185 {
00186 loadSaveTest("unit_test.pcd");
00187 }
00188
00189 TEST_F(IOLoadSaveTest, CSV)
00190 {
00191 loadSaveTest("unit_test.csv");
00192 }