31 #ifndef HPP_PINOCCHIO_UTIL_HH
32 #define HPP_PINOCCHIO_UTIL_HH
36 #include <hpp/util/indent.hh>
77 template <
typename T,
int Option>
79 static std::ostream&
run(std::ostream& os,
const T& pp);
94 template <
bool OneLine,
bool PythonStyle,
bool Vector>
96 static const Eigen::IOFormat run();
100 template <
bool OneLine,
bool PythonStyle,
bool Vector>
101 const Eigen::IOFormat eigen_format<OneLine, PythonStyle, Vector>::run() {
102 static const Eigen::IOFormat fmt(
103 (PythonStyle ? Eigen::FullPrecision : Eigen::StreamPrecision), 0,
106 ? (OneLine ?
", " :
",\n")
107 : (OneLine ?
"; " :
"\n")),
108 (PythonStyle ?
"(" :
""),
109 (PythonStyle ?
",)" :
""),
110 (PythonStyle && !Vector ?
"( " :
""),
111 (PythonStyle && !Vector ?
", )" :
"")
116 template <
typename T,
int Option>
119 inline explicit PrettyPrint(
const T& t) : value(t) {}
122 template <
typename T,
int Option>
123 std::ostream&
operator<<(std::ostream& os,
const PrettyPrint<T, Option> pp) {
128 template <
typename Derived,
int Option>
130 static inline std::ostream &
131 run(std::ostream & os,
const Derived& M){
134 static const Eigen::IOFormat mfmt_py =
135 eigen_format<Condensed, true, false>::run();
136 static const Eigen::IOFormat vfmt_py =
137 eigen_format<Condensed, true, true>::run();
138 static const Eigen::IOFormat mfmt_raw =
139 eigen_format<Condensed, false, false>::run();
140 static const Eigen::IOFormat vfmt_raw =
141 eigen_format<Condensed, false, true>::run();
142 bool use_py_fmt = (getpythonformat(os) != 0);
143 const Eigen::IOFormat& fmt =
144 (Derived::IsVectorAtCompileTime ? (use_py_fmt ? vfmt_py : vfmt_raw)
145 : (use_py_fmt ? mfmt_py : mfmt_raw));
146 bool transpose = (Derived::ColsAtCompileTime == 1);
149 return os << M.transpose().format(fmt);
151 return os << M.format(fmt);
158 template <
typename _Scalar,
int _Rows,
int _Cols,
int _Options,
int _MaxRows,
159 int _MaxCols,
int Option>
161 Eigen::Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>, Option>
163 Eigen::Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>,
167 template <
typename OtherDerived,
int Size,
int Option>
169 prettyPrint<Eigen::VectorBlock<OtherDerived, Size>, Option>
170 : prettyPrintEigen<Eigen::VectorBlock<OtherDerived, Size>, Option> {};
173 template <
typename XprType,
int BlockRows,
int BlockCols,
bool InnerPanel,
176 prettyPrint<Eigen::Block<XprType, BlockRows, BlockCols, InnerPanel>, Option>
177 : prettyPrintEigen<Eigen::Block<XprType, BlockRows, BlockCols, InnerPanel>,
181 template <
typename _PlainObjectType,
int _Options,
typename _StrideType,
184 prettyPrint<Eigen::Ref<_PlainObjectType, _Options, _StrideType>, Option>
185 : prettyPrintEigen<Eigen::Ref<_PlainObjectType, _Options, _StrideType>,
189 template <
typename _PlainObjectType,
int Option>
191 prettyPrint<Eigen::Transpose<_PlainObjectType>, Option>
192 : prettyPrintEigen<Eigen::Transpose<_PlainObjectType>, Option> {};
195 template <
typename _Scalar,
int _Options,
int Option>
197 prettyPrint<Eigen::Quaternion<_Scalar, _Options>, Option> {
198 typedef Eigen::Quaternion<_Scalar, _Options> Derived;
199 typedef typename Eigen::internal::traits<Derived>::Coefficients Coefficients;
200 static inline std::ostream& run(std::ostream& os,
const Derived& M) {
213 template <
typename T>
215 return PrettyPrint<T, PrettyOutput>(t);
218 template <
typename T>
219 inline PrettyPrint<T, CondensedOutput>
condensed(
const T& t) {
220 return PrettyPrint<T, CondensedOutput>(t);
223 template <
typename T>
224 inline PrettyPrint<T, OneLineOutput>
one_line(
const T& t) {
225 return PrettyPrint<T, OneLineOutput>(t);
#define HPP_PINOCCHIO_DLLAPI
Definition: config.hh:88
PrettyPrint< T, PrettyOutput > pretty_print(const T &t)
Pretty printing.
Definition: util.hh:214
PrettyPrint< T, CondensedOutput > condensed(const T &t)
Condensed printing.
Definition: util.hh:219
HPP_PINOCCHIO_DLLAPI std::ostream & unsetpyformat(std::ostream &o)
PrettyPrint< T, OneLineOutput > one_line(const T &t)
Print on one line.
Definition: util.hh:224
HPP_PINOCCHIO_DLLAPI std::ostream & setpyformat(std::ostream &o)
@ PrettyOutput
Definition: util.hh:88
@ CondensedOutput
Definition: util.hh:87
@ OutputFormatBits
Definition: util.hh:84
@ OneLineOutput
Definition: util.hh:86
std::ostream & operator<<(std::ostream &os, const hpp::pinocchio::Device &device)
Definition: device.hh:366
Utility functions.
Definition: body.hh:39
This function must be specialized for the type you want to print.
Definition: util.hh:78
static std::ostream & run(std::ostream &os, const T &pp)