27 #include <boost/test/unit_test.hpp>
28 #include <boost/utility/binary.hpp>
30 BOOST_AUTO_TEST_SUITE(BOOST_TEST_MODULE)
32 template<
typename T1,
typename T2 = T1>
35 static bool run(
const T1 & v1,
const T2 & v2)
48 #ifdef PINOCCHIO_WITH_EIGEN_TENSOR_MODULE
49 template<
typename Scalar,
int NumIndices,
int Options,
typename IndexType>
54 static bool run(
const T & v1,
const T & v2)
56 typedef Eigen::Matrix<Scalar, Eigen::Dynamic, 1, Options> VectorXd;
57 Eigen::Map<const VectorXd> map1(v1.data(), v1.size(), 1);
58 Eigen::Map<const VectorXd> map2(v2.data(), v2.size(), 1);
89 void generic_test(
const T &
object,
const std::string & filename,
const std::string & tag_name)
94 const std::string txt_filename =
filename +
".txt";
98 T & object_loaded = *empty_contructor<T>();
104 delete &object_loaded;
108 std::stringstream ss_out;
112 T & object_loaded = *empty_contructor<T>();
113 std::istringstream is(ss_out.str());
119 delete &object_loaded;
126 T & object_loaded = *empty_contructor<T>();
127 std::string str_in(str_out);
133 delete &object_loaded;
136 const std::string xml_filename =
filename +
".xml";
137 saveToXML(
object, xml_filename, tag_name);
140 T & object_loaded = *empty_contructor<T>();
141 loadFromXML(object_loaded, xml_filename, tag_name);
145 delete &object_loaded;
149 const std::string bin_filename =
filename +
".bin";
153 T & object_loaded = *empty_contructor<T>();
159 delete &object_loaded;
163 boost::asio::streambuf buffer;
167 T & object_loaded = *empty_contructor<T>();
173 delete &object_loaded;
181 T & object_loaded = *empty_contructor<T>();
187 delete &object_loaded;
194 const size_t size = 10000000;
196 BOOST_CHECK(
size == static_buffer.
size());
198 const size_t new_size = 2 *
size;
199 static_buffer.
resize(new_size);
200 BOOST_CHECK(new_size == static_buffer.
size());
202 BOOST_CHECK(static_buffer.
data() != NULL);
203 BOOST_CHECK(
reinterpret_cast<const StaticBuffer &
>(static_buffer).
data() != NULL);
204 BOOST_CHECK(
reinterpret_cast<const StaticBuffer &
>(static_buffer).
data() == static_buffer.
data());
211 const Eigen::DenseIndex num_cols = 10;
212 const Eigen::DenseIndex num_rows = 20;
214 const Eigen::DenseIndex array_size = 3;
216 Eigen::MatrixXd Mat = Eigen::MatrixXd::Random(num_rows, num_cols);
217 generic_test(Mat, TEST_SERIALIZATION_FOLDER
"/eigen_matrix",
"matrix");
219 Eigen::VectorXd Vec = Eigen::VectorXd::Random(num_rows * num_cols);
220 generic_test(Vec, TEST_SERIALIZATION_FOLDER
"/eigen_vector",
"vector");
223 generic_test(array, TEST_SERIALIZATION_FOLDER
"/eigen_array",
"array");
225 const Eigen::DenseIndex tensor_size = 3;
226 const Eigen::DenseIndex
x_dim = 10,
y_dim = 20, z_dim = 30;
231 Eigen::Map<Eigen::VectorXd>(tensor.
data(), tensor.
size(), 1).setRandom();
233 generic_test(tensor, TEST_SERIALIZATION_FOLDER
"/eigen_tensor",
"tensor");
240 SE3 M(SE3::Random());
244 generic_test(
m, TEST_SERIALIZATION_FOLDER
"/Motion",
"Motion");
247 generic_test(
f, TEST_SERIALIZATION_FOLDER
"/Force",
"Force");
250 generic_test(
S, TEST_SERIALIZATION_FOLDER
"/Symmetric3",
"Symmetric3");
253 generic_test(I, TEST_SERIALIZATION_FOLDER
"/Inertia",
"Inertia");
264 template<
typename Jo
intModel_>
267 template<
typename Jo
intModel_>
273 jmodel.setIndexes(0, 0, 0);
278 template<
typename Scalar,
int Options>
286 JointModel jmodel(Vector3::Random().normalized());
293 template<
typename Scalar,
int Options>
301 JointModel jmodel(Vector3::Random().normalized());
308 template<
typename Scalar,
int Options>
316 JointModel jmodel(Vector3::Random().normalized());
323 template<
typename Scalar,
int Options>
331 JointModel jmodel(Vector3::Random().normalized());
338 template<
typename Scalar,
int Options,
int axis>
352 template<
typename Scalar,
int Options,
template<
typename,
int>
class JointCollection>
367 template<
typename Scalar,
int Options>
381 template<
typename Scalar,
int Options,
template<
typename,
int>
class JointCollection>
393 jmodel.setIndexes(0, 0, 0);
398 template<
typename Scalar,
int Options,
template<
typename,
int>
class JointCollection>
409 jmodel.setIndexes(1, 0, 0, 0);
417 template<
typename Jo
intModel>
424 template<
typename Jo
intType>
425 static void test(JointType & jmodel)
427 generic_test(jmodel, TEST_SERIALIZATION_FOLDER
"/Joint",
"jmodel");
439 template<
typename Jo
intModel>
442 typedef typename JointModel::JointDerived JointDerived;
455 Eigen::VectorXd lb(Eigen::VectorXd::Constant(jmodel.nq(), -1.));
456 Eigen::VectorXd ub(Eigen::VectorXd::Constant(jmodel.nq(), 1.));
458 Eigen::VectorXd q_random = lg.randomConfiguration(lb, ub);
460 jmodel.
calc(jdata, q_random);
461 Transform &
m = jdata_base.
M();
464 Constraint &
S = jdata_base.
S();
468 template<
typename Scalar,
int Options,
template<
typename S,
int O>
class JointCollectionTpl>
474 template<
typename Scalar,
int Options,
template<
typename,
int>
class JointCollection>
480 template<
typename Transform>
483 generic_test(
m, TEST_SERIALIZATION_FOLDER
"/JointTransform",
"transform");
495 template<
typename Jo
intModel>
498 typedef typename JointModel::JointDerived JointDerived;
511 Eigen::VectorXd lb(Eigen::VectorXd::Constant(jmodel.nq(), -1.));
512 Eigen::VectorXd ub(Eigen::VectorXd::Constant(jmodel.nq(), 1.));
514 Eigen::VectorXd q_random = lg.randomConfiguration(lb, ub);
515 Eigen::VectorXd v_random = Eigen::VectorXd::Random(jmodel.nv());
517 jmodel.
calc(jdata, q_random, v_random);
522 Bias &
b = jdata_base.
c();
526 template<
typename Scalar,
int Options,
template<
typename S,
int O>
class JointCollectionTpl>
532 template<
typename Scalar,
int Options,
template<
typename,
int>
class JointCollection>
538 template<
typename Motion>
541 generic_test(
m, TEST_SERIALIZATION_FOLDER
"/JointMotion",
"motion");
553 template<
typename Jo
intModel>
556 typedef typename JointModel::JointDerived JointDerived;
565 Eigen::VectorXd lb(Eigen::VectorXd::Constant(jmodel.nq(), -1.));
566 Eigen::VectorXd ub(Eigen::VectorXd::Constant(jmodel.nq(), 1.));
568 Eigen::VectorXd q_random = lg.randomConfiguration(lb, ub);
569 Eigen::VectorXd v_random = Eigen::VectorXd::Random(jmodel.nv());
571 jmodel.
calc(jdata, q_random, v_random);
572 pinocchio::Inertia::Matrix6 I(pinocchio::Inertia::Matrix6::Identity());
573 jmodel.
calc_aba(jdata, Eigen::VectorXd::Zero(jmodel.nv()), I,
false);
577 template<
typename Scalar,
int Options,
template<
typename S,
int O>
class JointCollectionTpl>
581 typedef typename JointModel::JointDerived JointDerived;
587 model.addJoint(0, jmodel_build, pinocchio::SE3::Random(),
"model");
588 model.lowerPositionLimit.fill(-1.);
589 model.upperPositionLimit.fill(1.);
593 Eigen::VectorXd v_random = Eigen::VectorXd::Random(
model.nv);
598 jmodel.
calc(jdata, q_random, v_random);
599 pinocchio::Inertia::Matrix6 I(pinocchio::Inertia::Matrix6::Identity());
600 jmodel.
calc_aba(jdata, Eigen::VectorXd::Zero(jmodel.nv()), I,
false);
605 template<
typename Scalar,
int Options,
template<
typename,
int>
class JointCollection>
609 typedef typename JointModel::JointDerived JointDerived;
615 Eigen::VectorXd q_random = Eigen::VectorXd::Random(jmodel.jmodel().nq());
616 Eigen::VectorXd v_random = Eigen::VectorXd::Random(jmodel.jmodel().nv());
617 jmodel.
calc(jdata, q_random, v_random);
622 template<
typename Jo
intData>
625 generic_test(joint_data, TEST_SERIALIZATION_FOLDER
"/JointData",
"data");
632 boost::mpl::for_each<JointModelVariant::types>(
TestJointData());
652 const std::string & fake_filename =
"this_is_a_fake_filename";
655 const std::string complete_filename = fake_filename +
".txt";
656 BOOST_REQUIRE_THROW(
loadFromText(
model, complete_filename), std::invalid_argument);
660 saveToXML(
model, TEST_SERIALIZATION_FOLDER
"/model.xml",
"model");
664 const std::string complete_filename = fake_filename +
".txte";
666 BOOST_REQUIRE_THROW(
loadFromText(
model, complete_filename), std::invalid_argument);
670 const std::string complete_filename = fake_filename +
".xmle";
671 BOOST_REQUIRE_THROW(
loadFromXML(
model, complete_filename,
"model"), std::invalid_argument);
675 const std::string complete_filename = fake_filename +
".bine";
705 GeometryObject_ModelItem model_item(
"pinocchio", 1, 2, SE3::Random());
706 generic_test(model_item, TEST_SERIALIZATION_FOLDER
"/ModelItem",
"ModelItem");
714 GeometryObject geometry_object(
"nullptr", 1, 2, SE3::Random(),
nullptr);
715 generic_test(geometry_object, TEST_SERIALIZATION_FOLDER
"/GeometryObject",
"GeometryObject");
718 #ifdef PINOCCHIO_WITH_HPP_FCL
724 #if HPP_FCL_VERSION_AT_LEAST(3, 0, 0)
727 CollisionGeometryPtr box_ptr = CollisionGeometryPtr(
new hpp::fcl::Box(1., 2., 3.));
728 GeometryObject geometry_object(
"box", 1, 2, SE3::Random(), box_ptr);
729 generic_test(geometry_object, TEST_SERIALIZATION_FOLDER
"/GeometryObject",
"GeometryObject");
731 #endif // hpp-fcl >= 3.0.0
752 #ifdef PINOCCHIO_WITH_HPP_FCL
753 #if HPP_FCL_VERSION_AT_LEAST(3, 0, 0)
769 const double min_altitude = -1.;
771 const Eigen::DenseIndex
nx = 100,
ny = 200;
772 const Eigen::MatrixXd
heights = Eigen::MatrixXd::Random(
ny,
nx);
790 #endif // hpp-fcl >= 3.0.0
791 #endif // PINOCCHIO_WITH_HPP_FCL
794 BOOST_AUTO_TEST_SUITE_END()