Browse Source

sample edges from FAST

Former-commit-id: e6997d5a94a5bb1431c2ba7c37e66ce7b61ba492
Alec Jacobson (jalec 12 years ago
parent
commit
b7c14347a1
3 changed files with 57 additions and 1 deletions
  1. 1 1
      include/igl/readTGF.h
  2. 26 0
      include/igl/sample_edges.cpp
  3. 30 0
      include/igl/sample_edges.h

+ 1 - 1
include/igl/readTGF.h

@@ -35,7 +35,7 @@ namespace igl
     std::vector<std::vector<int> > & BE,
     std::vector<std::vector<int> > & CE,
     std::vector<std::vector<int> > & PE);
-  
+
   #ifndef IGL_NO_EIGEN
   IGL_INLINE bool readTGF(
     const std::string tgf_filename,

+ 26 - 0
include/igl/sample_edges.cpp

@@ -0,0 +1,26 @@
+#include "sample_edges.h"
+
+IGL_INLINE void igl::sample_edges(
+  const Eigen::MatrixXd & V,
+  const Eigen::MatrixXi & E,
+  const int k,
+  Eigen::MatrixXd & S)
+{
+  using namespace Eigen;
+  // Resize output
+  S.resize(V.rows() + k * E.rows(),V.cols());
+  // Copy V at front of S
+  S.block(0,0,V.rows(),V.cols()) = V;
+
+  // loop over edges
+  for(int i = 0;i<E.rows();i++)
+  {
+    VectorXd tip = V.row(E(i,0));
+    VectorXd tail = V.row(E(i,1));
+    for(int s=0;s<k;s++)
+    {
+      double f = double(s+1)/double(k+1);
+      S.row(V.rows()+k*i+s) = f*tail + (1.0-f)*tip;
+    }
+  }
+}

+ 30 - 0
include/igl/sample_edges.h

@@ -0,0 +1,30 @@
+#ifndef IGL_SAMPLE_EDGES_H
+#define IGL_SAMPLE_EDGES_H
+#include "igl_inline.h"
+
+#include <Eigen/Dense>
+
+namespace igl
+{
+  // Compute samples_per_edge extra points along each edge in E defined over
+  // vertices of V.
+  //
+  // Inputs:
+  //   V  vertices over which edges are defined, # vertices by dim
+  //   E  edge list, # edges by 2
+  //   k  number of extra samples to be computed along edge not
+  //        including start and end points
+  // Output:
+  //   S  sampled vertices, size less than # edges * (2+k) by dim always begins
+  //        with V so that E is also defined over S
+  void sample_edges(
+    const Eigen::MatrixXd & V,
+    const Eigen::MatrixXi & E,
+    const int k,
+    Eigen::MatrixXd & S);
+}
+#ifdef IGL_HEADER_ONLY
+#  include "sample_edges.cpp"
+#endif
+
+#endif