#ifndef SOPUHS_TESTS_HPP #define SOPUHS_TESTS_HPP #include #include #include "sophus.hpp" namespace Sophus { using namespace std; using namespace Eigen; template class Tests { public: typedef typename LieGroup::Scalar Scalar; typedef typename LieGroup::Transformation Transformation; typedef typename LieGroup::Tangent Tangent; typedef typename LieGroup::Point Point; typedef typename LieGroup::Adjoint Adjoint; static const int N = LieGroup::N; static const int DoF = LieGroup::DoF; const Scalar SMALL_EPS; Tests() : SMALL_EPS(SophusConstants::epsilon()) { } void setGroupElements(const vector & group_vec) { group_vec_ = group_vec; } void setTangentVectors(const vector & tangent_vec) { tangent_vec_ = tangent_vec; } void setPoints(const vector & point_vec) { point_vec_ = point_vec; } bool adjointTest() { bool passed = true; for (size_t i=0; i20.*SMALL_EPS) { cerr << "Adjoint" << endl; cerr << "Test case: " << i << "," << j <SMALL_EPS) { cerr << "G - exp(log(G))" << endl; cerr << "Test case: " << i << endl; cerr << DiffT <10.*SMALL_EPS) { cerr << "expmap(hat(x)) - exp(x)" << endl; cerr << "Test case: " << i << endl; cerr << exp_x <SMALL_EPS) { cerr << "Transform vector" << endl; cerr << "Test case: " << i << endl; cerr << (res1-res2) <SMALL_EPS) { cerr << "Lie Bracket Test" << endl; cerr << "Test case: " << i << ", " < fastmul_res(fastmul_res_raw); Eigen::Map group_j_constmap(group_vec_[j].data()); fastmul_res = group_vec_[i]; fastmul_res.fastMultiply(group_j_constmap); Transformation diff = mul_resmat-fastmul_res.matrix(); Scalar nrm = diff.norm(); if (isnan(nrm) || nrm>SMALL_EPS) { cerr << "Map & Multiply" << endl; cerr << "Test case: " << i << "," << j << endl; cerr << diff <SMALL_EPS) { cerr << "Hat-vee Test" << endl; cerr << "Test case: " << i << endl; cerr << resDiff << endl; cerr << endl; passed = false; } } return passed; } void runAllTests() { bool passed = adjointTest(); if (!passed) { cerr << "failed!" << endl << endl; exit(-1); } passed = expLogTest(); if (!passed) { cerr << "failed!" << endl << endl; exit(-1); } passed = expMapTest(); if (!passed) { cerr << "failed!" << endl << endl; exit(-1); } passed = groupActionTest(); if (!passed) { cerr << "failed!" << endl << endl; exit(-1); } passed = lieBracketTest(); if (!passed) { cerr << "failed!" << endl << endl; exit(-1); } passed = mapAndMultTest(); if (!passed) { cerr << "failed!" << endl << endl; exit(-1); } passed = veeHatTest(); if (!passed) { cerr << "failed!" << endl << endl; exit(-1); } cerr << "passed." << endl << endl; } private: Matrix map(const Matrix & T, const Matrix & p) { return T.template topLeftCorner()*p + T.template topRightCorner(); } Matrix map(const Matrix & T, const Matrix & p) { return T*p; } Scalar norm(const Scalar & v) { return std::abs(v); } Scalar norm(const Matrix & T) { return T.norm(); } std::vector group_vec_; std::vector tangent_vec_; std::vector point_vec_; }; } #endif // TESTS_HPP