Selaa lähdekoodia

added unique edge map

Former-commit-id: 05a3477f3883262575315ee9def1620213ad450c
Alec Jacobson 10 vuotta sitten
vanhempi
commit
22f006a98d
2 muutettua tiedostoa jossa 74 lisäystä ja 0 poistoa
  1. 37 0
      include/igl/unique_edge_map.cpp
  2. 37 0
      include/igl/unique_edge_map.h

+ 37 - 0
include/igl/unique_edge_map.cpp

@@ -0,0 +1,37 @@
+#include "unique_edge_map.h"
+#include "all_edges.h"
+#include "unique_simplices.h"
+#include <cassert>
+#include <algorithm>
+template <
+  typename DerivedF,
+  typename DerivedE,
+  typename DeriveduE,
+  typename DerivedEMAP,
+  typename uE2EType>
+IGL_INLINE void igl::unique_edge_map(
+  const Eigen::PlainObjectBase<DerivedF> & F,
+  Eigen::PlainObjectBase<DerivedE> & E,
+  Eigen::PlainObjectBase<DeriveduE> & uE,
+  Eigen::PlainObjectBase<DerivedEMAP> & EMAP,
+  std::vector<std::vector<uE2EType> > & uE2E)
+{
+  using namespace Eigen;
+  using namespace std;
+  // All occurances of directed edges
+  all_edges(F,E);
+  const size_t ne = E.rows();
+  // This is 2x faster to create than a map from pairs to lists of edges and 5x
+  // faster to access (actually access is probably assympotically faster O(1)
+  // vs. O(log m)
+  Matrix<typename DerivedEMAP::Scalar,Dynamic,1> IA;
+  unique_simplices(E,uE,IA,EMAP);
+  uE2E.resize(uE.rows());
+  // This does help a little
+  for_each(uE2E.begin(),uE2E.end(),[](vector<uE2EType > & v){v.reserve(2);});
+  assert(EMAP.size() == ne);
+  for(uE2EType e = 0;e<ne;e++)
+  {
+    uE2E[EMAP(e)].push_back(e);
+  }
+}

+ 37 - 0
include/igl/unique_edge_map.h

@@ -0,0 +1,37 @@
+#ifndef IGL_EXTERIOR_EDGES_H
+#define IGL_EXTERIOR_EDGES_H
+#include "igl_inline.h"
+#include <Eigen/Dense>
+#include <vector>
+namespace igl
+{
+  // Constuct relationships between facet "half"-(or rather "viewed")-edges E
+  // to unique edges of the mesh seen as a graph.
+  //
+  // Inputs:
+  //   F  #F by 3  list of simplices
+  // Outputs:
+  //   E  #F*3 by 2 list of all of directed edges
+  //   uE  #uE by 2 list of unique undirected edges
+  //   EMAP #F*3 list of indices into uE, mapping each directed edge to unique
+  //     undirected edge
+  //   uE2E  #uE list of lists of indices into E of coexisting edges
+  template <
+    typename DerivedF,
+    typename DerivedE,
+    typename DeriveduE,
+    typename DerivedEMAP,
+    typename uE2EType>
+  IGL_INLINE void unique_edge_map(
+    const Eigen::PlainObjectBase<DerivedF> & F,
+    Eigen::PlainObjectBase<DerivedE> & E,
+    Eigen::PlainObjectBase<DeriveduE> & uE,
+    Eigen::PlainObjectBase<DerivedEMAP> & EMAP,
+    std::vector<std::vector<uE2EType> > & uE2E);
+
+}
+#ifndef IGL_STATIC_LIBRARY
+#  include "unique_edge_map.cpp"
+#endif
+
+#endif