Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable advanced users to modify binding/wrapping for access to non-exposed classes/methods #3414

Closed
aymanhab opened this issue Feb 27, 2023 · 13 comments
Assignees

Comments

@aymanhab
Copy link
Member

This would be a backdoor for swig failure/overlooked classes/methods and to enable users to access simbody methods not available through the swig interface as described in this forum thread
https://simtk.org/plugins/phpBB/viewtopicPhpbb.php?f=91&t=15254&p=0&start=0&view=&sid=0cf16905bd2b7d10252faa4b0cb17a67

@jsn54
Copy link

jsn54 commented Feb 28, 2023

To address the issue described in the post mentioned above, it might be possible to create, via SWIG, a tiny Python which would only rely on C++ code to execute the expected function of the hidden class and retrieve its result into an OpenSim compatible format. The attached files could be the basis of a first attempt :

  • a cpp source file which defines a wrapping class : GravityWrapper.cpp (see draft proposed)
  • its associated header file : GravityWrapper.h (see draft proposed)
  • a mini runable app for debugging purposes : TestGravityWrapper.cpp (pure C++) (see draft proposed)
  • a SWIG interface file GravityWrapper.i to create the GravityWrapper python module (to do)
  • a CMake MakeLists.txt to manage the compilation of C++ code and the SWIG derived (to do).
    Unfortunately I haven't coded in C++ for years, and my CMake skills are minimal, so the attached files are just a non-functional draft for now.
    SwigGravityWrapper.zip

@aymanhab
Copy link
Member Author

aymanhab commented Mar 1, 2023

Thanks for getting started on this @jsn54 You actually don't need to have a separate cpp and h file and all the complications that come with that. I started a quick and dirty PR here #3416
that does what you want as an extension to the Model class in the .i file.

With a little more work you can promote this method to a new utility class (e.g. GravityWrapper) rather than injecting code into the OpenSim::Model class. At any rate I'd try as much as possible to leverage the .i files and avoid creating a separate class with header and cpp files. Please let me know how that works for you.

@aymanhab
Copy link
Member Author

aymanhab commented Mar 1, 2023

I'd add that you shouldn't create a new Gravity force class/instance, you should retrieve that from the Model instead.

@jsn54
Copy link

jsn54 commented Mar 2, 2023 via email

@jsn54
Copy link

jsn54 commented Mar 10, 2023

Hi everyone,
after many steps of "trial and error" caused by my lack in CMake-swig, please attached find a minimum version of a swig-based GravityWrapper. An executable is build, it works fine. SWIG process seems to work as well (compile/link/.so library build), however I can't import the module in a python interpreter. Would anyone examine this draft version and correct / tell me how to correct it ? Thanks in advance !
MinimumGravityWrapper.zip

@aymanhab
Copy link
Member Author

@jsn54 As I pointed out, sorry if that wasn't clear, you don't need a separate cpp file which require a big fight with cmake to get right and integrate. Instead keep all the implementation in a header file and include it in the .i file thus reusing the existing build system as is.
For any new development like this I'd use the main branch and latest tools (vstudio, etc.) not the 4.4 codebase unless you're willing to fight with these as it's likely some new code/features may not compile with earlier tools.

@aymanhab
Copy link
Member Author

@jsn54 Following up to see if you were able to get past your swig/compilation problems so we can close this issue. Thank you

@jenhicks jenhicks closed this as completed May 9, 2023
@jsn-inrs
Copy link

I'm sorry this topic was closed yesterday. Unfortunately, I haven't been able to go through swig/compilation issues, as I wrote in PR3416 which is closely linked to this topic. Actually, I was lost between those topics on github et their counterparts on OpenSim forums.
Would someone please help me have a correct cmake file in order to compile a little swig-python module ? Either through this approach (swig-python module) or the one described in #PR3416 (recompile opensim python bindings), I was not able to carry out how to retrieve gravity forces in python. And in both cases only because compilation in Windows is a ugly mess !

@jenhicks jenhicks reopened this May 10, 2023
@aymanhab
Copy link
Member Author

Hello, I just updated the PR with my earlier suggestion (#3416) with no necessary cmake changes. The signature of the methods in GravityHelper.java seem correct please give it a try when the PR is done building or let me know if you run into problems using it.

@aymanhab
Copy link
Member Author

@jsn-inrs I haven't heard back from you so I'll assume you were able to proceed and extract what you want from simbody, if not please comment here and reopen as needed. Thank you

@jsn-inrs
Copy link

Thank you for regularly following the progress of this PR. My schedule has been very busy this month and I was only able to start testing the compilation of the updated version of the OpenSim code yesterday. I'll keep you posted on my progress over the next few days. Thanks again for your attention to this request.

@jsn-inrs
Copy link

jsn-inrs commented Jun 2, 2023

It's already friday evening, unfortunately I didn't manage to have my script retrieve gravity forces. Would it be possible to carry on discussing the practical actions by means of mail or (even better) video conference (and screen sharing) ? I know opensim fellows are over-busy, but it may be more efficient and time saving to save a date in our agenda. Thanks in advance.

@jsn-inrs
Copy link

jsn-inrs commented Jul 7, 2023

Hi everyone,
I've tried the PR3414 and 3416 but what I plan is more complex. I think that SWIG wrapping is the best way to access and process Gravity Forces features. I've created a new project available on github : https://github.com/jsn-inrs/GravForcesProcessor
Would you please help me building a working Python package ? At least for what is linked to SWIG configuration of the Makefile (spdlog and OpenSim dependencies...). I lack skills but I'm really eager to learn and contribute then to OpenSim's development. Thanks in advance !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants