8 #include <SpaceVecAlg/PTransform.h>
9 #include <fmt/format.h>
12 #if FMT_VERSION >= 9 * 10000
13 # define MC_FMT_STREAMED(X) fmt::streamed(X)
14 # include <boost/filesystem.hpp>
15 # include <eigen-fmt/fmt.h>
16 # include <filesystem>
17 # include <fmt/ostream.h>
21 struct fmt::formatter<
boost::filesystem::path> : fmt::formatter<std::string>
23 template<
typename FormatContext>
24 auto format(
const boost::filesystem::path & p, FormatContext & ctx)
26 return fmt::formatter<std::string>::format(p.string(), ctx);
32 struct fmt::formatter<
std::filesystem::path> : fmt::formatter<std::string>
34 template<
typename FormatContext>
35 auto format(
const std::filesystem::path & p, FormatContext & ctx)
37 return fmt::formatter<std::string>::format(p.string(), ctx);
74 int arg_id_vec = -1, arg_id_mat = -1;
76 const std::string default_vec_fmt =
"t;noal;p{3};csep{, };rpre{[};rsuf{]}";
77 const std::string default_mat_fmt =
"p{3};csep{, };rpre{ [};rsuf{]};rsep{\n}";
82 auto parse(format_parse_context & ctx)
84 auto it = ctx.begin(), end = ctx.end();
85 if(it == end || *it ==
'}')
return it;
89 arg_id_vec = ctx.next_arg_id();
90 if(it != end && *it ==
'}')
94 if(it != end && *it ==
'{')
97 arg_id_mat = ctx.next_arg_id();
98 if(it != end && *it ==
'}') { ++it; }
103 throw format_error(
"invalid format");
106 template<
typename FormatContext>
107 auto format(
const sva::PTransformd & pt, FormatContext & ctx)
const
110 std::string vec_fmt = default_vec_fmt;
111 std::string mat_fmt = default_mat_fmt;
115 vec_fmt = fmt::visit_format_arg(
116 [](
auto val) -> std::string
118 if constexpr(std::is_same_v<std::decay_t<decltype(val)>,
const char *>) {
return std::string(val); }
124 ctx.arg(arg_id_vec));
125 if(vec_fmt.empty()) vec_fmt = default_vec_fmt;
129 mat_fmt = fmt::visit_format_arg(
130 [](
auto && val) -> std::string
132 if constexpr(std::is_same_v<std::decay_t<decltype(val)>,
const char *>) {
return std::string(val); }
138 ctx.arg(arg_id_mat));
139 if(mat_fmt.empty()) mat_fmt = default_mat_fmt;
142 const auto & rotation_ft = pt.rotation();
143 auto rotation_std = pt.rotation().transpose();
151 return fmt::format_to(ctx.out(),
152 "translation: {:{}}\n"
154 " - matrix (Featherstone, left-handed convention):\n{:{}}\n"
155 " - matrix (Standard, right-handed convention):\n{:{}}\n"
156 " - rpy (Featherstone): {:{}} (rad), {:{}} (deg)\n"
157 " - rpy (standard): {:{}} (rad), {:{}} (deg)\n",
158 pt.translation(), vec_fmt, rotation_ft, mat_fmt, rotation_std, mat_fmt, rpy_ft, vec_fmt,
159 rpy_ft_deg, vec_fmt, rpy_std, vec_fmt, rpy_std_deg, vec_fmt);
164 # define MC_FMT_STREAMED(X) X
Eigen::Vector3d rpyFromMat(const Eigen::Matrix3d &E)
Definition: rpy_utils.h:83
constexpr double PI
Definition: constants.h:18