summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobias Klauser <tklauser@distanz.ch>2013-01-28 16:59:35 +0100
committerTobias Klauser <tklauser@distanz.ch>2013-01-28 16:59:35 +0100
commitdc42304b0778a10b9639253523b82f615a358dfa (patch)
treea33d55f3edc0054c7ac871438a5746f5624b24a3
parent458c1e0af1927264b2a9e1c4b66456d9b05180c5 (diff)
LocomotorPrimitives: Allow to specify output directory
-rw-r--r--LocomotorPrimitives.cpp32
1 files changed, 22 insertions, 10 deletions
diff --git a/LocomotorPrimitives.cpp b/LocomotorPrimitives.cpp
index 868726c..0a0ebcc 100644
--- a/LocomotorPrimitives.cpp
+++ b/LocomotorPrimitives.cpp
@@ -8,6 +8,7 @@
*/
#include <OpenSim/OpenSim.h>
+#include <OpenSim/Common/IO.h>
#include "LocomotorPrimitivesManager.h"
#include "LocomotorPrimitivesController.h"
@@ -56,13 +57,20 @@ static void constructModel(OpenSim::Model &model, OpenSim::Storage actData)
}
void simulateModel(OpenSim::Model &model, const double initial_time,
- const double final_time, double fixed_step_size)
+ const double final_time, double fixed_step_size,
+ std::string output_dir)
{
if (NO_SIM) {
logger.log("Skipping simulation as per NO_SIM=%d\n", NO_SIM);
return;
}
+ std::string cwd = OpenSim::IO::getCwd();
+ if (OpenSim::IO::chDir(output_dir) != 0) {
+ logger.err("Failed to change to ouput directory %s", output_dir.c_str());
+ return;
+ }
+
logger.log("Simulating model %s\n", MODEL_NAME.c_str());
logger.log("+ Initializing system\n");
@@ -105,6 +113,7 @@ static void usage()
std::cout << "usage: " << MODEL_NAME << " [OPTION...]" << std::endl << std::endl
<< " -d FILE specify .sto datafile to use for muscle activation data" << std::endl
<< " -m FILE specify .osim to use as model" << std::endl
+ << " -o DIR set output directory to DIR (default: current directory)" << std::endl
<< " -s N set fixed step size for integrator to N (default: dynamic)" << std::endl
<< " -h show this help and exit" << std::endl;
}
@@ -113,18 +122,21 @@ int main(int argc, char **argv)
{
clock_t ts_start = clock();
double fixed_step_size = 0.0;
-
/* set default values (to work on windows) */
- std::string modelFile = FIXED_IN_SPACE ? "../../locomotor-primitives-fixed.osim" : "../../locomotor-primitives.osim";
- std::string dataFile = "../../data/adults.sto";
+ std::string model_file = FIXED_IN_SPACE ? "../../locomotor-primitives-fixed.osim" : "../../locomotor-primitives.osim";
+ std::string data_file = "../../data/adults.sto";
+ std::string output_dir = ".";
for (int i = 1; (i < argc) && (argv[i][0] == '-'); i++) {
switch (argv[i][1]) {
case 'd':
- dataFile = argv[++i];
+ data_file = argv[++i];
break;
case 'm':
- modelFile = argv[++i];
+ model_file = argv[++i];
+ break;
+ case 'o':
+ output_dir = argv[++i];
break;
case 's':
fixed_step_size = strtod(argv[++i], NULL);
@@ -139,7 +151,7 @@ int main(int argc, char **argv)
}
}
- OpenSim::Storage actData(dataFile);
+ OpenSim::Storage actData(data_file);
const double initial_time = actData.getFirstTime();
const double final_time = actData.getLastTime();
@@ -148,17 +160,17 @@ int main(int argc, char **argv)
exit(-1);
}
- logger.log("Starting simulation %s with model file %s, actuation data file %s\n, fixed step size: %f", MODEL_NAME.c_str(), modelFile.c_str(), dataFile.c_str(), fixed_step_size);
+ logger.log("Starting simulation %s with model file %s, actuation data file %s\n, fixed step size: %f", MODEL_NAME.c_str(), model_file.c_str(), data_file.c_str(), fixed_step_size);
try {
// Create an OpenSim model and set its name
- OpenSim::Model osimModel(modelFile);
+ OpenSim::Model osimModel(model_file);
osimModel.setName(MODEL_NAME);
osimModel.setUseVisualizer(false);
constructModel(osimModel, actData);
- simulateModel(osimModel, initial_time, final_time, fixed_step_size);
+ simulateModel(osimModel, initial_time, final_time, fixed_step_size, output_dir);
} catch (OpenSim::Exception ex) {
logger.err("Exception: %s. Press ENTER to quit", ex.getMessage());
std::cin.get();