// This file is part of libigl, a simple c++ geometry processing library. // // Copyright (C) 2014 Stefan Brugger // // 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 "boundary_loop.h" #include "igl/boundary_facets.h" #include "igl/slice.h" #include template IGL_INLINE void igl::boundary_loop( const Eigen::PlainObjectBase & F, std::vector >& L) { using namespace std; using namespace Eigen; MatrixXi E; boundary_facets(F, E); set unseen; for (int i = 0; i < E.rows(); ++i) { unseen.insert(unseen.end(),i); } while (!unseen.empty()) { vector l; // Get first vertex of loop int startEdge = *unseen.begin(); unseen.erase(unseen.begin()); int start = E(startEdge,0); int next = E(startEdge,1); l.push_back(start); while (start != next) { l.push_back(next); // Find next edge int nextEdge; set::iterator it; for (it=unseen.begin(); it != unseen.end() ; ++it) { if (E(*it,0) == next || E(*it,1) == next) { nextEdge = *it; break; } } unseen.erase(nextEdge); next = (E(nextEdge,0) == next) ? E(nextEdge,1) : E(nextEdge,0); } L.push_back(l); } } template IGL_INLINE void igl::boundary_loop( const Eigen::PlainObjectBase& F, std::vector& L) { using namespace Eigen; using namespace std; vector > Lall; boundary_loop(F,Lall); int idxMax = -1; int maxLen = 0; for (int i = 0; i < Lall.size(); ++i) { if (Lall[i].size() > maxLen) { maxLen = Lall[i].size(); idxMax = i; } } L.resize(Lall[idxMax].size()); for (int i = 0; i < Lall[idxMax].size(); ++i) L[i] = Lall[idxMax][i]; } template IGL_INLINE void igl::boundary_loop( const Eigen::PlainObjectBase& F, Eigen::PlainObjectBase& L) { using namespace Eigen; using namespace std; vector Lvec; boundary_loop(F,Lvec); L.resize(Lvec.size()); for (int i = 0; i < Lvec.size(); ++i) L(i) = Lvec[i]; }