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 
14 namespace ndcurves {
18 template <typename Time = double, typename Numeric = Time, bool Safe = false,
19  typename Point = Eigen::Matrix<Numeric, Eigen::Dynamic, 1>, typename Point_derivate = Point>
20 struct constant_curve : public curve_abc<Time, Numeric, Safe, Point, Point_derivate> {
21  typedef Point point_t;
22  typedef Point_derivate point_derivate_t;
23  typedef Time time_t;
24  typedef Numeric num_t;
28 
29  /* Constructors - destructors */
30  public:
33  constant_curve() : T_min_(0), T_max_(0), dim_(0) {}
34 
40  constant_curve(const Point& value, const time_t T_min = 0., const time_t T_max = std::numeric_limits<time_t>::max())
41  : value_(value), T_min_(T_min), T_max_(T_max), dim_(value.size()) {
42  if (Safe && T_min_ > T_max_) {
43  throw std::invalid_argument("can't create constant curve: min bound is higher than max bound");
44  }
45  }
46 
49  constant_curve(const constant_curve_t& other)
50  : value_(other.value_), T_min_(other.T_min_), T_max_(other.T_max_), dim_(other.dim_) {}
51 
53  virtual ~constant_curve() {}
54  /* Constructors - destructors */
55 
56  /*Operations*/
60  virtual point_t operator()(const time_t t) const {
61  if (Safe && (t < T_min_ || t > T_max_)) {
62  throw std::invalid_argument(
63  "error in constant curve : time t to evaluate should be in range [Tmin, Tmax] of the curve");
64  }
65  return value_;
66  }
67 
72  curve_derivate_t compute_derivate() const {
73  size_t derivate_size;
74  if (point_derivate_t::RowsAtCompileTime == Eigen::Dynamic) {
75  derivate_size = dim_;
76  } else {
77  derivate_size = point_derivate_t::RowsAtCompileTime;
78  }
79  point_derivate_t value(point_derivate_t::Zero(derivate_size));
80  return curve_derivate_t(value, T_min_, T_max_);
81  }
82 
86  virtual curve_derivate_t* compute_derivate_ptr(const std::size_t) const {
87  return new curve_derivate_t(compute_derivate());
88  }
89 
94  virtual point_derivate_t derivate(const time_t t, const std::size_t) const {
95  if (Safe && (t < T_min_ || t > T_max_)) {
96  throw std::invalid_argument(
97  "error in constant curve : time t to derivate should be in range [Tmin, Tmax] of the curve");
98  }
99  size_t derivate_size;
100  if (point_derivate_t::RowsAtCompileTime == Eigen::Dynamic) {
101  derivate_size = dim_;
102  } else {
103  derivate_size = point_derivate_t::RowsAtCompileTime;
104  }
105  return point_derivate_t::Zero(derivate_size);
106  }
107 
116  virtual bool isApprox(const constant_curve_t& other,
117  const Numeric prec = Eigen::NumTraits<Numeric>::dummy_precision()) const {
118  return ndcurves::isApprox<num_t>(T_min_, other.min()) && ndcurves::isApprox<num_t>(T_max_, other.max()) &&
119  dim_ == other.dim() && value_.isApprox(other.value_, prec);
120  }
121 
122  virtual bool isApprox(const curve_abc_t* other,
123  const Numeric prec = Eigen::NumTraits<Numeric>::dummy_precision()) const {
124  const constant_curve_t* other_cast = dynamic_cast<const constant_curve_t*>(other);
125  if (other_cast)
126  return isApprox(*other_cast, prec);
127  else
128  return false;
129  }
130 
131  virtual bool operator==(const constant_curve_t& other) const { return isApprox(other); }
132 
133  virtual bool operator!=(const constant_curve_t& other) const { return !(*this == other); }
134 
135  /*Helpers*/
138  std::size_t virtual dim() const { return dim_; }
141  num_t virtual min() const { return T_min_; }
144  num_t virtual max() const { return T_max_; }
147  virtual std::size_t degree() const { return 0; }
148  /*Helpers*/
149 
150  /*Attributes*/
152  time_t T_min_, T_max_; // const
153  std::size_t dim_; // const
154  /*Attributes*/
155 
156  // Serialization of the class
158 
159  template <class Archive>
160  void serialize(Archive& ar, const unsigned int version) {
161  if (version) {
162  // Do something depending on version ?
163  }
164  ar& BOOST_SERIALIZATION_BASE_OBJECT_NVP(curve_abc_t);
165  ar& boost::serialization::make_nvp("value", value_);
166  ar& boost::serialization::make_nvp("T_min", T_min_);
167  ar& boost::serialization::make_nvp("T_max", T_max_);
168  ar& boost::serialization::make_nvp("dim", dim_);
169  }
170 
171 }; // struct constant_curve
172 } // namespace ndcurves
173 
174 DEFINE_CLASS_TEMPLATE_VERSION(SINGLE_ARG(typename Time, typename Numeric, bool Safe, typename Point,
175  typename Point_derivate),
177 
178 #endif // _CLASS_CONSTANTCURVE
Numeric num_t
Definition: constant_curve.h:24
std::size_t dim_
Definition: constant_curve.h:153
constant_curve< Time, Numeric, Safe, Point_derivate > curve_derivate_t
Definition: constant_curve.h:26
Definition: bernstein.h:20
void serialize(Archive &ar, const unsigned int version)
Definition: constant_curve.h:160
virtual num_t max() const
Get the maximum time for which the curve is defined.
Definition: constant_curve.h:144
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 treshold Only two curves...
Definition: constant_curve.h:116
friend class boost::serialization::access
Definition: constant_curve.h:157
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:40
virtual std::size_t dim() const
Get dimension of curve.
Definition: constant_curve.h:138
Point_derivate point_derivate_t
Definition: constant_curve.h:22
time_t T_max_
Definition: constant_curve.h:152
virtual ~constant_curve()
Destructor.
Definition: constant_curve.h:53
interface for a Curve of arbitrary dimension.
constant_curve(const constant_curve_t &other)
Copy constructor.
Definition: constant_curve.h:49
Point point_t
Definition: constant_curve.h:21
constant_curve< Time, Numeric, Safe, Point, Point_derivate > constant_curve_t
Definition: constant_curve.h:25
virtual num_t min() const
Get the minimum time for which the curve is defined.
Definition: constant_curve.h:141
double Time
Definition: effector_spline.h:27
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:94
virtual bool operator==(const constant_curve_t &other) const
Definition: constant_curve.h:131
virtual bool operator!=(const constant_curve_t &other) const
Definition: constant_curve.h:133
time_t T_min_
Definition: constant_curve.h:152
Time time_t
Definition: constant_curve.h:23
Eigen::Matrix< Numeric, Eigen::Dynamic, 1 > Point
Definition: effector_spline.h:28
double Numeric
Definition: effector_spline.h:26
virtual curve_derivate_t * compute_derivate_ptr(const std::size_t) const
Compute the derived curve at order N.
Definition: constant_curve.h:86
virtual bool isApprox(const curve_abc_t *other, const Numeric prec=Eigen::NumTraits< Numeric >::dummy_precision()) const
Definition: constant_curve.h:122
virtual std::size_t degree() const
Get the degree of the curve.
Definition: constant_curve.h:147
virtual point_t operator()(const time_t t) const
Evaluation of the cubic spline at time t.
Definition: constant_curve.h:60
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:72
constant_curve()
Empty constructor. Curve obtained this way can not perform other class functions. ...
Definition: constant_curve.h:33
curve_abc< Time, Numeric, Safe, point_t, Point_derivate > curve_abc_t
Definition: constant_curve.h:27
Point value_
Definition: constant_curve.h:151
Represents a curve of dimension Dim. If value of parameter Safe is false, no verification is made on ...
Definition: curve_abc.h:34
Represents a constant_curve curve, always returning the same value and a null derivative.
Definition: constant_curve.h:20