param_func.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Software License Agreement (BSD License) *
3  * Copyright (C) 2016 by Horatiu George Todoran <todorangrg@gmail.com> *
4  * *
5  * Redistribution and use in source and binary forms, with or without *
6  * modification, are permitted provided that the following conditions *
7  * are met: *
8  * *
9  * 1. Redistributions of source code must retain the above copyright *
10  * notice, this list of conditions and the following disclaimer. *
11  * 2. Redistributions in binary form must reproduce the above copyright *
12  * notice, this list of conditions and the following disclaimer in *
13  * the documentation and/or other materials provided with the *
14  * distribution. *
15  * 3. Neither the name of the copyright holder nor the names of its *
16  * contributors may be used to endorse or promote products derived *
17  * from this software without specific prior written permission. *
18  * *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *
21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS *
22  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE *
23  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, *
24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, *
25  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; *
26  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER *
27  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT *
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY *
29  * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE *
30  * POSSIBILITY OF SUCH DAMAGE. *
31  ***************************************************************************/
32 
33 #ifndef PARAM_FUNC_H
34 #define PARAM_FUNC_H
35 
36 #include <memory>
37 #include <vector>
38 #include <map>
39 #include <tuw_control/utils.h>
40 
41 namespace tuw
42 {
52 class ParamFuncs;
53 using ParamFuncsUPtr = std::unique_ptr<ParamFuncs>;
54 using ParamFuncsConstUPtr = std::unique_ptr<ParamFuncs const>;
55 using ParamFuncsSPtr = std::shared_ptr<ParamFuncs>;
56 using ParamFuncsConstSPtr = std::shared_ptr<ParamFuncs const>;
58 {
59  // enums
61 public:
62  enum class FuncEvalMode
63  {
64  DIFF1,
65  DIFF2,
66  INT1,
67  INT2,
68  FUNC,
69  ENUM_SIZE
70  };
72 public:
73  enum class CtrlPtDim
74  {
75  VAL,
76  ARC
77  };
79 public:
80  enum class EvalArcGuarantee
81  {
82  NONE,
83  AFTER_LAST,
84  BEFORE_LAST,
85  AT_BEGIN,
86  AT_END
87  };
88 
91 public:
92  static constexpr const std::size_t nrModesMax_ = asInt(FuncEvalMode::ENUM_SIZE) - 1;
93 
94 public:
95  using FuncEvalModesFlags = std::array<bool, nrModesMax_>;
96 
97  // structs
99 public:
101  {
102  ParamFuncsStructure() : ctrlPtsSize(0), ctrlPtsArcRefIdx(0), evalReq()
103  {
104  evalReq.fill(false);
105  }
106  std::size_t ctrlPtsSize;
107  std::size_t ctrlPtsArcRefIdx;
109  FuncEvalModesFlags evalReq;
112  };
114 protected:
115  struct FuncCtrlPt
116  {
117  FuncCtrlPt(const double& _val, double& _arc) : val(_val), arc(_arc)
118  {
119  }
120  double val;
121  double& arc;
122  };
123 
124  // special class member functions
125 public:
126  ParamFuncs() = default;
127 
128 public:
129  virtual ~ParamFuncs() = default;
130 
131 public:
132  ParamFuncs(const ParamFuncs&); // = default;
133 public:
134  ParamFuncs& operator=(const ParamFuncs&); // = default;
135 public:
136  ParamFuncs(ParamFuncs&&) = delete;
137 
138 public:
139  ParamFuncs& operator=(ParamFuncs&&) = delete;
140 
159 private:
160  void initBase(const std::vector<tuw::ParamFuncs::ParamFuncsStructure>& _paramFuncsStructure);
179 public:
180  void init(const std::vector<tuw::ParamFuncs::ParamFuncsStructure>& _paramFuncsStructure);
182 public:
183  std::size_t funcsSize() const;
185 public:
186  std::size_t funcsArcSize() const;
188 public:
189  std::size_t funcsArcSize(const std::size_t& _i) const;
191 public:
192  std::size_t funcCtrlPtSize(const std::size_t& _i) const;
194 public:
195  double& funcsArcBegin();
197 public:
198  const double& funcsArcBegin() const;
200 public:
201  double& funcsArcEnd();
203 public:
204  const double& funcsArcEnd() const;
206 public:
207  const double& funcsArcEval() const;
209 public:
210  double& funcsArc(const std::size_t& _i, const std::size_t& _j);
212 public:
213  const double& funcsArc(const std::size_t& _i, const std::size_t& _j) const;
215 public:
216  FuncCtrlPt& ctrlPt(const std::size_t& _funcIdx, const std::size_t& _funcCtrlPtIdx);
218 public:
219  const FuncCtrlPt& ctrlPt(const std::size_t& _funcIdx, const std::size_t& _funcCtrlPtIdx) const;
221 public:
222  double& ctrlPtVal(const std::size_t& _funcIdx, const std::size_t& _funcCtrlPtIdx,
223  const CtrlPtDim& _ctrlPtDim = CtrlPtDim::VAL);
225 public:
226  const double& ctrlPtVal(const std::size_t& _funcIdx, const std::size_t& _funcCtrlPtIdx,
227  const CtrlPtDim& _ctrlPtDim = CtrlPtDim::VAL) const;
228 
229 public:
230  void shiftStartCtrlPt(const double& _dt);
231 
233 protected:
234  std::vector<FuncEvalModesFlags> funcEvalReq_;
236 protected:
237  std::vector<std::vector<FuncCtrlPt> > funcCtrlPt_;
239 private:
240  std::vector<std::vector<double> > funcCtrlPtArc_;
242 protected:
243  std::vector<std::size_t> func2Arc_;
245 protected:
248 protected:
249  double funcsArcEnd_;
251 protected:
254 protected:
255  std::vector<ParamFuncsStructure> paramFuncsStructure_;
256 
257  // pure virtual functions
259 protected:
260  virtual void initImpl() = 0;
262 public:
263  virtual void precompute() = 0;
265 public:
266  virtual void setEvalArc(const double& _funcsArcEval,
267  const EvalArcGuarantee& _evalArcGuarantee = EvalArcGuarantee::NONE) = 0;
269 public:
270  virtual double computeFuncVal(const std::size_t& _funcIdx) const = 0;
273 public:
274  virtual double computeFuncDiff1(const std::size_t& _funcIdx) const = 0;
277 public:
278  virtual double computeFuncDiff2(const std::size_t& _funcIdx) const = 0;
281 public:
282  virtual double computeFuncInt1(const std::size_t& _funcIdx) const = 0;
285 public:
286  virtual double computeFuncInt2(const std::size_t& _funcIdx) const = 0;
287 };
288 }
289 
290 #endif // PARAM_FUNC_H
double & funcsArc(const std::size_t &_i, const std::size_t &_j)
Access to the arc parameter vector at index _i, control point _j.
std::shared_ptr< ParamFuncs > ParamFuncsSPtr
Definition: param_func.h:55
ParamFuncs()=default
control point value
std::vector< FuncEvalModesFlags > funcEvalReq_
Flags for required function computation modes.
Definition: param_func.h:234
std::unique_ptr< ParamFuncs > ParamFuncsUPtr
Definition: param_func.h:53
virtual double computeFuncDiff2(const std::size_t &_funcIdx) const =0
Computes 2nd derivative of parametric function with index _funcIdx at parametric arc set by setEvalAr...
control point arc parameter
double funcsArcBegin_
Arc parametrization at the beginning of the functions domain definitions (common for all functions)...
Definition: param_func.h:246
std::shared_ptr< ParamFuncs const > ParamFuncsConstSPtr
Definition: param_func.h:56
std::vector< std::vector< FuncCtrlPt > > funcCtrlPt_
Stores the control points for all the parametrized functions.
Definition: param_func.h:237
double & funcsArcBegin()
Access to the initial value of the arc parametrization.
Definition: param_func.cpp:197
constexpr auto asInt(Enumeration const value) -> typename std::underlying_type< Enumeration >::type
Definition: utils.h:87
double funcsArcEnd_
Arc parametrization at the end of the functions domain definitions (common for all functions)...
Definition: param_func.h:249
std::array< bool, nrModesMax_ > FuncEvalModesFlags
Definition: param_func.h:95
static constexpr const std::size_t nrModesMax_
Maximum number of computation modes (except the parametric function itself FUNC). Currently 4 other c...
Definition: param_func.h:92
virtual double computeFuncDiff1(const std::size_t &_funcIdx) const =0
Computes 1st derivative of parametric function with index _funcIdx at parametric arc set by setEvalAr...
ParamFuncs & operator=(const ParamFuncs &)
Definition: param_func.cpp:122
void initBase(const std::vector< tuw::ParamFuncs::ParamFuncsStructure > &_paramFuncsStructure)
Initializes the control structure for the base class.
Definition: param_func.cpp:41
virtual void initImpl()=0
Called at end of init. To be used by extended classes.
double & funcsArcEnd()
Access to the final value of the arc parametrization.
Definition: param_func.cpp:205
std::vector< std::size_t > func2Arc_
Maps the parametrized functions to their afferent arc parametrizations.
Definition: param_func.h:243
EvalArcGuarantee
Flags if any guarantees about evaluation arc relative to last evaluation arc are present.
Definition: param_func.h:80
Control point variable.
Definition: param_func.h:115
double & arc
control point arc parameter
Definition: param_func.h:121
Containts parametric function initialization data.
Definition: param_func.h:100
FuncCtrlPt(const double &_val, double &_arc)
Definition: param_func.h:117
virtual double computeFuncVal(const std::size_t &_funcIdx) const =0
Computes value of parametric function with index _funcIdx at parametric arc set by setEvalArc...
double & ctrlPtVal(const std::size_t &_funcIdx, const std::size_t &_funcCtrlPtIdx, const CtrlPtDim &_ctrlPtDim=CtrlPtDim::VAL)
Access of a parametric function control point dimension.
std::size_t funcsSize() const
Number of parametric functions.
Definition: param_func.cpp:184
function single integral
std::size_t funcCtrlPtSize(const std::size_t &_i) const
Number of control points for a parametric function.
Definition: param_func.cpp:188
std::vector< std::vector< double > > funcCtrlPtArc_
Stores the control points arc parameters for all the parametrized functions.
Definition: param_func.h:240
CtrlPtDim
Control point variable dimension.
Definition: param_func.h:73
double funcsArcEval_
Arc parametrization at the evaluation point (set by setEvalArc)/.
Definition: param_func.h:252
function second derivative
function first derivative
virtual double computeFuncInt1(const std::size_t &_funcIdx) const =0
Computes integral of parametric function with index _funcIdx on interval [funcsArcBegin_, funcsArcEnd_].
function value (always assumed to have the highest integer value of the enum)
function double integral
virtual double computeFuncInt2(const std::size_t &_funcIdx) const =0
Computes double integral of parametric function with index _funcIdx on interval [funcsArcBegin_, funcsArcEnd_].
FuncEvalMode
Required type of computation relative to the parametric function.
Definition: param_func.h:62
std::size_t funcsArcSize() const
Number of arc parametrizations.
Definition: param_func.cpp:192
void init(const std::vector< tuw::ParamFuncs::ParamFuncsStructure > &_paramFuncsStructure)
Initializes the control structure.
Definition: param_func.cpp:96
std::unique_ptr< ParamFuncs const > ParamFuncsConstUPtr
Definition: param_func.h:54
const double & funcsArcEval() const
Const access to the active evaluation point arc parametrization.
Definition: param_func.cpp:213
virtual void precompute()=0
Precomputes cached data.
virtual ~ParamFuncs()=default
void shiftStartCtrlPt(const double &_dt)
Definition: param_func.cpp:148
double val
control point value
Definition: param_func.h:120
this evaluation arc is at the arc parametrization begin
virtual void setEvalArc(const double &_funcsArcEval, const EvalArcGuarantee &_evalArcGuarantee=EvalArcGuarantee::NONE)=0
Sets parametric function evaluation arc.
this evaluation arc is at the arc parametrization end
std::vector< ParamFuncsStructure > paramFuncsStructure_
Initialization structure "store" variable.
Definition: param_func.h:255
FuncCtrlPt & ctrlPt(const std::size_t &_funcIdx, const std::size_t &_funcCtrlPtIdx)
Access of a parametric function control point.
Storage and manipulation of parametric functions collection.
Definition: param_func.h:57


tuw_control
Author(s): George Todoran
autogenerated on Mon Jun 10 2019 15:27:21