6 #ifndef FLEXIVRDK_UTILITY_HPP_
7 #define FLEXIVRDK_UTILITY_HPP_
10 #include <Eigen/Eigen>
25 inline std::vector<double>
quat2EulerZYX(
const std::vector<double>& quat)
28 if (quat.size() != 4) {
30 "[flexiv::utility] quat2EulerZYX: input vector is not size 4");
34 Eigen::Quaterniond q(quat[0], quat[1], quat[2], quat[3]);
37 auto eulerZYX = q.toRotationMatrix().eulerAngles(2, 1, 0);
40 return (std::vector<double> {eulerZYX[2], eulerZYX[1], eulerZYX[0]});
48 constexpr
double k_pi = 3.14159265358979323846;
49 return (rad / k_pi * 180.0);
55 inline std::vector<double>
rad2Deg(
const std::vector<double>& radVec)
57 std::vector<double> degVec = {};
58 for (
const auto& v : radVec) {
74 const std::vector<T>& vec,
size_t decimal = 3,
bool trailingSpace =
true)
78 ss.precision(decimal);
81 for (
const auto& v : vec) {
100 template <
typename T,
size_t N>
102 const std::array<T, N>& arr,
size_t decimal = 3,
bool trailingSpace =
true)
105 std::stringstream ss;
106 ss.precision(decimal);
109 for (
const auto& v : arr) {
129 int argc,
char** argv,
const std::vector<std::string>& refStrs)
131 for (
int i = 0; i < argc; i++) {
132 for (
const auto& v : refStrs) {
133 if (v == std::string(argv[i])) {
164 const std::vector<std::string>& ptStates,
const std::string& parseTarget)
166 for (
const auto& state : ptStates) {
171 std::stringstream ss(state);
173 std::vector<std::string> parsedState;
174 while (ss >> buffer) {
175 parsedState.push_back(buffer);
177 if (parsedState.front() == parseTarget) {
178 return parsedState.back();
std::string vec2Str(const std::vector< T > &vec, size_t decimal=3, bool trailingSpace=true)
Convert a std::vector to a string.
std::string arr2Str(const std::array< T, N > &arr, size_t decimal=3, bool trailingSpace=true)
Convert a std::array to a string.
std::string parsePtStates(const std::vector< std::string > &ptStates, const std::string &parseTarget)
Parse the value of a specified primitive state from the ptStates string list.
bool programArgsExist(int argc, char **argv, const std::string &refStr)
Check if one specific string exists in the program arguments.
bool programArgsExistAny(int argc, char **argv, const std::vector< std::string > &refStrs)
Check if any provided strings exist in the program arguments.
double rad2Deg(double rad)
Convert radians to degrees for a single value.
std::vector< double > quat2EulerZYX(const std::vector< double > &quat)
Convert quaternion to Euler angles with ZYX axis rotations.