From e57c1f6d91c70f94d72b077a0b24fc64ef730773 Mon Sep 17 00:00:00 2001 From: Nicholas Bianco Date: Wed, 30 Aug 2023 10:19:41 -0700 Subject: [PATCH] Handle unsupported path types when replacing muscles --- OpenSim/Actuators/DeGrooteFregly2016Muscle.cpp | 16 ++++++++++------ OpenSim/Actuators/ModelFactory.cpp | 13 +++++++++---- OpenSim/Simulation/Model/PathActuator.cpp | 6 +++--- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/OpenSim/Actuators/DeGrooteFregly2016Muscle.cpp b/OpenSim/Actuators/DeGrooteFregly2016Muscle.cpp index 72bb79db3f..beab802644 100644 --- a/OpenSim/Actuators/DeGrooteFregly2016Muscle.cpp +++ b/OpenSim/Actuators/DeGrooteFregly2016Muscle.cpp @@ -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(&path)) { - auto& thisGeometryPath = actu->initGeometryPath(); - + if (auto* pGeometryPath = muscBase.tryUpdPath()) { const auto& pathPointSet = pGeometryPath->getPathPointSet(); for (int ipp = 0; ipp < pathPointSet.getSize(); ++ipp) { auto* pathPoint = pathPointSet.get(ipp).clone(); @@ -1037,7 +1034,8 @@ void DeGrooteFregly2016Muscle::replaceMuscles( .getSocket(socketName) .getConnecteeAsObject()); } - thisGeometryPath.updPathPointSet().adoptAndAppend(pathPoint); + actu->updGeometryPath().updPathPointSet() + .adoptAndAppend(pathPoint); } const auto& pathWrapSet = pGeometryPath->getWrapSet(); @@ -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(); diff --git a/OpenSim/Actuators/ModelFactory.cpp b/OpenSim/Actuators/ModelFactory.cpp index 340e7d8609..d3aa60a70a 100644 --- a/OpenSim/Actuators/ModelFactory.cpp +++ b/OpenSim/Actuators/ModelFactory.cpp @@ -174,8 +174,6 @@ void ModelFactory::replaceMusclesWithPathActuators(OpenSim::Model &model) { // Copy the muscle's path. if (auto* pGeometryPath = musc.tryUpdPath()) { - 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(); @@ -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 @@ -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); diff --git a/OpenSim/Simulation/Model/PathActuator.cpp b/OpenSim/Simulation/Model/PathActuator.cpp index 313dcfeff3..c420cd9e27 100644 --- a/OpenSim/Simulation/Model/PathActuator.cpp +++ b/OpenSim/Simulation/Model/PathActuator.cpp @@ -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);