codac 1.5.6
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"
15
16namespace codac2
17{
18 template<typename T>
19 class AnalyticTraj : public TrajBase<typename T::Scalar>, public AnalyticFunction<T>
20 {
21 public:
22
23 using Type = T;
24
25 AnalyticTraj(const AnalyticFunction<T>& f, const Interval& tdomain)
26 : TrajBase<typename T::Scalar>(), AnalyticFunction<T>(f), _tdomain(tdomain)
27 {
28 assert_release(f.args().total_size() == 1 && "domain of f must be 1d");
29 }
30
31 virtual Index size() const
32 {
33 return AnalyticFunction<T>::output_size();
34 }
35
36 virtual std::pair<Index,Index> shape() const
37 {
38 return AnalyticFunction<T>::output_shape();
39 }
40
41 virtual bool is_empty() const
42 {
43 return _tdomain.is_empty();
44 }
45
46 virtual Interval tdomain() const
47 {
48 return _tdomain;
49 }
50
51 virtual void truncate_tdomain(const Interval& new_tdomain)
52 {
53 assert_release(this->tdomain().is_superset(new_tdomain));
54 _tdomain &= new_tdomain;
55 }
56
57 virtual typename T::Domain codomain() const
58 {
59 return AnalyticFunction<T>::eval(this->_tdomain);
60 }
61
62 virtual typename T::Scalar operator()(double t) const
63 {
64 if(!this->tdomain().contains(t))
65 return this->nan_value();
66 return AnalyticFunction<T>::real_eval(t);
67 }
68
69 virtual typename T::Domain operator()(const Interval& t) const
70 {
71 if(!this->tdomain().is_superset(t))
72 return typename T::Domain((*this)(tdomain().lb())) // we obtain the output dimension by an evalution...
73 .init(Interval(-oo,oo));
74 return AnalyticFunction<T>::eval(t);
75 }
76
77 AnalyticFunction<T> as_function() const
78 {
79 ScalarVar t;
80 return {{t},
81 AnalyticExprWrapper<T>(
82 std::make_shared<AnalyticOperationExpr<
83 TrajectoryOp<AnalyticTraj<T>>,T,ScalarType>>(*this,t))
84 };
85 }
86
87 protected:
88
89 Interval _tdomain;
90 };
91}