Page 1 of 1

Building Wrapping Object from Scratch in MATLAB

Posted: Tue Mar 23, 2021 6:47 am
by gent
Hi everyone,

I am building my own Shoulder model and was wondering how to build Wrap objects (espacially Spheres) from Scratch. Is there an MATLAB example how to build a WrapSphere, add it to a body and apply it to certain muscles?

Edit:
I have tried the following:
Humerus_head = WrapSphere();
Humerus_head.setAllPropertiesUseDefault(true)
Humerus_head.setName('humeralHead')
Humerus_head.updPropertyByName("radius") = 0.225;
Humerus_head.connectToModelAndBody(osimModel,Humerus);

but I get the following error:
Unrecognized property 'updPropertyByName' for class 'org.opensim.modeling.WrapSphere'.

I get similar erros if I use
Humerus_head.setRadius(0.225)
Humerus_headd.set_radius(0.225)

Can someone help?
Thanks

Cheers,
Jeremy

Re: Building Wrapping Object from Scratch in MATLAB

Posted: Thu Mar 25, 2021 5:54 am
by gent
If someone has the same problem I hope this helps


So I found a work around here:
viewtopicPhpbb.php?f=91&t=3931&p=16839&start=0&view=
and
https://simtk.org/forums/viewtopic.php?f=91&t=6123

For the Sphere specifically I used this piece of Code:


wrapSphere=WrapSphere(); %Create a new wrap object
wrapSphere.setAllPropertiesUseDefault(true);
wrapSphere.setName('HumeralHead');
prop = wrapSphere.getPropertyByName('radius');
PropertyHelper.setValueDouble(0.026 , prop);
wrapSphere.setQuadrantName('all');

wrapObjSet = Humerus.getWrapObjectSet(); % Humerus is a bodydefined previously
wrapObjSet.cloneAndAppend(wrapSphere);



And for appling it to the muscle:


%Create the Muscle Wrap Object
newWrapObj = PathWrap();
newWrapObj.setName('Humeral Head');
newWrapObj.setWrapObject(wrapSphere);

% add wrap object to muscle
geoPath = SUPSP.getGeometryPath(); %Get the muscles geometry SUPSP is a muscle defined previously
wrapSet = geoPath.getWrapSet(); %Get the muscle's wrap set
wrapSet.cloneAndAppend(newWrapObj);

Re: Building Wrapping Object from Scratch in MATLAB

Posted: Tue Jun 14, 2022 9:17 am
by pvb
I tried to follow the above code, but it didn't work for me (perhaps the syntax has been slightly changed with changing versions of OpenSim). After some debugging, the following worked. The main difference is that I had to use "addWrapObject" to the body itself, for some reason "cloneAndAppend" didn't work for me. This might be because my model didn't previously have anything in the specific body's WrapObjectSet. I also wanted to add this new wrapping object to two muscles, and OpenSim (via the Matlab api) threw an error unless I called model.finalizeConnections after each added PathWrap.

Hope this helps someone in the future!

Cheers,
Pasha

Code: Select all

%create wrapping geometry
ankle_cylinder = WrapCylinder();
%ankle_cylinder.setAllPropertiesUseDefault(true);  %this line isn't doesn't seem necessary so I commented it

ankle_cylinder.set_radius(0.03)  
ankle_cylinder.set_length(0.05)
ankle_cylinder.setName('ankle_wrap_r');
ankle_cylinder.set_quadrant('-x');	%pick a quadrant, or set to 'all'
%ankle_cylinder.set_xyz_body_rotation(ArrayDouble.createVec3([0 0 0])) %if you want to rotate it
ankle_cylinder.set_translation(ArrayDouble.createVec3([1 1 1]))  %set the location
ankle_cylinder.setFrame(shank_dist_r)	%shank_dist_r is a previously defined body
shank_dist_r.addWrapObject(ankle_cylinder); 

%create path wrap
ankleWrap_r = PathWrap();
ankleWrap_r.setName('ankle_wrap_r');
ankleWrap_r.setWrapObject(ankle_cylinder);

%add the path wrap the the GeometryPath of the muscles

model.getMuscles.get('AE_r').getGeometryPath.getWrapSet.cloneAndAppend(ankleWrap_r); %my muscle is named 'AE_r'.
model.finalizeConnections(); 
model.getMuscles.get('KFAE_r').getGeometryPath.getWrapSet.cloneAndAppend(ankleWrap_r); %second muscle is 'named KFAE_r'
model.finalizeConnections();

Re: Building Wrapping Object from Scratch in MATLAB

Posted: Fri Jun 24, 2022 5:27 am
by glitterfairy
If you were initially having issues with cloneAndAppend, how does adding the Wrap Object to the body fix the issues with cloneAndAppend? I am slightly confused as to why cloneAndAppend was still used in the workaround for cloneAndAppend issues?

I am new to all this and very confused about pretty much everything so any clarity is appreciated

Regards
Alex

Re: Building Wrapping Object from Scratch in MATLAB

Posted: Fri Jun 24, 2022 7:35 am
by pvb
To be more specific, my issue was using "cloneAndAppend" to add wrapping a cylinder to the WrapGeometrySet - presumably because the body in question in my model didn't have any WrapGeometry yet, or alternatively because I'm using a newer version of OpenSim than the initial example.

Cheers,
Pasha