Browse Source

missing directed edge parents file

Former-commit-id: 070bafce63980502292c4d4d77958c5f1f801f33
Alec Jacobson 11 years ago
parent
commit
76a662d23f
2 changed files with 59 additions and 0 deletions
  1. 27 0
      include/igl/directed_edge_parents.cpp
  2. 32 0
      include/igl/directed_edge_parents.h

+ 27 - 0
include/igl/directed_edge_parents.cpp

@@ -0,0 +1,27 @@
+#include "directed_edge_parents.h"
+#include "slice_into.h"
+#include "slice.h"
+#include "colon.h"
+#include "setdiff.h"
+#include <algorithm>
+
+template <typename DerivedE, typename DerivedP>
+IGL_INLINE void igl::directed_edge_parents(
+  const Eigen::PlainObjectBase<DerivedE> & E,
+  Eigen::PlainObjectBase<DerivedP> & P)
+{
+  using namespace Eigen;
+  using namespace std;
+  VectorXi I = VectorXi::Constant(E.maxCoeff()+1,1,-1);
+  //I(E.col(1)) = 0:E.rows()-1
+  slice_into(colon<int>(0,E.rows()-1),E.col(1).eval(),I);
+  VectorXi roots,_;
+  setdiff(E.col(0).eval(),E.col(1).eval(),roots,_);
+  for_each(roots.data(),roots.data()+roots.size(),[&](int r){I(r)=-1;});
+  slice(I,E.col(0).eval(),P);
+}
+
+#ifdef IGL_STATIC_LIBRARY
+// Explicit template instanciation
+template void igl::directed_edge_parents<Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, 1, 0, -1, 1> >(Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> >&);
+#endif

+ 32 - 0
include/igl/directed_edge_parents.h

@@ -0,0 +1,32 @@
+// This file is part of libigl, a simple c++ geometry processing library.
+// 
+// Copyright (C) 2014 Alec Jacobson <alecjacobson@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_DIRECTED_EDGE_PARENTS_H
+#define IGL_DIRECTED_EDGE_PARENTS_H
+#include "igl_inline.h"
+
+#include <Eigen/Dense>
+
+namespace igl
+{
+  // Recover "parents" (preceeding edges) in a tree given just directed edges.
+  //
+  // Inputs:
+  //   E  #E by 2 list of directed edges
+  // Outputs:
+  //   P  #E list of parent indices into E (-1) means root
+  //
+  template <typename DerivedE, typename DerivedP>
+  IGL_INLINE void directed_edge_parents(
+    const Eigen::PlainObjectBase<DerivedE> & E,
+    Eigen::PlainObjectBase<DerivedP> & P);
+}
+
+#ifndef IGL_STATIC_LIBRARY
+#  include "directed_edge_parents.cpp"
+#endif
+#endif