Loading...
Searching...
No Matches
constant_curve.h
Go to the documentation of this file.
1
9#ifndef _CLASS_CONSTANTCURVE
10#define _CLASS_CONSTANTCURVE
11
12#include "curve_abc.h"
13
14namespace ndcurves {
19template <typename Time = double, typename Numeric = Time, bool Safe = false,
20 typename Point = Eigen::Matrix<Numeric, Eigen::Dynamic, 1>,
21 typename Point_derivate = Point>
23 : public curve_abc<Time, Numeric, Safe, Point, Point_derivate> {
24 typedef Point point_t;
26 typedef Time time_t;
27 typedef Numeric num_t;
32 curve_abc_t; // parent class
33
34 /* Constructors - destructors */
35 public:
39 constant_curve() : T_min_(0), T_max_(0), dim_(0) {}
40
46 constant_curve(const Point& value, const time_t T_min = 0.,
47 const time_t T_max = std::numeric_limits<time_t>::max())
48 : value_(value), T_min_(T_min), T_max_(T_max), dim_(value.size()) {
49 if (Safe && T_min_ > T_max_) {
50 throw std::invalid_argument(
51 "can't create constant curve: min bound is higher than max bound");
52 }
53 }
54
62
64 virtual ~constant_curve() {}
65 /* Constructors - destructors */
66
67 /*Operations*/
71 virtual point_t operator()(const time_t t) const {
72 if (Safe && (t < T_min_ || t > T_max_)) {
73 throw std::invalid_argument(
74 "error in constant curve : time t to evaluate should be in range "
75 "[Tmin, Tmax] of the curve");
76 }
77 return value_;
78 }
79
85 size_t derivate_size;
86 if (point_derivate_t::RowsAtCompileTime == Eigen::Dynamic) {
88 } else {
89 derivate_size = point_derivate_t::RowsAtCompileTime;
90 }
91 point_derivate_t value(point_derivate_t::Zero(derivate_size));
93 }
94
99 virtual curve_derivate_t* compute_derivate_ptr(const std::size_t) const {
101 }
102
108 virtual point_derivate_t derivate(const time_t t, const std::size_t) const {
109 if (Safe && (t < T_min_ || t > T_max_)) {
110 throw std::invalid_argument(
111 "error in constant curve : time t to derivate should be in range "
112 "[Tmin, Tmax] of the curve");
113 }
114 size_t derivate_size;
115 if (point_derivate_t::RowsAtCompileTime == Eigen::Dynamic) {
117 } else {
118 derivate_size = point_derivate_t::RowsAtCompileTime;
119 }
120 return point_derivate_t::Zero(derivate_size);
121 }
122
132 virtual bool isApprox(
133 const constant_curve_t& other,
134 const Numeric prec = Eigen::NumTraits<Numeric>::dummy_precision()) const {
135 return ndcurves::isApprox<num_t>(T_min_, other.min()) &&
137 dim_ == other.dim() && value_.isApprox(other.value_, prec);
138 }
139
140 virtual bool isApprox(
141 const curve_abc_t* other,
142 const Numeric prec = Eigen::NumTraits<Numeric>::dummy_precision()) const {
144 dynamic_cast<const constant_curve_t*>(other);
145 if (other_cast)
146 return isApprox(*other_cast, prec);
147 else
148 return false;
149 }
150
151 virtual bool operator==(const constant_curve_t& other) const {
152 return isApprox(other);
153 }
154
155 virtual bool operator!=(const constant_curve_t& other) const {
156 return !(*this == other);
157 }
158
159 /*Helpers*/
162 std::size_t virtual dim() const { return dim_; }
165 num_t virtual min() const { return T_min_; }
168 num_t virtual max() const { return T_max_; }
171 virtual std::size_t degree() const { return 0; }
172 /*Helpers*/
173
174 /*Attributes*/
175 Point value_;
177 std::size_t dim_; // const
178 /*Attributes*/
179
180 // Serialization of the class
182
183 template <class Archive>
184 void serialize(Archive& ar, const unsigned int version) {
185 if (version) {
186 // Do something depending on version ?
187 }
189 ar& boost::serialization::make_nvp("value", value_);
190 ar& boost::serialization::make_nvp("T_min", T_min_);
191 ar& boost::serialization::make_nvp("T_max", T_max_);
192 ar& boost::serialization::make_nvp("dim", dim_);
193 }
194
195}; // struct constant_curve
196} // namespace ndcurves
197
199 SINGLE_ARG(typename Time, typename Numeric, bool Safe, typename Point,
200 typename Point_derivate),
203
204#endif // _CLASS_CONSTANTCURVE
#define DEFINE_CLASS_TEMPLATE_VERSION(Template, Type)
Definition archive.hpp:27
#define SINGLE_ARG(...)
Definition archive.hpp:23
interface for a Curve of arbitrary dimension.
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:25
Represents a constant_curve curve, always returning the same value and a null derivative.
Definition constant_curve.h:23
Point point_t
Definition constant_curve.h:24
constant_curve< Time, Numeric, Safe, Point, Point_derivate > constant_curve_t
Definition constant_curve.h:29
virtual std::size_t degree() const
Get the degree of the curve.
Definition constant_curve.h:171
void serialize(Archive &ar, const unsigned int version)
Definition constant_curve.h:184
Time time_t
Definition constant_curve.h:26
curve_derivate_t compute_derivate() const
Compute the derived curve at order N. Computes the derivative order N, of bezier curve of parametric...
Definition constant_curve.h:84
constant_curve(const Point &value, const time_t T_min=0., const time_t T_max=std::numeric_limits< time_t >::max())
Constructor..
Definition constant_curve.h:46
constant_curve< Time, Numeric, Safe, Point_derivate > curve_derivate_t
Definition constant_curve.h:30
std::size_t dim_
Definition constant_curve.h:177
constant_curve()
Empty constructor. Curve obtained this way can not perform other class functions.
Definition constant_curve.h:39
virtual bool operator==(const constant_curve_t &other) const
Definition constant_curve.h:151
virtual bool isApprox(const constant_curve_t &other, const Numeric prec=Eigen::NumTraits< Numeric >::dummy_precision()) const
isApprox check if other and *this are approximately equals given a precision threshold Only two curve...
Definition constant_curve.h:132
virtual num_t max() const
Get the maximum time for which the curve is defined.
Definition constant_curve.h:168
virtual std::size_t dim() const
Get dimension of curve.
Definition constant_curve.h:162
curve_abc< Time, Numeric, Safe, point_t, Point_derivate > curve_abc_t
Definition constant_curve.h:32
virtual ~constant_curve()
Destructor.
Definition constant_curve.h:64
Point value_
Definition constant_curve.h:175
Numeric num_t
Definition constant_curve.h:27
constant_curve(const constant_curve_t &other)
Copy constructor.
Definition constant_curve.h:57
virtual curve_derivate_t * compute_derivate_ptr(const std::size_t) const
Compute the derived curve at order N.
Definition constant_curve.h:99
virtual point_derivate_t derivate(const time_t t, const std::size_t) const
Evaluate the derivative of order N of curve at time t.
Definition constant_curve.h:108
virtual point_t operator()(const time_t t) const
Evaluation of the cubic spline at time t.
Definition constant_curve.h:71
virtual bool operator!=(const constant_curve_t &other) const
Definition constant_curve.h:155
friend class boost::serialization::access
Definition constant_curve.h:181
virtual bool isApprox(const curve_abc_t *other, const Numeric prec=Eigen::NumTraits< Numeric >::dummy_precision()) const
Definition constant_curve.h:140
virtual num_t min() const
Get the minimum time for which the curve is defined.
Definition constant_curve.h:165
time_t T_max_
Definition constant_curve.h:176
time_t T_min_
Definition constant_curve.h:176
Point_derivate point_derivate_t
Definition constant_curve.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