Rigid Body Dynamics Library
SmoothSegmentedFunction.h
Go to the documentation of this file.
1#ifndef SMOOTHSEGMENTEDFUNCTION_H_
2#define SMOOTHSEGMENTEDFUNCTION_H_
3/* -------------------------------------------------------------------------- *
4 * OpenSim: SmoothSegmentedFunction.h *
5 * -------------------------------------------------------------------------- *
6 * The OpenSim API is a toolkit for musculoskeletal modeling and simulation. *
7 * See http://opensim.stanford.edu and the NOTICE file for more information. *
8 * OpenSim is developed at Stanford University and supported by the US *
9 * National Institutes of Health (U54 GM072970, R24 HD065690) and by DARPA *
10 * through the Warrior Web program. *
11 * *
12 * Copyright (c) 2005-2012 Stanford University and the Authors *
13 * Author(s): Matthew Millard *
14 * *
15 * Licensed under the Apache License, Version 2.0 (the "License"); you may *
16 * not use this file except in compliance with the License. You may obtain a *
17 * copy of the License at http://www.apache.org/licenses/LICENSE-2.0. *
18 * *
19 * Unless required by applicable law or agreed to in writing, software *
20 * distributed under the License is distributed on an "AS IS" BASIS, *
21 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
22 * See the License for the specific language governing permissions and *
23 * limitations under the License. *
24 * -------------------------------------------------------------------------- */
25/*
26 Update:
27 This is a port of the original code so that it will work with
28 the multibody code RBDL written by Martin Felis.
29
30 Author:
31 Matthew Millard
32
33 Date:
34 Nov 2015
35
36*/
37
38#include "Function.h"
40#include <vector>
41#include <rbdl/rbdl_math.h>
42#include <rbdl/rbdl_config.h>
43
85namespace RigidBodyDynamics {
86 namespace Addons {
87 namespace Geometry{
88
89 class RBDL_ADDON_DLLAPI SmoothSegmentedFunction : public Function_<double>
90 {
91
92
93 public:
94
98
99 //SmoothSegmentedFunction();
149 double x0, double x1,
150 double y0, double y1,
151 double dydx0, double dydx1,
152 const std::string& name);
153
154
197 double x0, double x1,
198 double y0, double y1,
199 double dydx0, double dydx1,
200 const std::string& name);
201
209 void shift(double xShift, double yShift);
210
221 void scale(double xScale, double yScale);
222
223
224
246 double calcValue(double x) const;
247
259 double calcInverseValue( double y,
260 double xGuess) const;
261
286 double calcDerivative(double x, int order) const;
287
288
289
290
291 /*This will return the value of the integral of this objects curve
292 evaluated at x.
293
294 @param x the domain point of interest
295
296 \b aborts \b
297 -If the function does not have a pre-computed integral
298 @return the value of the functions integral evaluated at x
299
300 The integral is approximate, though its errors are small.
301 The integral is computed by numerically integrating the function when
302 the constructor for this class is called (if computeIntegral is true) and
303 then splining the result, thus the regions between the knot points may
304 have some error in them. A very fine mesh of points is used to create the
305 spline so the errors will be small
306
307 <B>Computational Costs</B>
308 \verbatim
309 x in curve domain : ~13 flops
310 x in linear section: ~19 flops
311 \endverbatim
312
313 */
314 //double calcIntegral(double x) const;
315
316 /*
317 Returns a bool that indicates if the integral curve has been computed.
318
319 @return true if the integral of this function is available, false if
320 it has not been computed.
321 */
322 //bool isIntegralAvailable() const;
323
324 /*
325 Returns a bool that indicates if the integral computed is compuated left
326 to right, or right to left.
327
328 @return true if the integral was computed left to right, and false if the
329 integral was computed right to left. Note that the output of
330 this function is only valid if isIntegralAvailable() returns
331 true.
332 */
333 //bool isIntegralComputedLeftToRight() const;
334
340 std::string getName() const;
341
349 void setName(const std::string &name);
350
362
427 void printCurveToCSVFile(const std::string& path,
428 const std::string& fileNameWithoutExtension,
429 double domainMin,
430 double domainMax) const;
431
432
470 double domainMin,
471 double domainMax) const;
472
473
476
477 private:
478
479
482 //Nov 2015: Not needed in the RBDL port.
483 //SimTK::Array_<SimTK::Spline> _arraySplineUX;
487 //SimTK::Spline _splineYintX;
488
491 std::vector<RigidBodyDynamics::Math::VectorNd> _mXVec;
494 std::vector<RigidBodyDynamics::Math::VectorNd> _mYVec;
495
498
500 double _x0;
502 double _x1;
504 double _y0;
506 double _y1;
508 double _dydx0;
510 double _dydx1;
511 /*This is the users */
512 //bool _computeIntegral;
513
514 /*This variable, when true, indicates that the user wants the integral
515 from left to right (x0 to x1). If it is false, the integral from right
516 to left (x1 to x0) is computed*/
517 //bool _intx0x1;
519 std::string _name;
520
525 friend class SmoothSegmentedFunctionFactory;
526
527
528
529
530
544 std::vector<std::string>& colnames,
545 const std::string& path,
546 const std::string& filename) const;
547
556 /*virtual*/
557
563 double calcDerivative(const std::vector<int>& derivComponents,
564 const RigidBodyDynamics::Math::VectorNd& x) const;
565 /*virtual*/
566
584 int getArgumentSize() const; /*virtual*/
585
588 /*virtual*/
590
591
592 };
593
594}
595}
596}
597
598
599
600#endif
SmoothSegmentedFunction(const RigidBodyDynamics::Math::MatrixNd &mX, const RigidBodyDynamics::Math::MatrixNd &mY, double x0, double x1, double y0, double y1, double dydx0, double dydx1, const std::string &name)
void getYControlPoints(RigidBodyDynamics::Math::MatrixNd &mat) const
double calcDerivative(const std::vector< int > &derivComponents, const RigidBodyDynamics::Math::VectorNd &x) const
std::vector< RigidBodyDynamics::Math::VectorNd > _mYVec
void printCurveToCSVFile(const std::string &path, const std::string &fileNameWithoutExtension, double domainMin, double domainMax) const
double calcInverseValue(double y, double xGuess) const
void printMatrixToFile(RigidBodyDynamics::Math::MatrixNd &data, std::vector< std::string > &colnames, const std::string &path, const std::string &filename) const
RigidBodyDynamics::Math::MatrixNd calcSampledCurve(int maxOrder, double domainMin, double domainMax) const
void getXControlPoints(RigidBodyDynamics::Math::MatrixNd &mat) const
void updSmoothSegmentedFunction(const RigidBodyDynamics::Math::MatrixNd &mX, const RigidBodyDynamics::Math::MatrixNd &mY, double x0, double x1, double y0, double y1, double dydx0, double dydx1, const std::string &name)
std::vector< RigidBodyDynamics::Math::VectorNd > _mXVec
double calcValue(const RigidBodyDynamics::Math::VectorNd &x) const
RigidBodyDynamics::Math::VectorNd getCurveDomain() const