// 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 "face_occurrences.h" #include "list_to_matrix.h" #include "matrix_to_list.h" #include #include "sort.h" #include template IGL_INLINE void igl::face_occurrences( const std::vector > & F, std::vector & C) { using namespace std; // Get a list of sorted faces vector > sortedF = F; for(int i = 0; i < (int)F.size();i++) { sort(sortedF[i].begin(),sortedF[i].end()); } // Count how many times each sorted face occurs map,int> counts; for(int i = 0; i < (int)sortedF.size();i++) { if(counts.find(sortedF[i]) == counts.end()) { // initialize to count of 1 counts[sortedF[i]] = 1; }else { // increment count counts[sortedF[i]]++; assert(counts[sortedF[i]] == 2 && "Input should be manifold"); } } // Resize output to fit number of ones C.resize(F.size()); for(int i = 0;i< (int)F.size();i++) { // sorted face should definitely be in counts map assert(counts.find(sortedF[i]) != counts.end()); C[i] = counts[sortedF[i]]; } } template IGL_INLINE void igl::face_occurrences( const Eigen::MatrixBase & F, Eigen::PlainObjectBase & C) { // Should really just rewrite using Eigen+libigl ... std::vector > vF; matrix_to_list(F,vF); std::vector > vC; igl::face_occurrences(vF,vC); list_to_matrix(vC,C); } #ifdef IGL_STATIC_LIBRARY // Explicit template instantiation // generated by autoexplicit.sh template void igl::face_occurrences(std::vector >, std::allocator > > > const&, std::vector >&); template void igl::face_occurrences(std::vector >, std::allocator > > > const&, std::vector >&); #endif