Loading...
Searching...
No Matches
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
22namespace ndcurves {
23
24template <typename T>
25bool isApprox(const T a, const T b, const T eps = 1e-6) {
26 return fabs(a - b) < eps;
27}
28
33template <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;
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:
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
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()) &&
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
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};
165} // namespace ndcurves
166
168 SINGLE_ARG(typename Time, typename Numeric, bool Safe, typename Point,
169 typename Point_derivate),
171#endif //_STRUCT_CURVE_ABC
#define DEFINE_CLASS_TEMPLATE_VERSION(Template, Type)
Definition archive.hpp:27
#define SINGLE_ARG(...)
Definition archive.hpp:23
Definition bernstein.h:20
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:36
std::shared_ptr< curve_t > curve_ptr_t
Definition curve_abc.h:45
Numeric num_t
Definition curve_abc.h:40
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...
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
virtual std::size_t dim() const =0
Get dimension of curve.
Time time_t
Definition curve_abc.h:39
curve_abc< Time, Numeric, Safe, point_t, point_derivate_t > curve_t
Definition curve_abc.h:42
virtual ~curve_abc()
Destructor.
Definition curve_abc.h:53
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:50
Point_derivate point_derivate_t
Definition curve_abc.h:38
virtual time_t min() const =0
Get the minimum time for which the curve is defined.
std::pair< time_t, time_t > timeRange()
Definition curve_abc.h:151
curve_abc< Time, Numeric, Safe, point_derivate_t > curve_derivate_t
Definition curve_abc.h:44
friend class boost::serialization::access
Definition curve_abc.h:155
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:157
virtual curve_derivate_t * compute_derivate_ptr(const std::size_t order) const =0
Compute the derived curve at order N.
Point point_t
Definition curve_abc.h:37
virtual std::size_t degree() const =0
Get the degree of the curve.
Definition archive.hpp:41