-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPose.h
165 lines (140 loc) · 5.52 KB
/
Pose.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/*
* This file is part of ALVAR, A Library for Virtual and Augmented Reality.
*
* Copyright 2007-2012 VTT Technical Research Centre of Finland
*
* Contact: VTT Augmented Reality Team <[email protected]>
* <http://www.vtt.fi/multimedia/alvar.html>
*
* ALVAR is free software; you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with ALVAR; if not, see
* <http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html>.
*/
#ifndef POSE_H
#define POSE_H
/*****************************************************************************
****************************** I N C L U D E ******************************
****************************************************************************/
#include "Alvar.h"
#include "Rotation.h"
/**
* \file Pose.h
*
* \brief This file implements a pose.
*/
namespace alvar {
/*****************************************************************************
*
*** class Pose
*
* Pose representation
*
* The rotation part of the transformation is handled by \e Rotation .
* The translation part is stored internally using homogeneous 4-vector.
*
* Internally in ALVAR we assume coordinate system where
* 'x' is right, 'y' is down, and 'z' is forward. However
* the \e SetMatrixGL and \e GetMatrixGL change the pose
* to support coordinates commonly used in OpenGL:
* 'x' is right, 'y' is up, and 'z' is backward.
*
*****************************************************************************/
class ALVAR_EXPORT Pose
{
// Note, although we are using homogeneous coordinates x, y, z, w -- w is now mostly ignored
public:
/** \e Constructor */
Pose();
~Pose() = default;
/** \e Constructor using the given translation and rotation elements
* \param tra Column vector containing three translation elements
* \param rot Handled using the \e Rotation class
* \param t Handled using the \e Rotation class
*/
Pose(cv::Mat& tra, cv::Mat_<double>& rot, Rotation::RotationType t);
/** \e Constructor with 3x3, 3x4 or 4x4 matrix representation
* \param mat A 3x3 rotation matrix or 3x4 / 4x4 transformation matrix
*/
Pose(cv::Mat_<double>& mat);
/** \e Copy constructor */
Pose(const Pose& src);
/** Assignment operator for copying \e Pose class */
Pose& operator = (const Pose& rhs);
/** \e Reset the pose */
void Reset();
/** Set the transformation from the given matrix \e mat
* \param mat A 3x3 rotation matrix or 3x4 / 4x4 transformation matrix
*/
void SetMatrix(const cv::Mat& mat);
/** \brief Set the \e Pose using OpenGL's transposed format.
* Note, that by default this also mirrors both the y- and z-axis (see \e Camera and \e Pose for more information)
* \param gl OpenGL 4x4 transformation matrix elements in column-order
*/
void SetMatrixGL(double gl[16], bool mirror = true);
void SetRodrigues(cv::Mat_<double>& rod)
{
rotation.SetRodrigues(rod);
return;
}
cv::Mat_<double> GetRodrigues() const
{
return (rotation.GetRodrigues());
}
/** Get the transformation into the given matrix \e mat
* \param mat A 3x3 rotation matrix
*/
cv::Mat_<double> GetRotationMatrix() const
{
return (rotation.GetMatrix());
}
/** Get the transformation into the given matrix \e mat
* \param mat A 3x3 rotation matrix
*/
cv::Mat_<double> GetHomogeneousMatrix() const;
/** \brief Get the transformation matrix representation of the \e Pose using OpenGL's transposed format.
* Note, that by default this also mirrors both the y- and z-axis (see \e Camera and \e Pose for more information)
* \param gl OpenGL 4x4 transformation matrix elements in column-order
*/
void GetMatrixGL(double gl[16], bool mirror=true);
/** \e Transpose the transformation */
void Transpose();
/** Invert the pose */
void Invert();
/** \e Mirror the \e Pose
* \param x If true mirror the x-coordinates
* \param y If true mirror the y-coordinates
* \param z If true mirror the z-coordinates
*/
void Mirror(bool x, bool y, bool z);
/** Set the translation part for the \e Pose
* \param tra Column vector containing three translation elements
*/
void SetTranslation(const cv::Mat& tra);
/** Set the translation part for the \e Pose
* \param tra Array containing three translation elements
*/
void SetTranslation(const double* tra);
/** Set the translation part for the \e Pose */
void SetTranslation(const double x, const double y, const double z);
/** Get the translation part from the \e Pose
* \param tra Column vector where the three translation elements are filled in
*/
void GetTranslation(cv::Mat& tra) const;
/** \e Output for debugging purposes */
void Output() const;
protected:
Rotation rotation;
cv::Mat_<double> translation_mat;
}; // end of class Pose
} // namespace alvar
#endif