Commit a58c324d authored by Steve Tonneau's avatar Steve Tonneau

added exact_cubic

parent ab3e8f97
#include "spline/bezier_curve.h"
#include "spline/spline_curve.h"
#include "spline/exact_cubic.h"
#include <vector>
......@@ -11,6 +12,7 @@
/*** TEMPLATE SPECIALIZATION FOR PYTHON ****/
typedef double real;
typedef Eigen::Vector3d point_t;
typedef Eigen::VectorXd time_waypoints_t;
typedef Eigen::Matrix<real, 3, Eigen::Dynamic> point_list_t;
typedef std::vector<point_t,Eigen::aligned_allocator<point_t> > t_point_t;
typedef std::pair<real, point_t> Waypoint;
......@@ -18,7 +20,10 @@ typedef std::vector<Waypoint> T_Waypoint;
typedef spline::bezier_curve <real, real, 3, true, point_t> bezier_t;
typedef spline::spline_curve <real, real, 3, true, point_t, t_point_t> spline_curve_t;
typedef spline::exact_cubic <real, real, 3, true, point_t, t_point_t> exact_cubic_t;
typedef spline_curve_t::coeff_t coeff_t;
typedef std::pair<real, point_t> waypoint_t;
typedef std::vector<waypoint_t, Eigen::aligned_allocator<point_t> > t_waypoint_t;
/*** TEMPLATE SPECIALIZATION FOR PYTHON ****/
EIGENPY_DEFINE_STRUCT_ALLOCATOR_SPECIALIZATION(bezier_t)
......@@ -54,6 +59,20 @@ spline_curve_t* wrapSplineConstructor(const coeff_t& array)
}
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)
res.push_back(std::make_pair(time_wp(i), array.col(i)));
return res;
}
exact_cubic_t* wrapExactCubicConstructor(const coeff_t& array, const time_waypoints_t& time_wp)
{
t_waypoint_t wps = getWayPoints(array, time_wp);
return new exact_cubic_t(wps.begin(), wps.end());
}
BOOST_PYTHON_MODULE(spline)
{
......@@ -90,6 +109,16 @@ BOOST_PYTHON_MODULE(spline)
/** END cubic function**/
/** BEGIN exact_cubic curve**/
class_<exact_cubic_t>
("exact_cubic", no_init)
.def("__init__", make_constructor(&wrapExactCubicConstructor))
.def("min", &exact_cubic_t::min)
.def("max", &exact_cubic_t::max)
.def("__call__", &exact_cubic_t::operator())
.def("derivate", &exact_cubic_t::derivate)
;
/** END bezier curve**/
}
......
from spline import bezier, spline
from spline import bezier, spline, exact_cubic
from numpy import matrix
waypoints = matrix([[1.,2.,3.],[4.,5.,6.]]).transpose()
time_waypoints = matrix([0.,1.])
#testing bezier curve
a = bezier(waypoints)
......@@ -20,3 +21,11 @@ a.max()
a(0.4)
assert((a.derivate(0.4,0) == a(0.4)).all())
a.derivate(0.4,2)
#testing exact_cubic function
a = exact_cubic(waypoints, time_waypoints)
a.min()
a.max()
a(0.4)
assert((a.derivate(0.4,0) == a(0.4)).all())
a.derivate(0.4,2)
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