00001 #include "m23d_rotation_from_ortho_projection.h" 00002 //: 00003 // \file 00004 // \author Tim Cootes 00005 // \brief Generate pure 3 x 3 rotation matrix from 2 x 3 projection matrix 00006 00007 #include <vnl/vnl_cross.h> 00008 #include <m23d/m23d_pure_ortho_projection.h> 00009 00010 //: Generate pure 3 x 3 rotation matrix from 2 x 3 projection matrix 00011 // Result may also include a reflection. 00012 // The result, R, should be such that PR.transpose() approx= (sI|0) 00013 vnl_matrix<double> m23d_rotation_from_ortho_projection(const vnl_matrix<double>& M) 00014 { 00015 vnl_matrix<double> P = m23d_pure_ortho_projection(M); 00016 vnl_matrix<double> R(3,3); 00017 R.update(P,0,0); 00018 R.set_row(2,vnl_cross_3d(P.get_row(0),P.get_row(1))); 00019 00020 // Test for reflection 00021 vnl_matrix<double> PRt = M*R.transpose(); 00022 if (PRt(0,0)<0) R*=-1.0; 00023 return R; 00024 }