Skip to content
Snippets Groups Projects
Commit 795d6e9a authored by JasonChmn's avatar JasonChmn Committed by Pierre Fernbach
Browse files

[exact_cubic] Add serialization for exact cubic / binding python => Test OK

parent 66d3a01a
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
......@@ -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**/
......
......@@ -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):
......
......@@ -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[]*/)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment