20 #ifndef HPP_PINOCCHIO_UTIL_HH 21 # define HPP_PINOCCHIO_UTIL_HH 23 # include <hpp/util/indent.hh> 25 # include <hpp/pinocchio/config.hh> 67 template <
typename T,
int Option>
struct HPP_PINOCCHIO_DLLAPI
prettyPrint {
static std::ostream& run (std::ostream& os,
const T& pp); };
79 HPP_PINOCCHIO_DLLAPI
long& getpythonformat (std::ostream&
o);
81 template <
bool OneLine,
bool PythonStyle,
bool Vector>
82 struct HPP_PINOCCHIO_DLLAPI eigen_format {
static const Eigen::IOFormat run(); };
85 template <
bool OneLine,
bool PythonStyle,
bool Vector>
const Eigen::IOFormat
86 eigen_format<OneLine, PythonStyle, Vector>::run() {
87 static const Eigen::IOFormat fmt(
88 (PythonStyle ? Eigen::FullPrecision : Eigen::StreamPrecision),
92 ? (OneLine ?
", ":
",\n" )
93 : (OneLine ?
"; ":
"\n" )),
94 (PythonStyle ?
"(" :
""),
95 (PythonStyle ?
",)" :
""),
96 (PythonStyle && !Vector ?
"( " :
""),
97 (PythonStyle && !Vector ?
", )" :
"")
102 template <
typename T,
int Option>
struct PrettyPrint {
104 inline explicit PrettyPrint (
const T&
t) : value (t) {}
107 template <
typename T,
int Option>
108 std::ostream& operator<< (std::ostream& os, const PrettyPrint<T, Option> pp)
114 template <
typename Derived,
int Option>
115 struct HPP_PINOCCHIO_DLLAPI prettyPrintEigen {
116 static inline std::ostream& run (std::ostream& os,
const Derived& M)
119 static const Eigen::IOFormat mfmt_py = eigen_format< Condensed, true , false>::run();
120 static const Eigen::IOFormat vfmt_py = eigen_format< Condensed, true , true >::run();
121 static const Eigen::IOFormat mfmt_raw = eigen_format< Condensed, false, false>::run();
122 static const Eigen::IOFormat vfmt_raw = eigen_format< Condensed, false, true >::run();
123 bool use_py_fmt = (getpythonformat(os) != 0);
124 const Eigen::IOFormat& fmt =
125 (Derived::IsVectorAtCompileTime
126 ? (use_py_fmt ? vfmt_py : vfmt_raw)
127 : (use_py_fmt ? mfmt_py : mfmt_raw));
128 bool transpose = (Derived::ColsAtCompileTime == 1);
130 if (transpose)
return os << M.transpose().format(fmt);
131 else return os << M.format(fmt);
137 template<
typename _Scalar,
int _Rows,
int _Cols,
int _Options,
int _MaxRows,
int _MaxCols,
int Option>
138 struct HPP_PINOCCHIO_DLLAPI
prettyPrint <
Eigen::Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols >, Option>
139 : prettyPrintEigen <Eigen::Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols >, Option> {};
142 template<
typename OtherDerived,
int Size,
int Option>
143 struct HPP_PINOCCHIO_DLLAPI
prettyPrint <Eigen::VectorBlock< OtherDerived, Size >, Option>
144 : prettyPrintEigen <Eigen::VectorBlock< OtherDerived, Size >, Option > {};
147 template<
typename XprType,
int BlockRows,
int BlockCols,
bool InnerPanel,
int Option>
148 struct HPP_PINOCCHIO_DLLAPI
prettyPrint <Eigen::Block<XprType, BlockRows, BlockCols, InnerPanel>, Option>
149 : prettyPrintEigen <Eigen::Block<XprType, BlockRows, BlockCols, InnerPanel>, Option > {};
152 template<
typename _PlainObjectType,
int _Options,
typename _Str
ideType,
int Option>
153 struct HPP_PINOCCHIO_DLLAPI
prettyPrint <Eigen::Ref< _PlainObjectType, _Options, _StrideType>, Option>
154 : prettyPrintEigen <Eigen::Ref< _PlainObjectType, _Options, _StrideType>, Option> {};
157 template<
typename _Scalar,
int _Options,
int Option>
158 struct HPP_PINOCCHIO_DLLAPI
prettyPrint <Eigen::Quaternion< _Scalar, _Options>, Option>
160 typedef Eigen::Quaternion< _Scalar, _Options> Derived;
161 typedef typename Eigen::internal::traits<Derived>::Coefficients Coefficients;
162 static inline std::ostream& run (std::ostream& os,
const Derived& M)
170 HPP_PINOCCHIO_DLLAPI std::ostream&
setpyformat (std::ostream&
o);
173 HPP_PINOCCHIO_DLLAPI std::ostream&
unsetpyformat (std::ostream&
o);
176 template <
typename T>
inline PrettyPrint<T, PrettyOutput >
pretty_print (
const T&
t) {
return PrettyPrint<T, PrettyOutput >(
t); }
178 template <
typename T>
inline PrettyPrint<T, CondensedOutput >
condensed (
const T&
t) {
return PrettyPrint<T, CondensedOutput >(
t); }
180 template <
typename T>
inline PrettyPrint<T, OneLineOutput >
one_line (
const T&
t) {
return PrettyPrint<T, OneLineOutput >(
t); }
184 #endif // HPP_PINOCCHIO_UTIL_HH
static std::ostream & run(std::ostream &os, const T &pp)
HPP_PINOCCHIO_DLLAPI std::ostream & setpyformat(std::ostream &o)
This function must be specialized for the type you want to print.
Definition: util.hh:67
PrettyPrint< T, PrettyOutput > pretty_print(const T &t)
Pretty printing.
Definition: util.hh:176
HPP_PINOCCHIO_DLLAPI std::ostream & unsetpyformat(std::ostream &o)
PrettyPrint< T, CondensedOutput > condensed(const T &t)
Condensed printing.
Definition: util.hh:178
PrettyPrint< T, OneLineOutput > one_line(const T &t)
Print on one line.
Definition: util.hh:180