Eigen  5.0.1
 
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 <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// SPDX-License-Identifier: MPL-2.0
10
11#ifndef EIGEN_SCALING_H
12#define EIGEN_SCALING_H
13
14// IWYU pragma: private
15#include "./InternalHeaderCheck.h"
16
17namespace Eigen {
18
36
37namespace internal {
38// This helper helps nvcc+MSVC to properly parse this file.
39// See bug 1412.
40template <typename Scalar, int Dim, int Mode>
41struct uniformscaling_times_affine_returntype {
42 enum { NewMode = int(Mode) == int(Isometry) ? Affine : Mode };
43 using type = Transform<Scalar, Dim, NewMode>;
44};
45} // namespace internal
46
47template <typename Scalar_>
49 public:
51 using Scalar = Scalar_;
52
53 protected:
54 Scalar m_factor;
55
56 public:
60 explicit inline UniformScaling(const Scalar& s) : m_factor(s) {}
61
62 inline const Scalar& factor() const { return m_factor; }
63 inline Scalar& factor() { return m_factor; }
64
66 inline UniformScaling operator*(const UniformScaling& other) const {
67 return UniformScaling(m_factor * other.factor());
68 }
69
71 template <int Dim>
73
75 template <int Dim, int Mode, int Options>
76 inline typename internal::uniformscaling_times_affine_returntype<Scalar, Dim, Mode>::type operator*(
78 typename internal::uniformscaling_times_affine_returntype<Scalar, Dim, Mode>::type res = t;
79 res.prescale(factor());
80 return res;
81 }
82
84 // TODO: return an expression instead of a dense matrix.
85 template <typename Derived>
86 inline typename Eigen::internal::plain_matrix_type<Derived>::type operator*(const MatrixBase<Derived>& other) const {
87 return other * m_factor;
88 }
89
90 template <typename Derived, int Dim>
92 return r.toRotationMatrix() * m_factor;
93 }
94
96 inline UniformScaling inverse() const { return UniformScaling(Scalar(1) / m_factor); }
97
103 template <typename NewScalarType>
105 return UniformScaling<NewScalarType>(NewScalarType(m_factor));
106 }
107
109 template <typename OtherScalarType>
110 inline explicit UniformScaling(const UniformScaling<OtherScalarType>& other) {
111 m_factor = Scalar(other.factor());
112 }
113
118 bool isApprox(const UniformScaling& other,
119 const typename NumTraits<Scalar>::Real& prec = NumTraits<Scalar>::dummy_precision()) const {
120 return internal::isApprox(m_factor, other.factor(), prec);
121 }
122};
123
126
130// NOTE this operator is defined in MatrixBase and not as a friend function
131// of UniformScaling to fix an internal crash of Intel's ICC
132template <typename Derived, typename Scalar>
133EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(Derived, Scalar, internal::scalar_product_op)
134operator*(const MatrixBase<Derived>& matrix, const UniformScaling<Scalar>& s) {
135 return matrix.derived() * s.factor();
136}
137
139inline UniformScaling<float> Scaling(float s) { return UniformScaling<float>(s); }
141inline UniformScaling<double> Scaling(double s) { return UniformScaling<double>(s); }
143template <typename RealScalar>
144inline UniformScaling<std::complex<RealScalar> > Scaling(const std::complex<RealScalar>& s) {
146}
147
149template <typename Scalar>
150inline DiagonalMatrix<Scalar, 2> Scaling(const Scalar& sx, const Scalar& sy) {
151 return DiagonalMatrix<Scalar, 2>(sx, sy);
152}
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}
158
162template <typename Derived>
163inline const DiagonalWrapper<const Derived> Scaling(const MatrixBase<Derived>& coeffs) {
164 return coeffs.asDiagonal();
165}
166
168template <typename Derived>
169inline typename DiagonalWrapper<const Derived>::PlainObject Scaling(MatrixBase<Derived>&& coeffs) {
170 return typename DiagonalWrapper<const Derived>::PlainObject(std::move(coeffs.derived()));
171}
172
174using AlignedScaling2f = DiagonalMatrix<float, 2>;
176using AlignedScaling2d = DiagonalMatrix<double, 2>;
178using AlignedScaling3f = DiagonalMatrix<float, 3>;
180using AlignedScaling3d = DiagonalMatrix<double, 3>;
182
183template <typename Scalar>
184template <int Dim>
187 res.matrix().setZero();
188 res.linear().diagonal().fill(factor());
189 res.translation() = factor() * t.vector();
190 res(Dim, Dim) = Scalar(1);
191 return res;
192}
193
194} // end namespace Eigen
195
196#endif // EIGEN_SCALING_H
Represents a diagonal matrix with its storage.
Definition DiagonalMatrix.h:233
Expression of a diagonal matrix.
Definition DiagonalMatrix.h:400
Base class for all dense matrices, vectors, and expressions.
Definition MatrixBase.h:53
The matrix class, also used for vectors and row-vectors.
Definition Matrix.h:188
Common base class for compact rotation representations.
Definition RotationBase.h:33
RotationMatrixType toRotationMatrix() const
Definition RotationBase.h:48
Represents an homogeneous transformation in a N dimensional space.
Definition Transform.h:222
ConstLinearPart linear() const
Definition Transform.h:415
ConstTranslationPart translation() const
Definition Transform.h:425
const MatrixType & matrix() const
Definition Transform.h:410
Represents a translation transformation.
Definition Translation.h:34
Represents a generic uniform scaling transformation.
Definition Scaling.h:48
UniformScaling inverse() const
Definition Scaling.h:96
Scalar_ Scalar
Definition Scaling.h:51
bool isApprox(const UniformScaling &other, const typename NumTraits< Scalar >::Real &prec=NumTraits< Scalar >::dummy_precision()) const
Definition Scaling.h:118
UniformScaling operator*(const UniformScaling &other) const
Definition Scaling.h:66
UniformScaling()
Definition Scaling.h:58
Eigen::internal::plain_matrix_type< Derived >::type operator*(const MatrixBase< Derived > &other) const
Definition Scaling.h:86
UniformScaling(const Scalar &s)
Definition Scaling.h:60
internal::uniformscaling_times_affine_returntype< Scalar, Dim, Mode >::type operator*(const Transform< Scalar, Dim, Mode, Options > &t) const
Definition Scaling.h:76
UniformScaling< NewScalarType > cast() const
Definition Scaling.h:104
UniformScaling(const UniformScaling< OtherScalarType > &other)
Definition Scaling.h:110
@ Affine
Definition Constants.h:475
@ Isometry
Definition Constants.h:472