本文整理汇总了C++中simtk::State::toString方法的典型用法代码示例。如果您正苦于以下问题:C++ State::toString方法的具体用法?C++ State::toString怎么用?C++ State::toString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类simtk::State
的用法示例。
在下文中一共展示了State::toString方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main()
{
try {
int status = 0;
// To Retrace the steps taken by the GUI this test case follows the same call sequence:
// new Model(file)
// new OpenSimContext(model.initSystem(), model);
// context.updateDisplayer(muscle) // to display muscles
// context.getCurrentPath(muscle)
// context.getTransform(body)
// context.transformPosition(body, loc, global) // to display markers
// context.getLocked(Coordinate)
// context.getValue(cooridnate)
LoadOpenSimLibrary("osimActuators");
LoadOpenSimLibrary("osimSimulation");
LoadOpenSimLibrary("osimJavaJNI");
Model *model = new Model("wrist.osim");
OpenSimContext* context = new OpenSimContext(&model->initSystem(), model);
const ForceSet& fs = model->getForceSet();
int n1 = fs.getNumGroups();
const ObjectGroup* grp = fs.getGroup("wrist");
assert(grp);
const Array<const Object*>& members = grp->getMembers();
int sz = members.getSize();
ASSERT_EQUAL(sz,5,0);
assert(members.get(0)->getName()=="ECRB");
delete model;
delete context;
model = new Model("arm26_20.osim");
context = new OpenSimContext(&model->initSystem(), model);
// Make a copy of state contained in context ad make sure content match
SimTK::State stateCopy = context->getCurrentStateCopy();
assert(context->getCurrentStateRef().toString()==stateCopy.toString());
Array<std::string> stateNames = model->getStateVariableNames();
OpenSim::Force* dForce=&(model->updForceSet().get("TRIlong"));
Muscle* dTRIlong = dynamic_cast<Muscle*>(dForce);
assert(dTRIlong);
context->setPropertiesFromState();
OpenSim::Thelen2003Muscle* thelenMsl = dynamic_cast<Thelen2003Muscle*>(dTRIlong);
AbstractProperty& dProp = thelenMsl->updPropertyByName("ignore_tendon_compliance");
PropertyHelper::setValueBool(true, dProp);
cout << "Prop after is " << dProp.toString() << endl;
bool exceptionThrown = false;
try{// adding to the system should cause Muscle that do not handle
// ignore_tendon_compliance to throw an exception
context->recreateSystemKeepStage();
}
catch (const std::exception& e) {
cout << e.what() << endl;
exceptionThrown = true;
PropertyHelper::setValueBool(false, dProp);
cout << "Prop reset to " << dProp.toString() << endl;
// recreate the system so test can continue
context->recreateSystemKeepStage();
}
SimTK_ASSERT_ALWAYS(exceptionThrown, "Setting ignore_tendon_compliance must throw an exception.");
AbstractProperty& dProp2 = thelenMsl->updPropertyByName("ignore_tendon_compliance");
cout << "Prop after create system is " << dProp2.toString() << endl;
bool after = PropertyHelper::getValueBool(dProp);
SimTK_ASSERT_ALWAYS(!after, "Property has wrong value!!");
dTRIlong->updGeometryPath().updateGeometry(context->getCurrentStateRef());
const OpenSim::Array<PathPoint*>& path = context->getCurrentPath(*dTRIlong);
cout << "Muscle Path" << endl;
cout << path.getSize() << endl;
for(int i=0; i< path.getSize(); i++)
cout << path.get(i)->getBodyName() << path.get(i)->getLocation() << endl;
// Compare to known path
const OpenSim::Body& dBody = model->getBodySet().get("r_ulna_radius_hand");
Transform xform = context->getTransform(dBody);
cout << xform << endl;
double flat[16];
context->getTransformAsDouble16(xform, flat);
// Compare to known xform
double markerPosition[] = {.005000000000, -0.290400000000, 0.030000000000};
double markerPositionInGround[3];
context->transformPosition(dBody, markerPosition, markerPositionInGround); // to display markers
cout << "Global frame position = " << markerPositionInGround[0] <<
markerPositionInGround[1] << markerPositionInGround[2]<< endl;
// Check xformed point against known position
const Coordinate& dr_elbow_flex = model->getCoordinateSet().get("r_elbow_flex");
bool isLocked = context->getLocked(dr_elbow_flex);
assert(!isLocked);
double startValue = context->getValue(dr_elbow_flex);
cout << "Coordinate start value = " << startValue << endl;
double length1 = context->getMuscleLength(*dTRIlong);
cout << length1 << endl;
ASSERT_EQUAL(.277609, length1, 1e-5);
// Coordinate Slider
context->setValue(dr_elbow_flex, 100*SimTK_PI/180.);
// Get body transform, marker position and muscle path (tests wrapping as well)
xform = context->getTransform(dBody);
cout << "After setting coordinate to 100 deg." << endl;
//.........这里部分代码省略.........