8 #ifndef _CLASS_CUBICHERMITESPLINE 9 #define _CLASS_CUBICHERMITESPLINE 11 #include <boost/serialization/utility.hpp> 32 template <
typename Time = double,
typename Numeric =
Time,
bool Safe =
false,
33 typename Point = Eigen::Matrix<Numeric, Eigen::Dynamic, 1> >
38 Eigen::aligned_allocator<pair_point_tangent_t> >
63 template <
typename In>
66 :
size_(std::distance(PairsBegin, PairsEnd)),
degree_(3) {
68 if (Safe &&
size_ < 1) {
69 throw std::length_error(
70 "can not create cubic_hermite_spline, number of pairs is inferior to " 74 dim_ = PairsBegin->first.size();
77 for (; it != PairsEnd; ++it) {
78 if (Safe && (static_cast<size_t>(it->first.size()) !=
dim_ ||
79 static_cast<size_t>(it->second.size()) !=
dim_))
80 throw std::invalid_argument(
81 "All the control points and their derivatives must have the same " 111 throw std::invalid_argument(
112 "can't evaluate cubic hermite spline, out of range");
117 const bezier_t bezier = buildCurrentBezier(t);
133 const Numeric prec = Eigen::NumTraits<Numeric>::dummy_precision())
const {
134 bool equal = ndcurves::isApprox<num_t>(
T_min_, other.
min()) &&
135 ndcurves::isApprox<num_t>(
T_max_, other.
max()) &&
140 if (!equal)
return false;
141 for (std::size_t i = 0; i <
size_; ++i) {
153 const Numeric prec = Eigen::NumTraits<Numeric>::dummy_precision())
const {
167 return !(*
this == other);
179 throw std::invalid_argument(
180 "can't derivate cubic hermite spline, out of range");
185 const bezier_t bezier = buildCurrentBezier(t);
192 for (
size_t i = 0; i <
size_ - 1; ++i) {
217 if (time_control_points.size() !=
size()) {
218 throw std::length_error(
219 "size of time control points should be equal to number of control " 222 computeDurationSplines();
223 if (!checkDurationSplines()) {
224 throw std::invalid_argument(
225 "time_splines not monotonous, all spline duration should be superior " 255 std::size_t findInterval(
const time_t t)
const {
264 std::size_t left_id = 0;
265 std::size_t right_id =
size_ - 1;
266 while (left_id <= right_id) {
267 const std::size_t middle_id = left_id + (right_id - left_id) / 2;
269 left_id = middle_id + 1;
271 right_id = middle_id - 1;
287 size_t id_interval = findInterval(t);
293 control_points.reserve(4);
294 control_points.push_back(pair0.first);
295 control_points.push_back(pair0.first + pair0.second / 3. * (t1 - t0));
296 control_points.push_back(pair1.first - pair1.second / 3. * (t1 - t0));
297 control_points.push_back(pair1.first);
298 return bezier_t(control_points.begin(), control_points.end(), t0, t1);
304 void check_conditions()
const {
306 throw std::runtime_error(
307 "Error in cubic hermite : there is no control points set / did you " 308 "use empty constructor ?");
309 }
else if (
dim_ == 0) {
310 throw std::runtime_error(
311 "Error in cubic hermite : Dimension of points is zero / did you use " 312 "empty constructor ?");
321 void computeDurationSplines() {
326 for (i = 0; i <
size() - 1; i++) {
329 prev_time = actual_time;
336 bool checkDurationSplines()
const {
338 bool is_positive =
true;
351 std::size_t
virtual dim()
const {
return dim_; }
394 template <
class Archive>
395 void serialize(Archive& ar,
const unsigned int version) {
399 ar& BOOST_SERIALIZATION_BASE_OBJECT_NVP(
curve_abc_t);
400 ar& boost::serialization::make_nvp(
"dim",
dim_);
402 ar& boost::serialization::make_nvp(
"time_control_points",
405 ar& boost::serialization::make_nvp(
"T_min",
T_min_);
406 ar& boost::serialization::make_nvp(
"T_max",
T_max_);
407 ar& boost::serialization::make_nvp(
"size",
size_);
408 ar& boost::serialization::make_nvp(
"degree",
degree_);
416 #endif //_CLASS_CUBICHERMITESPLINE #define SINGLE_ARG(...)
Definition: archive.hpp:23
Definition: bernstein.h:20
virtual bool isApprox(const curve_abc_t *other, const Numeric prec=Eigen::NumTraits< Numeric >::dummy_precision()) const
Definition: cubic_hermite_spline.h:151
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
t_pair_point_tangent_t control_points_
Vector of pair < Point, Tangent >.
Definition: cubic_hermite_spline.h:367
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
Numeric num_t
Definition: cubic_hermite_spline.h:42
vector_time_t duration_splines_
Definition: cubic_hermite_spline.h:378
virtual Time max() const
Get the maximum time for which the curve is defined.
Definition: cubic_hermite_spline.h:357
friend class boost::serialization::access
Definition: cubic_hermite_spline.h:392
virtual Time min() const
Get the minimum time for which the curve is defined.
Definition: cubic_hermite_spline.h:354
Definition: cubic_hermite_spline.h:34
Time T_max_
Definition: cubic_hermite_spline.h:384
bezier_curve< Time, Numeric, Safe, point_t > bezier_t
Definition: cubic_hermite_spline.h:46
virtual Point derivate(const time_t t, const std::size_t order) const
Evaluate the derivative of order N of spline at time t.
Definition: cubic_hermite_spline.h:176
cubic_hermite_spline< Time, Numeric, Safe, point_t > cubic_hermite_spline_t
Definition: cubic_hermite_spline.h:45
std::size_t size() const
Get number of control points contained in the trajectory.
Definition: cubic_hermite_spline.h:243
interface for a Curve of arbitrary dimension.
Time time_t
Definition: cubic_hermite_spline.h:41
piecewise_curve< Time, Numeric, Safe, point_t, point_t, bezier_t > piecewise_bezier_t
Definition: cubic_hermite_spline.h:49
t_pair_point_tangent_t getControlPoints()
Get vector of pair (positition, derivative) corresponding to control points.
Definition: cubic_hermite_spline.h:233
class allowing to create a Bezier curve of dimension 1 <= n <= 3.
std::vector< point_t, Eigen::aligned_allocator< point_t > > t_point_t
Definition: bezier_curve.h:38
std::vector< Time > vector_time_t
Definition: cubic_hermite_spline.h:40
virtual std::size_t dim() const
Get dimension of curve.
Definition: cubic_hermite_spline.h:351
virtual std::size_t degree() const
Get the degree of the curve.
Definition: cubic_hermite_spline.h:360
std::size_t degree_
Degree (Cubic so degree 3)
Definition: cubic_hermite_spline.h:388
double Time
Definition: effector_spline.h:27
cubic_hermite_spline(In PairsBegin, In PairsEnd, const vector_time_t &time_control_points)
Constructor.
Definition: cubic_hermite_spline.h:64
piecewise_bezier_t compute_derivate(const std::size_t order) const
Definition: cubic_hermite_spline.h:190
virtual bool operator!=(const cubic_hermite_spline_t &other) const
Definition: cubic_hermite_spline.h:166
Time T_min_
Definition: cubic_hermite_spline.h:381
virtual ~cubic_hermite_spline()
Destructor.
Definition: cubic_hermite_spline.h:100
#define DEFINE_CLASS_TEMPLATE_VERSION(Template, Type)
Definition: archive.hpp:27
cubic_hermite_spline()
Empty constructor. Curve obtained this way can not perform other class functions. ...
Definition: cubic_hermite_spline.h:55
cubic_hermite_spline(const cubic_hermite_spline &other)
Definition: cubic_hermite_spline.h:89
std::size_t size_
Number of control points (pairs).
Definition: cubic_hermite_spline.h:386
Eigen::Matrix< Numeric, Eigen::Dynamic, 1 > Point
Definition: effector_spline.h:28
Definition: bezier_curve.h:31
std::size_t numIntervals() const
Get number of intervals (subsplines) contained in the trajectory.
Definition: cubic_hermite_spline.h:248
std::pair< Point, Point > pair_point_tangent_t
Definition: cubic_hermite_spline.h:36
bool isApprox(const cubic_hermite_spline_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: cubic_hermite_spline.h:131
std::vector< pair_point_tangent_t, Eigen::aligned_allocator< pair_point_tangent_t > > t_pair_point_tangent_t
Definition: cubic_hermite_spline.h:39
double Numeric
Definition: effector_spline.h:26
class allowing to create a piecewise curve.
virtual bool operator==(const cubic_hermite_spline_t &other) const
Definition: cubic_hermite_spline.h:162
void add_curve(const Curve &curve)
Definition: piecewise_curve.h:176
std::size_t dim_
Dim of curve.
Definition: cubic_hermite_spline.h:365
virtual Point operator()(const time_t t) const
Evaluation of the cubic hermite spline at time t.
Definition: cubic_hermite_spline.h:108
void setTime(const vector_time_t &time_control_points)
Set time of each control point of cubic hermite spline. Set duration of each spline, Exemple : with values corresponding to times for respectively.
Definition: cubic_hermite_spline.h:213
void serialize(Archive &ar, const unsigned int version)
Definition: cubic_hermite_spline.h:395
vector_time_t getTime()
Get vector of Time corresponding to Time for each control point.
Definition: cubic_hermite_spline.h:238
piecewise_bezier_t * compute_derivate_ptr(const std::size_t order) const
Compute the derived curve at order N.
Definition: cubic_hermite_spline.h:203
Point point_t
Definition: cubic_hermite_spline.h:35
curve_abc< Time, Numeric, Safe, point_t > curve_abc_t
Definition: cubic_hermite_spline.h:43
Represents a curve of dimension Dim. If value of parameter Safe is false, no verification is made on ...
Definition: curve_abc.h:37
bezier_t::t_point_t t_point_t
Definition: cubic_hermite_spline.h:47
vector_time_t time_control_points_
Definition: cubic_hermite_spline.h:372