Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
Eigen
src
Geometry
Translation.h
Go to the documentation of this file.
1
// This file is part of Eigen, a lightweight C++ template library
2
// for linear algebra.
3
//
4
// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
5
//
6
// Eigen is free software; you can redistribute it and/or
7
// modify it under the terms of the GNU Lesser General Public
8
// License as published by the Free Software Foundation; either
9
// version 3 of the License, or (at your option) any later version.
10
//
11
// Alternatively, you can redistribute it and/or
12
// modify it under the terms of the GNU General Public License as
13
// published by the Free Software Foundation; either version 2 of
14
// the License, or (at your option) any later version.
15
//
16
// Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
17
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18
// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
19
// GNU General Public License for more details.
20
//
21
// You should have received a copy of the GNU Lesser General Public
22
// License and a copy of the GNU General Public License along with
23
// Eigen. If not, see <http://www.gnu.org/licenses/>.
24
25
#ifndef EIGEN_TRANSLATION_H
26
#define EIGEN_TRANSLATION_H
27
28
namespace
Eigen {
29
44
template
<
typename
_Scalar,
int
_Dim>
45
class
Translation
46
{
47
public
:
48
EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF_VECTORIZABLE_FIXED_SIZE
(_Scalar,_Dim)
50
enum {
Dim
= _Dim };
52
typedef
_Scalar
Scalar
;
54
typedef
Matrix<Scalar,Dim,1>
VectorType
;
56
typedef
Matrix<Scalar,Dim,Dim>
LinearMatrixType
;
58
typedef
Transform<Scalar,Dim,Affine>
AffineTransformType
;
60
typedef
Transform<Scalar,Dim,Isometry>
IsometryTransformType
;
61
62
protected
:
63
64
VectorType
m_coeffs
;
65
66
public
:
67
69
Translation
() {}
71
inline
Translation
(
const
Scalar
& sx,
const
Scalar
& sy)
72
{
73
eigen_assert
(
Dim
==2);
74
m_coeffs
.x() = sx;
75
m_coeffs
.y() = sy;
76
}
78
inline
Translation
(
const
Scalar
& sx,
const
Scalar
& sy,
const
Scalar
& sz)
79
{
80
eigen_assert
(
Dim
==3);
81
m_coeffs
.x() = sx;
82
m_coeffs
.y() = sy;
83
m_coeffs
.z() = sz;
84
}
86
explicit
inline
Translation
(
const
VectorType
&
vector
) :
m_coeffs
(vector) {}
87
89
inline
Scalar
x
()
const
{
return
m_coeffs
.x(); }
91
inline
Scalar
y
()
const
{
return
m_coeffs
.y(); }
93
inline
Scalar
z
()
const
{
return
m_coeffs
.z(); }
94
96
inline
Scalar
&
x
() {
return
m_coeffs
.x(); }
98
inline
Scalar
&
y
() {
return
m_coeffs
.y(); }
100
inline
Scalar
&
z
() {
return
m_coeffs
.z(); }
101
102
const
VectorType
&
vector
()
const
{
return
m_coeffs
; }
103
VectorType
&
vector
() {
return
m_coeffs
; }
104
105
const
VectorType
&
translation
()
const
{
return
m_coeffs
; }
106
VectorType
&
translation
() {
return
m_coeffs
; }
107
109
inline
Translation
operator*
(
const
Translation
& other)
const
110
{
return
Translation
(
m_coeffs
+ other.
m_coeffs
); }
111
113
inline
AffineTransformType
operator*
(
const
UniformScaling<Scalar>
& other)
const
;
114
116
template
<
typename
OtherDerived>
117
inline
AffineTransformType
operator*
(
const
EigenBase<OtherDerived>
& linear)
const
;
118
120
template
<
typename
Derived>
121
inline
IsometryTransformType
operator*
(
const
RotationBase<Derived,Dim>
& r)
const
122
{
return
*
this
*
IsometryTransformType
(r); }
123
125
// its a nightmare to define a templated friend function outside its declaration
126
template
<
typename
OtherDerived>
friend
127
inline
AffineTransformType
operator*
(
const
EigenBase<OtherDerived>
& linear,
const
Translation
& t)
128
{
129
AffineTransformType
res;
130
res.
matrix
().
setZero
();
131
res.
linear
() = linear.
derived
();
132
res.
translation
() = linear.
derived
() * t.
m_coeffs
;
133
res.
matrix
().
row
(
Dim
).setZero();
134
res(
Dim
,
Dim
) =
Scalar
(1);
135
return
res;
136
}
137
139
template
<
int
Mode,
int
Options>
140
inline
Transform<Scalar,Dim,Mode>
operator*
(
const
Transform<Scalar,Dim,Mode,Options>
& t)
const
141
{
142
Transform<Scalar,Dim,Mode>
res = t;
143
res.
pretranslate
(
m_coeffs
);
144
return
res;
145
}
146
148
inline
VectorType
operator*
(
const
VectorType
& other)
const
149
{
return
m_coeffs
+ other; }
150
152
Translation
inverse
()
const
{
return
Translation
(-
m_coeffs
); }
153
154
Translation
&
operator=
(
const
Translation
& other)
155
{
156
m_coeffs
= other.
m_coeffs
;
157
return
*
this
;
158
}
159
160
static
const
Translation
Identity
() {
return
Translation
(VectorType::Zero()); }
161
167
template
<
typename
NewScalarType>
168
inline
typename
internal::cast_return_type<Translation,Translation<NewScalarType,Dim> >::type
cast
()
const
169
{
return
typename
internal::cast_return_type<Translation,Translation<NewScalarType,Dim> >::type(*
this
); }
170
172
template
<
typename
OtherScalarType>
173
inline
explicit
Translation
(
const
Translation<OtherScalarType,Dim>
& other)
174
{
m_coeffs
= other.
vector
().template cast<Scalar>(); }
175
180
bool
isApprox
(
const
Translation
& other,
typename
NumTraits<Scalar>::Real
prec =
NumTraits<Scalar>::dummy_precision
())
const
181
{
return
m_coeffs
.isApprox(other.
m_coeffs
, prec); }
182
183
};
184
187
typedef
Translation<float, 2>
Translation2f
;
188
typedef
Translation<double,2>
Translation2d
;
189
typedef
Translation<float, 3>
Translation3f
;
190
typedef
Translation<double,3>
Translation3d
;
192
193
template
<
typename
Scalar,
int
Dim>
194
inline
typename
Translation<Scalar,Dim>::AffineTransformType
195
Translation<Scalar,Dim>::operator*
(
const
UniformScaling<Scalar>
& other)
const
196
{
197
AffineTransformType
res;
198
res.
matrix
().
setZero
();
199
res.
linear
().diagonal().fill(other.
factor
());
200
res.
translation
() = m_coeffs;
201
res(Dim,Dim) =
Scalar
(1);
202
return
res;
203
}
204
205
template
<
typename
Scalar,
int
Dim>
206
template
<
typename
OtherDerived>
207
inline
typename
Translation<Scalar,Dim>::AffineTransformType
208
Translation<Scalar,Dim>::operator*
(
const
EigenBase<OtherDerived>
& linear)
const
209
{
210
AffineTransformType
res;
211
res.
matrix
().
setZero
();
212
res.
linear
() = linear.
derived
();
213
res.
translation
() = m_coeffs;
214
res.
matrix
().
row
(Dim).setZero();
215
res(Dim,Dim) =
Scalar
(1);
216
return
res;
217
}
218
219
}
// end namespace Eigen
220
221
#endif // EIGEN_TRANSLATION_H
Generated on Fri Jun 29 2012 20:20:01 for Eigen by
1.8.1.1