My Project
Rotation.h
Go to the documentation of this file.
1 /*
2  * This file is part of ALVAR, A Library for Virtual and Augmented Reality.
3  *
4  * Copyright 2007-2012 VTT Technical Research Centre of Finland
5  *
6  * Contact: VTT Augmented Reality Team <alvar.info@vtt.fi>
7  * <http://www.vtt.fi/multimedia/alvar.html>
8  *
9  * ALVAR is free software; you can redistribute it and/or modify it under the
10  * terms of the GNU Lesser General Public License as published by the Free
11  * Software Foundation; either version 2.1 of the License, or (at your option)
12  * any later version.
13  *
14  * This library is distributed in the hope that it will be useful, but WITHOUT
15  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
17  * for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public License
20  * along with ALVAR; if not, see
21  * <http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html>.
22  */
23 
24 #ifndef ROTATION_H
25 #define ROTATION_H
26 
27 #include <iostream>
28 #include <opencv2/opencv.hpp>
29 
36 #include "Alvar.h"
37 #include "Util.h"
38 
39 namespace alvar {
40 
44 class ALVAR_EXPORT Rotation
45 {
46 protected:
47  double quaternion[4];
48  cv::Mat quaternion_mat;
49 
50 public:
54  enum RotationType { QUAT, MAT, EUL, ROD };
55 
56  Rotation();
57  Rotation(const Rotation &r);
58 
64  Rotation(const cv::Mat &data, RotationType t);
65 
66  Rotation &operator=(const Rotation &p);
67  Rotation &operator+=(const Rotation &v);
68  //Rotation& operator + () {return *this;}
69 
70  void Transpose();
71 
79  static void MirrorMat(cv::Mat &mat, bool x, bool y, bool z);
80 
87  void Mirror(bool x, bool y, bool z);
88 
92  void Reset();
93 
99  static void Mat9ToRod(double *mat, double *rod);
100 
106  static void RodToMat9(const double *rod, double *mat);
107 
113  static void QuatInv(const double *q, double *qi);
114 
119  static void QuatNorm(double *q);
120 
127  static void QuatMul(const double *q1, const double *q2, double *q3);
128 
129  //% The quaternion has to be normalized!!!
135  static void QuatToMat9(const double *quat, double *mat);
136 
137  // TODO: Now we don't want to eliminate the translation part from the matrix here. Did this change break something???
143  static void QuatToMat16(const double *quat, double *mat);
144 
150  static void QuatToEul(const double *q, double *eul);
151 
157  static void Mat9ToQuat(const double *mat, double *quat);
158 
164  static void EulToQuat(const double *eul, double *quat);
165 
170  void SetQuaternion(const cv::Mat &mat);
171 
176  void SetQuaternion(const double *quat);
177 
182  void SetEuler(const cv::Mat &mat);
183 
188  void SetRodriques(const cv::Mat &mat);
189 
194  void SetMatrix(const cv::Mat &mat);
195 
200  void GetMatrix(cv::Mat &mat) const;
201 
206  void GetRodriques(cv::Mat &mat) const;
207 
212  void GetEuler(cv::Mat &mat) const;
213 
218  void GetQuaternion(cv::Mat &mat) const;
219 };
220 
221 } // namespace alvar
222 
223 #endif
This file defines library export definitions, version numbers and build information.
This file implements generic utility functions and a serialization interface.
Rotation structure and transformations between different parameterizations.
Definition: Rotation.h:45
static void QuatToMat16(const double *quat, double *mat)
Converts a rotation described by a quaternion into 4x4 OpenGL-like transformation matrix....
void GetQuaternion(cv::Mat &mat) const
Returns the rotation in quaternion form.
Rotation(const cv::Mat &data, RotationType t)
Constructor.
void Reset()
Resets the rotation into identity.
static void QuatToMat9(const double *quat, double *mat)
Converts a rotation described by a quaternion into 3x3 rotation matrix.
void GetRodriques(cv::Mat &mat) const
Returns the rotation in rotation vector form.
void SetQuaternion(const cv::Mat &mat)
Sets the rotation from given quaternion.
static void QuatNorm(double *q)
Normalizes a quaternion.
static void EulToQuat(const double *eul, double *quat)
Converts a rotation described by Euler angles into quaternion form.
void SetMatrix(const cv::Mat &mat)
Sets the rotation from given rotation matrix. 3x3 and 4x4 matrices are allowed.
void SetEuler(const cv::Mat &mat)
Sets the rotation from given Euler angles.
void GetMatrix(cv::Mat &mat) const
Returns the rotation in matrix form. 3x3 and 4x4 matrices are allowed.
static void RodToMat9(const double *rod, double *mat)
Converts 3x1 rotation vector into 3x3 rotation matrix using Rodriques' formula.
static void QuatInv(const double *q, double *qi)
Inverts unit quaternion.
void SetQuaternion(const double *quat)
Sets the rotation from given quaternion.
void Mirror(bool x, bool y, bool z)
Mirrors the rotation in selected directions.
static void MirrorMat(cv::Mat &mat, bool x, bool y, bool z)
Simple function to mirror a rotation matrix in different directions.
static void Mat9ToQuat(const double *mat, double *quat)
Converts a 3x3 rotation martix into quaternion form.
RotationType
Rotation can be represented in four ways: quaternion (QUAT), matrix (MAT), euler angles (EUL) and exp...
Definition: Rotation.h:54
static void Mat9ToRod(double *mat, double *rod)
Converts 3x3 rotation matrix into Rodriques representation.
static void QuatToEul(const double *q, double *eul)
Converts a rotation described by a quaternion into Euler angles.
void SetRodriques(const cv::Mat &mat)
Sets the rotation from given rotation vector.
static void QuatMul(const double *q1, const double *q2, double *q3)
Quaternion multiplication.
void GetEuler(cv::Mat &mat) const
Returns the rotation in Euler angles.
Main ALVAR namespace.
Definition: Alvar.h:174