Browse Source

Merge pull request #27 from stefanbrugger/master

Added outline_ordered() as available in gptoolbox

Former-commit-id: 904bad35e6a7f7aa75d44f0f943a60be6e680c5d
Alec Jacobson 10 years ago
parent
commit
fff0d0ea5e
2 changed files with 87 additions and 0 deletions
  1. 52 0
      include/igl/outline_ordered.cpp
  2. 35 0
      include/igl/outline_ordered.h

+ 52 - 0
include/igl/outline_ordered.cpp

@@ -0,0 +1,52 @@
+#include "outline_ordered.h"
+
+#include "igl/exterior_edges.h"
+#include <set>
+
+using namespace std;
+using namespace Eigen;
+
+template <typename Index>
+IGL_INLINE void igl::outline_ordered(
+    const Eigen::MatrixXi& F, 
+    std::vector<std::vector<Index> >& L)
+{
+  MatrixXi E = exterior_edges(F);
+
+  set<int> unseen;
+  for (int i = 0; i < E.rows(); ++i)
+      unseen.insert(unseen.end(),i);
+
+  while (!unseen.empty())
+  {
+      vector<Index> 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<int>::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);
+  }
+}

+ 35 - 0
include/igl/outline_ordered.h

@@ -0,0 +1,35 @@
+// This file is part of libigl, a simple c++ geometry processing library.
+// 
+// Copyright (C) 2014 Stefan Brugger <stefanbrugger@gmail.com>
+// 
+// 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/.
+#ifndef IGL_OUTLINE_H
+#define IGL_OUTLINE_H
+#include <igl/igl_inline.h>
+
+#include <Eigen/Dense>
+#include <vector>
+
+namespace igl
+{
+  // Compute list of ordered boundary loops for a manifold mesh.
+  //
+  // Templates:
+  //  Index  index type
+  // Inputs:
+  //   F  #V by dim list of mesh faces
+  // Outputs:
+  //   L  list of loops where L[i] = ordered list of boundary vertices in loop i
+  //
+  template <typename Index>
+  IGL_INLINE void outline_ordered(
+    const Eigen::MatrixXi& F, 
+    std::vector<std::vector<Index> >& L);
+}
+
+#ifndef IGL_STATIC_LIBRARY
+#  include "outline_ordered.cpp"
+#endif
+#endif