outline_ordered.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. // Exterior edges include some non-manifold edges (poor function name). I
  19. // suppose `outline_ordered` is not well defined for non-manifold meshes, but
  20. // perhaps this should just call `boundary_facets`
  21. MatrixXi E = exterior_edges(F);
  22. set<int> unseen;
  23. for (int i = 0; i < E.rows(); ++i)
  24. {
  25. unseen.insert(unseen.end(),i);
  26. }
  27. while (!unseen.empty())
  28. {
  29. vector<Index> l;
  30. // Get first vertex of loop
  31. int startEdge = *unseen.begin();
  32. unseen.erase(unseen.begin());
  33. int start = E(startEdge,0);
  34. int next = E(startEdge,1);
  35. l.push_back(start);
  36. while (start != next)
  37. {
  38. l.push_back(next);
  39. // Find next edge
  40. int nextEdge;
  41. set<int>::iterator it;
  42. for (it=unseen.begin(); it != unseen.end() ; ++it)
  43. {
  44. if (E(*it,0) == next || E(*it,1) == next)
  45. {
  46. nextEdge = *it;
  47. break;
  48. }
  49. }
  50. unseen.erase(nextEdge);
  51. next = (E(nextEdge,0) == next) ? E(nextEdge,1) : E(nextEdge,0);
  52. }
  53. L.push_back(l);
  54. }
  55. }