I was trying to create an OpenSim model with using c++. I've tried the code below to add a new ligament element to an existing model but the output model is missing its geometry path. The C++ code is as follows:
Code: Select all
// Create a new Ligament
Ligament* newLigament = new Ligament();
newLigament->setName("new_ligament");
newLigament->set_pcsa_force(0.01); // Example value for PCSA (cross-sectional area)
newLigament->set_resting_length(0.5); // Example value for resting length
Constant* lig_flCurve = new Constant();
lig_flCurve->setValue(500);
newLigament->setForceLengthCurve(*lig_flCurve);
// Define the Geometry Path
GeometryPath geopath = newLigament->upd_GeometryPath();
geopath.appendNewPathPoint("P1", model.getBodySet().get("pelvis"), Vec3(0));
geopath.appendNewPathPoint("P2", model.getBodySet().get("femur_r"), Vec3(0));
model.addForce(newLigament);
model.print("ligGenTest.osim");
Code: Select all
<Ligament name="new_ligament">
<!--the set of points defining the path of the ligament-->
<GeometryPath name="geometrypath">
<!--Default appearance attributes for this GeometryPath-->
<Appearance>
<!--The color, (red, green, blue), [0, 1], used to display the geometry. -->
<color>0 1 0</color>
</Appearance>
</GeometryPath>
<!--resting length of the ligament-->
<resting_length>0.5</resting_length>
<!--force magnitude that scales the force-length curve-->
<pcsa_force>0.01</pcsa_force>
<!--Function representing the force-length behavior of the ligament-->
<Constant name="force_length_curve">
<value>500</value>
</Constant>
</Ligament>
May I ask if someone point me out what I have done wrong in here? Thank you.
Best,
Hojin
P.S. I'm using OpenSim 4.4.