~siretart/ubuntu/utopic/blender/libav10

« back to all changes in this revision

Viewing changes to extern/Eigen2/Eigen/src/Geometry/RotationBase.h

  • Committer: Bazaar Package Importer
  • Author(s): Kevin Roy
  • Date: 2011-02-08 22:20:54 UTC
  • mfrom: (1.4.2 upstream)
  • mto: (14.2.6 sid) (1.5.1)
  • mto: This revision was merged to the branch mainline in revision 27.
  • Revision ID: james.westby@ubuntu.com-20110208222054-kk0gwa4bu8h5lyq4
Tags: upstream-2.56.1-beta-svn34076
ImportĀ upstreamĀ versionĀ 2.56.1-beta-svn34076

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// This file is part of Eigen, a lightweight C++ template library
 
2
// for linear algebra. Eigen itself is part of the KDE project.
 
3
//
 
4
// Copyright (C) 2008 Gael Guennebaud <g.gael@free.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_ROTATIONBASE_H
 
26
#define EIGEN_ROTATIONBASE_H
 
27
 
 
28
// this file aims to contains the various representations of rotation/orientation
 
29
// in 2D and 3D space excepted Matrix and Quaternion.
 
30
 
 
31
/** \class RotationBase
 
32
  *
 
33
  * \brief Common base class for compact rotation representations
 
34
  *
 
35
  * \param Derived is the derived type, i.e., a rotation type
 
36
  * \param _Dim the dimension of the space
 
37
  */
 
38
template<typename Derived, int _Dim>
 
39
class RotationBase
 
40
{
 
41
  public:
 
42
    enum { Dim = _Dim };
 
43
    /** the scalar type of the coefficients */
 
44
    typedef typename ei_traits<Derived>::Scalar Scalar;
 
45
    
 
46
    /** corresponding linear transformation matrix type */
 
47
    typedef Matrix<Scalar,Dim,Dim> RotationMatrixType;
 
48
 
 
49
    inline const Derived& derived() const { return *static_cast<const Derived*>(this); }
 
50
    inline Derived& derived() { return *static_cast<Derived*>(this); }
 
51
 
 
52
    /** \returns an equivalent rotation matrix */
 
53
    inline RotationMatrixType toRotationMatrix() const { return derived().toRotationMatrix(); }
 
54
 
 
55
    /** \returns the inverse rotation */
 
56
    inline Derived inverse() const { return derived().inverse(); }
 
57
 
 
58
    /** \returns the concatenation of the rotation \c *this with a translation \a t */
 
59
    inline Transform<Scalar,Dim> operator*(const Translation<Scalar,Dim>& t) const
 
60
    { return toRotationMatrix() * t; }
 
61
 
 
62
    /** \returns the concatenation of the rotation \c *this with a scaling \a s */
 
63
    inline RotationMatrixType operator*(const Scaling<Scalar,Dim>& s) const
 
64
    { return toRotationMatrix() * s; }
 
65
 
 
66
    /** \returns the concatenation of the rotation \c *this with an affine transformation \a t */
 
67
    inline Transform<Scalar,Dim> operator*(const Transform<Scalar,Dim>& t) const
 
68
    { return toRotationMatrix() * t; }
 
69
};
 
70
 
 
71
/** \geometry_module
 
72
  *
 
73
  * Constructs a Dim x Dim rotation matrix from the rotation \a r
 
74
  */
 
75
template<typename _Scalar, int _Rows, int _Cols, int _Storage, int _MaxRows, int _MaxCols>
 
76
template<typename OtherDerived>
 
77
Matrix<_Scalar, _Rows, _Cols, _Storage, _MaxRows, _MaxCols>
 
78
::Matrix(const RotationBase<OtherDerived,ColsAtCompileTime>& r)
 
79
{
 
80
  EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE(Matrix,int(OtherDerived::Dim),int(OtherDerived::Dim))
 
81
  *this = r.toRotationMatrix();
 
82
}
 
83
 
 
84
/** \geometry_module
 
85
  *
 
86
  * Set a Dim x Dim rotation matrix from the rotation \a r
 
87
  */
 
88
template<typename _Scalar, int _Rows, int _Cols, int _Storage, int _MaxRows, int _MaxCols>
 
89
template<typename OtherDerived>
 
90
Matrix<_Scalar, _Rows, _Cols, _Storage, _MaxRows, _MaxCols>&
 
91
Matrix<_Scalar, _Rows, _Cols, _Storage, _MaxRows, _MaxCols>
 
92
::operator=(const RotationBase<OtherDerived,ColsAtCompileTime>& r)
 
93
{
 
94
  EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE(Matrix,int(OtherDerived::Dim),int(OtherDerived::Dim))
 
95
  return *this = r.toRotationMatrix();
 
96
}
 
97
 
 
98
/** \internal
 
99
  *
 
100
  * Helper function to return an arbitrary rotation object to a rotation matrix.
 
101
  *
 
102
  * \param Scalar the numeric type of the matrix coefficients
 
103
  * \param Dim the dimension of the current space
 
104
  *
 
105
  * It returns a Dim x Dim fixed size matrix.
 
106
  *
 
107
  * Default specializations are provided for:
 
108
  *   - any scalar type (2D),
 
109
  *   - any matrix expression,
 
110
  *   - any type based on RotationBase (e.g., Quaternion, AngleAxis, Rotation2D)
 
111
  *
 
112
  * Currently ei_toRotationMatrix is only used by Transform.
 
113
  *
 
114
  * \sa class Transform, class Rotation2D, class Quaternion, class AngleAxis
 
115
  */
 
116
template<typename Scalar, int Dim>
 
117
inline static Matrix<Scalar,2,2> ei_toRotationMatrix(const Scalar& s)
 
118
{
 
119
  EIGEN_STATIC_ASSERT(Dim==2,YOU_MADE_A_PROGRAMMING_MISTAKE)
 
120
  return Rotation2D<Scalar>(s).toRotationMatrix();
 
121
}
 
122
 
 
123
template<typename Scalar, int Dim, typename OtherDerived>
 
124
inline static Matrix<Scalar,Dim,Dim> ei_toRotationMatrix(const RotationBase<OtherDerived,Dim>& r)
 
125
{
 
126
  return r.toRotationMatrix();
 
127
}
 
128
 
 
129
template<typename Scalar, int Dim, typename OtherDerived>
 
130
inline static const MatrixBase<OtherDerived>& ei_toRotationMatrix(const MatrixBase<OtherDerived>& mat)
 
131
{
 
132
  EIGEN_STATIC_ASSERT(OtherDerived::RowsAtCompileTime==Dim && OtherDerived::ColsAtCompileTime==Dim,
 
133
    YOU_MADE_A_PROGRAMMING_MISTAKE)
 
134
  return mat;
 
135
}
 
136
 
 
137
#endif // EIGEN_ROTATIONBASE_H