31 OpenSim_DECLARE_PROPERTY(station_path, std::string,
"Absolute path (e.g. `/componentset/some_station`) to a `Station` component in the model");
32 OpenSim_DECLARE_PROPERTY(wrap_cylinder_path, std::string,
"Absolute path (e.g. `/bodyset/body/wrap_cylinder_2`) to a `WrapCylinder` component in the model");
35 ScalingStep{
"Recalculate WrapCylinder 'xyz_body_rotation' from Station Placed Along Its Midline"}
37 setDescription(
"Recalculates the 'xyz_body_rotation' of a `WrapCylinder` component, located at `wrap_cylinder_path` such that the cylinder's +Z direction (midline) points toward the Station component located at `station_path`");
38 constructProperty_station_path(
"");
39 constructProperty_wrap_cylinder_path(
"");
45 const OpenSim::Model&
model)
const final
47 std::vector<ScalingStepValidationMessage> messages;
50 const auto* station = FindComponent<OpenSim::Station>(
model, get_station_path());
52 std::stringstream msg;
53 msg << get_station_path() <<
": Cannot find `station_path` in the source model (or it isn't a Station).";
58 const auto* wrapCylinder = FindComponent<OpenSim::WrapCylinder>(
model, get_wrap_cylinder_path());
59 if (not wrapCylinder) {
60 std::stringstream msg;
61 msg << get_wrap_cylinder_path() <<
": Cannot find 'wrap_cylinder_path' in the source model (or it isn't a `WrapCylinder`).";
71 const OpenSim::Model&,
72 OpenSim::Model& resultModel)
const final
77 const auto* station = FindComponent<OpenSim::Station>(resultModel, get_station_path());
79 auto* wrapCylinder = FindComponentMut<OpenSim::WrapCylinder>(resultModel, get_wrap_cylinder_path());
83 const SimTK::Transform cylinder2cylinderFrame = wrapCylinder->getTransform();
84 const SimTK::Transform cylinderFrame2ground = wrapCylinder->getFrame().getTransformInGround(resultModel.getWorkingState());
85 const SimTK::Transform ground2cylinder = (cylinderFrame2ground * cylinder2cylinderFrame).invert();
86 const SimTK::Vec3 stationPosInCylinder = ground2cylinder * station->getLocationInGround(resultModel.getWorkingState());
89 const SimTK::UnitVec3 cylinderDirectionInCylinder{SimTK::CoordinateAxis::ZCoordinateAxis{}};
90 const SimTK::UnitVec3 stationDirectionInCylinder{stationPosInCylinder};
93 const auto cosRotationAngle = SimTK::dot(cylinderDirectionInCylinder, stationDirectionInCylinder);
94 if (abs(cosRotationAngle) >= 1.0 - SimTK::Eps) {
100 const auto rotationAngle = acos(cosRotationAngle);
101 const SimTK::UnitVec3 rotationAxis{SimTK::cross(cylinderDirectionInCylinder, stationDirectionInCylinder)};
102 const SimTK::Rotation rotation{rotationAngle, rotationAxis};
105 const SimTK::Rotation newRotation = cylinder2cylinderFrame.R() * rotation;
108 wrapCylinder->set_xyz_body_rotation(newRotation.convertRotationToBodyFixedXYZ());
Definition recalculate_wrap_cylinder_xyz_body_rotation_from_station_scaling_step.h:28
std::vector< ScalingStepValidationMessage > implValidate(ScalingCache &, const ScalingParameters &, const OpenSim::Model &model) const final
Definition recalculate_wrap_cylinder_xyz_body_rotation_from_station_scaling_step.h:42
void implApplyScalingStep(ScalingCache &, const ScalingParameters &, const OpenSim::Model &, OpenSim::Model &resultModel) const final
Definition recalculate_wrap_cylinder_xyz_body_rotation_from_station_scaling_step.h:68