Eigen  3.4.90 (git rev a4098ac676528a83cfb73d4d26ce1b42ec05f47c)
Scaling.h
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// This Source Code Form is subject to the terms of the Mozilla
7// Public License v. 2.0. If a copy of the MPL was not distributed
8// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9
10#ifndef EIGEN_SCALING_H
11#define EIGEN_SCALING_H
12
13#include "./InternalHeaderCheck.h"
14
15namespace Eigen {
16
35namespace internal
36{
37 // This helper helps nvcc+MSVC to properly parse this file.
38 // See bug 1412.
39 template <typename Scalar, int Dim, int Mode>
40 struct uniformscaling_times_affine_returntype
41 {
42 enum
43 {
44 NewMode = int(Mode) == int(Isometry) ? Affine : Mode
45 };
46 typedef Transform <Scalar, Dim, NewMode> type;
47 };
48}
49
50template<typename Scalar_>
52{
53public:
55 typedef Scalar_ Scalar;
56
57protected:
58
59 Scalar m_factor;
60
61public:
62
66 explicit inline UniformScaling(const Scalar& s) : m_factor(s) {}
67
68 inline const Scalar& factor() const { return m_factor; }
69 inline Scalar& factor() { return m_factor; }
70
72 inline UniformScaling operator* (const UniformScaling& other) const
73 { return UniformScaling(m_factor * other.factor()); }
74
76 template<int Dim>
78
80 template<int Dim, int Mode, int Options>
81 inline typename
84 {
86 res.prescale(factor());
87 return res;
88 }
89
91 // TODO returns an expression
92 template<typename Derived>
93 inline typename Eigen::internal::plain_matrix_type<Derived>::type operator* (const MatrixBase<Derived>& other) const
94 { return other * m_factor; }
95
96 template<typename Derived,int Dim>
98 { return r.toRotationMatrix() * m_factor; }
99
101 inline UniformScaling inverse() const
102 { return UniformScaling(Scalar(1)/m_factor); }
103
109 template<typename NewScalarType>
111 { return UniformScaling<NewScalarType>(NewScalarType(m_factor)); }
112
114 template<typename OtherScalarType>
116 { m_factor = Scalar(other.factor()); }
117
123 { return internal::isApprox(m_factor, other.factor(), prec); }
124
125};
126
129
133// NOTE this operator is defined in MatrixBase and not as a friend function
134// of UniformScaling to fix an internal crash of Intel's ICC
135template<typename Derived,typename Scalar>
136EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(Derived,Scalar,product)
137operator*(const MatrixBase<Derived>& matrix, const UniformScaling<Scalar>& s)
138{ return matrix.derived() * s.factor(); }
139
145template<typename RealScalar>
146inline UniformScaling<std::complex<RealScalar> > Scaling(const std::complex<RealScalar>& s)
148
150template<typename Scalar>
151inline DiagonalMatrix<Scalar,2> Scaling(const Scalar& sx, const Scalar& sy)
152{ return DiagonalMatrix<Scalar,2>(sx, sy); }
154template<typename Scalar>
155inline DiagonalMatrix<Scalar,3> Scaling(const Scalar& sx, const Scalar& sy, const Scalar& sz)
156{ return DiagonalMatrix<Scalar,3>(sx, sy, sz); }
157
161template<typename Derived>
163{ return coeffs.asDiagonal(); }
164
174
175template<typename Scalar>
176template<int Dim>
179{
181 res.matrix().setZero();
182 res.linear().diagonal().fill(factor());
183 res.translation() = factor() * t.vector();
184 res(Dim,Dim) = Scalar(1);
185 return res;
186}
187
188} // end namespace Eigen
189
190#endif // EIGEN_SCALING_H
Represents a diagonal matrix with its storage.
Definition: DiagonalMatrix.h:144
Expression of a diagonal matrix.
Definition: DiagonalMatrix.h:295
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:52
const DiagonalWrapper< const Derived > asDiagonal() const
Definition: DiagonalMatrix.h:325
The matrix class, also used for vectors and row-vectors.
Definition: Matrix.h:182
Derived & setZero(Index size)
Definition: CwiseNullaryOp.h:564
Common base class for compact rotation representations.
Definition: RotationBase.h:32
RotationMatrixType toRotationMatrix() const
Definition: RotationBase.h:47
Represents an homogeneous transformation in a N dimensional space.
Definition: Transform.h:207
ConstTranslationPart translation() const
Definition: Transform.h:408
const MatrixType & matrix() const
Definition: Transform.h:393
ConstLinearPart linear() const
Definition: Transform.h:398
Represents a translation transformation.
Definition: Translation.h:33
Represents a generic uniform scaling transformation.
Definition: Scaling.h:52
UniformScaling inverse() const
Definition: Scaling.h:101
Scalar_ Scalar
Definition: Scaling.h:55
bool isApprox(const UniformScaling &other, const typename NumTraits< Scalar >::Real &prec=NumTraits< Scalar >::dummy_precision()) const
Definition: Scaling.h:122
UniformScaling operator*(const UniformScaling &other) const
Definition: Scaling.h:72
UniformScaling()
Definition: Scaling.h:64
UniformScaling(const Scalar &s)
Definition: Scaling.h:66
UniformScaling< NewScalarType > cast() const
Definition: Scaling.h:110
UniformScaling(const UniformScaling< OtherScalarType > &other)
Definition: Scaling.h:115
@ Affine
Definition: Constants.h:462
@ Isometry
Definition: Constants.h:459
Namespace containing all symbols from the Eigen library.
Definition: B01_Experimental.dox:1
DiagonalMatrix< double, 3 > AlignedScaling3d
Definition: Scaling.h:172
UniformScaling< float > Scaling(float s)
Definition: Scaling.h:141
DiagonalMatrix< float, 3 > AlignedScaling3f
Definition: Scaling.h:170
DiagonalMatrix< float, 2 > AlignedScaling2f
Definition: Scaling.h:166
DiagonalMatrix< double, 2 > AlignedScaling2d
Definition: Scaling.h:168
Holds information about the various numeric (i.e. scalar) types allowed by Eigen.
Definition: NumTraits.h:235