Skip to content

Commit

Permalink
Handle unsupported path types when replacing muscles
Browse files Browse the repository at this point in the history
  • Loading branch information
nickbianco committed Aug 30, 2023
1 parent c383f64 commit e57c1f6
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
16 changes: 10 additions & 6 deletions OpenSim/Actuators/DeGrooteFregly2016Muscle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1023,10 +1023,7 @@ void DeGrooteFregly2016Muscle::replaceMuscles(
muscBase.get_ignore_activation_dynamics());

// Copy the muscle's path.
AbstractPath& path = muscBase.updPath();
if (auto* pGeometryPath = dynamic_cast<GeometryPath*>(&path)) {
auto& thisGeometryPath = actu->initGeometryPath();

if (auto* pGeometryPath = muscBase.tryUpdPath<GeometryPath>()) {
const auto& pathPointSet = pGeometryPath->getPathPointSet();
for (int ipp = 0; ipp < pathPointSet.getSize(); ++ipp) {
auto* pathPoint = pathPointSet.get(ipp).clone();
Expand All @@ -1037,7 +1034,8 @@ void DeGrooteFregly2016Muscle::replaceMuscles(
.getSocket(socketName)
.getConnecteeAsObject());
}
thisGeometryPath.updPathPointSet().adoptAndAppend(pathPoint);
actu->updGeometryPath().updPathPointSet()
.adoptAndAppend(pathPoint);
}

const auto& pathWrapSet = pGeometryPath->getWrapSet();
Expand All @@ -1050,8 +1048,14 @@ void DeGrooteFregly2016Muscle::replaceMuscles(
.getSocket(socketName)
.getConnecteeAsObject());
}
thisGeometryPath.updWrapSet().adoptAndAppend(pathWrap);
actu->updGeometryPath().updWrapSet()
.adoptAndAppend(pathWrap);
}
} else {
OPENSIM_THROW(Exception,
"Muscle '{}' contains supported path type {}.",
muscBase.getName(),
muscBase.getPath().getConcreteClassName())
}

std::string actname = actu->getName();
Expand Down
13 changes: 9 additions & 4 deletions OpenSim/Actuators/ModelFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,6 @@ void ModelFactory::replaceMusclesWithPathActuators(OpenSim::Model &model) {

// Copy the muscle's path.
if (auto* pGeometryPath = musc.tryUpdPath<GeometryPath>()) {
GeometryPath& thisGeometryPath = actu->initGeometryPath();

// For the connectee names in the PathPoints to be correct, we must
// add the path points after adding the PathActuator to the model.
const auto& pathPointSet = pGeometryPath->getPathPointSet();
Expand All @@ -188,7 +186,8 @@ void ModelFactory::replaceMusclesWithPathActuators(OpenSim::Model &model) {
.getSocket(socketName)
.getConnecteeAsObject());
}
thisGeometryPath.updPathPointSet().adoptAndAppend(pathPoint);
actu->updGeometryPath().updPathPointSet()
.adoptAndAppend(pathPoint);
}

// For the connectee names in the PathWraps to be correct, we must
Expand All @@ -203,8 +202,14 @@ void ModelFactory::replaceMusclesWithPathActuators(OpenSim::Model &model) {
.getSocket(socketName)
.getConnecteeAsObject());
}
thisGeometryPath.updWrapSet().adoptAndAppend(pathWrap);
actu->updGeometryPath().updWrapSet()
.adoptAndAppend(pathWrap);
}
} else {
OPENSIM_THROW(Exception,
"Muscle '{}' contains supported path type {}.",
musc.getName(),
musc.getPath().getConcreteClassName())
}

musclesToDelete.push_back(&musc);
Expand Down
6 changes: 3 additions & 3 deletions OpenSim/Simulation/Model/PathActuator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,13 @@ double PathActuator::getStress( const SimTK::State& s) const

//_____________________________________________________________________________
/**
* Add a Path point to the _path of the actuator. The new point is appended
* Add a Path point to the _path of the actuator. The new point is appended
* to the end of the current path
*
*/
void PathActuator::addNewPathPoint(
const std::string& proposedName,
const PhysicalFrame& aBody,
const std::string& proposedName,
const PhysicalFrame& aBody,
const SimTK::Vec3& aPositionOnBody) {
// Create new PathPoint already appended to the PathPointSet for the path
updGeometryPath().appendNewPathPoint(proposedName, aBody, aPositionOnBody);
Expand Down

0 comments on commit e57c1f6

Please sign in to comment.