// 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 "components.h" #include //#include #include #include #include #include #include template IGL_INLINE void igl::components( const Eigen::SparseMatrix & A, Eigen::PlainObjectBase & C) { assert(A.rows() == A.cols()); using namespace Eigen; // THIS IS DENSE: //boost::adjacency_matrix bA(A.rows()); boost::adjacency_list bA(A.rows()); for(int j=0; j::InnerIterator it (A,j); it; ++it) { if(0 != it.value()) { boost::add_edge(it.row(),it.col(),bA); } } } C.resize(A.rows(),1); boost::connected_components(bA,C.data()); } template IGL_INLINE void igl::components( const Eigen::PlainObjectBase & F, Eigen::PlainObjectBase & C) { Eigen::SparseMatrix A; igl::adjacency_matrix(F,A); return components(A,C); } #ifndef IGL_HEADER_ONLY // Explicit template specialization template void igl::components, Eigen::Matrix >(Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase >&); #endif