Eigen  3.4.90 (git rev 5a9f66fb35d03a4da9ef8976e67a61b30aa16dcf)
 
Loading...
Searching...
No Matches
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 <[email protected]>
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// IWYU pragma: private
14#include "./InternalHeaderCheck.h"
15
16namespace Eigen {
17
36namespace internal {
37// This helper helps nvcc+MSVC to properly parse this file.
38// See bug 1412.
39template <typename Scalar, int Dim, int Mode>
40struct uniformscaling_times_affine_returntype {
41 enum { NewMode = int(Mode) == int(Isometry) ? Affine : Mode };
42 typedef Transform<Scalar, Dim, NewMode> type;
43};
44} // namespace internal
45
46template <typename Scalar_>
48 public:
50 typedef Scalar_ Scalar;
51
52 protected:
53 Scalar m_factor;
54
55 public:
59 explicit inline UniformScaling(const Scalar& s) : m_factor(s) {}
60
61 inline const Scalar& factor() const { return m_factor; }
62 inline Scalar& factor() { return m_factor; }
63
65 inline UniformScaling operator*(const UniformScaling& other) const {
66 return UniformScaling(m_factor * other.factor());
67 }
68
70 template <int Dim>
72
74 template <int Dim, int Mode, int Options>
81
83 // TODO returns an expression
84 template <typename Derived>
85 inline typename Eigen::internal::plain_matrix_type<Derived>::type operator*(const MatrixBase<Derived>& other) const {
86 return other * m_factor;
87 }
88
89 template <typename Derived, int Dim>
91 return r.toRotationMatrix() * m_factor;
92 }
93
95 inline UniformScaling inverse() const { return UniformScaling(Scalar(1) / m_factor); }
96
102 template <typename NewScalarType>
104 return UniformScaling<NewScalarType>(NewScalarType(m_factor));
105 }
106
108 template <typename OtherScalarType>
109 inline explicit UniformScaling(const UniformScaling<OtherScalarType>& other) {
110 m_factor = Scalar(other.factor());
111 }
112
117 bool isApprox(const UniformScaling& other,
118 const typename NumTraits<Scalar>::Real& prec = NumTraits<Scalar>::dummy_precision()) const {
119 return internal::isApprox(m_factor, other.factor(), prec);
120 }
121};
122
125
129// NOTE this operator is defined in MatrixBase and not as a friend function
130// of UniformScaling to fix an internal crash of Intel's ICC
131template <typename Derived, typename Scalar>
132EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(Derived, Scalar, product)
133operator*(const MatrixBase<Derived>& matrix, const UniformScaling<Scalar>& s) {
134 return matrix.derived() * s.factor();
135}
136
142template <typename RealScalar>
143inline UniformScaling<std::complex<RealScalar> > Scaling(const std::complex<RealScalar>& s) {
145}
146
148template <typename Scalar>
149inline DiagonalMatrix<Scalar, 2> Scaling(const Scalar& sx, const Scalar& sy) {
150 return DiagonalMatrix<Scalar, 2>(sx, sy);
151}
153template <typename Scalar>
154inline DiagonalMatrix<Scalar, 3> Scaling(const Scalar& sx, const Scalar& sy, const Scalar& sz) {
155 return DiagonalMatrix<Scalar, 3>(sx, sy, sz);
156}
157
161template <typename Derived>
163 return coeffs.asDiagonal();
164}
165
167template <typename Derived>
169 return typename DiagonalWrapper<const Derived>::PlainObject(std::move(coeffs.derived()));
170}
171
181
182template <typename Scalar>
183template <int Dim>
186 res.matrix().setZero();
187 res.linear().diagonal().fill(factor());
188 res.translation() = factor() * t.vector();
189 res(Dim, Dim) = Scalar(1);
190 return res;
191}
192
193} // end namespace Eigen
194
195#endif // EIGEN_SCALING_H
Represents a diagonal matrix with its storage.
Definition DiagonalMatrix.h:172
Expression of a diagonal matrix.
Definition DiagonalMatrix.h:317
Base class for all dense matrices, vectors, and expressions.
Definition MatrixBase.h:52
const DiagonalWrapper< const Derived > asDiagonal() const
Definition DiagonalMatrix.h:344
The matrix class, also used for vectors and row-vectors.
Definition Matrix.h:186
Derived & setZero(Index size)
Definition CwiseNullaryOp.h:563
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:192
ConstLinearPart linear() const
Definition Transform.h:374
ConstTranslationPart translation() const
Definition Transform.h:384
const MatrixType & matrix() const
Definition Transform.h:369
Represents a translation transformation.
Definition Translation.h:33
Represents a generic uniform scaling transformation.
Definition Scaling.h:47
UniformScaling inverse() const
Definition Scaling.h:95
Scalar_ Scalar
Definition Scaling.h:50
bool isApprox(const UniformScaling &other, const typename NumTraits< Scalar >::Real &prec=NumTraits< Scalar >::dummy_precision()) const
Definition Scaling.h:117
UniformScaling operator*(const UniformScaling &other) const
Definition Scaling.h:65
UniformScaling()
Definition Scaling.h:57
Eigen::internal::plain_matrix_type< Derived >::type operator*(const MatrixBase< Derived > &other) const
Definition Scaling.h:85
UniformScaling(const Scalar &s)
Definition Scaling.h:59
internal::uniformscaling_times_affine_returntype< Scalar, Dim, Mode >::type operator*(const Transform< Scalar, Dim, Mode, Options > &t) const
Definition Scaling.h:75
UniformScaling< NewScalarType > cast() const
Definition Scaling.h:103
UniformScaling(const UniformScaling< OtherScalarType > &other)
Definition Scaling.h:109
@ Affine
Definition Constants.h:458
@ Isometry
Definition Constants.h:455
Namespace containing all symbols from the Eigen library.
Definition Core:137
UniformScaling< float > Scaling(float s)
Definition Scaling.h:138
Holds information about the various numeric (i.e. scalar) types allowed by Eigen.
Definition Meta.h:523