param_func.cpp
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 
34 
35 #include <float.h>
36 #include <math.h>
37 
38 using namespace tuw;
39 using namespace std;
40 
41 void ParamFuncs::initBase(const vector<ParamFuncs::ParamFuncsStructure>& _paramFuncsStructure)
42 {
43  paramFuncsStructure_ = _paramFuncsStructure;
44  const size_t funcsSize = _paramFuncsStructure.size();
45  if (funcsSize < 1)
46  {
47  throw "Error in ParamFuncs::checkParamFuncsStructure: initialization with 0 number of functions!";
48  }
49  funcCtrlPt_.resize(funcsSize);
50  for (auto& funcCtrlPtrI : funcCtrlPt_)
51  {
52  funcCtrlPtrI.clear();
53  }
54  func2Arc_.resize(funcsSize);
55  funcEvalReq_.resize(funcsSize);
56  funcCtrlPtArc_.clear();
57  vector<size_t> funcSameArcCtrlPtSize;
58  for (size_t i = 0; i < funcsSize; ++i)
59  {
60  const size_t& funcCtrlPtsSize = _paramFuncsStructure[i].ctrlPtsSize;
61  if (funcCtrlPtsSize < 2)
62  {
63  throw "Error in ParamFuncs::checkParamFuncsStructure: function has less than 2 control points!";
64  }
65 
66  func2Arc_[i] = _paramFuncsStructure[i].ctrlPtsArcRefIdx;
67  if (func2Arc_[i] >= funcCtrlPtArc_.size())
68  {
69  if (func2Arc_[i] == funcCtrlPtArc_.size())
70  {
71  funcCtrlPtArc_.emplace_back(vector<double>(funcCtrlPtsSize - 2, 0));
72  funcSameArcCtrlPtSize.emplace_back(funcCtrlPtsSize);
73  }
74  else
75  {
76  throw "Error in ParamFuncs::init: a ctrlPtsArcRefIdx is not consistent (new Idx not unit incremental)";
77  }
78  }
79  if (funcCtrlPtsSize != funcSameArcCtrlPtSize[func2Arc_[i]])
80  {
81  throw "Error in ParamFuncs::init: inconsistent number of control points for functions with same arc "
82  "parametrization reference";
83  }
84  funcCtrlPt_[i].reserve(funcCtrlPtsSize);
85  funcCtrlPt_[i].emplace_back(FuncCtrlPt(0, funcsArcBegin_));
86  for (size_t j = 1; j < funcCtrlPtsSize - 1; ++j)
87  {
88  funcCtrlPt_[i].emplace_back(FuncCtrlPt(0, funcCtrlPtArc_[func2Arc_[i]][j - 1]));
89  }
90  funcCtrlPt_[i].emplace_back(FuncCtrlPt(0, funcsArcEnd_));
91 
92  funcEvalReq_[i] = _paramFuncsStructure[i].evalReq;
93  }
94 }
95 
96 void ParamFuncs::init(const vector<ParamFuncsStructure>& _paramFuncsStructure)
97 {
98  initBase(_paramFuncsStructure);
99  initImpl();
100 }
101 
103 {
104  using PfCpD = ParamFuncs::CtrlPtDim;
105  initBase(_other.paramFuncsStructure_);
106  for (size_t i = 0; i < funcsArcSize(); ++i)
107  {
108  for (size_t j = 0; j < funcsArcSize(i); ++j)
109  {
110  funcsArc(i, j) = _other.funcsArc(i, j);
111  }
112  }
113  for (size_t i = 0; i < funcsSize(); ++i)
114  {
115  for (size_t j = 0; j < funcCtrlPtSize(i); ++j)
116  {
117  ctrlPtVal(i, j, PfCpD::VAL) = _other.ctrlPtVal(i, j, PfCpD::VAL);
118  }
119  }
120 }
121 
123 {
124  if (this == &_other)
125  {
126  return *this;
127  }
128 
129  using PfCpD = ParamFuncs::CtrlPtDim;
130  init(_other.paramFuncsStructure_);
131  for (size_t i = 0; i < funcsArcSize(); ++i)
132  {
133  for (size_t j = 0; j < funcsArcSize(i); ++j)
134  {
135  funcsArc(i, j) = _other.funcsArc(i, j);
136  }
137  }
138  for (size_t i = 0; i < funcsSize(); ++i)
139  {
140  for (size_t j = 0; j < funcCtrlPtSize(i); ++j)
141  {
142  ctrlPtVal(i, j, PfCpD::VAL) = _other.ctrlPtVal(i, j, PfCpD::VAL);
143  }
144  }
145  return *this;
146 }
147 
148 void ParamFuncs::shiftStartCtrlPt(const double& _dt)
149 {
150  std::vector<std::vector<size_t> > ctrlPtModif(funcsSize(), std::vector<size_t>(0, 0));
151  ctrlPtModif.reserve(10);
152  const double evalArc = funcsArcBegin_ + _dt;
153  setEvalArc(evalArc);
154  for (size_t i = 0; i < funcsSize(); ++i)
155  {
156  for (size_t j = 0; j < funcCtrlPtSize(i); ++j)
157  {
158  if (ctrlPtVal(i, j, CtrlPtDim::ARC) < evalArc)
159  {
160  ctrlPtModif[i].emplace_back(j);
161  }
162  }
163  }
164  for (size_t i = 0; i < ctrlPtModif.size(); ++i)
165  {
166  const double newVal = computeFuncVal(i);
167  for (size_t j = 0; j < ctrlPtModif[i].size(); ++j)
168  {
169  ctrlPtVal(i, j, CtrlPtDim::VAL) = newVal;
170  }
171  }
172  for (size_t k = 0; k < funcsArcSize(); ++k)
173  {
174  for (size_t j = 0; j < funcCtrlPtArc_[k].size(); ++j)
175  {
176  funcCtrlPtArc_[k][j] -= _dt;
177  }
178  }
179  funcsArcEnd_ -= _dt;
180  precompute();
181  setEvalArc(funcsArcBegin_);
182 }
183 
184 size_t ParamFuncs::funcsSize() const
185 {
186  return funcCtrlPt_.size();
187 }
188 size_t ParamFuncs::funcCtrlPtSize(const size_t& _i) const
189 {
190  return funcCtrlPt_[_i].size();
191 }
193 {
194  return funcCtrlPtArc_.size();
195 }
196 
198 {
199  return funcsArcBegin_;
200 }
201 const double& ParamFuncs::funcsArcBegin() const
202 {
203  return funcsArcBegin_;
204 }
206 {
207  return funcsArcEnd_;
208 }
209 const double& ParamFuncs::funcsArcEnd() const
210 {
211  return funcsArcEnd_;
212 }
213 const double& ParamFuncs::funcsArcEval() const
214 {
215  return funcsArcEval_;
216 }
217 
218 size_t ParamFuncs::funcsArcSize(const size_t& _i) const
219 {
220  return funcCtrlPtArc_[_i].size() + 2;
221 }
222 
223 double& ParamFuncs::funcsArc(const size_t& _i, const size_t& _j)
224 {
225  if (_j == 0)
226  {
227  return funcsArcBegin_;
228  }
229  if (_j > funcCtrlPtArc_[_i].size())
230  {
231  return funcsArcEnd_;
232  }
233  return funcCtrlPtArc_[_i][_j - 1];
234 }
235 const double& ParamFuncs::funcsArc(const size_t& _i, const size_t& _j) const
236 {
237  if (_j == 0)
238  {
239  return funcsArcBegin_;
240  }
241  if (_j > funcCtrlPtArc_[_i].size())
242  {
243  return funcsArcEnd_;
244  }
245  return funcCtrlPtArc_[_i][_j - 1];
246 }
247 
248 double& ParamFuncs::ctrlPtVal(const size_t& _funcIdx, const size_t& _funcCtrlPtIdx, const CtrlPtDim& _ctrlPtDim)
249 {
250  switch (_ctrlPtDim)
251  {
252  case CtrlPtDim::VAL:
253  return funcCtrlPt_[_funcIdx][_funcCtrlPtIdx].val;
254  break;
255  case CtrlPtDim::ARC:
256  return funcCtrlPt_[_funcIdx][_funcCtrlPtIdx].arc;
257  break;
258  default:
259  throw "CtrlPtDim unrecognised in function ParamFuncs::ctrlPtVal !";
260  break;
261  }
262 }
263 const double& ParamFuncs::ctrlPtVal(const size_t& _funcIdx, const size_t& _funcCtrlPtIdx,
264  const CtrlPtDim& _ctrlPtDim) const
265 {
266  switch (_ctrlPtDim)
267  {
268  case CtrlPtDim::VAL:
269  return funcCtrlPt_[_funcIdx][_funcCtrlPtIdx].val;
270  break;
271  case CtrlPtDim::ARC:
272  return funcCtrlPt_[_funcIdx][_funcCtrlPtIdx].arc;
273  break;
274  default:
275  throw "CtrlPtDim unrecognised in function ParamFuncs::ctrlPtVal !";
276  break;
277  }
278 }
279 
280 ParamFuncs::FuncCtrlPt& ParamFuncs::ctrlPt(const size_t& _funcIdx, const size_t& _funcCtrlPtIdx)
281 {
282  return funcCtrlPt_[_funcIdx][_funcCtrlPtIdx];
283 }
284 const ParamFuncs::FuncCtrlPt& ParamFuncs::ctrlPt(const size_t& _funcIdx, const size_t& _funcCtrlPtIdx) const
285 {
286  return funcCtrlPt_[_funcIdx][_funcCtrlPtIdx];
287 }
288 
289 // void ParamFuncs::computeS2TLattice ( const double& _arc0, const double& _ds, vector< double >& _tLattice ) {
290 // std::vector<double> sLattice;
291 //
292 // setEvalArc( funcsArcEnd_ , EvalArcGuarantee::AT_END ); double sEnd = computeS();
293 // setEvalArc( fmin(funcsArcEnd_, _arc0) );
294 //
295 // size_t idxBeforeStart = static_cast<int>( computeS() / _ds );
296 //
297 // sLattice.resize( static_cast<int>( sEnd/ _ds ) - idxBeforeStart );
298 // for( size_t i = 0; i < sLattice.size(); ++i ) { sLattice[i] = _ds * ( idxBeforeStart + i + 1 ); }
299 // computeS2TLattice(sLattice, _tLattice);
300 //
301 // setEvalArc(funcsArcBegin_);
302 // }
double & funcsArc(const std::size_t &_i, const std::size_t &_j)
Access to the arc parameter vector at index _i, control point _j.
ParamFuncs()=default
control point value
control point arc parameter
Helper function needed to upgrade c++ 2011.
Definition: utils.h:193
double & funcsArcBegin()
Access to the initial value of the arc parametrization.
Definition: param_func.cpp:197
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
double & funcsArcEnd()
Access to the final value of the arc parametrization.
Definition: param_func.cpp:205
Control point variable.
Definition: param_func.h:115
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
std::size_t funcCtrlPtSize(const std::size_t &_i) const
Number of control points for a parametric function.
Definition: param_func.cpp:188
CtrlPtDim
Control point variable dimension.
Definition: param_func.h:73
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
const double & funcsArcEval() const
Const access to the active evaluation point arc parametrization.
Definition: param_func.cpp:213
void shiftStartCtrlPt(const double &_dt)
Definition: param_func.cpp:148
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