6 #ifndef FLEXIV_RDK_UTILITY_HPP_
7 #define FLEXIV_RDK_UTILITY_HPP_
23 inline std::array<double, 3>
Quat2EulerZYX(
const std::array<double, 4>& quat)
26 Eigen::Quaterniond q(quat[0], quat[1], quat[2], quat[3]);
29 auto euler_ZYX = q.toRotationMatrix().eulerAngles(2, 1, 0);
32 return (std::array<double, 3> {euler_ZYX[2], euler_ZYX[1], euler_ZYX[0]});
40 constexpr
double kPi = 3.14159265358979323846;
41 return (rad / kPi * 180.0);
48 inline std::array<double, N>
Rad2Deg(
const std::array<double, N>& rad_arr)
50 std::array<double, N> deg_arr;
51 for (
size_t i = 0; i < N; i++) {
52 deg_arr[i] =
Rad2Deg(rad_arr[i]);
67 inline std::string
Vec2Str(
const std::vector<T>& vec,
size_t decimal = 3,
68 bool trailing_space =
true,
const std::string& separator =
" ")
70 std::string padding =
"";
72 ss.precision(decimal);
75 for (
const auto& v : vec) {
95 template <
typename T,
size_t N>
96 inline std::string
Arr2Str(
const std::array<T, N>& arr,
size_t decimal = 3,
97 bool trailing_space =
true,
const std::string& separator =
" ")
99 std::vector<T> vec(N);
100 std::copy(arr.begin(), arr.end(), vec.begin());
101 return Vec2Str(vec, decimal, trailing_space, separator);
114 for (
int i = 0; i < argc; i++) {
115 for (
const auto& v : ref_strings) {
116 if (v == std::string(argv[i])) {
145 const std::vector<std::string>& pt_states,
const std::string& parse_target)
147 for (
const auto& state : pt_states) {
152 std::stringstream ss(state);
154 std::vector<std::string> parsed_state;
155 while (ss >> buffer) {
156 parsed_state.push_back(buffer);
158 if (parsed_state.front() == parse_target) {
159 return parsed_state.back();
std::array< double, 3 > Quat2EulerZYX(const std::array< double, 4 > &quat)
Convert quaternion to Euler angles with ZYX axis rotations.
std::string ParsePtStates(const std::vector< std::string > &pt_states, const std::string &parse_target)
Parse the value of a specified primitive state from the pt_states string list.
bool ProgramArgsExist(int argc, char **argv, const std::string &ref_strings)
Check if one specific string exists in the program arguments.
std::string Vec2Str(const std::vector< T > &vec, size_t decimal=3, bool trailing_space=true, const std::string &separator=" ")
Convert an std::vector to a string.
std::string Arr2Str(const std::array< T, N > &arr, size_t decimal=3, bool trailing_space=true, const std::string &separator=" ")
Convert an std::array to a string.
double Rad2Deg(double rad)
Convert radians to degrees for a single value.
bool ProgramArgsExistAny(int argc, char **argv, const std::vector< std::string > &ref_strings)
Check if any provided strings exist in the program arguments.