Edit Wrapping Surface Proprties API

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Bryce Killen
Posts: 104
Joined: Mon Nov 24, 2014 7:12 pm

Edit Wrapping Surface Proprties API

Post by Bryce Killen » Mon Mar 28, 2022 5:28 am

Hi All,

I am trying to find replacements for functions that existed in the OpenSim 3.3 API but are now no longer in the OpenSim API guide ( to my knowledge).

I am specificlaly trying to automatically update wrapping surface (ellipsoidsand spheres) properties such as transaltion, radius etc.

In OpenSim 4.0 I have only been able to update the translation and rotations when querying the Wrapping surface as a WrapObject type, i.e,,

Code: Select all

Model.getBodySet().get(bod).getWrapObjectSet().get(wrapName).set_translation(newLoc)
Model.getBodySet().get(bod).getWrapObjectSet().get(wrapName).set_xyz_body_rotation(newRot)
I have not been able to update the size of a wrapping sphere for example using the PropertyHelper class (see below) which has been removed

Code: Select all

radProp = wrapObject.getPropertyByName('radius')
osim.PropertyHelper.setValueDouble( newRad , radProp , 0)
Is there any work around (no matter how ugly) I can use to edit these properties using the OpenSim API in python ?

Thank you in advance for any ideas

Bryce

Tags:

User avatar
Ayman Habib
Posts: 2248
Joined: Fri Apr 01, 2005 12:24 pm

Re: Edit Wrapping Surface Proprties API

Post by Ayman Habib » Mon Mar 28, 2022 7:52 am

Hi Bryce,

Not sure what version of OpenSim 4.0+ you're using but PropertyHelper is available in version 4.1 and later, and the reason it's back is that there's no workaround in cases where classes are not exposed in their native API where normally setters and getters give access to properties. This is problematic for scripting languages that do not have access to the templated C++ accessor methods.

Please type:

Code: Select all

import org.opensim.modeling as osim
methodsview(osim.PropertyHelper)
at the scripting shell of the OpenSim application you installed to confirm if PropertyHelper is available and what methods it exposes.

Hope this helps,
-Ayman

User avatar
Bryce Killen
Posts: 104
Joined: Mon Nov 24, 2014 7:12 pm

Re: Edit Wrapping Surface Proprties API

Post by Bryce Killen » Mon Mar 28, 2022 8:15 am

Hi Ayman,

Thank you for your reply. I am using just OpenSim 4.0 so not 4.1 or higher. I'm happy to hear that it has been added back to the API for these versions.
I will try and upgrade my current version to one of these more recent versions and translate the rest of my code.

Thanks for the help.

Bryce

User avatar
Bryce Killen
Posts: 104
Joined: Mon Nov 24, 2014 7:12 pm

Re: Edit Wrapping Surface Proprties API

Post by Bryce Killen » Mon Mar 28, 2022 8:37 am

Hi Ayman,

I just did a quick check, when I open the OpenSim 4.1 GUI , and type the code you suggested, it does indeed return the different methods of PropertyHelper I was looking for. While this is useful, I want to be able to access these functions OUTSIDE of the GUI , i.e., through the Python API.

When I have mapped the OpenSim API to my Python version and import the opensim module - I cannot access these same functions. When I try to run a small sample code, it states

Code: Select all

AttributeError: module 'opensim' has no attribute 'PropertyHelper'
Should this be the case or I have something wrong with my OpenSim + Python interaction ?

Thanks
Bryce

User avatar
Najoua Assila
Posts: 34
Joined: Thu Aug 30, 2018 9:24 am

Re: Edit Wrapping Surface Proprties API

Post by Najoua Assila » Wed Mar 30, 2022 6:08 am

Hi Bryce,

I am not sure what changes were included in the 4.1 version, but I had a compiled version from the gihub repo somewhere between the 4.0 and 4.1 Opensim releases. I was able then to modify the properties of the wrapping objects via pyhton by safe downcasting the functions from the class corresponding to the wrapping type (WrapEllipsoid, WrapTorus, ...).

Hope it helps,

Najoua

User avatar
Bryce Killen
Posts: 104
Joined: Mon Nov 24, 2014 7:12 pm

Re: Edit Wrapping Surface Proprties API

Post by Bryce Killen » Thu Mar 31, 2022 12:37 am

HI Najoua,

Thank you for the reply. Are you able to share a small snippet of the code you used to edit, for example, the wraping surface radius , in the case of a sphere. I am assuming you were still reliant on the PropertyHelper function ?

Thanks in advance for any help you can provide.

Best
Bryce

User avatar
Bryce Killen
Posts: 104
Joined: Mon Nov 24, 2014 7:12 pm

Re: Edit Wrapping Surface Proprties API

Post by Bryce Killen » Thu Mar 31, 2022 12:50 pm

[SOLVED] ** to some degree

I managed to get around this by calculating a scale factor and scaling the wrapping surface object (after safeDownCast) , then resetting the translations to what they were previously.

User avatar
Najoua Assila
Posts: 34
Joined: Thu Aug 30, 2018 9:24 am

Re: Edit Wrapping Surface Proprties API

Post by Najoua Assila » Fri Apr 01, 2022 12:32 am

Hi Bryce,

Here is a code snippet for an ellipsoid wrapping object

Code: Select all

ellipsoid = osim_model.getBodySet().get(0).getWrapObjectSet().get(4)
wrap_ellip = osim.WrapEllipsoid.safeDownCast(ellipsoid)
initial_dim = wrap_ellip.getRadii() # value: [0.1,0.135,0.08]
wrap_ellip.set_dimensions(osim.Vec3(0.1, 0.235, 0.08))
wrap_ellip.getRadii().toString() #output: '~[0.1,0.235,0.08]'
Hope it helps,

Najoua

POST REPLY