Skip to content

Commit 60d0e39

Browse files
author
Dimitar Stanev
committed
fix a bug when testing the tool
1. when getting constant reference from OpenSim make sure to specify (e.g., const auto& something = opensim.getSomething()) 2. fix bug in print_muscle_attachments setting
1 parent 3b23ad5 commit 60d0e39

4 files changed

Lines changed: 65 additions & 67 deletions

File tree

CPP/MuscleForceDirection/MuscleForceDirection.cpp

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ MuscleForceDirection::MuscleForceDirection(
7575
// CLONE CONSTRUCTOR
7676
Object* MuscleForceDirection::copy() const {
7777
MuscleForceDirection* object = new MuscleForceDirection(*this);
78-
return (object);
78+
return object;
7979
}
8080

8181
//============ OPERATORS ============
@@ -93,7 +93,7 @@ MuscleForceDirection& MuscleForceDirection::operator=(
9393
_bodyNames = aMuscleForceDirection._bodyNames;
9494
_effectInsertion = aMuscleForceDirection._effectInsertion;
9595

96-
return (*this);
96+
return *this;
9797
}
9898

9999
// setNull()
@@ -130,7 +130,7 @@ void MuscleForceDirection::setupProperties() {
130130
"directions are desired at the effective muscle attachments.");
131131
_propertySet.append(&_boolEffectiveInsertionsProp);
132132

133-
_boolPrintAttachPointProp.setName("print_attachments");
133+
_boolPrintAttachPointProp.setName("print_muscle_attachments");
134134
_boolPrintAttachPointProp.setComment(
135135
"Flag (true or false)specifying whether a storage file with the "
136136
"position of the muscle attachments will be printed.");
@@ -197,7 +197,7 @@ void MuscleForceDirection::constructDescriptionAttachments() {
197197
// constructColumnLabels() for the output results
198198
void MuscleForceDirection::constructColumnLabels() {
199199
if (_model == NULL) return;
200-
const Set<Muscle> muscleSet = _model->getMuscles();
200+
const auto& muscleSet = _model->getMuscles();
201201

202202
// Get the indexes of the muscles attached to the specified bodies.
203203
_muscleIndices = getMusclesIndexForBody(_model, _bodyNames);
@@ -210,7 +210,7 @@ void MuscleForceDirection::constructColumnLabels() {
210210
if (!_expressInLocalFrame) {
211211
// get ground body name
212212
auto groundbody = _model->getGround();
213-
std::string GroundName = groundbody.getName();
213+
auto GroundName = groundbody.getName();
214214

215215
// creates labels for muscles in global reference frame
216216
for (int i = 0; i < _muscleIndices.getSize(); i++) {
@@ -229,7 +229,7 @@ void MuscleForceDirection::constructColumnLabels() {
229229
for (int i = 0; i < _muscleIndices.getSize(); i++) {
230230
j = _muscleIndices[i];
231231

232-
const PathPointSet& pathpointSet =
232+
const auto& pathpointSet =
233233
muscleSet[j].getGeometryPath().getPathPointSet();
234234
int SetLast = pathpointSet.getSize() - 1;
235235

@@ -300,14 +300,14 @@ void MuscleForceDirection::setModel(Model& aModel) {
300300
// RECORD: THE CORE OF THE ANALYSIS
301301
int MuscleForceDirection::record(const SimTK::State& s) {
302302
// Muscles
303-
const BodySet& bodySet = _model->getBodySet();
304-
const Set<Muscle>& muscleSet = _model->getMuscles();
303+
const auto& bodySet = _model->getBodySet();
304+
const auto& muscleSet = _model->getMuscles();
305305

306306
// the analysis to be performed is defined within the for loop.
307307
for (int i = 0; i < _muscleIndices.getSize(); i++) {
308308
// Extract the path of selected muscle
309-
Muscle& muscle = muscleSet.get(_muscleIndices[i]);
310-
const GeometryPath& path = muscle.getGeometryPath();
309+
const auto& muscle = muscleSet.get(_muscleIndices[i]);
310+
const auto& path = muscle.getGeometryPath();
311311

312312
/* ----------NOTE-------------------------------------------
313313
GetCurrentPath doesn't work as well as PointForceDirection.
@@ -420,7 +420,7 @@ int MuscleForceDirection::record(const SimTK::State& s) {
420420
for (int k = 0; k < PFDs.getSize(); k++) { delete PFDs[k]; }
421421
}
422422

423-
return (0);
423+
return 0;
424424
}
425425

426426
// BEGIN
@@ -437,7 +437,7 @@ int MuscleForceDirection::begin(SimTK::State& s) {
437437
int status = 0;
438438
if (_storeDir.getSize() <= 0) { status = record(s); }
439439

440-
return (status);
440+
return status;
441441
}
442442
// STEP
443443

@@ -446,7 +446,7 @@ int MuscleForceDirection::step(const SimTK::State& s, int stepNumber) {
446446

447447
record(s);
448448

449-
return (0);
449+
return 0;
450450
}
451451

452452
// END
@@ -455,7 +455,7 @@ int MuscleForceDirection::end(SimTK::State& s) {
455455

456456
record(s);
457457

458-
return (0);
458+
return 0;
459459
}
460460

461461
// Print results.
@@ -485,7 +485,7 @@ int MuscleForceDirection::printResults(const string& aBaseName,
485485
aDT, aExtension);
486486
}
487487

488-
return (0);
488+
return 0;
489489
}
490490

491491
// UTILITIES Utilities implemented by Luca Modenese (check on 15th March 2012).
@@ -495,8 +495,8 @@ int MuscleForceDirection::printResults(const string& aBaseName,
495495
bool MuscleForceDirection::isMuscleAttachedToBody(const Muscle& aMuscle,
496496
const string& aBodyName) {
497497
bool Attached = false;
498-
OpenSim::GeometryPath aGeometryPath = aMuscle.getGeometryPath();
499-
OpenSim::PathPointSet aPointSet = aGeometryPath.getPathPointSet();
498+
const auto& aGeometryPath = aMuscle.getGeometryPath();
499+
const auto& aPointSet = aGeometryPath.getPathPointSet();
500500
int FinalPointIndex = aPointSet.getSize() - 1;
501501

502502
/* ---------NOTE--------------------------------------------
@@ -517,7 +517,7 @@ bool MuscleForceDirection::isMuscleAttachedToBody(const Muscle& aMuscle,
517517
Array<int> MuscleForceDirection::getMusclesIndexForBody(
518518
Model* model, const Array<std::string>& bodyNames) {
519519
// Entire muscleset
520-
const Set<Muscle> muscles = model->getMuscles();
520+
const auto& muscles = model->getMuscles();
521521
Array<int> musclesIndexForBody;
522522

523523
// CASE 1: the 'all' flag is considered: all muscles will be analyzed.
@@ -532,10 +532,10 @@ Array<int> MuscleForceDirection::getMusclesIndexForBody(
532532
else {
533533
int k = 0, n = 0;
534534

535-
OpenSim::Array<int> MusclesIndexForBody_temp;
536-
// OpenSim::Set<OpenSim::Muscle> muscles = _model->getMuscles();
535+
Array<int> MusclesIndexForBody_temp;
536+
// Set<Muscle> muscles = _model->getMuscles();
537537
for (int n_body = 0; n_body < bodyNames.getSize(); ++n_body) {
538-
std::string aBodyName = bodyNames.get(n_body);
538+
auto aBodyName = bodyNames.get(n_body);
539539

540540
/*----------------NOTE----------------------------------------------
541541
Here an array of indexes MusclesIndexForBody_temp is created
@@ -599,7 +599,7 @@ void MuscleForceDirection::getEffectiveAttachments(
599599
--------------------------------------------*/
600600

601601
const auto& InitialBody = aPFDs[0]->frame();
602-
std::string InitialBodyName = InitialBody.getName();
602+
auto InitialBodyName = InitialBody.getName();
603603
// int effecInsertProx;
604604
for (int n = 0; n < N_points; n++) {
605605
const auto& FollowBody = aPFDs[n]->frame();
@@ -615,7 +615,7 @@ void MuscleForceDirection::getEffectiveAttachments(
615615
is found. The previous point is the effective insertion.
616616
--------------------------------------------*/
617617
const auto& FinalBody = aPFDs[N_points - 1]->frame();
618-
std::string FinalBodyName = FinalBody.getName();
618+
auto FinalBodyName = FinalBody.getName();
619619
for (int n = N_points - 1; n >= 0; n--) {
620620
const auto& PreviousBody = aPFDs[n]->frame();
621621
if (FinalBodyName != PreviousBody.getName()) {
@@ -626,8 +626,8 @@ void MuscleForceDirection::getEffectiveAttachments(
626626
}
627627

628628
// NormalizeVec3 is an inline function to calculate the norm of a vector Vec3.
629-
inline void MuscleForceDirection::NormalizeVec3(SimTK::Vec3& v1,
630-
SimTK::Vec3& rNormv1) {
629+
void MuscleForceDirection::NormalizeVec3(SimTK::Vec3& v1,
630+
SimTK::Vec3& rNormv1) {
631631
double Magnitude =
632632
sqrt(pow(v1[0], 2.0) + pow(v1[1], 2.0) + pow(v1[2], 2.0));
633633
rNormv1 = v1 / Magnitude;

CPP/MuscleForceDirection/MuscleForceDirection.h

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ namespace OpenSim {
1919

2020
class Model;
2121

22-
class OSIMPLUGIN_API MuscleForceDirection : public Analysis
23-
24-
{
22+
class OSIMPLUGIN_API MuscleForceDirection : public Analysis {
2523
OpenSim_DECLARE_CONCRETE_OBJECT(MuscleForceDirection, Analysis);
2624

2725
protected:
@@ -75,9 +73,9 @@ class OSIMPLUGIN_API MuscleForceDirection : public Analysis
7573
// COPY CONSTRUCTOR
7674
MuscleForceDirection(const MuscleForceDirection& aObject);
7775
// DESTRUCTOR
78-
virtual ~MuscleForceDirection();
76+
~MuscleForceDirection();
7977
// CLONE
80-
virtual Object* copy() const;
78+
Object* copy() const;
8179

8280
private:
8381
// ZERO DATA AND NULL POINTERS
@@ -94,15 +92,15 @@ class OSIMPLUGIN_API MuscleForceDirection : public Analysis
9492
#endif
9593

9694
//========================== Required Methods =============================
97-
virtual void setModel(Model& aModel);
95+
void setModel(Model& aModel) override;
9896
// INTEGRATION
99-
virtual int begin(SimTK::State& s);
100-
virtual int step(const SimTK::State& s, int stepNumber);
101-
virtual int end(SimTK::State& s);
97+
int begin(SimTK::State& s);
98+
int step(const SimTK::State& s, int stepNumber) override;
99+
int end(SimTK::State& s);
102100
// IO
103-
virtual int printResults(const std::string& aBaseName,
104-
const std::string& aDir = "", double aDT = -1.0,
105-
const std::string& aExtension = ".sto");
101+
int printResults(const std::string& aBaseName, const std::string& aDir = "",
102+
double aDT = -1.0,
103+
const std::string& aExtension = ".sto") override;
106104

107105
protected:
108106
//========================== Internal Methods =============================
@@ -121,8 +119,7 @@ class OSIMPLUGIN_API MuscleForceDirection : public Analysis
121119
static void
122120
getEffectiveAttachments(const Array<PointForceDirection*>& aPFDs,
123121
int& effecInsertProx, int& effecInsertDist);
124-
inline void NormalizeVec3(SimTK::Vec3& v1, SimTK::Vec3& rNormv1);
125-
122+
void NormalizeVec3(SimTK::Vec3& v1, SimTK::Vec3& rNormv1);
126123
}; // END of class MuscleForceDirection
127124

128125
}; // namespace OpenSim

CPP/legacy_code/README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
# Overview
2-
Code originally exported from svn repository set up at https://simtk.org/projects/force_direction.
3-
It was rearranged for this repository, which is the one currently supported.
2+
3+
Code originally exported from svn repository set up at
4+
https://simtk.org/projects/force_direction. It was rearranged for
5+
this repository, which is the one currently supported.

tests/Arm26/MySetupFile.xml

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,28 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<OpenSimDocument Version="20302">
3-
<AnalyzeTool name="ArmFlexion">
4-
<model_file> arm26.osim </model_file>
5-
<results_directory> . </results_directory>
6-
<output_precision> 12 </output_precision>
7-
<initial_time> 0.00000000 </initial_time>
8-
<final_time> 1.00000000 </final_time>
9-
<AnalysisSet name="Analyses">
10-
<objects>
11-
<MuscleForceDirection name="MuscleForceDirection">
12-
<on> true </on>
13-
<start_time> 0.00000000 </start_time>
14-
<end_time> 1.00000000 </end_time>
15-
<step_interval> 1 </step_interval>
16-
<in_degrees> true </in_degrees>
17-
<local_ref_system> true </local_ref_system>
18-
<effec_attachments> false </effec_attachments>
19-
<print_muscle_attachments> false </print_muscle_attachments>
20-
<body_names> all </body_names>
21-
</MuscleForceDirection>
22-
</objects>
23-
<groups/>
24-
</AnalysisSet>
25-
<coordinates_file> elbow_flexion.mot </coordinates_file>
26-
<lowpass_cutoff_frequency_for_coordinates> 6.0 </lowpass_cutoff_frequency_for_coordinates>
27-
</AnalyzeTool>
3+
<AnalyzeTool name="ArmFlexion">
4+
<model_file> arm26.osim </model_file>
5+
<results_directory> . </results_directory>
6+
<output_precision> 12 </output_precision>
7+
<initial_time> 0.00000000 </initial_time>
8+
<final_time> 1.00000000 </final_time>
9+
<AnalysisSet name="Analyses">
10+
<objects>
11+
<MuscleForceDirection name="MuscleForceDirection">
12+
<on> true </on>
13+
<start_time> 0.00000000 </start_time>
14+
<end_time> 1.00000000 </end_time>
15+
<step_interval> 1 </step_interval>
16+
<in_degrees> true </in_degrees>
17+
<local_ref_system> true </local_ref_system>
18+
<effec_attachments> false </effec_attachments>
19+
<print_muscle_attachments> false </print_muscle_attachments>
20+
<body_names> all </body_names>
21+
</MuscleForceDirection>
22+
</objects>
23+
<groups/>
24+
</AnalysisSet>
25+
<coordinates_file> elbow_flexion.mot </coordinates_file>
26+
<lowpass_cutoff_frequency_for_coordinates> 6.0 </lowpass_cutoff_frequency_for_coordinates>
27+
</AnalyzeTool>
2828
</OpenSimDocument>
29-

0 commit comments

Comments
 (0)