Selaa lähdekoodia

switched to polar_svd and polar_dec

Former-commit-id: 7bb21ad652791c4cc919eb62320afcad8bb4c000
Stefan Brugger 10 vuotta sitten
vanhempi
commit
9b846b6edd
2 muutettua tiedostoa jossa 13 lisäystä ja 16 poistoa
  1. 12 16
      include/igl/procrustes.cpp
  2. 1 0
      include/igl/procrustes.h

+ 12 - 16
include/igl/procrustes.cpp

@@ -6,6 +6,8 @@
 // v. 2.0. If a copy of the MPL was not distributed with this file, You can 
 // obtain one at http://mozilla.org/MPL/2.0/.
 #include "procrustes.h"
+#include "polar_svd.h"
+#include "polar_dec.h"
  
 template <typename DerivedV, typename Scalar, int DIM, int TType>
 IGL_INLINE void igl::procrustes(
@@ -20,8 +22,8 @@ IGL_INLINE void igl::procrustes(
    assert(X.cols() == Y.cols() && "Points have same dimensions");
 
    // Center data
-   VectorXd Xmean = X.colwise().mean();      
-   VectorXd Ymean = Y.colwise().mean();      
+   const VectorXd Xmean = X.colwise().mean();      
+   const VectorXd Ymean = Y.colwise().mean();      
    MatrixXd XC = X.rowwise() - Xmean.transpose();
    MatrixXd YC = Y.rowwise() - Ymean.transpose();
 
@@ -39,22 +41,16 @@ IGL_INLINE void igl::procrustes(
 
 
    // Rotation 
-   MatrixXd M = XC.transpose() * YC; 
-   JacobiSVD<Eigen::MatrixXd> svd(M, Eigen::ComputeFullU | Eigen::ComputeFullV);
-
-   MatrixXd sigma;
-   sigma.setIdentity(DIM,DIM);
-   if (!includeReflections && (svd.matrixU() * svd.matrixV().transpose()).determinant() < 0)
-       sigma(DIM-1,DIM-1) = -1.;
-
-   Matrix<Scalar,DIM,DIM> R = svd.matrixU() * sigma * svd.matrixV().transpose();
-   assert(abs(R.determinant() - 1) < 1e-10);
-
+   MatrixXd S = XC.transpose() * YC; 
+   Matrix<Scalar,DIM,DIM> Rm,Tm;
+   if (includeReflections)
+     polar_dec(S,Rm,Tm);
+   else
+     polar_svd(S,Rm,Tm);
 
    // Translation
-   Matrix<Scalar,DIM,1> t = Ymean - scale*R*Xmean;
-     
+   Matrix<Scalar,DIM,1> t = Ymean - scale*Rm*Xmean;
 
    // Combine
-   T = Translation<Scalar,DIM>(t) * R.transpose() * Scaling(scale);
+   T = Translation<Scalar,DIM>(t) * Rm.transpose() * Scaling(scale);
 }

+ 1 - 0
include/igl/procrustes.h

@@ -44,6 +44,7 @@ namespace igl
         bool includeScaling,
         bool includeReflections,
         Eigen::Transform<Scalar,DIM,TType>& T);
+    
 }
 
 #ifndef IGL_STATIC_LIBRARY