Update frame's translations and orientations

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Hojin Song
Posts: 76
Joined: Wed Jul 08, 2020 9:46 am

Update frame's translations and orientations

Post by Hojin Song » Mon Aug 28, 2023 12:21 am

Hi OpenSim experts!

I'm wondering if anyone can help me figuring out how to change the translations and orientations of the joints' frames. I was able to get the values with the following C++ code:

Code: Select all

	Model model("my_model.osim");
	const JointSet& jset = model.getJointSet();
	const Joint& femur_weld_r = jset.get("femur_weld_r");
	const Joint& tibial_plat_weld_r = jset.get("tibial_plat_weld_r");
	const PhysicalOffsetFrame& fem_offset = femur_weld_r.get_frames(1);
	const PhysicalOffsetFrame& tib_offset = tibial_plat_weld_r.get_frames(1);
	const SimTK::Vec<3>& fem_translation = fem_offset.get_translation();
	const SimTK::Vec<3>& fem_rotation = fem_offset.get_orientation();
	const SimTK::Vec<3>& tib_translation = tib_offset.get_translation();
	const SimTK::Vec<3>& tib_rotation = tib_offset.get_orientation();

	cout << fem_translation << endl;
	cout << fem_rotation << endl;
	cout << tib_translation << endl;
	cout << tib_rotation << endl;;
Unfortunately, I could not find a way to update these translations and orientations. Could anyone possible teach me how to do so?

Thankfully,
Hojin

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

Re: Update frame's translations and orientations

Post by Ayman Habib » Tue Aug 29, 2023 1:24 pm

Hello,

Generally the API uses two parallel mechanisms in C++, one to obtain const references (e.g. get_translation) and a different call to return a mutable reference (e.g. upd_translation). If you want to change the contents of a property (Vec3 translation in this case), you'd call upd_translation and then set the new values you want through the mutable reference, for example here
https://github.com/opensim-org/opensim- ... ame.h#L331

Hope this helps,
-Ayman

POST REPLY