Swig Object?

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Mohammadreza Rezaie
Posts: 398
Joined: Fri Nov 24, 2017 12:48 am

Swig Object?

Post by Mohammadreza Rezaie » Sat May 27, 2023 2:21 am

Hi, I'm trying to get access to model.getMultibodySystem(), particularly for mobility and rigid body forces, but it returns a Swig Object:
<Swig Object of type 'SimTK::MultibodySystem *' at 0x000001F6355933F0>

This happens for OpenSim::Storage::exportToTable() as well:
<Swig Object of type 'TimeSeriesTable *' at 0x000001F646736030>

Any idea how to work with that? Thank you.

Tags:

User avatar
Thomas Uchida
Posts: 1790
Joined: Wed May 16, 2012 11:40 am

Re: Swig Object?

Post by Thomas Uchida » Sat May 27, 2023 8:58 am

The documentation for the SimTK::MultibodySystem class can be found here: https://simtk.org/api_docs/simbody/3.5/ ... ystem.html. To see what methods are available in Matlab, you can use the built-in Matlab functions "methods()" and "methodsview()" (please see the "Scripting with Matlab" page in the Confluence documentation: https://simtk-confluence.stanford.edu:8 ... ith+Matlab). The documentation for TimeSeriesTable can be found here: https://simtk.org/api_docs/opensim/api_ ... ble__.html. For some example code, TimeSeriesTable is used in testDataTable.cpp (https://github.com/opensim-org/opensim- ... aTable.cpp).

User avatar
Mohammadreza Rezaie
Posts: 398
Joined: Fri Nov 24, 2017 12:48 am

Re: Swig Object?

Post by Mohammadreza Rezaie » Sat May 27, 2023 11:16 am

Thank you Dr. Uchida, I'm already aware of that, but they are different objects and I can't use them. For example, there are no getRigidBodyForces() and getMobilityForces() methods in model.getMultibodySystem():

Code: Select all

dir(model.getMultibodySystem())
['__class__',
 '__delattr__',
 '__dir__',
 '__doc__',
 '__eq__',
 '__format__',
 '__ge__',
 '__getattribute__',
 '__getstate__',
 '__gt__',
 '__hash__',
 '__init__',
 '__init_subclass__',
 '__int__',
 '__le__',
 '__lt__',
 '__ne__',
 '__new__',
 '__reduce__',
 '__reduce_ex__',
 '__repr__',
 '__setattr__',
 '__sizeof__',
 '__str__',
 '__subclasshook__',
 'acquire',
 'append',
 'disown',
 'next',
 'own']
The second one also in not a TimeSeriesTable(). This is what I'm expecting to see for TimeSeriesTable class:
<opensim.common.TimeSeriesTable; proxy of <Swig Object of type 'std::shared_ptr< OpenSim::TimeSeriesTable_< double > > *' at 0x000001F095F6C9C0> >

Why don't these two examples work? Any help is greatly appreciated.

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

Re: Swig Object?

Post by Ayman Habib » Tue May 30, 2023 11:39 am

Hello,

Using SWIG to map C++ classes to different languages is a bit complicated by the fact that to expose a class, all its base classes need to be exposed as well. This allows SWIG to translate methods easily between the different languages. Exposing all Simbody classes and class hierarchy would add hundreds of classes that are intended to be internal to Simbody, that are rarely used in the OpenSim API and end up of little use to our user-community. so we had to draw the line somewhere. The SWIG* object classes are basically classes that we didn't expose so they end up in an unusable form.

You can modify the swig interface to try to expose more classes or to add a utility that exposes specific C++ methods to bindings if needed. An example code snippet addressing this is available on github (https://github.com/opensim-org/opensim-core/issues/3414)

If an OpenSim native class/method is not available however then I suggest you open an issue on github and we'll address as needed.

Hope this helps,
-Ayman

User avatar
Mohammadreza Rezaie
Posts: 398
Joined: Fri Nov 24, 2017 12:48 am

Re: Swig Object?

Post by Mohammadreza Rezaie » Wed May 31, 2023 1:06 am

Ayman, I appreciate your comprehensive response. I just opened an issue on GitHub for Storage::exportToTable():
https://github.com/opensim-org/opensim-core/issues/3472
Thank you.

POST REPLY