-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathExample_deform_distal_tibia_Rajagopal.py
More file actions
83 lines (64 loc) · 3.05 KB
/
Example_deform_distal_tibia_Rajagopal.py
File metadata and controls
83 lines (64 loc) · 3.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
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)