codac 2.0.0
Loading...
Searching...
No Matches
codac2_AnalyticTraj.h
Go to the documentation of this file.
1
9
10#pragma once
11
13#include "codac2_TrajBase.h"
14#include "codac2_SampledTraj.h"
15
16namespace codac2
17{
18 template<typename O, typename S = typename O::Scalar>
19 class AnalyticTraj : public TrajBase<S>, public AnalyticFunction<O>
20 {
21 public:
22
23 AnalyticTraj(const AnalyticFunction<O>& f, const Interval& tdomain)
24 : TrajBase<S>(), AnalyticFunction<O>(f), _tdomain(tdomain)
25 {
26 assert_release(f.args().total_size() == 1 && "domain of f must be 1d");
27 }
28
29 virtual Index size() const
30 {
31 return AnalyticFunction<O>::output_size();
32 }
33
34 virtual std::pair<Index,Index> shape() const
35 {
36 return AnalyticFunction<O>::output_shape();
37 }
38
39 virtual bool is_empty() const
40 {
41 return _tdomain.is_empty();
42 }
43
44 virtual Interval tdomain() const
45 {
46 return _tdomain;
47 }
48
49 virtual void truncate_tdomain(const Interval& new_tdomain)
50 {
51 assert_release(this->tdomain().is_superset(new_tdomain));
52 _tdomain &= new_tdomain;
53 }
54
55 virtual typename Wrapper<S>::Domain codomain() const
56 {
57 return AnalyticFunction<O>::eval(this->_tdomain);
58 }
59
60 virtual S operator()(double t) const
61 {
62 if(!this->tdomain().contains(t))
63 return this->nan_value();
64 return AnalyticFunction<O>::real_eval(t);
65 }
66
67 virtual typename Wrapper<S>::Domain operator()(const Interval& t) const
68 {
69 if(!this->tdomain().is_superset(t))
70 return typename Wrapper<S>::Domain((*this)(tdomain().lb())) // we obtain the output dimension by an evalution...
71 .init(Interval(-oo,oo));
72 return AnalyticFunction<O>::eval(t);
73 }
74
75 protected:
76
77 Interval _tdomain;
78 };
79}