utest.h
Go to the documentation of this file.
00001 #ifndef UTEST_HPP_
00002 #define UTEST_HPP_
00003 
00004 #include "pointmatcher/PointMatcher.h"
00005 #include "pointmatcher/IO.h"
00006 #include "../contrib/gtest/gtest.h"
00007 
00008 #include <string>
00009 #include <fstream>
00010 
00011 #include "boost/filesystem.hpp"
00012 #include "boost/filesystem/path.hpp"
00013 #include "boost/filesystem/operations.hpp"
00014 
00015 typedef PointMatcher<float> PM;
00016 typedef PM::DataPoints DP;
00017 
00018 extern std::string dataPath;
00019 
00020 extern DP ref2D;
00021 extern DP data2D;
00022 extern DP ref3D;
00023 extern DP data3D;
00024 extern PM::TransformationParameters validT2d;
00025 extern PM::TransformationParameters validT3d;
00026 
00027 //---------------------------
00028 // Base for ICP tests
00029 //---------------------------
00030 
00031 class IcpHelper: public testing::Test
00032 {
00033 public:
00034         
00035         PM::ICP icp;
00036         
00037         PM::Parameters params;
00038 
00039         virtual void dumpVTK()
00040         {
00041                 // Make available a VTK inspector for manual inspection
00042                 icp.inspector.reset(
00043                         PM::get().InspectorRegistrar.create(
00044                                 "VTKFileInspector", 
00045                                 boost::assign::map_list_of
00046                                         ("baseFileName","./unitTest")
00047                         )
00048                 );
00049         }
00050         
00051         void validate2dTransformation()
00052         {
00053                 const PM::TransformationParameters testT = icp(data2D, ref2D);
00054                 const int dim = validT2d.cols();
00055 
00056                 const BOOST_AUTO(validTrans, validT2d.block(0, dim-1, dim-1, 1).norm());
00057                 const BOOST_AUTO(testTrans, testT.block(0, dim-1, dim-1, 1).norm());
00058         
00059                 const BOOST_AUTO(validAngle, acos(validT2d(0,0)));
00060                 const BOOST_AUTO(testAngle, acos(testT(0,0)));
00061                 
00062                 EXPECT_NEAR(validTrans, testTrans, 0.05);
00063                 EXPECT_NEAR(validAngle, testAngle, 0.05);
00064         }
00065 
00066         void validate3dTransformation()
00067         {
00068                 //dumpVTK();
00069 
00070                 const PM::TransformationParameters testT = icp(data3D, ref3D);
00071                 const int dim = validT2d.cols();
00072 
00073                 const BOOST_AUTO(validTrans, validT3d.block(0, dim-1, dim-1, 1).norm());
00074                 const BOOST_AUTO(testTrans, testT.block(0, dim-1, dim-1, 1).norm());
00075         
00076                 const BOOST_AUTO(testRotation, Eigen::Quaternion<float>(Eigen::Matrix<float,3,3>(testT.topLeftCorner(3,3))));
00077                 const BOOST_AUTO(validRotation, Eigen::Quaternion<float>(Eigen::Matrix<float,3,3>(validT3d.topLeftCorner(3,3))));
00078                 
00079                 const BOOST_AUTO(angleDist, validRotation.angularDistance(testRotation));
00080                 
00081                 //cout << testT << endl;
00082                 //cout << "angleDist: " << angleDist << endl;
00083                 //cout << "transDist: " << abs(validTrans-testTrans) << endl;
00084                 EXPECT_NEAR(validTrans, testTrans, 0.1);
00085                 EXPECT_NEAR(angleDist, 0.0, 0.1);
00086 
00087         }
00088 };
00089 
00090 #endif /* UTEST_HPP_ */
00091 
00092 


upstream_src
Author(s):
autogenerated on Mon Oct 6 2014 10:27:42