-
Notifications
You must be signed in to change notification settings - Fork 326
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
Comments
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 :
|
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 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. |
I'd add that you shouldn't create a new Gravity force class/instance, you should retrieve that from the Model instead. |
Thank you very much for your answers and hints.
Let me please sum up the info you gave, just to check that I've correctly understood the ins / outs, pro / cons and further steps:
- you created a quick and dirty Pull Resquest. If I add these lines in the source files on my local computer, recompiling my local install with Swig-Python extensions would enable me to access the desired feature. Thanks a lot ! It may help me a lot ! Even if it may imply some other actions to integrate such changes in python local virtual environments. However, this request may never be adopted nor accessible to other "basic opensim users".
- you advise me to go on creating a light "one-cpp-file" version of my code, which could be easily wrapped by swig. This would let me build a light easily diffusible swig-based Python module. Please enclosed find such a "light-weight" cpp file, retrieving the gravity force from the Model (I found and tested this morning that it is far more easy and you confirmed it, thanks !). Would you please help me building the swig-interface .i file ? I guess I have to include part of the numerous instructions found in C:\OpenSim 4.4\sourcecode\opensim-core-4.4\Bindings (for instance in common.i) ???
Thanks in advance for your help !
De: "Ayman Habib" ***@***.***>
À: "opensim-org/opensim-core" ***@***.***>
Cc: "jonathan" ***@***.***>, "Mention" ***@***.***>
Envoyé: Mercredi 1 Mars 2023 23:03:12
Objet: Re: [opensim-org/opensim-core] Enable advanced users to modify binding/wrapping for access to non-exposed classes/methods (Issue #3414)
I'd add that you shouldn't create a new Gravity force class/instance, you should retrieve that from the Model instead.
—
Reply to this email directly, [ #3414 (comment) | view it on GitHub ] , or [ https://github.com/notifications/unsubscribe-auth/ACQ6TJFJITQGPX2U6CESIS3WZ7BSBANCNFSM6AAAAAAVJW6CGA | unsubscribe ] .
You are receiving this because you were mentioned. Message ID: ***@***.***>
#==============================================================================
# JSN, 20230227
# This is the root-directory CMake file for building a SWIG-Python wrapper to
# enable OpenSim-based Python scripts to access simBody hidden classes and
# functions.
#==============================================================================
#--- CMakeLists.txt ---
# This is the minimum version of CMake that OpenSim requires:
cmake_minimum_required(VERSION 3.2)
project(LightGravityWrapper)
# OpenSim requires a compiler that supports C++11.
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# OpenSim stuff
set(OPENSIM_INSTALL_DIR
"C:/OpenSim 4.4/cmake")
set(OPENSIM_INC_DIRS
"C:/OpenSim 4.4/sdk/include/OpenSim/" "C:/OpenSim 4.4/sdk/include/OpenSim/Common")
find_package(OpenSim 4.4 REQUIRED HINTS "${OPENSIM_INSTALL_DIR}")
#===========================================================
# First target: a library (to check that the code compiles)
#===========================================================
add_library(LibGravityWrapper LightGravityWrapper.cpp)
target_link_libraries(LibGravityWrapper osimCommon)
#================================
# Second target: the swig module
#================================
find_package(Python COMPONENTS Development Interpreter)
if (Python_FOUND)
message("Found Python: ${Python_SITELIB}") # print sitepath
else()
message("No Python found.")
return()
endif()
find_package(SWIG)
include(UseSWIG)
if(SWIG_FOUND)
message("Found SWIG ${SWIG_VERSION}")
else()
message("No SWIG found.")
return()
endif()
set(UseSWIG_TARGET_NAME_PREFERENCE STANDARD)
set_property(SOURCE LightGravityWrapper.i PROPERTY CPLUSPLUS ON)
message("Binary dir: ${CMAKE_SOURCE_DIR}/build")
set(BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR}/SwigGravityWrapper)
swig_add_library(swigGravityWrapper
TYPE SHARED
LANGUAGE python
OUTPUT_DIR ${BUILD_DIR} # important! else find_packages() wont find
SOURCES LightGravityWrapper.i
)
target_include_directories(swigGravityWrapper PUBLIC ${OPENSIM_INC_DIRS})
target_link_libraries(swigGravityWrapper osimCommon)
#set_property(TARGET swigGravityWrapper PROPERTY LIBRARY_OUTPUT_DIRECTORY ${BUILD_DIR})
|
Hi everyone, |
@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. |
@jsn54 Following up to see if you were able to get past your swig/compilation problems so we can close this issue. Thank you |
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. |
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. |
@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 |
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. |
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. |
Hi everyone, |
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
The text was updated successfully, but these errors were encountered: