curve_abc.h
Go to the documentation of this file.
1 
11 #ifndef _STRUCT_CURVE_ABC
12 #define _STRUCT_CURVE_ABC
13 
14 #include "MathDefs.h"
15 #include "serialization/archive.hpp"
16 #include "serialization/eigen-matrix.hpp"
17 #include "serialization/registeration.hpp"
18 #include <boost/serialization/shared_ptr.hpp>
19 #include <boost/smart_ptr/shared_ptr.hpp>
20 #include <functional>
21 
22 namespace curves {
23 
24 template <typename T>
25 bool isApprox(const T a, const T b, const T eps = 1e-6) {
26  return fabs(a - b) < eps;
27 }
28 
32 template <typename Time = double, typename Numeric = Time, bool Safe = false,
33  typename Point = Eigen::Matrix<Numeric, Eigen::Dynamic, 1>, typename Point_derivate = Point>
34 struct curve_abc : std::unary_function<Time, Point>, public serialization::Serializable {
35  typedef Point point_t;
36  typedef Point_derivate point_derivate_t;
37  typedef Time time_t;
38  typedef Numeric num_t;
41  typedef boost::shared_ptr<curve_t> curve_ptr_t;
42 
43  /* Constructors - destructors */
44  public:
46  curve_abc() {}
47 
49  virtual ~curve_abc() {}
50  /* Constructors - destructors */
51 
52  /*Operations*/
56  virtual point_t operator()(const time_t t) const = 0;
57 
61  virtual curve_derivate_t* compute_derivate_ptr(const std::size_t order) const = 0;
62 
67  virtual point_derivate_t derivate(const time_t t, const std::size_t order) const = 0;
68 
77  bool isEquivalent(const curve_t* other, const Numeric prec = Eigen::NumTraits<Numeric>::dummy_precision(),
78  const size_t order = 5) const {
79  bool equal = curves::isApprox<num_t>(min(), other->min()) && curves::isApprox<num_t>(max(), other->max()) &&
80  (dim() == other->dim());
81  if (!equal) {
82  return false;
83  }
84  time_t inc = (max() - min()) / 10.; // FIXME : define this step somewhere ??
85  // check the value along the two curves
86  time_t t = min();
87  while (t <= max()) {
88  if (!(*this)(t).isApprox(other->operator()(t), prec)) {
89  return false;
90  }
91  t += inc;
92  }
93  // check if the derivatives are equal
94  for (size_t n = 1; n <= order; ++n) {
95  t = min();
96  while (t <= max()) {
97  if (!derivate(t, n).isApprox(other->derivate(t, n), prec)) {
98  return false;
99  }
100  t += inc;
101  }
102  }
103  return true;
104  }
105 
114  virtual bool isApprox(const curve_t* other,
115  const Numeric prec = Eigen::NumTraits<Numeric>::dummy_precision()) const = 0;
116 
117  /*Operations*/
118 
119  /*Helpers*/
122  virtual std::size_t dim() const = 0;
125  virtual time_t min() const = 0;
128  virtual time_t max() const = 0;
131  virtual std::size_t degree() const = 0;
132 
133  std::pair<time_t, time_t> timeRange() { return std::make_pair(min(), max()); }
134  /*Helpers*/
135 
136  // Serialization of the class
137  friend class boost::serialization::access;
138  template <class Archive>
139  void serialize(Archive& ar, const unsigned int version) {
140  serialization::register_types<Archive>(ar, version);
141  if (version) {
142  // Do something depending on version ?
143  }
144  }
145 };
146 BOOST_SERIALIZATION_ASSUME_ABSTRACT(curve_abc)
147 } // namespace curves
148 
149 DEFINE_CLASS_TEMPLATE_VERSION(SINGLE_ARG(typename Time, typename Numeric, bool Safe, typename Point, typename Point_derivate),
151 #endif //_STRUCT_CURVE_ABC
virtual time_t max() const =0
Get the maximum time for which the curve is defined.
curve_abc()
Constructor.
Definition: curve_abc.h:46
virtual curve_derivate_t * compute_derivate_ptr(const std::size_t order) const =0
Compute the derived curve at order N.
virtual bool isApprox(const curve_t *other, const Numeric prec=Eigen::NumTraits< Numeric >::dummy_precision()) const =0
isApprox check if other and *this are approximately equal given a precision treshold Only two curves ...
virtual point_t operator()(const time_t t) const =0
Evaluation of the cubic spline at time t.
double Numeric
Definition: effector_spline.h:26
bool isEquivalent(const curve_t *other, const Numeric prec=Eigen::NumTraits< Numeric >::dummy_precision(), const size_t order=5) const
isEquivalent check if other and *this are approximately equal by values, given a precision treshold...
Definition: curve_abc.h:77
virtual point_derivate_t derivate(const time_t t, const std::size_t order) const =0
Evaluate the derivative of order N of curve at time t.
Point point_t
Definition: curve_abc.h:35
virtual time_t min() const =0
Get the minimum time for which the curve is defined.
Definition: bernstein.h:20
Time time_t
Definition: curve_abc.h:37
std::pair< time_t, time_t > timeRange()
Definition: curve_abc.h:133
virtual std::size_t degree() const =0
Get the degree of the curve.
virtual std::size_t dim() const =0
Get dimension of curve.
Point_derivate point_derivate_t
Definition: curve_abc.h:36
curve_abc< Time, Numeric, Safe, point_t, point_derivate_t > curve_t
Definition: curve_abc.h:39
void serialize(Archive &ar, const unsigned int version)
Definition: curve_abc.h:139
curve_abc< Time, Numeric, Safe, point_derivate_t > curve_derivate_t
Definition: curve_abc.h:40
boost::shared_ptr< curve_t > curve_ptr_t
Definition: curve_abc.h:41
double Time
Definition: effector_spline.h:27
Eigen::Matrix< Numeric, Eigen::Dynamic, 1 > Point
Definition: effector_spline.h:28
bool isApprox(const T a, const T b, const T eps=1e-6)
Definition: curve_abc.h:25
Represents a curve of dimension Dim. If value of parameter Safe is false, no verification is made on ...
Definition: curve_abc.h:34
Numeric num_t
Definition: curve_abc.h:38
virtual ~curve_abc()
Destructor.
Definition: curve_abc.h:49