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 #include "utest.h"
00037
00038 using namespace std;
00039 using namespace PointMatcherSupport;
00040 using boost::assign::map_list_of;
00041
00042
00043
00044 std::string dataPath;
00045
00046 DP ref2D;
00047 DP data2D;
00048 DP ref3D;
00049 DP data3D;
00050 PM::TransformationParameters validT2d;
00051 PM::TransformationParameters validT3d;
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075 TEST(icpTest, icpTest)
00076 {
00077 DP ref = DP::load(dataPath + "cloud.00000.vtk");
00078 DP data = DP::load(dataPath + "cloud.00001.vtk");
00079
00080 namespace fs = boost::filesystem;
00081 fs::path config_dir(dataPath + "icp_data");
00082 EXPECT_TRUE( fs::exists(config_dir) && fs::is_directory(config_dir) );
00083
00084 fs::directory_iterator end_iter;
00085 for( fs::directory_iterator d(config_dir); d != end_iter; ++d)
00086 {
00087 if (!fs::is_regular_file(d->status()) ) continue;
00088
00089
00090 PM::ICP icp;
00091 std::string config_file = d->path().string();
00092 if (fs::extension(config_file) != ".yaml") continue;
00093 std::ifstream ifs(config_file.c_str());
00094 EXPECT_NO_THROW(icp.loadFromYaml(ifs)) << "This error was caused by the test file:" << endl << " " << config_file;
00095
00096
00097 PM::TransformationParameters curT = icp(data, ref);
00098
00099
00100
00101 fs::path cur_file = d->path();
00102 cur_file.replace_extension(".cur_trans");
00103
00104 std::ofstream otfs(cur_file.c_str());
00105 otfs.precision(16);
00106 otfs << curT;
00107 otfs.close();
00108
00109
00110 fs::path ref_file = d->path();
00111 ref_file.replace_extension(".ref_trans");
00112 PM::TransformationParameters refT = 0*curT;
00113
00114 std::ifstream itfs(ref_file.c_str());
00115 for (int row = 0; row < refT.cols(); row++)
00116 {
00117 for (int col = 0; col < refT.cols(); col++)
00118 {
00119 itfs >>refT(row, col);
00120 }
00121 }
00122
00123
00124
00125
00126
00127
00128
00129 double rotTol = 0.1, transTol = 0.1;
00130
00131
00132
00133 PM::TransformationParameters refRot = refT.block(0, 0, 3, 3);
00134 PM::TransformationParameters refTrans = refT.block(0, 3, 3, 1);
00135 PM::TransformationParameters curRot = curT.block(0, 0, 3, 3);
00136 PM::TransformationParameters curTrans = curT.block(0, 3, 3, 1);
00137 PM::TransformationParameters rotErrMat = refRot*(curRot.transpose())
00138 - PM::TransformationParameters::Identity(3, 3);
00139 PM::TransformationParameters transErrMat = refTrans - curTrans;
00140 double rotErr = rotErrMat.array().abs().sum();
00141 double transErr = transErrMat.array().abs().sum();
00142
00143
00144
00145
00146 EXPECT_LT(rotErr, rotTol) << "This error was caused by the test file:" << endl << " " << config_file;
00147 EXPECT_LT(transErr, transTol) << "This error was caused by the test file:" << endl << " " << config_file;
00148 }
00149 }
00150
00151
00152 class GenericTest: public IcpHelper
00153 {
00154
00155 public:
00156
00157
00158 virtual void SetUp()
00159 {
00160 icp.setDefault();
00161
00162
00163 }
00164
00165
00166 virtual void TearDown()
00167 {
00168 }
00169 };
00170
00171
00172
00173
00174
00175 TEST_F(GenericTest, ICP_default)
00176 {
00177 validate2dTransformation();
00178 validate3dTransformation();
00179 }
00180
00181
00182
00183
00184 int main(int argc, char **argv)
00185 {
00186 dataPath = "";
00187 for(int i=1; i < argc; i++)
00188 {
00189 if (strcmp(argv[i], "--path") == 0 && i+1 < argc)
00190 dataPath = argv[i+1];
00191 }
00192
00193 if(dataPath == "")
00194 {
00195 cerr << "Missing the flag --path ./path/to/examples/data\n Please give the path to the test data folder which should be included with the source code. The folder is named 'examples/data'." << endl;
00196 return -1;
00197 }
00198
00199
00200 ref2D = DP::load(dataPath + "2D_oneBox.csv");
00201 data2D = DP::load(dataPath + "2D_twoBoxes.csv");
00202 ref3D = DP::load(dataPath + "car_cloud400.csv");
00203 data3D = DP::load(dataPath + "car_cloud401.csv");
00204
00205
00206 validT2d = PM::TransformationParameters(3,3);
00207 validT2d << 0.987498, 0.157629, 0.0859918,
00208 -0.157629, 0.987498, 0.203247,
00209 0, 0, 1;
00210
00211 validT3d = PM::TransformationParameters(4,4);
00212 validT3d << 0.982304, 0.166685, -0.0854066, 0.0446816,
00213 -0.150189, 0.973488, 0.172524, 0.191998,
00214 0.111899, -0.156644, 0.981296, -0.0356313,
00215 0, 0, 0, 1;
00216
00217 testing::GTEST_FLAG(print_time) = true;
00218 testing::InitGoogleTest(&argc, argv);
00219 return RUN_ALL_TESTS();
00220 }
00221
00222
00223