// 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 "repmat.h" #include "verbose.h" #include "polar_dec.h" #include "polar_svd.h" #include "C_STR.h" #include template IGL_INLINE void igl::fit_rotations( const Eigen::PlainObjectBase & S, const bool single_precision, Eigen::PlainObjectBase & R) { using namespace std; const int dim = S.cols(); const int nr = S.rows()/dim; assert(nr * dim == S.rows()); assert(dim == 3); // 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 Mat3; typedef Eigen::Matrix Vec3; Mat3 ri; if(single_precision) { polar_svd3x3(si, ri); }else { Mat3 ti,ui,vi; Vec3 _; igl::polar_svd(si,ri,ti,ui,_,vi); } assert(ri.determinant() >= 0); R.block(0,r*dim,dim,dim) = ri.block(0,0,dim,dim).transpose(); //cout< 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(dim == 2 && "_planar input should be 2D"); 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 Mat2; typedef Eigen::Matrix Vec2; Mat2 ri,ti,ui,vi; Vec2 _; igl::polar_svd(si,ri,ti,ui,_,vi); #ifndef FIT_ROTATIONS_ALLOW_FLIPS // Check for reflection if(ri.determinant() < 0) { vi.col(1) *= -1.; ri = ui * vi.transpose(); } assert(ri.determinant() >= 0); #endif // Not sure why polar_dec computes transpose... R.block(0,r*dim,dim,dim).setIdentity(); R.block(0,r*dim,2,2) = ri.transpose(); } } #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&, bool, 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 >&); template void igl::fit_rotations,Eigen::Matrix >(Eigen::PlainObjectBase > const &,bool,Eigen::PlainObjectBase > &); #endif