Пример #1
0
void scaleGait2354()
{
	// SET OUTPUT FORMATTING
	IO::SetDigitsPad(4);

	std::string setupFilePath="";
	ScaleTool* subject;
	Model* model;

	// Remove old results if any
	FILE* file2Remove = IO::OpenFile(setupFilePath+"subject01_scaleSet_applied.xml", "w");
	fclose(file2Remove);
	file2Remove = IO::OpenFile(setupFilePath+"subject01_simbody.osim", "w");
	fclose(file2Remove);

	// Construct model and read parameters file
	subject = new ScaleTool("subject01_Setup_Scale.xml");

	// Keep track of the folder containing setup file, wil be used to locate results to comapre against
	setupFilePath=subject->getPathToSubject();

	model = subject->createModel();

    SimTK::State& s = model->updWorkingState();
    model->getMultibodySystem().realize(s, SimTK::Stage::Position );

	if(!model) {
		//throw Exception("scale: ERROR- No model specified.",__FILE__,__LINE__);
		cout << "scale: ERROR- No model specified.";
    }

	ASSERT(!subject->isDefaultModelScaler() && subject->getModelScaler().getApply());
	ModelScaler& scaler = subject->getModelScaler();
	ASSERT(scaler.processModel(s, model, subject->getPathToSubject(), subject->getSubjectMass()));

	/*
	if (!subject->isDefaultMarkerPlacer() && subject->getMarkerPlacer().getApply()) {
		MarkerPlacer& placer = subject->getMarkerPlacer();
	    if( false == placer.processModel(s, model, subject->getPathToSubject())) return(false);
	}
	else {
        return(1);
	}
	*/
	// Compare ScaleSet
	ScaleSet stdScaleSet = ScaleSet(setupFilePath+"std_subject01_scaleSet_applied.xml");

	const ScaleSet& computedScaleSet = ScaleSet(setupFilePath+"subject01_scaleSet_applied.xml");

	ASSERT(computedScaleSet == stdScaleSet);
    
	delete model;
	delete subject;
}
Пример #2
0
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, will be used to locate results to compare against
    guiModel.initSystem();
    MarkerSet *markerSet = new MarkerSet(guiModel, setupFilePath + subject->getGenericModelMaker().getMarkerSetFileName());
    guiModel.updateMarkerSet(*markerSet);

    // processedModelContext.processModelScale(scaleTool.getModelScaler(), processedModel, "", scaleTool.getSubjectMass())
    guiModel.getMultibodySystem().realizeTopology();
    SimTK::State* configState=&guiModel.updWorkingState();
    subject->getModelScaler().processModel(&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(&guiModel, subject->getPathToSubject())) 
            throw Exception("testScale failed 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(compareStdScaleToComputed(stdScaleSet, computedScaleSet));

    delete subject;
}
Пример #3
0
void scaleModelWithLigament()
{
    // SET OUTPUT FORMATTING
    IO::SetDigitsPad(4);

    std::string setupFilePath("");
    ScaleTool* subject;
    Model* model;

    // Remove old model if any
    FILE* file2Remove = IO::OpenFile(setupFilePath + "toyLigamentModelScaled.osim", "w");
    fclose(file2Remove);

    // Construct model and read parameters file
    subject = new ScaleTool("toyLigamentModel_Setup_Scale.xml");

    // Keep track of the folder containing setup file, wil be used to locate results to comapre against
    setupFilePath = subject->getPathToSubject();

    model = subject->createModel();

    SimTK::State& s = model->updWorkingState();
    model->getMultibodySystem().realize(s, SimTK::Stage::Position);

    if (!model) {
        //throw Exception("scale: ERROR- No model specified.",__FILE__,__LINE__);
        cout << "scale: ERROR- No model specified.";
    }

    ASSERT(!subject->isDefaultModelScaler() && subject->getModelScaler().getApply());
    ModelScaler& scaler = subject->getModelScaler();
    ASSERT(scaler.processModel(s, model, subject->getPathToSubject(), subject->getSubjectMass()));

    const std::string& scaledModelFile = scaler.getOutputModelFileName();
    const std::string& std_scaledModelFile = "std_toyLigamentModelScaled.osim";

    ASSERT(Model(scaledModelFile) == Model(std_scaledModelFile));

    delete model;
    delete subject;
}
Пример #4
0
void scaleModelWithLigament()
{
    // SET OUTPUT FORMATTING
    IO::SetDigitsPad(4);

    std::string setupFilePath("");
    ScaleTool* scaleTool;
    Model* model;

    // Remove old model if any
    FILE* file2Remove = IO::OpenFile(setupFilePath + "toyLigamentModelScaled.osim", "w");
    fclose(file2Remove);

    // Construct model and read parameters file
    scaleTool = new ScaleTool("toyLigamentModel_Setup_Scale.xml");

    // Keep track of the folder containing setup file, will be used to locate results to compare against
    setupFilePath = scaleTool->getPathToSubject();

    model = scaleTool->createModel();

    if (!model) {
        throw Exception("scale: ERROR- No model specified.",__FILE__,__LINE__);
        //cout << "scale: ERROR- No model specified.";
    }

    SimTK::State& s = model->updWorkingState();
    model->getMultibodySystem().realize(s, SimTK::Stage::Position);

    ASSERT(!scaleTool->isDefaultModelScaler() && scaleTool->getModelScaler().getApply());
    ModelScaler& scaler = scaleTool->getModelScaler();
    ASSERT(scaler.processModel(model, setupFilePath, scaleTool->getSubjectMass()));

    const std::string& scaledModelFile = scaler.getOutputModelFileName();
    const std::string& std_scaledModelFile = "std_toyLigamentModelScaled.osim";

    Model comp(scaledModelFile);
    Model std(std_scaledModelFile);

    std.print("std_toyLigamentModelScaled_latest.osim");
    comp.print("comp_toyLigamentModelScaled_latest.osim");

    // the latest model will not match the standard because the naming convention has
    // been updated to store path names and connecting a model results in connectors
    // storing relative paths so that collections of components are more portable.
    // The models must be equivalent after being connected.
    comp.setup();
    std.setup();

    ComponentList<Ligament> compLigs = comp.getComponentList<Ligament>();
    ComponentList<Ligament> stdLigs = std.getComponentList<Ligament>();

    ComponentList<Ligament>::const_iterator itc = compLigs.begin();
    ComponentList<Ligament>::const_iterator its = stdLigs.begin();

    for (; its != stdLigs.end() && itc != compLigs.end(); ++its, ++itc){
        cout << "std:" << its->getName() << "==";
        cout << "comp:" << itc->getName() << " : ";
        cout << (*its == *itc) << endl;
        ASSERT(*its == *itc, __FILE__, __LINE__,
            "Scaled ligament " + its->getName() + " did not match standard.");
    }

    //Finally make sure we didn't incorrectly scale anything else in the model
    ASSERT(std == comp);

    delete model;
    delete scaleTool;
}
Пример #5
0
/**
* 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);
	}

}