Page 1 of 2

OpenSim API: set-translation/rotation for wrapping objects

Posted: Wed Nov 18, 2015 1:14 am
by mojtaba2069
Hi,

Is it possible to set the properties "translation" and "xyz_body_rotation"for WrapCylinder in opensim API?

Yours,
Mojtaba

Re: OpenSim API: set-translation/rotation for wrapping obje

Posted: Fri Nov 20, 2015 2:24 pm
by jimmy
Hi,

Yes, it is possible. But it is a hack that may have unpredictable effects if not done correctly. We will be building methods into future versions that can help edit properties and make sure that the model is valid, but for now, proceed at your own risk! ;)

This is how to do it in MATLAB:

Code: Select all

% Access a property named 'factor' in an OpenSim::Object 
% it is equivalent to having the XML tag name <factor> in an .osim file
factorProp  = objectWithFactor.getPropertyByName('factor');
% get its value
factor = PropertyHelper.getValueDouble(factorProp);
% double the factor and set it on the property
PropertyHelper.setValueDouble(2*factor, factorProp);

% Access a property named point, which is of type SimTK::Vec3
pointVec3Prop = objectWithPoint.getPropertyByName('point');
point(1) = PropertyHelper.getValueVec3(pointVec3Prop , 0); % x component
point(2) = PropertyHelper.getValueVec3(pointVec3Prop , 1); % y component 
point(3) = PropertyHelper.getValueVec3(pointVec3Prop , 2); % z component
NOTE: All property editing should be complete before the Model::finalizeFromProperties() method is invoked, which gets called at the beginning of Model::initSystem(). Any downstream edits on properties will have no (or in some cases unpredictable) effects on the system.

Let me know if this works
-James

Re: OpenSim API: set-translation/rotation for wrapping obje

Posted: Mon Nov 23, 2015 7:59 am
by mojtaba2069
thanks for your consideration,
I tried to do that in this way :
wrap=WrapCylinder();
wrap.setName(name);
pointVec3Prop = wrap.getPropertyByName('translation');
PropertyHelper.setValueVec3(0.01,pointVec3Prop , 0)

but I ran into this error :

"Java exception occurred:
java.lang.RuntimeException: Bad dynamic_cast!

at org.opensim.modeling.opensimModelJNI.PropertyHelper_setValueVec3(Native
Method)

at org.opensim.modeling.PropertyHelper.setValueVec3(PropertyHelper.java:131)
"
btw , trying to run this command "PropertyHelper.getValueVec3(pointVec3Prop , 0)" is also lead to same error.
can you help to solve it?

Re: OpenSim API: set-translation/rotation for wrapping obje

Posted: Tue Nov 24, 2015 12:20 pm
by jimmy
Hi

You trying to access a Vec3 and not a Double. Let me show a 'real' example;

Code: Select all

## this is written in python. Just get rid of the 'osm.' parts and it should work in ## matlab

import opensim as osm 

# load a model
model = osm.Model('/home/support/Arnoldetal2010_2Legs_50pct_v2.1.osim')

# get a handle to a wrap object
wrap = model.getBodySet().get('pelvis').getWrapObjectSet().get(1)

# get handle to the property
prop = wrap.getPropertyByName('translation')

# get the x translation value
x_translation = osm.PropertyHelper.getValueDouble(prop , 0)

# set a new x tranlsation value
osm.PropertyHelper.setValueDouble(x_translation + 1 ,prop, 0)

# re-initialize the system to validate the 'new' model.
model.initSystem()
There is some documentation for the PropertyHelper, here. This is old (OpenSIm 3.0) and we don't provide documentation for it now because -as I mentioned earlier- in general we do not want people using this hack to change the model. If you call the wrong method, it will most likely crash the system you are using (either matlab or python), so backup your code trying to mess around with it.

Goodluck,
-James

Re: OpenSim API: set-translation/rotation for wrapping objects

Posted: Mon Nov 07, 2016 4:42 pm
by vinhnguyen
Hi,

I am using OpenSim 3.3, and it seems that it does not have PropertyHelper class.
Do you have any suggestions for this?

Thanks.

Re: OpenSim API: set-translation/rotation for wrapping objects

Posted: Mon Nov 07, 2016 4:47 pm
by aymanh
Hi Vinh,

OpenSim 3.3 does have this class indeed (in fact it is used by the OpenSim application) though the documentation maybe lacking or missing. Why do you think the class is missing? Can you provide code snippet?

Best regards,
-Ayman

Re: OpenSim API: set-translation/rotation for wrapping objects

Posted: Mon Nov 07, 2016 9:09 pm
by vinhnguyen
Hi Ayman,

I tried to find "PropertyHelper" in OpenSim 3.3 doxygen (https://simtk.org/api_docs/opensim/api_docs/index.html), and
source code 3.3, but I could not find it.
Maybe I missed somethings here? Any suggestions?

Best regards,
Vinh

Re: OpenSim API: set-translation/rotation for wrapping objects

Posted: Thu Nov 10, 2016 2:22 pm
by aymanh
Vinh,

PropertyHelper class is used only when creating bindings to call OpenSim from Python or Matlab, (primarily because these languages do not support templates, and the Property classes are all templatized). If you're coding on the C++ side then you should use the templatized version of the methods. The Doxygen documentation does not include the PropertyHelper class for that reason (not available in C++).

Please indicate your context (language/environment), what you're trying to accomplish & what error you're getting and we'll try to help you out.

Best regards,
-Ayman

Re: OpenSim API: set-translation/rotation for wrapping objects

Posted: Thu Nov 10, 2016 3:12 pm
by vinhnguyen
Thank you for your answers,

I am writing in VS C++. I would like to create a model which has a WrapCylinder().
The thing is when I add the wrapcylinder to the body, it is by default attached to the coordinate system of the body.
But I want to translate it to other position. This would be easy by modifying the .osim file. However, I would like to
get a way to do that with VS C++ so I don't need to switch to .osim file.

Best regards,

Vinh

Re: OpenSim API: set-translation/rotation for wrapping objects

Posted: Sat Nov 02, 2019 6:00 am
by zannecox
Thank you for this thread. Using the suggested approach, I was able to use MATLAB optimization tools to fit wrap surfaces to experimentally collected moment arm data. I'm using it to make subject specific models - but it would have been a lot easier to build the model in the first place without hand fitting wrap surfaces! This thread was specific to V3. Have there been any changes in 4.0 that would change the best way to do this?