123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- #include "adjacency_matrix.h"
- #include "verbose.h"
- #include <vector>
- template <typename DerivedF, typename T>
- IGL_INLINE void igl::adjacency_matrix(
- const Eigen::MatrixBase<DerivedF> & F,
- Eigen::SparseMatrix<T>& A)
- {
- using namespace std;
- using namespace Eigen;
- typedef typename DerivedF::Scalar Index;
- typedef Triplet<T> IJV;
- vector<IJV > ijv;
- ijv.reserve(F.size()*2);
-
- for(int i = 0;i<F.rows();i++)
- {
-
- for(int j = 0;j<F.cols();j++)
- for(int k = j+1;k<F.cols();k++)
- {
-
- 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());
-
-
- for(int k=0; k<A.outerSize(); ++k)
- {
-
- for(typename Eigen::SparseMatrix<T>::InnerIterator it (A,k); it; ++it)
- {
- assert(it.value() != 0);
- A.coeffRef(it.row(),it.col()) = 1;
- }
- }
- }
- #ifdef IGL_STATIC_LIBRARY
- template void igl::adjacency_matrix<Eigen::Matrix<int, -1, -1, 0, -1, -1>, bool>(Eigen::MatrixBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::SparseMatrix<bool, 0, int>&);
- template void igl::adjacency_matrix<Eigen::Matrix<int, -1, -1, 0, -1, -1>, double>(Eigen::MatrixBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::SparseMatrix<double, 0, int>&);
- template void igl::adjacency_matrix<Eigen::Matrix<int, -1, -1, 0, -1, -1>, int>(Eigen::MatrixBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::SparseMatrix<int, 0, int>&);
- template void igl::adjacency_matrix<Eigen::Matrix<int, -1, 3, 0, -1, 3>, int>(Eigen::MatrixBase<Eigen::Matrix<int, -1, 3, 0, -1, 3> > const&, Eigen::SparseMatrix<int, 0, int>&);
- #endif
|