Commit 66d3a01a authored by JasonChmn's avatar JasonChmn Committed by Pierre Fernbach
Browse files

Add Python bindings for serialization of bezier,hermite,polynomial...

Add Python bindings for serialization of bezier,hermite,polynomial curves/piecewise curves => All tests ok
parent 782edde3
...@@ -319,10 +319,11 @@ struct piecewise_curve : public curve_abc<Time, Numeric, Safe, Point>, ...@@ -319,10 +319,11 @@ struct piecewise_curve : public curve_abc<Time, Numeric, Safe, Point>,
template<class Archive> template<class Archive>
void serialize(Archive& ar, const unsigned int version){ void serialize(Archive& ar, const unsigned int version){
ar & curves_; ar & boost::serialization::make_nvp("curves", curves_);
ar & time_curves_; ar & boost::serialization::make_nvp("time_curves", time_curves_);
ar & size_; ar & boost::serialization::make_nvp("size", size_);
ar & T_min_ & T_max_; ar & boost::serialization::make_nvp("T_min", T_min_);
ar & boost::serialization::make_nvp("T_max", T_max_);
} }
}; };
......
...@@ -153,7 +153,11 @@ cubic_hermite_spline_t* wrapCubicHermiteSplineConstructor(const point_list_t& po ...@@ -153,7 +153,11 @@ cubic_hermite_spline_t* wrapCubicHermiteSplineConstructor(const point_list_t& po
/* End wrap Cubic hermite spline */ /* End wrap Cubic hermite spline */
/* Wrap polynomial */ /* Wrap polynomial */
polynomial_t* wrapSplineConstructor(const coeff_t& array) polynomial_t* wrapSplineConstructor1(const coeff_t& array, const real min, const real max)
{
return new polynomial_t(array, min, max);
}
polynomial_t* wrapSplineConstructor2(const coeff_t& array)
{ {
return new polynomial_t(array, 0., 1.); return new polynomial_t(array, 0., 1.);
} }
...@@ -275,8 +279,7 @@ BOOST_PYTHON_MODULE(curves) ...@@ -275,8 +279,7 @@ BOOST_PYTHON_MODULE(curves)
/** END eigenpy init**/ /** END eigenpy init**/
/** BEGIN bezier curve 6**/ /** BEGIN bezier curve 6**/
class_<bezier6_t> class_<bezier6_t>("bezier6", init<>())
("bezier6", no_init)
.def("__init__", make_constructor(&wrapBezierConstructor6)) .def("__init__", make_constructor(&wrapBezierConstructor6))
.def("__init__", make_constructor(&wrapBezierConstructorBounds6)) .def("__init__", make_constructor(&wrapBezierConstructorBounds6))
//.def("__init__", make_constructor(&wrapBezierConstructor6Constraints)) //.def("__init__", make_constructor(&wrapBezierConstructor6Constraints))
...@@ -288,15 +291,14 @@ BOOST_PYTHON_MODULE(curves) ...@@ -288,15 +291,14 @@ BOOST_PYTHON_MODULE(curves)
.def("compute_derivate", &bezier6_t::compute_derivate) .def("compute_derivate", &bezier6_t::compute_derivate)
.def("compute_primitive", &bezier6_t::compute_primitive) .def("compute_primitive", &bezier6_t::compute_primitive)
.def("waypoints", &wayPointsToList<bezier6_t,6>) .def("waypoints", &wayPointsToList<bezier6_t,6>)
.def(SerializableVisitor<bezier6_t>())
.def_readonly("degree", &bezier6_t::degree_) .def_readonly("degree", &bezier6_t::degree_)
.def_readonly("nbWaypoints", &bezier6_t::size_) .def_readonly("nbWaypoints", &bezier6_t::size_)
.def(SerializableVisitor<bezier6_t>())
; ;
/** END bezier curve**/ /** END bezier curve**/
/** BEGIN bezier curve**/ /** BEGIN bezier curve**/
class_<bezier3_t> class_<bezier3_t>("bezier3", init<>())
("bezier3", no_init)
.def("__init__", make_constructor(&wrapBezierConstructor3)) .def("__init__", make_constructor(&wrapBezierConstructor3))
.def("__init__", make_constructor(&wrapBezierConstructorBounds3)) .def("__init__", make_constructor(&wrapBezierConstructorBounds3))
.def("__init__", make_constructor(&wrapBezierConstructor3Constraints)) .def("__init__", make_constructor(&wrapBezierConstructor3Constraints))
...@@ -308,28 +310,27 @@ BOOST_PYTHON_MODULE(curves) ...@@ -308,28 +310,27 @@ BOOST_PYTHON_MODULE(curves)
.def("compute_derivate", &bezier3_t::compute_derivate) .def("compute_derivate", &bezier3_t::compute_derivate)
.def("compute_primitive", &bezier3_t::compute_primitive) .def("compute_primitive", &bezier3_t::compute_primitive)
.def("waypoints", &wayPointsToList<bezier3_t,3>) .def("waypoints", &wayPointsToList<bezier3_t,3>)
.def(SerializableVisitor<bezier3_t>())
.def_readonly("degree", &bezier3_t::degree_) .def_readonly("degree", &bezier3_t::degree_)
.def_readonly("nbWaypoints", &bezier3_t::size_) .def_readonly("nbWaypoints", &bezier3_t::size_)
.def(SerializableVisitor<bezier3_t>())
; ;
/** END bezier curve**/ /** END bezier curve**/
/** BEGIN variable points bezier curve**/ /** BEGIN variable points bezier curve**/
class_<LinearControlPointsHolder> class_<LinearControlPointsHolder>
("LinearWaypoint", no_init) ("LinearWaypoint", no_init)
.def_readonly("A", &LinearControlPointsHolder::A) .def_readonly("A", &LinearControlPointsHolder::A)
.def_readonly("b", &LinearControlPointsHolder::b) .def_readonly("b", &LinearControlPointsHolder::b)
; ;
class_<LinearBezierVector> class_<LinearBezierVector>
("bezierVarVector", no_init) ("bezierVarVector", no_init)
.def_readonly("size", &LinearBezierVector::size) .def_readonly("size", &LinearBezierVector::size)
.def("at", &LinearBezierVector::at, return_value_policy<manage_new_object>()) .def("at", &LinearBezierVector::at, return_value_policy<manage_new_object>())
; ;
class_<bezier_linear_variable_t> class_<bezier_linear_variable_t>("bezierVar", no_init)
("bezierVar", no_init)
.def("__init__", make_constructor(&wrapBezierLinearConstructor)) .def("__init__", make_constructor(&wrapBezierLinearConstructor))
.def("__init__", make_constructor(&wrapBezierLinearConstructorBounds)) .def("__init__", make_constructor(&wrapBezierLinearConstructorBounds))
.def("min", &bezier_linear_variable_t::min) .def("min", &bezier_linear_variable_t::min)
...@@ -345,10 +346,10 @@ BOOST_PYTHON_MODULE(curves) ...@@ -345,10 +346,10 @@ BOOST_PYTHON_MODULE(curves)
; ;
/** END variable points bezier curve**/ /** END variable points bezier curve**/
/** BEGIN polynomial curve function**/ /** BEGIN polynomial curve function**/
class_<polynomial_t>("polynomial", init<const polynomial_t::coeff_t, const real, const real >()) class_<polynomial_t>("polynomial", init<>())
.def("__init__", make_constructor(&wrapSplineConstructor)) .def("__init__", make_constructor(&wrapSplineConstructor1))
.def("__init__", make_constructor(&wrapSplineConstructor2))
.def("min", &polynomial_t::min) .def("min", &polynomial_t::min)
.def("max", &polynomial_t::max) .def("max", &polynomial_t::max)
.def("__call__", &polynomial_t::operator()) .def("__call__", &polynomial_t::operator())
...@@ -359,7 +360,7 @@ BOOST_PYTHON_MODULE(curves) ...@@ -359,7 +360,7 @@ BOOST_PYTHON_MODULE(curves)
/** BEGIN piecewise curve function **/ /** BEGIN piecewise curve function **/
class_<piecewise_polynomial_curve_t> class_<piecewise_polynomial_curve_t>
("piecewise_polynomial_curve", no_init) ("piecewise_polynomial_curve", init<>())
.def("__init__", make_constructor(&wrapPiecewisePolynomialCurveConstructor)) .def("__init__", make_constructor(&wrapPiecewisePolynomialCurveConstructor))
.def("min", &piecewise_polynomial_curve_t::min) .def("min", &piecewise_polynomial_curve_t::min)
.def("max", &piecewise_polynomial_curve_t::max) .def("max", &piecewise_polynomial_curve_t::max)
...@@ -367,10 +368,10 @@ BOOST_PYTHON_MODULE(curves) ...@@ -367,10 +368,10 @@ BOOST_PYTHON_MODULE(curves)
.def("derivate", &piecewise_polynomial_curve_t::derivate) .def("derivate", &piecewise_polynomial_curve_t::derivate)
.def("add_curve", &piecewise_polynomial_curve_t::add_curve) .def("add_curve", &piecewise_polynomial_curve_t::add_curve)
.def("is_continuous", &piecewise_polynomial_curve_t::is_continuous) .def("is_continuous", &piecewise_polynomial_curve_t::is_continuous)
//.def(SerializableVisitor<piecewise_polynomial_curve_t>()) .def(SerializableVisitor<piecewise_polynomial_curve_t>())
; ;
class_<piecewise_bezier3_curve_t> class_<piecewise_bezier3_curve_t>
("piecewise_bezier3_curve", no_init) ("piecewise_bezier3_curve", init<>())
.def("__init__", make_constructor(&wrapPiecewiseBezier3CurveConstructor)) .def("__init__", make_constructor(&wrapPiecewiseBezier3CurveConstructor))
.def("min", &piecewise_bezier3_curve_t::min) .def("min", &piecewise_bezier3_curve_t::min)
.def("max", &piecewise_bezier3_curve_t::max) .def("max", &piecewise_bezier3_curve_t::max)
...@@ -378,10 +379,10 @@ BOOST_PYTHON_MODULE(curves) ...@@ -378,10 +379,10 @@ BOOST_PYTHON_MODULE(curves)
.def("derivate", &piecewise_bezier3_curve_t::derivate) .def("derivate", &piecewise_bezier3_curve_t::derivate)
.def("add_curve", &piecewise_bezier3_curve_t::add_curve) .def("add_curve", &piecewise_bezier3_curve_t::add_curve)
.def("is_continuous", &piecewise_bezier3_curve_t::is_continuous) .def("is_continuous", &piecewise_bezier3_curve_t::is_continuous)
//.def(SerializableVisitor<piecewise_bezier3_curve_t>()) .def(SerializableVisitor<piecewise_bezier3_curve_t>())
; ;
class_<piecewise_bezier6_curve_t> class_<piecewise_bezier6_curve_t>
("piecewise_bezier6_curve", no_init) ("piecewise_bezier6_curve", init<>())
.def("__init__", make_constructor(&wrapPiecewiseBezier6CurveConstructor)) .def("__init__", make_constructor(&wrapPiecewiseBezier6CurveConstructor))
.def("min", &piecewise_bezier6_curve_t::min) .def("min", &piecewise_bezier6_curve_t::min)
.def("max", &piecewise_bezier6_curve_t::max) .def("max", &piecewise_bezier6_curve_t::max)
...@@ -389,10 +390,10 @@ BOOST_PYTHON_MODULE(curves) ...@@ -389,10 +390,10 @@ BOOST_PYTHON_MODULE(curves)
.def("derivate", &piecewise_bezier6_curve_t::derivate) .def("derivate", &piecewise_bezier6_curve_t::derivate)
.def("add_curve", &piecewise_bezier6_curve_t::add_curve) .def("add_curve", &piecewise_bezier6_curve_t::add_curve)
.def("is_continuous", &piecewise_bezier6_curve_t::is_continuous) .def("is_continuous", &piecewise_bezier6_curve_t::is_continuous)
//.def(SerializableVisitor<piecewise_bezier6_curve_t>()) .def(SerializableVisitor<piecewise_bezier6_curve_t>())
; ;
class_<piecewise_cubic_hermite_curve_t> class_<piecewise_cubic_hermite_curve_t>
("piecewise_cubic_hermite_curve", no_init) ("piecewise_cubic_hermite_curve", init<>())
.def("__init__", make_constructor(&wrapPiecewiseCubicHermiteCurveConstructor)) .def("__init__", make_constructor(&wrapPiecewiseCubicHermiteCurveConstructor))
.def("min", &piecewise_cubic_hermite_curve_t::min) .def("min", &piecewise_cubic_hermite_curve_t::min)
.def("max", &piecewise_cubic_hermite_curve_t::max) .def("max", &piecewise_cubic_hermite_curve_t::max)
...@@ -400,7 +401,7 @@ BOOST_PYTHON_MODULE(curves) ...@@ -400,7 +401,7 @@ BOOST_PYTHON_MODULE(curves)
.def("derivate", &piecewise_cubic_hermite_curve_t::derivate) .def("derivate", &piecewise_cubic_hermite_curve_t::derivate)
.def("add_curve", &piecewise_cubic_hermite_curve_t::add_curve) .def("add_curve", &piecewise_cubic_hermite_curve_t::add_curve)
.def("is_continuous", &piecewise_cubic_hermite_curve_t::is_continuous) .def("is_continuous", &piecewise_cubic_hermite_curve_t::is_continuous)
//.def(SerializableVisitor<piecewise_cubic_hermite_curve_t>()) .def(SerializableVisitor<piecewise_cubic_hermite_curve_t>())
; ;
/** END piecewise curve function **/ /** END piecewise curve function **/
...@@ -422,7 +423,7 @@ BOOST_PYTHON_MODULE(curves) ...@@ -422,7 +423,7 @@ BOOST_PYTHON_MODULE(curves)
/** BEGIN cubic_hermite_spline **/ /** BEGIN cubic_hermite_spline **/
class_<cubic_hermite_spline_t> class_<cubic_hermite_spline_t>
("cubic_hermite_spline", no_init) ("cubic_hermite_spline", init<>())
.def("__init__", make_constructor(&wrapCubicHermiteSplineConstructor)) .def("__init__", make_constructor(&wrapCubicHermiteSplineConstructor))
.def("min", &cubic_hermite_spline_t::min) .def("min", &cubic_hermite_spline_t::min)
.def("max", &cubic_hermite_spline_t::max) .def("max", &cubic_hermite_spline_t::max)
......
...@@ -28,8 +28,6 @@ class TestCurves(unittest.TestCase): ...@@ -28,8 +28,6 @@ class TestCurves(unittest.TestCase):
while t < 2.: while t < 2.:
self.assertTrue(norm(a(t) - matrix([1., 2., 3.]).T) < __EPS) self.assertTrue(norm(a(t) - matrix([1., 2., 3.]).T) < __EPS)
t += 0.1 t += 0.1
waypoints_0 = matrix([[0,0,0], [0,0,0]]).transpose()
waypoints6_0 = matrix([[0,0,0,0,0,0], [0,0,0,0,0,0]]).transpose()
waypoints = matrix([[1., 2., 3.], [4., 5., 6.]]).transpose() waypoints = matrix([[1., 2., 3.], [4., 5., 6.]]).transpose()
waypoints6 = matrix([[1., 2., 3., 7., 5., 5.], [4., 5., 6., 4., 5., 6.]]).transpose() waypoints6 = matrix([[1., 2., 3., 7., 5., 5.], [4., 5., 6., 4., 5., 6.]]).transpose()
time_waypoints = matrix([0., 1.]).transpose() time_waypoints = matrix([0., 1.]).transpose()
...@@ -82,23 +80,25 @@ class TestCurves(unittest.TestCase): ...@@ -82,23 +80,25 @@ class TestCurves(unittest.TestCase):
a = bezier3(waypoints, c) a = bezier3(waypoints, c)
self.assertTrue(norm(a.derivate(0, 1) - c.init_vel) < 1e-10) self.assertTrue(norm(a.derivate(0, 1) - c.init_vel) < 1e-10)
self.assertTrue(norm(a.derivate(1, 2) - c.end_acc) < 1e-10) self.assertTrue(norm(a.derivate(1, 2) - c.end_acc) < 1e-10)
# Test serialization : Bezier 6
a6.saveAsText("serialization_bezier6.test")
#waypoints = matrix([[0,0,0,], [0,0,0,]]).transpose()
b6 = bezier6(waypoints6_0)
b6.loadFromText("serialization_bezier6.test")
self.assertTrue((a6(0.4) == b6(0.4)).all())
# Test serialization : bezier 3 # Test serialization : bezier 3
a.saveAsText("serialization_bezier3.test") a.saveAsText("serialization_curve.test")
#waypoints = matrix([[0,0,0,], [0,0,0,]]).transpose() #waypoints = matrix([[0,0,0,], [0,0,0,]]).transpose()
b = bezier3(waypoints_0) b = bezier3()
b.loadFromText("serialization_bezier3.test") b.loadFromText("serialization_curve.test")
self.assertTrue((a(0.4) == b(0.4)).all()) self.assertTrue((a(0.4) == b(0.4)).all())
# Test serialization : Bezier 6
a6.saveAsText("serialization_curve.test")
b6 = bezier6()
b6.loadFromText("serialization_curve.test")
self.assertTrue((a6(0.4) == b6(0.4)).all())
return return
def test_polynomial(self): def test_polynomial(self):
# To test : # To test :
# - Functions : constructor, min, max, derivate, serialize, deserialize # - Functions : constructor, min, max, derivate, serialize, deserialize
waypoints_0 = matrix([[0.,0.,0.], [0.,0.,0.]]).transpose()
waypoints = matrix([[1., 2., 3.], [4., 5., 6.]]).transpose() waypoints = matrix([[1., 2., 3.], [4., 5., 6.]]).transpose()
a = polynomial(waypoints) # Defined on [0.,1.] a = polynomial(waypoints) # Defined on [0.,1.]
a = polynomial(waypoints, -1., 3.) # Defined on [-1.,3.] a = polynomial(waypoints, -1., 3.) # Defined on [-1.,3.]
...@@ -108,31 +108,52 @@ class TestCurves(unittest.TestCase): ...@@ -108,31 +108,52 @@ class TestCurves(unittest.TestCase):
self.assertTrue((a.derivate(0.4, 0) == a(0.4)).all()) self.assertTrue((a.derivate(0.4, 0) == a(0.4)).all())
a.derivate(0.4, 2) a.derivate(0.4, 2)
# Test serialization # Test serialization
a.saveAsText("serialiation_polynomial.test") a.saveAsText("serialization_curve.test")
#waypoints = matrix([[0,0,0,], [0,0,0,]]).transpose() b = polynomial()
b = polynomial(waypoints) b.loadFromText("serialization_curve.test")
b.loadFromText("serialiation_polynomial.test") self.assertTrue((a(0.4) == b(0.4)).all())
return
def test_cubic_hermite_spline(self):
points = matrix([[1., 2., 3.], [4., 5., 6.]]).transpose()
tangents = matrix([[1., 2., 3.], [4., 5., 6.]]).transpose()
time_points = matrix([0., 1.]).transpose()
a = cubic_hermite_spline(points, tangents, time_points)
a.min()
a.max()
a(0.4)
self.assertTrue((a.derivate(0.4, 0) == a(0.4)).all())
a.derivate(0.4, 2)
# Test serialization
a.saveAsText("serialization_curve.test")
b = cubic_hermite_spline()
b.loadFromText("serialization_curve.test")
self.assertTrue((a(0.4) == b(0.4)).all()) self.assertTrue((a(0.4) == b(0.4)).all())
return return
def test_piecewise_polynomial_curve(self): def test_piecewise_polynomial_curve(self):
# To test : # To test :
# - Functions : constructor, min, max, derivate, add_curve, is_continuous, serialize, deserialize # - Functions : constructor, min, max, derivate, add_curve, is_continuous, serialize, deserialize
waypoints0 = matrix([[0., 0., 0.]]).transpose()
waypoints1 = matrix([[1., 1., 1.]]).transpose() waypoints1 = matrix([[1., 1., 1.]]).transpose()
waypoints2 = matrix([[1., 1., 1.], [1., 1., 1.]]).transpose() waypoints2 = matrix([[1., 1., 1.], [1., 1., 1.]]).transpose()
pol0 = polynomial(waypoints0, 0., 0.1)
a = polynomial(waypoints1, 0., 1.) a = polynomial(waypoints1, 0., 1.)
b = polynomial(waypoints2, 1., 3.) b = polynomial(waypoints2, 1., 3.)
ppc = piecewise_polynomial_curve(a) pc = piecewise_polynomial_curve(a)
ppc.add_curve(b) pc.add_curve(b)
ppc.min() pc.min()
ppc.max() pc.max()
ppc(0.4) pc(0.4)
self.assertTrue((ppc.derivate(0.4, 0) == ppc(0.4)).all()) self.assertTrue((pc.derivate(0.4, 0) == pc(0.4)).all())
ppc.derivate(0.4, 2) pc.derivate(0.4, 2)
ppc.is_continuous(0) pc.is_continuous(0)
ppc.is_continuous(1) pc.is_continuous(1)
# Test serialization # Test serialization
pc.saveAsText("serialization_pc.test")
pc_test = piecewise_polynomial_curve()
pc_test.loadFromText("serialization_pc.test")
self.assertTrue((pc(0.4) == pc_test(0.4)).all())
return return
def test_piecewise_bezier3_curve(self): def test_piecewise_bezier3_curve(self):
...@@ -141,15 +162,20 @@ class TestCurves(unittest.TestCase): ...@@ -141,15 +162,20 @@ class TestCurves(unittest.TestCase):
waypoints = matrix([[1., 2., 3.], [4., 5., 6.]]).transpose() waypoints = matrix([[1., 2., 3.], [4., 5., 6.]]).transpose()
a = bezier3(waypoints, 0., 1.) a = bezier3(waypoints, 0., 1.)
b = bezier3(waypoints, 1., 2.) b = bezier3(waypoints, 1., 2.)
ppc = piecewise_bezier3_curve(a) pc = piecewise_bezier3_curve(a)
ppc.add_curve(b) pc.add_curve(b)
ppc.min() pc.min()
ppc.max() pc.max()
ppc(0.4) pc(0.4)
self.assertTrue((ppc.derivate(0.4, 0) == ppc(0.4)).all()) self.assertTrue((pc.derivate(0.4, 0) == pc(0.4)).all())
ppc.derivate(0.4, 2) pc.derivate(0.4, 2)
ppc.is_continuous(0) pc.is_continuous(0)
ppc.is_continuous(1) pc.is_continuous(1)
# Test serialization
pc.saveAsText("serialization_pc.test")
pc_test = piecewise_bezier3_curve()
pc_test.loadFromText("serialization_pc.test")
self.assertTrue((pc(0.4) == pc_test(0.4)).all())
return return
def test_piecewise_bezier6_curve(self): def test_piecewise_bezier6_curve(self):
...@@ -158,15 +184,20 @@ class TestCurves(unittest.TestCase): ...@@ -158,15 +184,20 @@ class TestCurves(unittest.TestCase):
waypoints = matrix([[1., 2., 3., 7., 5., 5.], [4., 5., 6., 4., 5., 6.]]).transpose() waypoints = matrix([[1., 2., 3., 7., 5., 5.], [4., 5., 6., 4., 5., 6.]]).transpose()
a = bezier6(waypoints, 0., 1.) a = bezier6(waypoints, 0., 1.)
b = bezier6(waypoints, 1., 2.) b = bezier6(waypoints, 1., 2.)
ppc = piecewise_bezier6_curve(a) pc = piecewise_bezier6_curve(a)
ppc.add_curve(b) pc.add_curve(b)
ppc.min() pc.min()
ppc.max() pc.max()
ppc(0.4) pc(0.4)
self.assertTrue((ppc.derivate(0.4, 0) == ppc(0.4)).all()) self.assertTrue((pc.derivate(0.4, 0) == pc(0.4)).all())
ppc.derivate(0.4, 2) pc.derivate(0.4, 2)
ppc.is_continuous(0) pc.is_continuous(0)
ppc.is_continuous(1) pc.is_continuous(1)
# Test serialization
pc.saveAsText("serialization_pc.test")
pc_test = piecewise_bezier6_curve()
pc_test.loadFromText("serialization_pc.test")
self.assertTrue((pc(0.4) == pc_test(0.4)).all())
return return
def test_piecewise_cubic_hermite_curve(self): def test_piecewise_cubic_hermite_curve(self):
...@@ -178,15 +209,20 @@ class TestCurves(unittest.TestCase): ...@@ -178,15 +209,20 @@ class TestCurves(unittest.TestCase):
time_points1 = matrix([1., 2.]).transpose() time_points1 = matrix([1., 2.]).transpose()
a = cubic_hermite_spline(points, tangents, time_points0) a = cubic_hermite_spline(points, tangents, time_points0)
b = cubic_hermite_spline(points, tangents, time_points1) b = cubic_hermite_spline(points, tangents, time_points1)
ppc = piecewise_cubic_hermite_curve(a) pc = piecewise_cubic_hermite_curve(a)
ppc.add_curve(b) pc.add_curve(b)
ppc.min() pc.min()
ppc.max() pc.max()
ppc(0.4) pc(0.4)
self.assertTrue((ppc.derivate(0.4, 0) == ppc(0.4)).all()) self.assertTrue((pc.derivate(0.4, 0) == pc(0.4)).all())
ppc.derivate(0.4, 2) pc.derivate(0.4, 2)
ppc.is_continuous(0) pc.is_continuous(0)
ppc.is_continuous(1) pc.is_continuous(1)
# Test serialization
pc.saveAsText("serialization_pc.test")
pc_test = piecewise_cubic_hermite_curve()
pc_test.loadFromText("serialization_pc.test")
self.assertTrue((pc(0.4) == pc_test(0.4)).all())
return return
def test_exact_cubic(self): def test_exact_cubic(self):
...@@ -222,18 +258,6 @@ class TestCurves(unittest.TestCase): ...@@ -222,18 +258,6 @@ class TestCurves(unittest.TestCase):
a = exact_cubic(waypoints, time_waypoints, c) a = exact_cubic(waypoints, time_waypoints, c)
return return
def test_cubic_hermite_spline(self):
points = matrix([[1., 2., 3.], [4., 5., 6.]]).transpose()
tangents = matrix([[1., 2., 3.], [4., 5., 6.]]).transpose()
time_points = matrix([0., 1.]).transpose()
a = cubic_hermite_spline(points, tangents, time_points)
a.min()
a.max()
a(0.4)
self.assertTrue((a.derivate(0.4, 0) == a(0.4)).all())
a.derivate(0.4, 2)
return
def test_conversion_curves(self): def test_conversion_curves(self):
__EPS = 1e-6 __EPS = 1e-6
waypoints = matrix([[1., 2., 3.], [4., 5., 6.]]).transpose() waypoints = matrix([[1., 2., 3.], [4., 5., 6.]]).transpose()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment