00001 /**************************************************************************** 00002 * VCGLib o o * 00003 * Visual and Computer Graphics Library o o * 00004 * _ O _ * 00005 * Copyright(C) 2004 \/)\/ * 00006 * Visual Computing Lab /\/| * 00007 * ISTI - Italian National Research Council | * 00008 * \ * 00009 * All rights reserved. * 00010 * * 00011 * This program is free software; you can redistribute it and/or modify * 00012 * it under the terms of the GNU General Public License as published by * 00013 * the Free Software Foundation; either version 2 of the License, or * 00014 * (at your option) any later version. * 00015 * * 00016 * This program is distributed in the hope that it will be useful, * 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00019 * GNU General Public License (http://www.gnu.org/licenses/gpl.txt) * 00020 * for more details. * 00021 * * 00022 ****************************************************************************/ 00023 /**************************************************************************** 00024 History 00025 00026 $Log: not supported by cvs2svn $ 00027 00028 00029 ****************************************************************************/ 00030 #ifndef POLAR_DECOMPOSITION_VCG 00031 #define POLAR_DECOMPOSITION_VCG 00032 00033 00034 #include <vcg/math/matrix33.h> 00035 #include <vcg/math/matrix44.h> 00036 #include <vcg/math/lin_algebra.h> 00037 00038 namespace vcg{ 00039 00041 /* @{ */ 00044 template <class S> 00045 void RotationalPartByPolarDecomposition( const vcg::Matrix33<S> & m, vcg::Matrix33<S> &r ){ 00046 00047 vcg::Matrix33<S> tmp,s; 00048 00049 r.SetZero(); 00050 s.SetZero(); 00051 00052 tmp = m*m.transpose(); 00053 00054 Matrix33<S> res; 00055 Point3<S> e; 00056 00057 bool ss = SingularValueDecomposition<vcg::Matrix33<S> >(tmp,&e[0],res); 00058 00059 e[0]=math::Sqrt(e[0]); 00060 e[1]=math::Sqrt(e[1]); 00061 e[2]=math::Sqrt(e[2]); 00062 #ifdef VCG_USE_EIGEN 00063 tmp = tmp*e.asDiagonal()*res.transpose(); 00064 #else 00065 tmp = tmp*Matrix33Diag<S>(e)*res.transpose(); 00066 #endif 00067 00068 bool s1 = SingularValueDecomposition<vcg::Matrix33<S> >(tmp,&e[0],res.transpose()); 00069 e[0]=1/e[0]; 00070 e[1]=1/e[1]; 00071 e[2]=1/e[2]; 00072 00073 #ifdef VCG_USE_EIGEN 00074 tmp = res*e.asDiagonal()*tmp.transpose(); 00075 #else 00076 tmp = res*Matrix33Diag<S>(e)*tmp.transpose(); 00077 #endif 00078 00079 r = m*tmp; 00080 } 00081 00083 }; 00084 #endif