#ifndef IGL_ADJACENCY_MATRIX_H #define IGL_ADJACENCY_MATRIX_H #define EIGEN_YES_I_KNOW_SPARSE_MODULE_IS_NOT_STABLE_YET #include #include namespace igl { // Constructs the graph adjacency matrix of a given mesh (V,F) // Templates: // T should be a eigen sparse matrix primitive type like int or double // Inputs: // F #F by dim list of mesh faces (must be triangles) // Outputs: // A max(F) by max(F) cotangent matrix, each row i corresponding to V(i,:) // // Example: // // Mesh in (V,F) // Eigen::SparseMatrix A; // adjacency_matrix(F,A); // // sum each row // SparseVector Asum; // sum(A,1,Asum); // // Convert row sums into diagonal of sparse matrix // SparseMatrix Adiag; // diag(Asum,Adiag); // // Build uniform laplacian // SparseMatrix U; // U = A-Adiag; // // See also: edges, cotmatrix, diag template inline void adjacency_matrix( const Eigen::MatrixXi & F, Eigen::SparseMatrix& A); } // Implementation #include "verbose.h" template inline void igl::adjacency_matrix( const Eigen::MatrixXi & F, Eigen::SparseMatrix& A) { Eigen::DynamicSparseMatrix dyn_A(F.maxCoeff()+1, F.maxCoeff()+1); // Loop over faces for(int i = 0;i d int s = F(i,j); int d = F(i,(j+1)%F.cols()); dyn_A.coeffRef(s, d) = 1; dyn_A.coeffRef(d, s) = 1; } } A = Eigen::SparseMatrix(dyn_A); } #endif