20 #include "pinocchio/spatial/fwd.hpp" 21 #include "pinocchio/spatial/skew.hpp" 22 #include "pinocchio/utils/timer.hpp" 24 #include <boost/random.hpp> 25 #include <Eigen/Geometry> 27 #include "pinocchio/spatial/symmetric3.hpp" 29 #include <boost/test/unit_test.hpp> 30 #include <boost/utility/binary.hpp> 33 #include <Eigen/StdVector> 34 EIGEN_DEFINE_STL_VECTOR_SPECIALIZATION(Eigen::Matrix3d)
46 #include <metapod/tools/spatial/lti.hh> 47 #include <metapod/tools/spatial/rm-general.hh> 49 EIGEN_DEFINE_STL_VECTOR_SPECIALIZATION(metapod::Spatial::ltI<double>)
50 EIGEN_DEFINE_STL_VECTOR_SPECIALIZATION(metapod::Spatial::RotationMatrixTpl<double>)
52 void timeLTI(
const metapod::Spatial::ltI<double>& S,
53 const metapod::Spatial::RotationMatrixTpl<double>&
R,
54 metapod::Spatial::ltI<double> &
res)
56 res =
R.rotTSymmetricMatrix(S);
62 const Eigen::Matrix3d & Sdense,
63 Eigen::Matrix3d & ASA )
65 typedef Eigen::SelfAdjointView<const Eigen::Matrix3d,Eigen::Upper> Sym3;
67 ASA.triangularView<Eigen::Upper>()
68 = A * S * A.transpose();
85 Matrix3
M = Matrix3::Random(); M = M*M.transpose();
87 BOOST_CHECK(S.
matrix().isApprox(M, 1e-12));
97 BOOST_CHECK(S.
matrix().isApprox(S2.matrix()+Scopy.
matrix(), 1e-12));
103 Matrix3
M = Matrix3::Random(); M = M*M.transpose();
115 Vector3
v = Vector3::Random();
117 BOOST_CHECK(Sv.isApprox(S.
matrix()*
v, 1e-12));
121 for(
int i=0;
i<100;++
i )
123 Matrix3
M = Matrix3::Random(); M = M*M.transpose();
125 Vector3
v = Vector3::Random();
126 BOOST_CHECK_GT( (v.transpose()*(S*
v))[0] , 0);
136 Vector3
v = Vector3::Random();
139 Vector3
p = Vector3::UnitX();
140 BOOST_CHECK((vxvx*p).
isApprox(v.cross(v.cross(p)), 1e-12));
142 p = Vector3::UnitY();
143 BOOST_CHECK((vxvx*p).
isApprox(v.cross(v.cross(p)), 1e-12));
145 p = Vector3::UnitZ();
146 BOOST_CHECK((vxvx*p).
isApprox(v.cross(v.cross(p)), 1e-12));
148 Matrix3 vx =
skew(v);
149 Matrix3 vxvx2 = (vx*vx).eval();
150 BOOST_CHECK(vxvx.
matrix().isApprox(vxvx2, 1e-12));
153 BOOST_CHECK((S-Symmetric3::SkewSquare(v)).matrix()
154 .
isApprox(S.matrix()-vxvx2, 1e-12));
156 double m = Eigen::internal::random<double>()+1;
157 BOOST_CHECK((S-m*Symmetric3::SkewSquare(v)).matrix()
158 .
isApprox(S.matrix()-m*vxvx2, 1e-12));
162 S -= Symmetric3::SkewSquare(v);
163 BOOST_CHECK(S.matrix().isApprox(S2.
matrix()-vxvx2, 1e-12));
165 S = S2; S -= m*Symmetric3::SkewSquare(v);
166 BOOST_CHECK(S.matrix().isApprox(S2.
matrix()-m*vxvx2, 1e-12));
172 Matrix3
M = Matrix3::Random(); M = M*M.transpose();
176 BOOST_CHECK_SMALL(S(
i,j) - M(
i,j), Eigen::NumTraits<double>::dummy_precision());
183 Matrix3
R = (Eigen::Quaterniond(Eigen::Matrix<double,4,1>::Random())).normalized().matrix();
186 BOOST_CHECK(RSRt.
matrix().isApprox(R*S.
matrix()*R.transpose(), 1e-12));
189 BOOST_CHECK(RtSR.
matrix().isApprox(R.transpose()*S.
matrix()*R, 1e-12));
195 Vector3
v = Vector3::Random();
196 double kinetic_ref = v.transpose() * S.
matrix() *
v;
197 double kinetic = S.
vtiv(v);
198 BOOST_CHECK_SMALL(kinetic_ref - kinetic, 1e-12);
204 Vector3
v = Vector3::Random();
205 Matrix3 Vcross =
skew(v);
206 Matrix3 M_ref(Vcross * S.
matrix());
210 BOOST_CHECK(M_res.isApprox(M_ref));
212 BOOST_CHECK(S.
vxs(v).isApprox(M_ref));
218 Vector3
v = Vector3::Random();
219 Matrix3 Vcross =
skew(v);
220 Matrix3 M_ref(S.
matrix() * Vcross);
224 BOOST_CHECK(M_res.isApprox(M_ref));
226 BOOST_CHECK(S.
svx(v).isApprox(M_ref));
232 BOOST_CHECK(!S_not_zero.
isZero());
235 BOOST_CHECK(S_zero.isZero());
252 const size_t NBT = 100000;
255 std::vector<Symmetric3> Sres (NBT);
256 std::vector<Matrix3> Rs (NBT);
257 for(
size_t i=0;
i<NBT;++
i)
258 Rs[
i] = (Eigen::Quaterniond(Eigen::Matrix<double,4,1>::Random())).normalized().matrix();
260 std::cout <<
"Pinocchio: ";
264 timeSym3(S,Rs[_smooth],Sres[_smooth]);
266 timer.
toc(std::cout,NBT);
277 typedef Eigen::Matrix3d Matrix3;
278 typedef Eigen::SelfAdjointView<Matrix3,Eigen::Upper> Sym3;
280 Matrix3
M = Matrix3::Random();
284 BOOST_CHECK((Scp-Scp.transpose()).
isApprox(Matrix3::Zero(), 1e-16));
287 Matrix3 M2 = Matrix3::Random();
288 M.triangularView<Eigen::Upper>() = M2;
290 Matrix3
A = Matrix3::Random(), ASA1, ASA2;
291 ASA1.triangularView<Eigen::Upper>() = A * S * A.transpose();
295 Matrix3 Masa1 = ASA1.selfadjointView<Eigen::Upper>();
296 Matrix3 Masa2 = ASA2.selfadjointView<Eigen::Upper>();
297 BOOST_CHECK(Masa1.isApprox(Masa2, 1e-16));
300 const size_t NBT = 100000;
301 std::vector<Eigen::Matrix3d> Sres (NBT);
302 std::vector<Eigen::Matrix3d> Rs (NBT);
303 for(
size_t i=0;
i<NBT;++
i)
304 Rs[
i] = (Eigen::Quaterniond(Eigen::Matrix<double,4,1>::Random())).normalized().matrix();
306 std::cout <<
"Eigen: ";
312 timer.
toc(std::cout,NBT);
323 BOOST_CHECK(sym2 != sym1);
324 BOOST_CHECK(sym1 == sym1);
332 BOOST_CHECK(sym.
cast<
double>() == sym);
333 BOOST_CHECK(sym.
cast<
long double>().cast<
double>() == sym);
336 BOOST_AUTO_TEST_SUITE_END ()
JointCollectionTpl const Eigen::MatrixBase< ConfigVectorType > const Eigen::MatrixBase< TangentVectorType > & v
bool isApprox(const Symmetric3Tpl &other, const Scalar &prec=Eigen::NumTraits< Scalar >::dummy_precision()) const
static Symmetric3Tpl Random()
Eigen::Matrix< Scalar, 3, 3, Options > Matrix3
NewScalar cast(const Scalar &value)
bool isZero(const Scalar &prec=Eigen::NumTraits< Scalar >::dummy_precision()) const
Symmetric3Tpl< NewScalar, Options > cast() const
static Symmetric3Tpl Zero()
void sym(const Eigen::MatrixBase< MatrixDerived > &eig_mat, std::string const &name)
static Symmetric3Tpl RandomPositive()
bool isApprox(const Shape &s1, const Shape &s2, const FCL_REAL tol)
static void svx(const Eigen::MatrixBase< Vector3 > &v, const Symmetric3Tpl &S3, const Eigen::MatrixBase< Matrix3 > &M)
Performs the operation .
static Symmetric3Tpl Identity()
#define BOOST_TEST_MODULE
Symmetric3Tpl rotate(const Eigen::MatrixBase< D > &R) const
Scalar vtiv(const Vector3 &v) const
Main pinocchio namespace.
Eigen::Matrix< Scalar, 3, 1, Options > Vector3
static void vxs(const Eigen::MatrixBase< Vector3 > &v, const Symmetric3Tpl &S3, const Eigen::MatrixBase< Matrix3 > &M)
Performs the operation . This operation is equivalent to applying the cross product of v on each colu...
Symmetric3Tpl< double, 0 > Symmetric3
void skew(const Eigen::MatrixBase< Vector3 > &v, const Eigen::MatrixBase< Matrix3 > &M)
Computes the skew representation of a given 3d vector, i.e. the antisymmetric matrix representation o...
const Vector6 & data() const
BOOST_AUTO_TEST_CASE(test_pinocchio_Sym3)
void timeSym3(const pinocchio::Symmetric3 &S, const pinocchio::Symmetric3::Matrix3 &R, pinocchio::Symmetric3 &res)
void timeSelfAdj(const Eigen::Matrix3d &A, const Eigen::Matrix3d &Sdense, Eigen::Matrix3d &ASA)