Hi Felix, would you mind sharing your code?
For this specific model, I've gotten as far as adjusting the "thorax_offset" frame of the scapulothoracic joint (that determines the origin of the ellipsoid if I understand properly), then possibly reorienting the "scapula_offset" frame to adjust the scapula body orientation.
Then the PointConstraint tag:
- either manually modifying the values in <location_in_body_x>
- or creating an intermediate frame so that the scale tool handles that automatically.
Is that correct?
Problem with scaling and point constraint
- Martin Nousi
- Posts: 4
- Joined: Tue Apr 26, 2022 7:36 am
- Ayman Habib
- Posts: 2239
- Joined: Fri Apr 01, 2005 12:24 pm
Re: Problem with scaling and point constraint
Hi Felix,
Thanks for reporting, indeed you should report your findings to the model authors so that they fix the model or improve the documentation so that other users of the model do not run into this issue.
Best regards,
-Ayman
Thanks for reporting, indeed you should report your findings to the model authors so that they fix the model or improve the documentation so that other users of the model do not run into this issue.
Best regards,
-Ayman
- Félix Lefebvre
- Posts: 16
- Joined: Fri Oct 05, 2018 5:41 am
Re: Problem with scaling and point constraint
Hi,
What I do is the following:
- I added 2 markers to the model at the location of the PointContraint in each body, so that I can get this adjusted position once the model is scaled.
- Location_in_body_x is then adjusted following the marker's position.
About the position of the scapula body on the scaled model, I have a seperate script that optimizes the ellipsoid position and dimensions (orientation is kept aligned with thorax coordinate system) based on several static poses (it minimizes the distance between the ellipsoid and the scapula contact point for the selected poses).
Once this optimization is done, the resulting ellipsoid parameters are loaded to the scaled model by adjusting the radii and position in the parent frame. (The wrap ellipsoid is also modified for correct visualization.)
About the adjustement of the PointConstraint, I think the proposed solution of defining a dedicated frame with the constraint positioned in 0,0,0 in this frame would be the best and most transparent solution that would allow any user to safely scale the model. I just did not have the time to implement it yet.
Regards,
Felix
What I do is the following:
- I added 2 markers to the model at the location of the PointContraint in each body, so that I can get this adjusted position once the model is scaled.
- Location_in_body_x is then adjusted following the marker's position.
Code: Select all
clavicle_CP = scaledModel.getMarkerSet().get("ClavC")
acro_CP = scaledModel.getMarkerSet().get("AcroC")
clavicle_CP_loc = clavicle_CP.get_location()
acro_CP_loc = acro_CP.get_location()
AC_const = scaledModel.getConstraintSet().get("AC")
AC_constraint = osim.PointConstraint.safeDownCast(AC_const)
AC_constraint.set_location_body_1(clavicle_CP_loc)
AC_constraint.set_location_body_2(acro_CP_loc)
About the position of the scapula body on the scaled model, I have a seperate script that optimizes the ellipsoid position and dimensions (orientation is kept aligned with thorax coordinate system) based on several static poses (it minimizes the distance between the ellipsoid and the scapula contact point for the selected poses).
Once this optimization is done, the resulting ellipsoid parameters are loaded to the scaled model by adjusting the radii and position in the parent frame. (The wrap ellipsoid is also modified for correct visualization.)
Code: Select all
scap = scaledModel.getJointSet().get("scapulothoracic")
scap_joint = osim.ScapulothoracicJoint.safeDownCast(scap)
#Load new ellipsoid parameters
new_ell_params = [0,0,0,0,0,0]
f = open(os.path.join(folder, dataFolder, currDir, Ell_param_filename),'r')
for i,x in enumerate(f):
new_ell_params[i] = float(x) / 1000 #convert from mm to m
f.close()
#set new parameters to ellipsoid
paramsVec3 = osim.Vec3(new_ell_params[0],new_ell_params[1],new_ell_params[2])
posVec3 = osim.Vec3(new_ell_params[3],new_ell_params[5],new_ell_params[5])
scap_joint.set_thoracic_ellipsoid_radii_x_y_z(paramsVec3)
parent_frame = osim.PhysicalOffsetFrame.safeDownCast(scap_joint.getParentFrame())
parent_frame.set_translation(posVec3)
#set parameters to ellipsoid representation
compEll = scaledModel.getBodySet().get("thorax").getComponent("wrapobjectset").getComponent("EllipsoidSurface")
wrapEll = osim.WrapEllipsoid.safeDownCast(compEll)
wrapEll.set_dimensions(paramsVec3)
wrapEll.set_translation(posVec3)
Regards,
Felix
- Martin Nousi
- Posts: 4
- Joined: Tue Apr 26, 2022 7:36 am
Re: Problem with scaling and point constraint
Thanks Felix, that's great
I'll update if I get to set up dedicated frames to scale the PointConstraint automatically
(also, potential typo in "posVec3" depending on the output of your optimizer: using [3] [5] [5], maybe it should be [3] [4] [5] ? # posVec3 = osim.Vec3(new_ell_params[3],new_ell_params[5],new_ell_params[5]) )
I'll update if I get to set up dedicated frames to scale the PointConstraint automatically
(also, potential typo in "posVec3" depending on the output of your optimizer: using [3] [5] [5], maybe it should be [3] [4] [5] ? # posVec3 = osim.Vec3(new_ell_params[3],new_ell_params[5],new_ell_params[5]) )
- Félix Lefebvre
- Posts: 16
- Joined: Fri Oct 05, 2018 5:41 am
Re: Problem with scaling and point constraint
Allright thank you.
I will also contact the model author's about this. I will follow on the feedback they can give me here.
Thanks for pointing up that mistake, that is obviously an error and I bet you just saved me from some extra-time on finding the issue !
Best regards,
Felix
I will also contact the model author's about this. I will follow on the feedback they can give me here.
Thanks for pointing up that mistake, that is obviously an error and I bet you just saved me from some extra-time on finding the issue !
Best regards,
Felix
- Martin Nousi
- Posts: 4
- Joined: Tue Apr 26, 2022 7:36 am
Re: Problem with scaling and point constraint
I tested adding frames, but it's the pointconstraint that does not respect the origin of the frame.
@felix, do you have a simple example for the optimization of the ellipsoid that you could share?
@felix, do you have a simple example for the optimization of the ellipsoid that you could share?
- Félix Lefebvre
- Posts: 16
- Joined: Fri Oct 05, 2018 5:41 am
Re: Problem with scaling and point constraint
Could you elaborate a little bit more on the issues you are facing ?
About the ellipsoid optimization, I would like to keep my code private until the article in preparation is accepted and published.
Thank you,
Felix
About the ellipsoid optimization, I would like to keep my code private until the article in preparation is accepted and published.
Thank you,
Felix
- Martin Nousi
- Posts: 4
- Joined: Tue Apr 26, 2022 7:36 am
Re: Problem with scaling and point constraint
No worries for the optimization code, good luck with the paper.
Regarding the frames, I tried to do what Thomas suggested and change the pointConstraint properties:
In the default model, pointConstraint is currently with non-0 coordinates in <location_body_1> and <location_body_2>,
and the bodies are <socket_body_1>/bodyset/clavicle</socket_body_1> and <socket_body_2>/bodyset/scapula</socket_body_2>
I tried setting the <socket_body_1+2> to a PhysicalFrame (there are two already existing in the model: "cp_in_clavicle" and "cp_in_scapula", and the <location_body_1+2> to (0,0,0).
In this way, the origin of the physicalFrame does move during the scaling process,
but the pointConstraint does not work properly: instead of "anchoring" to the origin of the physicalFrame, the scapula goes back to the center of the scene.
This makes me think that the pointConstraint either ignores the physicalFrame if it is not an actual body, or there's an error somewhere and it falls back to either the origin of the previous body or to ground.
It is weird that the two physicalFrames are already existing in the model ("cp_in_clavicle" and "cp_in_scapula") with the proper offset coordinates for their origin in their respective bodies, but the pointConstraint does not rely on them and instead is defined in the bodies directly, with the same offset coordinates hard-coded.
Hopefully all of this makes sense! Manually changing the values of the pointConstraint after scaling obviously works, but it is weird (and annoying!) that there is no smooth way to make it automatic
Regarding the frames, I tried to do what Thomas suggested and change the pointConstraint properties:
In the default model, pointConstraint is currently with non-0 coordinates in <location_body_1> and <location_body_2>,
and the bodies are <socket_body_1>/bodyset/clavicle</socket_body_1> and <socket_body_2>/bodyset/scapula</socket_body_2>
I tried setting the <socket_body_1+2> to a PhysicalFrame (there are two already existing in the model: "cp_in_clavicle" and "cp_in_scapula", and the <location_body_1+2> to (0,0,0).
In this way, the origin of the physicalFrame does move during the scaling process,
but the pointConstraint does not work properly: instead of "anchoring" to the origin of the physicalFrame, the scapula goes back to the center of the scene.
This makes me think that the pointConstraint either ignores the physicalFrame if it is not an actual body, or there's an error somewhere and it falls back to either the origin of the previous body or to ground.
It is weird that the two physicalFrames are already existing in the model ("cp_in_clavicle" and "cp_in_scapula") with the proper offset coordinates for their origin in their respective bodies, but the pointConstraint does not rely on them and instead is defined in the bodies directly, with the same offset coordinates hard-coded.
Hopefully all of this makes sense! Manually changing the values of the pointConstraint after scaling obviously works, but it is weird (and annoying!) that there is no smooth way to make it automatic