1 #ifndef _ForceReporter_h_
2 #define _ForceReporter_h_
3 /* -------------------------------------------------------------------------- *
4  *                         OpenSim:  ForceReporter.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): Ayman Habib                                                     *
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 
27 //=============================================================================
28 // INCLUDES
29 //=============================================================================
30 #include <OpenSim/Simulation/Model/Analysis.h>
31 #include "osimAnalysesDLL.h"
32 
33 #ifdef SWIG
34     #ifdef OSIMANALYSES_API
35         #undef OSIMANALYSES_API
36         #define OSIMANALYSES_API
37     #endif
38 #endif
39 //=============================================================================
40 //=============================================================================
41 namespace OpenSim {
42 
43 /**
44  * A class for recording the Forces applied to a model
45  * during a simulation.
46  *
47  * @author Ayman Habib
48  * @version 1.0
49  */
50 class OSIMANALYSES_API ForceReporter : public Analysis {
51 OpenSim_DECLARE_CONCRETE_OBJECT(ForceReporter, Analysis);
52 
53 //=============================================================================
54 // DATA
55 //=============================================================================
56 private:
57 
58 protected:
59 
60     /** Include constraint forces? */
61     PropertyBool _includeConstraintForcesProp;
62     bool &_includeConstraintForces;
63 
64     /** Force storage. */
65     Storage _forceStore;
66 
67 //=============================================================================
68 // METHODS
69 //=============================================================================
70 public:
71     ForceReporter(Model *aModel=0);
72     ForceReporter(const std::string &aFileName);
73     // Copy constructor and virtual copy
74     ForceReporter(const ForceReporter &aObject);
75     virtual ~ForceReporter();
76 
77 private:
78     void setNull();
79     void constructDescription();
80     void constructColumnLabels(const SimTK::State& s);
81     void allocateStorage();
82     void deleteStorage();
83     void tidyForceNames();
84 
85 public:
86     //--------------------------------------------------------------------------
87     // OPERATORS
88     //--------------------------------------------------------------------------
89 #ifndef SWIG
90     ForceReporter& operator=(const ForceReporter &aActuation);
91 #endif
92     //--------------------------------------------------------------------------
93     // GET AND SET
94     //--------------------------------------------------------------------------
95     // STORAGE
getForceStorage()96     const Storage& getForceStorage() const
97     {
98         return _forceStore;
99     };
updForceStorage()100     Storage& updForceStorage()
101     {
102         return _forceStore;
103     }
104 
105     /** Get forces table.                                                     */
getForcesTable()106     TimeSeriesTable getForcesTable() const {
107         return _forceStore.exportToTable();
108     }
109 
110     // MODEL
111     void setModel(Model& aModel) override;
112 
113     //--------------------------------------------------------------------------
114     // ANALYSIS
115     //--------------------------------------------------------------------------
includeConstraintForces(bool flag)116     void includeConstraintForces(bool flag) {_includeConstraintForces = flag;}
117 
118     int begin(const SimTK::State& s ) override;
119     int step(const SimTK::State& s, int setNumber ) override;
120     int end(const SimTK::State& s ) override;
121 
122 protected:
123     virtual int
124         record(const SimTK::State& s );
125 
126     //--------------------------------------------------------------------------
127     // IO
128     //--------------------------------------------------------------------------
129 public:
130     int
131         printResults(const std::string &aBaseName,const std::string &aDir="",
132         double aDT=-1.0,const std::string &aExtension=".sto") override;
133 
134 //=============================================================================
135 };  // END of class ForceReporter
136 
137 }; //namespace
138 //=============================================================================
139 //=============================================================================
140 
141 
142 #endif // #ifndef __ForceReporter_h__
143