1 #ifndef __XYFunctionInterfaceInterface_h__ 2 #define __XYFunctionInterfaceInterface_h__ 3 /* -------------------------------------------------------------------------- * 4 * OpenSim: XYFunctionInterface.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-2017 Stanford University and the Authors * 13 * Author(s): Peter Loan * 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 #include <OpenSim/Common/osimCommonDLL.h> 27 #include <OpenSim/Common/Array.h> 28 #include <OpenSim/Common/Object.h> 29 30 31 32 namespace OpenSim { 33 34 class Constant; 35 class Function; 36 class GCVSpline; 37 class LinearFunction; 38 class PiecewiseConstantFunction; 39 class PiecewiseLinearFunction; 40 class SimmSpline; 41 class StepFunction; 42 43 #ifdef SWIG 44 #ifdef OSIMCOMMON_API 45 #undef OSIMCOMMON_API 46 #define OSIMCOMMON_API 47 #endif 48 #endif 49 50 // Excluding this from Doxygen until it has better documentation! -Sam Hamner 51 /// @cond 52 53 #if 1 54 class XYPoint { 55 public: 56 double _x; 57 double _y; XYPoint()58 XYPoint() { _x = _y = 0.0; } XYPoint(double aX,double aY)59 XYPoint(double aX, double aY) { _x = aX; _y = aY; } 60 61 #ifndef SWIG 62 bool operator==(const XYPoint &aXYPoint) const { return false; } 63 bool operator<(const XYPoint &aXYPoint) const { return false; } 64 #endif 65 66 }; 67 #endif 68 69 class OSIMCOMMON_API XYFunctionInterface : public Object { 70 OpenSim_DECLARE_CONCRETE_OBJECT(XYFunctionInterface, Object); 71 72 public: 73 enum FunctionType 74 { 75 typeConstant, 76 typeStepFunction, 77 typePiecewiseConstantFunction, 78 typePiecewiseLinearFunction, 79 typeLinearFunction, 80 typeNatCubicSpline, 81 typeGCVSpline, 82 typeUndefined 83 }; 84 85 //============================================================================= 86 // DATA 87 //============================================================================= 88 89 private: 90 FunctionType _functionType; 91 92 Constant* _constant; 93 StepFunction* _stepFunction; 94 PiecewiseLinearFunction* _piecewiseLinearFunction; 95 LinearFunction* _linearFunction; 96 SimmSpline* _natCubicSpline; 97 GCVSpline* _gcvSpline; 98 PiecewiseConstantFunction* _mStepFunction; 99 Function* _genericFunction; 100 101 double _scaleFactor; // = 1.0 unless function is a MultiplierFunction 102 103 104 public: 105 static bool isXYFunction(Function* f); 106 XYFunctionInterface(Function* f); 107 108 bool isSpecifiedByControlPoints() const; // Flag to indicate whether function can be edited by changing control points 109 110 int getNumberOfPoints() const; 111 const double* getXValues() const; 112 const double* getYValues() const; 113 double getX(int aIndex) const; 114 double getY(int aIndex) const; 115 void setX(int aIndex, double aValue); 116 void setY(int aIndex, double aValue); 117 bool deletePoint(int aIndex); 118 bool deletePoints(const Array<int>& indices); 119 int addPoint(double aX, double aY); 120 Array<XYPoint>* renderAsLineSegments(int aIndex); deleteXYPointArray(Array<XYPoint> * aArray)121 static void deleteXYPointArray(Array<XYPoint>* aArray) { if (aArray) delete aArray; } getFunctionType()122 FunctionType getFunctionType() const { return _functionType; } getScale()123 double getScale() const { return _scaleFactor; } 124 // Utility methods for getting the function as each of the supported types getConstant()125 Constant* getConstant() const { return _constant; } getStepFunction()126 StepFunction* getStepFunction() const { return _stepFunction; } getMultiStepFunction()127 PiecewiseConstantFunction* getMultiStepFunction() const { return _mStepFunction; } getPiecewiseLinearFunction()128 PiecewiseLinearFunction* getPiecewiseLinearFunction() const { return _piecewiseLinearFunction; } getLinearFunction()129 LinearFunction* getLinearFunction() const { return _linearFunction; } getSimmSpline()130 SimmSpline* getSimmSpline() const { return _natCubicSpline; } getGCVSpline()131 GCVSpline* getGCVSpline() const { return _gcvSpline; } 132 133 }; // class XYFunctionInterface 134 /// @endcond 135 } // namespace OpenSim 136 137 #endif // __XYFunctionInterface_h__ 138 139