9#ifndef _CLASS_BEZIERCURVE
10#define _CLASS_BEZIERCURVE
30 typename Point = Eigen::Matrix<Numeric, Eigen::Dynamic, 1> >
33 typedef Eigen::Matrix<Numeric, Eigen::Dynamic, 1>
vector_x_t;
38 typedef std::vector<point_t, Eigen::aligned_allocator<point_t> >
t_point_t;
63 template <
typename In>
74 throw std::invalid_argument(
"Invalid size of polynomial");
77 if (
Safe && (size_ < 1 || T_max_ <= T_min_)) {
78 throw std::invalid_argument(
79 "can't create bezier min bound is higher than max bound");
82 if (
Safe &&
static_cast<size_t>(
it->size()) != dim_)
83 throw std::invalid_argument(
84 "All the control points must have the same dimension.");
85 control_points_.push_back(*
it);
101 template <
typename In>
112 if (
Safe && (size_ < 1 || T_max_ <= T_min_)) {
113 throw std::invalid_argument(
114 "can't create bezier min bound is higher than max bound");
120 if (
Safe &&
static_cast<size_t>(
cit->size()) != dim_)
121 throw std::invalid_argument(
122 "All the control points must have the same dimension.");
123 control_points_.push_back(*
cit);
129 T_min_(
other.T_min_),
130 T_max_(
other.T_max_),
133 degree_(
other.degree_),
135 control_points_(
other.control_points_) {}
146 if (
Safe & !(T_min_ <=
t &&
t <= T_max_)) {
147 throw std::invalid_argument(
148 "can't evaluate bezier curve, time t is out of range");
151 return mult_T_ * control_points_[0];
168 const Numeric
prec = Eigen::NumTraits<Numeric>::dummy_precision())
const {
171 dim_ ==
other.dim() && degree_ ==
other.degree() &&
172 size_ ==
other.size_ &&
175 if (!
equal)
return false;
176 for (
size_t i = 0;
i < size_; ++
i) {
177 if (!control_points_.at(
i).isApprox(
other.control_points_.at(
i),
prec))
185 const Numeric
prec = Eigen::NumTraits<Numeric>::dummy_precision())
const {
199 return !(*
this ==
other);
212 for (
typename t_point_t::const_iterator
pit = control_points_.begin();
213 pit != control_points_.end() - 1; ++
pit) {
220 mult_T_ * (1. / (T_max_ - T_min_)));
248 for (
typename t_point_t::const_iterator
pit = control_points_.begin();
249 pit != control_points_.end(); ++
pit) {
274 for (std::size_t
i = 1;
i <=
order; ++
i) {
322 const Numeric
u = (
t - T_min_) / (T_max_ - T_min_);
325 control_points_.begin();
347 const Numeric
u = (
t - T_min_) / (T_max_ - T_min_);
349 control_points_.begin();
368 if (
index < control_points_.size()) {
384 const Numeric u = (
t - T_min_) / (T_max_ - T_min_);
386 while (
pts.size() > 1) {
393 const Numeric u = (
t - T_min_) / (T_max_ - T_min_);
408 throw std::out_of_range(
"In deCasteljau reduction : u is not in [0;1]");
410 if (
pts.size() == 1) {
425 std::pair<bezier_curve_t, bezier_curve_t>
split(
const Numeric
t)
const {
427 if (
fabs(
t - T_max_) < MARGIN) {
428 throw std::runtime_error(
429 "can't split curve, interval range is equal to original curve");
432 const Numeric u = (
t - T_min_) / (T_max_ - T_min_);
456 std::vector<bezier_curve_t>
curves;
458 for (
int i = 0;
i <
times.rows(); ++
i) {
459 std::pair<bezier_curve_t, bezier_curve_t>
pairsplit =
466 for (
typename std::vector<bezier_curve_t>::const_iterator
cit =
485 throw std::out_of_range(
"In Extract curve : times out of bounds");
487 if (
fabs(
t1 - T_min_) < MARGIN &&
488 fabs(
t2 - T_max_) < MARGIN)
493 if (
fabs(
t1 - T_min_) < MARGIN)
497 if (
fabs(
t2 - T_max_) < MARGIN)
501 std::pair<bezier_curve_t, bezier_curve_t>
c_split = this->
split(
t1);
518 assert_operator_compatible(
g);
520 throw std::invalid_argument(
521 "Can't perform cross product on Bezier curves with dimensions != 3 ");
523 int n = (
int)(
g.degree());
526 for (
int i = 0;
i <=
m +
n; ++
i) {
528 bezier_curve_t::point_t::Zero(
dim());
529 for (
int j = std::max(0,
i -
n);
j <= std::min(
m,
i); ++
j) {
555 throw std::invalid_argument(
556 "Can't perform cross product on Bezier curves with dimensions != 3 ");
567 assert_operator_compatible(
other);
571 if (other.degree() >
degree()) {
576 typename t_point_t::const_iterator
otherit =
578 for (
typename t_point_t::iterator
it = control_points_.begin();
586 assert_operator_compatible(
other);
588 if (other.degree() >
degree()) {
593 typename t_point_t::const_iterator
otherit =
595 for (
typename t_point_t::iterator
it = control_points_.begin();
603 for (
typename t_point_t::iterator
it = control_points_.begin();
604 it != control_points_.end(); ++
it) {
611 for (
typename t_point_t::iterator
it = control_points_.begin();
612 it != control_points_.end(); ++
it) {
619 for (
typename t_point_t::iterator
it = control_points_.begin();
620 it != control_points_.end(); ++
it) {
627 for (
typename t_point_t::iterator
it = control_points_.begin();
628 it != control_points_.end(); ++
it) {
639 template <
typename In>
643 num_t T = T_max_ - T_min_;
666 void check_conditions()
const {
667 if (control_points_.size() == 0) {
668 throw std::runtime_error(
669 "Error in bezier curve : there is no control points set / did you "
670 "use empty constructor ?");
671 }
else if (dim_ == 0) {
672 throw std::runtime_error(
673 "Error in bezier curve : Dimension of points is zero / did you use "
674 "empty constructor ?");
681 throw std::invalid_argument(
682 "Can't perform base operation (+ - ) on two Bezier curves with "
683 "different time ranges");
693 std::size_t
virtual dim()
const {
return dim_; };
696 virtual time_t min()
const {
return T_min_; }
699 virtual time_t max()
const {
return T_max_; }
702 virtual std::size_t
degree()
const {
return degree_; }
722 std::vector<point_t>
ts;
723 ts.push_back(point_t::Zero(
dim));
728 friend class boost::serialization::access;
730 template <
class Archive>
736 ar& boost::serialization::make_nvp(
"dim", dim_);
737 ar& boost::serialization::make_nvp(
"T_min", T_min_);
738 ar& boost::serialization::make_nvp(
"T_max", T_max_);
739 ar& boost::serialization::make_nvp(
"mult_T",
mult_T_);
740 ar& boost::serialization::make_nvp(
"size", size_);
741 ar& boost::serialization::make_nvp(
"degree", degree_);
742 ar& boost::serialization::make_nvp(
"bernstein",
bernstein_);
743 ar& boost::serialization::make_nvp(
"control_points", control_points_);
747template <
typename T,
typename N,
bool S,
typename P>
754template <
typename T,
typename N,
bool S,
typename P>
756 std::vector<typename bezier_curve<T, N, S, P>::point_t>
ts;
757 for (std::size_t
i = 0;
i <=
p1.degree(); ++
i) {
765template <
typename T,
typename N,
bool S,
typename P>
772template <
typename T,
typename N,
bool S,
typename P>
780template <
typename T,
typename N,
bool S,
typename P>
788template <
typename T,
typename N,
bool S,
typename P>
796template <
typename T,
typename N,
bool S,
typename P>
804template <
typename T,
typename N,
bool S,
typename P>
811template <
typename T,
typename N,
bool S,
typename P>
818template <
typename T,
typename N,
bool S,
typename P>
828 SINGLE_ARG(
typename Time,
typename Numeric,
bool Safe,
typename Point),
#define DEFINE_CLASS_TEMPLATE_VERSION(Template, Type)
Definition archive.hpp:27
#define SINGLE_ARG(...)
Definition archive.hpp:23
brief Computes all Bernstein polynomes for a certain degree std::vector< Bern< Numeric > > makeBernstein(const unsigned int n)
Definition bernstein.h:91
class allowing to create a cubic hermite spline of any dimension.
interface for a Curve of arbitrary dimension.
struct to define constraints on start / end velocities and acceleration on a curve
Eigen::Matrix< Numeric, Eigen::Dynamic, 1 > Point
Definition effector_spline.h:28
double Numeric
Definition effector_spline.h:26
double Time
Definition effector_spline.h:27
std::vector< bezier_curve< Numeric, Numeric, true, linear_variable< Numeric > > > split(const problem_definition< Point, Numeric > &pDef, problem_data< Point, Numeric > &pData)
Definition details.h:230
Definition bernstein.h:20
bezier_curve< T, N, S, P > operator*(const bezier_curve< T, N, S, P > &p1, const double k)
Definition bezier_curve.h:812
bezier_curve< T, N, S, P > operator/(const bezier_curve< T, N, S, P > &p1, const double k)
Definition bezier_curve.h:805
Eigen::Vector3d cross(const Eigen::VectorXd &a, const Eigen::VectorXd &b)
Definition cross_implementation.h:14
bezier_curve< T, N, S, P > operator-(const bezier_curve< T, N, S, P > &p1)
Definition bezier_curve.h:755
bezier_curve< T, N, S, P > operator+(const bezier_curve< T, N, S, P > &p1, const bezier_curve< T, N, S, P > &p2)
Definition bezier_curve.h:748
bool isApprox(const T a, const T b, const T eps=1e-6)
Definition curve_abc.h:25
class allowing to create a piecewise curve.
Definition bezier_curve.h:31
virtual bool operator!=(const bezier_curve_t &other) const
Definition bezier_curve.h:198
void elevate_self(const std::size_t order)
Elevate the Bezier curve of order degrees higher than the current curve, but strictly equivalent....
Definition bezier_curve.h:296
Point point_t
Definition bezier_curve.h:32
virtual point_t operator()(const time_t t) const
Evaluation of the bezier curve at time t.
Definition bezier_curve.h:144
curve_abc< Time, Numeric, Safe, point_t > curve_abc_t
Definition bezier_curve.h:44
curve_constraints< point_t > curve_constraints_t
Definition bezier_curve.h:37
Eigen::Matrix< Numeric, Eigen::Dynamic, 1 > vector_x_t
Definition bezier_curve.h:33
Numeric num_t
Definition bezier_curve.h:36
bezier_curve_t elevate(const std::size_t order) const
Computes a Bezier curve of order degrees higher than the current curve, but strictly equivalent....
Definition bezier_curve.h:272
bezier_curve()
Empty constructor. Curve obtained this way can not perform other class functions.
Definition bezier_curve.h:52
std::vector< point_t, Eigen::aligned_allocator< point_t > > t_point_t
Definition bezier_curve.h:38
bezier_curve_t compute_primitive(const std::size_t order, const point_t &init) const
Compute the primitive of the curve at order N. Computes the primitive at order N of bezier curve of p...
Definition bezier_curve.h:238
bezier_curve(In PointsBegin, In PointsEnd, const time_t T_min=0., const time_t T_max=1., const time_t mult_T=1.)
Constructor. Given the first and last point of a control points set, create the bezier curve.
Definition bezier_curve.h:64
bezier_curve_t * compute_derivate_ptr(const std::size_t order) const
Compute the derived curve at order N.
Definition bezier_curve.h:228
bezier_curve_t * compute_primitive_ptr(const std::size_t order, const point_t &init) const
Definition bezier_curve.h:262
bezier_curve(In PointsBegin, In PointsEnd, const curve_constraints_t &constraints, const time_t T_min=0., const time_t T_max=1., const time_t mult_T=1.)
Constructor with constraints. This constructor will add 4 points (2 after the first one,...
Definition bezier_curve.h:102
bezier_curve(const bezier_curve &other)
Definition bezier_curve.h:127
bezier_curve_t compute_derivate(const std::size_t order) const
Compute the derived curve at order N. Computes the derivative order N, of bezier curve of parametric...
Definition bezier_curve.h:206
point_t evalBernstein(const Numeric t) const
Evaluate all Bernstein polynomes for a certain degree. A bezier curve with N control points is repres...
Definition bezier_curve.h:321
virtual bool isApprox(const curve_abc_t *other, const Numeric prec=Eigen::NumTraits< Numeric >::dummy_precision()) const
Definition bezier_curve.h:183
virtual point_t derivate(const time_t t, const std::size_t order) const
Evaluate the derivative order N of curve at time t. If derivative is to be evaluated several times,...
Definition bezier_curve.h:308
curve_abc_t::curve_ptr_t curve_ptr_t
Definition bezier_curve.h:45
bool isApprox(const bezier_curve_t &other, const Numeric prec=Eigen::NumTraits< Numeric >::dummy_precision()) const
isApprox check if other and *this are approximately equals. Only two curves of the same class can be ...
Definition bezier_curve.h:166
Time time_t
Definition bezier_curve.h:35
piecewise_curve< Time, Numeric, Safe, point_t, point_t, bezier_curve_t > piecewise_curve_t
Definition bezier_curve.h:43
bezier_curve< Time, Numeric, Safe, Point > bezier_curve_t
Definition bezier_curve.h:40
virtual bool operator==(const bezier_curve_t &other) const
Definition bezier_curve.h:194
bezier_curve_t compute_primitive(const std::size_t order) const
Definition bezier_curve.h:258
Eigen::Ref< const vector_x_t > vector_x_ref_t
Definition bezier_curve.h:34
std::shared_ptr< bezier_curve_t > bezier_curve_ptr_t
Definition bezier_curve.h:41
t_point_t::const_iterator cit_point_t
Definition bezier_curve.h:39
virtual ~bezier_curve()
Destructor.
Definition bezier_curve.h:138
Represents a curve of dimension Dim. If value of parameter Safe is false, no verification is made on ...
Definition curve_abc.h:36
std::shared_ptr< curve_t > curve_ptr_t
Definition curve_abc.h:45
virtual std::size_t dim() const =0
Get dimension of curve.
virtual time_t min() const =0
Get the minimum time for which the curve is defined.
virtual time_t max() const =0
Get the maximum time for which the curve is defined.
void serialize(Archive &ar, const unsigned int version)
Definition curve_abc.h:157
virtual std::size_t degree() const =0
Get the degree of the curve.
Definition curve_constraint.h:20
Definition piecewise_curve.h:37
std::shared_ptr< curve_t > curve_ptr_t
Definition piecewise_curve.h:49