void scaleGait2354_GUI(bool useMarkerPlacement) { // SET OUTPUT FORMATTING IO::SetDigitsPad(4); // Construct model and read parameters file ScaleTool* subject = new ScaleTool("subject01_Setup_Scale_GUI.xml"); std::string setupFilePath=subject->getPathToSubject(); // Remove old results if any FILE* file2Remove = IO::OpenFile(setupFilePath+"subject01_scaleSet_applied_GUI.xml", "w"); fclose(file2Remove); file2Remove = IO::OpenFile(setupFilePath+"subject01_scaledOnly_GUI.osim", "w"); fclose(file2Remove); Model guiModel("gait2354_simbody.osim"); // Keep track of the folder containing setup file, wil be used to locate results to comapre against guiModel.initSystem(); MarkerSet *markerSet = new MarkerSet(setupFilePath + subject->getGenericModelMaker().getMarkerSetFileName()); guiModel.updateMarkerSet(*markerSet); // processedModelContext.processModelScale(scaleTool.getModelScaler(), processedModel, "", scaleTool.getSubjectMass()) guiModel.getMultibodySystem().realizeTopology(); SimTK::State* configState=&guiModel.updWorkingState(); bool retValue= subject->getModelScaler().processModel(*configState, &guiModel, setupFilePath, subject->getSubjectMass()); // Model has changed need to recreate a valid state guiModel.getMultibodySystem().realizeTopology(); configState=&guiModel.updWorkingState(); guiModel.getMultibodySystem().realize(*configState, SimTK::Stage::Position); if (!subject->isDefaultMarkerPlacer() && subject->getMarkerPlacer().getApply()) { MarkerPlacer& placer = subject->getMarkerPlacer(); if( false == placer.processModel(*configState, &guiModel, subject->getPathToSubject())) throw Exception("testScale filed to place markers"); } // Compare ScaleSet ScaleSet stdScaleSet = ScaleSet(setupFilePath+"std_subject01_scaleSet_applied.xml"); const ScaleSet& computedScaleSet = ScaleSet(setupFilePath+"subject01_scaleSet_applied_GUI.xml"); ASSERT(computedScaleSet == stdScaleSet); delete subject; }
/** * Test program to read SIMM model elements from an XML file. * * @param argc Number of command line arguments (should be 1). * @param argv Command line arguments: simmReadXML inFile */ int main(int argc,char **argv) { //TODO: put these options on the command line //LoadOpenSimLibrary("osimSimbodyEngine"); // SET OUTPUT FORMATTING IO::SetDigitsPad(4); // REGISTER TYPES Object::registerType(VisibleObject()); Object::registerType(ScaleTool()); ScaleTool::registerTypes(); // PARSE COMMAND LINE string inName; string option = ""; if (argc < 2) { PrintUsage(argv[0], cout); exit(-1); } else { // Load libraries first LoadOpenSimLibraries(argc,argv); int i; for(i=1;i<=(argc-1);i++) { option = argv[i]; // PRINT THE USAGE OPTIONS if((option=="-help")||(option=="-h")||(option=="-Help")||(option=="-H")|| (option=="-usage")||(option=="-u")||(option=="-Usage")||(option=="-U")) { PrintUsage(argv[0], cout); return(0); // Identify the setup file } else if((option=="-S")||(option=="-Setup")) { if (argv[i+1]==0){ PrintUsage(argv[0], cout); return(0); } inName = argv[i+1]; break; // Print a default setup file } else if((option=="-PrintSetup")||(option=="-PS")) { ScaleTool *subject = new ScaleTool(); subject->setName("default"); // Add in useful objects that may need to be instantiated Object::setSerializeAllDefaults(true); subject->print("default_Setup_Scale.xml"); Object::setSerializeAllDefaults(false); cout << "Created file default_Setup_Scale.xml with default setup" << endl; return(0); // PRINT PROPERTY INFO } else if((option=="-PropertyInfo")||(option=="-PI")) { if((i+1)>=argc) { Object::PrintPropertyInfo(cout,""); } else { char *compoundName = argv[i+1]; if(compoundName[0]=='-') { Object::PrintPropertyInfo(cout,""); } else { Object::PrintPropertyInfo(cout,compoundName); } } return(0); // Unrecognized } else { cout << "Unrecognized option " << option << " on command line... Ignored" << endl; PrintUsage(argv[0], cout); return(0); } } } try { // Construct model and read parameters file ScaleTool* subject = new ScaleTool(inName); Model* model = subject->createModel(); if(!model) throw Exception("scale: ERROR- No model specified.",__FILE__,__LINE__); // Realize the topology and initialize state SimTK::State& s = model->initSystem(); if (!subject->isDefaultModelScaler() && subject->getModelScaler().getApply()) { ModelScaler& scaler = subject->getModelScaler(); if(!scaler.processModel(s, model, subject->getPathToSubject(), subject->getSubjectMass())) return 1; } else { cout << "Scaling parameters disabled (apply is false) or not set. Model is not scaled." << endl; } SimTK::State& news = model->initSystem(); // old state is messed up by scaling. can't use it if (!subject->isDefaultMarkerPlacer()) { MarkerPlacer& placer = subject->getMarkerPlacer(); if(!placer.processModel(news, model, subject->getPathToSubject())) return 1; } else { cout << "Marker placement parameters disabled (apply is false) or not set. No markers have been moved." << endl; } delete model; delete subject; } catch(const Exception& x) { x.print(cout); } }