Commit 86554a37 authored by Steve Tonneau's avatar Steve Tonneau

exposed degree of curve

parent 2b340be9
......@@ -47,7 +47,8 @@ struct bezier_curve : public curve_abc<Time, Numeric, Dim, Safe, Point>
: minBound_(minBound)
, maxBound_(maxBound)
, size_(std::distance(PointsBegin, PointsEnd))
, bernstein_(spline::makeBernstein<num_t>(size_-1))
, degree_(size_-1)
, bernstein_(spline::makeBernstein<num_t>(degree_))
{
assert(bernstein_.size() == size_);
In it(PointsBegin);
......@@ -117,16 +118,12 @@ struct bezier_curve : public curve_abc<Time, Numeric, Dim, Safe, Point>
bezier_curve_t compute_derivate(const std::size_t order) const
{
if(order == 0) return *this;
num_t degree = (num_t)(size_-1);
t_point_t derived_wp;
for(typename t_point_t::const_iterator pit = pts_.begin(); pit != pts_.end()-1; ++pit)
derived_wp.push_back(degree * (*(pit+1) - (*pit)));
derived_wp.push_back(degree_ * (*(pit+1) - (*pit)));
if(derived_wp.empty())
derived_wp.push_back(point_t::Zero());
bezier_curve_t deriv(derived_wp.begin(), derived_wp.end(),minBound_,maxBound_);
std::cout << "deriv size" << deriv.size_ << std::endl;
std::cout << "val size" << size_ << std::endl;
assert(deriv.size_ +1 == this->size_);
return deriv.compute_derivate(order-1);
}
......@@ -136,7 +133,7 @@ struct bezier_curve : public curve_abc<Time, Numeric, Dim, Safe, Point>
bezier_curve_t compute_primitive(const std::size_t order) const
{
if(order == 0) return *this;
num_t new_degree = (num_t)(size_);
num_t new_degree = (num_t)(degree_+1);
t_point_t n_wp;
point_t current_sum = point_t::Zero();
// recomputing waypoints q_i from derivative waypoints p_i. q_0 is the given constant.
......@@ -148,7 +145,6 @@ struct bezier_curve : public curve_abc<Time, Numeric, Dim, Safe, Point>
n_wp.push_back(current_sum / new_degree);
}
bezier_curve_t integ(n_wp.begin(), n_wp.end(),minBound_,maxBound_);
assert(integ.size_== this->size_ +1 );
return integ.compute_primitive(order-1);
}
......@@ -179,10 +175,7 @@ struct bezier_curve : public curve_abc<Time, Numeric, Dim, Safe, Point>
return res;
}
const t_point_t& waypoints() const
{
return pts_;
}
const t_point_t& waypoints() const {return pts_;}
/*Operations*/
......@@ -194,6 +187,7 @@ struct bezier_curve : public curve_abc<Time, Numeric, Dim, Safe, Point>
public:
const time_t minBound_, maxBound_;
const std::size_t size_;
const std::size_t degree_;
const std::vector<Bern<Numeric> > bernstein_;
private:
......
......@@ -200,6 +200,8 @@ BOOST_PYTHON_MODULE(spline)
.def("compute_derivate", &bezier6_t::compute_derivate)
.def("compute_primitive", &bezier6_t::compute_primitive)
.def("waypoints", &wayPointsToList<bezier6_t,6>)
.def_readonly("degree", &bezier6_t::degree_)
.def_readonly("nbWaypoints", &bezier6_t::size_)
;
/** END bezier curve**/
......@@ -215,6 +217,8 @@ BOOST_PYTHON_MODULE(spline)
.def("compute_derivate", &bezier_t::compute_derivate)
.def("compute_primitive", &bezier_t::compute_primitive)
.def("waypoints", &wayPointsToList<bezier_t,3>)
.def_readonly("degree", &bezier_t::degree_)
.def_readonly("nbWaypoints", &bezier_t::size_)
;
/** END bezier curve**/
......
......@@ -9,6 +9,7 @@ time_waypoints = matrix([0.,1.])
a = bezier(waypoints, -1., 3.)
a = bezier(waypoints)
assert(a.degree == a.nbWaypoints -1)
a.min()
a.max()
a(0.4)
......
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