-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGeometryTypes.cpp
157 lines (122 loc) · 2.95 KB
/
GeometryTypes.cpp
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
/*****************************************************************************
* GeometryTypes.cpp
* Example_MarkerBasedAR
******************************************************************************
* by Khvedchenia Ievgen, 5th Dec 2012
* http://computer-vision-talks.com
******************************************************************************
* Ch2 of the book "Mastering OpenCV with Practical Computer Vision Projects"
* Copyright Packt Publishing 2012.
* http://www.packtpub.com/cool-projects-with-opencv/book
*****************************************************************************/
#include "GeometryTypes.hpp"
Matrix44 Matrix44::getTransposed() const
{
Matrix44 t;
for (int i=0;i<4; i++)
for (int j=0;j<4;j++)
t.mat[i][j] = mat[j][i];
return t;
}
Matrix44 Matrix44::identity()
{
Matrix44 eye;
for (int i=0;i<4; i++)
for (int j=0;j<4;j++)
eye.mat[i][j] = i == j ? 1 : 0;
return eye;
}
Matrix44 Matrix44::getInvertedRT() const
{
Matrix44 t = identity();
for (int col=0;col<3; col++)
{
for (int row=0;row<3;row++)
{
// Transpose rotation component (inversion)
t.mat[row][col] = mat[col][row];
}
// Inverse translation component
t.mat[3][col] = - mat[3][col];
}
return t;
}
Matrix33 Matrix33::identity()
{
Matrix33 eye;
for (int i=0;i<3; i++)
for (int j=0;j<3;j++)
eye.mat[i][j] = i == j ? 1 : 0;
return eye;
}
Matrix33 Matrix33::getTransposed() const
{
Matrix33 t;
for (int i=0;i<3; i++)
for (int j=0;j<3;j++)
t.mat[i][j] = mat[j][i];
return t;
}
Vector3 Vector3::zero()
{
Vector3 v = { 0,0,0 };
return v;
}
Vector3 Vector3::operator-() const
{
Vector3 v = { -data[0],-data[1],-data[2] };
return v;
}
Transformation::Transformation()
: m_rotation(Matrix33::identity())
, m_translation(Vector3::zero())
{
}
Transformation::Transformation(const Matrix33& r, const Vector3& t)
: m_rotation(r)
, m_translation(t)
{
}
Matrix33& Transformation::r()
{
return m_rotation;
}
Vector3& Transformation::t()
{
return m_translation;
}
int& Transformation::id()
{
return iD;
}
const Matrix33& Transformation::r() const
{
return m_rotation;
}
const Vector3& Transformation::t() const
{
return m_translation;
}
const int& Transformation::id() const
{
return iD;
}
Matrix44 Transformation::getMat44() const
{
Matrix44 res = Matrix44::identity();
for (int col=0;col<3;col++)
{
for (int row=0;row<3;row++)
{
// Copy rotation component
res.mat[row][col] = m_rotation.mat[row][col];
}
// Copy translation component
res.mat[3][col] = m_translation.data[col];
}
return res;
}
Transformation Transformation::getInverted() const
{
return Transformation(m_rotation.getTransposed(), -m_translation);
}