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

Modif of Pierre : Add docstring in python API for piecewise polynomial and...

Modif of Pierre : Add docstring in python API for piecewise polynomial and polynomial / Init T_min and T_max in empty constructor of curves
parent ea8ac10c
......@@ -47,7 +47,9 @@ namespace curves
/* Constructors - destructors */
public:
bezier_curve(){}
bezier_curve()
: T_min_(0), T_max_(0)
{}
/// \brief Constructor.
/// Given the first and last point of a control points set, create the bezier curve.
......
......@@ -46,7 +46,9 @@ namespace curves
public:
cubic_hermite_spline(){}
cubic_hermite_spline()
: T_min_(0), T_max_(0)
{}
/// \brief Constructor.
/// \param wayPointsBegin : an iterator pointing to the first element of a pair(position, derivative) container.
......
......@@ -66,7 +66,9 @@ namespace curves
/* Constructors - destructors */
public:
exact_cubic(){}
exact_cubic()
: piecewise_curve_t()
{}
/// \brief Constructor.
/// \param wayPointsBegin : an iterator pointing to the first element of a waypoint container.
......
......@@ -44,7 +44,7 @@ namespace curves
public:
piecewise_curve()
: size_(0)
: size_(0), T_min_(0), T_max_(0)
{}
/// \brief Constructor.
......
......@@ -50,7 +50,9 @@ namespace curves
/* Constructors - destructors */
public:
polynomial(){}
polynomial()
: T_min_(0), T_max_(0)
{}
/// \brief Constructor.
/// \param coefficients : a reference to an Eigen matrix where each column is a coefficient,
......
......@@ -79,7 +79,7 @@ namespace curves
}
template <typename Bezier, typename PointList, typename T_Point, typename CurveConstraints>
Bezier* wrapBezierConstructorConstraintsTemplate(const PointList& array, const CurveConstraints& constraints,
Bezier* wrapBezierConstructorConstraintsTemplate(const PointList& array, const CurveConstraints& constraints,
const real T_min =0., const real T_max =1.)
{
T_Point asVector = vectorFromEigenArray<PointList, T_Point>(array);
......@@ -103,7 +103,8 @@ namespace curves
bezier3_t* wrapBezierConstructorBounds3Constraints(const point_list_t& array, const curve_constraints_t& constraints,
const real T_min, const real T_max)
{
return wrapBezierConstructorConstraintsTemplate<bezier3_t, point_list_t, t_point_t, curve_constraints_t>(array, constraints, T_min, T_max) ;
return wrapBezierConstructorConstraintsTemplate<bezier3_t, point_list_t, t_point_t, curve_constraints_t>(array, constraints,
T_min, T_max) ;
}
/*END 3D constructors bezier */
/*6D constructors bezier */
......@@ -135,14 +136,15 @@ namespace curves
{
throw std::length_error("size of points and tangents must be the same");
}
for(int i =0;i<points.cols();++i)
for(int i =0;i<points.cols();++i)
{
res.push_back(pair_point_tangent_t(tangents.col(i), tangents.col(i)));
}
return res;
}
cubic_hermite_spline_t* wrapCubicHermiteSplineConstructor(const point_list_t& points, const point_list_t& tangents, const time_waypoints_t& time_pts)
cubic_hermite_spline_t* wrapCubicHermiteSplineConstructor(const point_list_t& points, const point_list_t& tangents,
const time_waypoints_t& time_pts)
{
t_pair_point_tangent_t ppt = getPairsPointTangent(points, tangents);
std::vector<real> time_control_pts;
......@@ -170,25 +172,41 @@ namespace curves
{
return new piecewise_polynomial_curve_t(pol);
}
piecewise_polynomial_curve_t* wrapPiecewisePolynomialCurveEmptyConstructor()
{
return new piecewise_polynomial_curve_t();
}
piecewise_bezier3_curve_t* wrapPiecewiseBezier3CurveConstructor(const bezier3_t& bc)
{
return new piecewise_bezier3_curve_t(bc);
}
piecewise_bezier3_curve_t* wrapPiecewiseBezier3CurveEmptyConstructor()
{
return new piecewise_bezier3_curve_t();
}
piecewise_bezier6_curve_t* wrapPiecewiseBezier6CurveConstructor(const bezier6_t& bc)
{
return new piecewise_bezier6_curve_t(bc);
}
piecewise_bezier6_curve_t* wrapPiecewiseBezier6CurveEmptyConstructor()
{
return new piecewise_bezier6_curve_t();
}
piecewise_cubic_hermite_curve_t* wrapPiecewiseCubicHermiteCurveConstructor(const cubic_hermite_spline_t& ch)
{
return new piecewise_cubic_hermite_curve_t(ch);
}
piecewise_cubic_hermite_curve_t* wrapPiecewiseCubicHermiteCurveEmptyConstructor()
{
return new piecewise_cubic_hermite_curve_t();
}
/* end wrap piecewise polynomial curve */
/* Wrap exact cubic spline */
t_waypoint_t getWayPoints(const coeff_t& array, const time_waypoints_t& time_wp)
{
t_waypoint_t res;
for(int i =0;i<array.cols();++i)
for(int i =0;i<array.cols();++i)
{
res.push_back(std::make_pair(time_wp(i), array.col(i)));
}
......@@ -216,7 +234,8 @@ namespace curves
return new exact_cubic_t(wps.begin(), wps.end());
}
exact_cubic_t* wrapExactCubicConstructorConstraint(const coeff_t& array, const time_waypoints_t& time_wp, const curve_constraints_t& constraints)
exact_cubic_t* wrapExactCubicConstructorConstraint(const coeff_t& array, const time_waypoints_t& time_wp,
const curve_constraints_t& constraints)
{
t_waypoint_t wps = getWayPoints(array, time_wp);
return new exact_cubic_t(wps.begin(), wps.end(), constraints);
......@@ -341,26 +360,36 @@ namespace curves
;
/** END variable points bezier curve**/
/** BEGIN polynomial curve function**/
class_<polynomial_t>("polynomial", init<>())
.def("__init__", make_constructor(&wrapSplineConstructor1))
.def("__init__", make_constructor(&wrapSplineConstructor2))
.def("min", &polynomial_t::min)
.def("max", &polynomial_t::max)
.def("__call__", &polynomial_t::operator())
.def("derivate", &polynomial_t::derivate)
class_<polynomial_t>("polynomial", init<>())
.def("__init__", make_constructor(&wrapSplineConstructor1),
"Create polynomial spline from an Eigen matrix of coefficient defined for t \in [min,max]."
" The matrix should contain one coefficient per column, from the zero order coefficient,up to the highest order."
" Spline order is given by the number of the columns -1.")
.def("__init__", make_constructor(&wrapSplineConstructor2),
"Create polynomial spline from an Eigen matrix of coefficient defined for t \in [0,1]."
" The matrix should contain one coefficient per column, from the zero order coefficient,up to the highest order."
" Spline order is given by the number of the columns -1.")
.def("min", &polynomial_t::min, "Get the LOWER bound on interval definition of the curve.")
.def("max", &polynomial_t::max,"Get the HIGHER bound on interval definition of the curve.")
.def("__call__", &polynomial_t::operator(),"Evaluate the spline at the given time.")
.def("derivate", &polynomial_t::derivate,"Evaluate the derivative of order N of curve at time t.",args("self","t","N"))
.def(SerializableVisitor<polynomial_t>())
;
/** END polynomial function**/
/** BEGIN piecewise curve function **/
class_<piecewise_polynomial_curve_t>
("piecewise_polynomial_curve", init<>())
.def("__init__", make_constructor(&wrapPiecewisePolynomialCurveConstructor))
.def("min", &piecewise_polynomial_curve_t::min)
.def("max", &piecewise_polynomial_curve_t::max)
.def("__call__", &piecewise_polynomial_curve_t::operator())
.def("derivate", &piecewise_polynomial_curve_t::derivate)
.def("add_curve", &piecewise_polynomial_curve_t::add_curve)
.def("is_continuous", &piecewise_polynomial_curve_t::is_continuous)
.def("__init__", make_constructor(&wrapPiecewisePolynomialCurveConstructor),
"Create a peicewise-polynomial curve containing the given polynomial curve.")
.def("min", &piecewise_polynomial_curve_t::min,"Set the LOWER bound on interval definition of the curve.")
.def("max", &piecewise_polynomial_curve_t::max,"Set the HIGHER bound on interval definition of the curve.")
.def("__call__", &piecewise_polynomial_curve_t::operator(),"Evaluate the curve at the given time.")
.def("derivate", &piecewise_polynomial_curve_t::derivate,"Evaluate the derivative of order N of curve at time t.",args("self","t","N"))
.def("add_curve", &piecewise_polynomial_curve_t::add_curve,
"Add a new curve to piecewise curve, which should be defined in T_{min},T_{max}] "
"where T_{min} is equal toT_{max} of the actual piecewise curve.")
.def("is_continuous", &piecewise_polynomial_curve_t::is_continuous,"Check if the curve is continuous at the given order.")
.def(SerializableVisitor<piecewise_polynomial_curve_t>())
;
class_<piecewise_bezier3_curve_t>
......
import unittest
import os
from numpy import matrix
from numpy.linalg import norm
......@@ -93,6 +94,7 @@ class TestCurves(unittest.TestCase):
b6 = bezier6()
b6.loadFromText("serialization_curve.test")
self.assertTrue((a6(0.4) == b6(0.4)).all())
os.remove("serialization_curve.test")
return
def test_polynomial(self):
......@@ -112,6 +114,7 @@ class TestCurves(unittest.TestCase):
b = polynomial()
b.loadFromText("serialization_curve.test")
self.assertTrue((a(0.4) == b(0.4)).all())
os.remove("serialization_curve.test")
return
def test_cubic_hermite_spline(self):
......@@ -129,6 +132,7 @@ class TestCurves(unittest.TestCase):
b = cubic_hermite_spline()
b.loadFromText("serialization_curve.test")
self.assertTrue((a(0.4) == b(0.4)).all())
os.remove("serialization_curve.test")
return
def test_piecewise_polynomial_curve(self):
......@@ -154,6 +158,7 @@ class TestCurves(unittest.TestCase):
pc_test = piecewise_polynomial_curve()
pc_test.loadFromText("serialization_pc.test")
self.assertTrue((pc(0.4) == pc_test(0.4)).all())
os.remove("serialization_pc.test")
return
def test_piecewise_bezier3_curve(self):
......@@ -176,6 +181,7 @@ class TestCurves(unittest.TestCase):
pc_test = piecewise_bezier3_curve()
pc_test.loadFromText("serialization_pc.test")
self.assertTrue((pc(0.4) == pc_test(0.4)).all())
os.remove("serialization_pc.test")
return
def test_piecewise_bezier6_curve(self):
......@@ -198,6 +204,7 @@ class TestCurves(unittest.TestCase):
pc_test = piecewise_bezier6_curve()
pc_test.loadFromText("serialization_pc.test")
self.assertTrue((pc(0.4) == pc_test(0.4)).all())
os.remove("serialization_pc.test")
return
def test_piecewise_cubic_hermite_curve(self):
......@@ -223,6 +230,7 @@ class TestCurves(unittest.TestCase):
pc_test = piecewise_cubic_hermite_curve()
pc_test.loadFromText("serialization_pc.test")
self.assertTrue((pc(0.4) == pc_test(0.4)).all())
os.remove("serialization_pc.test")
return
def test_exact_cubic(self):
......@@ -243,6 +251,7 @@ class TestCurves(unittest.TestCase):
b = exact_cubic()
b.loadFromText("serialization_pc.test")
self.assertTrue((a(0.4) == b(0.4)).all())
os.remove("serialization_pc.test")
return
def test_exact_cubic_constraint(self):
......
Markdown is supported
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