Skip to content

Commit

Permalink
Use swig4.2 or later (#3985)
Browse files Browse the repository at this point in the history
* Loosen swig version to 4.1.1 or higher

* Do without R specification that SWIG fails to parse

* SWIG out problematic signatures that break swig 4.2+

* A bit cleaner way to separate the scripting capable signature of createPeriodicTrajectory

* Update MocoUtilities.h

undo formatting changes for non-swig side for cleaner diff
  • Loading branch information
aymanhab authored Jan 14, 2025
1 parent 3783fbe commit b4ba7ca
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Bindings/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
if(BUILD_PYTHON_WRAPPING OR BUILD_JAVA_WRAPPING)
find_package(SWIG 4.1.1 EXACT REQUIRED)
find_package(SWIG 4.1.1 REQUIRED)
endif()

# Flags are both Python and Java bindings will use.
Expand Down
2 changes: 2 additions & 0 deletions OpenSim/Common/DelimFileAdapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ DelimFileAdapter<T>::clone() const {
template<typename T>
typename DelimFileAdapter<T>::OutputTables
DelimFileAdapter<T>::extendRead(const std::string& fileName) const {
#ifndef SWIG
OPENSIM_THROW_IF(fileName.empty(),
EmptyFileName);

Expand Down Expand Up @@ -468,6 +469,7 @@ DelimFileAdapter<T>::extendRead(const std::string& fileName) const {
output_tables.emplace(tableString(), table);

return output_tables;
#endif
}

template<typename T>
Expand Down
21 changes: 16 additions & 5 deletions OpenSim/Moco/MocoUtilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ OSIMMOCO_API void prescribeControlsToModel(const MocoTrajectory& trajectory,
OSIMMOCO_API MocoTrajectory simulateTrajectoryWithTimeStepping(
const MocoTrajectory& trajectory, Model model,
double integratorAccuracy = SimTK::NaN);

#ifndef SWIG
/// Convert a trajectory covering half the period of a symmetric motion into a
/// trajectory over the full period. This is useful for simulations of half a
/// gait cycle.
Expand Down Expand Up @@ -171,12 +171,23 @@ OSIMMOCO_API MocoTrajectory createPeriodicTrajectory(
".*lumbar_bending(?!/value).*",
".*lumbar_rotation.*"},
std::vector<std::string> negateAndShiftPatterns = {
".*pelvis_list/value",
".*pelvis_tz/value",
".*lumbar_bending/value"},
".*pelvis_list/value",
".*pelvis_tz/value",
".*lumbar_bending/value"},
std::vector<std::pair<std::string, std::string>> symmetryPatterns =
{{R"(_r(\/|_|$))", "_l$1"}, {R"(_l(\/|_|$))", "_r$1"}});

#else
// Variant that doesn't take symmetryPatterns which are unusable from scripting
OSIMMOCO_API MocoTrajectory createPeriodicTrajectory(
const MocoTrajectory& halfPeriodTrajectory,
std::vector<std::string> addPatterns = {".*pelvis_tx/value"},
std::vector<std::string> negatePatterns = {".*pelvis_list(?!/value).*",
".*pelvis_rotation.*", ".*pelvis_tz(?!/value).*",
".*lumbar_bending(?!/value).*", ".*lumbar_rotation.*"},
std::vector<std::string> negateAndShiftPatterns = {
".*pelvis_list/value", ".*pelvis_tz/value",
".*lumbar_bending/value"});
#endif
/// This obtains the value of the OPENSIM_MOCO_PARALLEL environment variable.
/// The value has the following meanings:
/// - 0: run in series (not parallel).
Expand Down

0 comments on commit b4ba7ca

Please sign in to comment.