Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
96ed87e
environment requirements file
Feb 18, 2026
f14525f
Example_deform_distal_femur_gait2392.py added
Feb 18, 2026
cfce2a0
added utils funcs
Feb 18, 2026
ae6d82a
updated example
Feb 18, 2026
1925559
example distal tibia Rajagopal
Feb 18, 2026
59a4ab2
example Rajagopal femur
Feb 18, 2026
1e0e4c3
example gait2392 tibia
Feb 18, 2026
42012de
updated read me for python
Feb 18, 2026
554a968
updated readme
Feb 18, 2026
aecf2bd
updated read me
Feb 18, 2026
ee63848
updated readme
Feb 18, 2026
6436841
updated readme
Feb 18, 2026
f79e7e8
Merge pull request #1 from nicos1993/python_version
nicos1993 Feb 18, 2026
a892787
upd readme
Feb 18, 2026
d72cb85
Merge pull request #2 from nicos1993/python_version
nicos1993 Feb 18, 2026
dc2bbd3
testing the decomposition approach
nicos1993 Feb 28, 2026
e23728d
there seems to be a need to subtract the prox joint vert
nicos1993 Feb 28, 2026
2b6487c
added some comments to help; some bad hard coded parts too
nicos1993 Feb 28, 2026
654902b
function to permit rotating about a specific axis with decomposition
nicos1993 Feb 28, 2026
17d849a
applying the new rotation decomposition in ApplyTorsionToJoints
nicos1993 Feb 28, 2026
5543712
I think the CustomJoint/SpatialT part now is problematic...
nicos1993 Feb 28, 2026
7510a17
readded some of the methods for comparison purposes...
nicos1993 Feb 28, 2026
a504e07
fixed the offset to subtract - proxJoint
nicos1993 Mar 1, 2026
2d13f8f
Miller model
nicos1993 Mar 2, 2026
41c9600
model geometry and new rough script to deform
nicos1993 Mar 2, 2026
6e5b8d3
deformed model geometries
nicos1993 Mar 2, 2026
0878eb9
tweaked to enable femur/tibia changes
nicos1993 Mar 2, 2026
90acd5e
just pushing for latest
nicos1993 Mar 2, 2026
936579f
deleting unwanted geo's
nicos1993 Mar 2, 2026
5df8f21
deformed models
nicos1993 Mar 2, 2026
7d8ddb6
frame offset script
nicos1993 Mar 2, 2026
063e161
deleting models as incorrect
nicos1993 Mar 8, 2026
27f41cb
removing wrong models
nicos1993 Mar 8, 2026
9c560db
deleting wrong vtps
nicos1993 Mar 8, 2026
e567cbd
single corrected deformation; offsets are relative to default
nicos1993 Mar 9, 2026
79a0778
angulation stuff
nicos1993 Mar 12, 2026
96b88f9
changes
nicos1993 Mar 12, 2026
49ecbc7
Merge pull request #3 from nicos1993/added_head_offset
nicos1993 Mar 17, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions Example_deform_distal_femur_Rajagopal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# import libraries
import numpy as np
import opensim as osim
import os
import utils.getJointCentresForBone
import utils.createTorsionProfile
import utils.applyTorsionToJoints
import utils.applyTorsionToVTPBoneGeom
import utils.applyTorsionToMuscleAttachments
import utils.applyTorsionToMarkers
import utils.saveDeformedModel

#--------------- MAIN SETTINGS ---------------
# Model to deform
modelFileName = './examples_Rajagopal2015/Rajagopal2015.osim'

# where the bone geometries are stored
OpenSim_Geometry_folder = './examples_Rajagopal2015/Geometry'

# body to deform
bone_to_deform = 'femur_r'

# axis of deformation
torsionAxis = 'y'

# define the rotational profile at the joint centres of the bone of
# interest: TorsionProfilePointsDeg = [ proximalTorsion DistalTorsion ];
TorsionProfilePointsDeg = (40, 0)

# decide if you want to apply torsion to joint as well as other objects.
# E.g. choose no for investigating the effect of femoral anteversion in a
# leg with straight alignment.
# Choose yes for modelling a CP child with deformation of bone resulting in
# joint rotation, meaning the kinematic model is altered.
apply_torsion_to_joints = 'yes'

# where the deformed models will be saved
altered_models_folder = './examples_Rajagopal2015'
#----------------------------------------------

# import model
osimModel = osim.Model(modelFileName)

# compute bone length
Pprox, Pdist, total_L, V = utils.getJointCentresForBone(osimModel, bone_to_deform)

# define length corresponding to torsion points
LengthProfilePoints = np.vstack((Pprox,Pdist))

# compute torsion profile
torsion_angle_func_rad, torsion_doc_string = utils.createTorsionProfile(LengthProfilePoints, TorsionProfilePointsDeg, torsionAxis)

# suffix used for saving geometries
bone_short = bone_to_deform[0:3]+bone_to_deform[-2:]
deformed_model_suffix = ('_Tors'+bone_short[0].upper()+bone_short[1:]+'_'+torsion_doc_string)

# if you want you can apply torsion to joints
if apply_torsion_to_joints == 'yes':
osimModel = utils.applyTorsionToJoints(osimModel, bone_to_deform, torsionAxis, torsion_angle_func_rad)

# deforming muscle attachments
osimModel = utils.applyTorsionToMuscleAttachments(osimModel, bone_to_deform, torsionAxis, torsion_angle_func_rad)

# if there are markers rotate them
osimModel = utils.applyTorsionToMarkers(osimModel, bone_to_deform, torsionAxis, torsion_angle_func_rad)

# deform the bone geometries of the generic model
osimModel = utils.applyTorsionToVTPBoneGeom(osimModel, bone_to_deform, torsionAxis,
torsion_angle_func_rad, torsion_doc_string,
OpenSim_Geometry_folder)

# save output model
if not os.path.exists(altered_models_folder):
os.mkdir(altered_models_folder)

_, name_ext = os.path.split(modelFileName)
name, ext = os.path.splitext(name_ext)
deformed_model_name = name + deformed_model_suffix + ext
output_model_path = os.path.join(altered_models_folder, deformed_model_name)
osimModel.setName(osimModel.getName()+deformed_model_suffix)

# save model
utils.saveDeformedModel(osimModel, output_model_path)
83 changes: 83 additions & 0 deletions Example_deform_distal_femur_gait2392.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# import libraries
import numpy as np
import opensim as osim
import os
import utils.getJointCentresForBone
import utils.createTorsionProfile
import utils.applyTorsionToJoints
import utils.applyTorsionToVTPBoneGeom
import utils.applyTorsionToMuscleAttachments
import utils.applyTorsionToMarkers
import utils.saveDeformedModel

#--------------- MAIN SETTINGS ---------------
# Model to deform
modelFileName = './examples_gait2392/gait2392_simbody.osim'

# where the bone geometries are stored
OpenSim_Geometry_folder = 'C:/OpenSim 4.5/Geometry'

# body to deform
bone_to_deform = 'femur_r'

# axis of deformation
torsionAxis = 'y'

# define the rotational profile at the joint centres of the bone of
# interest: TorsionProfilePointsDeg = [ proximalTorsion DistalTorsion ];
TorsionProfilePointsDeg = (40, 0)

# decide if you want to apply torsion to joint as well as other objects.
# E.g. choose no for investigating the effect of femoral anteversion in a
# leg with straight alignment.
# Choose yes for modelling a CP child with deformation of bone resulting in
# joint rotation, meaning the kinematic model is altered.
apply_torsion_to_joints = 'yes'

# where the deformed models will be saved
altered_models_folder = './examples_gait2392'
#----------------------------------------------

# import model
osimModel = osim.Model(modelFileName)

# compute bone length
Pprox, Pdist, total_L, V = utils.getJointCentresForBone(osimModel, bone_to_deform)

# define length corresponding to torsion points
LengthProfilePoints = np.vstack((Pprox,Pdist))

# compute torsion profile
torsion_angle_func_rad, torsion_doc_string = utils.createTorsionProfile(LengthProfilePoints, TorsionProfilePointsDeg, torsionAxis)

