GCC Code Coverage Report


Directory: ./
File: src/util.cc
Date: 2025-05-04 12:09:19
Exec Total Coverage
Lines: 32 32 100.0%
Branches: 3 4 75.0%

Line Branch Exec Source
1 // Copyright (c) 2017-2018, Joseph Mirabel
2 // Authors: Joseph Mirabel (joseph.mirabel@laas.fr)
3 //
4
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are
7 // met:
8 //
9 // 1. Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 //
12 // 2. Redistributions in binary form must reproduce the above copyright
13 // notice, this list of conditions and the following disclaimer in the
14 // documentation and/or other materials provided with the distribution.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
27 // DAMAGE.
28
29 #include <hpp/pinocchio/util.hh>
30 #include <iostream>
31 #include <pinocchio/spatial/se3.hpp>
32
33 namespace hpp {
34 21 long& getpythonformat(std::ostream& o) {
35 // The slot to store the current python format type.
36
3/4
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 20 times.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
21 static const int pythonformat_index = std::ios::xalloc();
37 21 return o.iword(pythonformat_index);
38 }
39 2 std::ostream& setpyformat(std::ostream& o) {
40 2 getpythonformat(o) = 1;
41 2 return o;
42 }
43 1 std::ostream& unsetpyformat(std::ostream& o) {
44 1 getpythonformat(o) = 0;
45 1 return o;
46 }
47
48 // ::pinocchio::SE3
49 template <int Option>
50 struct HPP_PINOCCHIO_DLLAPI prettyPrint<pinocchio::SE3, Option> {
51 6 static std::ostream& run(std::ostream& os, const ::pinocchio::SE3& M) {
52 enum {
53 OneLine = ((Option & OutputFormatBits) == OneLineOutput),
54 Condensed = ((Option & OutputFormatBits) == CondensedOutput)
55 };
56 6 static const Eigen::IOFormat mfmt_py = eigen_format < OneLine || Condensed,
57 true, false > ::run();
58 6 static const Eigen::IOFormat vfmt_py = eigen_format < OneLine || Condensed,
59 true, true > ::run();
60 6 static const Eigen::IOFormat mfmt_raw = eigen_format < OneLine || Condensed,
61 false, false > ::run();
62 6 static const Eigen::IOFormat vfmt_raw = eigen_format < OneLine || Condensed,
63 false, true > ::run();
64 6 bool use_py_fmt = (getpythonformat(os) != 0);
65 6 const Eigen::IOFormat& vfmt = (use_py_fmt ? vfmt_py : vfmt_raw);
66
67 switch (Option & OutputFormatBits) {
68 case OneLineOutput:
69 2 return os << "q = "
70 2 << one_line(::pinocchio::SE3::Quaternion(M.rotation()))
71 2 << ", p = " << M.translation().transpose().format(vfmt);
72 case CondensedOutput:
73 2 return os << "q = "
74 2 << one_line(::pinocchio::SE3::Quaternion(M.rotation()))
75 2 << iendl
76 2 << "p = " << M.translation().transpose().format(vfmt);
77 case PrettyOutput:
78 default:
79 2 char po[] = "( ", pc[] = " )", sp[] = " ";
80 2 if (!use_py_fmt) {
81 1 po[0] = ' ';
82 1 pc[1] = ' ';
83 }
84 4 return os << "R = " << po << M.rotation().row(0).format(vfmt) << iendl
85 4 << " " << sp << M.rotation().row(1).format(vfmt) << iendl
86 4 << " " << sp << M.rotation().row(2).format(vfmt) << pc
87 2 << iendl
88 2 << "p = " << M.translation().transpose().format(vfmt);
89 }
90 }
91 };
92
93 template struct HPP_PINOCCHIO_DLLAPI prettyPrint<pinocchio::SE3, PrettyOutput>;
94 template struct HPP_PINOCCHIO_DLLAPI
95 prettyPrint<pinocchio::SE3, CondensedOutput>;
96 template struct HPP_PINOCCHIO_DLLAPI prettyPrint<pinocchio::SE3, OneLineOutput>;
97 } // namespace hpp
98