1 /* -------------------------------------------------------------------------- *
2 * OpenSim: StepFunction.cpp *
3 * -------------------------------------------------------------------------- *
4 * The OpenSim API is a toolkit for musculoskeletal modeling and simulation. *
5 * See http://opensim.stanford.edu and the NOTICE file for more information. *
6 * OpenSim is developed at Stanford University and supported by the US *
7 * National Institutes of Health (U54 GM072970, R24 HD065690) and by DARPA *
8 * through the Warrior Web program. *
9 * *
10 * Copyright (c) 2005-2017 Stanford University and the Authors *
11 * Author(s): Ajay Seth *
12 * *
13 * Licensed under the Apache License, Version 2.0 (the "License"); you may *
14 * not use this file except in compliance with the License. You may obtain a *
15 * copy of the License at http://www.apache.org/licenses/LICENSE-2.0. *
16 * *
17 * Unless required by applicable law or agreed to in writing, software *
18 * distributed under the License is distributed on an "AS IS" BASIS, *
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
20 * See the License for the specific language governing permissions and *
21 * limitations under the License. *
22 * -------------------------------------------------------------------------- */
23
24 //=============================================================================
25 // INCLUDES
26 //=============================================================================
27 #include "StepFunction.h"
28
29 //=============================================================================
30 // STATICS
31 //=============================================================================
32 using namespace std;
33 using namespace OpenSim;
34
35 //=============================================================================
36 // DESTRUCTOR AND CONSTRUCTORS
37 //=============================================================================
38 //_____________________________________________________________________________
39 /**
40 * Destructor.
41 */
~StepFunction()42 StepFunction::~StepFunction()
43 {
44 }
45
46 //_____________________________________________________________________________
47 /**
48 * Default constructor.
49 */
StepFunction()50 StepFunction::StepFunction() :
51 _startTime(_startTimeProp.getValueDbl()),
52 _endTime(_endTimeProp.getValueDbl()),
53 _startValue(_startValueProp.getValueDbl()),
54 _endValue(_endValueProp.getValueDbl())
55
56 {
57 setNull();
58 setupProperties();
59 }
60
61 //_____________________________________________________________________________
62 /**
63 */
StepFunction(double startTime,double endTime,double startValue,double endValue)64 StepFunction::StepFunction(double startTime, double endTime, double startValue, double endValue) :
65 _startTime(_startTimeProp.getValueDbl()),
66 _endTime(_endTimeProp.getValueDbl()),
67 _startValue(_startValueProp.getValueDbl()),
68 _endValue(_endValueProp.getValueDbl())
69
70 {
71 setNull();
72 setupProperties();
73
74 setStartTime(startTime);
75 setEndTime(endTime);
76 setStartValue(startValue);
77 setEndValue(endValue);
78 }
79
80 //_____________________________________________________________________________
81 /**
82 * Copy constructor.
83 * All data members of the specified StepFunction are copied.
84 *
85 * @param aStepFunction StepFunction object to be copied.
86 */
StepFunction(const StepFunction & aStepFunction)87 StepFunction::StepFunction(const StepFunction &aStepFunction) :
88 _startTime(_startTimeProp.getValueDbl()),
89 _endTime(_endTimeProp.getValueDbl()),
90 _startValue(_startValueProp.getValueDbl()),
91 _endValue(_endValueProp.getValueDbl())
92
93 {
94 setNull();
95 setupProperties();
96 copyData(aStepFunction);
97 }
98
99 //=============================================================================
100 // CONSTRUCTION METHODS
101 //=============================================================================
102 //_____________________________________________________________________________
103 /**
104 * Set all member variables to their NULL or default values.
105 */
setNull()106 void StepFunction::setNull()
107 {
108 setAuthors("Ajay Seth");
109 }
110
111 //_____________________________________________________________________________
112 /**
113 * Set up the serialized member variables. This involves both generating
114 * the properties and connecting them to the local pointers used to access
115 * the serialized member variables.
116 */
setupProperties()117 void StepFunction::setupProperties()
118 {
119 _startTimeProp.setName("transition_start_time");
120 _startTimeProp.setValue(0.99);
121 _propertySet.append(&_startTimeProp);
122
123 _endTimeProp.setName("transition_end_time");
124 _endTimeProp.setValue(1.01);
125 _propertySet.append(&_endTimeProp);
126
127 _startValueProp.setName("start_value");
128 _startValueProp.setValue(0.0);
129 _propertySet.append(&_startValueProp);
130
131 _endValueProp.setName("end_value");
132 _endValueProp.setValue(1.0);
133 _propertySet.append(&_endValueProp);
134
135 }
136
137 //_____________________________________________________________________________
138 /**
139 * Set all member variables equal to the members of another object.
140 * Note that this method is private. It is only meant for copying the data
141 * members defined in this class. It does not, for example, make any changes
142 * to data members of base classes.
143 *
144 * @param aStepFunction StepFunction to be copied.
145 */
copyData(const StepFunction & aStepFunction)146 void StepFunction::copyData(const StepFunction &aStepFunction)
147 {
148 setStartTime(aStepFunction._startTime);
149 setEndTime(aStepFunction._endTime);
150 setStartValue(aStepFunction._startValue);
151 setEndValue(aStepFunction._endValue);
152 resetFunction();
153 }
154
155 //=============================================================================
156 // OPERATORS
157 //=============================================================================
158 //_____________________________________________________________________________
159 /**
160 * Assignment operator.
161 * Note that data members of the base class are also assigned.
162 *
163 * @param aStepFunction StepFunction to be copied.
164 * @return Reference to this object.
165 */
operator =(const StepFunction & aStepFunction)166 StepFunction& StepFunction::operator=(const StepFunction &aStepFunction)
167 {
168 // BASE CLASS
169 Function::operator=(aStepFunction);
170
171 // DATA
172 copyData(aStepFunction);
173
174 return(*this);
175 }
176
177
178 //=============================================================================
179 // UTILITY
180 //=============================================================================
createSimTKFunction() const181 SimTK::Function* StepFunction::createSimTKFunction() const
182 {
183 return new SimTK::Function::Step(_startValue, _endValue, _startTime, _endTime);
184 }
185