OSVR Framework (Internal Development Docs)  0.6-1962-g59773924
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
QuatToEuler.h
Go to the documentation of this file.
1 
11 // Copyright 2016 Sensics, Inc.
12 //
13 // Licensed under the Apache License, Version 2.0 (the "License");
14 // you may not use this file except in compliance with the License.
15 // You may obtain a copy of the License at
16 //
17 // http://www.apache.org/licenses/LICENSE-2.0
18 //
19 // Unless required by applicable law or agreed to in writing, software
20 // distributed under the License is distributed on an "AS IS" BASIS,
21 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 // See the License for the specific language governing permissions and
23 // limitations under the License.
24 
25 #ifndef INCLUDED_QuatToEuler_h_GUID_146FCB5A_7820_4B98_5BED_3223776E8CDF
26 #define INCLUDED_QuatToEuler_h_GUID_146FCB5A_7820_4B98_5BED_3223776E8CDF
27 
28 // Internal Includes
29 #include "CSVCellGroup.h"
30 
31 // Library/third-party includes
32 #include <Eigen/Core>
33 #include <Eigen/Geometry>
34 #include <quat.h>
35 
36 // Standard includes
37 // - none
38 
39 namespace osvr {
40 namespace util {
41  struct QuatAsEulerTag;
42 
43  inline Eigen::Vector3d getEuler(Eigen::Quaterniond const &q) {
45  q_type quat;
46  quat[Q_W] = q.w();
47  quat[Q_X] = q.x();
48  quat[Q_Y] = q.y();
49  quat[Q_Z] = q.z();
50  Eigen::Vector3d ret;
51  // Actually gets yaw, pitch, roll in that order - not just any Euler
52  // angles.
53  q_to_euler(ret.data(), quat);
54  // This method seems terribly unreliable.
55  // return q.toRotationMatrix().eulerAngles(2, 0, 2);
56  return ret;
57  }
58 
59  template <typename T>
60  inline void operator<<(CellGroupProxy<T, QuatAsEulerTag> &group,
61  Eigen::Vector3d const &euler) {
62 #if 0
63  group << cell("rot.zprime", euler[0]) << cell("rot.xprime", euler[1])
64  << cell("rot.z", euler[2]);
65 #else
66  group << cell("yaw", euler[0]) << cell("pitch", euler[1])
67  << cell("roll", euler[2]);
68 
69 #endif
70  }
71  template <typename T>
72  inline void operator<<(CellGroupProxy<T, QuatAsEulerTag> &group,
73  Eigen::Quaterniond const &q) {
74  group << getEuler(q);
75  }
76 } // namespace util
77 } // namespace osvr
78 
79 #endif // INCLUDED_QuatToEuler_h_GUID_146FCB5A_7820_4B98_5BED_3223776E8CDF
Eigen::Vector3d getEuler(Eigen::Quaterniond const &q)
Definition: QuatToEuler.h:43
detail::Cell< T > cell(const char *header, T const &data)
Helper free function to make a CSV cell.
Definition: CSV.h:401