What do getPositionInGround and getRotationInGround return?

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
User avatar
Connor Pyles
Posts: 20
Joined: Wed Jul 19, 2017 1:46 pm

What do getPositionInGround and getRotationInGround return?

Post by Connor Pyles » Thu Aug 10, 2017 2:18 pm

Hi all,

Just wanted to clarify, when working with the 4.0 API, do these methods return the translations and rotations of the geometry file with respect to the CAD space of the VTP file?

As for the rotation, what is the origin, (0,0,0)? Otherwise, if the origin based on the geometric center of the geometry or the body or something along those lines, how would you recommend I pull the position of that point in the global frame to apply the transformation correctly? I'm also assuming rotation is performed prior to translation?

Apologies if I'm overthinking this, any help is greatly appreciated.

Thanks,
Connor Pyles
JHU Applied Physics Lab

User avatar
Christopher Dembia
Posts: 506
Joined: Fri Oct 12, 2012 4:09 pm

Re: What do getPositionInGround and getRotationInGround return?

Post by Christopher Dembia » Thu Aug 10, 2017 5:44 pm

Where do you see the getPositionInGround() and getRotationInGround() functions? Which class are they on?

User avatar
Connor Pyles
Posts: 20
Joined: Wed Jul 19, 2017 1:46 pm

Re: What do getPositionInGround and getRotationInGround return?

Post by Connor Pyles » Thu Aug 10, 2017 5:55 pm

They are methods for the body class but are new to the 4.0 AP I. Actually it is getTranformInGround instead of getRotationInGround, was going from memory.

User avatar
Christopher Dembia
Posts: 506
Joined: Fri Oct 12, 2012 4:09 pm

Re: What do getPositionInGround and getRotationInGround return?

Post by Christopher Dembia » Thu Aug 10, 2017 7:01 pm

Ah. If you are calling these functions on a body, then their outputs are unrelated to any geometry you may have attached to the bodies. Actually, those functions are on Frame, not Body (but Body is a type of frame). I don't know if I'll be able to answer all your questions but it might be helpful if you describe specifically what you're hoping to obtain.

getPositionInGround gives you the x, y, z position of the origin of the body (again, this is not really related to any geometry that you may have attached to the body) from the origin of the ground frame (and expressed in the ground frame).

getTransformInGround contains both the position and orientation of the body frame relative to the ground frame.

Hopefully the doxygen documentation of these methods is a little helpful: https://github.com/opensim-org/opensim- ... ame.h#L123

User avatar
Connor Pyles
Posts: 20
Joined: Wed Jul 19, 2017 1:46 pm

Re: What do getPositionInGround and getRotationInGround return?

Post by Connor Pyles » Thu Aug 10, 2017 8:50 pm

Thanks for the responses! What I'm trying to do is visualize the OpenSim model in Unity, which I'll eventually use to build a Hololens app.

My thought process was that I could convert all geometries attached to each body from .vtp to .blend which is accepted by unity, then use the getTranformInGround method in each state to build a Translation and quaternion which would allow me to reposition the .blend files for each state in Unity.

My assumption was that the frame transforms for getTranformInGround used the global (0,0,0) as the origin, but it sounds like I need to keep track of the frame origin that each body is attached to? Is there a way for me to query that point as I advance the state of the model?

I had a forum post a couple of weeks ago giving some example code for how I am reading in the .mot files to update body positions for each state, I can show you my most recent code once I get back to the lab if that would help.

Best,
Connor Pyles

User avatar
Christopher Dembia
Posts: 506
Joined: Fri Oct 12, 2012 4:09 pm

Re: What do getPositionInGround and getRotationInGround return?

Post by Christopher Dembia » Fri Aug 11, 2017 11:05 am

That sounds awesome! Are you going to use a scene graph representation, where the geometries are attached to bodies that articulate, or are you going to reposition the geometries in the global frame for each state? I ask because I think using a scene graph is usually more efficient.

First, I assume you're using C++. To loop through all geometries in a model, use

Code: Select all

model.getComponentList<Geometry>()
. If you want to loop through only mesh geometry, use

Code: Select all

model.getComponentList<Mesh>()
. Then you can ask for either (a) the transform in the ground frame (the global (0, 0, 0), as you call it) or (b) the (constant) transform of the geometry in the body on which it resides. Here's some pseudocode:

Code: Select all

for (const auto& mesh: model.getComponentList<Mesh>()) {
    mesh.getFrame().getTransformInGround(state); // get the orientation and position of this mesh relative to and expressed in the ground frame.
    mesh.getFrame().findTransformInBaseFrame(); // get the transform of the geomtry relative to the body it's fixed to.
    mesh.getFrame().findBaseFrame().getTransformInGround(state); // get the transform (in ground) of the body frame to which the geometry is fixed.
}
Note that you can obtain a quaternion from the transform using

