outline_ordered.cpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 "igl/boundary_facets.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;
  19. boundary_facets(F, E);
  20. set<int> unseen;
  21. for (int i = 0; i < E.rows(); ++i)
  22. {
  23. unseen.insert(unseen.end(),i);
  24. }
  25. while (!unseen.empty())
  26. {
  27. vector<Index> l;
  28. // Get first vertex of loop
  29. int startEdge = *unseen.begin();
  30. unseen.erase(unseen.begin());
  31. int start = E(startEdge,0);
  32. int next = E(startEdge,1);
  33. l.push_back(start);
  34. while (start != next)
  35. {
  36. l.push_back(next);
  37. // Find next edge
  38. int nextEdge;
  39. set<int>::iterator it;
  40. for (it=unseen.begin(); it != unseen.end() ; ++it)
  41. {
  42. if (E(*it,0) == next || E(*it,1) == next)
  43. {
  44. nextEdge = *it;
  45. break;
  46. }
  47. }
  48. unseen.erase(nextEdge);
  49. next = (E(nextEdge,0) == next) ? E(nextEdge,1) : E(nextEdge,0);
  50. }
  51. L.push_back(l);
  52. }
  53. }