curve_abc.h
Go to the documentation of this file.
1 
11 #ifndef _STRUCT_CURVE_ABC
12 #define _STRUCT_CURVE_ABC
13 
14 #include <boost/serialization/shared_ptr.hpp>
15 #include <boost/smart_ptr/shared_ptr.hpp>
16 #include <functional>
17 
18 #include "MathDefs.h"
22 
23 namespace ndcurves {
24 
25 template <typename T>
26 bool isApprox(const T a, const T b, const T eps = 1e-6) {
27  return fabs(a - b) < eps;
28 }
29 
34 template <typename Time = double, typename Numeric = Time, bool Safe = false,
35  typename Point = Eigen::Matrix<Numeric, Eigen::Dynamic, 1>,
36  typename Point_derivate = Point>
38  typedef Point point_t;
39  typedef Point_derivate point_derivate_t;
40  typedef Time time_t;
41  typedef Numeric num_t;
43  curve_t; // parent class
45  curve_derivate_t; // parent class
46  typedef boost::shared_ptr<curve_t> curve_ptr_t;
47 
48  /* Constructors - destructors */
49  public:
51  curve_abc() {}
52 
54  virtual ~curve_abc() {}
55  /* Constructors - destructors */
56 
57  /*Operations*/
61  virtual point_t operator()(const time_t t) const = 0;
62 
68  const std::size_t order) const = 0;
69 
75  virtual point_derivate_t derivate(const time_t t,
76  const std::size_t order) const = 0;
77 
90  const curve_t* other,
91  const Numeric prec = Eigen::NumTraits<Numeric>::dummy_precision(),
92  const size_t order = 5) const {
93  bool equal = ndcurves::isApprox<num_t>(min(), other->min()) &&
94  ndcurves::isApprox<num_t>(max(), other->max()) &&
95  (dim() == other->dim());
96  if (!equal) {
97  return false;
98  }
99  time_t inc =
100  (max() - min()) / 10.; // FIXME : define this step somewhere ??
101  // check the value along the two curves
102  time_t t = min();
103  while (t <= max()) {
104  if (!(*this)(t).isApprox(other->operator()(t), prec)) {
105  return false;
106  }
107  t += inc;
108  }
109  // check if the derivatives are equal
110  for (size_t n = 1; n <= order; ++n) {
111  t = min();
112  while (t <= max()) {
113  if (!derivate(t, n).isApprox(other->derivate(t, n), prec)) {
114  return false;
115  }
116  t += inc;
117  }
118  }
119  return true;
120  }
121 
131  virtual bool isApprox(
132  const curve_t* other,
133  const Numeric prec =
134  Eigen::NumTraits<Numeric>::dummy_precision()) const = 0;
135 
136  /*Operations*/
137 
138  /*Helpers*/
141  virtual std::size_t dim() const = 0;
144  virtual time_t min() const = 0;
147  virtual time_t max() const = 0;
150  virtual std::size_t degree() const = 0;
151 
152  std::pair<time_t, time_t> timeRange() { return std::make_pair(min(), max()); }
153  /*Helpers*/
154 
155  // Serialization of the class
157  template <class Archive>
158  void serialize(Archive& ar, const unsigned int version) {
159  serialization::register_types<Archive>(ar, version);
160  if (version) {
161  // Do something depending on version ?
162  }
163  }
164 };
165 BOOST_SERIALIZATION_ASSUME_ABSTRACT(curve_abc)
166 } // namespace ndcurves
167 
169  SINGLE_ARG(typename Time, typename Numeric, bool Safe, typename Point,
170  typename Point_derivate),
172 #endif //_STRUCT_CURVE_ABC
#define DEFINE_CLASS_TEMPLATE_VERSION(Template, Type)
Definition: archive.hpp:27
#define SINGLE_ARG(...)
Definition: archive.hpp:23
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
Definition: bernstein.h:20
bool isApprox(const T a, const T b, const T eps=1e-6)
Definition: curve_abc.h:26
Represents a curve of dimension Dim. If value of parameter Safe is false, no verification is made on ...
Definition: curve_abc.h:37
std::pair< time_t, time_t > timeRange()
Definition: curve_abc.h:152
Numeric num_t
Definition: curve_abc.h:41
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 ...
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:89
virtual std::size_t dim() const =0
Get dimension of curve.
Time time_t
Definition: curve_abc.h:40
curve_abc< Time, Numeric, Safe, point_t, point_derivate_t > curve_t
Definition: curve_abc.h:43
virtual ~curve_abc()
Destructor.
Definition: curve_abc.h:54
boost::shared_ptr< curve_t > curve_ptr_t
Definition: curve_abc.h:46
virtual point_t operator()(const time_t t) const =0
Evaluation of the cubic spline at time t.
curve_abc()
Constructor.
Definition: curve_abc.h:51
Point_derivate point_derivate_t
Definition: curve_abc.h:39
virtual time_t min() const =0
Get the minimum time for which the curve is defined.
virtual curve_derivate_t * compute_derivate_ptr(const std::size_t order) const =0
Compute the derived curve at order N.
curve_abc< Time, Numeric, Safe, point_derivate_t > curve_derivate_t
Definition: curve_abc.h:45
friend class boost::serialization::access
Definition: curve_abc.h:156
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.
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:158
Point point_t
Definition: curve_abc.h:38
virtual std::size_t degree() const =0
Get the degree of the curve.
Definition: archive.hpp:41