Commit e2acbb61 by pitiot

### init

parent 6db3ac1c
 #ifndef __RIGIDXFCOMPUTATION_09122008__ #define __RIGIDXFCOMPUTATION_09122008__ #include "Geometry/matrix.h" #include "Geometry/vector_gen.h" using namespace CGoGN; /** two ways to compute the minimal linear transformation between 2 sets of points*/ class RigidComputation { public : /** SVD decomposition */ //Thanks to Frederic Larue // extern gmtl::Matrix44f getRigidTransform( std::vector from,std::vector to, float time); /** Jacobian rotation : to use with the covariance matrix*/ // http://books.google.com/books?id=weYj75E_t6MC&pg=PA263&lpg=PA263&dq=diagonalize+matrix+Jacobi+rotation+method&source=web&ots=LPY0V-udrx&sig=0mBoM5L9nH3KAdiunJKuGeVDW0s&hl=en&sa=X&oi=book_result&resnum=5&ct=result#PPA266,M1 // rotate a throught beta in pq-plane to set a[p][q]=0 // rotation stored in r whose columns are eigenvectors of a void rotate(Geom::Matrix33f &a,Geom::Matrix33f &r, int p, int q); float maxoffdiag(Geom::Matrix33f &a,int &p, int &q); //final a is diagonal matrix of eigenvalues //final r has eigenvectors in rows void jacrot(Geom::Matrix33f &a, Geom::Matrix33f &r); static int jacobiDiagonalization( Geom::Matrix33f& A, Geom::Matrix33f& V ); }; #endif
 #ifndef SHAPEMATCHING_H #define SHAPEMATCHING_H #include "Geometry/matrix.h" #include "Geometry/vector_gen.h" #include "env_map.h" using namespace CGoGN; template class ShapeMatchingGen { public: ShapeMatchingGen(typename PFP::MAP& map, VertexAttribute& position,std::vector v_darts, typename PFP::REAL beta): m_map(map), m_position(position), m_darts(v_darts), m_beta(beta) { this->goal = this->m_map.template addAttribute(""); } ~ShapeMatchingGen() { if(goal.isValid()) this->m_map.template removeAttribute(this->goal); } virtual void initialize()=0; virtual void animate()=0; void computeAqqMatrix() { this->aqq.zero(); for(unsigned int i = 0 ; i < this->q.size() ; i++) { this->aqq(0,0)+=this->q[i][0]*this->q[i][0]; this->aqq(1,0)+=this->q[i][0]*this->q[i][1]; this->aqq(2,0)+=this->q[i][0]*this->q[i][2]; this->aqq(0,1)+=this->q[i][1]*this->q[i][0]; this->aqq(1,1)+=this->q[i][1]*this->q[i][1]; this->aqq(2,1)+=this->q[i][1]*this->q[i][2]; this->aqq(0,2)+=this->q[i][2]*this->q[i][0]; this->aqq(1,2)+=this->q[i][2]*this->q[i][1]; this->aqq(2,2)+=this->q[i][2]*this->q[i][2]; } this->aqq.invert(this->aqq); } VEC3 computeBarycenterDarts() { VEC3 b(0); for(std::vector::iterator it = this->m_darts.begin() ; it != this->m_darts.end() ; ++it) b += this->m_position[*it]; b /= this->m_darts.size(); return b; } typename PFP::REAL computeDeterminant(const Geom::Matrix33f& a) { return a(0,0)*a(1,1)*a(2,2)+a(0,2)*a(1,0)*a(2,1)+a(0,1)*a(1,2)*a(2,0)-a(0,2)*a(1,1)*a(2,0)-a(0,0)*a(1,2)*a(2,1)-a(0,1)*a(1,0)*a(2,2); } // LIST_MAT m_lm; // typename PFP::MAP& m_map; VertexAttribute& m_position; std::vector m_darts; VertexAttribute goal; Geom::Matrix33f aqq; std::vector q; typename PFP::REAL m_beta; }; #endif
 #ifndef SHAPEMATCHING_LINEAR_H #define SHAPEMATCHING_LINEAR_H #include "shapeMatching.h" using namespace CGoGN; template class ShapeMatchingLinear : public ShapeMatchingGen { public: ShapeMatchingLinear(typename PFP::MAP& map, VertexAttribute& position,std::vector v_darts, typename PFP::REAL beta); ~ShapeMatchingLinear(); void initialize(); void animate(); protected: VertexAttribute vecToBary; }; #include "shapeMatchingLinear.hpp" #endif
 #include "rigidXfComputation.h" //****************************************************************************** template ShapeMatchingLinear::ShapeMatchingLinear(typename PFP::MAP& map, VertexAttribute& position,std::vector v_darts, typename PFP::REAL beta) : ShapeMatchingGen(map,position,v_darts,beta) { this->vecToBary = this->m_map.template addAttribute(""); } //****************************************************************************** template ShapeMatchingLinear::~ShapeMatchingLinear() { std::cout << "delete SM" << std::endl; if(this->vecToBary.isValid()) this->m_map.template removeAttribute(this->vecToBary); } template void ShapeMatchingLinear::initialize() { assert(this->m_darts.size()>0); typedef typename PFP::VEC3 VEC3; typedef typename PFP::REAL REAL; //********************* first compute the data for the MATS*********************************************************** //barycenter VEC3 x0cm = this->computeBarycenterDarts(); this->q.reserve(this->m_darts.size()); for (std::vector::iterator it = this->m_darts.begin(); it != this->m_darts.end(); ++it) { VEC3 myQ(this->m_position[*it]-x0cm); this->q.push_back(myQ); } this->computeAqqMatrix(); //********************* then compute the vector to barycenter for the map*********************************************************** //compute barycenter // VEC3 b = this->computeBarycenterDarts(); for(std::vector::iterator it = this->m_darts.begin() ; it != this->m_darts.end() ; ++it) this->vecToBary[*it] = this->m_position[*it] - x0cm; } template void ShapeMatchingLinear::animate() { typedef typename PFP::VEC3 VEC3; //initialize(nfe,frame_prec); unsigned int n = m_darts.size(); VEC3 xcm = this->computeBarycenterDarts(); std::vector p; p.reserve( n ); for(std::vector::iterator it = this->m_darts.begin(); it != this->m_darts.end(); ++it) p.push_back(this->m_position[*it]-xcm); Geom::Matrix33f apq; apq.zero(); for(unsigned int i=0;iq[i][y]; Geom::Matrix33f s = apq.transposed()*apq; Geom::Matrix33f sr; RigidComputation::jacobiDiagonalization(s,sr); s(0,0) = 1.0f/sqrt(s(0,0)); s(1,1) = 1.0f/sqrt(s(1,1)); s(2,2) = 1.0f/sqrt(s(2,2)); s = sr*s*sr.transposed(); Geom::Matrix33f r = apq*s; Geom::Matrix33f a = apq*this->aqq; typename PFP::REAL det = this->computeDeterminant(a); typename PFP::REAL detAInv = 1.0f/powf(det,1.0f/3.0f); if(std::isfinite(detAInv)) { for(unsigned int x=0;x<3;++x) for(unsigned int y=0;y<3;++y) r(x,y) = this->m_beta*a(x,y)*detAInv+(1.0f-this->m_beta)*r(x,y); } else { std::cout << "no linear deformation (planar config ?), applying identity" << std::endl; r.identity(); } //once the transformation computed : move the vertices of the map //compute barycenter VEC3 b = this->computeBarycenterDarts(); //move the vertices for(std::vector::iterator it = this->m_darts.begin() ; it != this->m_darts.end() ; ++it) { this->goal[*it] = r*this->vecToBary[*it]+xcm; } }
 #ifndef SHAPEMATCHING_QUAD_H #define SHAPEMATCHING_QUAD_H #include "shapeMatching.h" #include "Geometry/vector_gen.h" using namespace CGoGN; template class ShapeMatchingQuadratic : public ShapeMatchingGen { public: ShapeMatchingQuadratic(typename PFP::MAP& map, VertexAttribute& position,std::vector v_darts, typename PFP::REAL beta); ~ShapeMatchingQuadratic(); void initialize(); void animate(); protected: Geom::Matrix<9,9,typename PFP::REAL> aqqQuad; //vectors to barycenter std::vector > qQuad; VertexAttribute > vecQuad ; }; #include "shapeMatchingQuadratic.hpp" #endif