Ejemplo n.º 1
0
/**
 * Get the names of the states of the actuators.
 *
 * @param rNames Array of names.
 */
void ForceSet::
getStateVariableNames(OpenSim::Array<std::string> &rNames) const
{
    for(int i=0;i<getSize();i++) {
        ScalarActuator *act = dynamic_cast<ScalarActuator*>(&get(i));
       
        if(act) {
            rNames.append(act->getStateVariableNames());
        }
    }
}
Ejemplo n.º 2
0
// Spatial Transform specific methods
OpenSim::Array<string> SpatialTransform::getCoordinateNames() const
{
    OpenSim::Array<string> coordinateNames;

    for(int i=0; i < NumTransformAxes; i++){
        const TransformAxis& transform = getTransformAxis(i);
        for(int j = 0; j < transform.getCoordinateNames().size(); j++){
            string name = transform.getCoordinateNames()[j];
            if(coordinateNames.findIndex(name) < 0)
                coordinateNames.append(name);
        }
    }
    return coordinateNames;
}
Array<std::string> MuscleOptimizer::getJointSpannedByMuscle(Model& model, const string& muscleName)
{
    OpenSim::Array<std::string> jointNames;

    OpenSim::BodySet bodySet(model.getBodySet());
    OpenSim::Set<OpenSim::Muscle> muscles = model.getMuscles();
    OpenSim::Muscle& muscle = muscles.get(muscleName);

    OpenSim::GeometryPath musclePath(muscle.getGeometryPath());
    OpenSim::PathPointSet musclePathPointSet(musclePath.getPathPointSet());

    // check if there is a simple kinematic chain between geometry path extremes
    int firstBodyIndex = 0;
    const OpenSim::JointSet& jointSet = model.getJointSet();
    // try to use consider first path point as on the proximal body, and last path point on the distal body
    OpenSim::Body& lastBody = musclePathPointSet.get(musclePathPointSet.getSize() - 1).getBody();
    OpenSim::Body& firstBody = musclePathPointSet.get(firstBodyIndex).getBody();
    std::string currentBodyName(lastBody.getName());
    std::string proximalBodyName(firstBody.getName());
    while (currentBodyName != proximalBodyName && currentBodyName !="ground") {
        for (int i = 0; i < jointSet.getSize(); i++)
        {
            if (jointSet.get(i).getBody().getName() == currentBodyName)
            {
                currentBodyName = jointSet.get(i).getParentBody().getName();
                continue;
            }
        }
    }
    if (currentBodyName == "ground") {
        // reverse - consider first path point as on distal body
        currentBodyName = firstBody.getName();
        proximalBodyName = lastBody.getName();
        while (currentBodyName != proximalBodyName && currentBodyName != "ground") {
            for (int i = 0; i < jointSet.getSize(); i++)
            {
                if (jointSet.get(i).getBody().getName() == currentBodyName)
                {
                    currentBodyName = jointSet.get(i).getParentBody().getName();
                    continue;
                }
            }
        }
        if (currentBodyName == "ground") {
            std::cout << "WARNING: Geometry Path for muscle " << muscleName << " does not follow a simple open kinematic chain" << std::endl;
            return jointNames;
        }
        else {
            currentBodyName = firstBody.getName();
        }

    }
    else {
        currentBodyName = lastBody.getName();
    }

    while (currentBodyName != proximalBodyName) {
        for (int i = 0; i < jointSet.getSize(); i++)
        {
            if (jointSet.get(i).getBody().getName() == currentBodyName)
            {
                if (jointSet.get(i).getCoordinateSet().getSize() != 0)
                    jointNames.append(jointSet.get(i).getName());
                currentBodyName = jointSet.get(i).getParentBody().getName();
                continue;
            }
        }
    }
    return jointNames;

}