10 #ifndef EIGEN_UMEYAMA_H
11 #define EIGEN_UMEYAMA_H
23 #ifndef EIGEN_PARSED_BY_DOXYGEN
33 template<
typename MatrixType,
typename OtherMatrixType>
34 struct umeyama_transform_matrix_type
41 HomogeneousDimension = int(MinRowsAtCompileTime) ==
Dynamic ?
Dynamic : int(MinRowsAtCompileTime)+1
95 template <
typename Derived,
typename OtherDerived>
96 typename internal::umeyama_transform_matrix_type<Derived, OtherDerived>::type
99 typedef typename internal::umeyama_transform_matrix_type<Derived, OtherDerived>::type TransformationMatrixType;
100 typedef typename internal::traits<TransformationMatrixType>::Scalar Scalar;
104 EIGEN_STATIC_ASSERT((internal::is_same<Scalar,
typename internal::traits<OtherDerived>::Scalar>::value),
105 YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY)
117 const RealScalar one_over_n = RealScalar(1) /
static_cast<RealScalar
>(
n);
120 const VectorType src_mean = src.
rowwise().
sum() * one_over_n;
121 const VectorType dst_mean = dst.
rowwise().
sum() * one_over_n;
124 const RowMajorMatrixType src_demean = src.
colwise() - src_mean;
125 const RowMajorMatrixType dst_demean = dst.
colwise() - dst_mean;
128 const MatrixType sigma = one_over_n * dst_demean * src_demean.transpose();
133 TransformationMatrixType Rt = TransformationMatrixType::Identity(
m+1,
m+1);
136 VectorType S = VectorType::Ones(
m);
138 if (
svd.matrixU().determinant() *
svd.matrixV().determinant() < 0 ) {
144 Rt.block(0,0,
m,
m).
noalias() =
svd.matrixU() * S.asDiagonal() *
svd.matrixV().transpose();
149 const Scalar src_var = src_demean.rowwise().squaredNorm().sum() * one_over_n;
152 const Scalar
c = Scalar(1)/src_var *
svd.singularValues().dot(S);
155 Rt.col(
m).head(
m) = dst_mean;
156 Rt.col(
m).head(
m).noalias() -=
c*Rt.topLeftCorner(
m,
m)*src_mean;
157 Rt.block(0,0,
m,
m) *=
c;
161 Rt.col(
m).head(
m) = dst_mean;
162 Rt.col(
m).head(
m).noalias() -= Rt.topLeftCorner(
m,
m)*src_mean;
cout<< "Here is the matrix m:"<< endl<< m<< endl;JacobiSVD< MatrixXf, ComputeThinU|ComputeThinV > svd(m)
#define EIGEN_STATIC_ASSERT(X, MSG)
Matrix< float, 1, Dynamic > MatrixType
ConstColwiseReturnType colwise() const
ConstRowwiseReturnType rowwise() const
EIGEN_CONSTEXPR Index cols() const EIGEN_NOEXCEPT
EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT
Two-sided Jacobi SVD decomposition of a rectangular matrix.
Base class for all dense matrices, vectors, and expressions.
NoAlias< Derived, Eigen::MatrixBase > noalias()
The matrix class, also used for vectors and row-vectors.
internal::traits< Matrix< Scalar_, Rows_, Cols_, Options_, MaxRows_, MaxCols_ > >::Scalar Scalar
const SumReturnType sum() const
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.
const unsigned int RowMajorBit
constexpr int min_size_prefer_dynamic(A a, B b)
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Holds information about the various numeric (i.e. scalar) types allowed by Eigen.