// This file is part of libigl, a simple c++ geometry processing library. // // Copyright (C) 2013 Alec Jacobson // // This Source Code Form is subject to the terms of the Mozilla Public License // 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 "fit_rotations.h" #include "polar_svd3x3.h" #include #include #include #include #include template IGL_INLINE void igl::fit_rotations( const Eigen::PlainObjectBase & S, Eigen::PlainObjectBase & R) { using namespace std; const int dim = S.cols(); const int nr = S.rows()/dim; assert(nr * dim == S.rows()); // resize output R.resize(dim,dim*nr); // hopefully no op (should be already allocated) //std::cout<<"S=["< si;// = Eigen::Matrix3d::Identity(); // loop over number of rotations we're computing for(int r = 0;r ri; Eigen::Matrix ti; //polar_dec(si,ri,ti); //polar_svd(si,ri,ti); polar_svd3x3(si, ri); assert(ri.determinant() >= 0); #ifndef FIT_ROTATIONS_ALLOW_FLIPS // Check for reflection if(ri.determinant() < 0) { cerr<<"Error: Warning: flipping is wrong..."<= 0); #endif // Not sure why polar_dec computes transpose... R.block(0,r*dim,dim,dim) = ri.block(0,0,dim,dim).transpose(); } } template IGL_INLINE void igl::fit_rotations_planar( const Eigen::PlainObjectBase & S, Eigen::PlainObjectBase & R) { using namespace std; const int dim = S.cols(); const int nr = S.rows()/dim; assert(nr * dim == S.rows()); // resize output R.resize(dim,dim*nr); // hopefully no op (should be already allocated) Eigen::Matrix si; // loop over number of rotations we're computing for(int r = 0;r ri; Eigen::Matrix ti; igl::polar_svd(si,ri,ti); #ifndef FIT_ROTATIONS_ALLOW_FLIPS // Check for reflection if(ri.determinant() < 0) { cerr<<"Error: Warning: flipping is wrong..."<= 0); #endif // Not sure why polar_dec computes transpose... R.block(0,r*dim,2,2) = ri.block(0,0,2,2).transpose(); // Set remaining part to identity R(0,r*3+2) = 0; R(1,r*3+2) = 0; R(2,r*3+0) = 0; R(2,r*3+1) = 0; R(2,r*3+2) = 1; } } #ifdef __SSE__ IGL_INLINE void igl::fit_rotations_SSE( const Eigen::MatrixXf & S, Eigen::MatrixXf & R) { const int cStep = 4; assert(S.cols() == 3); const int dim = 3; //S.cols(); const int nr = S.rows()/dim; assert(nr * dim == S.rows()); // resize output R.resize(dim,dim*nr); // hopefully no op (should be already allocated) Eigen::Matrix siBig; // using SSE decompose cStep matrices at a time: int r = 0; for( ; r= nr) numMats = nr - r; // build siBig: for (int k=0; k ri; polar_svd3x3_sse(siBig, ri); for (int k=0; k= 0); // Not sure why polar_dec computes transpose... for (int k=0; k(); Eigen::MatrixXf Rf; fit_rotations_SSE(Sf,Rf); R = Rf.cast(); } #endif #ifdef __AVX__ IGL_INLINE void igl::fit_rotations_AVX( const Eigen::MatrixXf & S, Eigen::MatrixXf & R) { const int cStep = 8; assert(S.cols() == 3); const int dim = 3; //S.cols(); const int nr = S.rows()/dim; assert(nr * dim == S.rows()); // resize output R.resize(dim,dim*nr); // hopefully no op (should be already allocated) Eigen::Matrix siBig; // using SSE decompose cStep matrices at a time: int r = 0; for( ; r= nr) numMats = nr - r; // build siBig: for (int k=0; k ri; polar_svd3x3_avx(siBig, ri); for (int k=0; k= 0); // Not sure why polar_dec computes transpose... for (int k=0; k, Eigen::Matrix >(Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase >&); template void igl::fit_rotations_planar, Eigen::Matrix >(Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase >&); template void igl::fit_rotations_planar, Eigen::Matrix >(Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase >&); #endif