diff --git a/Applications/IK/ik.cpp b/Applications/IK/ik.cpp index 03ef24d0df..ae1491fc4a 100644 --- a/Applications/IK/ik.cpp +++ b/Applications/IK/ik.cpp @@ -68,9 +68,6 @@ int main(int argc,char **argv) )"; std::cout << deprecationNotice << std::endl; - // REGISTER TYPES - InverseKinematicsTool::registerTypes(); - // PARSE COMMAND LINE string option = ""; string setupFileName; diff --git a/OpenSim/Tools/InverseDynamicsTool.cpp b/OpenSim/Tools/InverseDynamicsTool.cpp index 94b9ee5411..6b2a68a072 100644 --- a/OpenSim/Tools/InverseDynamicsTool.cpp +++ b/OpenSim/Tools/InverseDynamicsTool.cpp @@ -274,7 +274,6 @@ bool InverseDynamicsTool::run() << _lowpassCutoffFrequency << "..." << endl << endl; _coordinateValues->pad(_coordinateValues->getSize()/2); _coordinateValues->lowpassIIR(_lowpassCutoffFrequency); - if (getVerboseLevel()==Debug) _coordinateValues->print("coordinateDataFiltered.sto"); } // Convert degrees to radian if indicated if(_coordinateValues->isInDegrees()){ diff --git a/OpenSim/Tools/InverseKinematicsTool.cpp b/OpenSim/Tools/InverseKinematicsTool.cpp index 84ab911749..dde2062190 100644 --- a/OpenSim/Tools/InverseKinematicsTool.cpp +++ b/OpenSim/Tools/InverseKinematicsTool.cpp @@ -58,20 +58,9 @@ InverseKinematicsTool::~InverseKinematicsTool() /** * Default constructor. */ -InverseKinematicsTool::InverseKinematicsTool() : Tool(), - _modelFileName(_modelFileNameProp.getValueStr()), - _constraintWeight(_constraintWeightProp.getValueDbl()), - _accuracy(_accuracyProp.getValueDbl()), - _ikTaskSetProp(PropertyObj("", IKTaskSet())), - _ikTaskSet((IKTaskSet&)_ikTaskSetProp.getValueObj()), - _markerFileName(_markerFileNameProp.getValueStr()), - _coordinateFileName(_coordinateFileNameProp.getValueStr()), - _timeRange(_timeRangeProp.getValueDblArray()), - _reportErrors(_reportErrorsProp.getValueBool()), - _outputMotionFileName(_outputMotionFileNameProp.getValueStr()), - _reportMarkerLocations(_reportMarkerLocationsProp.getValueBool()) +InverseKinematicsTool::InverseKinematicsTool() : Tool() { - setNull(); + constructProperties(); } //_____________________________________________________________________________ /** @@ -83,176 +72,32 @@ InverseKinematicsTool::InverseKinematicsTool() : Tool(), * @param aFileName File name of the document. */ InverseKinematicsTool::InverseKinematicsTool(const string &aFileName, bool aLoadModel) : - Tool(aFileName, true), - _modelFileName(_modelFileNameProp.getValueStr()), - _constraintWeight(_constraintWeightProp.getValueDbl()), - _accuracy(_accuracyProp.getValueDbl()), - _ikTaskSetProp(PropertyObj("", IKTaskSet())), - _ikTaskSet((IKTaskSet&)_ikTaskSetProp.getValueObj()), - _markerFileName(_markerFileNameProp.getValueStr()), - _coordinateFileName(_coordinateFileNameProp.getValueStr()), - _timeRange(_timeRangeProp.getValueDblArray()), - _reportErrors(_reportErrorsProp.getValueBool()), - _outputMotionFileName(_outputMotionFileNameProp.getValueStr()), - _reportMarkerLocations(_reportMarkerLocationsProp.getValueBool()) + Tool(aFileName, true) { - setNull(); + constructProperties(); updateFromXMLDocument(); - - if(aLoadModel) { - //loadModel(aFileName); - } -} -//_____________________________________________________________________________ -/** - * Copy constructor. - * - * @param aTool Object to be copied. - - */ -InverseKinematicsTool::InverseKinematicsTool(const InverseKinematicsTool &aTool) : - Tool(aTool), - _modelFileName(_modelFileNameProp.getValueStr()), - _constraintWeight(_constraintWeightProp.getValueDbl()), - _accuracy(_accuracyProp.getValueDbl()), - _ikTaskSetProp(PropertyObj("", IKTaskSet())), - _ikTaskSet((IKTaskSet&)_ikTaskSetProp.getValueObj()), - _markerFileName(_markerFileNameProp.getValueStr()), - _coordinateFileName(_coordinateFileNameProp.getValueStr()), - _timeRange(_timeRangeProp.getValueDblArray()), - _reportErrors(_reportErrorsProp.getValueBool()), - _outputMotionFileName(_outputMotionFileNameProp.getValueStr()), - _reportMarkerLocations(_reportMarkerLocationsProp.getValueBool()) -{ - setNull(); - *this = aTool; -} - -//_____________________________________________________________________________ -/** - * Set all member variables to their null or default values. - */ -void InverseKinematicsTool::setNull() -{ - setupProperties(); - _model = NULL; -} -//_____________________________________________________________________________ -/** - * Connect properties to local pointers. - */ -void InverseKinematicsTool::setupProperties() -{ - _modelFileNameProp.setComment( - "Name of the model file (.osim) to use for inverse kinematics."); - _modelFileNameProp.setName("model_file"); - _propertySet.append( &_modelFileNameProp ); - - _constraintWeightProp.setComment( - "A positive scalar that weights the relative importance of satisfying " - "constraints. A weighting of 'Infinity' (the default) results in the " - "constraints being strictly enforced. Otherwise, the weighted-squared " - "constraint errors are appended to the cost function."); - _constraintWeightProp.setName("constraint_weight"); - _constraintWeightProp.setValue(std::numeric_limits::infinity()); - _propertySet.append( &_constraintWeightProp ); - - _accuracyProp.setComment( - "The accuracy of the solution in absolute terms. Default is 1e-5. " - "It determines the number of significant digits to which the solution " - "can be trusted."); - _accuracyProp.setName("accuracy"); - _accuracyProp.setValue(1e-5); - _propertySet.append( &_accuracyProp ); - - _ikTaskSetProp.setComment( - "Markers and coordinates to be considered (tasks) and their weightings. " - "The sum of weighted-squared task errors composes the cost function."); - _ikTaskSetProp.setName("IKTaskSet"); - _propertySet.append(&_ikTaskSetProp); - - _markerFileNameProp.setComment( - "TRC file (.trc) containing the time history of observations of marker " - "positions obtained during a motion capture experiment. Markers in this " - "file that have a corresponding task and model marker are included."); - _markerFileNameProp.setName("marker_file"); - _propertySet.append(&_markerFileNameProp); - - _coordinateFileNameProp.setComment( - "The name of the storage (.sto or .mot) file containing the time history" - " of coordinate observations. Coordinate values from this file are " - "included if there is a corresponding model coordinate and task. "); - _coordinateFileNameProp.setName("coordinate_file"); - _propertySet.append(&_coordinateFileNameProp); - - const double defaultTimeRange[] = - {-std::numeric_limits::infinity(), - std::numeric_limits::infinity()}; - _timeRangeProp.setComment( - "The desired time range over which inverse kinematics is solved. " - "The closest start and final times from the provided observations " - "are used to specify the actual time range to be processed."); - _timeRangeProp.setName("time_range"); - _timeRangeProp.setValue(2, defaultTimeRange); - _timeRangeProp.setAllowableListSize(2); - _propertySet.append(&_timeRangeProp); - - _reportErrorsProp.setComment( - "Flag (true or false) indicating whether or not to report marker " - "errors from the inverse kinematics solution."); - _reportErrorsProp.setName("report_errors"); - _reportErrorsProp.setValue(true); - _propertySet.append(&_reportErrorsProp); - - _outputMotionFileNameProp.setComment( - "Name of the resulting inverse kinematics motion (.mot) file."); - _outputMotionFileNameProp.setName("output_motion_file"); - _propertySet.append(&_outputMotionFileNameProp); - - _reportMarkerLocationsProp.setComment( - "Flag indicating whether or not to report model marker locations. " - "Note, model marker locations are expressed in Ground."); - _reportMarkerLocationsProp.setName("report_marker_locations"); - _reportMarkerLocationsProp.setValue(false); - _propertySet.append(&_reportMarkerLocationsProp); } //_____________________________________________________________________________ /** - * Register InverseKinematicsTool and any Object types it may employ internally. - */ -void InverseKinematicsTool::registerTypes() -{ - Object::registerType(InverseKinematicsTool()); -} -//============================================================================= -// OPERATORS -//============================================================================= -//_____________________________________________________________________________ -/** - * Assignment operator. - * - * @return Reference to this object. + * Construct properties */ -InverseKinematicsTool& InverseKinematicsTool:: -operator=(const InverseKinematicsTool &aTool) +void InverseKinematicsTool::constructProperties() { - // BASE CLASS - Tool::operator=(aTool); - - // MEMBER VARIABLES - _modelFileName = aTool._modelFileName; - _constraintWeight = aTool._constraintWeight; - _accuracy = aTool._accuracy; - _ikTaskSet = aTool._ikTaskSet; - _markerFileName = aTool._markerFileName; - _timeRange = aTool._timeRange; - _coordinateFileName = aTool._coordinateFileName; - _reportErrors = aTool._reportErrors; - _outputMotionFileName = aTool._outputMotionFileName; - _reportMarkerLocations = aTool._reportMarkerLocations; - - return(*this); + constructProperty_model_file(""); + constructProperty_constraint_weight(Infinity); + constructProperty_accuracy(1e-5); + constructProperty_IKTaskSet(IKTaskSet()); + constructProperty_marker_file(""); + constructProperty_coordinate_file(""); + Array range{Infinity, 2}; + range[0] = -Infinity; // Make range -Infinity to Infinity unless limited by + // data + constructProperty_time_range(range); + + constructProperty_report_errors(true); + constructProperty_output_motion_file(""); + constructProperty_report_marker_locations(false); } //============================================================================= @@ -274,10 +119,10 @@ bool InverseKinematicsTool::run() Kinematics* kinematicsReporter = nullptr; try{ //Load and create the indicated model - if (!_model) { - OPENSIM_THROW_IF_FRMOBJ(_modelFileName.empty(), Exception, - "No model filename was provided."); - _model = new Model(_modelFileName); + if (_model.empty()) { + OPENSIM_THROW_IF_FRMOBJ(get_model_file().empty(), Exception, + "No model filename was provided."); + _model.reset(new Model(get_model_file())); } else modelFromFile = false; @@ -317,11 +162,11 @@ bool InverseKinematicsTool::run() // specified then use time from marker reference. // Adjust the time range for the tool if the provided range exceeds // that of the marker data. - SimTK::Vec2 markersValidTimRange = markersReference.getValidTimeRange(); - double start_time = (markersValidTimRange[0] > _timeRange[0]) ? - markersValidTimRange[0] : _timeRange[0]; - double final_time = (markersValidTimRange[1] < _timeRange[1]) ? - markersValidTimRange[1] : _timeRange[1]; + SimTK::Vec2 markersValidTimeRange = markersReference.getValidTimeRange(); + double start_time = (markersValidTimeRange[0] > get_time_range(0)) ? + markersValidTimeRange[0] : get_time_range(0); + double final_time = (markersValidTimeRange[1] < get_time_range(1)) ? + markersValidTimeRange[1] : get_time_range(1); SimTK_ASSERT2_ALWAYS(final_time >= start_time, "InverseKinematicsTool final time (%f) is before start time (%f).", @@ -337,8 +182,8 @@ bool InverseKinematicsTool::run() // create the solver given the input data InverseKinematicsSolver ikSolver(*_model, markersReference, - coordinateReferences, _constraintWeight); - ikSolver.setAccuracy(_accuracy); + coordinateReferences, get_constraint_weight()); + ikSolver.setAccuracy(get_accuracy()); s.updTime() = times[start_ix]; ikSolver.assemble(s); kinematicsReporter->begin(s); @@ -352,9 +197,9 @@ bool InverseKinematicsTool::run() SimTK::Array_ squaredMarkerErrors(nm, 0.0); SimTK::Array_ markerLocations(nm, Vec3(0)); - Storage *modelMarkerLocations = _reportMarkerLocations ? + Storage *modelMarkerLocations = get_report_marker_locations() ? new Storage(Nframes, "ModelMarkerLocations") : nullptr; - Storage *modelMarkerErrors = _reportErrors ? + Storage *modelMarkerErrors = get_report_errors() ? new Storage(Nframes, "ModelMarkerErrors") : nullptr; Stopwatch watch; @@ -365,7 +210,7 @@ bool InverseKinematicsTool::run() // show progress line every 1000 frames so users see progress if (std::remainder(i - start_ix, 1000) == 0 && i != start_ix) cout << "Solved " << i - start_ix << " frames..." << std::endl; - if(_reportErrors){ + if(get_report_errors()){ Array markerErrors(0.0, 3); double totalSquaredMarkerError = 0.0; double maxSquaredMarkerError = 0.0; @@ -393,7 +238,7 @@ bool InverseKinematicsTool::run() << ikSolver.getMarkerNameForIndex(worst) << ")" << endl; } - if(_reportMarkerLocations){ + if(get_report_marker_locations()){ ikSolver.computeCurrentMarkerLocations(markerLocations); Array locations(0.0, 3*nm); for(int j=0; jgetPositionStorage()->print(_outputMotionFileName); + if (get_output_motion_file() != "" && + get_output_motion_file() != "Unassigned") { + kinematicsReporter->getPositionStorage()->print( + get_output_motion_file()); } // Remove the analysis we added to the model, this also deletes it _model->removeAnalysis(kinematicsReporter); @@ -472,7 +319,8 @@ bool InverseKinematicsTool::run() "please see messages window for details...")); } - if (modelFromFile) delete _model; + if (modelFromFile) + _model.reset(); return success; } @@ -511,9 +359,7 @@ void InverseKinematicsTool::updateFromXMLNode(SimTK::Xml::Element& aNode, int ve for (; p!= trialIter->node_end(); ++p) { iter->insertNodeAfter( iter->node_end(), p->clone()); } - iter->insertNodeAfter( iter->node_end(), Xml::Comment(_constraintWeightProp.getComment())); iter->insertNodeAfter( iter->node_end(), Xml::Element("constraint_weight", "20.0")); - iter->insertNodeAfter( iter->node_end(), Xml::Comment(_accuracyProp.getComment())); iter->insertNodeAfter( iter->node_end(), Xml::Element("accuracy", "1e-4")); // erase node for IKTrialSet iter->eraseNode(toolIter); @@ -545,9 +391,7 @@ void InverseKinematicsTool::updateFromXMLNode(SimTK::Xml::Element& aNode, int ve for (; p!= trialIter->node_end(); ++p) { root.insertNodeAfter( root.node_end(), p->clone()); } - root.insertNodeAfter( root.node_end(), Xml::Comment(_constraintWeightProp.getComment())); root.insertNodeAfter( root.node_end(), Xml::Element("constraint_weight", "20.0")); - root.insertNodeAfter( root.node_end(), Xml::Comment(_accuracyProp.getComment())); root.insertNodeAfter( root.node_end(), Xml::Element("accuracy", "1e-5")); // erase node for IKTrialSet root.eraseNode(toolIter); @@ -577,8 +421,8 @@ void InverseKinematicsTool::populateReferences(MarkersReference& markersReferenc FunctionSet *coordFunctions = NULL; // Load the coordinate data // bool haveCoordinateFile = false; - if (_coordinateFileName != "" && _coordinateFileName != "Unassigned") { - Storage coordinateValues(_coordinateFileName); + if (get_coordinate_file() != "" && get_coordinate_file() != "Unassigned") { + Storage coordinateValues(get_coordinate_file()); // Convert degrees to radian (TODO: this needs to have a check that the storage is, in fact, in degrees!) _model->getSimbodyEngine().convertDegreesToRadians(coordinateValues); // haveCoordinateFile = true; @@ -589,9 +433,9 @@ void InverseKinematicsTool::populateReferences(MarkersReference& markersReferenc // Loop through old "IKTaskSet" and assign weights to the coordinate and marker references // For coordinates, create the functions for coordinate reference values int index = 0; - for (int i = 0; i < _ikTaskSet.getSize(); i++) { - if (!_ikTaskSet[i].getApply()) continue; - if (IKCoordinateTask *coordTask = dynamic_cast(&_ikTaskSet[i])) { + for (int i = 0; i < get_IKTaskSet().getSize(); i++) { + if (!get_IKTaskSet()[i].getApply()) continue; + if (IKCoordinateTask *coordTask = dynamic_cast(&get_IKTaskSet()[i])) { CoordinateReference *coordRef = NULL; if (coordTask->getValueType() == IKCoordinateTask::FromFile) { if (!coordFunctions) @@ -619,7 +463,7 @@ void InverseKinematicsTool::populateReferences(MarkersReference& markersReferenc coordinateReferences.push_back(*coordRef); } - else if (IKMarkerTask *markerTask = dynamic_cast(&_ikTaskSet[i])) { + else if (IKMarkerTask *markerTask = dynamic_cast(&get_IKTaskSet()[i])) { if (markerTask->getApply()) { // Only track markers that have a task and it is "applied" markerWeights.adoptAndAppend( @@ -631,7 +475,7 @@ void InverseKinematicsTool::populateReferences(MarkersReference& markersReferenc //Read in the marker data file and set the weights for associated markers. //Markers in the model and the marker file but not in the markerWeights are //ignored - markersReference.initializeFromMarkersFile(_markerFileName, markerWeights); + markersReference.initializeFromMarkersFile(get_marker_file(), markerWeights); } diff --git a/OpenSim/Tools/InverseKinematicsTool.h b/OpenSim/Tools/InverseKinematicsTool.h index 0f57dca83e..5d01afe214 100644 --- a/OpenSim/Tools/InverseKinematicsTool.h +++ b/OpenSim/Tools/InverseKinematicsTool.h @@ -24,9 +24,10 @@ * -------------------------------------------------------------------------- */ #include "osimToolsDLL.h" -#include -#include +#include +#include #include "Tool.h" +#include #ifdef SWIG #ifdef OSIMTOOLS_API @@ -38,7 +39,6 @@ namespace OpenSim { class Model; -class IKTaskSet; class MarkersReference; class CoordinateReference; @@ -63,51 +63,55 @@ OpenSim_DECLARE_CONCRETE_OBJECT(InverseKinematicsTool, Tool); private: /** Pointer to the model being investigated. */ - Model *_model; + SimTK::ReferencePtr _model; - /** Name of the xml file used to deserialize or construct a model. */ - PropertyStr _modelFileNameProp; - std::string &_modelFileName; +public: + OpenSim_DECLARE_PROPERTY(model_file, std::string, + "Name/path to the xml .osim file used to load a model to be analyzed."); - /** The relative weight of the constraints. Infinity is a strictly enforced constraint. - Any other non-zero positive scalar is the penalty factor for constraint violations. */ - PropertyDbl _constraintWeightProp; - double &_constraintWeight; + OpenSim_DECLARE_PROPERTY(constraint_weight, double, + "The relative weighting of kinematic constraint errors. By default this " + "is Infinity, which means constraints are strictly enforced as part of " + "the optimization and are not appended to the objective (cost) function. " + "Any other non-zero positive scalar is the penalty factor for " + "constraint violations."); - /** The accuracy of the solution in absolute terms, i.e. the number of significant digits - to which the solution can be trusted. */ - PropertyDbl _accuracyProp; - double &_accuracy; + OpenSim_DECLARE_PROPERTY(accuracy, double, + "The accuracy of the solution in absolute terms, i.e. the number of " + "significant digits to which the solution can be trusted. Default 1e-5."); - // Markers and coordinates to be matched and their respective weightings - PropertyObj _ikTaskSetProp; - IKTaskSet &_ikTaskSet; + OpenSim_DECLARE_UNNAMED_PROPERTY( + IKTaskSet, + "Markers and coordinates to be considered (tasks) and their weightings. " + "The sum of weighted-squared task errors composes the cost function."); - // name of marker file that contains marker locations for IK solving - PropertyStr _markerFileNameProp; - std::string &_markerFileName; + OpenSim_DECLARE_PROPERTY(marker_file, std::string, + "TRC file (.trc) containing the time history of observations of marker " + "positions obtained during a motion capture experiment. Markers in this " + "file that have a corresponding task and model marker are included."); - // name of storage file that contains coordinate values for IK solving - PropertyStr _coordinateFileNameProp; - std::string &_coordinateFileName; - // range of frames to solve in marker file, specified by time - PropertyDblArray _timeRangeProp; - Array &_timeRange; + OpenSim_DECLARE_PROPERTY(coordinate_file, std::string, + "The name of the storage (.sto or .mot) file containing the time " + "history of coordinate observations. Coordinate values from this file are " + "included if there is a corresponding model coordinate and task. "); - // flag if inverse kinematics should report marker errors - PropertyBool _reportErrorsProp; - bool &_reportErrors; + OpenSim_DECLARE_LIST_PROPERTY_SIZE( + time_range, double, 2, "The time range for the study."); - // name of motion file with inverse kinematics solution - PropertyStr _outputMotionFileNameProp; - std::string &_outputMotionFileName; + OpenSim_DECLARE_PROPERTY(report_errors, bool, + "Flag (true or false) indicating whether or not to report marker " + "errors from the inverse kinematics solution."); - // flag indicating whether or not to resulting marker locations - PropertyBool _reportMarkerLocationsProp; - bool &_reportMarkerLocations; + OpenSim_DECLARE_PROPERTY(output_motion_file, std::string, + "Name of the resulting inverse kinematics motion (.mot) file."); -//============================================================================= + + OpenSim_DECLARE_PROPERTY(report_marker_locations, bool, + "Flag indicating whether or not to report model marker locations. " + "Note, model marker locations are expressed in Ground."); + + //============================================================================= // METHODS //============================================================================= //-------------------------------------------------------------------------- @@ -117,49 +121,48 @@ OpenSim_DECLARE_CONCRETE_OBJECT(InverseKinematicsTool, Tool); virtual ~InverseKinematicsTool(); InverseKinematicsTool(); InverseKinematicsTool(const std::string &aFileName, bool aLoadModel=true) SWIG_DECLARE_EXCEPTION; - InverseKinematicsTool(const InverseKinematicsTool &aObject); - - /* Register types to be used when reading an InverseKinematicsTool object from xml file. */ - static void registerTypes(); + /* Handle reading older formats/Versioning */ void updateFromXMLNode(SimTK::Xml::Element& aNode, int versionNumber=-1) override; //---- Setters and getters for various attributes void setModel(Model& aModel) { _model = &aModel; }; - void setStartTime(double d) { _timeRange[0] = d; }; - double getStartTime() const {return _timeRange[0]; }; - - void setEndTime(double d) { _timeRange[1] = d; }; - double getEndTime() const {return _timeRange[1]; }; - - void setMarkerDataFileName(const std::string& markerDataFileName) { _markerFileName=markerDataFileName;}; - const std::string& getMarkerDataFileName() const { return _markerFileName;}; - - void setCoordinateFileName(const std::string& coordDataFileName) { _coordinateFileName=coordDataFileName;}; - const std::string& getCoordinateFileName() const { return _coordinateFileName;}; + void setStartTime(double d) { upd_time_range(0) = d; }; + double getStartTime() const { return get_time_range(0); }; + + void setEndTime(double d) { upd_time_range(1) = d; }; + double getEndTime() const { return get_time_range(1); }; + + void setMarkerDataFileName(const std::string& markerDataFileName) { + upd_marker_file() = markerDataFileName; + }; + const std::string& getMarkerDataFileName() const { + return get_marker_file(); + }; + + void setCoordinateFileName(const std::string& coordDataFileName) { + upd_coordinate_file() = coordDataFileName; + }; + const std::string& getCoordinateFileName() const { + return get_coordinate_file(); + }; - //const OpenSim::Storage& getOutputStorage() const; private: - void setNull(); - void setupProperties(); + void constructProperties(); +public: //-------------------------------------------------------------------------- // OPERATORS //-------------------------------------------------------------------------- -public: -#ifndef SWIG - InverseKinematicsTool& - operator=(const InverseKinematicsTool &aInverseKinematicsTool); -#endif //-------------------------------------------------------------------------- // GET AND SET //-------------------------------------------------------------------------- void setOutputMotionFileName(const std::string aOutputMotionFileName) { - _outputMotionFileName = aOutputMotionFileName; + upd_output_motion_file() = aOutputMotionFileName; } - std::string getOutputMotionFileName() { return _outputMotionFileName;} - IKTaskSet& getIKTaskSet() { return _ikTaskSet; } + std::string getOutputMotionFileName() { return get_output_motion_file(); } + IKTaskSet& getIKTaskSet() { return upd_IKTaskSet(); } //-------------------------------------------------------------------------- // INTERFACE diff --git a/OpenSim/Tools/Tool.h b/OpenSim/Tools/Tool.h index d3125fede2..7f8ecdca22 100644 --- a/OpenSim/Tools/Tool.h +++ b/OpenSim/Tools/Tool.h @@ -48,26 +48,16 @@ namespace OpenSim { class OSIMTOOLS_API Tool : public Object { OpenSim_DECLARE_ABSTRACT_OBJECT(Tool, Object); -public: - /** Perturbation types. See setPerturbation(). */ - enum VerboseLevel {Quiet=0, Progress=1, DetailedProgress=2, Debug=3}; //============================================================================= // DATA //============================================================================= -protected: - - /** Directory for reading inputs (model, settings, etc...) from. */ - PropertyStr _inputsDirProp; - std::string &_inputsDir; - - /** Directory for writing results (new model, states, etc...) to. */ - PropertyStr _resultsDirProp; - std::string &_resultsDir; - - /** How much details to put out while running. */ - VerboseLevel _verboseLevel; +public: -//============================================================================= + OpenSim_DECLARE_PROPERTY(results_directory, std::string, + "Name of the directory where results are written. Be default this " + "is the directory in which the setup file is be executed."); + + //============================================================================= // METHODS //============================================================================= //-------------------------------------------------------------------------- @@ -83,9 +73,9 @@ OpenSim_DECLARE_ABSTRACT_OBJECT(Tool, Object); /** * Default constructor. */ - Tool() : _inputsDir(_inputsDirProp.getValueStr()), - _resultsDir(_resultsDirProp.getValueStr()) - { setNull(); }; + Tool() { + constructProperties(); + }; /** * Construct from file @@ -97,76 +87,17 @@ OpenSim_DECLARE_ABSTRACT_OBJECT(Tool, Object); * @param aUpdateFromXMLNode */ Tool(const std::string &aFileName, bool aUpdateFromXMLNode = true): - Object(aFileName, true), _inputsDir(_inputsDirProp.getValueStr()), - _resultsDir(_resultsDirProp.getValueStr()) { - setNull(); - if(aUpdateFromXMLNode) updateFromXMLDocument(); + Object(aFileName, true) { + constructProperties(); + updateFromXMLDocument(); }; - /** - * Copy constructor. - * - * @param aTool to be copied. - */ - Tool(const Tool &aTool) : _inputsDir(_inputsDirProp.getValueStr()), - _resultsDir(_resultsDirProp.getValueStr()) - {setNull(); *this = aTool; }; - - private: - /** - * %Set all member variables to their null or default values. - */ - void setNull() { - setupProperties(); - _resultsDir = "./"; - _inputsDir = ""; - _verboseLevel = Progress; - }; - - /** - * Connect properties to local pointers. - */ - void setupProperties() - { - std::string comment; - comment = "Directory used for writing results."; - _resultsDirProp.setComment(comment); - _resultsDirProp.setName("results_directory"); - _propertySet.append( &_resultsDirProp ); - - comment = "Directory for input files"; - _inputsDirProp.setComment(comment); - _inputsDirProp.setName("input_directory"); - _propertySet.append( &_inputsDirProp ); - }; - - - - //-------------------------------------------------------------------------- - // OPERATORS - //-------------------------------------------------------------------------- -public: -#ifndef SWIG - - /** - * Assignment operator. - * - * @return Reference to this object. - */ - Tool& operator=(const Tool& source) { - if (&source != this) { - Super::operator=(source); - _resultsDir = source._resultsDir; - _inputsDir = source._inputsDir; - _verboseLevel = source._verboseLevel; - } - return *this; + void constructProperties() { + constructProperty_results_directory("./"); } -#endif - - +public: //-------------------------------------------------------------------------- // INTERFACE //-------------------------------------------------------------------------- @@ -184,21 +115,11 @@ OpenSim_DECLARE_ABSTRACT_OBJECT(Tool, Object); // GET AND SET //-------------------------------------------------------------------------- /** - * Get/set Inputs Directory - */ - const std::string& getInputsDir() const { return _inputsDir; } - void setInputsDir(const std::string& aString) { _inputsDir = aString; } - /** - * Get/set Results Directory + * Get/set Results Directory, will replace with Property accessors eventually */ - const std::string& getResultsDir() const { return _resultsDir; } - void setResultsDir(const std::string& aString) { _resultsDir = aString; } + const std::string& getResultsDir() const { return get_results_directory(); } + void setResultsDir(const std::string& aString) { set_results_directory(aString); } - /** - * Get/Set verbose level - */ - const VerboseLevel getVerboseLevel() const { return _verboseLevel; }; - void setVerboseLevel(const VerboseLevel aVerboseLevel) { _verboseLevel = aVerboseLevel; }; //============================================================================= }; // END of class Tool