# suffix used for saving geometries
bone_short = bone_to_deform[0:3]+bone_to_deform[-2:]
deformed_model_suffix = ('_Tors'+bone_short[0].upper()+bone_short[1:]+'_'+torsion_doc_string)

# if you want you can apply torsion to joints
if apply_torsion_to_joints == 'yes':
osimModel = utils.applyTorsionToJoints(osimModel, bone_to_deform, torsionAxis, torsion_angle_func_rad)

# deforming muscle attachments
osimModel = utils.applyTorsionToMuscleAttachments(osimModel, bone_to_deform, torsionAxis, torsion_angle_func_rad)

# if there are markers rotate them
osimModel = utils.applyTorsionToMarkers(osimModel, bone_to_deform, torsionAxis, torsion_angle_func_rad)

# deform the bone geometries of the generic model
osimModel = utils.applyTorsionToVTPBoneGeom(osimModel, bone_to_deform, torsionAxis,
torsion_angle_func_rad, torsion_doc_string,
OpenSim_Geometry_folder)

# save output model
if not os.path.exists(altered_models_folder):
os.mkdir(altered_models_folder)

_, name_ext = os.path.split(modelFileName)
name, ext = os.path.splitext(name_ext)
deformed_model_name = name + deformed_model_suffix + ext
output_model_path = os.path.join(altered_models_folder, deformed_model_name)
osimModel.setName(osimModel.getName()+deformed_model_suffix)

# save model
utils.saveDeformedModel(osimModel, output_model_path)
83 changes: 83 additions & 0 deletions Example_deform_distal_tibia_Rajagopal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# import libraries
import numpy as np
import opensim as osim
import os
import utils.getJointCentresForBone
import utils.createTorsionProfile
import utils.applyTorsionToJoints
import utils.applyTorsionToVTPBoneGeom
import utils.applyTorsionToMuscleAttachments
import utils.applyTorsionToMarkers
import utils.saveDeformedModel

#--------------- MAIN SETTINGS ---------------
# Model to deform
modelFileName = './examples_Rajagopal2015/Rajagopal2015.osim'

# where the bone geometries are stored
OpenSim_Geometry_folder = './examples_Rajagopal2015/Geometry'

# body to deform
bone_to_deform = 'tibia_l'

# axis of deformation
torsionAxis = 'y'

# define the rotational profile at the joint centres of the bone of
# interest: TorsionProfilePointsDeg = [ proximalTorsion DistalTorsion ];
TorsionProfilePointsDeg = (0, -30)

# decide if you want to apply torsion to joint as well as other objects.
# E.g. choose no for investigating the effect of femoral anteversion in a
# leg with straight alignment.
# Choose yes for modelling a CP child with deformation of bone resulting in
# joint rotation, meaning the kinematic model is altered.
apply_torsion_to_joints = 'yes'

# where the deformed models will be saved
altered_models_folder = './examples_Rajagopal2015'
#----------------------------------------------

# import model
osimModel = osim.Model(modelFileName)

# compute bone length
Pprox, Pdist, total_L, V = utils.getJointCentresForBone(osimModel, bone_to_deform)

# define length corresponding to torsion points
LengthProfilePoints = np.vstack((Pprox,Pdist))

# compute torsion profile
torsion_angle_func_rad, torsion_doc_string = utils.createTorsionProfile(LengthProfilePoints, TorsionProfilePointsDeg, torsionAxis)

# suffix used for saving geometries
bone_short = bone_to_deform[0:3]+bone_to_deform[-2:]
deformed_model_suffix = ('_Tors'+bone_short[0].upper()+bone_short[1:]+'_'+torsion_doc_string)

# if you want you can apply torsion to joints
if apply_torsion_to_joints == 'yes':
osimModel = utils.applyTorsionToJoints(osimModel, bone_to_deform, torsionAxis, torsion_angle_func_rad)

# deforming muscle attachments
osimModel = utils.applyTorsionToMuscleAttachments(osimModel, bone_to_deform, torsionAxis, torsion_angle_func_rad)

# if there are markers rotate them
osimModel = utils.applyTorsionToMarkers(osimModel, bone_to_deform, torsionAxis, torsion_angle_func_rad)

