// 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 "adjacency_matrix.h" #include "verbose.h" #include template IGL_INLINE void igl::adjacency_matrix( const Eigen::MatrixBase & F, Eigen::SparseMatrix& A) { using namespace std; using namespace Eigen; typedef typename DerivedF::Scalar Index; typedef Triplet IJV; vector ijv; ijv.reserve(F.size()*2); // Loop over **simplex** (i.e., **not quad**) for(int i = 0;i d Index s = F(i,j); Index d = F(i,k); ijv.push_back(IJV(s,d,1)); ijv.push_back(IJV(d,s,1)); } } const Index n = F.maxCoeff()+1; A.resize(n,n); switch(F.cols()) { case 3: A.reserve(6*(F.maxCoeff()+1)); break; case 4: A.reserve(26*(F.maxCoeff()+1)); break; } A.setFromTriplets(ijv.begin(),ijv.end()); // Force all non-zeros to be one // Iterate over outside for(int k=0; k::InnerIterator it (A,k); it; ++it) { assert(it.value() != 0); A.coeffRef(it.row(),it.col()) = 1; } } } #ifdef IGL_STATIC_LIBRARY // Explicit template instantiation // generated by autoexplicit.sh template void igl::adjacency_matrix, bool>(Eigen::MatrixBase > const&, Eigen::SparseMatrix&); template void igl::adjacency_matrix, double>(Eigen::MatrixBase > const&, Eigen::SparseMatrix&); template void igl::adjacency_matrix, int>(Eigen::MatrixBase > const&, Eigen::SparseMatrix&); template void igl::adjacency_matrix, int>(Eigen::MatrixBase > const&, Eigen::SparseMatrix&); #endif