10#ifndef EIGEN_UMEYAMA_H
11#define EIGEN_UMEYAMA_H
21#ifndef EIGEN_PARSED_BY_DOXYGEN
31template<
typename MatrixType,
typename OtherMatrixType>
32struct umeyama_transform_matrix_type
35 MinRowsAtCompileTime = EIGEN_SIZE_MIN_PREFER_DYNAMIC(MatrixType::RowsAtCompileTime, OtherMatrixType::RowsAtCompileTime),
39 HomogeneousDimension = int(MinRowsAtCompileTime) == Dynamic ? Dynamic : int(MinRowsAtCompileTime)+1
42 typedef Matrix<typename traits<MatrixType>::Scalar,
93template <
typename Derived,
typename OtherDerived>
94typename internal::umeyama_transform_matrix_type<Derived, OtherDerived>::type
97 typedef typename internal::umeyama_transform_matrix_type<Derived, OtherDerived>::type TransformationMatrixType;
98 typedef typename internal::traits<TransformationMatrixType>::Scalar Scalar;
99 typedef typename NumTraits<Scalar>::Real RealScalar;
100 typedef typename Derived::Index Index;
102 EIGEN_STATIC_ASSERT(!NumTraits<Scalar>::IsComplex, NUMERIC_TYPE_MUST_BE_REAL)
103 EIGEN_STATIC_ASSERT((internal::is_same<Scalar,
typename internal::traits<OtherDerived>::Scalar>::value),
104 YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY)
106 enum { Dimension = EIGEN_SIZE_MIN_PREFER_DYNAMIC(Derived::RowsAtCompileTime, OtherDerived::RowsAtCompileTime) };
110 typedef typename internal::plain_matrix_type_row_major<Derived>::type RowMajorMatrixType;
112 const Index m = src.rows();
113 const Index n = src.cols();
116 const RealScalar one_over_n = 1 /
static_cast<RealScalar
>(n);
119 const VectorType src_mean = src.
rowwise().
sum() * one_over_n;
120 const VectorType dst_mean = dst.
rowwise().
sum() * one_over_n;
123 const RowMajorMatrixType src_demean = src.
colwise() - src_mean;
124 const RowMajorMatrixType dst_demean = dst.
colwise() - dst_mean;
127 const Scalar src_var = src_demean.rowwise().
squaredNorm().sum() * one_over_n;
130 const MatrixType sigma = one_over_n * dst_demean * src_demean.transpose();
135 TransformationMatrixType Rt = TransformationMatrixType::Identity(m+1,m+1);
138 VectorType S = VectorType::Ones(m);
139 if (sigma.determinant()<0) S(m-1) = -1;
143 Index rank = 0;
for (Index i=0; i<m; ++i)
if (!internal::isMuchSmallerThan(d.coeff(i),d.coeff(0))) ++rank;
148 const Scalar s = S(m-1); S(m-1) = -1;
162 Rt.col(m).head(m) = dst_mean;
163 Rt.col(m).head(m).noalias() -= c*Rt.topLeftCorner(m,m)*src_mean;
165 if (with_scaling) Rt.block(0,0,m,m) *= c;
ConstColwiseReturnType colwise() const
Definition VectorwiseOp.h:555
Eigen::Transpose< Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > > transpose()
Definition Transpose.h:199
ConstRowwiseReturnType rowwise() const
Definition VectorwiseOp.h:580
Two-sided Jacobi SVD decomposition of a rectangular matrix.
Definition JacobiSVD.h:479
const MatrixVType & matrixV() const
Definition JacobiSVD.h:604
const SingularValuesType & singularValues() const
Definition JacobiSVD.h:616
const MatrixUType & matrixU() const
Definition JacobiSVD.h:588
Base class for all dense matrices, vectors, and expressions.
Definition MatrixBase.h:50
const DiagonalWrapper< const Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > > asDiagonal() const
Definition DiagonalMatrix.h:273
Scalar determinant() const
Definition Determinant.h:92
The matrix class, also used for vectors and row-vectors.
Definition Matrix.h:129
const ReturnType< internal::member_sum >::Type sum() const
Definition VectorwiseOp.h:330
const ReturnType< internal::member_squaredNorm, RealScalar >::Type squaredNorm() const
Definition VectorwiseOp.h:283
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:95
@ RowMajor
Definition Constants.h:259
@ ColMajor
Definition Constants.h:257
@ ComputeFullV
Definition Constants.h:324
@ ComputeFullU
Definition Constants.h:320
const unsigned int RowMajorBit
Definition Constants.h:48