# deform the bone geometries of the generic model
osimModel = utils.applyTorsionToVTPBoneGeom(osimModel, bone_to_deform, torsionAxis,
torsion_angle_func_rad, torsion_doc_string,
OpenSim_Geometry_folder)

# save output model
if not os.path.exists(altered_models_folder):
os.mkdir(altered_models_folder)

_, name_ext = os.path.split(modelFileName)
name, ext = os.path.splitext(name_ext)
deformed_model_name = name + deformed_model_suffix + ext
output_model_path = os.path.join(altered_models_folder, deformed_model_name)
osimModel.setName(osimModel.getName()+deformed_model_suffix)

# save model
utils.saveDeformedModel(osimModel, output_model_path)
83 changes: 83 additions & 0 deletions Example_deform_distal_tibia_gait2392.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# import libraries
import numpy as np
import opensim as osim
import os
import utils.getJointCentresForBone
import utils.createTorsionProfile
import utils.applyTorsionToJoints
import utils.applyTorsionToVTPBoneGeom
import utils.applyTorsionToMuscleAttachments
import utils.applyTorsionToMarkers
import utils.saveDeformedModel

#--------------- MAIN SETTINGS ---------------
# Model to deform
modelFileName = './examples_gait2392/gait2392_simbody.osim'

# where the bone geometries are stored
OpenSim_Geometry_folder = 'C:/OpenSim 4.5/Geometry'

# body to deform
bone_to_deform = 'tibia_l'

# axis of deformation
torsionAxis = 'y'

# define the rotational profile at the joint centres of the bone of
# interest: TorsionProfilePointsDeg = [ proximalTorsion DistalTorsion ];
TorsionProfilePointsDeg = (0, -30)

# decide if you want to apply torsion to joint as well as other objects.
# E.g. choose no for investigating the effect of femoral anteversion in a
# leg with straight alignment.
# Choose yes for modelling a CP child with deformation of bone resulting in
# joint rotation, meaning the kinematic model is altered.
apply_torsion_to_joints = 'yes'

# where the deformed models will be saved
altered_models_folder = './examples_gait2392'
#----------------------------------------------

# import model
osimModel = osim.Model(modelFileName)

# compute bone length
Pprox, Pdist, total_L, V = utils.getJointCentresForBone(osimModel, bone_to_deform)

# define length corresponding to torsion points
LengthProfilePoints = np.vstack((Pprox,Pdist))

# compute torsion profile
torsion_angle_func_rad, torsion_doc_string = utils.createTorsionProfile(LengthProfilePoints, TorsionProfilePointsDeg, torsionAxis)

# suffix used for saving geometries
bone_short = bone_to_deform[0:3]+bone_to_deform[-2:]
deformed_model_suffix = ('_Tors'+bone_short[0].upper()+bone_short[1:]+'_'+torsion_doc_string)

# if you want you can apply torsion to joints
if apply_torsion_to_joints == 'yes':
osimModel = utils.applyTorsionToJoints(osimModel, bone_to_deform, torsionAxis, torsion_angle_func_rad)

# deforming muscle attachments
osimModel = utils.applyTorsionToMuscleAttachments(osimModel, bone_to_deform, torsionAxis, torsion_angle_func_rad)

# if there are markers rotate them
osimModel = utils.applyTorsionToMarkers(osimModel, bone_to_deform, torsionAxis, torsion_angle_func_rad)

# deform the bone geometries of the generic model
osimModel = utils.applyTorsionToVTPBoneGeom(osimModel, bone_to_deform, torsionAxis,
torsion_angle_func_rad, torsion_doc_string,
OpenSim_Geometry_folder)

# save output model
if not os.path.exists(altered_models_folder):
os.mkdir(altered_models_folder)

_, name_ext = os.path.split(modelFileName)
name, ext = os.path.splitext(name_ext)
deformed_model_name = name + deformed_model_suffix + ext
output_model_path = os.path.join(altered_models_folder, deformed_model_name)
osimModel.setName(osimModel.getName()+deformed_model_suffix)

# save model
utils.saveDeformedModel(osimModel, output_model_path)
Loading