Skip to content

Commit aa816e9

Browse files
authored
Merge pull request #2535 from JafarAbdi/fix_unknown_size_vector
mjcf parser: Fix unknown size vector parsing
2 parents 600b2ac + f3cf7e5 commit aa816e9

File tree

3 files changed

+35
-4
lines changed

3 files changed

+35
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
1111
- Fix aba explicit template instantiation ([#2541](https://github.com/stack-of-tasks/pinocchio/pull/2541))
1212
- Add parsing meshes with vertices for MJCF format ([#2537](https://github.com/stack-of-tasks/pinocchio/pull/2537))
1313
- CMake: fix RPATH on macos ([#2546](https://github.com/stack-of-tasks/pinocchio/pull/2546))
14+
- Fix aba explicit template instantiation ([#2541](https://github.com/stack-of-tasks/pinocchio/pull/2541))
15+
- Fix mjcf parsing of keyframe qpos with newlines ([#2535](https://github.com/stack-of-tasks/pinocchio/pull/2535))
1416

1517
## [3.3.1] - 2024-12-13
1618

include/pinocchio/parsers/mjcf/mjcf-graph.hpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ namespace pinocchio
549549
inline std::istringstream getConfiguredStringStream(const std::string & str)
550550
{
551551
std::istringstream posStream(str);
552-
posStream.exceptions(std::ios::failbit);
552+
posStream.exceptions(std::ios::badbit);
553553
return posStream;
554554
}
555555

@@ -569,9 +569,8 @@ namespace pinocchio
569569
std::istringstream stream = getConfiguredStringStream(str);
570570
std::vector<double> vector;
571571
double elem;
572-
while (!stream.eof())
572+
while (stream >> elem)
573573
{
574-
stream >> elem;
575574
vector.push_back(elem);
576575
}
577576

unittest/mjcf.cpp

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "pinocchio/multibody/model.hpp"
99

1010
#include "pinocchio/parsers/mjcf.hpp"
11+
#include "pinocchio/parsers/mjcf/mjcf-graph.hpp"
1112
#include "pinocchio/parsers/urdf.hpp"
1213

1314
#include "pinocchio/algorithm/joint-configuration.hpp"
@@ -923,7 +924,8 @@ BOOST_AUTO_TEST_CASE(adding_keyframes)
923924
<key name="test"
924925
qpos="0 0 0.596
925926
0.988015 0 0.154359 0
926-
0.988015 0 0.154359 0"/>
927+
0.988015 0 0.154359 0
928+
"/>
927929
</keyframe>
928930
</mujoco>)");
929931

@@ -1398,4 +1400,32 @@ BOOST_AUTO_TEST_CASE(parse_mesh_with_vertices)
13981400
}
13991401
}
14001402

1403+
BOOST_AUTO_TEST_CASE(test_get_unknown_size_vector_from_stream)
1404+
{
1405+
const auto v = pinocchio::mjcf::details::internal::getUnknownSizeVectorFromStream("");
1406+
BOOST_CHECK(v.size() == 0);
1407+
1408+
const auto v1 = pinocchio::mjcf::details::internal::getUnknownSizeVectorFromStream("1 2 3");
1409+
BOOST_CHECK(v1.size() == 3);
1410+
Eigen::VectorXd expected(3);
1411+
expected << 1, 2, 3;
1412+
BOOST_CHECK(v1 == expected);
1413+
1414+
const auto v2 = pinocchio::mjcf::details::internal::getUnknownSizeVectorFromStream(R"(1 2 3
1415+
4 5 6)");
1416+
BOOST_CHECK(v2.size() == 6);
1417+
Eigen::VectorXd expected2(6);
1418+
expected2 << 1, 2, 3, 4, 5, 6;
1419+
BOOST_CHECK(v2 == expected2);
1420+
1421+
const auto v3 = pinocchio::mjcf::details::internal::getUnknownSizeVectorFromStream(R"(1 2 3
1422+
4 5 6
1423+
7 8 9
1424+
)");
1425+
BOOST_CHECK(v3.size() == 9);
1426+
Eigen::VectorXd expected3(9);
1427+
expected3 << 1, 2, 3, 4, 5, 6, 7, 8, 9;
1428+
BOOST_CHECK(v3 == expected3);
1429+
}
1430+
14011431
BOOST_AUTO_TEST_SUITE_END()

0 commit comments

Comments
 (0)