forked from opensim-org/opensim-core
-
Notifications
You must be signed in to change notification settings - Fork 2
Interpolation support for GeometryPath's #11
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
Open
joris997
wants to merge
44
commits into
ComputationalBiomechanicsLab:master
Choose a base branch
from
joris997:interpolation
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
44 commits
Select commit
Hold shift + click to select a range
d24a799
test commit
290baff
removed test
19062db
initial changes to geometrypath with introduction of force and point …
fb67d1e
update
3810cf7
Merge remote-tracking branch 'origin/master' into interpolation
7adca62
Merge remote-tracking branch 'central/master'
0a963a6
merge conflict 'resolved' by just guessing it will work out
2b89575
updates to interpolation integration but methods not detected
aa760d7
finally integrated interpolator
3b4b304
updates to interpolation
e486f12
Delete CMakeLists.txt.user
joris997 e466408
formatting and introducing conversion tool
d6c6c54
formatting and tool
f10526c
changed order in interpolate constructor
4cd6e0b
Delete CMakeLists.txt.user
joris997 a96c4fe
fixed dependency to make dir
dca5e5f
Merge branch 'interpolation' of https://github.com/joris997/opensim-c…
a9e8d23
Initial refactor - compiles but needs fixing etc.
adamkewley 66c1f95
Mostly refactored, apart from Interpolate itself
adamkewley 8a5a014
Merge pull request #2 from adamkewley/ak_interpolation
joris997 d209c86
updates to tool and application for functionbasedpath conversion
c6e1598
interpolation to working state
46e095d
fixed inerpolation, removed user cmake file
bb7528e
partially addInEquivalentForces and getPointDirectionForces
2327c12
removing dependencies on GeometryPath, placing in fbp and pbp both
977ba7a
updates to FBP
b4a7cc6
updates
14e7343
finally fixed interpolator. roughly 6 times speed-up achieved for arm26
c096599
finally fixed interpolator. roughly 6 times speed-up achieved for arm26
6f5cb71
Remove VLA (doesn't compile on Windows)
adamkewley 080ef82
Refactored CLI and CLI test suite - seems to crash when running FPB t…
adamkewley 360e6d8
Minor C++11 change to make it compile on Ubuntu
4cc4100
Made file readers switch to model dir before reading files (so apps c…
64bab8d
Merge pull request #3 from adamkewley/interpolation
joris997 c10ded6
Refactored a variety of implementation files
9c543e0
Minor refactors to FBP implementation
5a72b5a
Made new implementation (superficially?) work and made fitting parame…
2ecd89d
Minor fixes/tweaks from microbenchmarks
5a07f37
Tweaked h value (used for derivative calc)
6d21aeb
Implemented variety of fixes and extra measurements
ad87919
Fixed invalid step size when computing evals
4c4aebe
Merge pull request #4 from adamkewley/interpolation
joris997 11fc9b0
implementation of analytical derivative and more testcases in convers…
b31afe4
added some other test-cases (commented out)
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
if(OPENSIM_BUILD_INDIVIDUAL_APPS) | ||
OpenSimAddApplication(NAME FunctionBasedPathConversion) | ||
endif() | ||
|
||
if(BUILD_TESTING) | ||
subdirs(test) | ||
endif(BUILD_TESTING) |
162 changes: 162 additions & 0 deletions
162
Applications/FunctionBasedPathConversion/functionbasedpathconversion.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
/* -------------------------------------------------------------------------- * | ||
* OpenSim: fbp-compiler.cpp * | ||
* -------------------------------------------------------------------------- * | ||
* ScapulothoracicJoint is offered as an addition to the OpenSim API * | ||
* See http://opensim.stanford.edu and the NOTICE file for more information. * | ||
* * | ||
* OpenSim is developed at Stanford University and is supported by: * | ||
* * | ||
* - The National Institutes of Health (U54 GM072970, R24 HD065690) * | ||
* - DARPA, through the Warrior Web program * | ||
* - The Chan Zuckerberg Initiative (CZI 2020-218896) * | ||
* * | ||
* Copyright (c) 2005-2021 Stanford University, TU Delft, and the Authors * | ||
* Author(s): Joris Verhagen * | ||
* * | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may * | ||
* not use this file except in compliance with the License. You may obtain a * | ||
* copy of the License at http://www.apache.org/licenses/LICENSE-2.0. * | ||
* * | ||
* Unless required by applicable law or agreed to in writing, software * | ||
* distributed under the License is distributed on an "AS IS" BASIS, * | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * | ||
* See the License for the specific language governing permissions and * | ||
* limitations under the License. * | ||
* -------------------------------------------------------------------------- */ | ||
|
||
#include <OpenSim/Common/Function.h> | ||
#include <OpenSim/Common/Logger.h> | ||
#include <OpenSim/Tools/FunctionBasedPathConversionTool.h> | ||
|
||
#include <cassert> | ||
#include <cstring> | ||
#include <iostream> | ||
#include <exception> | ||
|
||
static const char usage[] = "FunctionBasedPathConversion [--help] INPUT_MODEL OUTPUT_NAME"; | ||
static const char help_text[] = | ||
R"( | ||
ARGS | ||
|
||
--help print this help | ||
|
||
DESCRIPTION | ||
|
||
This compiler tries to convert an .osim model input file (INPUT_MODEL), which | ||
may contain `<PointBasedPath>` or `<GeometryPath>`s, into a functionally | ||
equivalent model output file (${OUTPUT_NAME}.osim) with associated curve | ||
fitting data (${OUTPUT_NAME}_DATA_${i}.txt). The output model is the same, | ||
but with each `<PointBasedPath>` or `<GeometryPath>` potentially replaced by a | ||
`<FunctionBasedPath>`. | ||
|
||
The phrases "functionally equivalent" and "potentially replaced" are | ||
important. The implementation tries to parameterize each input (point-based) | ||
path with the coordinates in the input model. The implementation will | ||
permute through the coordinates, trying to figure out which of them | ||
ultimately affect the input path. If the implementation determines the | ||
coordintate-to-path relationship, it will then try and fit the relationship | ||
to a multidimensional curve. If that curve appears to produce the same | ||
same outputs as the input (point-based) path, it will replace that path | ||
with the function-/curve-based equivalent. This replacement is only | ||
"functionally equivalent" if the model is then used in ways that ensure its | ||
coordinates roughly stay in the same value range as was used during curve | ||
fitting. Input paths are only "potentially replaced" because the implementation | ||
may not be able to parameterize all input paths. | ||
|
||
The primary reason to replace point-based (input) paths with function-based | ||
(output) equivalents is runtime performance. Point-based path computations | ||
can be expensive--especially if those paths are "wrapped" around other geometry-- | ||
whereas function-based paths are (effectively) lookups into precomputed curves. | ||
Those curves are usually smooth, so the resulting path outpus (length, speed, | ||
etc.) are usually smoother when integrated over multiple states. This smoothness | ||
can accelerate error-controlled integration schemes (OpenSim's default). | ||
|
||
If performance isn't an issue for you, you should probably keep using point-based | ||
paths. | ||
|
||
IMPLEMENTATION STEPS (high-level): | ||
|
||
- Reads INPUT_MODEL | ||
- Finds `GeometryPath`/`PointBasedPath`s in INPUT_MODEL | ||
- Parameterizes each input path against each of INPUT_MODEL's coordinates | ||
to produce an n-dimensional Bezier curve fit of those paths | ||
- Saves the curve data to ${OUTPUT_NAME}_DATA_${i}.txt, where `i` is an | ||
arbirary ID that links the `FunctionBasedPath` in the output .osim file | ||
to the Bezier fit's data | ||
- Updates the source model to contain `FunctionBasedPath`s | ||
- Writes the updated model to `${OUTPUT_NAME}.osim` | ||
|
||
EXAMPLE USAGE | ||
|
||
FunctionBasedPathModelTool RajagopalModel.osim RajagopalModel_Precomputed | ||
)"; | ||
|
||
int main(int argc, char **argv) { | ||
// skip exe name | ||
--argc; | ||
++argv; | ||
|
||
// set during parsing | ||
char const* sourceModelPath = nullptr; | ||
char const* outputName = nullptr; | ||
|
||
// parse CLI args | ||
int nUnnamed = 0; | ||
while (argc) { | ||
const char* arg = *argv; | ||
|
||
if (arg[0] != '-') { // handle unnamed args | ||
switch (nUnnamed) { | ||
case 0: | ||
// INPUT_MODEL | ||
sourceModelPath = arg; | ||
break; | ||
case 1: | ||
// OUTPUT_NAME | ||
outputName = arg; | ||
break; | ||
default: | ||
std::cerr << "FunctionBasedPathModelTool: error: too many arguments: should only supply 'MODEL' and 'OUTPUT_NAME'\n\nUSAGE: " | ||
<< usage | ||
<< std::endl; | ||
return -1; | ||
} | ||
|
||
++nUnnamed; | ||
--argc; | ||
++argv; | ||
continue; | ||
} else { // else: handle named args | ||
if (std::strcmp(arg, "--help") == 0) { | ||
std::cout << "usage: " << usage << '\n' << help_text << std::endl; | ||
return 0; | ||
} else { | ||
std::cerr << "FunctionBasedPathModelTool: error: unknown argument '" | ||
<< arg | ||
<< "': see --help for usage info"; | ||
return -1; | ||
} | ||
} | ||
} | ||
|
||
// ensure inputs are correct | ||
if (nUnnamed != 2) { | ||
std::cerr << "FunctionBasedPathModelTool: error: too few arguments supplied\n\n" | ||
<< usage | ||
<< std::endl; | ||
return -1; | ||
} | ||
|
||
assert(argc == 0); | ||
assert(sourceModelPath != nullptr); | ||
assert(outputName != nullptr); | ||
|
||
// run the tool | ||
try { | ||
OpenSim::FunctionBasedPathConversionTool tool(sourceModelPath,outputName); | ||
return tool.run() ? 0 : 1; | ||
} catch(const std::exception& ex) { | ||
OpenSim::log_error("Exception in ID: {}", ex.what()); | ||
return -1; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
|
||
file(GLOB TEST_PROGS "test*.cpp") | ||
file(GLOB TEST_FILES *.osim *.xml *.sto *.mot *.trc) | ||
|
||
OpenSimAddTests( | ||
TESTPROGRAMS ${TEST_PROGS} | ||
DATAFILES ${TEST_FILES} | ||
LINKLIBS osimTools | ||
) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.