Skip to content

Commit

Permalink
clean up removing constraint opensim code
Browse files Browse the repository at this point in the history
  • Loading branch information
antoinefalisse committed Jul 3, 2024
1 parent beb0c44 commit 737bea8
Showing 1 changed file with 11 additions and 17 deletions.
28 changes: 11 additions & 17 deletions utilsOpenSim.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,32 +171,26 @@ def runIKTool(pathGenericSetupFile, pathScaledModel, pathTRCFile,
model = opensim.Model(pathScaledModel)
# Remove all actuators.
forceSet = model.getForceSet()
i = 0
while i < forceSet.getSize():
forceSet.remove(i)
# Remove all constraints.
forceSet.setSize(0)
# Remove patellofemoral constraints.
constraintSet = model.getConstraintSet()
i = 0
while i < constraintSet.getSize():
constraintSet.remove(i)
patellofemoral_constraints = [
'patellofemoral_knee_angle_r_con', 'patellofemoral_knee_angle_l_con']
for patellofemoral_constraint in patellofemoral_constraints:
i = constraintSet.getIndex(patellofemoral_constraint, 0)
constraintSet.remove(i)
# Remove patella bodies.
bodySet = model.getBodySet()
patella_bodies = ['patella_r', 'patella_l']
for patella in patella_bodies:
for i in range(bodySet.getSize()):
c_body = bodySet.get(i).getName()
if c_body == patella:
bodySet.remove(i)
break
i = bodySet.getIndex(patella, 0)
bodySet.remove(i)
# Remove patellofemoral joints.
jointSet = model.getJointSet()
patellofemoral_joints = ['patellofemoral_r', 'patellofemoral_l']
for patellofemoral in patellofemoral_joints:
for i in range(jointSet.getSize()):
c_joint = jointSet.get(i).getName()
if c_joint == patellofemoral:
jointSet.remove(i)
break
i = jointSet.getIndex(patellofemoral, 0)
jointSet.remove(i)
# Print the model to a new file.
model.finalizeConnections
model.initSystem()
Expand Down

0 comments on commit 737bea8

Please sign in to comment.