outline_ordered.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2014 Stefan Brugger <stefanbrugger@gmail.com>
  4. //
  5. // This Source Code Form is subject to the terms of the Mozilla Public License
  6. // v. 2.0. If a copy of the MPL was not distributed with this file, You can
  7. // obtain one at http://mozilla.org/MPL/2.0/.
  8. #include "outline_ordered.h"
  9. #include "exterior_edges.h"
  10. #include <set>
  11. template <typename DerivedF, typename Index>
  12. IGL_INLINE void igl::outline_ordered(
  13. const Eigen::PlainObjectBase<DerivedF> & F,
  14. std::vector<std::vector<Index> >& L)
  15. {
  16. using namespace std;
  17. using namespace Eigen;
  18. MatrixXi E = exterior_edges(F);
  19. set<int> unseen;
  20. for (int i = 0; i < E.rows(); ++i)
  21. {
  22. unseen.insert(unseen.end(),i);
  23. }
  24. while (!unseen.empty())
  25. {
  26. vector<Index> l;
  27. // Get first vertex of loop
  28. int startEdge = *unseen.begin();
  29. unseen.erase(unseen.begin());
  30. int start = E(startEdge,0);
  31. int next = E(startEdge,1);
  32. l.push_back(start);
  33. while (start != next)
  34. {
  35. l.push_back(next);
  36. // Find next edge
  37. int nextEdge;
  38. set<int>::iterator it;
  39. for (it=unseen.begin(); it != unseen.end() ; ++it)
  40. {
  41. if (E(*it,0) == next || E(*it,1) == next)
  42. {
  43. nextEdge = *it;
  44. break;
  45. }
  46. }
  47. unseen.erase(nextEdge);
  48. next = (E(nextEdge,0) == next) ? E(nextEdge,1) : E(nextEdge,0);
  49. }
  50. L.push_back(l);
  51. }
  52. }