10 #ifndef EIGEN_UMEYAMA_H 11 #define EIGEN_UMEYAMA_H 20 #include "./InternalHeaderCheck.h" 32 template <
typename MatrixType,
typename OtherMatrixType>
33 struct umeyama_transform_matrix_type {
35 MinRowsAtCompileTime =
36 internal::min_size_prefer_dynamic(MatrixType::RowsAtCompileTime, OtherMatrixType::RowsAtCompileTime),
40 HomogeneousDimension = int(MinRowsAtCompileTime) ==
Dynamic ?
Dynamic : int(MinRowsAtCompileTime) + 1
43 typedef Matrix<typename traits<MatrixType>::Scalar, HomogeneousDimension, HomogeneousDimension,
89 template <
typename Derived,
typename OtherDerived>
93 typedef typename internal::traits<TransformationMatrixType>::Scalar Scalar;
98 (internal::is_same<Scalar,
typename internal::traits<OtherDerived>::Scalar>::value),
99 YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY)
101 enum { Dimension = internal::min_size_prefer_dynamic(Derived::RowsAtCompileTime, OtherDerived::RowsAtCompileTime) };
111 const RealScalar one_over_n = RealScalar(1) /
static_cast<RealScalar
>(n);
114 const VectorType src_mean = src.
rowwise().sum() * one_over_n;
115 const VectorType dst_mean = dst.
rowwise().sum() * one_over_n;
118 const RowMajorMatrixType src_demean = src.
colwise() - src_mean;
119 const RowMajorMatrixType dst_demean = dst.
colwise() - dst_mean;
122 const MatrixType sigma = one_over_n * dst_demean * src_demean.transpose();
127 TransformationMatrixType Rt = TransformationMatrixType::Identity(m + 1, m + 1);
130 VectorType S = VectorType::Ones(m);
132 if (svd.
matrixU().determinant() * svd.
matrixV().determinant() < 0) {
138 Rt.block(0, 0, m, m).noalias() = svd.
matrixU() * S.asDiagonal() * svd.
matrixV().transpose();
142 const Scalar src_var = src_demean.rowwise().squaredNorm().sum() * one_over_n;
145 const Scalar c = Scalar(1) / src_var * svd.
singularValues().dot(S);
148 Rt.col(m).head(m) = dst_mean;
149 Rt.col(m).head(m).noalias() -= c * Rt.topLeftCorner(m, m) * src_mean;
150 Rt.block(0, 0, m, m) *= c;
152 Rt.col(m).head(m) = dst_mean;
153 Rt.col(m).head(m).noalias() -= Rt.topLeftCorner(m, m) * src_mean;
161 #endif // EIGEN_UMEYAMA_H Definition: Constants.h:318
const MatrixUType & matrixU() const
Definition: SVDBase.h:173
Namespace containing all symbols from the Eigen library.
Definition: B01_Experimental.dox:1
Holds information about the various numeric (i.e. scalar) types allowed by Eigen. ...
Definition: NumTraits.h:232
const unsigned int RowMajorBit
Definition: Constants.h:70
Definition: Constants.h:322
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:82
internal::umeyama_transform_matrix_type< Derived, OtherDerived >::type umeyama(const MatrixBase< Derived > &src, const MatrixBase< OtherDerived > &dst, bool with_scaling=true)
Returns the transformation between two point sets.
Definition: Umeyama.h:90
ConstColwiseReturnType colwise() const
Definition: DenseBase.h:518
ConstRowwiseReturnType rowwise() const
Definition: DenseBase.h:508
Definition: Constants.h:320
Two-sided Jacobi SVD decomposition of a rectangular matrix.
Definition: ForwardDeclarations.h:437
const SingularValuesType & singularValues() const
Definition: SVDBase.h:200
const MatrixVType & matrixV() const
Definition: SVDBase.h:189
const int Dynamic
Definition: Constants.h:25
The matrix class, also used for vectors and row-vectors.
Definition: Matrix.h:186
constexpr Index rows() const noexcept
Definition: EigenBase.h:59
constexpr Index cols() const noexcept
Definition: EigenBase.h:61
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:52