diff --git a/include/curves/exact_cubic.h b/include/curves/exact_cubic.h index d8dfd5a457acdbc320dda19c8aeaeda905c35961..f7da3b0eb0db32a519d2a053410a610ddbf9ee4c 100644 --- a/include/curves/exact_cubic.h +++ b/include/curves/exact_cubic.h @@ -32,6 +32,9 @@ #include <functional> #include <vector> +#include "serialization/archive.hpp" +#include "serialization/eigen-matrix.hpp" + namespace curves { /// \class ExactCubic. @@ -41,7 +44,8 @@ namespace curves template<typename Time= double, typename Numeric=Time, std::size_t Dim=3, bool Safe=false , typename Point= Eigen::Matrix<Numeric, Eigen::Dynamic, 1>, typename T_Point =std::vector<Point,Eigen::aligned_allocator<Point> > , typename SplineBase=polynomial<Time, Numeric, Dim, Safe, Point, T_Point> > -struct exact_cubic : public piecewise_curve<Time, Numeric, Dim, Safe, Point, T_Point, SplineBase> +struct exact_cubic : public piecewise_curve<Time, Numeric, Dim, Safe, Point, T_Point, SplineBase>//, + //public serialization::Serializable< exact_cubic<Time, Numeric, Dim, Safe, Point, T_Point, SplineBase> > { typedef Point point_t; typedef T_Point t_point_t; @@ -55,10 +59,14 @@ struct exact_cubic : public piecewise_curve<Time, Numeric, Dim, Safe, Point, T_P typedef typename t_spline_t::const_iterator cit_spline_t; typedef curve_constraints<Point, Dim> spline_constraints; + typedef exact_cubic<Time, Numeric, Dim, Safe, Point, T_Point, SplineBase> exact_cubic_t; typedef piecewise_curve<Time, Numeric, Dim, Safe, Point, T_Point, SplineBase> piecewise_curve_t; /* Constructors - destructors */ public: + + exact_cubic(){} + /// \brief Constructor. /// \param wayPointsBegin : an iterator pointing to the first element of a waypoint container. /// \param wayPointsEns : an iterator pointing to the last element of a waypoint container. @@ -253,6 +261,15 @@ struct exact_cubic : public piecewise_curve<Time, Numeric, Dim, Safe, Point, T_P subSplines.push_back(create_quintic<Time,Numeric,Dim,Safe,Point,T_Point> (a0,b0,c0,d,e,f, init_t, end_t)); } + + public: + // Serialization of the class + friend class boost::serialization::access; + + template<class Archive> + void serialize(Archive& ar, const unsigned int version){ + ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(exact_cubic_t); + } }; } // namespace curves #endif //_CLASS_EXACTCUBIC diff --git a/python/curves_python.cpp b/python/curves_python.cpp index ea2fbbb71a9e62559e0efa95855eb4f5e45acb55..e35510ca15dfdc1728de6e01accbf590f47b45ae 100644 --- a/python/curves_python.cpp +++ b/python/curves_python.cpp @@ -408,7 +408,7 @@ BOOST_PYTHON_MODULE(curves) /** BEGIN exact_cubic curve**/ class_<exact_cubic_t> - ("exact_cubic", no_init) + ("exact_cubic", init<>()) .def("__init__", make_constructor(&wrapExactCubicConstructor)) .def("__init__", make_constructor(&wrapExactCubicConstructorConstraint)) .def("min", &exact_cubic_t::min) @@ -417,6 +417,7 @@ BOOST_PYTHON_MODULE(curves) .def("derivate", &exact_cubic_t::derivate) .def("getNumberSplines", &exact_cubic_t::getNumberSplines) .def("getSplineAt", &exact_cubic_t::getSplineAt) + .def(SerializableVisitor<exact_cubic_t>()) ; /** END exact_cubic curve**/ diff --git a/python/test/test.py b/python/test/test.py index 325078fe51ef1b3bd9a829f560e8914ad32da876..69f3dbb5d3df60d75bdf865ae4a5fd38ff029fe6 100644 --- a/python/test/test.py +++ b/python/test/test.py @@ -238,6 +238,11 @@ class TestCurves(unittest.TestCase): a.derivate(0.4, 2) a.getNumberSplines() a.getSplineAt(0) + # Test serialization + a.saveAsText("serialization_pc.test") + b = exact_cubic() + b.loadFromText("serialization_pc.test") + self.assertTrue((a(0.4) == b(0.4)).all()) return def test_exact_cubic_constraint(self): diff --git a/tests/Main.cpp b/tests/Main.cpp index a0b7f4cfca816ebcd482b871fa81165cf4e9afe6..aeb038db8d9caf9fa1447feefdcac12280d1bb79 100644 --- a/tests/Main.cpp +++ b/tests/Main.cpp @@ -1443,6 +1443,7 @@ void serializationCurvesTest(bool& error) std::string errMsg2("in serializationCurveTest, Error While serializing Bezier : "); std::string errMsg3("in serializationCurveTest, Error While serializing Cubic Hermite : "); std::string errMsg4("in serializationCurveTest, Error While serializing Piecewise curves : "); + std::string errMsg5("in serializationCurveTest, Error While serializing Exact cubic : "); point_t a(1,1,1); // in [0,1[ point_t b(2,1,1); // in [1,2[ point_t c(3,1,1); // in [2,3] @@ -1494,6 +1495,23 @@ void serializationCurvesTest(bool& error) piecewise_cubic_hermite_curve_t pchc_test; pchc_test.loadFromText(fileName); CompareCurves<piecewise_polynomial_curve_t,piecewise_cubic_hermite_curve_t>(ppc, pchc_test, errMsg4, error); + + // Test serialization on exact cubic + curves::T_Waypoint waypoints; + for(double i = 0; i <= 1; i = i + 0.2) + { + waypoints.push_back(std::make_pair(i,point_t(i,i,i))); + } + spline_constraints_t constraints; + constraints.end_vel = point_t(0,0,0); + constraints.init_vel = point_t(0,0,0); + constraints.end_acc = point_t(0,0,0); + constraints.init_acc = point_t(0,0,0); + exact_cubic_t ec(waypoints.begin(), waypoints.end(), constraints); + ec.saveAsText(fileName); + exact_cubic_t ec_test; + ec_test.loadFromText(fileName); + CompareCurves<exact_cubic_t,exact_cubic_t>(ec, ec_test, errMsg5, error); } int main(int /*argc*/, char** /*argv[]*/)