Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mjcf parser: Fix unknown size vector parsing #2535

Merged
merged 5 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
### Fixed
- Fix mjcf Euler angle parsing: use xyz as a default value for eulerseq compiler option ([#2526](https://github.com/stack-of-tasks/pinocchio/pull/2526))
- Add parsing meshes with vertices for MJCF format ([#2537](https://github.com/stack-of-tasks/pinocchio/pull/2537))
- Fix aba explicit template instantiation ([#2541](https://github.com/stack-of-tasks/pinocchio/pull/2541))
- Fix mjcf parsing of keyframe qpos with newlines ([#2535](https://github.com/stack-of-tasks/pinocchio/pull/2535))

## [3.3.1] - 2024-12-13

Expand Down
4 changes: 2 additions & 2 deletions include/pinocchio/algorithm/aba.txx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace pinocchio
{
extern template PINOCCHIO_EXPLICIT_INSTANTIATION_DEFINITION_DLLAPI const context::VectorXs & aba<
extern template PINOCCHIO_EXPLICIT_INSTANTIATION_DECLARATION_DLLAPI const context::VectorXs & aba<
context::Scalar,
context::Options,
JointCollectionDefaultTpl,
Expand All @@ -21,7 +21,7 @@ namespace pinocchio
const Eigen::MatrixBase<Eigen::Ref<const context::VectorXs>> &,
const Convention);

extern template PINOCCHIO_EXPLICIT_INSTANTIATION_DEFINITION_DLLAPI const context::VectorXs & aba<
extern template PINOCCHIO_EXPLICIT_INSTANTIATION_DECLARATION_DLLAPI const context::VectorXs & aba<
context::Scalar,
context::Options,
JointCollectionDefaultTpl,
Expand Down
5 changes: 2 additions & 3 deletions include/pinocchio/parsers/mjcf/mjcf-graph.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ namespace pinocchio
inline std::istringstream getConfiguredStringStream(const std::string & str)
{
std::istringstream posStream(str);
posStream.exceptions(std::ios::failbit);
posStream.exceptions(std::ios::badbit);
return posStream;
}

Expand All @@ -569,9 +569,8 @@ namespace pinocchio
std::istringstream stream = getConfiguredStringStream(str);
std::vector<double> vector;
double elem;
while (!stream.eof())
while (stream >> elem)
{
stream >> elem;
vector.push_back(elem);
}

Expand Down
32 changes: 31 additions & 1 deletion unittest/mjcf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "pinocchio/multibody/model.hpp"

#include "pinocchio/parsers/mjcf.hpp"
#include "pinocchio/parsers/mjcf/mjcf-graph.hpp"
#include "pinocchio/parsers/urdf.hpp"

#include "pinocchio/algorithm/joint-configuration.hpp"
Expand Down Expand Up @@ -923,7 +924,8 @@ BOOST_AUTO_TEST_CASE(adding_keyframes)
<key name="test"
qpos="0 0 0.596
0.988015 0 0.154359 0
0.988015 0 0.154359 0"/>
0.988015 0 0.154359 0
"/>
MegMll marked this conversation as resolved.
Show resolved Hide resolved
</keyframe>
</mujoco>)");

Expand Down Expand Up @@ -1398,4 +1400,32 @@ BOOST_AUTO_TEST_CASE(parse_mesh_with_vertices)
}
}

BOOST_AUTO_TEST_CASE(test_get_unknown_size_vector_from_stream)
{
const auto v = pinocchio::mjcf::details::internal::getUnknownSizeVectorFromStream("");
BOOST_CHECK(v.size() == 0);

const auto v1 = pinocchio::mjcf::details::internal::getUnknownSizeVectorFromStream("1 2 3");
BOOST_CHECK(v1.size() == 3);
Eigen::VectorXd expected(3);
expected << 1, 2, 3;
BOOST_CHECK(v1 == expected);

const auto v2 = pinocchio::mjcf::details::internal::getUnknownSizeVectorFromStream(R"(1 2 3
4 5 6)");
BOOST_CHECK(v2.size() == 6);
Eigen::VectorXd expected2(6);
expected2 << 1, 2, 3, 4, 5, 6;
BOOST_CHECK(v2 == expected2);

const auto v3 = pinocchio::mjcf::details::internal::getUnknownSizeVectorFromStream(R"(1 2 3
4 5 6
7 8 9
)");
BOOST_CHECK(v3.size() == 9);
Eigen::VectorXd expected3(9);
expected3 << 1, 2, 3, 4, 5, 6, 7, 8, 9;
BOOST_CHECK(v3 == expected3);
}

BOOST_AUTO_TEST_SUITE_END()
Loading