Add ligament on TugofWar Model

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Yueh-Lin Lee
Posts: 8
Joined: Thu Jun 27, 2013 12:09 am

Add ligament on TugofWar Model

Post by Yueh-Lin Lee » Wed Nov 13, 2013 8:33 am

Hello everyone,

I'm experimenting on "TugofWar" model(an example of OpenSim) by adding two ligaments to replace the original two muscles. And then I generated osim file by C++ code. When loading the model on OpenSim GUI, I can't see any ligament on the view but I could find it in the navigator window. It just seemed to be hidden. So I trace the xml of the osim file. I found it lacked <PathPointSet/> in <GeometryPath/> of the model. Could anyone give me some hints or suggestions about if I missed some steps in my C++ code.

Code: Select all

Ligament *ligament1 = new Ligament();
ligament1->setName("ligament1");
if(ligament1->hasGeometryPath())
{
  GeometryPath ligamentPath1 = ligament1->getGeometryPath();		
  ligamentPath1.appendNewPathPoint("ligament1-point1", *metatarsal1,Vec3(0.0,0.05,-0.35));
  ligamentPath1.appendNewPathPoint("ligament1-point2", *metatarsal2,Vec3(0.0,0.0,-0.05));
}
osimModel.addForce(ligament1);     

User avatar
Yueh-Lin Lee
Posts: 8
Joined: Thu Jun 27, 2013 12:09 am

Re: Add ligament on TugofWar Model

Post by Yueh-Lin Lee » Thu Nov 14, 2013 12:29 am

Finally I solved this problem. But I don't know why I could solve it by repeating these actions as function "appendNewPathPoint" doing.Could anyone give me some hints or suggestions about this?
Thanks so much,
Leonard

I changed my code as below:

Code: Select all

Ligament *ligament1 = new Ligament();
ligament1->setName("ligament1");

if(ligament1->hasGeometryPath())
{
  string ligament1Point1Name = "ligament1-point1";
  Vec3 aPositionOnBody1 = Vec3(0.0,0.05,-0.35);
  PathPoint* ligament1PathPoint1 = ligament1->updGeometryPath().appendNewPathPoint(ligament1Point1Name, ground, aPositionOnBody1);
		
  ligament1PathPoint1->setName(ligament1Point1Name);
  for(int i=0; i< 3; i++)
    ligament1PathPoint1->setLocationCoord(i, aPositionOnBody1[i]);

  string ligament1Point2Name = "ligament1-point2";
  Vec3 aPositionOnBody2 = Vec3(0.0,0.0,-0.05);
  PathPoint* ligament1PathPoint2 = ligament1->updGeometryPath().appendNewPathPoint(ligament1Point1Name, *block, aPositionOnBody1);
  ligament1PathPoint2->setName(ligament1Point2Name);
  for(int i=0; i< 3; i++)
    ligament1PathPoint2->setLocationCoord(i, aPositionOnBody2[i]);

  osimModel.addForce(ligament1);
}
Original function "appendNewPathPoint" :

Code: Select all

PathPoint* GeometryPath::appendNewPathPoint(const std::string& proposedName, 
								OpenSim::Body& aBody, const SimTK::Vec3& aPositionOnBody)
{
	PathPoint* newPoint = new PathPoint();
	newPoint->setBody(aBody);
	newPoint->setName(proposedName);
	for (int i=0; i<3; i++) 
		newPoint->setLocationCoord(i, aPositionOnBody[i]);

	upd_PathPointSet().adoptAndAppend(newPoint);
	return newPoint;
}

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

Re: Add ligament on TugofWar Model

Post by Ayman Habib » Thu Nov 14, 2013 11:38 am

Hi,

The problem is not in putting the code into a separate function but rather more involved.

The earlier piece of code was creating a "copy" of the GeometryPath and adding points to it which has no effect on the original GeometryPath, while the new code uses a method that returns a modifiable "reference" to the GeometryPath instead, and accordingly the changes you made to it took effect!.

Hope this explains,
-Ayman

POST REPLY