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