Code: Select all

transform.R().convertRotationToQuaternion()
.


If you can link OpenSim to your Hololens app, you could alternately implement your own "visualizer"; see here for a "text" visualizer: https://github.com/opensim-org/opensim- ... on.cpp#L46.

User avatar
Christopher Dembia
Posts: 506
Joined: Fri Oct 12, 2012 4:09 pm

Re: What do getPositionInGround and getRotationInGround return?

Post by Christopher Dembia » Fri Aug 11, 2017 11:07 am

The gist is that you want to call getTransformInGround() on the frame to which the geometry is attached, not the *body* to which the geometry is attached. The frame to which the geometry is attached is not the same as the body to which it's attached.

User avatar
Connor Pyles
Posts: 20
Joined: Wed Jul 19, 2017 1:46 pm

Re: What do getPositionInGround and getRotationInGround return?

Post by Connor Pyles » Sun Aug 13, 2017 10:27 am

Thanks so much for response, I will play around with some of your ideas and let you know how it goes. To answer some of your questions, I was planning on using the global frame for each state, just because that is how I am used to operating in Unity. Also, I'm using MATLAB right now as I'm more comfortable with that language, and I think it wraps most of the functions you mentioned, but I wouldn't be against trying my hand at a little C++.

To be clear though, I should be asking for transform in ground for the FRAME to which each geometry is attached, and then I should be able to apply that transform directly to the VTP mesh?

-Connor

User avatar
Christopher Dembia
Posts: 506
Joined: Fri Oct 12, 2012 4:09 pm

Re: What do getPositionInGround and getRotationInGround return?

Post by Christopher Dembia » Sun Aug 13, 2017 11:33 pm

To be clear though, I should be asking for transform in ground for the FRAME to which each geometry is attached, and then I should be able to apply that transform directly to the VTP mesh?
Exactly.
Also, I'm using MATLAB right now
Then getComponentList<Mesh>() will not work for you. Check out https://github.com/opensim-org/opensim-core/pull/1851 and https://github.com/opensim-org/opensim- ... mponents.m for hints on what you might be able to do in MATLAB.

User avatar
Connor Pyles
Posts: 20
Joined: Wed Jul 19, 2017 1:46 pm

Re: What do getPositionInGround and getRotationInGround return?

Post by Connor Pyles » Wed Aug 30, 2017 7:40 am

Chris - Bringing this thread back to life. I've played around with some of you suggestions, and am still running into issues visualizing everything correctly. I have a MATLAB demo zipped up and posted here if you have a chance to take a look, although it requires you have the 4.0 MATLAB API set up:

https://drive.google.com/open?id=0B_gNk ... DJNbWItWU0

Basically, my steps as I loop through time are to first update the state of the entire model:

Code: Select all

for coordinateIdx = 1:obj.numCoordinates
                % Pull coordinate object and name
                coordinate = obj.coordinateSet.get(coordinateIdx - 1); % idx starts with zero as opposed to MATLAB 1
                coordinateName = char(coordinate);
                % Pull coordinate position in local frame from .mot file
                coordinateValueLocal = obj.motStruct.(coordinateName)(timeIdx);  % This is the struct output of STOFileAdapter, which reads the .mot files
                % Change the coordinate position in local frame, don't actually
                % update model until we have set all values
                coordinate.setValue(obj.state, coordinateValueLocal, double(coordinateIdx == obj.numCoordinates));  
                % only actually update after all coordinate values are updated
end
Then, once all the joint positions are set, I request the transform for all meshes:

Code: Select all

 
 for meshIdx = 1:obj.numMeshes
                  mesh  = obj.meshes{meshIdx};  % this is a mesh object I get by safe down casting from a geometry
                  frame = mesh.getFrame();
                  
                  meshP = mesh.get
                  thisP = frame.getPositionInGround(obj.state);
                  thisR = frame.getTransformInGround(obj.state).R;

                  % store values
                  obj.position(timeIdx, meshIdx, :)    = [thisP.get(0), thisP.get(1), thisP.get(2)];
                  obj.rotation(timeIdx, meshIdx, :, :) = [thisR.get(0,0), thisR.get(0,1), thisR.get(0,2);
                                                        thisR.get(1,0), thisR.get(1,1), thisR.get(1,2);
                                                        thisR.get(2,0), thisR.get(2,1), thisR.get(2,2)];                   
 end  
  
Then I later go on and apply these frame transforms to the .STL meshes and visualize using a MATLAB stl patch. However, the results have the bones flying all over the place.

Are the frame transforms truly going to give the transform for each mesh from their native CAD coordinate system? Maybe I'm missing on some sort of pre-positioning, because when I load all of the CAD meshes into something like MeshLab it looks like a pile of bones, but when I load the model into OpenSim it is obviously all oriented correctly initially.

Best,
Connor Pyles

POST REPLY